xref: /haiku/headers/os/media/MediaRoster.h (revision 893988af824e65e49e55f517b157db8386e8002b)
1 /*
2  * Copyright (c) 2008 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the the MIT licence.
4  *
5  */
6 
7 //! The BMediaRoster is the main API to the Media Kit.
8 
9 #ifndef _MEDIA_ROSTER_H
10 #define _MEDIA_ROSTER_H
11 
12 #include <MediaDefs.h>
13 #include <MediaNode.h>
14 #include <config_manager.h>
15 
16 class BBufferGroup;
17 class BMediaAddOn;
18 class BMimeType;
19 class BParameterWeb;
20 class BString;
21 
22 struct dormant_flavor_info;
23 struct entry_ref;
24 
25 namespace BPrivate { namespace media {
26 	class DefaultDeleter;
27 	class BMediaRosterEx;
28 } } // BPrivate::media
29 
30 
31 class BMediaRoster : public BLooper {
32 public:
33 
34 	// Retrieving the global instance of the BMediaRoster:
35 	static	BMediaRoster*		Roster(status_t* _error = NULL);
36 				// This version will create a roster instance if there isn't
37 				// one already. Thread safe for multiple calls to Roster().
38 
39 	static	BMediaRoster*		CurrentRoster();
40 				// This version won't create an instance if there isn't one
41 				// already. It is not thread safe if you call Roster() at the
42 				// same time.
43 
44 	// Getting common instances of system nodes:
45 			status_t			GetVideoInput(media_node* _node);
46 			status_t			GetAudioInput(media_node* _node);
47 			status_t			GetVideoOutput(media_node* _node);
48 			status_t			GetAudioMixer(media_node* _node);
49 			status_t			GetAudioOutput(media_node* _node);
50 				// The output should not be used directly in common use cases.
51 				// Use the mixer node instead.
52 			status_t			GetAudioOutput(media_node* _node,
53 									int32* _inputId, BString* _inputName);
54 			status_t			GetTimeSource(media_node* _node);
55 
56 	// Setting common system nodes:
57 			status_t			SetVideoInput(const media_node& producer);
58 			status_t			SetVideoInput(
59 									const dormant_node_info& producer);
60 
61 			status_t			SetAudioInput(const media_node& producer);
62 			status_t			SetAudioInput(
63 									const dormant_node_info& producer);
64 
65 			status_t			SetVideoOutput(const media_node& consumer);
66 			status_t			SetVideoOutput(
67 									const dormant_node_info& consumer);
68 
69 			status_t			SetAudioOutput(
70 									const media_node& consumer);
71 			status_t			SetAudioOutput(
72 									const media_input& inputToOutput);
73 			status_t			SetAudioOutput(
74 									const dormant_node_info& consumer);
75 
76 	// Get a media_node from a node ID -- this is how you reference your
77 	// own nodes!
78 			status_t			GetNodeFor(media_node_id node,
79 									media_node* clone);
80 			status_t			GetSystemTimeSource(media_node* clone);
81 				// Typically, you'll want to use GetTimeSource() instead.
82 			status_t			ReleaseNode(const media_node& node);
83 				// This method might free the node if there are no
84 				// more references.
85 			BTimeSource*		MakeTimeSourceFor(const media_node& for_node);
86 				// Release() the returned object when done!
87 
88 			status_t			Connect(const media_source& from,
89 									const media_destination& to,
90 									media_format* _inOutFormat,
91 									media_output* _output,
92 									media_input* _input);
93 				// Note that the media_source and media_destination found in
94 				// _output and _input are the ones actually used. From and to
95 				// are only "hints" that the app should not use once a real
96 				// connection has been established.
97 
98 			enum connect_flags {
99 				B_CONNECT_MUTED = 0x1
100 			};
101 
102 			status_t			Connect(const media_source& from,
103 									const media_destination& to,
104 									media_format* _inOutFormat,
105 									media_output* _output,
106 									media_input* _input,
107 									uint32 flags, void* _reserved = NULL);
108 
109 			status_t			Disconnect(media_node_id sourceNode,
110 									const media_source& source,
111 									media_node_id destinationNode,
112 									const media_destination& destination);
113 
114 
115 			status_t			Disconnect(const media_output& output,
116 									const media_input& input);
117 				// NOTE: This is a Haiku extension.
118 
119 			status_t			StartNode(const media_node& node,
120 									bigtime_t atPerformanceTime);
121 			status_t			StopNode(const media_node& node,
122 									bigtime_t atPerformanceTime,
123 									bool immediate = false);
124 				// If "immediate" is true, "atPerformanceTime" is ignored.
125 			status_t			SeekNode(const media_node& node,
126 									bigtime_t toMediaTime,
127 									bigtime_t atPerformanceTime = 0);
128 				// NOTE: The node needs to be running.
129 
130 			status_t			StartTimeSource(const media_node& node,
131 									bigtime_t atRealTime);
132 			status_t			StopTimeSource(const media_node& node,
133 									bigtime_t atRealTime,
134 									bool immediate = false);
135 			status_t			SeekTimeSource(const media_node& node,
136 									bigtime_t toPerformanceTime,
137 									bigtime_t atRealTime);
138 
139 			status_t			SyncToNode(const media_node& node,
140 									bigtime_t atTime,
141 									bigtime_t timeout = B_INFINITE_TIMEOUT);
142 			status_t			SetRunModeNode(const media_node& node,
143 									BMediaNode::run_mode mode);
144 			status_t			PrerollNode(const media_node& node);
145 				// NOTE: This method is synchronous.
146 			status_t			RollNode(const media_node& node,
147 									bigtime_t startPerformance,
148 									bigtime_t stopPerformance,
149 									bigtime_t atMediaTime
150 										= -B_INFINITE_TIMEOUT);
151 
152 			status_t			SetProducerRunModeDelay(const media_node& node,
153 									bigtime_t delay,
154 									BMediaNode::run_mode mode
155 										= BMediaNode::B_RECORDING);
156 				// NOTE: Should only be used with B_RECORDING
157 			status_t			SetProducerRate(const media_node& producer,
158 									int32 numer, int32 denom);
159 				// NOTE: This feature is not necessarily supported by the node.
160 
161 	// Retrieving information about available inputs/outputs.
162 	// Nodes will have available inputs/outputs as long as they are capable
163 	// of accepting more connections. The node may create an additional
164 	// output or input as the currently available is taken into usage.
165 			status_t			GetLiveNodeInfo(const media_node& node,
166 									live_node_info* _liveInfo);
167 			status_t			GetLiveNodes(live_node_info* _liveNodes,
168 									int32* inOutTotalCount,
169 									const media_format* hasInput = NULL,
170 									const media_format* hasOutput = NULL,
171 									const char* name = NULL,
172 									uint64 nodeKinds = 0);
173 										// B_BUFFER_PRODUCER etc.
174 
175 			status_t			GetFreeInputsFor(const media_node& node,
176 									media_input* _freeInputsBuffer,
177 									int32 bufferCapacity,
178 									int32* _foundCount,
179 									media_type filterType
180 										= B_MEDIA_UNKNOWN_TYPE);
181 			status_t			GetConnectedInputsFor(const media_node& node,
182 									media_input* _activeInputsBuffer,
183 									int32 bufferCapacity,
184 									int32* _foundCount);
185 			status_t			GetAllInputsFor(const media_node& node,
186 									media_input* _inputsBuffer,
187 									int32 bufferCapacity,
188 									int32* _foundCount);
189 			status_t			GetFreeOutputsFor(const media_node& node,
190 									media_output* _freeOutputsBuffer,
191 									int32 bufferCapacity,
192 									int32* _foundCount,
193 									media_type filterType
194 										= B_MEDIA_UNKNOWN_TYPE);
195 			status_t			GetConnectedOutputsFor(const media_node& node,
196 									media_output* _activeOutputsBuffer,
197 									int32 bufferCapacity,
198 									int32* _foundCount);
199 			status_t			GetAllOutputsFor(const media_node& node,
200 									media_output* _outputsBuffer,
201 									int32 bufferCapacity,
202 									int32* _foundCount);
203 
204 	// Event notification support:
205 			status_t			StartWatching(const BMessenger& target);
206 			status_t			StartWatching(const BMessenger& target,
207 									int32 notificationType);
208 			status_t			StartWatching(const BMessenger& target,
209 									const media_node& node,
210 									int32 notificationType);
211 			status_t			StopWatching(const BMessenger& target);
212 			status_t			StopWatching(const BMessenger& target,
213 									int32 notificationType);
214 			status_t			StopWatching(const BMessenger& target,
215 									const media_node& node,
216 									int32 notificationType);
217 
218 			status_t			RegisterNode(BMediaNode* node);
219 			status_t			UnregisterNode(BMediaNode* node);
220 
221 			status_t			SetTimeSourceFor(media_node_id node,
222 									media_node_id timeSource);
223 
224 	// Building a control GUI for a node:
225 			status_t			GetParameterWebFor(const media_node& node,
226 									BParameterWeb** _web);
227 			status_t			StartControlPanel(const media_node& node,
228 									BMessenger* _messenger = NULL);
229 
230 	// Information about nodes which are not running, but could
231 	// be instantiated from add-ons:
232 			status_t			GetDormantNodes(dormant_node_info* _info,
233 									int32* _inOutCount,
234 									const media_format* _hasInput = NULL,
235 									const media_format* _hasOutput = NULL,
236 									const char* name = NULL,
237 									uint64 requireKinds = 0,
238 									uint64 denyKinds = 0);
239 			status_t			InstantiateDormantNode(
240 									const dormant_node_info& info,
241 									media_node* _node,
242 									uint32 flags);
243 				// NOTE: Supported flags are currently B_FLAVOR_IS_GLOBAL
244 				// or B_FLAVOR_IS_LOCAL
245 			status_t			InstantiateDormantNode(
246 									const dormant_node_info& info,
247 									media_node* _node);
248 			status_t			GetDormantNodeFor(const media_node& node,
249 									dormant_node_info* _info);
250 			status_t			GetDormantFlavorInfoFor(
251 									const dormant_node_info& info,
252 									dormant_flavor_info* _flavor);
253 
254 	// Latency information:
255 			status_t			GetLatencyFor(const media_node& producer,
256 									bigtime_t* _latency);
257 			status_t			GetInitialLatencyFor(
258 									const media_node& producer,
259 									bigtime_t* _latency,
260 									uint32* _flags = NULL);
261 			status_t			GetStartLatencyFor(
262 									const media_node& timeSource,
263 									bigtime_t* _latency);
264 
265 	// Finding a suitable node to playback a file:
266 			status_t			GetFileFormatsFor(
267 									const media_node& fileInterface,
268 									media_file_format* _formatsBuffer,
269 									int32* _inOutNumInfos);
270 			status_t			SetRefFor(const media_node& fileInterface,
271 									const entry_ref& file,
272 									bool createAndTruncate,
273 									bigtime_t* _length);
274 										// if create is false
275 			status_t			GetRefFor(const media_node& node,
276 									entry_ref* _ref,
277 									BMimeType* mimeType = NULL);
278 			status_t			SniffRefFor(const media_node& fileInterface,
279 									const entry_ref& ref, BMimeType* _mimeType,
280 									float* _capability);
281 	// This is the generic "here's a file, now can someone please play it"
282 	// interface:
283 			status_t			SniffRef(const entry_ref& ref,
284 									uint64 requireNodeKinds,
285 										// if you need an EntityInterface
286 										// or BufferConsumer or something
287 									dormant_node_info* _node,
288 									BMimeType* _mimeType = NULL);
289 			status_t			GetDormantNodeForType(const BMimeType& type,
290 									uint64 requireNodeKinds,
291 									dormant_node_info* _info);
292 			status_t			GetReadFileFormatsFor(
293 									const dormant_node_info& node,
294 									media_file_format* _readFormatsBuffer,
295 									int32 bufferCapacity, int32* _foundCount);
296 			status_t			GetWriteFileFormatsFor(
297 									const dormant_node_info& node,
298 									media_file_format* _writeFormatsBuffer,
299 									int32 bufferCapacity, int32* _foundCount);
300 
301 			status_t			GetFormatFor(const media_output& output,
302 									media_format* _inOutFormat,
303 									uint32 flags = 0);
304 			status_t			GetFormatFor(const media_input& input,
305 									media_format* _inOutFormat,
306 									uint32 flags = 0);
307 			status_t			GetFormatFor(const media_node& node,
308 									media_format* _inOutFormat,
309 									float quality = B_MEDIA_ANY_QUALITY);
310 			ssize_t				GetNodeAttributesFor(const media_node& node,
311 									media_node_attribute* outArray,
312 									size_t inMaxCount);
313 			media_node_id		NodeIDFor(port_id sourceOrDestinationPort);
314 			status_t			GetInstancesFor(media_addon_id addon,
315 									int32 flavor,media_node_id* _id,
316 									int32* _inOutCount = NULL);
317 										// _inOutCount defaults to 1
318 										// if unspecified (NULL).
319 
320 	// General MediaKit configuration:
321 			status_t			SetRealtimeFlags(uint32 enabledFlags);
322 			status_t			GetRealtimeFlags(uint32* _enabledFlags);
323 			ssize_t				AudioBufferSizeFor(int32 channelCount,
324 									uint32 sampleFormat, float frameRate,
325 									bus_type busType = B_UNKNOWN_BUS);
326 
327 	// Use MediaFlags to inquire about specific features of the Media Kit.
328 	// Returns < 0 for "not present", positive size for output data size.
329 	// 0 means that the capability is present, but no data about it.
330 	static	ssize_t				MediaFlags(media_flags cap, void* buffer,
331 									size_t maxSize);
332 
333 	// BLooper overrides
334 	virtual	void				MessageReceived(BMessage* message);
335 	virtual	bool				QuitRequested();
336 
337 	virtual	BHandler*			ResolveSpecifier(BMessage* message,
338 									int32 index, BMessage* specifier,
339 									int32 form, const char* property);
340 	virtual	status_t			GetSupportedSuites(BMessage* data);
341 
342 	virtual						~BMediaRoster();
343 
344 private:
345 	// This method is deprecated:
346 			status_t			SetOutputBuffersFor(const media_source& output,
347 									BBufferGroup* group,
348 									bool willReclaim = false);
349 
350 	// Reserving virtual function slots.
351 	virtual	status_t			_Reserved_MediaRoster_0(void*);
352 	virtual	status_t			_Reserved_MediaRoster_1(void*);
353 	virtual	status_t			_Reserved_MediaRoster_2(void*);
354 	virtual	status_t			_Reserved_MediaRoster_3(void*);
355 	virtual	status_t			_Reserved_MediaRoster_4(void*);
356 	virtual	status_t			_Reserved_MediaRoster_5(void*);
357 	virtual	status_t			_Reserved_MediaRoster_6(void*);
358 	virtual	status_t			_Reserved_MediaRoster_7(void*);
359 
360 	friend class BPrivate::media::DefaultDeleter;
361 	friend class BPrivate::media::BMediaRosterEx;
362 
363 	// Constructor is private, since you are supposed to use
364 	// Roster() or CurrentRoster().
365 								BMediaRoster();
366 
367 	// TODO: Looks like these can be safely removed:
368 	static	status_t			ParseCommand(BMessage& reply);
369 
370 			status_t			GetDefaultInfo(media_node_id forDefault,
371 									BMessage& _config);
372 			status_t			SetRunningDefault(media_node_id forDefault,
373 									const media_node& node);
374 
375 private:
376 			uint32				_reserved_media_roster_[67];
377 
378 	static	BMediaRoster*		sDefaultInstance;
379 };
380 
381 
382 #endif // _MEDIA_ROSTER_H
383 
384