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