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