xref: /haiku/headers/os/media/MediaNode.h (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
1 /*******************************************************************************
2 /
3 /	File:			MediaNode.h
4 /
5 /   Description:  BMediaNode is the indirect base class for all Media Kit participants.
6 /	However, you should use the more specific BBufferConsumer, BBufferProducer
7 /	and others rather than BMediaNode directly. It's OK to multiply inherit.
8 /
9 /	Copyright 1997-98, Be Incorporated, All Rights Reserved
10 /
11 *******************************************************************************/
12 
13 
14 #if !defined(_MEDIA_NODE_H)
15 #define _MEDIA_NODE_H
16 
17 #include <MediaDefs.h>
18 #include <Point.h>
19 
20 #include <new>
21 
22 class BBufferConsumer;
23 class BBufferProducer;
24 class BControllable;
25 class BFileInterface;
26 class BMediaAddOn;
27 class BTimeSource;
28 
29 
30 class media_node {
31 
32 public:
33 
34 	media_node();
35 	~media_node();
36 
37 	media_node_id node;
38 	port_id port;
39 	uint32 kind;
40 
41 static media_node null;
42 
43 private:
44 	uint32 _reserved_[3];
45 };
46 
47 
48 struct media_input {
49 	media_input();
50 	~media_input();
51 	media_node node;
52 	media_source source;
53 	media_destination destination;
54 	media_format format;
55 	char name[B_MEDIA_NAME_LENGTH];
56 private:
57 	uint32 _reserved_media_input_[4];
58 };
59 
60 struct media_output {
61 	media_output();
62 	~media_output();
63 	media_node node;
64 	media_source source;
65 	media_destination destination;
66 	media_format format;
67 	char name[B_MEDIA_NAME_LENGTH];
68 private:
69 	uint32 _reserved_media_output_[4];
70 };
71 
72 struct live_node_info {
73 	live_node_info();
74 	~live_node_info();
75 	media_node node;
76 	BPoint hint_point;
77 	char name[B_MEDIA_NAME_LENGTH];
78 private:
79 	char reserved[160];
80 };
81 
82 
83 struct media_request_info
84 {
85 	enum what_code
86 	{
87 		B_SET_VIDEO_CLIPPING_FOR = 1,
88 		B_REQUEST_FORMAT_CHANGE,
89 		B_SET_OUTPUT_ENABLED,
90 		B_SET_OUTPUT_BUFFERS_FOR,
91 
92 		B_FORMAT_CHANGED = 4097
93 	};
94 	what_code what;
95 	int32 change_tag;
96 	status_t status;
97 	int32 cookie;
98 	void * user_data;
99 	media_source source;
100 	media_destination destination;
101 	media_format format;
102 	uint32 _reserved_[32];
103 };
104 
105 struct media_node_attribute
106 {
107 	enum {
108 		B_R40_COMPILED = 1,		//	has this attribute if compiled using R4.0 headers
109 		B_USER_ATTRIBUTE_NAME = 0x1000000,
110 		B_FIRST_USER_ATTRIBUTE
111 	};
112 	uint32		what;
113 	uint32		flags;			//	per attribute
114 	int64		data;			//	per attribute
115 };
116 
117 
118 namespace BPrivate { namespace media {
119 	class TimeSourceObject;
120 	class SystemTimeSourceObject;
121 	class BMediaRosterEx;
122 } } // BPrivate::media
123 
124 
125 class BMediaNode
126 {
127 protected:
128 		/* this has to be on top rather than bottom to force a vtable in mwcc */
129 virtual	~BMediaNode();	/* should be called through Release() */
130 public:
131 
132 		enum run_mode {
133 			B_OFFLINE = 1,				/* data accurate, no realtime constraint */
134 			B_DECREASE_PRECISION,		/* when slipping, try to catch up */
135 			B_INCREASE_LATENCY,			/* when slipping, increase playout delay */
136 			B_DROP_DATA,				/* when slipping, skip data */
137 			B_RECORDING					/* you're on the receiving end of recording; buffers are guaranteed to be late */
138 		};
139 
140 
141 		BMediaNode * Acquire();	/* return itself */
142 		BMediaNode * Release();	/* release will decrement refcount, and delete if 0 */
143 
144 		const char * Name() const;
145 		media_node_id ID() const;
146 		uint64 Kinds() const;
147 		media_node Node() const;
148 		run_mode RunMode() const;
149 		BTimeSource * TimeSource() const;
150 
151 	/* this port is what a media node listens to for commands */
152 virtual	port_id ControlPort() const;
153 
154 virtual	BMediaAddOn* AddOn(
155 				int32 * internal_id) const = 0;	/* Who instantiated you -- or NULL for app class */
156 
157 	/* These will be sent to anyone watching the MediaRoster. */
158 	/* The message field "be:node_id" will contain the node ID. */
159 		enum node_error {
160 			/* Note that these belong with the notifications in MediaDefs.h! */
161 			/* They are here to provide compiler type checking in ReportError(). */
162 			B_NODE_FAILED_START = 'TRI0',
163 			B_NODE_FAILED_STOP,						// TRI1
164 			B_NODE_FAILED_SEEK,						// TRI2
165 			B_NODE_FAILED_SET_RUN_MODE,				// TRI3
166 			B_NODE_FAILED_TIME_WARP,				// TRI4
167 			B_NODE_FAILED_PREROLL,					// TRI5
168 			B_NODE_FAILED_SET_TIME_SOURCE_FOR,		// TRI6
169 			/* display this node with a blinking exclamation mark or something */
170 			B_NODE_IN_DISTRESS						// TRI7
171 			/* TRIA and up are used in MediaDefs.h */
172 		};
173 
174 protected:
175 
176 		/* Send one of the above codes to anybody who's watching. */
177 		status_t ReportError(
178 				node_error what,
179 				const BMessage * info = NULL);	/* String "message" for instance */
180 
181 		/* When you've handled a stop request, call this function. If anyone is */
182 		/* listening for stop information from you, they will be notified. Especially */
183 		/* important for offline capable Nodes. */
184 		status_t NodeStopped(
185 				bigtime_t whenPerformance);	//	performance time
186 		void TimerExpired(
187 				bigtime_t notifyPoint,		//	performance time
188 				int32 cookie,
189 				status_t error = B_OK);
190 
191 explicit 	BMediaNode(		/* constructor sets refcount to 1 */
192 				const char * name);
193 
194 		status_t WaitForMessage(
195 				bigtime_t waitUntil,
196 				uint32 flags = 0,
197 				void * _reserved_ = 0);
198 
199 		/* These don't return errors; instead, they use the global error condition reporter. */
200 		/* A node is required to have a queue of at least one pending command (plus TimeWarp) */
201 		/* and is recommended to allow for at least one pending command of each type. */
202 		/* Allowing an arbitrary number of outstanding commands might be nice, but apps */
203 		/* cannot depend on that happening. */
204 virtual	void Start(
205 				bigtime_t performance_time);
206 virtual	void Stop(
207 				bigtime_t performance_time,
208 				bool immediate);
209 virtual	void Seek(
210 				bigtime_t media_time,
211 				bigtime_t performance_time);
212 virtual	void SetRunMode(
213 				run_mode mode);
214 virtual	void TimeWarp(
215 				bigtime_t at_real_time,
216 				bigtime_t to_performance_time);
217 virtual	void Preroll();
218 virtual	void SetTimeSource(
219 				BTimeSource * time_source);
220 
221 public:
222 
223 virtual	status_t HandleMessage(
224 				int32 message,
225 				const void * data,
226 				size_t size);
227 		void HandleBadMessage(		/* call this with messages you and your superclasses don't recognize */
228 				int32 code,
229 				const void * buffer,
230 				size_t size);
231 
232 		/* Called from derived system classes; you don't need to */
233 		void AddNodeKind(
234 				uint64 kind);
235 
236 		//	These were not in 4.0.
237 		//	We added them in 4.1 for future use. They just call
238 		//	the default global versions for now.
239 		void * operator new(
240 				size_t size);
241 		void * operator new(
242 				size_t size,
243 				const std::nothrow_t &) throw();
244 		void operator delete(
245 				void * ptr);
246 #if !__MWERKS__
247 		//	there's a bug in MWCC under R4.1 and earlier
248 		void operator delete(
249 				void * ptr,
250 				const std::nothrow_t &) throw();
251 #endif
252 
253 protected:
254 
255 		/* Called when requests have completed, or failed. */
256 virtual	status_t RequestCompleted(	/* reserved 0 */
257 				const media_request_info & info);
258 
259 private:
260 	friend class BTimeSource;
261 	friend class BMediaRoster;
262 	friend class BBufferProducer;	//	for getting _mNodeID
263 	friend class BPrivate::media::TimeSourceObject;
264 	friend class BPrivate::media::SystemTimeSourceObject;
265 	friend class BPrivate::media::BMediaRosterEx;
266 
267 		// Deprecated in 4.1
268 		int32 IncrementChangeTag();
269 		int32 ChangeTag();
270 		int32 MintChangeTag();
271 		status_t ApplyChangeTag(
272 				int32 previously_reserved);
273 
274 		/* Mmmh, stuffing! */
275 protected:
276 
277 virtual		status_t DeleteHook(BMediaNode * node);		/* reserved 1 */
278 
279 virtual		void NodeRegistered();	/* reserved 2 */
280 
281 public:
282 
283 		/* fill out your attributes in the provided array, returning however many you have. */
284 virtual		status_t GetNodeAttributes(	/* reserved 3 */
285 					media_node_attribute * outAttributes,
286 					size_t inMaxCount);
287 
288 virtual		status_t AddTimer(
289 					bigtime_t at_performance_time,
290 					int32 cookie);
291 
292 private:
293 
294 			status_t _Reserved_MediaNode_0(void *);		/* DeleteHook() */
295 			status_t _Reserved_MediaNode_1(void *);		/* RequestCompletionHook() */
296 			status_t _Reserved_MediaNode_2(void *);		/* NodeRegistered() */
297 			status_t _Reserved_MediaNode_3(void *);		/* GetNodeAttributes() */
298 			status_t _Reserved_MediaNode_4(void *);		/* AddTimer() */
299 virtual		status_t _Reserved_MediaNode_5(void *);
300 virtual		status_t _Reserved_MediaNode_6(void *);
301 virtual		status_t _Reserved_MediaNode_7(void *);
302 virtual		status_t _Reserved_MediaNode_8(void *);
303 virtual		status_t _Reserved_MediaNode_9(void *);
304 virtual		status_t _Reserved_MediaNode_10(void *);
305 virtual		status_t _Reserved_MediaNode_11(void *);
306 virtual		status_t _Reserved_MediaNode_12(void *);
307 virtual		status_t _Reserved_MediaNode_13(void *);
308 virtual		status_t _Reserved_MediaNode_14(void *);
309 virtual		status_t _Reserved_MediaNode_15(void *);
310 
311 		BMediaNode();	/* private unimplemented */
312 		BMediaNode(
313 				const BMediaNode & clone);
314 		BMediaNode & operator=(
315 				const BMediaNode & clone);
316 
317 		BMediaNode(		/* constructor sets refcount to 1 */
318 				const char * name,
319 				media_node_id id,
320 				uint32 kinds);
321 
322 		void _InitObject(const char *, media_node_id, uint64);
323 
324 		media_node_id fNodeID;
325 		BTimeSource * fTimeSource;
326 		int32 fRefCount;
327 		char fName[B_MEDIA_NAME_LENGTH];
328 		run_mode fRunMode;
329 		int32 _mChangeCount;			//	deprecated
330 		int32 _mChangeCountReserved;	//	deprecated
331 		uint64 fKinds;
332 		media_node_id fTimeSourceID;
333 
334 		BBufferProducer * fProducerThis;
335 		BBufferConsumer * fConsumerThis;
336 		BFileInterface * fFileInterfaceThis;
337 		BControllable * fControllableThis;
338 		BTimeSource * fTimeSourceThis;
339 
340 		bool _mReservedBool[4];
341 
342 mutable	port_id fControlPort;
343 
344 	uint32 _reserved_media_node_[8];
345 
346 
347 
348 protected:
349 
350 static	int32 NewChangeTag();	//	for use by BBufferConsumer, mostly
351 
352 private:
353 		// dont' rename this one, it's static and needed for binary compatibility
354 static	int32 _m_changeTag;		//	not to be confused with _mChangeCount
355 };
356 
357 
358 
359 #endif /* _MEDIA_NODE_H */
360 
361