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