1 /******************************************************************************* 2 / 3 / File: MediaDefs.h 4 / 5 / Description: Basic data types and defines for the Media Kit. 6 / 7 / Copyright 1997-1999, Be Incorporated, All Rights Reserved 8 / 9 *******************************************************************************/ 10 11 #if !defined(_MEDIA_DEFS_H) 12 #define _MEDIA_DEFS_H 13 14 #include <BeBuild.h> 15 #include <SupportDefs.h> 16 #include <OS.h> 17 #include <ByteOrder.h> 18 19 #if defined(__cplusplus) 20 #include <GraphicsDefs.h> 21 #include <Looper.h> 22 #endif 23 24 struct media_node; 25 26 #define B_MEDIA_NAME_LENGTH 64 27 28 29 enum { /* maybe migrate these into Errors.h */ 30 B_MEDIA_SYSTEM_FAILURE = (int)B_MEDIA_ERROR_BASE+0x100, /* 80004100 */ 31 B_MEDIA_BAD_NODE, 32 B_MEDIA_NODE_BUSY, 33 B_MEDIA_BAD_FORMAT, 34 B_MEDIA_BAD_BUFFER, 35 B_MEDIA_TOO_MANY_NODES, 36 B_MEDIA_TOO_MANY_BUFFERS, 37 B_MEDIA_NODE_ALREADY_EXISTS, 38 B_MEDIA_BUFFER_ALREADY_EXISTS, 39 B_MEDIA_CANNOT_SEEK, 40 B_MEDIA_CANNOT_CHANGE_RUN_MODE, 41 B_MEDIA_APP_ALREADY_REGISTERED, 42 B_MEDIA_APP_NOT_REGISTERED, 43 B_MEDIA_CANNOT_RECLAIM_BUFFERS, 44 B_MEDIA_BUFFERS_NOT_RECLAIMED, 45 B_MEDIA_TIME_SOURCE_STOPPED, 46 B_MEDIA_TIME_SOURCE_BUSY, /* 80004110 */ 47 B_MEDIA_BAD_SOURCE, 48 B_MEDIA_BAD_DESTINATION, 49 B_MEDIA_ALREADY_CONNECTED, 50 B_MEDIA_NOT_CONNECTED, 51 B_MEDIA_BAD_CLIP_FORMAT, 52 B_MEDIA_ADDON_FAILED, 53 B_MEDIA_ADDON_DISABLED, 54 B_MEDIA_CHANGE_IN_PROGRESS, 55 B_MEDIA_STALE_CHANGE_COUNT, 56 B_MEDIA_ADDON_RESTRICTED, 57 B_MEDIA_NO_HANDLER, 58 B_MEDIA_DUPLICATE_FORMAT, 59 B_MEDIA_REALTIME_DISABLED, 60 B_MEDIA_REALTIME_UNAVAILABLE 61 }; 62 63 /* Notification message 'what's */ 64 enum { 65 // Note that BMediaNode::node_error also belongs in here! */ 66 B_MEDIA_WILDCARD = 'TRWC', /* used to match any notification in Start/StopWatching */ 67 B_MEDIA_NODE_CREATED = 'TRIA', /* "media_node_id" (multiple items) */ 68 B_MEDIA_NODE_DELETED, /* "media_node_id" (multiple items) */ 69 B_MEDIA_CONNECTION_MADE, /* "output", "input", "format" */ 70 B_MEDIA_CONNECTION_BROKEN, /* "source", "destination" */ 71 B_MEDIA_BUFFER_CREATED, /* "clone_info" -- handled by BMediaRoster */ 72 B_MEDIA_BUFFER_DELETED, /* "media_buffer_id" -- handled by BMediaRoster */ 73 B_MEDIA_TRANSPORT_STATE, /* "state", "location", "realtime" */ 74 B_MEDIA_PARAMETER_CHANGED, /* N "node", "parameter" */ 75 B_MEDIA_FORMAT_CHANGED, /* N "source", "destination", "format" */ 76 B_MEDIA_WEB_CHANGED, /* N "node" */ 77 B_MEDIA_DEFAULT_CHANGED, /* "default", "node" -- handled by BMediaRoster */ 78 B_MEDIA_NEW_PARAMETER_VALUE, /* N "node", "parameter", "when", "value" */ 79 B_MEDIA_NODE_STOPPED, /* N "node", "when" */ 80 B_MEDIA_FLAVORS_CHANGED /* "be:addon_id", "be:new_count", "be:gone_count" */ 81 }; 82 83 enum media_type { 84 B_MEDIA_NO_TYPE = -1, 85 B_MEDIA_UNKNOWN_TYPE = 0, 86 B_MEDIA_RAW_AUDIO = 1, /* uncompressed raw_audio -- linear relationship bytes <-> samples */ 87 B_MEDIA_RAW_VIDEO, /* uncompressed raw_video -- linear relationship bytes <-> pixels */ 88 B_MEDIA_VBL, /* raw data from VBL area, 1600/line */ 89 B_MEDIA_TIMECODE, /* data format TBD */ 90 B_MEDIA_MIDI, 91 B_MEDIA_TEXT, /* typically closed captioning */ 92 B_MEDIA_HTML, 93 B_MEDIA_MULTISTREAM, /* AVI, etc */ 94 B_MEDIA_PARAMETERS, /* BControllable change data */ 95 B_MEDIA_ENCODED_AUDIO, /* dts, AC3, ... */ 96 B_MEDIA_ENCODED_VIDEO, /* Indeo, MPEG, ... */ 97 B_MEDIA_PRIVATE = 90000, /* Don't touch! */ 98 B_MEDIA_FIRST_USER_TYPE = 100000 /* Use something bigger than this for */ 99 /* experimentation with your own media forms */ 100 }; 101 102 enum node_kind { 103 B_BUFFER_PRODUCER = 0x1, 104 B_BUFFER_CONSUMER = 0x2, 105 B_TIME_SOURCE = 0x4, 106 B_CONTROLLABLE = 0x8, 107 B_FILE_INTERFACE = 0x10, 108 B_ENTITY_INTERFACE = 0x20, 109 /* Set these flags for nodes that are suitable as default entities */ 110 B_PHYSICAL_INPUT = 0x10000, 111 B_PHYSICAL_OUTPUT = 0x20000, 112 B_SYSTEM_MIXER = 0x40000 113 }; 114 115 enum video_orientation { /* for orientation, which pixel is first and how do we scan each "line"? */ 116 B_VIDEO_TOP_LEFT_RIGHT = 1, /* This is the typical progressive scan format */ 117 B_VIDEO_BOTTOM_LEFT_RIGHT /* This is how BMP and TGA might scan */ 118 }; 119 120 121 enum media_flags /* data */ 122 { 123 B_MEDIA_FLAGS_VERSION = 1, /* uint32, bigger for newer */ 124 B_MEDIA_FLAGS_PRIVATE = 0x40000000 /* private to Be */ 125 }; 126 127 128 enum media_producer_status { /* for producer status */ 129 B_DATA_NOT_AVAILABLE = 1, 130 B_DATA_AVAILABLE = 2, 131 B_PRODUCER_STOPPED = 3 132 }; 133 134 // realtime flags 135 enum media_realtime_flags { 136 B_MEDIA_REALTIME_ALLOCATOR = 0x1, 137 B_MEDIA_REALTIME_AUDIO = 0x2, 138 B_MEDIA_REALTIME_VIDEO = 0x4, 139 B_MEDIA_REALTIME_ANYKIND = 0xffff 140 }; 141 142 enum media_frame_flags { 143 B_MEDIA_KEY_FRAME = 0x1 144 }; 145 146 #define B_MEDIA_ANY_QUALITY 0.0f 147 #define B_MEDIA_LOW_QUALITY 0.1f 148 #define B_MEDIA_MEDIUM_QUALITY 0.5f 149 #define B_MEDIA_HIGH_QUALITY 1.0f 150 151 152 #if !defined(_MULTI_AUDIO_H) /* #define in protocol header */ 153 enum media_multi_channels { 154 B_CHANNEL_LEFT = 0x1, 155 B_CHANNEL_RIGHT = 0x2, 156 B_CHANNEL_CENTER = 0x4, /* 5.1+ or fake surround */ 157 B_CHANNEL_SUB = 0x8, /* 5.1+ */ 158 B_CHANNEL_REARLEFT = 0x10, /* quad surround or 5.1+ */ 159 B_CHANNEL_REARRIGHT = 0x20, /* quad surround or 5.1+ */ 160 B_CHANNEL_FRONT_LEFT_CENTER = 0x40, 161 B_CHANNEL_FRONT_RIGHT_CENTER = 0x80, 162 B_CHANNEL_BACK_CENTER = 0x100, /* 6.1 or fake surround */ 163 B_CHANNEL_SIDE_LEFT = 0x200, 164 B_CHANNEL_SIDE_RIGHT = 0x400, 165 B_CHANNEL_TOP_CENTER = 0x800, 166 B_CHANNEL_TOP_FRONT_LEFT = 0x1000, 167 B_CHANNEL_TOP_FRONT_CENTER = 0x2000, 168 B_CHANNEL_TOP_FRONT_RIGHT = 0x4000, 169 B_CHANNEL_TOP_BACK_LEFT = 0x8000, 170 B_CHANNEL_TOP_BACK_CENTER = 0x10000, 171 B_CHANNEL_TOP_BACK_RIGHT = 0x20000 172 }; 173 enum media_multi_matrix { 174 B_MATRIX_PROLOGIC_LR = 0x1, 175 B_MATRIX_AMBISONIC_WXYZ = 0x4 176 }; 177 #endif 178 179 180 typedef int32 media_node_id; 181 typedef int32 media_buffer_id; 182 typedef int32 media_addon_id; 183 184 185 #if defined(__cplusplus) 186 struct media_destination { 187 media_destination(port_id, int32); 188 media_destination(const media_destination & clone); 189 media_destination & operator=(const media_destination & clone); 190 media_destination(); 191 ~media_destination(); 192 port_id port; /* can be different from media_node.port */ 193 int32 id; 194 static media_destination null; 195 private: 196 uint32 _reserved_media_destination_[2]; 197 }; 198 199 struct media_source { 200 media_source(port_id, int32); 201 media_source(const media_source & clone); 202 media_source & operator=(const media_source & clone); 203 media_source(); 204 ~media_source(); 205 port_id port; /* must be the same as media_node.port for owner */ 206 int32 id; 207 static media_source null; 208 private: 209 uint32 _reserved_media_source_[2]; 210 }; 211 212 bool operator==(const media_destination & a, const media_destination & b); 213 bool operator!=(const media_destination & a, const media_destination & b); 214 bool operator<(const media_destination & a, const media_destination & b); 215 bool operator==(const media_source & a, const media_source & b); 216 bool operator!=(const media_source & a, const media_source & b); 217 bool operator<(const media_source & a, const media_source & b); 218 bool operator==(const media_node & a, const media_node & b); 219 bool operator!=(const media_node & a, const media_node & b); 220 bool operator<(const media_node & a, const media_node & b); 221 222 223 224 /* Buffers are low-level constructs identified by an ID. */ 225 /* Buffers consist of the actual data area, plus a 64-byte */ 226 /* header area that is different for each type. */ 227 /* Buffers contain typed data. Type is not part of the */ 228 /* buffer header; it's negotiated out-of-bounds by nodes. */ 229 230 enum { 231 B_MEDIA_BIG_ENDIAN = 1, 232 B_MEDIA_LITTLE_ENDIAN = 2, 233 #if B_HOST_IS_BENDIAN 234 B_MEDIA_HOST_ENDIAN = B_MEDIA_BIG_ENDIAN 235 #else 236 B_MEDIA_HOST_ENDIAN = B_MEDIA_LITTLE_ENDIAN 237 #endif 238 }; 239 240 struct media_multi_audio_format; 241 242 struct media_raw_audio_format { 243 enum { // for "format" 244 B_AUDIO_FLOAT = 0x24, // 0 == mid, -1.0 == bottom, 1.0 == top (the preferred format for non-game audio) 245 B_AUDIO_INT = 0x4, // 0 == mid, 0x80000001 == bottom, 0x7fffffff == top (all >16-bit formats, left-adjusted) 246 B_AUDIO_SHORT = 0x2, // 0 == mid, -32767 == bottom, +32767 == top 247 B_AUDIO_UCHAR = 0x11, // 128 == mid, 1 == bottom, 255 == top (discouraged but supported format) 248 B_AUDIO_CHAR = 0x1, // 0 == mid, -127 == bottom, +127 == top (not officially supported format) 249 B_AUDIO_SIZE_MASK = 0xf 250 }; // we guarantee that (format&0xf) == sizeof(sample) for raw formats 251 252 float frame_rate; 253 uint32 channel_count; // 1 or 2, mostly 254 uint32 format; // for compressed formats, go to media_encoded_audio_format 255 uint32 byte_order; // 2 for little endian (B_MEDIA_LITTLE_ENDIAN), 1 for big endian (B_MEDIA_BIG_ENDIAN) 256 size_t buffer_size; // size of each buffer 257 258 static media_multi_audio_format wildcard; 259 }; 260 261 struct media_audio_header { 262 // please put actual data at the end 263 int32 _reserved_[16]; // gotta have something 264 }; 265 266 struct media_multi_audio_info { 267 uint32 channel_mask; // bitmask 268 int16 valid_bits; // if < 32, for B_AUDIO_INT 269 uint16 matrix_mask; // each of these bits may mean more than one channel 270 271 uint32 _reserved_b[3]; 272 }; 273 274 #if defined(__cplusplus) 275 struct media_multi_audio_format : public media_raw_audio_format, public media_multi_audio_info { 276 static media_multi_audio_format wildcard; 277 }; 278 #else 279 struct media_multi_audio_format { 280 media_raw_audio_format raw; 281 media_multi_audio_info multi; 282 }; 283 #endif 284 285 286 struct media_encoded_audio_format { 287 enum audio_encoding { 288 B_ANY 289 }; 290 media_raw_audio_format output; 291 audio_encoding encoding; 292 293 float bit_rate; // BIT rate, not byte rate 294 size_t frame_size; 295 296 media_multi_audio_info multi_info; 297 298 uint32 _reserved_[3]; 299 300 static media_encoded_audio_format wildcard; 301 }; 302 303 struct media_encoded_audio_header { 304 // please put actual data at the end 305 int32 _reserved_0[14]; // gotta have something 306 uint32 buffer_flags; // B_MEDIA_KEY_FRAME for key buffers (ADPCM etc) 307 uchar unused_mask; // mask of unused bits for the last byte of data 308 uchar _reserved_2[3]; 309 310 }; 311 312 enum media_display_flags { 313 B_F1_DOMINANT = 0x1, // The first buffer sent (temporally) will be an F1 field 314 B_F2_DOMINANT = 0x2, // The first buffer sent (temporally) will be an F2 field 315 B_TOP_SCANLINE_F1 = 0x4, // The topmost scanline of the output buffer belongs to F1 316 B_TOP_SCANLINE_F2 = 0x8 // The topmost scanline of the output buffer belongs to F2 317 }; 318 struct media_video_display_info { 319 color_space format; 320 uint32 line_width; 321 uint32 line_count; // total of all interlace fields 322 uint32 bytes_per_row; // bytes_per_row is in format, not header, because it's part of SetBuffers 323 uint32 pixel_offset; // (in pixels) ... These are offsets from the start of the buffer ... 324 uint32 line_offset; // (in lines) ... to the start of the field. Think "buffer == framebuffer" ... 325 // ... when the window displaying the active field moves on screen. 326 uint32 flags; 327 uint32 _reserved_[3]; 328 static media_video_display_info wildcard; 329 }; 330 331 struct media_raw_video_format { 332 float field_rate; 333 uint32 interlace; // how many fields per frame -- 1 means progressive (non-interlaced) 334 uint32 first_active; // 0, typically (wildcard, or "don't care") 335 uint32 last_active; // line_count-1, if first_active is 0. 336 uint32 orientation; // B_VIDEO_TOP_LEFT_RIGHT is preferred 337 // PIXEL aspect ratio; not active area aspect ratio... 338 uint16 pixel_width_aspect; // 1:1 has 1 here, 4:3 has 4 here 339 uint16 pixel_height_aspect; // 1:1 has 1 here, 4:3 has 3 here 340 341 media_video_display_info display; 342 343 static media_raw_video_format wildcard; 344 }; 345 346 struct media_video_header { 347 uint32 _reserved_[12]; // at the top to push used data to the end 348 float field_gamma; 349 uint32 field_sequence; // sequence since start of capture -- may roll over if machine is on for a LONG time 350 uint16 field_number; // 0 .. {interlace-1}; F1 == 0 ("odd"), F2 == 1 ("even") 351 uint16 pulldown_number; // 0..2 for pulldown duplicated sequence 352 uint16 first_active_line; // the NTSC/PAL line number (1-based) of the first line in this field 353 uint16 line_count; // number of active lines in buffer 354 }; 355 356 struct media_encoded_video_format { 357 enum video_encoding { 358 B_ANY 359 }; 360 media_raw_video_format output; // set unknowns to wildcard 361 float avg_bit_rate; 362 float max_bit_rate; 363 video_encoding encoding; 364 size_t frame_size; 365 int16 forward_history; // maximum forward memory required by algorithm 366 int16 backward_history; // maximum backward memory required by algorithm 367 368 uint32 _reserved_[3]; // can't grow more than this 369 370 static media_encoded_video_format wildcard; 371 }; 372 373 struct media_encoded_video_header { 374 /* please put actual data at the end */ 375 int32 _reserved_1[9]; // gotta have something... 376 377 uint32 field_flags; // B_MEDIA_KEY_FRAME 378 379 int16 forward_history; // forward memory required by this buffer (0 for key frames) 380 int16 backward_history; // backward memory required by this buffer (0 for key frames) 381 uchar unused_mask; // mask of unused bits for the last byte of data 382 uchar _reserved_2[3]; 383 float field_gamma; 384 uint32 field_sequence; // sequence since start of capture 385 uint16 field_number; // 0 .. {interlace-1}; F1 == 0, F2 == 1 386 uint16 pulldown_number; // 0..2 for pulldown duplicated sequence 387 uint16 first_active_line; // 0 or 1, typically, but could be 10 or 11 for full-NTSC formats 388 uint16 line_count; // number of actual lines in buffer 389 }; 390 391 struct media_multistream_format { 392 enum { 393 B_ANY = 0, 394 B_VID = 1, // raw raw_video/raw_audio buffers 395 B_AVI, 396 B_MPEG1, 397 B_MPEG2, 398 B_QUICKTIME, 399 B_PRIVATE = 90000, 400 B_FIRST_USER_TYPE = 100000 // user formats >= 100000 401 }; 402 float avg_bit_rate; // 8 * byte rate, on average 403 float max_bit_rate; // 8 * byte rate, tops 404 uint32 avg_chunk_size; // == max_chunk_size for fixed-size chunks 405 uint32 max_chunk_size; // max buffer size 406 enum { 407 B_HEADER_HAS_FLAGS = 0x1, // are flags important? 408 B_CLEAN_BUFFERS = 0x2, // each buffer represents an integral number of "frames" 409 B_HOMOGENOUS_BUFFERS = 0x4 // a buffer has only one format in it 410 }; 411 uint32 flags; 412 int32 format; 413 uint32 _reserved_[2]; 414 415 struct vid_info { 416 float frame_rate; 417 uint16 width; 418 uint16 height; 419 color_space space; 420 421 float sampling_rate; 422 uint32 sample_format; 423 uint16 byte_order; 424 uint16 channel_count; 425 }; 426 struct avi_info { 427 uint32 us_per_frame; 428 uint16 width; 429 uint16 height; 430 uint16 _reserved_; 431 uint16 type_count; 432 media_type types[5]; 433 }; 434 435 union { 436 vid_info vid; 437 avi_info avi; 438 } u; 439 440 static media_multistream_format wildcard; 441 }; 442 443 struct media_multistream_header { 444 uint32 _reserved_[14]; 445 uchar unused_mask; // mask of unused bits for the last byte of data 446 uchar _reserved_2[3]; 447 enum { 448 B_MASTER_HEADER = 0x1, // for master stream header data in buffer 449 B_SUBSTREAM_HEADER = 0x2, // for sub-stream header data in buffer 450 B_COMPLETE_BUFFER = 0x4 // data is an integral number of "frames" 451 }; 452 uint32 flags; 453 }; 454 455 extern const type_code B_CODEC_TYPE_INFO; 456 457 enum media_format_flags { 458 B_MEDIA_RETAINED_DATA = 0x1, 459 B_MEDIA_MULTIPLE_BUFFERS = 0x2, 460 B_MEDIA_CONTIGUOUS_BUFFER = 0x4, 461 B_MEDIA_LINEAR_UPDATES = 0x8, 462 B_MEDIA_MAUI_UNDEFINED_FLAGS = ~0xf /* always deny these */ 463 }; 464 465 /* typically, a field of 0 means "anything" or "wildcard" */ 466 struct media_format { /* no more than 192 bytes */ 467 media_type type; 468 type_code user_data_type; 469 uchar user_data[48]; 470 uint32 _reserved_[3]; 471 uint16 require_flags; // media_format_flags 472 uint16 deny_flags; // media_format_flags 473 474 private: 475 476 void * meta_data; 477 int32 meta_data_size; 478 area_id meta_data_area; 479 area_id __unused_was_use_area; 480 team_id __unused_was_team; 481 void * __unused_was_thisPtr; 482 483 public: 484 485 union { 486 media_multi_audio_format raw_audio; 487 media_raw_video_format raw_video; 488 media_multistream_format multistream; 489 media_encoded_audio_format encoded_audio; 490 media_encoded_video_format encoded_video; 491 char _reserved_[96]; // pad to 96 bytes 492 } u; 493 494 bool IsVideo() const { return (type==B_MEDIA_ENCODED_VIDEO)||(type==B_MEDIA_RAW_VIDEO); }; 495 uint32 Width() const { return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.line_width:u.raw_video.display.line_width; }; 496 uint32 Height() const { return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.line_count:u.raw_video.display.line_count; }; 497 color_space ColorSpace() const { return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.format:u.raw_video.display.format; }; 498 uint32 & Width() { return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.line_width:u.raw_video.display.line_width; }; 499 uint32 & Height() { return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.line_count:u.raw_video.display.line_count; }; 500 color_space & ColorSpace() { return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.format:u.raw_video.display.format; }; 501 502 bool IsAudio() const { return (type==B_MEDIA_ENCODED_AUDIO)||(type==B_MEDIA_RAW_AUDIO); }; 503 uint32 AudioFormat() const { return (type==B_MEDIA_ENCODED_AUDIO)?u.encoded_audio.output.format:u.raw_audio.format; }; 504 uint32 & AudioFormat() { return (type==B_MEDIA_ENCODED_AUDIO)?u.encoded_audio.output.format:u.raw_audio.format; }; 505 uint32 AudioFrameSize() const { return (type==B_MEDIA_ENCODED_AUDIO)?(u.encoded_audio.output.format & 0xf)*u.encoded_audio.output.channel_count:(u.raw_audio.format & 0xf)*u.raw_audio.channel_count; }; 506 507 uint32 Encoding() const { return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.encoding:(type==B_MEDIA_ENCODED_AUDIO)?u.encoded_audio.encoding:(type==B_MEDIA_MULTISTREAM)?u.multistream.format:0UL; } 508 509 bool Matches(const media_format *otherFormat) const; 510 void SpecializeTo(const media_format *otherFormat); 511 512 status_t SetMetaData(const void *data, size_t size); 513 const void * MetaData() const; 514 int32 MetaDataSize() const; 515 516 media_format(); 517 media_format(const media_format &other); 518 ~media_format(); 519 media_format & operator=(const media_format & clone); 520 }; 521 522 bool operator==(const media_raw_audio_format & a, const media_raw_audio_format & b); 523 bool operator==(const media_multi_audio_info & a, const media_multi_audio_info & b); 524 bool operator==(const media_multi_audio_format & a, const media_multi_audio_format & b); 525 bool operator==(const media_encoded_audio_format & a, const media_encoded_audio_format & b); 526 bool operator==(const media_video_display_info & a, const media_video_display_info & b); 527 bool operator==(const media_raw_video_format & a, const media_raw_video_format & b); 528 bool operator==(const media_encoded_video_format & a, const media_encoded_video_format & b); 529 bool operator==(const media_multistream_format::vid_info & a, const media_multistream_format::vid_info & b); 530 bool operator==(const media_multistream_format::avi_info & a, const media_multistream_format::avi_info & b); 531 bool operator==(const media_multistream_format & a, const media_multistream_format & b); 532 bool operator==(const media_format & a, const media_format & b); 533 534 /* return true if a and b are compatible (accounting for wildcards) */ 535 bool format_is_compatible(const media_format & a, const media_format & b); /* a is the format you want to feed to something accepting b */ 536 bool string_for_format(const media_format & f, char * buf, size_t size); 537 538 struct media_seek_tag { 539 char data[16]; 540 }; 541 542 struct media_header_time_code { 543 int8 type; // See TimeCode.h; don't use the "DEFAULT" value 544 int8 _reserved; 545 int8 hours; 546 int8 minutes; 547 int8 seconds; 548 int8 frames; 549 int16 subframes; // -1 if not available 550 }; 551 552 struct media_header { // Broadcast() fills in fields marked with "//+" 553 media_type type; // what kind of data (for union) 554 media_buffer_id buffer; //+ what buffer does this header go with? 555 int32 destination; //+ what 'socket' is this intended for? 556 media_node_id time_source; // node that encoded start_time 557 uint32 _deprecated_; // used to be change_tag 558 uint32 size_used; // size within buffer that is used 559 bigtime_t start_time; // performance time 560 area_id owner; //+ buffer owner info area 561 enum { 562 B_SEEK_TAG = 'TRST', // user data type of the codec seek 563 // protocol. size of seek tag is 16 bytes 564 B_TIME_CODE = 'TRTC' // user data is media_header_time_code 565 }; 566 type_code user_data_type; 567 uchar user_data[64]; // user_data_type indicates what this is 568 uint32 _reserved_[2]; 569 570 off_t file_pos; // where in a file this data came from 571 size_t orig_size; // and how big it was. if unused, zero out 572 573 uint32 data_offset; // offset within buffer (already reflected in Data()) 574 575 union { 576 media_audio_header raw_audio; 577 media_video_header raw_video; 578 media_multistream_header multistream; 579 media_encoded_audio_header encoded_audio; 580 media_encoded_video_header encoded_video; 581 char _reserved_[64]; // pad to 64 bytes 582 } u; 583 }; 584 585 586 struct media_file_format_id { 587 ino_t node; 588 dev_t device; 589 uint32 internal_id; 590 }; 591 bool operator==(const media_file_format_id & a, const media_file_format_id & b); 592 bool operator<(const media_file_format_id & a, const media_file_format_id & b); 593 594 typedef enum { 595 B_ANY_FORMAT_FAMILY = 0, 596 B_BEOS_FORMAT_FAMILY = 1, 597 B_QUICKTIME_FORMAT_FAMILY = 2, /* QuickTime is a registered trademark of Apple Computer */ 598 B_AVI_FORMAT_FAMILY = 3, 599 B_ASF_FORMAT_FAMILY = 4, 600 B_MPEG_FORMAT_FAMILY = 5, 601 B_WAV_FORMAT_FAMILY = 6, 602 B_AIFF_FORMAT_FAMILY = 7, 603 B_AVR_FORMAT_FAMILY = 8, 604 B_MISC_FORMAT_FAMILY = 99999, 605 } media_format_family; 606 607 struct media_file_format { 608 enum { /* flags */ 609 B_READABLE = 0x1, 610 B_WRITABLE = 0x2, 611 B_PERFECTLY_SEEKABLE = 0x4, 612 B_IMPERFECTLY_SEEKABLE = 0x8, 613 B_KNOWS_RAW_VIDEO = 0x10, 614 B_KNOWS_RAW_AUDIO = 0x20, 615 B_KNOWS_MIDI = 0x40, 616 B_KNOWS_ENCODED_VIDEO = 0x80, 617 B_KNOWS_ENCODED_AUDIO = 0x100, 618 B_KNOWS_OTHER = 0x1000000, /* clipping, text, control, ... */ 619 B_KNOWS_ANYTHING = 0x2000000 620 }; 621 uint32 capabilities; // can this format support audio, video, etc 622 media_file_format_id id; // opaque id used to construct a BMediaFile 623 media_format_family family; // one of the family enums 624 int32 version; // 100 for 1.0 625 626 uint32 _reserved_[25]; 627 628 char mime_type[64]; // eg: "video/quicktime", "audio/aiff", etc 629 char pretty_name[64]; // eg: "QuickTime File Format" 630 char short_name[32]; // eg: "quicktime", "avi", "mpeg" 631 char file_extension[8]; // eg: "mov", "avi", "mpg" 632 char reserved[88]; 633 }; 634 635 636 // 637 // Use this function iterate through available file format writers 638 // 639 status_t get_next_file_format(int32 *cookie, media_file_format *mfi); 640 641 642 643 /* This struct is guaranteed to be large enough for any message your service */ 644 /* thread will get for any media_node -- 16k is an upper-bound size limit. */ 645 /* In your thread, read_port() into this struct, and call HandleMessage() on it. */ 646 const size_t B_MEDIA_MESSAGE_SIZE = 16384; 647 648 extern const char * B_MEDIA_SERVER_SIGNATURE; 649 650 class media_node; /* found in MediaNode.h */ 651 struct media_input; 652 struct media_output; 653 struct live_node_info; 654 struct dormant_node_info; 655 struct buffer_clone_info; 656 657 658 // If you for some reason need to get rid of the media_server (and friends) 659 // use these functions, rather than sending messages yourself. 660 // The callback will be called for various stages of the process, with 100 meaning completely done 661 // The callback should always return TRUE for the time being. 662 status_t shutdown_media_server(bigtime_t timeout = B_INFINITE_TIMEOUT, bool (*progress)(int stage, const char * message, void * cookie) = NULL, void * cookie = NULL); 663 status_t launch_media_server(uint32 flags = 0); 664 665 // Given an image_id, prepare that image_id for realtime media 666 // If the kind of media indicated by "flags" is not enabled for real-time, 667 // B_MEDIA_REALTIME_DISABLED is returned. 668 // If there are not enough system resources to enable real-time performance, 669 // B_MEDIA_REALTIME_UNAVAILABLE is returned. 670 status_t media_realtime_init_image(image_id image, uint32 flags); 671 672 // Given a thread ID, and an optional indication of what the thread is 673 // doing in "flags", prepare the thread for real-time media performance. 674 // Currently, this means locking the thread stack, up to size_used bytes, 675 // or all of it if 0 is passed. Typically, you will not be using all 676 // 256 kB of the stack, so you should pass some smaller value you determine 677 // from profiling the thread; typically in the 32-64kB range. 678 // Return values are the same as for media_prepare_realtime_image(). 679 status_t media_realtime_init_thread(thread_id thread, size_t stack_used, uint32 flags); 680 681 // A teeny bit of legacy preserved for BSoundFile from R3. 682 // These came from the old MediaDefs.h; don't use them 683 // unless you get them from BSoundFile. 684 685 /* values for byte_ordering */ 686 enum { B_BIG_ENDIAN, B_LITTLE_ENDIAN }; 687 688 /* values for sample_format */ 689 enum { 690 B_UNDEFINED_SAMPLES, 691 B_LINEAR_SAMPLES, 692 B_FLOAT_SAMPLES, 693 B_MULAW_SAMPLES 694 }; 695 696 697 /* for encoders and file writers */ 698 699 struct media_encode_info { 700 uint32 flags; /* B_MEDIA_KEY_FRAME, set before every use */ 701 int32 used_data_size; /* data size used by other tracks */ 702 /* add output size used by this encoder */ 703 bigtime_t start_time; /* us from start of file */ 704 bigtime_t time_to_encode; /* 0 - hurry up, B_INFINITE_TIMEOUT - don't care */ 705 int32 _pad[22]; 706 void *file_format_data; /* file format specific info */ 707 size_t file_format_data_size; 708 void *codec_data; /* codec specific info */ 709 size_t codec_data_size; 710 711 media_encode_info(); 712 }; 713 714 struct encode_parameters { 715 float quality; // 0.0-1.0 , 1.0 is high quality 716 int32 avg_field_size; // in bytes 717 int32 max_field_size; // in bytes 718 int32 _pad[27]; 719 void *user_data; // codec specific info 720 size_t user_data_size; 721 }; 722 723 struct media_decode_info { 724 bigtime_t time_to_decode; /* 0 - hurry up, B_INFINITE_TIMEOUT - don't care */ 725 int32 _pad[26]; 726 void *file_format_data; /* file format specific info */ 727 size_t file_format_data_size; 728 void *codec_data; /* codec specific info */ 729 size_t codec_data_size; 730 731 media_decode_info(); 732 }; 733 734 735 #endif // __cplusplus 736 737 #endif /* MEDIA_DEFS_H */ 738