xref: /haiku/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.h (revision f75a7bf508f3156d63a14f8fd77c5e0ca4d08c42)
1 /*	Copyright (c) 1998-99, Be Incorporated, All Rights Reserved.
2  *	Distributed under the terms of the Be Sample Code license.
3  *
4  *	Copyright (c) 2000-2008, Ingo Weinhold <ingo_weinhold@gmx.de>,
5  *	Copyright (c) 2000-2008, Stephan Aßmus <superstippi@gmx.de>,
6  *	All Rights Reserved. Distributed under the terms of the MIT license.
7  */
8 #ifndef AUDIO_PRODUCER_H
9 #define AUDIO_PRODUCER_H
10 
11 #include <BufferProducer.h>
12 //#include <Controllable.h>
13 #include <MediaEventLooper.h>
14 
15 class AudioSupplier;
16 class BHandler;
17 
18 enum {
19 	MSG_PEAK_NOTIFICATION		= 'pknt'
20 };
21 
22 class AudioProducer : public BBufferProducer, public BMediaEventLooper {
23 public:
24 								AudioProducer(const char* name,
25 									AudioSupplier* supplier,
26 									bool lowLatency = true);
27 	virtual						~AudioProducer();
28 
29 	// BMediaNode interface
30 	virtual	BMediaAddOn*		AddOn(int32 *internal_id) const;
31 
32 	// BBufferProducer interface
33 	virtual	status_t			FormatSuggestionRequested(media_type type,
34 									int32 quality, media_format* _format);
35 
36 	virtual	status_t			FormatProposal(const media_source& output,
37 									media_format* format);
38 
39 	virtual	status_t			FormatChangeRequested(
40 									const media_source& source,
41 									const media_destination& destination,
42 									media_format* ioFormat,
43 									int32* _deprecated_);
44 
45 	virtual	status_t			GetNextOutput(int32* cookie,
46 									media_output* _output);
47 
48 	virtual	status_t			DisposeOutputCookie(int32 cookie);
49 
50 	virtual	status_t			SetBufferGroup(const media_source& forSource,
51 									BBufferGroup* group);
52 
53 	virtual	status_t			GetLatency(bigtime_t* _latency);
54 
55 	virtual	status_t			PrepareToConnect(const media_source& what,
56 									const media_destination& where,
57 									media_format* format,
58 									media_source* outSource, char* outName);
59 
60 	virtual	void				Connect(status_t error,
61 									const media_source& source,
62 									const media_destination& destination,
63 									const media_format& format,
64 									char* ioName);
65 
66 	virtual	void				Disconnect(const media_source &what,
67 									const media_destination& where);
68 
69 	virtual	void				LateNoticeReceived(const media_source& what,
70 									bigtime_t howMuch,
71 									bigtime_t performanceTime);
72 
73 	virtual	void				EnableOutput(const media_source& what,
74 									bool enabled, int32* _deprecated_);
75 
76 	virtual	status_t			SetPlayRate(int32 numer, int32 denom);
77 
78 	virtual	status_t			HandleMessage(int32 message,
79 									const void* data, size_t size);
80 
81 	virtual	void				AdditionalBufferRequested(
82 									const media_source& source,
83 									media_buffer_id prevBuffer,
84 									bigtime_t prevTime,
85 									const media_seek_tag* prevTag);
86 										// may be NULL
87 
88 	virtual	void				LatencyChanged(const media_source& source,
89 									const media_destination& destination,
90 									bigtime_t newLatency, uint32 flags);
91 
92 	// BMediaEventLooper interface
93 	virtual	void				NodeRegistered();
94 
95 	virtual	void				SetRunMode(run_mode mode);
96 
97 	virtual	void				HandleEvent(const media_timed_event* event,
98 									bigtime_t lateness,
99 									bool realTimeEvent = false);
100 
101 			void				SetRunning(bool running);
102 
103 	// AudioProducer
104 			void				SetPeakListener(BHandler* handler);
105 
106 private:
107 			status_t			_AllocateBuffers(media_format* format);
108 			BBuffer*			_FillNextBuffer(bigtime_t eventTime);
109 
110 			void				_FillSampleBuffer(float* data,
111 									size_t numSamples);
112 
113 			BBufferGroup*		fBufferGroup;
114 			bool				fUsingOurBuffers;
115 			bigtime_t			fLatency;
116 			bigtime_t			fInternalLatency;
117 			bool				fLowLatency;
118 			media_output		fOutput;
119 			bool				fOutputEnabled;
120 			media_format		fPreferredFormat;
121 
122 			uint64				fFramesSent;
123 			bigtime_t			fStartTime;
124 
125 			AudioSupplier*		fSupplier;
126 	volatile bool				fRunning;
127 
128 			BHandler*			fPeakListener;
129 };
130 
131 #endif // AUDIO_PRODUCER_H
132