Skip to content

Commit ceb0909

Browse files
marconeAndroid (Google) Code Review
authored andcommitted
Merge "Parse gapless info from mp4 files"
2 parents 6d332c5 + eb473f3 commit ceb0909

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

media/libstagefright/MPEG4Extractor.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ static void convertTimeToDate(int64_t time_1904, String8 *s) {
599599
}
600600

601601
status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
602+
ALOGV("entering parseChunk %lld/%d", *offset, depth);
602603
uint32_t hdr[2];
603604
if (mDataSource->readAt(*offset, hdr, 8) < 8) {
604605
return ERROR_IO;
@@ -625,6 +626,7 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
625626

626627
char chunk[5];
627628
MakeFourCCString(chunk_type, chunk);
629+
ALOGV("chunk: %s @ %lld", chunk, *offset);
628630

629631
#if 0
630632
static const char kWhitespace[] = " ";
@@ -1302,6 +1304,8 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
13021304
break;
13031305
}
13041306

1307+
case FOURCC('m', 'e', 'a', 'n'):
1308+
case FOURCC('n', 'a', 'm', 'e'):
13051309
case FOURCC('d', 'a', 't', 'a'):
13061310
{
13071311
if (mPath.size() == 6 && underMetaDataPath(mPath)) {
@@ -1437,6 +1441,15 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
14371441
break;
14381442
}
14391443

1444+
case FOURCC('-', '-', '-', '-'):
1445+
{
1446+
mLastCommentMean.clear();
1447+
mLastCommentName.clear();
1448+
mLastCommentData.clear();
1449+
*offset += chunk_size;
1450+
break;
1451+
}
1452+
14401453
default:
14411454
{
14421455
*offset += chunk_size;
@@ -1553,6 +1566,9 @@ status_t MPEG4Extractor::parseMetaData(off64_t offset, size_t size) {
15531566
uint32_t flags = U32_AT(buffer);
15541567

15551568
uint32_t metadataKey = 0;
1569+
char chunk[5];
1570+
MakeFourCCString(mPath[4], chunk);
1571+
ALOGV("meta: %s @ %lld", chunk, offset);
15561572
switch (mPath[4]) {
15571573
case FOURCC(0xa9, 'a', 'l', 'b'):
15581574
{
@@ -1632,6 +1648,35 @@ status_t MPEG4Extractor::parseMetaData(off64_t offset, size_t size) {
16321648
}
16331649
break;
16341650
}
1651+
case FOURCC('-', '-', '-', '-'):
1652+
{
1653+
buffer[size] = '\0';
1654+
switch (mPath[5]) {
1655+
case FOURCC('m', 'e', 'a', 'n'):
1656+
mLastCommentMean.setTo((const char *)buffer + 4);
1657+
break;
1658+
case FOURCC('n', 'a', 'm', 'e'):
1659+
mLastCommentName.setTo((const char *)buffer + 4);
1660+
break;
1661+
case FOURCC('d', 'a', 't', 'a'):
1662+
mLastCommentData.setTo((const char *)buffer + 8);
1663+
break;
1664+
}
1665+
if (mLastCommentMean == "com.apple.iTunes"
1666+
&& mLastCommentName == "iTunSMPB"
1667+
&& mLastCommentData.length() != 0) {
1668+
int32_t delay, padding;
1669+
if (sscanf(mLastCommentData,
1670+
" %*x %x %x %*x", &delay, &padding) == 2) {
1671+
mLastTrack->meta->setInt32(kKeyEncoderDelay, delay);
1672+
mLastTrack->meta->setInt32(kKeyEncoderPadding, padding);
1673+
}
1674+
mLastCommentMean.clear();
1675+
mLastCommentName.clear();
1676+
mLastCommentData.clear();
1677+
}
1678+
break;
1679+
}
16351680

16361681
default:
16371682
break;

media/libstagefright/include/MPEG4Extractor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <media/stagefright/MediaExtractor.h>
2222
#include <utils/Vector.h>
23+
#include <utils/String8.h>
2324

2425
namespace android {
2526

@@ -64,6 +65,9 @@ class MPEG4Extractor : public MediaExtractor {
6465
sp<MetaData> mFileMetaData;
6566

6667
Vector<uint32_t> mPath;
68+
String8 mLastCommentMean;
69+
String8 mLastCommentName;
70+
String8 mLastCommentData;
6771

6872
status_t readMetaData();
6973
status_t parseChunk(off64_t *offset, int depth);

0 commit comments

Comments
 (0)