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