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