1 // MediaString.cpp 2 3 #include "MediaString.h" 4 5 // Media Kit 6 #include <MediaFormats.h> 7 // Support Kit 8 #include <String.h> 9 10 __USE_CORTEX_NAMESPACE 11 12 #include <Debug.h> 13 #define D_METHOD(x) //PRINT (x) 14 15 // -------------------------------------------------------- // 16 // *** media_node strings (public) 17 // -------------------------------------------------------- // 18 19 BString MediaString::getStringFor( 20 node_kind kinds, 21 bool complete) { 22 D_METHOD(("MediaString::getStringFor(node_kind)\n")); 23 24 BString list, last; 25 bool first = true; 26 27 if (kinds & B_BUFFER_PRODUCER) { 28 if (first) { 29 list = "Buffer producer"; 30 first = false; 31 } 32 } 33 if (kinds & B_BUFFER_CONSUMER) { 34 if (first) { 35 list = "Buffer consumer"; 36 first = false; 37 } 38 else { 39 if (last != "") 40 list << ", " << last; 41 last = "Buffer consumer"; 42 } 43 } 44 if (kinds & B_TIME_SOURCE) { 45 if (first) { 46 list = "Time source"; 47 first = false; 48 } 49 else { 50 if (last != "") 51 list << ", " << last; 52 last = "Time source"; 53 } 54 } 55 if (kinds & B_CONTROLLABLE) { 56 if (first) { 57 list = "Controllable"; 58 first = false; 59 } 60 else { 61 if (last != "") 62 list << ", " << last; 63 last = "Controllable"; 64 } 65 } 66 if (kinds & B_FILE_INTERFACE) { 67 if (first) { 68 list = "File interface"; 69 first = false; 70 } 71 else { 72 if (last != "") 73 list << ", " << last; 74 last = "File interface"; 75 } 76 } 77 if (kinds & B_ENTITY_INTERFACE) { 78 if (first) { 79 list = "Entity interface"; 80 first = false; 81 } 82 else { 83 if (last != "") 84 list << ", " << last; 85 last = "Entity interface"; 86 } 87 } 88 if (kinds & B_PHYSICAL_INPUT) { 89 if (first) { 90 list = "Physical input"; 91 first = false; 92 } 93 else { 94 if (last != "") 95 list << ", " << last; 96 last = "Physical input"; 97 } 98 } 99 if (kinds & B_PHYSICAL_OUTPUT) { 100 if (first) { 101 list = "Physical output"; 102 first = false; 103 } 104 else { 105 if (last != "") 106 list << ", " << last; 107 last = "Physical output"; 108 } 109 } 110 if (kinds & B_SYSTEM_MIXER) { 111 if (first) { 112 list = "System mixer"; 113 first = false; 114 } 115 else { 116 if (last != "") 117 list << ", " << last; 118 last = "System mixer"; 119 } 120 } 121 122 if (last != "") 123 list << " & " << last; 124 return list; 125 } 126 127 BString MediaString::getStringFor( 128 BMediaNode::run_mode runMode, 129 bool complete) 130 { 131 D_METHOD(("MediaString::getStringFor(run_mode)\n")); 132 133 switch (runMode) { 134 case BMediaNode::B_OFFLINE: return "Offline"; 135 case BMediaNode::B_RECORDING: return "Recording"; 136 case BMediaNode::B_DECREASE_PRECISION: return "Decrease precision"; 137 case BMediaNode::B_INCREASE_LATENCY: return "Increase latency"; 138 case BMediaNode::B_DROP_DATA: return "Drop data"; 139 default: return "(unknown run mode)"; 140 } 141 } 142 143 // -------------------------------------------------------- // 144 // *** media_format strings (public) 145 // -------------------------------------------------------- // 146 147 BString MediaString::getStringFor( 148 media_type type, 149 bool complete) { 150 D_METHOD(("MediaString::getStringFor(media_type)\n")); 151 152 switch (type) { 153 case B_MEDIA_NO_TYPE: return "Typeless media"; 154 case B_MEDIA_UNKNOWN_TYPE: return "Unknown media type"; 155 case B_MEDIA_RAW_AUDIO: return "Raw audio"; 156 case B_MEDIA_RAW_VIDEO: return "Raw video"; 157 case B_MEDIA_VBL: return "Raw data from VBL area"; 158 case B_MEDIA_TIMECODE: return "Timecode"; 159 case B_MEDIA_MIDI: return "MIDI"; 160 case B_MEDIA_TEXT: return "Text"; 161 case B_MEDIA_HTML: return "HTML"; 162 case B_MEDIA_MULTISTREAM: return "Multistream media"; 163 case B_MEDIA_PARAMETERS: return "Parameters"; 164 case B_MEDIA_ENCODED_AUDIO: return "Encoded audio"; 165 case B_MEDIA_ENCODED_VIDEO: return "Encoded video"; 166 default: { 167 if (type >= B_MEDIA_FIRST_USER_TYPE) 168 return "User-defined media type"; 169 if (type >= B_MEDIA_PRIVATE) 170 return "Private Be media type"; 171 } 172 } 173 return "Unknown Media Type"; 174 } 175 176 BString MediaString::getStringFor( 177 media_format_family family, 178 bool complete) { 179 D_METHOD(("MediaString::getStringFor(media_format_family)\n")); 180 181 switch (family) { 182 case B_ANY_FORMAT_FAMILY: return "Any format family"; 183 case B_BEOS_FORMAT_FAMILY: return "BeOS format family"; 184 case B_QUICKTIME_FORMAT_FAMILY: return "QuickTime format family"; 185 case B_AVI_FORMAT_FAMILY: return "AVI format family"; 186 case B_ASF_FORMAT_FAMILY: return "ASF format family"; 187 case B_MPEG_FORMAT_FAMILY: return "MPEG format family"; 188 case B_WAV_FORMAT_FAMILY: return "WAV format family"; 189 case B_AIFF_FORMAT_FAMILY: return "AIFF format family"; 190 default: return "Miscellaneous format family"; 191 } 192 } 193 194 BString MediaString::getStringFor( 195 const media_multi_audio_format &format, 196 bool complete) { 197 D_METHOD(("MediaString::getStringFor(media_raw_audio_format)\n")); 198 199 BString s = ""; 200 bool empty = true; 201 202 // sample rate 203 if (format.frame_rate != media_raw_audio_format::wildcard.frame_rate) { 204 s << (empty ? "" : ", ") << forAudioFrameRate(format.frame_rate); 205 empty = false; 206 } 207 208 // format 209 if (format.format != media_raw_audio_format::wildcard.format) { 210 s << (empty ? "" : ", ") << forAudioFormat(format.format, format.valid_bits); 211 empty = false; 212 } 213 214 // channels 215 if (format.channel_count != media_raw_audio_format::wildcard.channel_count) { 216 s << (empty ? "" : ", ") << forAudioChannelCount(format.channel_count); 217 empty = false; 218 } 219 220 if (complete) { 221 // channel mask 222 if (format.channel_mask != media_multi_audio_format::wildcard.channel_mask) { 223 s << (empty ? "" : " ") << "(" << forAudioChannelMask(format.channel_mask) << ")"; 224 empty = false; 225 } 226 227 // matrix mask 228 if (format.matrix_mask != media_multi_audio_format::wildcard.matrix_mask) { 229 s << (empty ? "" : " ") << "(" << forAudioMatrixMask(format.matrix_mask) << ")"; 230 empty = false; 231 } 232 233 // endianess 234 if (format.byte_order != media_raw_audio_format::wildcard.byte_order) { 235 s << (empty ? "" : ", ") << forAudioByteOrder(format.byte_order); 236 empty = false; 237 } 238 239 // buffer size 240 if (format.buffer_size != media_raw_audio_format::wildcard.buffer_size) { 241 s << (empty ? "" : ", ") << forAudioBufferSize(format.buffer_size); 242 empty = false; 243 } 244 } 245 246 return s; 247 } 248 249 BString MediaString::getStringFor( 250 const media_raw_video_format &format, 251 bool complete) { 252 D_METHOD(("MediaString::getStringFor(media_raw_video_format)\n")); 253 254 BString s = ""; 255 bool empty = true; 256 257 // format / color space 258 if (format.display.format != media_video_display_info::wildcard.format) { 259 s << (empty ? "" : ", ") << forVideoFormat(format.display.format); 260 empty = false; 261 } 262 263 // resolution 264 if ((format.display.line_width != media_video_display_info::wildcard.line_width) 265 && (format.display.line_count != media_video_display_info::wildcard.line_count)) { 266 s << (empty ? "" : ", ") << forVideoResolution(format.display.line_width, 267 format.display.line_count); 268 } 269 270 // field rate / interlace 271 if (format.field_rate != media_raw_video_format::wildcard.field_rate) { 272 s << (empty ? "" : ", ") << forVideoFieldRate(format.field_rate, 273 format.interlace); 274 empty = false; 275 } 276 277 if (complete) { 278 279 // aspect ratio 280 if ((format.pixel_width_aspect != media_raw_video_format::wildcard.pixel_width_aspect) 281 && (format.pixel_height_aspect != media_raw_video_format::wildcard.pixel_height_aspect)) { 282 s << (empty ? "" : ", ") << forVideoAspectRatio(format.pixel_width_aspect, 283 format.pixel_height_aspect); 284 empty = false; 285 } 286 287 // orientation 288 if (format.orientation != media_raw_video_format::wildcard.orientation) { 289 s << (empty ? "" : ", ") << forVideoOrientation(format.orientation); 290 empty = false; 291 } 292 293 // active lines 294 if ((format.first_active != media_raw_video_format::wildcard.first_active) 295 && (format.last_active != media_raw_video_format::wildcard.last_active)) { 296 s << (empty ? "" : ", ") << forVideoActiveLines(format.first_active, 297 format.last_active); 298 empty = false; 299 } 300 } 301 return s; 302 } 303 304 BString MediaString::getStringFor( 305 const media_encoded_audio_format &format, 306 bool complete) { 307 D_METHOD(("MediaString::getStringFor(media_encoded_audio_format)\n")); 308 309 BString s = ""; 310 bool empty = true; 311 312 // bit rate 313 if (format.bit_rate != media_encoded_audio_format::wildcard.bit_rate) { 314 s << (empty ? "" : ", ") << forAudioBitRate(format.bit_rate); 315 empty = false; 316 } 317 318 // frame size 319 if (format.frame_size != media_encoded_audio_format::wildcard.frame_size) { 320 s << (empty ? "" : ", ") << forAudioFrameSize(format.frame_size); 321 empty = false; 322 } 323 return s; 324 } 325 326 BString MediaString::getStringFor( 327 const media_encoded_video_format &format, 328 bool complete) { 329 D_METHOD(("MediaString::getStringFor(media_encoded_video_format)\n")); 330 331 BString s = ""; 332 bool empty = true; 333 334 // bit rate 335 if ((format.avg_bit_rate != media_encoded_video_format::wildcard.avg_bit_rate) 336 && (format.max_bit_rate != media_encoded_video_format::wildcard.max_bit_rate)) { 337 s << (empty ? "" : ", ") << forVideoBitRate(format.avg_bit_rate, 338 format.max_bit_rate); 339 empty = false; 340 } 341 342 if (complete) { 343 344 // frame size 345 if (format.frame_size != media_encoded_video_format::wildcard.frame_size) { 346 s << (empty ? "" : ", ") << forVideoFrameSize(format.frame_size); 347 empty = false; 348 } 349 350 // history 351 if ((format.forward_history != media_encoded_video_format::wildcard.forward_history) 352 && (format.backward_history != media_encoded_video_format::wildcard.backward_history)) { 353 s << (empty ? "" : ", ") << forVideoHistory(format.forward_history, 354 format.backward_history); 355 empty = false; 356 } 357 } 358 359 return s; 360 } 361 362 BString MediaString::getStringFor( 363 const media_multistream_format &format, 364 bool complete) { 365 D_METHOD(("MediaString::getStringFor(media_multistream_format)\n")); 366 367 BString s = ""; 368 bool empty = true; 369 370 // format 371 if (format.format != media_multistream_format::wildcard.format) { 372 s << (empty ? "" : ", ") << forMultistreamFormat(format.format); 373 empty = false; 374 } 375 376 // bit rate 377 if ((format.avg_bit_rate != media_multistream_format::wildcard.avg_bit_rate) 378 && (format.max_bit_rate != media_multistream_format::wildcard.max_bit_rate)) { 379 s << (empty ? "" : ", ") << forMultistreamBitRate(format.avg_bit_rate, 380 format.max_bit_rate); 381 empty = false; 382 } 383 384 if (complete) { 385 386 // chunk size 387 if ((format.avg_chunk_size != media_multistream_format::wildcard.avg_chunk_size) 388 && (format.max_chunk_size != media_multistream_format::wildcard.max_chunk_size)) { 389 s << (empty ? "" : ", ") << forMultistreamChunkSize(format.avg_chunk_size, 390 format.max_chunk_size); 391 empty = false; 392 } 393 394 // flags 395 if (format.flags != media_multistream_format::wildcard.flags) { 396 s << (empty ? "" : ", ") << forMultistreamFlags(format.flags); 397 empty = false; 398 } 399 } 400 401 return s; 402 } 403 404 BString MediaString::getStringFor( 405 const media_format &format, 406 bool complete) { 407 D_METHOD(("MediaString::getStringFor(media_format)\n")); 408 409 BString s = getStringFor(format.type, complete); 410 switch (format.type) { 411 case B_MEDIA_RAW_AUDIO: { 412 BString formatInfo = getStringFor(format.u.raw_audio, complete); 413 if (formatInfo.Length() > 0) 414 s << " (" << formatInfo << ")"; 415 break; 416 } 417 case B_MEDIA_RAW_VIDEO: { 418 BString formatInfo = getStringFor(format.u.raw_video, complete); 419 if (formatInfo.Length() > 0) 420 s << " (" << formatInfo << ")"; 421 break; 422 } 423 case B_MEDIA_ENCODED_AUDIO: { 424 BString formatInfo = getStringFor(format.u.encoded_audio, complete); 425 if (formatInfo.Length() > 0) 426 s << " (" << formatInfo << ")"; 427 break; 428 } 429 case B_MEDIA_ENCODED_VIDEO: { 430 BString formatInfo = getStringFor(format.u.encoded_video, complete); 431 if (formatInfo.Length() > 0) 432 s << " (" << formatInfo << ")"; 433 break; 434 } 435 case B_MEDIA_MULTISTREAM: { 436 BString formatInfo = getStringFor(format.u.multistream, complete); 437 if (formatInfo.Length() > 0) 438 s << " (" << formatInfo << ")"; 439 break; 440 } 441 default: { 442 break; 443 } 444 } 445 return s; 446 } 447 448 // -------------------------------------------------------- // 449 // *** media_source / media_destination strings (public) 450 // -------------------------------------------------------- // 451 452 BString MediaString::getStringFor( 453 const media_source &source, 454 bool complete) { 455 D_METHOD(("MediaString::getStringFor(media_source)\n")); 456 457 BString s; 458 if ((source.port != media_source::null.port) 459 && (source.id != media_source::null.id)) { 460 s << "Port " << source.port << ", ID " << source.id; 461 } 462 else { 463 s = "(none)"; 464 } 465 return s; 466 } 467 468 BString MediaString::getStringFor( 469 const media_destination &destination, 470 bool complete) { 471 D_METHOD(("MediaString::getStringFor(media_destination)\n")); 472 473 BString s; 474 if ((destination.port != media_destination::null.port) 475 && (destination.id != media_destination::null.id)) { 476 s << "Port " << destination.port << ", ID " << destination.id; 477 } 478 else { 479 s = "(none)"; 480 } 481 return s; 482 } 483 484 // -------------------------------------------------------- // 485 // *** strings for single fields in media_raw_audio_format 486 // (public) 487 // -------------------------------------------------------- // 488 489 BString MediaString::forAudioFormat( 490 uint32 format, 491 int32 validBits) { 492 D_METHOD(("MediaString::forAudioFormat()\n")); 493 494 if (format == media_raw_audio_format::wildcard.format) { 495 return "*"; 496 } 497 498 switch (format) { 499 case media_raw_audio_format::B_AUDIO_UCHAR: { 500 return "8 bit integer"; 501 } 502 case media_raw_audio_format::B_AUDIO_SHORT: { 503 return "16 bit integer"; 504 } 505 case media_raw_audio_format::B_AUDIO_FLOAT: { 506 return "32 bit float"; 507 } 508 case media_raw_audio_format::B_AUDIO_INT: { 509 BString s = ""; 510 if (validBits != media_multi_audio_format::wildcard.valid_bits) 511 s << validBits << " bit "; 512 else 513 s << "32 bit "; 514 s << "integer"; 515 return s; 516 } 517 default: { 518 return "(unknown format)"; 519 } 520 } 521 } 522 523 BString MediaString::forAudioFrameRate( 524 float frameRate) 525 { 526 D_METHOD(("MediaString::forAudioFrameRate()\n")); 527 528 if (frameRate == media_raw_audio_format::wildcard.frame_rate) { 529 return "*"; 530 } 531 532 BString s; 533 s << (frameRate / 1000) << " kHz"; 534 return s; 535 } 536 537 BString MediaString::forAudioChannelCount( 538 uint32 channelCount) 539 { 540 D_METHOD(("MediaString::forAudioChannelCount()\n")); 541 542 if (channelCount == media_raw_audio_format::wildcard.channel_count) { 543 return "*"; 544 } 545 546 switch (channelCount) { 547 case 1: { 548 return "Mono"; 549 } 550 case 2: { 551 return "Stereo"; 552 } 553 default: { 554 BString s = ""; 555 s << channelCount << " Channels"; 556 return s; 557 } 558 } 559 } 560 561 BString MediaString::forAudioByteOrder( 562 uint32 byteOrder) 563 { 564 D_METHOD(("MediaString::forAudioByteOrder()\n")); 565 566 if (byteOrder == media_raw_audio_format::wildcard.byte_order) { 567 return "*"; 568 } 569 570 switch (byteOrder) { 571 case B_MEDIA_BIG_ENDIAN: { 572 return "Big endian"; 573 } 574 case B_MEDIA_LITTLE_ENDIAN: { 575 return "Little endian"; 576 } 577 default: { 578 return "(unknown byte order)"; 579 } 580 } 581 } 582 583 BString MediaString::forAudioBufferSize( 584 size_t bufferSize) 585 { 586 D_METHOD(("MediaString::forAudioBufferSize()\n")); 587 588 if (bufferSize == media_raw_audio_format::wildcard.buffer_size) { 589 return "*"; 590 } 591 592 BString s = ""; 593 s << bufferSize << " bytes per buffer"; 594 return s; 595 } 596 597 BString MediaString::forAudioChannelMask( 598 uint32 channelMask) { 599 D_METHOD(("MediaString::forAudioChannelMask()\n")); 600 601 BString list, last; 602 bool first = true; 603 604 if (channelMask & B_CHANNEL_LEFT) { 605 if (first) { 606 list = "Left"; 607 first = false; 608 } 609 } 610 if (channelMask & B_CHANNEL_RIGHT) { 611 if (first) { 612 list = "Right"; 613 first = false; 614 } 615 else { 616 if (last != "") 617 list << ", " << last; 618 last = "Right"; 619 } 620 } 621 if (channelMask & B_CHANNEL_CENTER) { 622 if (first) { 623 list = "Center"; 624 first = false; 625 } 626 else { 627 if (last != "") 628 list << ", " << last; 629 last = "Center"; 630 } 631 } 632 if (channelMask & B_CHANNEL_SUB) { 633 if (first) { 634 list = "Sub"; 635 first = false; 636 } 637 else { 638 if (last != "") 639 list << ", " << last; 640 last = "Sub"; 641 } 642 } 643 if (channelMask & B_CHANNEL_REARLEFT) { 644 if (first) { 645 list = "Rear-left"; 646 first = false; 647 } 648 else { 649 if (last != "") 650 list << ", " << last; 651 last = "Rear-left"; 652 } 653 } 654 if (channelMask & B_CHANNEL_REARRIGHT) { 655 if (first) { 656 list = "Rear-right"; 657 first = false; 658 } 659 else { 660 if (last != "") 661 list << ", " << last; 662 last = "Rear-right"; 663 } 664 } 665 if (channelMask & B_CHANNEL_FRONT_LEFT_CENTER) { 666 if (first) { 667 list = "Front-left-center"; 668 first = false; 669 } 670 else { 671 if (last != "") 672 list << ", " << last; 673 last = "Front-left-center"; 674 } 675 } 676 if (channelMask & B_CHANNEL_FRONT_RIGHT_CENTER) { 677 if (first) { 678 list = "Front-right-center"; 679 first = false; 680 } 681 else { 682 if (last != "") 683 list << ", " << last; 684 last = "Front-right-center"; 685 } 686 } 687 if (channelMask & B_CHANNEL_BACK_CENTER) { 688 if (first) { 689 list = "Back-center"; 690 first = false; 691 } 692 else { 693 if (last != "") 694 list << ", " << last; 695 last = "Back-center"; 696 } 697 } 698 if (channelMask & B_CHANNEL_SIDE_LEFT) { 699 if (first) { 700 list = "Side-left"; 701 first = false; 702 } 703 else { 704 if (last != "") 705 list << ", " << last; 706 last = "Side-left"; 707 } 708 } 709 if (channelMask & B_CHANNEL_SIDE_RIGHT) { 710 if (first) { 711 list = "Side-right"; 712 first = false; 713 } 714 else { 715 if (last != "") 716 list << ", " << last; 717 last = "Side-right"; 718 } 719 } 720 if (channelMask & B_CHANNEL_TOP_CENTER) { 721 if (first) { 722 list = "Top-center"; 723 first = false; 724 } 725 else { 726 if (last != "") 727 list << ", " << last; 728 last = "Top-center"; 729 } 730 } 731 if (channelMask & B_CHANNEL_TOP_FRONT_LEFT) { 732 if (first) { 733 list = "Top-Front-left"; 734 first = false; 735 } 736 else { 737 if (last != "") 738 list << ", " << last; 739 last = "Top-Front-left"; 740 } 741 } 742 if (channelMask & B_CHANNEL_TOP_FRONT_CENTER) { 743 if (first) { 744 list = "Top-Front-center"; 745 first = false; 746 } 747 else { 748 if (last != "") 749 list << ", " << last; 750 last = "Top-Front-center"; 751 } 752 } 753 if (channelMask & B_CHANNEL_TOP_FRONT_RIGHT) { 754 if (first) { 755 list = "Top-Front-right"; 756 first = false; 757 } 758 else { 759 if (last != "") 760 list << ", " << last; 761 last = "Top-Front-right"; 762 } 763 } 764 if (channelMask & B_CHANNEL_TOP_BACK_LEFT) { 765 if (first) { 766 list = "Top-Back-left"; 767 first = false; 768 } 769 else { 770 if (last != "") 771 list << ", " << last; 772 last = "Top-Back-left"; 773 } 774 } 775 if (channelMask & B_CHANNEL_TOP_BACK_CENTER) { 776 if (first) { 777 list = "Top-Back-center"; 778 first = false; 779 } 780 else { 781 if (last != "") 782 list << ", " << last; 783 last = "Top-Back-center"; 784 } 785 } 786 if (channelMask & B_CHANNEL_TOP_BACK_RIGHT) { 787 if (first) { 788 list = "Top-Back-right"; 789 first = false; 790 } 791 else { 792 if (last != "") 793 list << ", " << last; 794 last = "Top-Back-right"; 795 } 796 } 797 if (last != "") { 798 list << " & " << last; 799 } 800 if (list == "") { 801 list = "(none)"; 802 } 803 804 return list; 805 } 806 807 BString MediaString::forAudioMatrixMask( 808 uint16 matrixMask) { 809 D_METHOD(("MediaString::forAudioMatrixMask()\n")); 810 811 switch (matrixMask) { 812 case 0: return "(none)"; 813 case B_MATRIX_PROLOGIC_LR: return "ProLogic LR"; 814 case B_MATRIX_AMBISONIC_WXYZ: return "Ambisonic WXYZ"; 815 default: return "(unknown matrix mask)"; 816 } 817 } 818 819 // -------------------------------------------------------- // 820 // *** strings for single fields in media_encoded_audio_format 821 // (public) 822 // -------------------------------------------------------- // 823 824 BString MediaString::forAudioBitRate( 825 float bitRate) 826 { 827 D_METHOD(("MediaString::forAudioBufferSize()\n")); 828 829 if (bitRate == media_encoded_audio_format::wildcard.bit_rate) { 830 return "*"; 831 } 832 833 BString s = ""; 834 s << bitRate / 1000.0f << " kb/s"; 835 return s; 836 } 837 838 BString MediaString::forAudioFrameSize( 839 size_t frameSize) 840 { 841 D_METHOD(("MediaString::forAudioFrameSize()\n")); 842 843 if (frameSize == media_encoded_audio_format::wildcard.frame_size) { 844 return "*"; 845 } 846 847 BString s = ""; 848 s << frameSize << " bytes per frame"; 849 return s; 850 } 851 852 // -------------------------------------------------------- // 853 // *** strings for single fields in media_raw_video_format 854 // (public) 855 // -------------------------------------------------------- // 856 857 BString MediaString::forVideoFormat( 858 color_space format) 859 { 860 D_METHOD(("MediaString::forVideoFormat()\n")); 861 862 if (format == media_video_display_info::wildcard.format) { 863 return "*"; 864 } 865 866 switch (format) { 867 case B_RGB32: 868 case B_RGB32_BIG: return "32 bit RGB"; 869 case B_RGBA32: 870 case B_RGBA32_BIG: return "32 bit RGBA"; 871 case B_RGB24: 872 case B_RGB24_BIG: return "24 bit RGB"; 873 case B_RGB16: 874 case B_RGB16_BIG: return "16 bit RGB"; 875 case B_RGB15: 876 case B_RGB15_BIG: return "15 bit RGB"; 877 case B_RGBA15: 878 case B_RGBA15_BIG: return "15 bit RGBA"; 879 case B_CMAP8: return "8 bit color-index"; 880 case B_GRAY8: return "8 bit grayscale-index"; 881 case B_GRAY1: return "Monochrome"; 882 case B_YUV422: return "YUV422"; 883 case B_YUV411: return "YUV411"; 884 case B_YUV420: return "YUV420"; 885 case B_YUV444: return "YUV444"; 886 case B_YUV9: return "YUV9"; 887 case B_YUV12: return "YUV12"; 888 case B_YCbCr422: return "YCbCr422"; 889 case B_YCbCr411: return "YCbCr411"; 890 case B_YCbCr444: return "YCbCr444"; 891 case B_YCbCr420: return "YCbCr420"; 892 case B_UVL24: return "24 bit UVL"; 893 case B_UVL32: return "32 bit UVL"; 894 case B_UVLA32: return "32 bit UVLA"; 895 case B_LAB24: return "24 bit LAB"; 896 case B_LAB32: return "32 bit LAB"; 897 case B_LABA32: return "32 bit LABA"; 898 case B_HSI24: return "24 bit HSI"; 899 case B_HSI32: return "32 bit HSI"; 900 case B_HSIA32: return "32 bit HSIA"; 901 case B_HSV24: return "24 bit HSV"; 902 case B_HSV32: return "32 bit HSV"; 903 case B_HSVA32: return "32 bit HSVA"; 904 case B_HLS24: return "24 bit HLS"; 905 case B_HLS32: return "32 bit HLS"; 906 case B_HLSA32: return "32 bit HLSA"; 907 case B_CMY24: return "24 bit CMY"; 908 case B_CMY32: return "32 bit CMY"; 909 case B_CMYA32: return "32 bit CMYA"; 910 case B_CMYK32: return "32 bit CMYK"; 911 default: { 912 return "(unknown video format)"; 913 } 914 } 915 } 916 917 BString MediaString::forVideoResolution( 918 uint32 lineWidth, 919 uint32 lineCount) 920 { 921 D_METHOD(("MediaString::forVideoResolution()\n")); 922 923 if ((lineWidth == media_video_display_info::wildcard.line_width) 924 || (lineCount == media_video_display_info::wildcard.line_count)) { 925 return "*"; 926 } 927 928 BString s = ""; 929 s << lineWidth << " x " << lineCount; 930 return s; 931 } 932 933 BString MediaString::forVideoFieldRate( 934 float fieldRate, 935 uint32 interlace) 936 { 937 D_METHOD(("MediaString::forVideoFieldRate()\n")); 938 939 if (fieldRate == media_raw_video_format::wildcard.field_rate) { 940 return "*"; 941 } 942 943 BString s = ""; 944 if (interlace == 1) { 945 s << "Non-interlaced "; 946 } 947 else { 948 s << "Interlaced "; 949 } 950 s << fieldRate << " Hz"; 951 if ((fieldRate > 49.9) && (fieldRate < 50.1)) { 952 s << " (PAL)"; 953 } 954 else if (((interlace == 2) && (fieldRate > 59.9) && (fieldRate < 60.0)) 955 || ((interlace == 1) && (fieldRate > 29.9) && (fieldRate < 30.0))) { 956 s << " (NTSC)"; 957 } 958 959 return s; 960 } 961 962 BString MediaString::forVideoOrientation( 963 uint32 orientation) 964 { 965 D_METHOD(("MediaString::forVideoOrientation()\n")); 966 967 if (orientation == media_raw_video_format::wildcard.orientation) { 968 return "*"; 969 } 970 971 switch (orientation) { 972 case B_VIDEO_TOP_LEFT_RIGHT: { 973 return "Top to bottom, left to right"; 974 } 975 case B_VIDEO_BOTTOM_LEFT_RIGHT: { 976 return "Bottom to top, left to right"; 977 } 978 default: { 979 return "(unkown video orientation)"; 980 } 981 } 982 } 983 984 BString MediaString::forVideoAspectRatio( 985 uint16 pixelWidth, 986 uint16 pixelHeight) 987 { 988 D_METHOD(("MediaString::forVideoPixelAspect()\n")); 989 990 if ((pixelWidth == media_raw_video_format::wildcard.pixel_width_aspect) 991 || (pixelHeight == media_raw_video_format::wildcard.pixel_height_aspect)) { 992 return "*"; 993 } 994 995 BString s = ""; 996 s << static_cast<uint32>(pixelWidth); 997 s << ":" << static_cast<uint32>(pixelHeight); 998 return s; 999 } 1000 1001 BString MediaString::forVideoActiveLines( 1002 uint32 firstActive, 1003 uint32 lastActive) 1004 { 1005 D_METHOD(("MediaString::forVideoActiveLines()\n")); 1006 1007 if ((firstActive == media_raw_video_format::wildcard.first_active) 1008 || (lastActive == media_raw_video_format::wildcard.last_active)) { 1009 return "*"; 1010 } 1011 1012 BString s = "Video data between"; 1013 s << " line " << firstActive; 1014 s << " and " << lastActive; 1015 return s; 1016 } 1017 1018 BString MediaString::forVideoBytesPerRow( 1019 uint32 bytesPerRow) 1020 { 1021 D_METHOD(("MediaString::forVideoBytesPerRow()\n")); 1022 1023 if (bytesPerRow == media_video_display_info::wildcard.bytes_per_row) { 1024 return "*"; 1025 } 1026 1027 BString s = ""; 1028 s << bytesPerRow << " bytes per row"; 1029 return s; 1030 } 1031 1032 BString MediaString::forVideoOffset( 1033 uint32 pixelOffset, 1034 uint32 lineOffset) 1035 { 1036 D_METHOD(("MediaString::forVideoResolution()\n")); 1037 1038 BString s = ""; 1039 if (pixelOffset != media_video_display_info::wildcard.pixel_offset) { 1040 s << pixelOffset << " pixels"; 1041 } 1042 if (lineOffset != media_video_display_info::wildcard.line_offset) { 1043 if (s != "") { 1044 s << ", "; 1045 } 1046 s << pixelOffset << " lines"; 1047 } 1048 if (s == "") { 1049 s = "*"; 1050 } 1051 return s; 1052 } 1053 1054 // -------------------------------------------------------- // 1055 // *** strings for single fields in media_encoded_video_format 1056 // (public) 1057 // -------------------------------------------------------- // 1058 1059 BString MediaString::forVideoBitRate( 1060 float avgBitRate, 1061 float maxBitRate) 1062 { 1063 D_METHOD(("MediaString::forVideoBitRate()\n")); 1064 1065 BString s = ""; 1066 if (avgBitRate != media_encoded_video_format::wildcard.avg_bit_rate) { 1067 s << avgBitRate / 1000.0f << " kb/s (avg)"; 1068 } 1069 if (maxBitRate != media_encoded_video_format::wildcard.max_bit_rate) { 1070 if (s != "") { 1071 s << ", "; 1072 } 1073 s << maxBitRate / 1000.0f << " kb/s (max)"; 1074 } 1075 if (s == "") { 1076 s = "*"; 1077 } 1078 return s; 1079 } 1080 1081 BString MediaString::forVideoFrameSize( 1082 size_t frameSize) 1083 { 1084 D_METHOD(("MediaString::forVideoFrameSize()\n")); 1085 1086 if (frameSize == media_encoded_video_format::wildcard.frame_size) { 1087 return "*"; 1088 } 1089 1090 BString s = ""; 1091 s << frameSize << " bytes per frame"; 1092 return s; 1093 } 1094 1095 BString MediaString::forVideoHistory( 1096 int16 forwardHistory, 1097 int16 backwardHistory) 1098 { 1099 D_METHOD(("MediaString::forVideoHistory()\n")); 1100 1101 BString s = ""; 1102 if (forwardHistory != media_encoded_video_format::wildcard.forward_history) { 1103 s << static_cast<int32>(forwardHistory) << " frames forward"; 1104 } 1105 if (backwardHistory != media_encoded_video_format::wildcard.backward_history) { 1106 if (s != "") { 1107 s << ", "; 1108 } 1109 s << static_cast<int32>(backwardHistory) << " frames backward"; 1110 } 1111 if (s == "") { 1112 s = "*"; 1113 } 1114 return s; 1115 } 1116 1117 // -------------------------------------------------------- // 1118 // *** strings for single fields in media_multistream_format 1119 // (public) 1120 // -------------------------------------------------------- // 1121 1122 BString MediaString::forMultistreamFormat( 1123 int32 format) 1124 { 1125 D_METHOD(("MediaString::forMultistreamFormat()\n")); 1126 1127 if (format == media_multistream_format::wildcard.format) { 1128 return "*"; 1129 } 1130 1131 switch (format) { 1132 case media_multistream_format::B_VID: return "BeOS video"; 1133 case media_multistream_format::B_AVI: return "AVI"; 1134 case media_multistream_format::B_MPEG1: return "MPEG1"; 1135 case media_multistream_format::B_MPEG2: return "MPEG2"; 1136 case media_multistream_format::B_QUICKTIME: return "QuickTime"; 1137 default: return "(unknown multistream format)"; 1138 } 1139 } 1140 1141 BString MediaString::forMultistreamBitRate( 1142 float avgBitRate, 1143 float maxBitRate) 1144 { 1145 D_METHOD(("MediaString::forMultistreamFormat()\n")); 1146 1147 BString s = ""; 1148 if (avgBitRate != media_multistream_format::wildcard.avg_bit_rate) { 1149 s << avgBitRate / 1000.0f << " kb/s (avg)"; 1150 } 1151 if (maxBitRate != media_multistream_format::wildcard.max_bit_rate) { 1152 if (s != "") { 1153 s << ", "; 1154 } 1155 s << maxBitRate / 1000.0f << " kb/s (max)"; 1156 } 1157 if (s == "") { 1158 s = "*"; 1159 } 1160 return s; 1161 } 1162 1163 BString MediaString::forMultistreamChunkSize( 1164 uint32 avgChunkSize, 1165 uint32 maxChunkSize) 1166 { 1167 D_METHOD(("MediaString::forMultistreamChunkSize()\n")); 1168 1169 BString s = ""; 1170 if (avgChunkSize != media_multistream_format::wildcard.avg_chunk_size) { 1171 s << avgChunkSize << " bytes (avg)"; 1172 } 1173 if (maxChunkSize != media_multistream_format::wildcard.max_chunk_size) { 1174 if (s != "") { 1175 s << ", "; 1176 } 1177 s << maxChunkSize << " bytes (max)"; 1178 } 1179 if (s == "") { 1180 s = "*"; 1181 } 1182 return s; 1183 } 1184 1185 BString MediaString::forMultistreamFlags( 1186 uint32 flags) 1187 { 1188 D_METHOD(("MediaString::forMultistreamFlags()\n")); 1189 1190 BString list, last; 1191 bool first = true; 1192 1193 if (flags & media_multistream_format::B_HEADER_HAS_FLAGS) { 1194 if (first) { 1195 list = "Header has flags"; 1196 first = false; 1197 } 1198 } 1199 if (flags & media_multistream_format::B_CLEAN_BUFFERS) { 1200 if (first) { 1201 list = "Clean buffers"; 1202 first = false; 1203 } 1204 else { 1205 if (last != "") 1206 list << ", " << last; 1207 last = "Clean buffers"; 1208 } 1209 } 1210 if (flags & media_multistream_format::B_HOMOGENOUS_BUFFERS) { 1211 if (first) { 1212 list = "Homogenous buffers"; 1213 first = false; 1214 } 1215 else { 1216 if (last != "") 1217 list << ", " << last; 1218 last = "Homogenous buffers"; 1219 } 1220 } 1221 1222 if (last != "") 1223 list << " & " << last; 1224 1225 if (list == "") 1226 list = "(none)"; 1227 1228 return list; 1229 } 1230 1231 // END -- MediaString.cpp -- 1232