summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/mp3dec
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2010-06-23 11:11:58 -0700
committerAndreas Huber <andih@google.com>2010-06-23 11:11:58 -0700
commit3e0339f9ec42c2c31deb632254e9cc8a06d3db91 (patch)
treed85036dff22fd4a5a87e1592e405b65dda3b4e9a /media/libstagefright/codecs/mp3dec
parentdadd0d1e7d5fbb88fd3420438c590a0bb4c18af5 (diff)
downloadframeworks_av-3e0339f9ec42c2c31deb632254e9cc8a06d3db91.zip
frameworks_av-3e0339f9ec42c2c31deb632254e9cc8a06d3db91.tar.gz
frameworks_av-3e0339f9ec42c2c31deb632254e9cc8a06d3db91.tar.bz2
Fix a number of timestamp mismatches in the mp3 extractor and decoder that would lead to invalid reporting of the current playback time for mono and/or non-44100 kHz mp3s.
Change-Id: I11abc05b62a958ffbc99ca997cd184a2f2199352 related-to-bug: 2667479
Diffstat (limited to 'media/libstagefright/codecs/mp3dec')
-rw-r--r--media/libstagefright/codecs/mp3dec/MP3Decoder.cpp57
1 files changed, 30 insertions, 27 deletions
diff --git a/media/libstagefright/codecs/mp3dec/MP3Decoder.cpp b/media/libstagefright/codecs/mp3dec/MP3Decoder.cpp
index efcb476..f40bd11 100644
--- a/media/libstagefright/codecs/mp3dec/MP3Decoder.cpp
+++ b/media/libstagefright/codecs/mp3dec/MP3Decoder.cpp
@@ -27,13 +27,35 @@ namespace android {
MP3Decoder::MP3Decoder(const sp<MediaSource> &source)
: mSource(source),
+ mNumChannels(0),
mStarted(false),
mBufferGroup(NULL),
mConfig(new tPVMP3DecoderExternal),
mDecoderBuf(NULL),
mAnchorTimeUs(0),
- mNumSamplesOutput(0),
+ mNumFramesOutput(0),
mInputBuffer(NULL) {
+ init();
+}
+
+void MP3Decoder::init() {
+ sp<MetaData> srcFormat = mSource->getFormat();
+
+ int32_t sampleRate;
+ CHECK(srcFormat->findInt32(kKeyChannelCount, &mNumChannels));
+ CHECK(srcFormat->findInt32(kKeySampleRate, &sampleRate));
+
+ mMeta = new MetaData;
+ mMeta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_RAW);
+ mMeta->setInt32(kKeyChannelCount, mNumChannels);
+ mMeta->setInt32(kKeySampleRate, sampleRate);
+
+ int64_t durationUs;
+ if (srcFormat->findInt64(kKeyDuration, &durationUs)) {
+ mMeta->setInt64(kKeyDuration, durationUs);
+ }
+
+ mMeta->setCString(kKeyDecoderComponent, "MP3Decoder");
}
MP3Decoder::~MP3Decoder() {
@@ -62,7 +84,7 @@ status_t MP3Decoder::start(MetaData *params) {
mSource->start();
mAnchorTimeUs = 0;
- mNumSamplesOutput = 0;
+ mNumFramesOutput = 0;
mStarted = true;
return OK;
@@ -90,26 +112,7 @@ status_t MP3Decoder::stop() {
}
sp<MetaData> MP3Decoder::getFormat() {
- sp<MetaData> srcFormat = mSource->getFormat();
-
- int32_t numChannels;
- int32_t sampleRate;
- CHECK(srcFormat->findInt32(kKeyChannelCount, &numChannels));
- CHECK(srcFormat->findInt32(kKeySampleRate, &sampleRate));
-
- sp<MetaData> meta = new MetaData;
- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_RAW);
- meta->setInt32(kKeyChannelCount, numChannels);
- meta->setInt32(kKeySampleRate, sampleRate);
-
- int64_t durationUs;
- if (srcFormat->findInt64(kKeyDuration, &durationUs)) {
- meta->setInt64(kKeyDuration, durationUs);
- }
-
- meta->setCString(kKeyDecoderComponent, "MP3Decoder");
-
- return meta;
+ return mMeta;
}
status_t MP3Decoder::read(
@@ -122,7 +125,7 @@ status_t MP3Decoder::read(
if (options && options->getSeekTo(&seekTimeUs)) {
CHECK(seekTimeUs >= 0);
- mNumSamplesOutput = 0;
+ mNumFramesOutput = 0;
if (mInputBuffer) {
mInputBuffer->release();
@@ -142,7 +145,7 @@ status_t MP3Decoder::read(
int64_t timeUs;
if (mInputBuffer->meta_data()->findInt64(kKeyTime, &timeUs)) {
mAnchorTimeUs = timeUs;
- mNumSamplesOutput = 0;
+ mNumFramesOutput = 0;
} else {
// We must have a new timestamp after seeking.
CHECK(seekTimeUs < 0);
@@ -179,7 +182,7 @@ status_t MP3Decoder::read(
// This is recoverable, just ignore the current frame and
// play silence instead.
- memset(buffer->data(), 0, mConfig->outputFrameSize);
+ memset(buffer->data(), 0, mConfig->outputFrameSize * sizeof(int16_t));
mConfig->inputBufferUsedLength = mInputBuffer->range_length();
}
@@ -198,9 +201,9 @@ status_t MP3Decoder::read(
buffer->meta_data()->setInt64(
kKeyTime,
mAnchorTimeUs
- + (mNumSamplesOutput * 1000000) / mConfig->samplingRate);
+ + (mNumFramesOutput * 1000000) / mConfig->samplingRate);
- mNumSamplesOutput += mConfig->outputFrameSize / sizeof(int16_t);
+ mNumFramesOutput += mConfig->outputFrameSize / mNumChannels;
*out = buffer;