xref: /haiku/src/kits/media/SoundPlayNode.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 #ifndef _SOUND_PLAY_NODE_
2 #define _SOUND_PLAY_NODE_
3 
4 #include <BufferProducer.h>
5 #include <MediaEventLooper.h>
6 #include <Buffer.h>
7 #include <BufferGroup.h>
8 #include "SoundPlayer.h"
9 
10 /***********************************************************************
11  * AUTHOR: Marcus Overhagen, Jérôme Duval
12  *   FILE: SoundPlayNode.h
13  *  DESCR: This is the BBufferProducer, used internally by BSoundPlayer
14  *         This belongs into a private namespace, but isn't for
15  *         compatibility reasons.
16  ***********************************************************************/
17 
18 class _SoundPlayNode
19 	: public BBufferProducer, public BMediaEventLooper
20 {
21 public:
22 	_SoundPlayNode(const char *name, const media_multi_audio_format *format, BSoundPlayer *player);
23 	~_SoundPlayNode();
24 
25 	bool IsPlaying();
26 	bigtime_t Latency();
27 
28 /*************************/
29 /* begin from BMediaNode */
30 public:
31 virtual	BMediaAddOn* AddOn(
32 				int32 * internal_id) const;	/* Who instantiated you -- or NULL for app class */
33 
34 protected:
35 		/* These don't return errors; instead, they use the global error condition reporter. */
36 		/* A node is required to have a queue of at least one pending command (plus TimeWarp) */
37 		/* and is recommended to allow for at least one pending command of each type. */
38 		/* Allowing an arbitrary number of outstanding commands might be nice, but apps */
39 		/* cannot depend on that happening. */
40 virtual	void Preroll(void);
41 
42 public:
43 virtual	status_t HandleMessage(
44 				int32 message,
45 				const void * data,
46 				size_t size);
47 
48 protected:
49 virtual		void NodeRegistered(void);	/* reserved 2 */
50 virtual		status_t RequestCompleted(const media_request_info &info);
51 virtual		void SetTimeSource(BTimeSource *timeSource);
52 virtual 	void SetRunMode(run_mode mode);
53 
54 /* end from BMediaNode */
55 /***********************/
56 
57 /******************************/
58 /* begin from BBufferProducer */
59 
60 		virtual status_t 	FormatSuggestionRequested(	media_type type,
61 														int32 quality,
62 														media_format* format);
63 
64 		virtual status_t 	FormatProposal(				const media_source& output,
65 														media_format* format);
66 
67 		virtual status_t 	FormatChangeRequested(		const media_source& source,
68 														const media_destination& destination,
69 														media_format* io_format,
70 														int32* _deprecated_);
71 		virtual status_t 	GetNextOutput(				int32* cookie,
72 														media_output* out_output);
73 		virtual status_t 	DisposeOutputCookie(		int32 cookie);
74 
75 		virtual	status_t 	SetBufferGroup(				const media_source& for_source,
76 														BBufferGroup* group);
77 		virtual	status_t 	GetLatency(					bigtime_t * out_latency);
78 
79 		virtual status_t 	PrepareToConnect(			const media_source& what,
80 														const media_destination& where,
81 														media_format* format,
82 														media_source* out_source,
83 														char* out_name);
84 
85 		virtual void 		Connect(					status_t error,
86 														const media_source& source,
87 														const media_destination& destination,
88 														const media_format& format,
89 														char* io_name);
90 
91 		virtual void 		Disconnect(					const media_source& what,
92 														const media_destination& where);
93 
94 		virtual void 		LateNoticeReceived(			const media_source& what,
95 														bigtime_t how_much,
96 														bigtime_t performance_time);
97 
98 		virtual void 		EnableOutput(				const media_source & what,
99 														bool enabled,
100 														int32* _deprecated_);
101 		virtual void 		AdditionalBufferRequested(	const media_source& source,
102 														media_buffer_id prev_buffer,
103 														bigtime_t prev_time,
104 														const media_seek_tag* prev_tag);
105 		virtual void 		LatencyChanged(				const media_source& source,
106 														const media_destination& destination,
107 														bigtime_t new_latency,
108 														uint32 flags);
109 /* end from BBufferProducer */
110 /****************************/
111 
112 /********************************/
113 /* start from BMediaEventLooper */
114 
115 	protected:
116 		/* you must override to handle your events! */
117 		/* you should not call HandleEvent directly */
118 		virtual void		HandleEvent(	const media_timed_event *event,
119 											bigtime_t lateness,
120 											bool realTimeEvent = false);
121 
122 /* end from BMediaEventLooper */
123 /******************************/
124 
125 public:
126 	media_multi_audio_format Format() const;
127 
128 protected:
129 
130 virtual status_t HandleStart(
131 						const media_timed_event *event,
132 						bigtime_t lateness,
133 						bool realTimeEvent = false);
134 virtual status_t HandleSeek(
135 						const media_timed_event *event,
136 						bigtime_t lateness,
137 						bool realTimeEvent = false);
138 virtual status_t HandleWarp(
139 						const media_timed_event *event,
140 						bigtime_t lateness,
141 						bool realTimeEvent = false);
142 virtual status_t HandleStop(
143 						const media_timed_event *event,
144 						bigtime_t lateness,
145 						bool realTimeEvent = false);
146 virtual status_t SendNewBuffer(
147 						const media_timed_event *event,
148 						bigtime_t lateness,
149 						bool realTimeEvent = false);
150 virtual status_t HandleDataStatus(
151 						const media_timed_event *event,
152 						bigtime_t lateness,
153 						bool realTimeEvent = false);
154 virtual status_t HandleParameter(
155 						const media_timed_event *event,
156 						bigtime_t lateness,
157 						bool realTimeEvent = false);
158 
159 	void 				AllocateBuffers();
160 	BBuffer*			FillNextBuffer(bigtime_t event_time);
161 
162 private:
163 	BSoundPlayer 		*mPlayer;
164 
165 	status_t 			mInitCheckStatus;
166 	bool 				mOutputEnabled;
167 	media_output		mOutput;
168 	BBufferGroup		*mBufferGroup;
169 	media_format		mFormat;
170 	bigtime_t 			mLatency;
171 	bigtime_t 			mInternalLatency;
172 	bigtime_t 			mStartTime;
173 	uint64 				mFramesSent;
174 	int32				mTooEarlyCount;
175 };
176 
177 #endif
178