xref: /haiku/src/add-ons/media/media-add-ons/mixer/AudioMixer.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
1 // AudioMixer.h
2 /*
3 
4 	By David Shipman, 2002
5 
6 */
7 
8 #ifndef _AUDIOMIXER_H
9 #define _AUDIOMIXER_H
10 
11 // forward declarations
12 
13 class MixerCore;
14 
15 
16 // includes
17 
18 #include <media/BufferGroup.h>
19 #include <media/MediaNode.h>
20 #include <media/BufferConsumer.h>
21 #include <media/BufferProducer.h>
22 #include <media/Controllable.h>
23 #include <media/MediaEventLooper.h>
24 
25 // ----------------
26 // AudioMixer class
27 
28 class AudioMixer :
29 		public BBufferConsumer,
30 		public BBufferProducer,
31 		public BControllable,
32 		public BMediaEventLooper
33 {
34 
35 	public:
36 
37 					AudioMixer(BMediaAddOn *addOn, bool isSystemMixer);
38 					~AudioMixer();
39 
40 
41 		void				DisableNodeStop();
42 
43 	// AudioMixer support
44 
45 		void				ApplySettings();
46 
47 		void				PublishEventLatencyChange();
48 		void				UpdateParameterWeb();
49 
50 		void				HandleInputBuffer(BBuffer *buffer, bigtime_t lateness);
51 
52 		BBufferGroup *		CreateBufferGroup();
53 
54 		float				dB_to_Gain(float db);
55 		float				Gain_to_dB(float gain);
56 
57 	// BMediaNode methods
58 
59 		BMediaAddOn		*	AddOn(int32*) const;
60 	//	void 			SetRunMode(run_mode);
61 	//	void Preroll();
62 		//	status_t RequestCompleted(const media_request_info & info);
63 		void				NodeRegistered();
64 		void 				Stop(bigtime_t performance_time, bool immediate);
65 		void 				SetTimeSource(BTimeSource * time_source);
66 
67 		using BBufferProducer::SendBuffer;
68 
69 	protected:
70 
71 	// BControllable methods
72 
73 		status_t 			GetParameterValue( int32 id, bigtime_t* last_change,
74 								void* value,
75 								size_t* ioSize);
76 
77 		void				SetParameterValue( int32 id, bigtime_t when,
78 								const void* value,
79 								size_t size);
80 
81 	// BBufferConsumer methods
82 
83 		status_t			HandleMessage( int32 message,
84 								const void* data,
85 								size_t size);
86 
87 		status_t			AcceptFormat( const media_destination &dest, media_format *format);
88 
89 		status_t			GetNextInput( int32 *cookie,
90 								media_input *out_input);
91 
92 		void				DisposeInputCookie( int32 cookie);
93 
94 		void				BufferReceived( BBuffer *buffer);
95 
96 		void				ProducerDataStatus( const media_destination &for_whom,
97 								int32 status,
98 								bigtime_t at_performance_time);
99 
100 		status_t			GetLatencyFor( const media_destination &for_whom,
101 								bigtime_t *out_latency,
102 								media_node_id *out_timesource);
103 
104 		status_t			Connected( const media_source &producer,
105 								const media_destination &where,
106 								const media_format &with_format,
107 								media_input *out_input);
108 
109 		void				Disconnected( const media_source &producer,
110 								const media_destination &where);
111 
112 		status_t			FormatChanged( const media_source &producer,
113 								const media_destination &consumer,
114 								int32 change_tag,
115 								const media_format &format);
116 
117 
118 	//
119 	// BBufferProducer methods
120 	//
121 
122 		status_t 			FormatSuggestionRequested( media_type type,
123 								int32 quality,
124 								media_format *format);
125 
126 		status_t 			FormatProposal(
127 		const media_source& output,
128 		media_format* format);
129 //
130 //	/* If the format isn't good, put a good format into *io_format and return error */
131 //	/* If format has wildcard, specialize to what you can do (and change). */
132 //	/* If you can change the format, return OK. */
133 //	/* The request comes from your destination sychronously, so you cannot ask it */
134 //	/* whether it likes it -- you should assume it will since it asked. */
135 	status_t FormatChangeRequested(
136 		const media_source& source,
137 		const media_destination& destination,
138 		media_format* io_format,
139 		int32* _deprecated_);
140 
141 	status_t GetNextOutput(	/* cookie starts as 0 */
142 		int32* cookie,
143 		media_output* out_output);
144 
145 	status_t DisposeOutputCookie(
146 		int32 cookie);
147 
148 	status_t SetBufferGroup(
149 		const media_source& for_source,
150 		BBufferGroup* group);
151 
152 	status_t GetLatency(
153 		bigtime_t* out_latency);
154 
155 	status_t PrepareToConnect(
156 		const media_source& what,
157 		const media_destination& where,
158 		media_format* format,
159 		media_source* out_source,
160 		char* out_name);
161 
162 	void Connect(
163 		status_t error,
164 		const media_source& source,
165 		const media_destination& destination,
166 		const media_format& format,
167 		char* io_name);
168 
169 	void Disconnect(
170 		const media_source& what,
171 		const media_destination& where);
172 
173 	void LateNoticeReceived(
174 		const media_source& what,
175 		bigtime_t how_much,
176 		bigtime_t performance_time);
177 
178 	void EnableOutput(
179 		const media_source & what,
180 		bool enabled,
181 		int32* _deprecated_);
182 
183 	void LatencyChanged(const media_source & source,
184 						const media_destination & destination,
185 						bigtime_t new_latency, uint32 flags);
186 
187 	// BMediaEventLooper methods
188 
189 		void				HandleEvent( const media_timed_event *event,
190 								bigtime_t lateness,
191 								bool realTimeEvent = false);
192 
193 
194 	private:
195 		BMediaAddOn		*fAddOn;
196 		MixerCore		*fCore;
197 		BParameterWeb	*fWeb; // local pointer to parameterweb
198 		BBufferGroup	*fBufferGroup;
199 		bigtime_t 		fDownstreamLatency;
200 		bigtime_t		fInternalLatency;
201 		bool			fDisableStop;
202 		media_format	fDefaultFormat;
203 };
204 
205 #endif
206