Skip to content

Commit 8320e70

Browse files
theandi666Android (Google) Code Review
authored andcommitted
Merge "MatroskaExtractor: to support MPEG4 and MP3 codec."
2 parents 43d5922 + a8854b2 commit 8320e70

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

media/libstagefright/matroska/MatroskaExtractor.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -610,36 +610,41 @@ bool MatroskaExtractor::isLiveStreaming() const {
610610
return mIsLiveStreaming;
611611
}
612612

613-
static void addESDSFromAudioSpecificInfo(
614-
const sp<MetaData> &meta, const void *asi, size_t asiSize) {
613+
static void addESDSFromCodecPrivate(
614+
const sp<MetaData> &meta,
615+
bool isAudio, const void *priv, size_t privSize) {
615616
static const uint8_t kStaticESDS[] = {
616617
0x03, 22,
617618
0x00, 0x00, // ES_ID
618619
0x00, // streamDependenceFlag, URL_Flag, OCRstreamFlag
619620

620621
0x04, 17,
621-
0x40, // Audio ISO/IEC 14496-3
622+
0x40, // ObjectTypeIndication
622623
0x00, 0x00, 0x00, 0x00,
623624
0x00, 0x00, 0x00, 0x00,
624625
0x00, 0x00, 0x00, 0x00,
625626

626627
0x05,
627-
// AudioSpecificInfo (with size prefix) follows
628+
// CodecSpecificInfo (with size prefix) follows
628629
};
629630

630631
// Make sure all sizes can be coded in a single byte.
631-
CHECK(asiSize + 22 - 2 < 128);
632-
size_t esdsSize = sizeof(kStaticESDS) + asiSize + 1;
632+
CHECK(privSize + 22 - 2 < 128);
633+
size_t esdsSize = sizeof(kStaticESDS) + privSize + 1;
633634
uint8_t *esds = new uint8_t[esdsSize];
634635
memcpy(esds, kStaticESDS, sizeof(kStaticESDS));
635636
uint8_t *ptr = esds + sizeof(kStaticESDS);
636-
*ptr++ = asiSize;
637-
memcpy(ptr, asi, asiSize);
637+
*ptr++ = privSize;
638+
memcpy(ptr, priv, privSize);
638639

639640
// Increment by codecPrivateSize less 2 bytes that are accounted for
640641
// already in lengths of 22/17
641-
esds[1] += asiSize - 2;
642-
esds[6] += asiSize - 2;
642+
esds[1] += privSize - 2;
643+
esds[6] += privSize - 2;
644+
645+
// Set ObjectTypeIndication.
646+
esds[7] = isAudio ? 0x40 // Audio ISO/IEC 14496-3
647+
: 0x20; // Visual ISO/IEC 14496-2
643648

644649
meta->setData(kKeyESDS, 0, esds, esdsSize);
645650

@@ -707,9 +712,21 @@ void MatroskaExtractor::addTracks() {
707712
if (!strcmp("V_MPEG4/ISO/AVC", codecID)) {
708713
meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
709714
meta->setData(kKeyAVCC, 0, codecPrivate, codecPrivateSize);
715+
} else if (!strcmp("V_MPEG4/ISO/ASP", codecID)) {
716+
if (codecPrivateSize > 0) {
717+
meta->setCString(
718+
kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG4);
719+
addESDSFromCodecPrivate(
720+
meta, false, codecPrivate, codecPrivateSize);
721+
} else {
722+
ALOGW("%s is detected, but does not have configuration.",
723+
codecID);
724+
continue;
725+
}
710726
} else if (!strcmp("V_VP8", codecID)) {
711727
meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_VPX);
712728
} else {
729+
ALOGW("%s is not supported.", codecID);
713730
continue;
714731
}
715732

@@ -727,13 +744,16 @@ void MatroskaExtractor::addTracks() {
727744
meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AAC);
728745
CHECK(codecPrivateSize >= 2);
729746

730-
addESDSFromAudioSpecificInfo(
731-
meta, codecPrivate, codecPrivateSize);
747+
addESDSFromCodecPrivate(
748+
meta, true, codecPrivate, codecPrivateSize);
732749
} else if (!strcmp("A_VORBIS", codecID)) {
733750
meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_VORBIS);
734751

735752
addVorbisCodecInfo(meta, codecPrivate, codecPrivateSize);
753+
} else if (!strcmp("A_MPEG/L3", codecID)) {
754+
meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_MPEG);
736755
} else {
756+
ALOGW("%s is not supported.", codecID);
737757
continue;
738758
}
739759

0 commit comments

Comments
 (0)