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