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