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