1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528
|
/*****************************************************************
|
| AP4 - Sample Description Objects
|
| Copyright 2002-2008 Axiomatic Systems, LLC
|
|
| This file is part of Bento4/AP4 (MP4 Atom Processing Library).
|
| Unless you have obtained Bento4 under a difference license,
| this version of Bento4 is Bento4|GPL.
| Bento4|GPL is free software; you can redistribute it and/or modify
| it under the terms of the GNU General Public License as published by
| the Free Software Foundation; either version 2, or (at your option)
| any later version.
|
| Bento4|GPL is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
|
| You should have received a copy of the GNU General Public License
| along with Bento4|GPL; see the file COPYING. If not, write to the
| Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
| 02111-1307, USA.
|
****************************************************************/
/*----------------------------------------------------------------------
| includes
+---------------------------------------------------------------------*/
#include "Ap4SampleDescription.h"
#include "Ap4EsDescriptor.h"
#include "Ap4SLConfigDescriptor.h"
#include "Ap4SampleEntry.h"
#include "Ap4AvccAtom.h"
#include "Ap4HvccAtom.h"
#include "Ap4VpccAtom.h"
#include "Ap4Av1cAtom.h"
#include "Ap4Utils.h"
#include "Ap4Mp4AudioInfo.h"
/*----------------------------------------------------------------------
| dynamic cast support
+---------------------------------------------------------------------*/
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_SampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_UnknownSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_AudioSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_VideoSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_GenericAudioSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_GenericVideoSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_MpegSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_MpegAudioSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_MpegVideoSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_MpegSystemSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_AvcSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_HevcSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_Av1SampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_SubtitleSampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_Ac3SampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_Eac3SampleDescription)
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_Ac4SampleDescription)
/*----------------------------------------------------------------------
| AP4_GetFormatName
+---------------------------------------------------------------------*/
const char*
AP4_GetFormatName(AP4_UI32 format)
{
switch (format) {
case AP4_SAMPLE_FORMAT_MP4A: return "MPEG-4 Audio";
case AP4_SAMPLE_FORMAT_MP4V: return "MPEG-4 Video";
case AP4_SAMPLE_FORMAT_MP4S: return "MPEG-4 Systems";
case AP4_SAMPLE_FORMAT_ALAC: return "Apple Lossless Audio";
case AP4_SAMPLE_FORMAT_AVC1: return "H.264";
case AP4_SAMPLE_FORMAT_AVC2: return "H.264";
case AP4_SAMPLE_FORMAT_AVC3: return "H.264";
case AP4_SAMPLE_FORMAT_AVC4: return "H.264";
case AP4_SAMPLE_FORMAT_DVAV: return "Dolby Vision (H.264)";
case AP4_SAMPLE_FORMAT_DVA1: return "Dolby Vision (H.264)";
case AP4_SAMPLE_FORMAT_HEV1: return "H.265";
case AP4_SAMPLE_FORMAT_HVC1: return "H.265";
case AP4_SAMPLE_FORMAT_DVH1: return "Dolby Vision (H.265)";
case AP4_SAMPLE_FORMAT_DVHE: return "Dolby Vision (H.265)";
case AP4_SAMPLE_FORMAT_AV01: return "AV1";
case AP4_SAMPLE_FORMAT_OVC1: return "VC-1";
case AP4_SAMPLE_FORMAT_OWMA: return "WMA";
case AP4_SAMPLE_FORMAT_AC_3: return "Dolby Digital (AC-3)";
case AP4_SAMPLE_FORMAT_EC_3: return "Dolby Digital Plus (Enhanced AC-3)";
case AP4_SAMPLE_FORMAT_AC_4: return "Dolby AC-4";
case AP4_SAMPLE_FORMAT_DTSC: return "DTS";
case AP4_SAMPLE_FORMAT_DTSH: return "DTS-HD";
case AP4_SAMPLE_FORMAT_DTSL: return "DTS-HD Lossless";
case AP4_SAMPLE_FORMAT_DTSE: return "DTS Low Bitrate";
case AP4_SAMPLE_FORMAT_AVCP: return "Advanced Video Coding Parameters";
case AP4_SAMPLE_FORMAT_DRAC: return "Dirac";
case AP4_SAMPLE_FORMAT_DRA1: return "DRA Audio";
case AP4_SAMPLE_FORMAT_G726: return "G726";
case AP4_SAMPLE_FORMAT_MJP2: return "Motion JPEG 2000";
case AP4_SAMPLE_FORMAT_OKSD: return "OMA Keys";
case AP4_SAMPLE_FORMAT_RAW_: return "Uncompressed Audio";
case AP4_SAMPLE_FORMAT_RTP_: return "RTP Hints";
case AP4_SAMPLE_FORMAT_S263: return "H.263";
case AP4_SAMPLE_FORMAT_SAMR: return "Narrowband AMR";
case AP4_SAMPLE_FORMAT_SAWB: return "Wideband AMR";
case AP4_SAMPLE_FORMAT_SAWP: return "Extended AMR";
case AP4_SAMPLE_FORMAT_SEVC: return "EVRC Voice";
case AP4_SAMPLE_FORMAT_SQCP: return "13K Voice";
case AP4_SAMPLE_FORMAT_SRTP: return "SRTP Hints";
case AP4_SAMPLE_FORMAT_SSMV: return "SMV Voice";
case AP4_SAMPLE_FORMAT_TEXT: return "Textual Metadata";
case AP4_SAMPLE_FORMAT_TWOS: return "Uncompressed 16-bit Audio";
case AP4_SAMPLE_FORMAT_TX3G: return "Timed Text";
case AP4_SAMPLE_FORMAT_VC_1: return "SMPTE VC-1";
case AP4_SAMPLE_FORMAT_XML_: return "XML Metadata";
case AP4_SAMPLE_FORMAT_STPP: return "Timed Text";
case AP4_SAMPLE_FORMAT_VP8: return "VP8";
case AP4_SAMPLE_FORMAT_VP9: return "VP9";
case AP4_SAMPLE_FORMAT_VP10: return "VP10";
default: return NULL;
}
}
/*----------------------------------------------------------------------
| AP4_SampleDescription::AP4_SampleDescription
+---------------------------------------------------------------------*/
AP4_SampleDescription::AP4_SampleDescription(Type type,
AP4_UI32 format,
AP4_AtomParent* details) :
m_Type(type), m_Format(format)
{
if (details) {
for (AP4_List<AP4_Atom>::Item* item = details->GetChildren().FirstItem();
item;
item = item->GetNext()) {
AP4_Atom* atom = item->GetData();
if (atom) {
AP4_Atom* clone = atom->Clone();
if (clone) m_Details.AddChild(clone);
}
}
}
}
/*----------------------------------------------------------------------
| AP4_SampleDescription::Clone
+---------------------------------------------------------------------*/
AP4_SampleDescription*
AP4_SampleDescription::Clone(AP4_Result* result)
{
if (result) *result = AP4_SUCCESS;
AP4_Atom* atom = ToAtom();
if (atom == NULL) {
if (result) *result = AP4_FAILURE;
return NULL;
}
// serialize the atom to a buffer
AP4_MemoryByteStream* mbs = new AP4_MemoryByteStream((AP4_UI32)atom->GetSize());
atom->Write(*mbs);
delete atom;
atom = NULL;
// parse the buffer back to an atom
mbs->Seek(0);
AP4_AtomFactory* factory = new AP4_AtomFactory();
factory->PushContext(AP4_ATOM_TYPE_STSD);
AP4_Atom* atom_clone = NULL;
AP4_Result lresult = factory->CreateAtomFromStream(*mbs, atom_clone);
factory->PopContext();
delete factory;
if (result) *result = lresult;
mbs->Release();
if (AP4_FAILED(lresult)) return NULL;
// convert the atom clone to a sample description
AP4_SampleEntry* sample_entry = AP4_DYNAMIC_CAST(AP4_SampleEntry, atom_clone);
if (sample_entry == NULL) {
if (result) *result = AP4_ERROR_INTERNAL;
delete atom_clone;
return NULL;
}
AP4_SampleDescription* clone = sample_entry->ToSampleDescription();
if (clone == NULL) {
if (result) *result = AP4_ERROR_INTERNAL;
}
delete atom_clone;
return clone;
}
/*----------------------------------------------------------------------
| AP4_SampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_SampleDescription::ToAtom() const
{
return new AP4_SampleEntry(m_Format);
}
/*----------------------------------------------------------------------
| AP4_SampleDescription::GetCodecString
+---------------------------------------------------------------------*/
AP4_Result
AP4_SampleDescription::GetCodecString(AP4_String& codec)
{
char coding[5];
AP4_FormatFourChars(coding, m_Format);
codec.Assign(coding, 4);
return AP4_SUCCESS;
}
/*----------------------------------------------------------------------
| AP4_UnknownSampleDescription::AP4_UnknownSampleDescription
+---------------------------------------------------------------------*/
AP4_UnknownSampleDescription::AP4_UnknownSampleDescription(AP4_Atom* atom) :
AP4_SampleDescription(AP4_SampleDescription::TYPE_UNKNOWN,
atom->GetType(),
NULL),
m_Atom(atom->Clone())
{
}
/*----------------------------------------------------------------------
| AP4_UnknownSampleDescription::~AP4_UnknownSampleDescription
+---------------------------------------------------------------------*/
AP4_UnknownSampleDescription::~AP4_UnknownSampleDescription()
{
delete m_Atom;
}
/*----------------------------------------------------------------------
| AP4_UnknownSampleDescription::Clone
+---------------------------------------------------------------------*/
AP4_SampleDescription*
AP4_UnknownSampleDescription::Clone(AP4_Result* result)
{
AP4_Atom* atom_clone = NULL;
if (m_Atom) {
atom_clone = m_Atom->Clone();
}
if (atom_clone == NULL) {
if (result) *result = AP4_FAILURE;
return NULL;
}
if (result) *result = AP4_SUCCESS;
return new AP4_UnknownSampleDescription(atom_clone);
}
/*----------------------------------------------------------------------
| AP4_UnknownSampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_UnknownSampleDescription::ToAtom() const
{
if (m_Atom) {
return m_Atom->Clone();
} else {
return NULL;
}
}
/*----------------------------------------------------------------------
| AP4_GenericAudioSampleDescription
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_GenericAudioSampleDescription::ToAtom() const
{
AP4_AudioSampleEntry* sample_entry = new AP4_AudioSampleEntry(m_Format,
m_SampleRate<<16,
m_SampleSize,
m_ChannelCount);
AP4_AtomParent& details = const_cast<AP4_AtomParent&>(m_Details);
for (AP4_List<AP4_Atom>::Item* item = details.GetChildren().FirstItem();
item;
item = item->GetNext()) {
AP4_Atom* child = item->GetData();
sample_entry->AddChild(child->Clone());
}
return sample_entry;
}
/*----------------------------------------------------------------------
| AP4_GenericVideoSampleDescription::GetCodecString
+---------------------------------------------------------------------*/
AP4_Result
AP4_GenericVideoSampleDescription::GetCodecString(AP4_String& codec)
{
// VPx override
AP4_VpccAtom* vpcc = AP4_DYNAMIC_CAST(AP4_VpccAtom, m_Details.GetChild(AP4_ATOM_TYPE_VPCC));
if (vpcc) {
return vpcc->GetCodecString(GetFormat(), codec);
}
return AP4_SampleDescription::GetCodecString(codec);
}
/*----------------------------------------------------------------------
| AP4_GenericVideoSampleDescription
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_GenericVideoSampleDescription::ToAtom() const
{
AP4_VisualSampleEntry* sample_entry = new AP4_VisualSampleEntry(m_Format,
m_Width,
m_Height,
m_Depth,
m_CompressorName.GetChars());
AP4_AtomParent& details = const_cast<AP4_AtomParent&>(m_Details);
for (AP4_List<AP4_Atom>::Item* item = details.GetChildren().FirstItem();
item;
item = item->GetNext()) {
AP4_Atom* child = item->GetData();
sample_entry->AddChild(child->Clone());
}
return sample_entry;
}
/*----------------------------------------------------------------------
| AP4_AvcSampleDescription::AP4_AvcSampleDescription
+---------------------------------------------------------------------*/
AP4_AvcSampleDescription::AP4_AvcSampleDescription(AP4_UI32 format,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
AP4_UI08 profile,
AP4_UI08 level,
AP4_UI08 profile_compatibility,
AP4_UI08 length_size,
AP4_UI08 chroma_format,
AP4_UI08 bit_depth_luma_minus8,
AP4_UI08 bit_depth_chroma_minus8,
const AP4_Array<AP4_DataBuffer>& sequence_parameters,
const AP4_Array<AP4_DataBuffer>& picture_parameters) :
AP4_SampleDescription(TYPE_AVC, format, NULL),
AP4_VideoSampleDescription(width, height, depth, compressor_name)
{
m_AvccAtom = new AP4_AvccAtom(profile,
level,
profile_compatibility,
length_size,
chroma_format,
bit_depth_luma_minus8,
bit_depth_chroma_minus8,
sequence_parameters,
picture_parameters);
m_Details.AddChild(m_AvccAtom);
}
/*----------------------------------------------------------------------
| AP4_AvcSampleDescription::AP4_AvcSampleDescription
+---------------------------------------------------------------------*/
AP4_AvcSampleDescription::AP4_AvcSampleDescription(AP4_UI32 format,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
const AP4_AvccAtom* avcc) :
AP4_SampleDescription(TYPE_AVC, format, NULL),
AP4_VideoSampleDescription(width, height, depth, compressor_name)
{
if (avcc) {
m_AvccAtom = new AP4_AvccAtom(*avcc);
} else {
// should never happen
m_AvccAtom = new AP4_AvccAtom();
}
m_Details.AddChild(m_AvccAtom);
}
/*----------------------------------------------------------------------
| AP4_AvcSampleDescription::AP4_AvcSampleDescription
+---------------------------------------------------------------------*/
AP4_AvcSampleDescription::AP4_AvcSampleDescription(AP4_UI32 format,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
AP4_AtomParent* details) :
AP4_SampleDescription(TYPE_AVC, format, details),
AP4_VideoSampleDescription(width, height, depth, compressor_name),
m_AvccAtom(NULL)
{
AP4_AvccAtom* avcc = AP4_DYNAMIC_CAST(AP4_AvccAtom, m_Details.GetChild(AP4_ATOM_TYPE_AVCC));
if (avcc) {
m_AvccAtom = avcc;
} else {
// shoud never happen
m_AvccAtom = new AP4_AvccAtom();
m_Details.AddChild(m_AvccAtom);
}
}
/*----------------------------------------------------------------------
| AP4_AvcSampleDescription::GetCodecString
+---------------------------------------------------------------------*/
AP4_Result
AP4_AvcSampleDescription::GetCodecString(AP4_String& codec) {
char coding[5];
AP4_FormatFourChars(coding, GetFormat());
char workspace[64];
AP4_FormatString(workspace,
sizeof(workspace),
"%s.%02X%02X%02X",
coding,
GetProfile(),
GetProfileCompatibility(),
GetLevel());
// Dolby Vision override
AP4_DvccAtom* dvcc = AP4_DYNAMIC_CAST(AP4_DvccAtom, m_Details.GetChild(AP4_ATOM_TYPE_DVCC));
if (dvcc) {
return dvcc->GetCodecString(workspace, GetFormat(), codec);
}
codec = workspace;
return AP4_SUCCESS;
}
/*----------------------------------------------------------------------
| AP4_AvcSampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_AvcSampleDescription::ToAtom() const
{
return new AP4_AvcSampleEntry(m_Format,
m_Width,
m_Height,
m_Depth,
m_CompressorName.GetChars(),
&m_Details);
}
/*----------------------------------------------------------------------
| AP4_AvcDoviSampleDescription::AP4_AvcDoviSampleDescription
+---------------------------------------------------------------------*/
AP4_AvcDoviSampleDescription::AP4_AvcDoviSampleDescription(AP4_UI32 format,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
AP4_UI08 profile,
AP4_UI08 level,
AP4_UI08 profile_compatibility,
AP4_UI08 length_size,
const AP4_Array<AP4_DataBuffer>& sequence_parameters,
const AP4_Array<AP4_DataBuffer>& picture_parameters,
AP4_UI08 chroma_format,
AP4_UI08 bit_depth_luma_minus8,
AP4_UI08 bit_depth_chroma_minus8,
AP4_UI08 dv_version_major,
AP4_UI08 dv_version_minor,
AP4_UI08 dv_profile,
AP4_UI08 dv_level,
bool rpu_present_flag,
bool el_present_flag,
bool bl_present_flag,
AP4_UI08 dv_bl_signal_compatibility_id) :
AP4_AvcSampleDescription(format,
width,
height,
depth,
compressor_name,
profile,
level,
profile_compatibility,
length_size,
chroma_format,
bit_depth_luma_minus8,
bit_depth_chroma_minus8,
sequence_parameters,
picture_parameters)
{
m_DvccAtom = new AP4_DvccAtom(dv_version_major,
dv_version_minor,
dv_profile,
dv_level,
rpu_present_flag,
el_present_flag,
bl_present_flag,
dv_bl_signal_compatibility_id);
m_Details.AddChild(m_DvccAtom);
}
/*----------------------------------------------------------------------
| AP4_HevcSampleDescription::AP4_HevcSampleDescription
+---------------------------------------------------------------------*/
AP4_HevcSampleDescription::AP4_HevcSampleDescription(AP4_UI32 format,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
const AP4_HvccAtom* hvcc) :
AP4_SampleDescription(TYPE_HEVC, format, NULL),
AP4_VideoSampleDescription(width, height, depth, compressor_name)
{
if (hvcc) {
m_HvccAtom = new AP4_HvccAtom(*hvcc);
} else {
// should never happen
m_HvccAtom = new AP4_HvccAtom();
}
m_Details.AddChild(m_HvccAtom);
}
/*----------------------------------------------------------------------
| AP4_HevcSampleDescription::AP4_HevcSampleDescription
+---------------------------------------------------------------------*/
AP4_HevcSampleDescription::AP4_HevcSampleDescription(AP4_UI32 format,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
AP4_AtomParent* details) :
AP4_SampleDescription(TYPE_HEVC, format, details),
AP4_VideoSampleDescription(width, height, depth, compressor_name),
m_HvccAtom(NULL)
{
AP4_HvccAtom* hvcc = AP4_DYNAMIC_CAST(AP4_HvccAtom, m_Details.GetChild(AP4_ATOM_TYPE_HVCC));
if (hvcc) {
m_HvccAtom = hvcc;
} else {
// shoud never happen
m_HvccAtom = new AP4_HvccAtom();
m_Details.AddChild(m_HvccAtom);
}
}
/*----------------------------------------------------------------------
| AP4_HevcSampleDescription::AP4_HevcSampleDescription
+---------------------------------------------------------------------*/
AP4_HevcSampleDescription::AP4_HevcSampleDescription(AP4_UI32 format,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
AP4_UI08 general_profile_space,
AP4_UI08 general_tier_flag,
AP4_UI08 general_profile,
AP4_UI32 general_profile_compatibility_flags,
AP4_UI64 general_constraint_indicator_flags,
AP4_UI08 general_level,
AP4_UI32 min_spatial_segmentation,
AP4_UI08 parallelism_type,
AP4_UI08 chroma_format,
AP4_UI08 luma_bit_depth,
AP4_UI08 chroma_bit_depth,
AP4_UI16 average_frame_rate,
AP4_UI08 constant_frame_rate,
AP4_UI08 num_temporal_layers,
AP4_UI08 temporal_id_nested,
AP4_UI08 nalu_length_size,
const AP4_Array<AP4_DataBuffer>& video_parameters,
AP4_UI08 video_parameters_completeness,
const AP4_Array<AP4_DataBuffer>& sequence_parameters,
AP4_UI08 sequence_parameters_completeness,
const AP4_Array<AP4_DataBuffer>& picture_parameters,
AP4_UI08 picture_parameters_completeness) :
AP4_SampleDescription(TYPE_HEVC, format, NULL),
AP4_VideoSampleDescription(width, height, depth, compressor_name)
{
m_HvccAtom = new AP4_HvccAtom(general_profile_space,
general_tier_flag,
general_profile,
general_profile_compatibility_flags,
general_constraint_indicator_flags,
general_level,
min_spatial_segmentation,
parallelism_type,
chroma_format,
luma_bit_depth,
chroma_bit_depth,
average_frame_rate,
constant_frame_rate,
num_temporal_layers,
temporal_id_nested,
nalu_length_size,
video_parameters,
video_parameters_completeness,
sequence_parameters,
sequence_parameters_completeness,
picture_parameters,
picture_parameters_completeness);
m_Details.AddChild(m_HvccAtom);
}
/*----------------------------------------------------------------------
| ReverseBits
+---------------------------------------------------------------------*/
static AP4_UI32
ReverseBits(AP4_UI32 bits)
{
unsigned int count = sizeof(bits) * 8;
AP4_UI32 reverse_bits = 0;
while (bits) {
reverse_bits = (reverse_bits << 1) | (bits & 1);
bits >>= 1;
count--;
}
return (count < 32) ? (reverse_bits << count) : 0;
}
/*----------------------------------------------------------------------
| AP4_HevcSampleDescription:GetCodecString
+---------------------------------------------------------------------*/
AP4_Result
AP4_HevcSampleDescription::GetCodecString(AP4_String& codec) {
char coding[5];
AP4_FormatFourChars(coding, GetFormat());
char profile_space[2] = {0,0};
if (GetGeneralProfileSpace() > 0 && GetGeneralProfileSpace() <= 3) {
profile_space[0] = 'A'+GetGeneralProfileSpace()-1;
}
AP4_UI64 constraints = GetGeneralConstraintIndicatorFlags();
while (constraints && ((constraints & 0xFF) == 0)) {
constraints >>= 8;
}
char workspace[64];
AP4_FormatString(workspace,
sizeof(workspace),
"%s.%s%d.%X.%c%d.%llx",
coding,
profile_space,
GetGeneralProfile(),
ReverseBits(GetGeneralProfileCompatibilityFlags()),
GetGeneralTierFlag()?'H':'L',
GetGeneralLevel(),
constraints);
// Dolby Vision override
AP4_DvccAtom* dvcc = AP4_DYNAMIC_CAST(AP4_DvccAtom, m_Details.GetChild(AP4_ATOM_TYPE_DVCC));
if (dvcc) {
return dvcc->GetCodecString(workspace, GetFormat(), codec);
}
codec = workspace;
return AP4_SUCCESS;
}
/*----------------------------------------------------------------------
| AP4_HevcSampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_HevcSampleDescription::ToAtom() const
{
return new AP4_HevcSampleEntry(m_Format,
m_Width,
m_Height,
m_Depth,
m_CompressorName.GetChars(),
&m_Details);
}
/*----------------------------------------------------------------------
| AP4_HevcDoviSampleDescription::AP4_HevcDoviSampleDescription
+---------------------------------------------------------------------*/
AP4_HevcDoviSampleDescription::AP4_HevcDoviSampleDescription(AP4_UI32 format,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
AP4_UI08 general_profile_space,
AP4_UI08 general_tier_flag,
AP4_UI08 general_profile,
AP4_UI32 general_profile_compatibility_flags,
AP4_UI64 general_constraint_indicator_flags,
AP4_UI08 general_level,
AP4_UI32 min_spatial_segmentation,
AP4_UI08 parallelism_type,
AP4_UI08 chroma_format,
AP4_UI08 luma_bit_depth,
AP4_UI08 chroma_bit_depth,
AP4_UI16 average_frame_rate,
AP4_UI08 constant_frame_rate,
AP4_UI08 num_temporal_layers,
AP4_UI08 temporal_id_nested,
AP4_UI08 nalu_length_size,
const AP4_Array<AP4_DataBuffer>& video_parameters,
AP4_UI08 video_parameters_completeness,
const AP4_Array<AP4_DataBuffer>& sequence_parameters,
AP4_UI08 sequence_parameters_completeness,
const AP4_Array<AP4_DataBuffer>& picture_parameters,
AP4_UI08 picture_parameters_completeness,
AP4_UI08 dv_version_major,
AP4_UI08 dv_version_minor,
AP4_UI08 dv_profile,
AP4_UI08 dv_level,
bool rpu_present_flag,
bool el_present_flag,
bool bl_present_flag,
AP4_UI08 dv_bl_signal_compatibility_id) :
AP4_HevcSampleDescription(format,
width,
height,
depth,
compressor_name,
general_profile_space,
general_tier_flag,
general_profile,
general_profile_compatibility_flags,
general_constraint_indicator_flags,
general_level,
min_spatial_segmentation,
parallelism_type,
chroma_format,
luma_bit_depth,
chroma_bit_depth,
average_frame_rate,
constant_frame_rate,
num_temporal_layers,
temporal_id_nested,
nalu_length_size,
video_parameters,
video_parameters_completeness,
sequence_parameters,
sequence_parameters_completeness,
picture_parameters,
picture_parameters_completeness)
{
m_DvccAtom = new AP4_DvccAtom(dv_version_major,
dv_version_minor,
dv_profile,
dv_level,
rpu_present_flag,
el_present_flag,
bl_present_flag,
dv_bl_signal_compatibility_id);
m_Details.AddChild(m_DvccAtom);
}
/*----------------------------------------------------------------------
| AP4_Av1SampleDescription::AP4_Av1SampleDescription
+---------------------------------------------------------------------*/
AP4_Av1SampleDescription::AP4_Av1SampleDescription(AP4_UI32 format,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
AP4_UI08 version,
AP4_UI08 seq_profile,
AP4_UI08 seq_level_idx_0,
AP4_UI08 seq_tier_0,
AP4_UI08 high_bitdepth,
AP4_UI08 twelve_bit,
AP4_UI08 monochrome,
AP4_UI08 chroma_subsampling_x,
AP4_UI08 chroma_subsampling_y,
AP4_UI08 chroma_sample_position,
AP4_UI08 initial_presentation_delay_present,
AP4_UI08 initial_presentation_delay_minus_one,
const AP4_UI08* config_obus,
AP4_Size config_obus_size) :
AP4_SampleDescription(TYPE_AV1, format, NULL),
AP4_VideoSampleDescription(width, height, depth, compressor_name)
{
m_Av1cAtom = new AP4_Av1cAtom(version,
seq_profile,
seq_level_idx_0,
seq_tier_0,
high_bitdepth,
twelve_bit,
monochrome,
chroma_subsampling_x,
chroma_subsampling_y,
chroma_sample_position,
initial_presentation_delay_present,
initial_presentation_delay_minus_one,
config_obus,
config_obus_size);
m_Details.AddChild(m_Av1cAtom);
}
/*----------------------------------------------------------------------
| AP4_Av1SampleDescription::AP4_Av1SampleDescription
+---------------------------------------------------------------------*/
AP4_Av1SampleDescription::AP4_Av1SampleDescription(AP4_UI32 format,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
const AP4_Av1cAtom* av1c) :
AP4_SampleDescription(TYPE_AV1, format, NULL),
AP4_VideoSampleDescription(width, height, depth, compressor_name)
{
if (av1c) {
m_Av1cAtom = new AP4_Av1cAtom(*av1c);
} else {
// should never happen
m_Av1cAtom = new AP4_Av1cAtom();
}
m_Details.AddChild(m_Av1cAtom);
}
/*----------------------------------------------------------------------
| AP4_Av1SampleDescription::AP4_Av1SampleDescription
+---------------------------------------------------------------------*/
AP4_Av1SampleDescription::AP4_Av1SampleDescription(AP4_UI32 format,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
AP4_AtomParent* details) :
AP4_SampleDescription(TYPE_AV1, format, details),
AP4_VideoSampleDescription(width, height, depth, compressor_name),
m_Av1cAtom(NULL)
{
AP4_Av1cAtom* av1c = AP4_DYNAMIC_CAST(AP4_Av1cAtom, m_Details.GetChild(AP4_ATOM_TYPE_AV1C));
if (av1c) {
m_Av1cAtom = av1c;
} else {
// shoud never happen
m_Av1cAtom = new AP4_Av1cAtom();
m_Details.AddChild(m_Av1cAtom);
}
}
/*----------------------------------------------------------------------
| AP4_Av1cSampleDescription::GetCodecString
+---------------------------------------------------------------------*/
AP4_Result
AP4_Av1SampleDescription::GetCodecString(AP4_String& codec) {
AP4_UI08 bit_depth = 10;
AP4_UI08 color_primaries = 1;
AP4_UI08 transfer_characteristics = 1;
AP4_UI08 matrix_coefficients = 1;
AP4_UI08 video_full_range_flag = 0;
char coding[5];
AP4_FormatFourChars(coding, GetFormat());
char workspace[64];
AP4_FormatString(workspace,
sizeof(workspace),
"%s.%d.%02d%c.%02d.%d.%d%d%d.%02d.%02d.%02d.%d",
coding,
this->GetSeqProfile(),
this->GetSeqLevelIdx0() >> 4,
this->GetSeqTier0() == 0 ? 'M' : 'H',
bit_depth,
this->GetMonochrome(),
this->GetChromaSubsamplingX(),
this->GetChromaSubsamplingY(),
(this->GetChromaSubsamplingX() == 1 && this->GetChromaSubsamplingY() == 1) ?
this->GetChromaSamplePosition() : 0,
color_primaries,
transfer_characteristics,
matrix_coefficients,
video_full_range_flag);
codec = workspace;
return AP4_SUCCESS;
}
/*----------------------------------------------------------------------
| AP4_Av1SampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_Av1SampleDescription::ToAtom() const
{
return new AP4_Av1SampleEntry(m_Format,
m_Width,
m_Height,
m_Depth,
m_CompressorName.GetChars(),
&m_Details);
}
/*----------------------------------------------------------------------
| AP4_MpegSampleDescription::AP4_MpegSampleDescription
+---------------------------------------------------------------------*/
AP4_MpegSampleDescription::AP4_MpegSampleDescription(AP4_UI32 format,
AP4_EsdsAtom* esds) :
AP4_SampleDescription(TYPE_MPEG, format, NULL),
m_StreamType(0),
m_ObjectTypeId(0),
m_BufferSize(0),
m_MaxBitrate(0),
m_AvgBitrate(0)
{
if (esds) {
// get the es descriptor
const AP4_EsDescriptor* es_desc = esds->GetEsDescriptor();
if (es_desc == NULL) return;
// get the decoder config descriptor
const AP4_DecoderConfigDescriptor* dc_desc =
es_desc->GetDecoderConfigDescriptor();
if (dc_desc) {
m_StreamType = dc_desc->GetStreamType();
m_ObjectTypeId = dc_desc->GetObjectTypeIndication();
m_BufferSize = dc_desc->GetBufferSize();
m_MaxBitrate = dc_desc->GetMaxBitrate();
m_AvgBitrate = dc_desc->GetAvgBitrate();
const AP4_DecoderSpecificInfoDescriptor* dsi_desc =
dc_desc->GetDecoderSpecificInfoDescriptor();
if (dsi_desc != NULL) {
m_DecoderInfo.SetData(dsi_desc->GetDecoderSpecificInfo().GetData(),
dsi_desc->GetDecoderSpecificInfo().GetDataSize());
}
}
}
}
/*----------------------------------------------------------------------
| AP4_MpegSampleDescription::AP4_MpegSampleDescription
+---------------------------------------------------------------------*/
AP4_MpegSampleDescription::AP4_MpegSampleDescription(
AP4_UI32 format,
StreamType stream_type,
OTI oti,
const AP4_DataBuffer* decoder_info,
AP4_UI32 buffer_size,
AP4_UI32 max_bitrate,
AP4_UI32 avg_bitrate) :
AP4_SampleDescription(TYPE_MPEG, format, NULL),
m_StreamType(stream_type),
m_ObjectTypeId(oti),
m_BufferSize(buffer_size),
m_MaxBitrate(max_bitrate),
m_AvgBitrate(avg_bitrate)
{
if (decoder_info != NULL) {
m_DecoderInfo.SetData(decoder_info->GetData(), decoder_info->GetDataSize());
}
}
/*----------------------------------------------------------------------
| AP4_MpegSampleDescription::CreateEsDescriptor
+---------------------------------------------------------------------*/
AP4_EsDescriptor*
AP4_MpegSampleDescription::CreateEsDescriptor() const
{
AP4_EsDescriptor* desc = new AP4_EsDescriptor(0);
AP4_DecoderSpecificInfoDescriptor* dsi_desc;
if (m_DecoderInfo.GetDataSize() != 0) {
dsi_desc = new AP4_DecoderSpecificInfoDescriptor(m_DecoderInfo);
} else {
dsi_desc = NULL;
}
AP4_DecoderConfigDescriptor* decoder_config =
new AP4_DecoderConfigDescriptor(m_StreamType,
m_ObjectTypeId,
m_BufferSize,
m_MaxBitrate,
m_AvgBitrate,
dsi_desc);
desc->AddSubDescriptor(decoder_config);
// add a fixed SL Config
desc->AddSubDescriptor(new AP4_SLConfigDescriptor());
return desc;
}
/*----------------------------------------------------------------------
| AP4_MpegSystemSampleDescription::AP4_MpegSystemSampleDescription
+---------------------------------------------------------------------*/
AP4_MpegSystemSampleDescription::AP4_MpegSystemSampleDescription(AP4_EsdsAtom* esds) :
AP4_MpegSampleDescription(AP4_ATOM_TYPE_MP4S, esds)
{
}
/*----------------------------------------------------------------------
| AP4_MpegSystemSampleDescription::AP4_MpegSystemSampleDescription
+---------------------------------------------------------------------*/
AP4_MpegSystemSampleDescription::AP4_MpegSystemSampleDescription(
StreamType stream_type,
OTI oti,
const AP4_DataBuffer* decoder_info,
AP4_UI32 buffer_size,
AP4_UI32 max_bitrate,
AP4_UI32 avg_bitrate) :
AP4_MpegSampleDescription(AP4_ATOM_TYPE_MP4S,
stream_type,
oti,
decoder_info,
buffer_size,
max_bitrate,
avg_bitrate)
{
}
/*----------------------------------------------------------------------
| AP4_MpegSystemSampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_MpegSystemSampleDescription::ToAtom() const
{
return new AP4_Mp4sSampleEntry(CreateEsDescriptor());
}
/*----------------------------------------------------------------------
| AP4_MpegAudioSampleDescription::AP4_MpegAudioSampleDescription
+---------------------------------------------------------------------*/
AP4_MpegAudioSampleDescription::AP4_MpegAudioSampleDescription(
AP4_UI32 sample_rate,
AP4_UI16 sample_size,
AP4_UI16 channel_count,
AP4_EsdsAtom* esds) :
AP4_MpegSampleDescription(AP4_ATOM_TYPE_MP4A, esds),
AP4_AudioSampleDescription(sample_rate, sample_size, channel_count)
{
}
/*----------------------------------------------------------------------
| AP4_MpegAudioSampleDescription::AP4_MpegAudioSampleDescription
+---------------------------------------------------------------------*/
AP4_MpegAudioSampleDescription::AP4_MpegAudioSampleDescription(
OTI oti,
AP4_UI32 sample_rate,
AP4_UI16 sample_size,
AP4_UI16 channel_count,
const AP4_DataBuffer* decoder_info,
AP4_UI32 buffer_size,
AP4_UI32 max_bitrate,
AP4_UI32 avg_bitrate) :
AP4_MpegSampleDescription(AP4_ATOM_TYPE_MP4A,
AP4_STREAM_TYPE_AUDIO,
oti,
decoder_info, buffer_size,
max_bitrate, avg_bitrate),
AP4_AudioSampleDescription(sample_rate, sample_size, channel_count)
{
}
/*----------------------------------------------------------------------
| AP4_MpegAudioSampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_MpegAudioSampleDescription::ToAtom() const
{
return new AP4_Mp4aSampleEntry(m_SampleRate<<16,
m_SampleSize,
m_ChannelCount,
CreateEsDescriptor());
}
/*----------------------------------------------------------------------
| AP4_MpegAudioSampleDescription::GetCodecString
+---------------------------------------------------------------------*/
AP4_Result
AP4_MpegAudioSampleDescription::GetCodecString(AP4_String& codec)
{
char coding[5];
AP4_FormatFourChars(coding, GetFormat());
char workspace[64];
workspace[0] = 0;
if (GetFormat() == AP4_SAMPLE_FORMAT_MP4A) {
if (GetObjectTypeId() == AP4_OTI_MPEG4_AUDIO) {
Mpeg4AudioObjectType object_type = GetMpeg4AudioObjectType();
if (object_type == AP4_MPEG4_AUDIO_OBJECT_TYPE_AAC_LC) {
const AP4_DataBuffer& dsi = GetDecoderInfo();
if (dsi.GetDataSize()) {
AP4_Mp4AudioDecoderConfig dec_config;
AP4_Result result = dec_config.Parse(dsi.GetData(), dsi.GetDataSize());
if (AP4_SUCCEEDED(result)) {
if (dec_config.m_Extension.m_PsPresent) {
object_type = AP4_MPEG4_AUDIO_OBJECT_TYPE_PS;
} else if (dec_config.m_Extension.m_SbrPresent) {
object_type = AP4_MPEG4_AUDIO_OBJECT_TYPE_SBR;
}
}
}
}
AP4_FormatString(workspace, sizeof(workspace), "%s.%02X.%d", coding, (int)GetObjectTypeId(), object_type);
} else {
AP4_FormatString(workspace, sizeof(workspace), "%s.%02X", coding, (int)GetObjectTypeId());
}
}
codec = workspace;
return AP4_SUCCESS;
}
/*----------------------------------------------------------------------
| AP4_MpegAudioSampleDescription::GetMpeg4AudioObjectType
+---------------------------------------------------------------------*/
AP4_MpegAudioSampleDescription::Mpeg4AudioObjectType
AP4_MpegAudioSampleDescription::GetMpeg4AudioObjectType() const
{
if (m_ObjectTypeId == AP4_OTI_MPEG4_AUDIO &&
m_DecoderInfo.GetDataSize() >= 1) {
AP4_UI08 type = m_DecoderInfo.GetData()[0]>>3;
if (type == 31) {
if (m_DecoderInfo.GetDataSize() < 2) return 0;
type = 32+(((m_DecoderInfo.GetData()[0]&0x07)<<3) |
((m_DecoderInfo.GetData()[1]&0xE0)>>5));
}
return type;
} else {
return 0;
}
}
/*----------------------------------------------------------------------
| AP4_Ac3SampleDescription::AP4_Ac3SampleDescription
+---------------------------------------------------------------------*/
AP4_Ac3SampleDescription::AP4_Ac3SampleDescription(AP4_UI32 sample_rate,
AP4_UI16 sample_size,
AP4_UI16 channel_count,
const AP4_Dac3Atom* dac3):
AP4_SampleDescription(TYPE_AC3, AP4_SAMPLE_FORMAT_AC_3, NULL),
AP4_AudioSampleDescription(sample_rate, sample_size, channel_count)
{
if (dac3) {
m_Dac3Atom = new AP4_Dac3Atom(*dac3);
} else {
// TODO: add default construtor, m_Dac3Atom = new AP4_Dac3Atom() / should never happen
m_Dac3Atom = NULL;
}
m_Details.AddChild(m_Dac3Atom);
}
/*----------------------------------------------------------------------
| AP4_Ac3SampleDescription::AP4_Ac3SampleDescription
+---------------------------------------------------------------------*/
AP4_Ac3SampleDescription::AP4_Ac3SampleDescription(AP4_UI32 sample_rate,
AP4_UI16 sample_size,
AP4_UI16 channel_count,
AP4_AtomParent* details) :
AP4_SampleDescription(TYPE_AC3, AP4_SAMPLE_FORMAT_AC_3, details),
AP4_AudioSampleDescription(sample_rate, sample_size, channel_count),
m_Dac3Atom(NULL)
{
AP4_Dac3Atom* ac3 = AP4_DYNAMIC_CAST(AP4_Dac3Atom, m_Details.GetChild(AP4_SAMPLE_FORMAT_AC_3));
if (ac3) {
m_Dac3Atom = ac3;
} else {
// TODO: add default construtor, m_Dac3Atom = new AP4_Dac3Atom() / should never happen
m_Dac3Atom = NULL;
m_Details.AddChild(m_Dac3Atom);
}
}
/*----------------------------------------------------------------------
| AP4_Ac3SampleDescription::AP4_Ac3SampleDescription
+---------------------------------------------------------------------*/
AP4_Ac3SampleDescription::AP4_Ac3SampleDescription(AP4_UI32 sample_rate,
AP4_UI16 sample_size,
AP4_UI16 channel_count,
AP4_UI32 size,
const AP4_Dac3Atom::StreamInfo* ac3_stream_info):
AP4_SampleDescription(TYPE_AC3, AP4_SAMPLE_FORMAT_AC_3, NULL),
AP4_AudioSampleDescription(sample_rate, sample_size, channel_count)
{
m_Dac3Atom = new AP4_Dac3Atom(ac3_stream_info);
m_Details.AddChild(m_Dac3Atom);
}
/*----------------------------------------------------------------------
| AP4_Ac3SampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_Ac3SampleDescription::ToAtom() const
{
return new AP4_Ac3SampleEntry(m_Format,
m_SampleRate<<16,
m_SampleSize,
m_ChannelCount,
&m_Details);
}
/*----------------------------------------------------------------------
| AP4_Eac3SampleDescription::AP4_Eac3SampleDescription
+---------------------------------------------------------------------*/
AP4_Eac3SampleDescription::AP4_Eac3SampleDescription():
AP4_SampleDescription(TYPE_EAC3, AP4_SAMPLE_FORMAT_EC_3, NULL),
AP4_AudioSampleDescription(48000, 16, 2)
{
m_Details.AddChild(new AP4_Dec3Atom());
}
/*----------------------------------------------------------------------
| AP4_Eac3SampleDescription::AP4_Eac3SampleDescription
+---------------------------------------------------------------------*/
AP4_Eac3SampleDescription::AP4_Eac3SampleDescription(AP4_UI32 sample_rate,
AP4_UI16 sample_size,
AP4_UI16 channel_count,
const AP4_Dec3Atom* dec3):
AP4_SampleDescription(TYPE_EAC3, AP4_SAMPLE_FORMAT_EC_3, NULL),
AP4_AudioSampleDescription(sample_rate, sample_size, channel_count)
{
if (dec3) {
m_Dec3Atom = new AP4_Dec3Atom(*dec3);
} else {
// shoud never happen
m_Dec3Atom = new AP4_Dec3Atom();
}
m_Details.AddChild(m_Dec3Atom);
}
/*----------------------------------------------------------------------
| AP4_Eac3SampleDescription::AP4_Eac3SampleDescription
+---------------------------------------------------------------------*/
AP4_Eac3SampleDescription::AP4_Eac3SampleDescription(AP4_UI32 sample_rate,
AP4_UI16 sample_size,
AP4_UI16 channel_count,
AP4_AtomParent* details) :
AP4_SampleDescription(TYPE_EAC3, AP4_SAMPLE_FORMAT_EC_3, details),
AP4_AudioSampleDescription(sample_rate, sample_size, channel_count),
m_Dec3Atom(NULL)
{
AP4_Dec3Atom* eac3 = AP4_DYNAMIC_CAST(AP4_Dec3Atom, m_Details.GetChild(AP4_SAMPLE_FORMAT_EC_3));
if (eac3) {
m_Dec3Atom = eac3;
} else {
// shoud never happen
m_Dec3Atom = new AP4_Dec3Atom();
m_Details.AddChild(m_Dec3Atom);
}
}
/*----------------------------------------------------------------------
| AP4_Eac3SampleDescription::AP4_Eac3SampleDescription
+---------------------------------------------------------------------*/
AP4_Eac3SampleDescription::AP4_Eac3SampleDescription(AP4_UI32 sample_rate,
AP4_UI16 sample_size,
AP4_UI16 channel_count,
AP4_UI32 size,
const AP4_Dec3Atom::SubStream* subStream,
const AP4_UI32 complexity_index_type_a):
AP4_SampleDescription(TYPE_EAC3, AP4_SAMPLE_FORMAT_EC_3, NULL),
AP4_AudioSampleDescription(sample_rate, sample_size, channel_count)
{
m_Dec3Atom = new AP4_Dec3Atom(size, subStream, complexity_index_type_a);
m_Details.AddChild(m_Dec3Atom);
}
/*----------------------------------------------------------------------
| AP4_Eac3SampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_Eac3SampleDescription::ToAtom() const
{
return new AP4_Eac3SampleEntry(m_Format,
m_SampleRate<<16,
m_SampleSize,
m_ChannelCount,
&m_Details);
}
/*----------------------------------------------------------------------
| AP4_Ac4SampleDescription::AP4_Ac4SampleDescription
+---------------------------------------------------------------------*/
AP4_Ac4SampleDescription::AP4_Ac4SampleDescription(AP4_UI32 sample_rate,
AP4_UI16 sample_size,
AP4_UI16 channel_count,
const AP4_Dac4Atom* dac4):
AP4_SampleDescription(TYPE_AC4, AP4_SAMPLE_FORMAT_AC_4, NULL),
AP4_AudioSampleDescription(sample_rate, sample_size, channel_count)
{
if (dac4) {
m_Dac4Atom = dac4->CloneConst();
;
} else {
// TODO: add default construtor, m_Dac4Atom = new AP4_Dac4Atom() / should never happen
m_Dac4Atom = NULL;
}
m_Details.AddChild(m_Dac4Atom);
}
/*----------------------------------------------------------------------
| AP4_Ac4SampleDescription::AP4_Ac4SampleDescription
+---------------------------------------------------------------------*/
AP4_Ac4SampleDescription::AP4_Ac4SampleDescription(AP4_UI32 sample_rate,
AP4_UI16 sample_size,
AP4_UI16 channel_count,
AP4_AtomParent* details) :
AP4_SampleDescription(TYPE_AC4, AP4_SAMPLE_FORMAT_AC_4, details),
AP4_AudioSampleDescription(sample_rate, sample_size, channel_count),
m_Dac4Atom(NULL)
{
AP4_Dac4Atom* ac4 = AP4_DYNAMIC_CAST(AP4_Dac4Atom, m_Details.GetChild(AP4_ATOM_TYPE_AC_4));
if (ac4) {
m_Dac4Atom = ac4;
} else {
// TODO: add default construtor, m_Dac4Atom = new AP4_Dac4Atom() / should never happen
m_Dac4Atom = NULL;
m_Details.AddChild(m_Dac4Atom);
}
}
/*----------------------------------------------------------------------
| AP4_Ac4SampleDescription::AP4_Ac4SampleDescription
+---------------------------------------------------------------------*/
AP4_Ac4SampleDescription::AP4_Ac4SampleDescription(AP4_UI32 sample_rate,
AP4_UI16 sample_size,
AP4_UI16 channel_count,
AP4_UI32 size,
const AP4_Dac4Atom::Ac4Dsi* ac4Dsi):
AP4_SampleDescription(TYPE_AC4, AP4_SAMPLE_FORMAT_AC_4, NULL),
AP4_AudioSampleDescription(sample_rate, sample_size, channel_count)
{
m_Dac4Atom = new AP4_Dac4Atom(size, ac4Dsi);
m_Details.AddChild(m_Dac4Atom);
}
/*----------------------------------------------------------------------
| AP4_Ac4SampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_Ac4SampleDescription::ToAtom() const
{
return new AP4_Ac4SampleEntry(m_Format,
m_SampleRate<<16,
m_SampleSize,
m_ChannelCount,
&m_Details);
}
/*----------------------------------------------------------------------
| AP4_MpegVideoSampleDescription::AP4_MpegVideoSampleDescription
+---------------------------------------------------------------------*/
AP4_MpegVideoSampleDescription::AP4_MpegVideoSampleDescription(
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
AP4_EsdsAtom* esds) :
AP4_MpegSampleDescription(AP4_ATOM_TYPE_MP4V, esds),
AP4_VideoSampleDescription(width, height, depth, compressor_name)
{
}
/*----------------------------------------------------------------------
| AP4_MpegVideoSampleDescription::AP4_MpegVideoSampleDescription
+---------------------------------------------------------------------*/
AP4_MpegVideoSampleDescription::AP4_MpegVideoSampleDescription(
OTI oti,
AP4_UI16 width,
AP4_UI16 height,
AP4_UI16 depth,
const char* compressor_name,
const AP4_DataBuffer* decoder_info,
AP4_UI32 buffer_size,
AP4_UI32 max_bitrate,
AP4_UI32 avg_bitrate) :
AP4_MpegSampleDescription(AP4_ATOM_TYPE_MP4V,
AP4_STREAM_TYPE_VISUAL,
oti,
decoder_info,
buffer_size,
max_bitrate,
avg_bitrate),
AP4_VideoSampleDescription(width, height, depth, compressor_name)
{
}
/*----------------------------------------------------------------------
| AP4_MpegVideoSampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_MpegVideoSampleDescription::ToAtom() const
{
return new AP4_Mp4vSampleEntry(m_Width,
m_Height,
m_Depth,
m_CompressorName.GetChars(),
CreateEsDescriptor());
}
/*----------------------------------------------------------------------
| AP4_MpegSampleDescription::GetStreamTypeString
+---------------------------------------------------------------------*/
const char*
AP4_MpegSampleDescription::GetStreamTypeString(StreamType type)
{
switch (type) {
case AP4_STREAM_TYPE_FORBIDDEN: return "INVALID";
case AP4_STREAM_TYPE_OD: return "Object Descriptor";
case AP4_STREAM_TYPE_CR: return "CR";
case AP4_STREAM_TYPE_BIFS: return "BIFS";
case AP4_STREAM_TYPE_VISUAL: return "Visual";
case AP4_STREAM_TYPE_AUDIO: return "Audio";
case AP4_STREAM_TYPE_MPEG7: return "MPEG-7";
case AP4_STREAM_TYPE_IPMP: return "IPMP";
case AP4_STREAM_TYPE_OCI: return "OCI";
case AP4_STREAM_TYPE_MPEGJ: return "MPEG-J";
default: return "UNKNOWN";
}
}
/*----------------------------------------------------------------------
| AP4_MpegSampleDescription::GetObjectTypeString
+---------------------------------------------------------------------*/
const char*
AP4_MpegSampleDescription::GetObjectTypeString(OTI oti)
{
switch (oti) {
case AP4_OTI_MPEG4_SYSTEM: return "MPEG-4 System";
case AP4_OTI_MPEG4_SYSTEM_COR: return "MPEG-4 System COR";
case AP4_OTI_MPEG4_VISUAL: return "MPEG-4 Video";
case AP4_OTI_MPEG4_AUDIO: return "MPEG-4 Audio";
case AP4_OTI_MPEG2_VISUAL_SIMPLE: return "MPEG-2 Video Simple Profile";
case AP4_OTI_MPEG2_VISUAL_MAIN: return "MPEG-2 Video Main Profile";
case AP4_OTI_MPEG2_VISUAL_SNR: return "MPEG-2 Video SNR";
case AP4_OTI_MPEG2_VISUAL_SPATIAL: return "MPEG-2 Video Spatial";
case AP4_OTI_MPEG2_VISUAL_HIGH: return "MPEG-2 Video High";
case AP4_OTI_MPEG2_VISUAL_422: return "MPEG-2 Video 4:2:2";
case AP4_OTI_MPEG2_AAC_AUDIO_MAIN: return "MPEG-2 Audio AAC Main Profile";
case AP4_OTI_MPEG2_AAC_AUDIO_LC: return "MPEG-2 Audio AAC Low Complexity";
case AP4_OTI_MPEG2_AAC_AUDIO_SSRP: return "MPEG-2 Audio AAC SSRP";
case AP4_OTI_MPEG2_PART3_AUDIO: return "MPEG-2 Audio Part-3";
case AP4_OTI_MPEG1_VISUAL: return "MPEG-1 Video";
case AP4_OTI_MPEG1_AUDIO: return "MPEG-1 Audio";
case AP4_OTI_JPEG: return "JPEG";
case AP4_OTI_JPEG2000: return "JPEG-2000";
case AP4_OTI_EVRC_VOICE: return "EVRC Voice";
case AP4_OTI_SMV_VOICE: return "SMV Voice";
case AP4_OTI_3GPP2_CMF: return "3GPP2 CMF";
case AP4_OTI_SMPTE_VC1: return "SMPTE VC1 Video";
case AP4_OTI_DIRAC_VIDEO: return "Dirac Video";
case AP4_OTI_AC3_AUDIO: return "AC3 Audio";
case AP4_OTI_EAC3_AUDIO: return "E-AC3 Audio";
case AP4_OTI_DRA_AUDIO: return "DRA Audio";
case AP4_OTI_G719_AUDIO: return "G.719 Audio";
case AP4_OTI_DTS_AUDIO: return "DTS Audio";
case AP4_OTI_DTS_HIRES_AUDIO: return "DTS High Resolution Audio";
case AP4_OTI_DTS_MASTER_AUDIO: return "DTS Master Audio";
case AP4_OTI_DTS_EXPRESS_AUDIO: return "DTS Express/LBR Audio";
case AP4_OTI_OPUS_AUDIO: return "Opus Audio";
case AP4_OTI_VP9_VIDEO: return "VP9 Video";
case AP4_OTI_VORBIS_AUDIO: return "Vorbis Audio";
case AP4_OTI_13K_VOICE: return "13K Voice";
default: return "UNKNOWN";
}
}
/*----------------------------------------------------------------------
| AP4_MpegAudioSampleDescription::GetMpeg4AudioObjectTypeString
+---------------------------------------------------------------------*/
const char*
AP4_MpegAudioSampleDescription::GetMpeg4AudioObjectTypeString(Mpeg4AudioObjectType type)
{
switch (type) {
case AP4_MPEG4_AUDIO_OBJECT_TYPE_AAC_MAIN: return "AAC Main Profile";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_AAC_LC: return "AAC Low Complexity";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_AAC_SSR: return "AAC Scalable Sample Rate";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_AAC_LTP: return "AAC Long Term Predictor";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_SBR: return "Spectral Band Replication";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_AAC_SCALABLE: return "AAC Scalable";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_TWINVQ: return "Twin VQ";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_CELP: return "CELP";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_HVXC: return "HVXC";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_TTSI: return "TTSI";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_MAIN_SYNTHETIC: return "Main Synthetic";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_WAVETABLE_SYNTHESIS: return "Wavetable Synthesis";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_GENERAL_MIDI: return "General MIDI";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ALGORITHMIC_SYNTHESIS: return "Algorithmic Synthesis";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ER_AAC_LC: return "Error Resilient AAC Low Complexity";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ER_AAC_LTP: return "Error Resilient AAC Long Term Prediction";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ER_AAC_SCALABLE: return "Error Resilient AAC Scalable";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ER_TWINVQ: return "Error Resilient Twin VQ";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ER_BSAC: return "Error Resilient Bit Sliced Arithmetic Coding";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ER_AAC_LD: return "Error Resilient AAC Low Delay";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ER_CELP: return "Error Resilient CELP";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ER_HVXC: return "Error Resilient HVXC";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ER_HILN: return "Error Resilient HILN";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ER_PARAMETRIC: return "Error Resilient Parametric";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_SSC: return "SSC";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_PS: return "Parametric Stereo";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_MPEG_SURROUND: return "MPEG Surround";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_LAYER_1: return "MPEG Layer 1";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_LAYER_2: return "MPEG Layer 2";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_LAYER_3: return "MPEG Layer 3";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_DST: return "Direct Stream Transfer";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ALS: return "ALS Lossless Coding";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_SLS: return "SLS Scalable Lossless Coding";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_SLS_NON_CORE: return "SLS Scalable Lossless Coding (Non Core)";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_ER_AAC_ELD: return "Error Resilient AAC ELD";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_SMR_SIMPLE: return "SMR Simple";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_SMR_MAIN: return "SMR Main";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_USAC: return "USAC";
case AP4_MPEG4_AUDIO_OBJECT_TYPE_SAOC: return "SAOC";
default: return "UNKNOWN";
}
}
/*----------------------------------------------------------------------
| AP4_SubtitleSampleDescription::AP4_SubtitleSampleDescription
+---------------------------------------------------------------------*/
AP4_SubtitleSampleDescription::AP4_SubtitleSampleDescription(AP4_UI32 format,
const char* namespce,
const char* schema_location,
const char* image_mime_type) :
AP4_SampleDescription(AP4_SampleDescription::TYPE_SUBTITLES, format, NULL),
m_Namespace(namespce),
m_SchemaLocation(schema_location),
m_ImageMimeType(image_mime_type)
{
}
/*----------------------------------------------------------------------
| AP4_SubtitleSampleDescription::Clone
+---------------------------------------------------------------------*/
AP4_SampleDescription*
AP4_SubtitleSampleDescription::Clone(AP4_Result* result)
{
if (result) *result = AP4_SUCCESS;
return new AP4_SubtitleSampleDescription(m_Format,
m_Namespace.GetChars(),
m_SchemaLocation.GetChars(),
m_ImageMimeType.GetChars());
}
/*----------------------------------------------------------------------
| AP4_SubtitleSampleDescription::ToAtom
+---------------------------------------------------------------------*/
AP4_Atom*
AP4_SubtitleSampleDescription::ToAtom() const
{
return new AP4_SubtitleSampleEntry(m_Format,
m_Namespace.GetChars(),
m_SchemaLocation.GetChars(),
m_ImageMimeType.GetChars());
}
|