1 /* 2 * Copyright 2002 David Shipman, 3 * Copyright 2003-2007 Marcus Overhagen 4 * Copyright 2007-2010 Haiku Inc. All rights reserved. 5 * Distributed under the terms of the MIT License. 6 */ 7 #ifndef AUDIO_MIXER_H 8 #define AUDIO_MIXER_H 9 10 11 #include <BufferConsumer.h> 12 #include <BufferGroup.h> 13 #include <BufferProducer.h> 14 #include <Controllable.h> 15 #include <MediaEventLooper.h> 16 #include <MediaNode.h> 17 18 19 class MixerCore; 20 class MixerOutput; 21 22 23 class AudioMixer : public BBufferConsumer, public BBufferProducer, 24 public BControllable, public BMediaEventLooper { 25 public: 26 AudioMixer(BMediaAddOn* addOn, 27 bool isSystemMixer); 28 virtual ~AudioMixer(); 29 30 void DisableNodeStop(); 31 32 // AudioMixer support 33 void ApplySettings(); 34 35 void PublishEventLatencyChange(); 36 void UpdateParameterWeb(); 37 38 void HandleInputBuffer(BBuffer* buffer, 39 bigtime_t lateness); 40 41 status_t CreateBufferGroup(BBufferGroup** buffer) const; 42 43 status_t SendBuffer(BBuffer* buffer, 44 MixerOutput* output); 45 46 float dB_to_Gain(float db); 47 float Gain_to_dB(float gain); 48 49 // BMediaNode methods 50 virtual BMediaAddOn* AddOn(int32* _internalID) const; 51 virtual void NodeRegistered(); 52 virtual void Stop(bigtime_t performanceTime, bool immediate); 53 virtual void SetTimeSource(BTimeSource* timeSource); 54 55 protected: 56 // BControllable methods 57 virtual status_t GetParameterValue(int32 id, 58 bigtime_t* _lastChange, void* _value, 59 size_t* _size); 60 virtual void SetParameterValue(int32 id, bigtime_t when, 61 const void* value, size_t size); 62 63 // BBufferConsumer methods 64 virtual status_t HandleMessage(int32 message, const void* data, 65 size_t size); 66 virtual status_t AcceptFormat(const media_destination& dest, 67 media_format* format); 68 virtual status_t GetNextInput(int32* cookie, 69 media_input* _input); 70 virtual void DisposeInputCookie(int32 cookie); 71 virtual void BufferReceived(BBuffer *buffer); 72 virtual void ProducerDataStatus( 73 const media_destination& forWhom, 74 int32 status, bigtime_t atPerformanceTime); 75 virtual status_t GetLatencyFor(const media_destination& forWhom, 76 bigtime_t* _latency, 77 media_node_id* _timesource); 78 virtual status_t Connected(const media_source& producer, 79 const media_destination& where, 80 const media_format& withFormat, 81 media_input* _input); 82 virtual void Disconnected(const media_source& producer, 83 const media_destination& where); 84 virtual status_t FormatChanged(const media_source& producer, 85 const media_destination& consumer, 86 int32 changeTag, 87 const media_format& format); 88 89 // BBufferProducer methods 90 virtual status_t FormatSuggestionRequested(media_type type, 91 int32 quality, media_format* format); 92 virtual status_t FormatProposal(const media_source& output, 93 media_format* format); 94 virtual status_t FormatChangeRequested( 95 const media_source& source, 96 const media_destination &destination, 97 media_format* format, 98 int32* /*deprecated*/); 99 virtual status_t GetNextOutput(int32* cookie, 100 media_output* _output); 101 virtual status_t DisposeOutputCookie(int32 cookie); 102 virtual status_t SetBufferGroup(const media_source& source, 103 BBufferGroup* group); 104 virtual status_t GetLatency(bigtime_t* _latency); 105 virtual status_t PrepareToConnect(const media_source& what, 106 const media_destination& where, 107 media_format* format, media_source* _source, 108 char* _name); 109 virtual void Connect(status_t error, 110 const media_source& source, 111 const media_destination& destination, 112 const media_format& format, char *_name); 113 virtual void Disconnect(const media_source& what, 114 const media_destination& where); 115 virtual void LateNoticeReceived(const media_source& what, 116 bigtime_t howMuch, 117 bigtime_t performanceTime); 118 virtual void EnableOutput(const media_source& what, 119 bool enabled, int32* /*_deprecated_*/); 120 virtual void LatencyChanged(const media_source& source, 121 const media_destination& destination, 122 bigtime_t newLatency, uint32 flags); 123 124 // BMediaEventLooper methods 125 virtual void HandleEvent(const media_timed_event* event, 126 bigtime_t lateness, 127 bool realTimeEvent = false); 128 129 private: 130 BMediaAddOn* fAddOn; 131 MixerCore* fCore; 132 BParameterWeb* fWeb; 133 BBufferGroup* fBufferGroup; 134 bigtime_t fDownstreamLatency; 135 bigtime_t fInternalLatency; 136 bool fDisableStop; 137 media_format fDefaultFormat; 138 bigtime_t fLastLateNotification; 139 bigtime_t fLastLateness; 140 }; 141 142 143 #endif // AUDIO_MIXER_H 144