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 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 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 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 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 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 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 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 media_format(); 608 media_format(const media_format& other); 609 ~media_format(); 610 611 media_format& operator=(const media_format& other); 612 }; 613 614 615 bool operator==(const media_raw_audio_format& a, 616 const media_raw_audio_format& b); 617 618 bool operator==(const media_multi_audio_info& a, 619 const media_multi_audio_info& b); 620 621 bool operator==(const media_multi_audio_format& a, 622 const media_multi_audio_format& b); 623 624 bool operator==(const media_encoded_audio_format& a, 625 const media_encoded_audio_format& b); 626 627 bool operator==(const media_video_display_info& a, 628 const media_video_display_info& b); 629 630 bool operator==(const media_raw_video_format& a, 631 const media_raw_video_format& b); 632 633 bool operator==(const media_encoded_video_format& a, 634 const media_encoded_video_format& b); 635 636 bool operator==(const media_multistream_format::vid_info& a, 637 const media_multistream_format::vid_info& b); 638 639 bool operator==(const media_multistream_format::avi_info& a, 640 const media_multistream_format::avi_info & b); 641 642 bool operator==(const media_multistream_format& a, 643 const media_multistream_format& b); 644 645 bool operator==(const media_format& a, const media_format& b); 646 647 648 bool format_is_compatible(const media_format & a, const media_format & b); 649 // Returns true if a and b are compatible (accounting for wildcards) 650 // (a is the format you want to feed to something accepting b 651 652 bool string_for_format(const media_format & f, char * buf, size_t size); 653 654 655 struct media_seek_tag { 656 char data[16]; 657 }; 658 659 660 struct media_header_time_code { 661 int8 type; // See TimeCode.h; don't use the "DEFAULT" value 662 int8 _reserved; 663 int8 hours; 664 int8 minutes; 665 int8 seconds; 666 int8 frames; 667 int16 subframes; // Set to -1 if not available 668 }; 669 670 671 // Broadcast() fills in fields marked with "//+" 672 struct media_header { 673 media_type type; // what kind of data (for union) 674 media_buffer_id buffer; //+ what buffer does this header go with? 675 int32 destination; //+ what 'socket' is this intended for? 676 media_node_id time_source; // node that encoded start_time 677 uint32 _deprecated_; // used to be change_tag 678 uint32 size_used; // size within buffer that is used 679 bigtime_t start_time; // performance time 680 area_id owner; //+ buffer owner info area 681 enum { 682 B_SEEK_TAG = 'TRST', // user data type of the codec seek 683 // protocol. size of seek tag is 16 bytes 684 B_TIME_CODE = 'TRTC' // user data is media_header_time_code 685 }; 686 type_code user_data_type; 687 uchar user_data[64]; // user_data_type indicates what this is 688 int32 source; 689 port_id source_port; 690 691 off_t file_pos; // where in a file this data came from 692 size_t orig_size; // and how big it was. if unused, zero out 693 694 uint32 data_offset; // offset within buffer (already reflected in Data()) 695 696 union { 697 media_audio_header raw_audio; 698 media_video_header raw_video; 699 media_multistream_header multistream; 700 media_encoded_audio_header encoded_audio; 701 media_encoded_video_header encoded_video; 702 char _reserved_[64]; // pad to 64 bytes 703 } u; 704 }; 705 706 707 struct media_file_format_id { 708 ino_t node; 709 dev_t device; 710 uint32 internal_id; 711 }; 712 713 714 bool operator==(const media_file_format_id& a, const media_file_format_id& b); 715 bool operator<(const media_file_format_id& a, const media_file_format_id& b); 716 717 718 typedef enum { 719 B_ANY_FORMAT_FAMILY = 0, 720 B_BEOS_FORMAT_FAMILY = 1, 721 B_QUICKTIME_FORMAT_FAMILY = 2, // QuickTime is a registered 722 // trademark of Apple Computer. 723 B_AVI_FORMAT_FAMILY = 3, 724 B_ASF_FORMAT_FAMILY = 4, 725 B_MPEG_FORMAT_FAMILY = 5, 726 B_WAV_FORMAT_FAMILY = 6, 727 B_AIFF_FORMAT_FAMILY = 7, 728 B_AVR_FORMAT_FAMILY = 8, 729 730 B_MISC_FORMAT_FAMILY = 99999, 731 } media_format_family; 732 733 734 struct media_file_format { 735 // Possible flags for capabilities bitmask 736 enum { 737 B_READABLE = 0x1, 738 B_WRITABLE = 0x2, 739 B_PERFECTLY_SEEKABLE = 0x4, 740 B_IMPERFECTLY_SEEKABLE = 0x8, 741 B_KNOWS_RAW_VIDEO = 0x10, 742 B_KNOWS_RAW_AUDIO = 0x20, 743 B_KNOWS_MIDI = 0x40, 744 B_KNOWS_ENCODED_VIDEO = 0x80, 745 B_KNOWS_ENCODED_AUDIO = 0x100, 746 B_KNOWS_OTHER = 0x1000000, // For example sub-title streams 747 B_KNOWS_ANYTHING = 0x2000000 748 }; 749 uint32 capabilities; // Bitmask, see flags above 750 media_file_format_id id; // Opaque id used to construct a 751 // BMediaFile 752 media_format_family family; // One of the family enums 753 int32 version; // 100 for 1.0 754 755 uint32 _reserved_[25]; 756 757 char mime_type[64]; 758 char pretty_name[64]; // "QuickTime File Format" 759 char short_name[32]; // "quicktime", "avi", "mpeg" 760 char file_extension[8]; // "mov", "avi", "mpg" 761 762 char reserved[88]; 763 }; 764 765 766 // Initialize the cookie to 0 and keep calling this function to iterate 767 // over all available media file format writers. 768 status_t get_next_file_format(int32* cookie, media_file_format* mfi); 769 770 771 // A buffer of this size is guaranteed to be large enough to hold any 772 // message, which your service thread can read from read_port() and 773 // passes on to HandleMessage(). 774 const size_t B_MEDIA_MESSAGE_SIZE = 16384; 775 776 777 extern const char* B_MEDIA_SERVER_SIGNATURE; 778 779 class media_node; 780 struct media_input; 781 struct media_output; 782 struct live_node_info; 783 struct dormant_node_info; 784 struct buffer_clone_info; 785 786 787 // Functions which control the shutdown and launching process of the 788 // media_server and it's friends. You can provide a call back hook which 789 // will be called during various steps of the process. This callback should 790 // currently always return TRUE. A 'stage' value of 100 means the process is 791 // completely finished. Differently from BeOS the functions automatically 792 // send notifications to the Deskbar if not differently specified. 793 // It's also provided a new version of launch_media_server allowing 794 // to specify a custom callback for notifications. 795 796 status_t launch_media_server(bigtime_t timeout = B_INFINITE_TIMEOUT, 797 bool (*progress)(int stage, const char* message, void* cookie) = NULL, 798 void* cookie = NULL, uint32 flags = 0); 799 800 status_t shutdown_media_server(bigtime_t timeout = B_INFINITE_TIMEOUT, 801 bool (*progress)(int stage, const char* message, void* cookie) = NULL, 802 void* cookie = NULL); 803 804 805 // A teeny bit of legacy preserved for BSoundFile from R3. 806 // These came from the old MediaDefs.h; don't use them 807 // unless you get them from BSoundFile. 808 809 810 // values for byte_ordering 811 enum { 812 B_BIG_ENDIAN, 813 B_LITTLE_ENDIAN 814 }; 815 816 817 // values for sample_format 818 enum { 819 B_UNDEFINED_SAMPLES, 820 B_LINEAR_SAMPLES, 821 B_FLOAT_SAMPLES, 822 B_MULAW_SAMPLES 823 }; 824 825 826 // #pragma mark - encoders and file writers 827 828 829 struct media_encode_info { 830 uint32 flags; // B_MEDIA_KEY_FRAME, set before every 831 // use 832 833 int32 used_data_size; // data size used by other tracks 834 // add output size used by this encoder 835 836 bigtime_t start_time; // us from start of file 837 bigtime_t time_to_encode; // 0 - hurry up, B_INFINITE_TIMEOUT 838 // - don't care 839 int32 _pad[22]; 840 841 void* file_format_data; // file format specific info 842 size_t file_format_data_size; 843 844 void* codec_data; // codec specific info 845 size_t codec_data_size; 846 847 media_encode_info(); 848 }; 849 850 851 struct encode_parameters { 852 float quality; // 0.0-1.0 , 1.0 is high quality 853 854 int32 avg_field_size; // in bytes 855 int32 max_field_size; // in bytes 856 857 int32 _pad[27]; 858 859 void* user_data; // codec specific info 860 size_t user_data_size; 861 }; 862 863 864 struct media_decode_info { 865 bigtime_t time_to_decode; // 0 - hurry up, B_INFINITE_TIMEOUT 866 // - don't care 867 868 int32 _pad[26]; 869 870 void* file_format_data; // file format specific info 871 size_t file_format_data_size; 872 873 void* codec_data; // codec specific info 874 size_t codec_data_size; 875 876 media_decode_info(); 877 }; 878 879 880 // #pragma mark - inline implementations 881 882 883 inline bool 884 media_format::IsVideo() const 885 { 886 return type == B_MEDIA_ENCODED_VIDEO || type == B_MEDIA_RAW_VIDEO; 887 } 888 889 890 inline uint32 891 media_format::Width() const 892 { 893 return type == B_MEDIA_ENCODED_VIDEO 894 ? u.encoded_video.output.display.line_width 895 : u.raw_video.display.line_width; 896 } 897 898 899 inline uint32 900 media_format::Height() const 901 { 902 return type == B_MEDIA_ENCODED_VIDEO 903 ? u.encoded_video.output.display.line_count 904 : u.raw_video.display.line_count; 905 } 906 907 908 inline color_space 909 media_format::ColorSpace() const 910 { 911 return type == B_MEDIA_ENCODED_VIDEO 912 ? u.encoded_video.output.display.format 913 : u.raw_video.display.format; 914 } 915 916 917 inline uint32& 918 media_format::Width() 919 { 920 return type == B_MEDIA_ENCODED_VIDEO 921 ? u.encoded_video.output.display.line_width 922 : u.raw_video.display.line_width; 923 } 924 925 926 inline uint32& 927 media_format::Height() 928 { 929 return type == B_MEDIA_ENCODED_VIDEO 930 ? u.encoded_video.output.display.line_count 931 : u.raw_video.display.line_count; 932 } 933 934 935 inline color_space& 936 media_format::ColorSpace() 937 { 938 return type == B_MEDIA_ENCODED_VIDEO 939 ? u.encoded_video.output.display.format 940 : u.raw_video.display.format; 941 } 942 943 944 inline bool 945 media_format::IsAudio() const 946 { 947 return type == B_MEDIA_ENCODED_AUDIO || type == B_MEDIA_RAW_AUDIO; 948 } 949 950 951 inline uint32 952 media_format::AudioFormat() const 953 { 954 return type == B_MEDIA_ENCODED_AUDIO 955 ? u.encoded_audio.output.format : u.raw_audio.format; 956 } 957 958 959 inline uint32& 960 media_format::AudioFormat() 961 { 962 return type == B_MEDIA_ENCODED_AUDIO 963 ? u.encoded_audio.output.format : u.raw_audio.format; 964 } 965 966 967 inline uint32 968 media_format::AudioFrameSize() const 969 { 970 return type == B_MEDIA_ENCODED_AUDIO 971 ? (u.encoded_audio.output.format 972 & media_raw_audio_format::B_AUDIO_SIZE_MASK) 973 * u.encoded_audio.output.channel_count 974 : (u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK) 975 * u.raw_audio.channel_count; 976 } 977 978 979 inline uint32 980 media_format::Encoding() const 981 { 982 return type == B_MEDIA_ENCODED_VIDEO 983 ? u.encoded_video.encoding : type == B_MEDIA_ENCODED_AUDIO 984 ? u.encoded_audio.encoding : type == B_MEDIA_MULTISTREAM 985 ? u.multistream.format : 0UL; 986 } 987 988 989 #endif /* end of __cplusplus section */ 990 991 992 #endif /* MEDIA_DEFS_H */ 993