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