Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b03b155f authored by Marco Nelissen's avatar Marco Nelissen Committed by android-build-merger
Browse files

DO NOT MERGE SimpleDecodingSource: fix handling of Vorbis buffers

am: 2817be0f

Change-Id: Iff73c1d4e7efdfae56c281aa105ae186d26fc11e
parents 5c743395 2817be0f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -71,12 +71,13 @@ private:
    // Construct this using a codec, source and looper.
    SimpleDecodingSource(
            const sp<MediaCodec> &codec, const sp<IMediaSource> &source, const sp<ALooper> &looper,
            bool usingSurface, const sp<AMessage> &format);
            bool usingSurface, bool isVorbis, const sp<AMessage> &format);

    sp<MediaCodec> mCodec;
    sp<IMediaSource> mSource;
    sp<ALooper> mLooper;
    bool mUsingSurface;
    bool mIsVorbis;
    enum State {
        INIT,
        STARTED,
+20 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <media/ICrypto.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/foundation/ALooper.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/AUtils.h>
@@ -74,7 +75,10 @@ sp<SimpleDecodingSource> SimpleDecodingSource::Create(
                err = codec->getOutputFormat(&format);
            }
            if (err == OK) {
                return new SimpleDecodingSource(codec, source, looper, surface != NULL, format);
                return new SimpleDecodingSource(codec, source, looper,
                        surface != NULL,
                        strcmp(mime, MEDIA_MIMETYPE_AUDIO_VORBIS) == 0,
                        format);
            }

            ALOGD("Failed to configure codec '%s'", componentName.c_str());
@@ -90,11 +94,12 @@ sp<SimpleDecodingSource> SimpleDecodingSource::Create(

SimpleDecodingSource::SimpleDecodingSource(
        const sp<MediaCodec> &codec, const sp<IMediaSource> &source, const sp<ALooper> &looper,
        bool usingSurface, const sp<AMessage> &format)
        bool usingSurface, bool isVorbis, const sp<AMessage> &format)
    : mCodec(codec),
      mSource(source),
      mLooper(looper),
      mUsingSurface(usingSurface),
      mIsVorbis(isVorbis),
      mProtectedState(format) {
    mCodec->getName(&mComponentName);
}
@@ -280,16 +285,25 @@ status_t SimpleDecodingSource::doRead(
            if (in_buf != NULL) {
                int64_t timestampUs = 0;
                CHECK(in_buf->meta_data()->findInt64(kKeyTime, &timestampUs));
                if (in_buf->range_length() > in_buffer->capacity()) {
                if (in_buf->range_length() + (mIsVorbis ? 4 : 0) > in_buffer->capacity()) {
                    ALOGW("'%s' received %zu input bytes for buffer of size %zu",
                            mComponentName.c_str(),
                            in_buf->range_length(), in_buffer->capacity());
                            in_buf->range_length() + (mIsVorbis ? 4 : 0), in_buffer->capacity());
                }
                size_t cpLen = min(in_buf->range_length(), in_buffer->capacity());
                memcpy(in_buffer->base(), (uint8_t *)in_buf->data() + in_buf->range_offset(),
                       min(in_buf->range_length(), in_buffer->capacity()));
                        cpLen );

                if (mIsVorbis) {
                    int32_t numPageSamples;
                    if (!in_buf->meta_data()->findInt32(kKeyValidSamples, &numPageSamples)) {
                        numPageSamples = -1;
                    }
                    memcpy(in_buffer->base() + cpLen, &numPageSamples, sizeof(numPageSamples));
                }

                res = mCodec->queueInputBuffer(
                        in_ix, 0 /* offset */, in_buf->range_length(),
                        in_ix, 0 /* offset */, in_buf->range_length() + (mIsVorbis ? 4 : 0),
                        timestampUs, 0 /* flags */);
                if (res != OK) {
                    ALOGI("[%s] failed to queue input buffer #%zu", mComponentName.c_str(), in_ix);