diff options
author | Andreas Huber <andih@google.com> | 2011-09-28 12:37:36 -0700 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2011-09-28 12:37:36 -0700 |
commit | 729de186450f78c099637e1fce743fe531862c52 (patch) | |
tree | bf05611a1943104189abce2f9b09514f2ec2adeb /cmds | |
parent | ac4d4d3698e920b9f5c648a781df5b6af8bcfdf0 (diff) | |
download | frameworks_av-729de186450f78c099637e1fce743fe531862c52.zip frameworks_av-729de186450f78c099637e1fce743fe531862c52.tar.gz frameworks_av-729de186450f78c099637e1fce743fe531862c52.tar.bz2 |
Support AMR, G.711 and vorbis audio in ACodec and friends.
Change-Id: I08c03219bf2d60fc5c6e89957bd4b4c615570983
Diffstat (limited to 'cmds')
-rw-r--r-- | cmds/stagefright/sf2.cpp | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/cmds/stagefright/sf2.cpp b/cmds/stagefright/sf2.cpp index 263ecd1..f547e01 100644 --- a/cmds/stagefright/sf2.cpp +++ b/cmds/stagefright/sf2.cpp @@ -46,7 +46,8 @@ struct Controller : public AHandler { mDecodeAudio(decodeAudio), mSurface(surface), mRenderToSurface(renderToSurface), - mCodec(new ACodec) { + mCodec(new ACodec), + mIsVorbis(false) { CHECK(!mDecodeAudio || mSurface == NULL); } @@ -85,6 +86,12 @@ protected: if (!strncasecmp(mDecodeAudio ? "audio/" : "video/", mime, 6)) { mSource = extractor->getTrack(i); + + if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_VORBIS)) { + mIsVorbis = true; + } else { + mIsVorbis = false; + } break; } } @@ -227,6 +234,7 @@ private: bool mRenderToSurface; sp<ACodec> mCodec; sp<MediaSource> mSource; + bool mIsVorbis; Vector<sp<ABuffer> > mCSD; size_t mCSDIndex; @@ -369,6 +377,20 @@ private: buffer->meta()->setInt32("csd", true); mCSD.push(buffer); + } else if (meta->findData(kKeyVorbisInfo, &type, &data, &size)) { + sp<ABuffer> buffer = new ABuffer(size); + memcpy(buffer->data(), data, size); + + buffer->meta()->setInt32("csd", true); + mCSD.push(buffer); + + CHECK(meta->findData(kKeyVorbisBooks, &type, &data, &size)); + + buffer = new ABuffer(size); + memcpy(buffer->data(), data, size); + + buffer->meta()->setInt32("csd", true); + mCSD.push(buffer); } int32_t maxInputSize; @@ -423,10 +445,17 @@ private: } } - if (inBuffer->range_length() > sizeLeft) { + size_t sizeNeeded = inBuffer->range_length(); + if (mIsVorbis) { + // Vorbis data is suffixed with the number of + // valid samples on the page. + sizeNeeded += sizeof(int32_t); + } + + if (sizeNeeded > sizeLeft) { if (outBuffer->size() == 0) { LOGE("Unable to fit even a single input buffer of size %d.", - inBuffer->range_length()); + sizeNeeded); } CHECK_GT(outBuffer->size(), 0u); @@ -448,10 +477,22 @@ private: + inBuffer->range_offset(), inBuffer->range_length()); + if (mIsVorbis) { + int32_t numPageSamples; + if (!inBuffer->meta_data()->findInt32( + kKeyValidSamples, &numPageSamples)) { + numPageSamples = -1; + } + + memcpy(outBuffer->data() + + outBuffer->size() + inBuffer->range_length(), + &numPageSamples, sizeof(numPageSamples)); + } + outBuffer->setRange( - 0, outBuffer->size() + inBuffer->range_length()); + 0, outBuffer->size() + sizeNeeded); - sizeLeft -= inBuffer->range_length(); + sizeLeft -= sizeNeeded; inBuffer->release(); inBuffer = NULL; |