1 /* 2 * Copyright 2009, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _MEDIA_DEFS_H 6 #define _MEDIA_DEFS_H 7 8 9 /*! Basic data types and defines for the Media Kit. */ 10 11 12 #include <OS.h> 13 #include <ByteOrder.h> 14 15 #if defined(__cplusplus) 16 # include <GraphicsDefs.h> 17 # include <Looper.h> 18 #endif 19 20 21 struct media_node; 22 23 #define B_MEDIA_NAME_LENGTH 64 24 25 26 /* Notification messages 'what' fields */ 27 enum { 28 /* Note that BMediaNode::node_error also belongs in here! */ 29 B_MEDIA_WILDCARD = 'TRWC', 30 /* Used to match any notification in */ 31 /* Start/StopWatching */ 32 B_MEDIA_NODE_CREATED = 'TRIA', 33 /* "media_node_id" (multiple items) */ 34 B_MEDIA_NODE_DELETED, /* "media_node_id" (multiple items) */ 35 B_MEDIA_CONNECTION_MADE, /* "output", "input", "format" */ 36 B_MEDIA_CONNECTION_BROKEN, /* "source", "destination" */ 37 B_MEDIA_BUFFER_CREATED, /* "clone_info" -- handled by */ 38 /* BMediaRoster */ 39 B_MEDIA_BUFFER_DELETED, /* "media_buffer_id" -- handled by */ 40 /* BMediaRoster */ 41 B_MEDIA_TRANSPORT_STATE, /* "state", "location", "realtime" */ 42 B_MEDIA_PARAMETER_CHANGED, /* N "node", "parameter" */ 43 B_MEDIA_FORMAT_CHANGED, /* N "source", "destination", "format" */ 44 B_MEDIA_WEB_CHANGED, /* N "node" */ 45 B_MEDIA_DEFAULT_CHANGED, /* "default", "node" -- handled by */ 46 /* BMediaRoster */ 47 B_MEDIA_NEW_PARAMETER_VALUE, /* N "node", "parameter", "when", */ 48 /* "value" */ 49 B_MEDIA_NODE_STOPPED, /* N "node", "when" */ 50 B_MEDIA_FLAVORS_CHANGED /* "be:addon_id", "be:new_count", */ 51 /* "be:gone_count" */ 52 }; 53 54 55 enum media_type { 56 B_MEDIA_NO_TYPE = -1, 57 B_MEDIA_UNKNOWN_TYPE = 0, 58 B_MEDIA_RAW_AUDIO = 1, /* uncompressed raw_audio */ 59 B_MEDIA_RAW_VIDEO, /* uncompressed raw_video */ 60 B_MEDIA_VBL, /* raw data from VBL area, 1600/line */ 61 B_MEDIA_TIMECODE, /* data format TBD */ 62 B_MEDIA_MIDI, 63 B_MEDIA_TEXT, /* typically closed captioning */ 64 B_MEDIA_HTML, 65 B_MEDIA_MULTISTREAM, /* AVI, etc */ 66 B_MEDIA_PARAMETERS, /* BControllable change data */ 67 B_MEDIA_ENCODED_AUDIO, /* MP3, AC-3, ... */ 68 B_MEDIA_ENCODED_VIDEO, /* H.264, Theora, ... */ 69 B_MEDIA_PRIVATE = 90000, 70 /* This are reserved. */ 71 B_MEDIA_FIRST_USER_TYPE = 100000 72 /* Use something bigger than this for */ 73 /* experimentation with your own media */ 74 /* formats. */ 75 }; 76 77 78 enum node_kind { 79 B_BUFFER_PRODUCER = 0x1, 80 B_BUFFER_CONSUMER = 0x2, 81 B_TIME_SOURCE = 0x4, 82 B_CONTROLLABLE = 0x8, 83 B_FILE_INTERFACE = 0x10, 84 B_ENTITY_INTERFACE = 0x20, 85 86 /* Set these flags for nodes that are suitable as default system nodes. */ 87 B_PHYSICAL_INPUT = 0x10000, 88 B_PHYSICAL_OUTPUT = 0x20000, 89 B_SYSTEM_MIXER = 0x40000 90 }; 91 92 93 enum video_orientation { 94 /* Which pixel is first and how do we scan each "line"? */ 95 B_VIDEO_TOP_LEFT_RIGHT = 1, /* This is the typical progressive scan */ 96 /* format */ 97 B_VIDEO_BOTTOM_LEFT_RIGHT /* This is how BMP and TGA might scan */ 98 }; 99 100 101 /* data */ 102 enum media_flags 103 { 104 B_MEDIA_FLAGS_VERSION = 1, 105 /* uint32, greater for newer versions */ 106 B_MEDIA_FLAGS_PRIVATE = 0x40000000 107 /* private to Haiku */ 108 }; 109 110 111 /* for producer status */ 112 enum media_producer_status { 113 B_DATA_NOT_AVAILABLE = 1, 114 B_DATA_AVAILABLE = 2, 115 B_PRODUCER_STOPPED = 3 116 }; 117 118 119 /* realtime flags */ 120 enum media_realtime_flags { 121 B_MEDIA_REALTIME_ALLOCATOR = 0x1, 122 B_MEDIA_REALTIME_AUDIO = 0x2, 123 B_MEDIA_REALTIME_VIDEO = 0x4, 124 B_MEDIA_REALTIME_ANYKIND = 0xffff 125 }; 126 127 enum media_frame_flags { 128 B_MEDIA_KEY_FRAME = 0x1 129 }; 130 131 #define B_MEDIA_ANY_QUALITY 0.0f 132 #define B_MEDIA_LOW_QUALITY 0.1f 133 #define B_MEDIA_MEDIUM_QUALITY 0.5f 134 #define B_MEDIA_HIGH_QUALITY 1.0f 135 136 137 #ifndef _MULTI_AUDIO_H /* #define in protocol header */ 138 enum media_multi_channels { 139 B_CHANNEL_LEFT = 0x00001, 140 B_CHANNEL_RIGHT = 0x00002, 141 B_CHANNEL_CENTER = 0x00004, /* 5.1+ or fake surround */ 142 B_CHANNEL_SUB = 0x00008, /* 5.1+ */ 143 B_CHANNEL_REARLEFT = 0x00010, /* quad surround or 5.1+ */ 144 B_CHANNEL_REARRIGHT = 0x00020, /* quad surround or 5.1+ */ 145 B_CHANNEL_FRONT_LEFT_CENTER = 0x00040, 146 B_CHANNEL_FRONT_RIGHT_CENTER = 0x00080, 147 B_CHANNEL_BACK_CENTER = 0x00100, /* 6.1 or fake surround */ 148 B_CHANNEL_SIDE_LEFT = 0x00200, 149 B_CHANNEL_SIDE_RIGHT = 0x00400, 150 B_CHANNEL_TOP_CENTER = 0x00800, 151 B_CHANNEL_TOP_FRONT_LEFT = 0x01000, 152 B_CHANNEL_TOP_FRONT_CENTER = 0x02000, 153 B_CHANNEL_TOP_FRONT_RIGHT = 0x04000, 154 B_CHANNEL_TOP_BACK_LEFT = 0x08000, 155 B_CHANNEL_TOP_BACK_CENTER = 0x10000, 156 B_CHANNEL_TOP_BACK_RIGHT = 0x20000 157 }; 158 159 160 enum media_multi_matrix { 161 B_MATRIX_PROLOGIC_LR = 0x1, 162 B_MATRIX_AMBISONIC_WXYZ = 0x4 163 }; 164 #endif // !_MULTI_AUDIO_H 165 166 167 typedef int32 media_node_id; 168 typedef int32 media_buffer_id; 169 typedef int32 media_addon_id; 170 171 172 #if defined(__cplusplus) 173 struct media_destination { 174 media_destination(); 175 media_destination(port_id, int32); 176 media_destination( 177 const media_destination& other); 178 ~media_destination(); 179 180 media_destination& operator=(const media_destination& other); 181 182 port_id port; /* can be different from */ 183 /* media_node.port */ 184 int32 id; 185 static media_destination null; 186 187 private: 188 uint32 _reserved_media_destination_[2]; 189 }; 190 191 192 struct media_source { 193 media_source(); 194 media_source(port_id, int32); 195 media_source(const media_source& other); 196 ~media_source(); 197 198 media_source& operator=(const media_source& other); 199 port_id port; /* must be the same as */ 200 /* media_node.port for owner */ 201 int32 id; 202 static media_source null; 203 204 private: 205 uint32 _reserved_media_source_[2]; 206 }; 207 208 209 bool operator==(const media_destination& a, const media_destination& b); 210 bool operator!=(const media_destination& a, const media_destination& b); 211 bool operator<(const media_destination& a, const media_destination& b); 212 bool operator==(const media_source& a, const media_source& b); 213 bool operator!=(const media_source& a, const media_source& b); 214 bool operator<(const media_source& a, const media_source& b); 215 bool operator==(const media_node& a, const media_node& b); 216 bool operator!=(const media_node& a, const media_node& b); 217 bool operator<(const media_node& a, const media_node& b); 218 219 220 221 /* Buffers are low-level constructs identified by an ID. */ 222 /* Buffers consist of the actual data area, plus a 64-byte */ 223 /* header area that is different for each type. */ 224 /* Buffers contain typed data. Type is not part of the */ 225 /* buffer header; it's negotiated out-of-bounds by nodes. */ 226 227 enum { 228 B_MEDIA_BIG_ENDIAN = 1, 229 B_MEDIA_LITTLE_ENDIAN = 2, 230 #if B_HOST_IS_BENDIAN 231 B_MEDIA_HOST_ENDIAN = B_MEDIA_BIG_ENDIAN 232 #else 233 B_MEDIA_HOST_ENDIAN = B_MEDIA_LITTLE_ENDIAN 234 #endif 235 }; 236 237 238 struct media_multi_audio_format; 239 240 241 struct media_raw_audio_format { 242 // possible values for "format" 243 enum { 244 B_AUDIO_FLOAT = 0x24, 245 // 0 == mid, -1.0 == bottom, 1.0 == top 246 // (the preferred format for non-game audio) 247 248 B_AUDIO_DOUBLE = 0x28, 249 // 0 == mid, -1.0 == bottom, 1.0 == top 250 // (only useful for pro audio) 251 252 B_AUDIO_INT = 0x4, 253 // 0 == mid, 0x80000001 == bottom, 0x7fffffff == top 254 // (all >16-bit formats, left-adjusted) 255 256 B_AUDIO_SHORT = 0x2, 257 // 0 == mid, -32767 == bottom, +32767 == top 258 259 B_AUDIO_UCHAR = 0x11, 260 // 128 == mid, 1 == bottom, 255 == top 261 // (discouraged but supported format) 262 263 B_AUDIO_CHAR = 0x1, 264 // 0 == mid, -127 == bottom, +127 == top 265 // (not officially supported format) 266 267 B_AUDIO_SIZE_MASK = 0xf 268 // This mask can be used to obtain the sample size 269 // for raw formats: (format & 0xf) == sizeof(sample) 270 }; 271 272 float frame_rate; 273 uint32 channel_count; 274 uint32 format; // see possible values above 275 uint32 byte_order; // B_MEDIA_LITTLE_ENDIAN or B_MEDIA_BIG_ENDIAN 276 size_t buffer_size; // size of each buffer 277 278 static media_multi_audio_format wildcard; 279 }; 280 281 282 struct media_audio_header { 283 // TODO: Define this structure, put actual data at the end 284 int32 _reserved_[16]; 285 }; 286 287 288 struct media_multi_audio_info { 289 uint32 channel_mask; // bitmask 290 int16 valid_bits; // if < 32, for B_AUDIO_INT 291 uint16 matrix_mask; // each of these bits may mean more than one 292 // channel 293 294 uint32 _reserved_b[3]; 295 }; 296 297 298 struct media_multi_audio_format : public media_raw_audio_format, 299 public media_multi_audio_info { 300 301 static media_multi_audio_format wildcard; 302 }; 303 304 305 struct media_encoded_audio_format { 306 enum audio_encoding { 307 B_ANY 308 }; 309 310 media_raw_audio_format output; 311 audio_encoding encoding; 312 313 float bit_rate; 314 size_t frame_size; 315 316 media_multi_audio_info multi_info; 317 318 uint32 _reserved_[3]; 319 320 static media_encoded_audio_format wildcard; 321 }; 322 323 324 struct media_encoded_audio_header { 325 // NOTE: More data fields need to go to the end 326 int32 _reserved_0[14]; 327 328 uint32 buffer_flags; 329 // B_MEDIA_KEY_FRAME for key frame chunks 330 uchar unused_mask; 331 // mask of unused bits for the last byte of data 332 uchar _reserved_2[3]; 333 334 }; 335 336 enum media_display_flags { 337 B_F1_DOMINANT = 0x1, // The first buffer sent (temporally) will 338 // be an F1 field. 339 B_F2_DOMINANT = 0x2, // The first buffer sent (temporally) will 340 // be an F2 field. 341 B_TOP_SCANLINE_F1 = 0x4, // The topmost scanline of the output buffer 342 // belongs to F1. 343 B_TOP_SCANLINE_F2 = 0x8 // The topmost scanline of the output buffer 344 // belongs to F2. 345 }; 346 347 348 struct media_video_display_info { 349 color_space format; 350 uint32 line_width; 351 uint32 line_count; // sum of all interlace fields lines 352 uint32 bytes_per_row; // bytes_per_row is in format, not header, 353 // because it's part of SetBuffers 354 uint32 pixel_offset; // (in pixels) Offset from the start of the 355 // buffer (see below). 356 uint32 line_offset; // (in lines) Offset to the start of the field. 357 // Think "buffer == framebuffer" when the 358 // window displaying the active field moves 359 // on screen. 360 uint32 flags; 361 uint32 _reserved_[3]; 362 363 static media_video_display_info wildcard; 364 }; 365 366 367 struct media_raw_video_format { 368 float field_rate; 369 uint32 interlace; // Number of fields per frame: 1 means 370 // progressive (non-interlaced) frames. 371 uint32 first_active; // Index of first active line. 0, typically 372 // (wildcard, or "don't care") 373 uint32 last_active; // Index of last active line (typically 374 // line_count - 1, if first_active is 0. 375 uint32 orientation; // B_VIDEO_TOP_LEFT_RIGHT is preferred. 376 377 // This is the display aspect ratio (DAR). Usually, you would reduce the 378 // width and height of the intended output frame size as far as possible 379 // without changing their ratio. Note that you should not put 1 in both 380 // fields to mean "undistorted pixels", unless you really intend square 381 // video output! 382 uint16 pixel_width_aspect; // 1:1 has 1 here, 4:3 has 4 here 383 // 16:9 has 16 here! 384 uint16 pixel_height_aspect; // 1:1 has 1 here, 4:3 has 3 here 385 // 16:9 has 9 here! 386 387 media_video_display_info display; 388 389 static media_raw_video_format wildcard; 390 }; 391 392 393 struct media_video_header { 394 uint32 _reserved_[12]; // NOTE: Keep reserved data at the top! 395 396 float field_gamma; 397 uint32 field_sequence; // Sequence number since start of capture 398 // May roll over if machine is on for a 399 // LONG time. 400 uint16 field_number; // 0 .. {interlace-1}; F1 == 0 ("odd"), 401 // F2 == 1 ("even") 402 uint16 pulldown_number; // 0..2 for pulldown duplicated sequence 403 uint16 first_active_line; // The NTSC/PAL line number (1-based) of 404 // the first line in this field 405 uint16 line_count; // The number of active lines in buffer. 406 }; 407 408 409 struct media_encoded_video_format { 410 enum video_encoding { 411 B_ANY 412 }; 413 414 media_raw_video_format output; // set unknowns to wildcard 415 416 float avg_bit_rate; 417 float max_bit_rate; 418 419 video_encoding encoding; 420 size_t frame_size; 421 422 int16 forward_history; // maximum forward memory 423 // required by codec 424 425 int16 backward_history; // maximum backward memory 426 // required by codec 427 428 uint32 _reserved_[3]; // This structure cannot grow 429 // more than this (embedded) 430 // in media_format union 431 432 static media_encoded_video_format wildcard; 433 }; 434 435 436 struct media_encoded_video_header { 437 // NOTE: More data fields need to go at the end of this structure. 438 int32 _reserved_1[9]; 439 440 uint32 field_flags; // B_MEDIA_KEY_FRAME 441 442 int16 forward_history; // forward memory required by this buffer 443 // (0 for key frames) 444 445 int16 backward_history; // backward memory required by this buffer 446 // (0 for key frames) 447 448 uchar unused_mask; // mask of unused bits for the last byte 449 // of data 450 uchar _reserved_2[3]; 451 float field_gamma; 452 uint32 field_sequence; // sequence since start of capture 453 uint16 field_number; // 0 .. {interlace-1}; F1 == 0, F2 == 1 454 uint16 pulldown_number; // 0..2 for pulldown duplicated sequence 455 uint16 first_active_line; // 0 or 1, typically, but could be 10 or 456 // 11 for full-NTSC formats 457 uint16 line_count; // number of actual lines in buffer 458 }; 459 460 struct media_multistream_format { 461 enum { 462 B_ANY = 0, 463 B_VID = 1, // raw raw_video/raw_audio buffers 464 B_AVI, 465 B_MPEG1, 466 B_MPEG2, 467 B_QUICKTIME, 468 B_PRIVATE = 90000, 469 B_FIRST_USER_TYPE = 100000 470 }; 471 float avg_bit_rate; // 8 * byte rate, on average 472 float max_bit_rate; // 8 * byte rate, tops 473 uint32 avg_chunk_size; // == max_chunk_size for fixed-size 474 // chunks 475 uint32 max_chunk_size; // max buffer size 476 enum { 477 B_HEADER_HAS_FLAGS = 0x1, // are flags important? 478 B_CLEAN_BUFFERS = 0x2, // each buffer represents an integral 479 // number of "frames" 480 B_HOMOGENOUS_BUFFERS = 0x4 // a buffer has only one format in it 481 }; 482 uint32 flags; 483 int32 format; 484 uint32 _reserved_[2]; 485 486 struct vid_info { 487 float frame_rate; 488 uint16 width; 489 uint16 height; 490 color_space space; 491 492 float sampling_rate; 493 uint32 sample_format; 494 uint16 byte_order; 495 uint16 channel_count; 496 }; 497 struct avi_info { 498 uint32 us_per_frame; 499 uint16 width; 500 uint16 height; 501 uint16 _reserved_; 502 uint16 type_count; 503 media_type types[5]; 504 }; 505 506 union { 507 vid_info vid; 508 avi_info avi; 509 } u; 510 511 static media_multistream_format wildcard; 512 }; 513 514 515 struct media_multistream_header { 516 uint32 _reserved_[14]; 517 uchar unused_mask; // mask of unused bits for the last byte 518 // of data 519 uchar _reserved_2[3]; 520 enum { 521 B_MASTER_HEADER = 0x1, // for master stream header data in buffer 522 B_SUBSTREAM_HEADER = 0x2, // for sub-stream header data in buffer 523 B_COMPLETE_BUFFER = 0x4 // data is an integral number of "frames" 524 }; 525 uint32 flags; 526 }; 527 528 529 extern const type_code B_CODEC_TYPE_INFO; 530 531 532 enum media_format_flags { 533 B_MEDIA_RETAINED_DATA = 0x1, 534 B_MEDIA_MULTIPLE_BUFFERS = 0x2, 535 B_MEDIA_CONTIGUOUS_BUFFER = 0x4, 536 B_MEDIA_LINEAR_UPDATES = 0x8, 537 B_MEDIA_MAUI_UNDEFINED_FLAGS = ~0xf // NOTE: Always deny these flags 538 // in new code. 539 }; 540 541 // NOTE: A field of 0 typically means "anything" or "wildcard". 542 // NOTE: This structure should not be bigger than 192 bytes! 543 struct media_format { 544 media_type type; 545 type_code user_data_type; 546 uchar user_data[48]; 547 uint32 _reserved_[3]; 548 uint16 require_flags; // media_format_flags 549 uint16 deny_flags; // media_format_flags 550 551 private: 552 void* meta_data; 553 int32 meta_data_size; 554 area_id meta_data_area; 555 area_id __unused_was_use_area; 556 team_id __unused_was_team; 557 void* __unused_was_thisPtr; 558 559 public: 560 union { 561 media_multi_audio_format raw_audio; 562 media_raw_video_format raw_video; 563 media_multistream_format multistream; 564 media_encoded_audio_format encoded_audio; 565 media_encoded_video_format encoded_video; 566 char _reserved_[96]; // pad to 96 bytes 567 } u; 568 569 bool IsVideo() const; 570 571 uint32 Width() const; 572 uint32 Height() const; 573 color_space ColorSpace() const; 574 575 uint32& Width(); 576 uint32& Height(); 577 color_space& ColorSpace(); 578 579 bool IsAudio() const; 580 uint32 AudioFormat() const; 581 uint32& AudioFormat(); 582 uint32 AudioFrameSize() const; 583 584 uint32 Encoding() const; 585 586 bool Matches(const media_format* other) const; 587 void SpecializeTo(const media_format* other); 588 589 status_t SetMetaData(const void* data, size_t size); 590 const void* MetaData() const; 591 int32 MetaDataSize() const; 592 593 media_format(); 594 media_format(const media_format& other); 595 ~media_format(); 596 597 media_format& operator=(const media_format& other); 598 }; 599 600 601 bool operator==(const media_raw_audio_format& a, 602 const media_raw_audio_format& b); 603 604 bool operator==(const media_multi_audio_info& a, 605 const media_multi_audio_info& b); 606 607 bool operator==(const media_multi_audio_format& a, 608 const media_multi_audio_format& b); 609 610 bool operator==(const media_encoded_audio_format& a, 611 const media_encoded_audio_format& b); 612 613 bool operator==(const media_video_display_info& a, 614 const media_video_display_info& b); 615 616 bool operator==(const media_raw_video_format& a, 617 const media_raw_video_format& b); 618 619 bool operator==(const media_encoded_video_format& a, 620 const media_encoded_video_format& b); 621 622 bool operator==(const media_multistream_format::vid_info& a, 623 const media_multistream_format::vid_info& b); 624 625 bool operator==(const media_multistream_format::avi_info& a, 626 const media_multistream_format::avi_info & b); 627 628 bool operator==(const media_multistream_format& a, 629 const media_multistream_format& b); 630 631 bool operator==(const media_format& a, const media_format& b); 632 633 634 bool format_is_compatible(const media_format & a, const media_format & b); 635 // Returns true if a and b are compatible (accounting for wildcards) 636 // (a is the format you want to feed to something accepting b 637 638 bool string_for_format(const media_format & f, char * buf, size_t size); 639 640 641 struct media_seek_tag { 642 char data[16]; 643 }; 644 645 646 struct media_header_time_code { 647 int8 type; // See TimeCode.h; don't use the "DEFAULT" value 648 int8 _reserved; 649 int8 hours; 650 int8 minutes; 651 int8 seconds; 652 int8 frames; 653 int16 subframes; // Set to -1 if not available 654 }; 655 656 657 // Broadcast() fills in fields marked with "//+" 658 struct media_header { 659 media_type type; // what kind of data (for union) 660 media_buffer_id buffer; //+ what buffer does this header go with? 661 int32 destination; //+ what 'socket' is this intended for? 662 media_node_id time_source; // node that encoded start_time 663 uint32 _deprecated_; // used to be change_tag 664 uint32 size_used; // size within buffer that is used 665 bigtime_t start_time; // performance time 666 area_id owner; //+ buffer owner info area 667 enum { 668 B_SEEK_TAG = 'TRST', // user data type of the codec seek 669 // protocol. size of seek tag is 16 bytes 670 B_TIME_CODE = 'TRTC' // user data is media_header_time_code 671 }; 672 type_code user_data_type; 673 uchar user_data[64]; // user_data_type indicates what this is 674 uint32 _reserved_[2]; 675 676 off_t file_pos; // where in a file this data came from 677 size_t orig_size; // and how big it was. if unused, zero out 678 679 uint32 data_offset; // offset within buffer (already reflected in Data()) 680 681 union { 682 media_audio_header raw_audio; 683 media_video_header raw_video; 684 media_multistream_header multistream; 685 media_encoded_audio_header encoded_audio; 686 media_encoded_video_header encoded_video; 687 char _reserved_[64]; // pad to 64 bytes 688 } u; 689 }; 690 691 692 struct media_file_format_id { 693 ino_t node; 694 dev_t device; 695 uint32 internal_id; 696 }; 697 698 699 bool operator==(const media_file_format_id& a, const media_file_format_id& b); 700 bool operator<(const media_file_format_id& a, const media_file_format_id& b); 701 702 703 typedef enum { 704 B_ANY_FORMAT_FAMILY = 0, 705 B_BEOS_FORMAT_FAMILY = 1, 706 B_QUICKTIME_FORMAT_FAMILY = 2, // QuickTime is a registered 707 // trademark of Apple Computer. 708 B_AVI_FORMAT_FAMILY = 3, 709 B_ASF_FORMAT_FAMILY = 4, 710 B_MPEG_FORMAT_FAMILY = 5, 711 B_WAV_FORMAT_FAMILY = 6, 712 B_AIFF_FORMAT_FAMILY = 7, 713 B_AVR_FORMAT_FAMILY = 8, 714 715 B_MISC_FORMAT_FAMILY = 99999, 716 } media_format_family; 717 718 719 struct media_file_format { 720 // Possible flags for capabilities bitmask 721 enum { 722 B_READABLE = 0x1, 723 B_WRITABLE = 0x2, 724 B_PERFECTLY_SEEKABLE = 0x4, 725 B_IMPERFECTLY_SEEKABLE = 0x8, 726 B_KNOWS_RAW_VIDEO = 0x10, 727 B_KNOWS_RAW_AUDIO = 0x20, 728 B_KNOWS_MIDI = 0x40, 729 B_KNOWS_ENCODED_VIDEO = 0x80, 730 B_KNOWS_ENCODED_AUDIO = 0x100, 731 B_KNOWS_OTHER = 0x1000000, // For example sub-title streams 732 B_KNOWS_ANYTHING = 0x2000000 733 }; 734 uint32 capabilities; // Bitmask, see flags above 735 media_file_format_id id; // Opaque id used to construct a 736 // BMediaFile 737 media_format_family family; // One of the family enums 738 int32 version; // 100 for 1.0 739 740 uint32 _reserved_[25]; 741 742 char mime_type[64]; 743 char pretty_name[64]; // "QuickTime File Format" 744 char short_name[32]; // "quicktime", "avi", "mpeg" 745 char file_extension[8]; // "mov", "avi", "mpg" 746 747 char reserved[88]; 748 }; 749 750 751 // Initialize the cookie to 0 and keep calling this function to iterate 752 // over all available media file format writers. 753 status_t get_next_file_format(int32* cookie, media_file_format* mfi); 754 755 756 // A buffer of this size is guaranteed to be large enough to hold any 757 // message, which your service thread can read from read_port() and 758 // passes on to HandleMessage(). 759 const size_t B_MEDIA_MESSAGE_SIZE = 16384; 760 761 762 extern const char* B_MEDIA_SERVER_SIGNATURE; 763 764 class media_node; 765 struct media_input; 766 struct media_output; 767 struct live_node_info; 768 struct dormant_node_info; 769 struct buffer_clone_info; 770 771 772 // Functions which control the shutdown and launching process of the 773 // media_server and it's friends. You can provide a call back hook which 774 // will be called during various steps of the process. This callback should 775 // currently always return TRUE. A 'stage' value of 100 means the process is 776 // completely finished. 777 status_t shutdown_media_server(bigtime_t timeout = B_INFINITE_TIMEOUT, 778 bool (*progress)(int stage, const char* message, void* cookie) = NULL, 779 void* cookie = NULL); 780 status_t launch_media_server(uint32 flags = 0); 781 782 783 // Given an image_id, prepare that image_id for realtime media 784 // If the kind of media indicated by 'flags' is not enabled for real-time, 785 // B_MEDIA_REALTIME_DISABLED is returned. 786 // If there are not enough system resources to enable real-time performance, 787 // B_MEDIA_REALTIME_UNAVAILABLE is returned. 788 status_t media_realtime_init_image(image_id image, uint32 flags); 789 790 791 // Given a thread ID, and an optional indication of what the thread is 792 // doing in "flags", prepare the thread for real-time media performance. 793 // Currently, this means locking the thread stack, up to size_used bytes, 794 // or all of it if 0 is passed. Typically, you will not be using all 795 // 256 kB of the stack, so you should pass some smaller value you determine 796 // from profiling the thread; typically in the 32-64kB range. 797 // Return values are the same as for media_prepare_realtime_image(). 798 status_t media_realtime_init_thread(thread_id thread, size_t stack_used, 799 uint32 flags); 800 801 802 // A teeny bit of legacy preserved for BSoundFile from R3. 803 // These came from the old MediaDefs.h; don't use them 804 // unless you get them from BSoundFile. 805 806 807 // values for byte_ordering 808 enum { 809 B_BIG_ENDIAN, 810 B_LITTLE_ENDIAN 811 }; 812 813 814 // values for sample_format 815 enum { 816 B_UNDEFINED_SAMPLES, 817 B_LINEAR_SAMPLES, 818 B_FLOAT_SAMPLES, 819 B_MULAW_SAMPLES 820 }; 821 822 823 // #pragma mark - encoders and file writers 824 825 826 struct media_encode_info { 827 uint32 flags; // B_MEDIA_KEY_FRAME, set before every 828 // use 829 830 int32 used_data_size; // data size used by other tracks 831 // add output size used by this encoder 832 833 bigtime_t start_time; // us from start of file 834 bigtime_t time_to_encode; // 0 - hurry up, B_INFINITE_TIMEOUT 835 // - don't care 836 int32 _pad[22]; 837 838 void* file_format_data; // file format specific info 839 size_t file_format_data_size; 840 841 void* codec_data; // codec specific info 842 size_t codec_data_size; 843 844 media_encode_info(); 845 }; 846 847 848 struct encode_parameters { 849 float quality; // 0.0-1.0 , 1.0 is high quality 850 851 int32 avg_field_size; // in bytes 852 int32 max_field_size; // in bytes 853 854 int32 _pad[27]; 855 856 void* user_data; // codec specific info 857 size_t user_data_size; 858 }; 859 860 861 struct media_decode_info { 862 bigtime_t time_to_decode; // 0 - hurry up, B_INFINITE_TIMEOUT 863 // - don't care 864 865 int32 _pad[26]; 866 867 void* file_format_data; // file format specific info 868 size_t file_format_data_size; 869 870 void* codec_data; // codec specific info 871 size_t codec_data_size; 872 873 media_decode_info(); 874 }; 875 876 877 // #pragma mark - inline implementations 878 879 880 inline bool 881 media_format::IsVideo() const 882 { 883 return type == B_MEDIA_ENCODED_VIDEO || type == B_MEDIA_RAW_VIDEO; 884 } 885 886 887 inline uint32 888 media_format::Width() const 889 { 890 return type == B_MEDIA_ENCODED_VIDEO 891 ? u.encoded_video.output.display.line_width 892 : u.raw_video.display.line_width; 893 } 894 895 896 inline uint32 897 media_format::Height() const 898 { 899 return type == B_MEDIA_ENCODED_VIDEO 900 ? u.encoded_video.output.display.line_count 901 : u.raw_video.display.line_count; 902 } 903 904 905 inline color_space 906 media_format::ColorSpace() const 907 { 908 return type == B_MEDIA_ENCODED_VIDEO 909 ? u.encoded_video.output.display.format 910 : u.raw_video.display.format; 911 } 912 913 914 inline uint32& 915 media_format::Width() 916 { 917 return type == B_MEDIA_ENCODED_VIDEO 918 ? u.encoded_video.output.display.line_width 919 : u.raw_video.display.line_width; 920 } 921 922 923 inline uint32& 924 media_format::Height() 925 { 926 return type == B_MEDIA_ENCODED_VIDEO 927 ? u.encoded_video.output.display.line_count 928 : u.raw_video.display.line_count; 929 } 930 931 932 inline color_space& 933 media_format::ColorSpace() 934 { 935 return type == B_MEDIA_ENCODED_VIDEO 936 ? u.encoded_video.output.display.format 937 : u.raw_video.display.format; 938 } 939 940 941 inline bool 942 media_format::IsAudio() const 943 { 944 return type == B_MEDIA_ENCODED_AUDIO || type == B_MEDIA_RAW_AUDIO; 945 } 946 947 948 inline uint32 949 media_format::AudioFormat() const 950 { 951 return type == B_MEDIA_ENCODED_AUDIO 952 ? u.encoded_audio.output.format : u.raw_audio.format; 953 } 954 955 956 inline uint32& 957 media_format::AudioFormat() 958 { 959 return type == B_MEDIA_ENCODED_AUDIO 960 ? u.encoded_audio.output.format : u.raw_audio.format; 961 } 962 963 964 inline uint32 965 media_format::AudioFrameSize() const 966 { 967 return type == B_MEDIA_ENCODED_AUDIO 968 ? (u.encoded_audio.output.format 969 & media_raw_audio_format::B_AUDIO_SIZE_MASK) 970 * u.encoded_audio.output.channel_count 971 : (u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK) 972 * u.raw_audio.channel_count; 973 } 974 975 976 inline uint32 977 media_format::Encoding() const 978 { 979 return type == B_MEDIA_ENCODED_VIDEO 980 ? u.encoded_video.encoding : type == B_MEDIA_ENCODED_AUDIO 981 ? u.encoded_audio.encoding : type == B_MEDIA_MULTISTREAM 982 ? u.multistream.format : 0UL; 983 } 984 985 986 #endif /* end of __cplusplus section */ 987 988 989 #endif /* MEDIA_DEFS_H */ 990