summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Grossman <johngro@google.com>2012-08-29 14:51:01 -0700
committerJohn Grossman <johngro@google.com>2012-09-06 10:18:38 -0700
commita39ad61a1c9c69c2cc60f5d14243dd56040f8571 (patch)
tree244c5a5b7629f21a86a31a51afbad1ad91c3a124
parent0b73d4730202fcad53aefc4314a06e7b95f442f0 (diff)
downloadframeworks_av-a39ad61a1c9c69c2cc60f5d14243dd56040f8571.zip
frameworks_av-a39ad61a1c9c69c2cc60f5d14243dd56040f8571.tar.gz
frameworks_av-a39ad61a1c9c69c2cc60f5d14243dd56040f8571.tar.bz2
Fix calculations for an obscure combo of MPEG audio options.
MPEGv2 and MPEGv2.5 Layer 2 audio payloads should 1152 samples per access unit, not 576. Adjust the frame size and samples out calculations accordingly. Also, adjust the max frame size in the MP3Extractor's MediaSource to be closer to the theoretical worst case max frame size. The theoretical worst case for MPEG audio is 2881 bytes per frame, but the max frame size being used was 32kB. It has been changed to be 4kB in order to remain a power of 2 allocation, but to be the power of 2 closest to the worst case. Change-Id: If11f5a843b06e70151bbe8298cc54f954938d9d7
-rw-r--r--media/libstagefright/MP3Extractor.cpp9
-rw-r--r--media/libstagefright/avc_utils.cpp5
2 files changed, 11 insertions, 3 deletions
diff --git a/media/libstagefright/MP3Extractor.cpp b/media/libstagefright/MP3Extractor.cpp
index 6abaf23..d94054b 100644
--- a/media/libstagefright/MP3Extractor.cpp
+++ b/media/libstagefright/MP3Extractor.cpp
@@ -228,6 +228,7 @@ protected:
virtual ~MP3Source();
private:
+ static const size_t kMaxFrameSize;
sp<MetaData> mMeta;
sp<DataSource> mDataSource;
off64_t mFirstFramePos;
@@ -405,6 +406,13 @@ sp<MetaData> MP3Extractor::getTrackMetaData(size_t index, uint32_t flags) {
////////////////////////////////////////////////////////////////////////////////
+// The theoretical maximum frame size for an MPEG audio stream should occur
+// while playing a Layer 2, MPEGv2.5 audio stream at 160kbps (with padding).
+// The size of this frame should be...
+// ((1152 samples/frame * 160000 bits/sec) /
+// (8000 samples/sec * 8 bits/byte)) + 1 padding byte/frame = 2881 bytes/frame.
+// Set our max frame size to the nearest power of 2 above this size (aka, 4kB)
+const size_t MP3Source::kMaxFrameSize = (1 << 12); /* 4096 bytes */
MP3Source::MP3Source(
const sp<MetaData> &meta, const sp<DataSource> &source,
off64_t first_frame_pos, uint32_t fixed_header,
@@ -433,7 +441,6 @@ status_t MP3Source::start(MetaData *) {
mGroup = new MediaBufferGroup;
- const size_t kMaxFrameSize = 32768;
mGroup->add_buffer(new MediaBuffer(kMaxFrameSize));
mCurrentPos = mFirstFramePos;
diff --git a/media/libstagefright/avc_utils.cpp b/media/libstagefright/avc_utils.cpp
index 65c1848..a141752 100644
--- a/media/libstagefright/avc_utils.cpp
+++ b/media/libstagefright/avc_utils.cpp
@@ -600,7 +600,7 @@ bool GetMPEGAudioFrameSize(
bitrate = kBitrateV2[bitrate_index - 1];
if (out_num_samples) {
- *out_num_samples = 576;
+ *out_num_samples = (layer == 1 /* L3 */) ? 576 : 1152;
}
}
@@ -612,7 +612,8 @@ bool GetMPEGAudioFrameSize(
*frame_size = 144000 * bitrate / sampling_rate + padding;
} else {
// V2 or V2.5
- *frame_size = 72000 * bitrate / sampling_rate + padding;
+ size_t tmp = (layer == 1 /* L3 */) ? 72000 : 144000;
+ *frame_size = tmp * bitrate / sampling_rate + padding;
}
}