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