xref: /haiku/headers/os/media/MediaRoster.h (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*******************************************************************************
2 /
3 /	File:			MediaRoster.h
4 /
5 /   Description:   The BMediaRoster is the main application interface to the Media Kit
6 /
7 /	Copyright 1997-98, Be Incorporated, All Rights Reserved
8 /
9 *******************************************************************************/
10 
11 #if !defined(_MEDIA_ROSTER_H)
12 #define _MEDIA_ROSTER_H
13 
14 #include <MediaDefs.h>
15 #include <MediaNode.h>
16 #include <config_manager.h>
17 
18 class BBufferGroup;
19 class BMediaAddOn;
20 class BMimeType;
21 class BParameterWeb;
22 class BString;
23 struct dormant_flavor_info;
24 struct entry_ref;
25 
26 namespace BPrivate { namespace media {
27 	class DefaultDeleter;
28 	class BMediaRosterEx;
29 } } // BPrivate::media
30 
31 class BMediaRoster : public BLooper
32 {
33 public:
34 
35 		status_t GetVideoInput(
36 				media_node * out_node);
37 		status_t GetAudioInput(
38 				media_node * out_node);
39 		status_t GetVideoOutput(
40 				media_node * out_node);
41 		status_t GetAudioMixer(
42 				media_node * out_node);
43 		status_t GetAudioOutput(
44 				media_node * out_node);	/* Use the mixer rather than the output for most needs! */
45 		status_t GetAudioOutput(
46 				media_node * out_node,
47 				int32 * out_input_id,
48 				BString * out_input_name);
49 		status_t GetTimeSource(
50 				media_node * out_node);
51 
52 		status_t SetVideoInput(
53 				const media_node & producer);
54 		status_t SetVideoInput(
55 				const dormant_node_info & producer);
56 		status_t SetAudioInput(
57 				const media_node & producer);
58 		status_t SetAudioInput(
59 				const dormant_node_info & producer);
60 		status_t SetVideoOutput(
61 				const media_node & consumer);
62 		status_t SetVideoOutput(
63 				const dormant_node_info & consumer);
64 		status_t SetAudioOutput(
65 				const media_node & consumer);
66 		status_t SetAudioOutput(
67 				const media_input & input_to_output);
68 		status_t SetAudioOutput(
69 				const dormant_node_info & consumer);
70 
71 		/* Get a media_node from a node ID -- this is how you reference your own nodes! */
72 		status_t GetNodeFor(
73 				media_node_id node,
74 				media_node * clone);
75 		status_t GetSystemTimeSource(	/* typically, you want to use GetTimeSource() */
76 				media_node * clone);
77 		status_t ReleaseNode(	/* might shut down Node if you're last */
78 				const media_node & node);
79 
80 		BTimeSource * MakeTimeSourceFor(	/* Release() the object when done */
81 				const media_node & for_node);
82 
83 		/* note that the media_source and media_destination found in */
84 		/* out_output and out_input are the ones actually used; from and to */
85 		/* are only "hints" that the app should not use once a real connection */
86 		/* has been established */
87 		status_t Connect(
88 				const media_source & from,
89 				const media_destination & to,
90 				media_format * io_format,
91 				media_output * out_output,
92 				media_input * out_input);
93 		enum connect_flags {
94 			B_CONNECT_MUTED = 0x1
95 		};
96 
97 		status_t Connect(
98 				const media_source & from,
99 				const media_destination & to,
100 				media_format * io_format,
101 				media_output * out_output,
102 				media_input * out_input,
103 				uint32 in_flags,
104 				void * _reserved = 0);
105 
106 		status_t Disconnect(
107 				media_node_id source_node,
108 				const media_source & source,
109 				media_node_id destination_node,
110 				const media_destination & destination);
111 
112 		status_t Disconnect( /* Haiku extension, not in R5 */
113 				const media_output &output,
114 				const media_input &input);
115 
116 		status_t StartNode(
117 				const media_node & node,
118 				bigtime_t at_performance_time);
119 		status_t StopNode(
120 				const media_node & node,
121 				bigtime_t at_performance_time,
122 				bool immediate = false);	/* immediate -> at_time is insignificant */
123 		status_t SeekNode(
124 				const media_node & node,
125 				bigtime_t to_media_time,
126 				bigtime_t at_performance_time = 0 /* if running */ );
127 
128 		status_t StartTimeSource(
129 				const media_node & node,
130 				bigtime_t at_real_time);
131 		status_t StopTimeSource(
132 				const media_node & node,
133 				bigtime_t at_real_time,
134 				bool immediate = false);
135 		status_t SeekTimeSource(
136 				const media_node & node,
137 				bigtime_t to_performance_time,
138 				bigtime_t at_real_time);
139 
140 		status_t SyncToNode(
141 				const media_node & node,
142 				bigtime_t at_time,
143 				bigtime_t timeout = B_INFINITE_TIMEOUT);
144 		status_t SetRunModeNode(
145 				const media_node & node,
146 				BMediaNode::run_mode mode);
147 		status_t PrerollNode(	/* synchronous */
148 				const media_node & node);
149 
150 		status_t RollNode(
151 				const media_node & node,
152 				bigtime_t startPerformance,
153 				bigtime_t stopPerformance,
154 				bigtime_t atMediaTime = -B_INFINITE_TIMEOUT);
155 
156 		status_t SetProducerRunModeDelay(	/* should only be used with B_RECORDING */
157 				const media_node & node,
158 				bigtime_t delay,
159 				BMediaNode::run_mode mode = BMediaNode::B_RECORDING);
160 		status_t SetProducerRate(	/* not necessarily supported by node */
161 				const media_node & producer,
162 				int32 numer,
163 				int32 denom);
164 
165 	/* Nodes will have available inputs/outputs as long as they are capable */
166 	/* of accepting more connections. The node may create an additional */
167 	/* output or input as the currently available is taken into usage. */
168 		status_t GetLiveNodeInfo(
169 				const media_node & node,
170 				live_node_info * out_live_info);
171 		status_t GetLiveNodes(
172 				live_node_info * out_live_nodes,
173 				int32 * io_total_count,
174 				const media_format * has_input = NULL,
175 				const media_format * has_output = NULL,
176 				const char * name = NULL,
177 				uint64 node_kinds = 0);	/* B_BUFFER_PRODUCER etc */
178 
179 		status_t GetFreeInputsFor(
180 				const media_node & node,
181 				media_input * out_free_inputs,
182 				int32 buf_num_inputs,
183 				int32 * out_total_count,
184 				media_type filter_type = B_MEDIA_UNKNOWN_TYPE);
185 		status_t GetConnectedInputsFor(
186 				const media_node & node,
187 				media_input * out_active_inputs,
188 				int32 buf_num_inputs,
189 				int32 * out_total_count);
190 		status_t GetAllInputsFor(
191 				const media_node & node,
192 				media_input * out_inputs,
193 				int32 buf_num_inputs,
194 				int32 * out_total_count);
195 		status_t GetFreeOutputsFor(
196 				const media_node & node,
197 				media_output * out_free_outputs,
198 				int32 buf_num_outputs,
199 				int32 * out_total_count,
200 				media_type filter_type = B_MEDIA_UNKNOWN_TYPE);
201 		status_t GetConnectedOutputsFor(
202 				const media_node & node,
203 				media_output * out_active_outputs,
204 				int32 buf_num_outputs,
205 				int32 * out_total_count);
206 		status_t GetAllOutputsFor(
207 				const media_node & node,
208 				media_output * out_outputs,
209 				int32 buf_num_outputs,
210 				int32 * out_total_count);
211 
212 		status_t StartWatching(
213 				const BMessenger & where);
214 		status_t StartWatching(
215 				const BMessenger & where,
216 				int32 notificationType);
217 		status_t StartWatching(
218 				const BMessenger & where,
219 				const media_node & node,
220 				int32 notificationType);
221 		status_t StopWatching(
222 				const BMessenger & where);
223 		status_t StopWatching(
224 				const BMessenger & where,
225 				int32 notificationType);
226 		status_t StopWatching(
227 				const BMessenger & where,
228 				const media_node & node,
229 				int32 notificationType);
230 
231 		status_t RegisterNode(
232 				BMediaNode * node);
233 		status_t UnregisterNode(
234 				BMediaNode * node);
235 
236 static	BMediaRoster * Roster(					//	will create if there isn't one
237 				status_t * out_error = NULL);	//	thread safe for multiple calls to Roster()
238 static	BMediaRoster * CurrentRoster();			//	won't create it if there isn't one
239 												//	not thread safe if you call Roster() at the same time
240 		status_t SetTimeSourceFor(
241 				media_node_id node,
242 				media_node_id time_source);
243 
244 		status_t GetParameterWebFor(
245 				const media_node & node,
246 				BParameterWeb ** out_web);
247 		status_t StartControlPanel(
248 				const media_node & node,
249 				BMessenger * out_messenger = NULL);
250 
251 		status_t GetDormantNodes(
252 				dormant_node_info * out_info,
253 				int32 * io_count,
254 				const media_format * has_input = NULL,
255 				const media_format * has_output = NULL,
256 				const char * name = NULL,
257 				uint64 require_kinds = 0,
258 				uint64 deny_kinds = 0);
259 		status_t InstantiateDormantNode(
260 				const dormant_node_info & in_info,
261 				media_node * out_node,
262 				uint32 flags /* currently B_FLAVOR_IS_GLOBAL or B_FLAVOR_IS_LOCAL */ );
263 		status_t InstantiateDormantNode(
264 				const dormant_node_info & in_info,
265 				media_node * out_node);
266 		status_t GetDormantNodeFor(
267 				const media_node & node,
268 				dormant_node_info * out_info);
269 		status_t GetDormantFlavorInfoFor(
270 				const dormant_node_info & in_dormant,
271 				dormant_flavor_info * out_flavor);
272 
273 		status_t GetLatencyFor(
274 				const media_node & producer,
275 				bigtime_t * out_latency);
276 		status_t GetInitialLatencyFor(
277 				const media_node & producer,
278 				bigtime_t * out_latency,
279 				uint32 * out_flags = 0);
280 		status_t GetStartLatencyFor(
281 				const media_node & time_source,
282 				bigtime_t * out_latency);
283 
284 		status_t GetFileFormatsFor(
285 				const media_node & file_interface,
286 				media_file_format * out_formats,
287 				int32 * io_num_infos);
288 		status_t SetRefFor(
289 				const media_node & file_interface,
290 				const entry_ref & file,
291 				bool create_and_truncate,
292 				bigtime_t * out_length);	/* if create is false */
293 		status_t GetRefFor(
294 				const media_node & node,
295 				entry_ref * out_file,
296 				BMimeType * mime_type = NULL);
297 		status_t SniffRefFor(
298 				const media_node & file_interface,
299 				const entry_ref & file,
300 				BMimeType * mime_type,
301 				float * out_capability);
302 		/* This is the generic "here's a file, now can someone please play it" interface */
303 		status_t SniffRef(
304 				const entry_ref & file,
305 				uint64 require_node_kinds,		/* if you need an EntityInterface or BufferConsumer or something */
306 				dormant_node_info * out_node,
307 				BMimeType * mime_type = NULL);
308 		status_t GetDormantNodeForType(
309 				const BMimeType & type,
310 				uint64 require_node_kinds,
311 				dormant_node_info * out_node);
312 		status_t GetReadFileFormatsFor(
313 				const dormant_node_info & in_node,
314 				media_file_format * out_read_formats,
315 				int32 in_read_count,
316 				int32 * out_read_count);
317 		status_t GetWriteFileFormatsFor(
318 				const dormant_node_info & in_node,
319 				media_file_format * out_write_formats,
320 				int32 in_write_count,
321 				int32 * out_write_count);
322 
323 		status_t GetFormatFor(
324 				const media_output & output,
325 				media_format * io_format,
326 				uint32 flags = 0);
327 		status_t GetFormatFor(
328 				const media_input & input,
329 				media_format * io_format,
330 				uint32 flags = 0);
331 		status_t GetFormatFor(
332 				const media_node & node,
333 				media_format * io_format,
334 				float quality = B_MEDIA_ANY_QUALITY);
335 		ssize_t GetNodeAttributesFor(
336 				const media_node & node,
337 				media_node_attribute * outArray,
338 				size_t inMaxCount);
339 		media_node_id NodeIDFor(
340 				port_id source_or_destination_port);
341 		status_t GetInstancesFor(
342 				media_addon_id addon,
343 				int32 flavor,
344 				media_node_id * out_id,
345 				int32 * io_count = 0);	//	default to 1
346 
347 
348 		status_t SetRealtimeFlags(
349 				uint32 in_enabled);
350 		status_t GetRealtimeFlags(
351 				uint32 * out_enabled);
352 		ssize_t AudioBufferSizeFor(
353 				int32 channel_count,
354 				uint32 sample_format,
355 				float frame_rate,
356 				bus_type bus_kind = B_UNKNOWN_BUS);
357 
358 		/* Use MediaFlags to inquire about specific features of the Media Kit. */
359 		/* Returns < 0 for "not present", positive size for output data size. */
360 		/* 0 means that the capability is present, but no data about it. */
361 static	ssize_t MediaFlags(
362 				media_flags cap,
363 				void * buf,
364 				size_t maxSize);
365 
366 		/* BLooper overrides */
367 virtual		void MessageReceived(
368 				BMessage * message);
369 
370 virtual		bool QuitRequested();
371 
372 virtual		BHandler * ResolveSpecifier(
373 				BMessage *msg,
374 				int32 index,
375 				BMessage *specifier,
376 				int32 form,
377 				const char *property);
378 virtual		status_t GetSupportedSuites(
379 				BMessage *data);
380 
381 			~BMediaRoster();
382 
383 private:
384 
385 		//	deprecated call
386 		status_t SetOutputBuffersFor(
387 				const media_source & output,
388 				BBufferGroup * group,
389 				bool will_reclaim = false);
390 
391 		/* FBC stuffing (Mmmh, Stuffing!) */
392 virtual		status_t _Reserved_MediaRoster_0(void *);
393 virtual		status_t _Reserved_MediaRoster_1(void *);
394 virtual		status_t _Reserved_MediaRoster_2(void *);
395 virtual		status_t _Reserved_MediaRoster_3(void *);
396 virtual		status_t _Reserved_MediaRoster_4(void *);
397 virtual		status_t _Reserved_MediaRoster_5(void *);
398 virtual		status_t _Reserved_MediaRoster_6(void *);
399 virtual		status_t _Reserved_MediaRoster_7(void *);
400 
401 friend class BPrivate::media::DefaultDeleter;
402 friend class BPrivate::media::BMediaRosterEx;
403 
404 static	bool _isMediaServer;
405 
406 		BMediaRoster();
407 
408 static	port_id _mReplyPort;
409 static	int32 _mReplyPortRes;
410 static	int32 _mReplyPortUnavailCount;
411 
412 		uint32 _reserved_media_roster_[67];
413 
414 
415 static	BMediaRoster * _sDefault;
416 
417 static	status_t ParseCommand(
418 				BMessage & reply);
419 
420 		status_t GetDefaultInfo(
421 				media_node_id for_default,
422 				BMessage & out_config);
423 		status_t SetRunningDefault(
424 				media_node_id for_default,
425 				const media_node & node);
426 
427 static	port_id checkout_reply_port(
428 				const char * name = NULL);
429 static	void checkin_reply_port(
430 				port_id port);
431 
432 };
433 
434 
435 #endif /* _MEDIA_ROSTER_H */
436 
437