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

Commit 80951a33 authored by Wonsik Kim's avatar Wonsik Kim Committed by Automerger Merge Worker
Browse files

Merge "MediaCodec: avoid touching output format at MediaCodec" am: de7ebba5 am: c426eeba

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/1694745

Change-Id: I242d7c0e0e6b7f95519a15ec67b9d140e5088479
parents 64ece9cc c426eeba
Loading
Loading
Loading
Loading
+45 −4
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include <media/omx/1.0/WOmxNode.h>
#include <media/openmax/OMX_Core.h>
#include <media/openmax/OMX_IndexExt.h>
#include <media/stagefright/foundation/avc_utils.h>
#include <media/stagefright/omx/1.0/WGraphicBufferSource.h>
#include <media/stagefright/omx/OmxGraphicBufferSource.h>
#include <media/stagefright/CCodec.h>
@@ -513,6 +514,44 @@ void RevertOutputFormatIfNeeded(
    }
}

void AmendOutputFormatWithCodecSpecificData(
        const uint8_t *data, size_t size, const std::string mediaType,
        const sp<AMessage> &outputFormat) {
    if (mediaType == MIMETYPE_VIDEO_AVC) {
        // Codec specific data should be SPS and PPS in a single buffer,
        // each prefixed by a startcode (0x00 0x00 0x00 0x01).
        // We separate the two and put them into the output format
        // under the keys "csd-0" and "csd-1".

        unsigned csdIndex = 0;

        const uint8_t *nalStart;
        size_t nalSize;
        while (getNextNALUnit(&data, &size, &nalStart, &nalSize, true) == OK) {
            sp<ABuffer> csd = new ABuffer(nalSize + 4);
            memcpy(csd->data(), "\x00\x00\x00\x01", 4);
            memcpy(csd->data() + 4, nalStart, nalSize);

            outputFormat->setBuffer(
                    AStringPrintf("csd-%u", csdIndex).c_str(), csd);

            ++csdIndex;
        }

        if (csdIndex != 2) {
            ALOGW("Expected two NAL units from AVC codec config, but %u found",
                    csdIndex);
        }
    } else {
        // For everything else we just stash the codec specific data into
        // the output format as a single piece of csd under "csd-0".
        sp<ABuffer> csd = new ABuffer(size);
        memcpy(csd->data(), data, size);
        csd->setRange(0, size);
        outputFormat->setBuffer("csd-0", csd);
    }
}

}  // namespace

// CCodec::ClientListener
@@ -2149,7 +2188,7 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) {
            }

            // handle configuration changes in work done
            std::unique_ptr<C2Param> initData;
            std::shared_ptr<const C2StreamInitDataInfo::output> initData;
            sp<AMessage> outputFormat = nullptr;
            {
                Mutexed<std::unique_ptr<Config>>::Locked configLocked(mConfig);
@@ -2228,13 +2267,15 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) {
                    config->mInputSurface->onInputBufferDone(work->input.ordinal.frameIndex);
                }
                if (initDataWatcher.hasChanged()) {
                    initData = C2Param::Copy(*initDataWatcher.update().get());
                    initData = initDataWatcher.update();
                    AmendOutputFormatWithCodecSpecificData(
                            initData->m.value, initData->flexCount(), config->mCodingMediaType,
                            config->mOutputFormat);
                }
                outputFormat = config->mOutputFormat;
            }
            mChannel->onWorkDone(
                    std::move(work), outputFormat,
                    initData ? (C2StreamInitDataInfo::output *)initData.get() : nullptr);
                    std::move(work), outputFormat, initData ? initData.get() : nullptr);
            break;
        }
        case kWhatWatch: {
+2 −1
Original line number Diff line number Diff line
@@ -3695,7 +3695,8 @@ void MediaCodec::handleOutputFormatChangeIfNeeded(const sp<MediaCodecBuffer> &bu
        // format as necessary.
        int32_t flags = 0;
        (void) buffer->meta()->findInt32("flags", &flags);
        if ((flags & BUFFER_FLAG_CODECCONFIG) && !(mFlags & kFlagIsSecure)) {
        if ((flags & BUFFER_FLAG_CODECCONFIG) && !(mFlags & kFlagIsSecure)
                && !mOwnerName.startsWith("codec2::")) {
            status_t err =
                amendOutputFormatWithCodecSpecificData(buffer);