1 /* 2 * Copyright 2012, Gerasim Troeglazov (3dEyes**), 3dEyes@gmail.com. 3 * All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 #ifndef __EQUALIZER_NODE_H__ 8 #define __EQUALIZER_NODE_H__ 9 10 #include <Controllable.h> 11 #include <BufferProducer.h> 12 #include <BufferConsumer.h> 13 #include <MediaEventLooper.h> 14 15 #include "Equalizer.h" 16 17 class BMediaAddOn; 18 class BBufferGroup; 19 20 #define BUFF_SIZE 0x2000 21 22 #define ID_AUDIO_INPUT 1 23 #define ID_AUDIO_OUTPUT 2 24 25 #define P_PREAMP_LABEL 100 26 #define P_PREAMP 101 27 #define P_MUTE 102 28 #define P_BYPASS 103 29 #define P_BAND_LABELS 200 30 #define P_BANDS 300 31 32 class EqualizerNode : public BBufferConsumer, 33 public BBufferProducer, 34 public BControllable, 35 public BMediaEventLooper { 36 public: 37 virtual ~EqualizerNode(); 38 EqualizerNode(BMediaAddOn* pAddOn = NULL); 39 //BMediaNode 40 public: 41 virtual BMediaAddOn *AddOn(int32* id) const; 42 virtual status_t HandleMessage(int32 code, const void* data, size_t size); 43 protected: 44 virtual void NodeRegistered(); 45 //BControllable 46 public: 47 virtual status_t GetParameterValue(int32 id, bigtime_t* lastChangeTime, 48 void* value, size_t* size); 49 virtual void SetParameterValue(int32 id, bigtime_t changeTime, 50 const void* value, size_t size); 51 //BBufferConsumer 52 public: 53 virtual void BufferReceived(BBuffer* buffer); 54 virtual status_t AcceptFormat(const media_destination &dst, 55 media_format* format); 56 virtual status_t GetNextInput(int32* cookie, media_input* input); 57 virtual void DisposeInputCookie(int32 cookie); 58 virtual status_t FormatChanged(const media_source &src, 59 const media_destination &dst, 60 int32 change_tag, const media_format &format); 61 virtual void ProducerDataStatus(const media_destination &dst, 62 int32 status, 63 bigtime_t when); 64 virtual status_t GetLatencyFor(const media_destination &dst, 65 bigtime_t* latency, 66 media_node_id* time_src); 67 virtual status_t Connected(const media_source &src, 68 const media_destination &dst, 69 const media_format &format, 70 media_input* input); 71 virtual void Disconnected(const media_source &src, 72 const media_destination &dst); 73 //BBufferProducer 74 public: 75 virtual status_t FormatSuggestionRequested(media_type type, 76 int32 quality, media_format* format); 77 virtual status_t FormatProposal(const media_source &src, 78 media_format* format); 79 virtual status_t FormatChangeRequested(const media_source &src, 80 const media_destination &dst, 81 media_format* format, 82 int32* _deprecated_); 83 virtual void LateNoticeReceived(const media_source &src, 84 bigtime_t late, bigtime_t when); 85 virtual status_t GetNextOutput(int32 *cookie, media_output* output); 86 virtual status_t DisposeOutputCookie(int32 cookie); 87 virtual status_t SetBufferGroup(const media_source &src, 88 BBufferGroup* group); 89 virtual status_t PrepareToConnect(const media_source &src, 90 const media_destination &dst, 91 media_format* format, media_source* source, 92 char* name); 93 virtual void Connect(status_t status, 94 const media_source &src, 95 const media_destination &dst, 96 const media_format &format, 97 char* name); 98 virtual void Disconnect(const media_source &src, 99 const media_destination &dst); 100 virtual void EnableOutput(const media_source &src, 101 bool enabled, int32* _deprecated_); 102 virtual status_t GetLatency(bigtime_t* outLatency); 103 virtual void LatencyChanged( const media_source &src, 104 const media_destination &dst, 105 bigtime_t latency, uint32 flags); 106 //BMediaEventLooper 107 protected: 108 virtual bigtime_t OfflineTime(); 109 //EqualizerNode 110 protected: 111 virtual void HandleEvent(const media_timed_event* event, 112 bigtime_t late, 113 bool realTimeEvent = false); 114 void ParameterEventProcessing(const media_timed_event* event); 115 status_t ValidateFormat(const media_format &preferred_format, 116 media_format &proposed_format); 117 void SetOutputFormat(media_format &format); 118 virtual void InitParameterValues(void); 119 virtual void InitParameterWeb(void); 120 virtual void InitFilter(void); 121 virtual bigtime_t GetFilterLatency(void); 122 virtual void FilterBuffer(BBuffer* pBuffer); 123 124 private: 125 BMediaAddOn* fAddOn; 126 BParameterWeb* fWeb; 127 128 Equalizer fEqualizer; 129 130 media_format fPreferredFormat; 131 media_format fFormat; 132 media_input fInputMedia; 133 media_output fOutputMedia; 134 135 int32 fMute; 136 int32 fByPass; 137 138 bigtime_t fMuteLastChanged; 139 bigtime_t fByPassLastChanged; 140 bigtime_t fPreAmpLastChanged; 141 bigtime_t fBandsLastChanged[EQ_BANDS]; 142 143 bigtime_t fProcessLatency; 144 bigtime_t fDownstreamLatency; 145 bool fOutputMediaEnabled; 146 }; 147 148 #endif //__EQUALIZER_NODE_H__ 149