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

Commit 69b5638c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Separate libstagefright_{ccodec|codecbase} from libstagefright"

parents 6bf1f8d6 058661c6
Loading
Loading
Loading
Loading
+8 −24
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@

#include <media/stagefright/BufferProducerWrapper.h>
#include <media/stagefright/MediaCodec.h>
#include <media/stagefright/MediaCodecList.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/PersistentSurface.h>
@@ -6415,34 +6414,19 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {

    sp<AMessage> notify = new AMessage(kWhatOMXDied, mCodec);

    AString componentName;
    CHECK(msg->findString("componentName", &componentName));

    sp<IMediaCodecList> list = MediaCodecList::getInstance();
    if (list == nullptr) {
        ALOGE("Unable to obtain MediaCodecList while "
                "attempting to create codec \"%s\"",
                componentName.c_str());
        mCodec->signalError(OMX_ErrorUndefined, NO_INIT);
        return false;
    }
    ssize_t index = list->findCodecByName(componentName.c_str());
    if (index < 0) {
        ALOGE("Unable to find codec \"%s\"",
                componentName.c_str());
        mCodec->signalError(OMX_ErrorInvalidComponent, NAME_NOT_FOUND);
        return false;
    }
    sp<MediaCodecInfo> info = list->getCodecInfo(index);
    sp<RefBase> obj;
    CHECK(msg->findObject("codecInfo", &obj));
    sp<MediaCodecInfo> info = (MediaCodecInfo *)obj.get();
    if (info == nullptr) {
        ALOGE("Unexpected error (index out-of-bound) while "
                "retrieving information for codec \"%s\"",
                componentName.c_str());
        ALOGE("Unexpected nullptr for codec information");
        mCodec->signalError(OMX_ErrorUndefined, UNKNOWN_ERROR);
        return false;
    }
    AString owner = (info->getOwnerName() == nullptr) ? "default" : info->getOwnerName();

    AString componentName;
    CHECK(msg->findString("componentName", &componentName));

    sp<CodecObserver> observer = new CodecObserver;
    sp<IOMX> omx;
    sp<IOMXNode> omxNode;
@@ -6490,7 +6474,7 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {

    mCodec->mOMX = omx;
    mCodec->mOMXNode = omxNode;
    mCodec->mCallback->onComponentAllocated(mCodec->mComponentName.c_str(), info);
    mCodec->mCallback->onComponentAllocated(mCodec->mComponentName.c_str());
    mCodec->changeState(mCodec->mLoadedState);

    return true;
+96 −14
Original line number Diff line number Diff line
@@ -48,6 +48,100 @@ cc_library_static {
    shared_libs: ["libmedia"],
}

cc_library_shared {
    name: "libstagefright_codecbase",

    export_include_dirs: ["include"],

    srcs: [
        "CodecBase.cpp",
        "FrameRenderTracker.cpp",
    ],

    cflags: [
        "-Werror",
        "-Wall",
    ],

    shared_libs: [
        "libgui",
        "liblog",
        "libmedia",
        "libstagefright_foundation",
        "libui",
        "libutils",
        "android.hardware.cas.native@1.0",
    ],

    sanitize: {
        cfi: true,
        misc_undefined: [
            "unsigned-integer-overflow",
            "signed-integer-overflow",
        ],
        diag: {
            cfi: true,
        },
    },
}

cc_library_shared {
    name: "libstagefright_ccodec",

    local_include_dirs: ["include"],

    srcs: [
        "C2OMXNode.cpp",
        "CCodec.cpp",
        "CCodecBufferChannel.cpp",
        "Codec2Buffer.cpp",
    ],

    cflags: [
        "-Werror",
        "-Wall",
    ],

    header_libs: [
        "libstagefright_codec2_internal",
    ],

    shared_libs: [
        "libbinder",
        "libcutils",
        "libgui",
        "libhidlallocatorutils",
        "libhidlbase",
        "liblog",
        "libmedia",
        "libmedia_omx",
        "libstagefright_codec2",
        "libstagefright_codec2_vndk",
        "libstagefright_codecbase",
        "libstagefright_foundation",
        "libstagefright_omx_utils",
        "libui",
        "libutils",
        "libv4l2_c2componentstore",
        "android.hardware.cas.native@1.0",

        // TODO: do not link directly with impl
        "libstagefright_bufferqueue_helper",
        "android.hardware.media.c2@1.0-service-impl",
    ],

    sanitize: {
        cfi: true,
        misc_undefined: [
            "unsigned-integer-overflow",
            "signed-integer-overflow",
        ],
        diag: {
            cfi: true,
        },
    },
}

cc_library_shared {
    name: "libstagefright",

@@ -60,12 +154,7 @@ cc_library_shared {
        "AudioPresentationInfo.cpp",
        "AudioSource.cpp",
        "BufferImpl.cpp",
        "C2OMXNode.cpp",
        "CCodec.cpp",
        "CCodecBufferChannel.cpp",
        "Codec2Buffer.cpp",
        "Codec2InfoBuilder.cpp",
        "CodecBase.cpp",
        "CallbackDataSource.cpp",
        "CallbackMediaSource.cpp",
        "CameraSource.cpp",
@@ -75,7 +164,6 @@ cc_library_shared {
        "DataURISource.cpp",
        "FileSource.cpp",
        "FrameDecoder.cpp",
        "FrameRenderTracker.cpp",
        "HTTPBase.cpp",
        "HevcUtils.cpp",
        "InterfaceUtils.cpp",
@@ -108,10 +196,6 @@ cc_library_shared {
        "VideoFrameScheduler.cpp",
    ],

    header_libs: [
        "libstagefright_codec2_internal",
    ],

    shared_libs: [
        "libaudioutils",
        "libbinder",
@@ -132,8 +216,10 @@ cc_library_shared {
        "libui",
        "libutils",
        "libmedia_helper",
        "libstagefright_ccodec",
        "libstagefright_codec2",
        "libstagefright_codec2_vndk",
        "libstagefright_codecbase",
        "libstagefright_foundation",
        "libstagefright_omx",
        "libstagefright_omx_utils",
@@ -150,10 +236,6 @@ cc_library_shared {
        "android.hardware.media.omx@1.0",
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.mapper@2.0",

        // TODO: do not link directly with impl
        "android.hardware.media.c2@1.0-service-impl",
        "libstagefright_bufferqueue_helper",
    ],

    static_libs: [
+15 −36
Original line number Diff line number Diff line
@@ -30,9 +30,7 @@
#include <media/stagefright/codec2/1.0/InputSurface.h>
#include <media/stagefright/BufferProducerWrapper.h>
#include <media/stagefright/CCodec.h>
#include <media/stagefright/MediaCodecList.h>
#include <media/stagefright/PersistentSurface.h>
#include <media/IMediaCodecList.h>

#include "include/C2OMXNode.h"
#include "include/CCodecBufferChannel.h"
@@ -261,44 +259,25 @@ void CCodec::initiateAllocateComponent(const sp<AMessage> &msg) {
        return;
    }

    AString componentName;
    if (!msg->findString("componentName", &componentName)) {
        // TODO: find componentName appropriate with the media type
    }
    sp<RefBase> codecInfo;
    CHECK(msg->findObject("codecInfo", &codecInfo));
    // For Codec 2.0 components, componentName == codecInfo->getCodecName().

    sp<AMessage> allocMsg(new AMessage(kWhatAllocate, this));
    allocMsg->setString("componentName", componentName);
    allocMsg->setObject("codecInfo", codecInfo);
    allocMsg->post();
}

void CCodec::allocate(const AString &componentName) {
    ALOGV("allocate(%s)", componentName.c_str());
    mListener.reset(new CCodecListener(this));

    sp<IMediaCodecList> list = MediaCodecList::getInstance();
    if (list == nullptr) {
        ALOGE("Unable to obtain MediaCodecList while "
                "attempting to create codec \"%s\"",
                componentName.c_str());
        mCallback->onError(NO_INIT, ACTION_CODE_FATAL);
        return;
    }
    ssize_t index = list->findCodecByName(componentName.c_str());
    if (index < 0) {
        ALOGE("Unable to find codec \"%s\"",
                componentName.c_str());
        mCallback->onError(NAME_NOT_FOUND, ACTION_CODE_FATAL);
        return;
    }
    sp<MediaCodecInfo> info = list->getCodecInfo(index);
    if (info == nullptr) {
        ALOGE("Unexpected error (index out-of-bound) while "
                "retrieving information for codec \"%s\"",
                componentName.c_str());
void CCodec::allocate(const sp<MediaCodecInfo> &codecInfo) {
    if (codecInfo == nullptr) {
        mCallback->onError(UNKNOWN_ERROR, ACTION_CODE_FATAL);
        return;
    }
    // TODO: use info->getOwnerName() for connecting to remote process.
    ALOGV("allocate(%s)", codecInfo->getCodecName());
    mListener.reset(new CCodecListener(this));

    AString componentName = codecInfo->getCodecName();
    // TODO: use codecInfo->getOwnerName() for connecting to remote process.

    std::shared_ptr<C2Component> comp;
    c2_status_t err = GetCodec2PlatformComponentStore()->createComponent(
@@ -334,7 +313,7 @@ void CCodec::allocate(const AString &componentName) {
    if (tryAndReportOnError(setAllocated) != OK) {
        return;
    }
    mCallback->onComponentAllocated(comp->intf()->getName().c_str(), info);
    mCallback->onComponentAllocated(comp->intf()->getName().c_str());
}

void CCodec::initiateConfigureComponent(const sp<AMessage> &format) {
@@ -839,9 +818,9 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) {
        case kWhatAllocate: {
            // C2ComponentStore::createComponent() should return within 100ms.
            setDeadline(now + 150ms, "allocate");
            AString componentName;
            CHECK(msg->findString("componentName", &componentName));
            allocate(componentName);
            sp<RefBase> obj;
            CHECK(msg->findObject("codecInfo", &obj));
            allocate((MediaCodecInfo *)obj.get());
            break;
        }
        case kWhatConfigure: {
+22 −17
Original line number Diff line number Diff line
@@ -278,8 +278,7 @@ public:
    virtual void onReleaseCompleted() override;
    virtual void onFlushCompleted() override;
    virtual void onError(status_t err, enum ActionCode actionCode) override;
    virtual void onComponentAllocated(
            const char *componentName, const sp<MediaCodecInfo> &codecInfo) override;
    virtual void onComponentAllocated(const char *componentName) override;
    virtual void onComponentConfigured(
            const sp<AMessage> &inputFormat, const sp<AMessage> &outputFormat) override;
    virtual void onInputSurfaceCreated(
@@ -339,14 +338,10 @@ void CodecCallback::onError(status_t err, enum ActionCode actionCode) {
    notify->post();
}

void CodecCallback::onComponentAllocated(
        const char *componentName, const sp<MediaCodecInfo> &codecInfo) {
void CodecCallback::onComponentAllocated(const char *componentName) {
    sp<AMessage> notify(mNotify->dup());
    notify->setInt32("what", kWhatComponentAllocated);
    notify->setString("componentName", componentName);
    if (codecInfo != nullptr) {
        notify->setObject("codecInfo", codecInfo);
    }
    notify->post();
}

@@ -606,6 +601,8 @@ status_t MediaCodec::init(const AString &name) {
        return NAME_NOT_FOUND;
    }

    mCodecInfo.clear();

    bool secureCodec = false;
    AString tmp = name;
    if (tmp.endsWith(".secure")) {
@@ -617,17 +614,24 @@ status_t MediaCodec::init(const AString &name) {
        mCodec = NULL;  // remove the codec.
        return NO_INIT; // if called from Java should raise IOException
    }
    ssize_t codecIdx = mcl->findCodecByName(tmp.c_str());
    if (codecIdx >= 0) {
        const sp<MediaCodecInfo> info = mcl->getCodecInfo(codecIdx);
    for (const AString &codecName : { name, tmp }) {
        ssize_t codecIdx = mcl->findCodecByName(codecName.c_str());
        if (codecIdx < 0) {
            continue;
        }
        mCodecInfo = mcl->getCodecInfo(codecIdx);
        Vector<AString> mimes;
        info->getSupportedMimes(&mimes);
        mCodecInfo->getSupportedMimes(&mimes);
        for (size_t i = 0; i < mimes.size(); i++) {
            if (mimes[i].startsWith("video/")) {
                mIsVideo = true;
                break;
            }
        }
        break;
    }
    if (mCodecInfo == nullptr) {
        return NAME_NOT_FOUND;
    }

    if (mIsVideo) {
@@ -654,6 +658,9 @@ status_t MediaCodec::init(const AString &name) {
                    new BufferCallback(new AMessage(kWhatCodecNotify, this))));

    sp<AMessage> msg = new AMessage(kWhatInit, this);
    msg->setObject("codecInfo", mCodecInfo);
    // name may be different from mCodecInfo->getCodecName() if we stripped
    // ".secure"
    msg->setString("name", name);

    if (mAnalyticsItem != NULL) {
@@ -1607,11 +1614,6 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {

                    CHECK(msg->findString("componentName", &mComponentName));

                    sp<RefBase> obj;
                    if (msg->findObject("codecInfo", &obj)) {
                        mCodecInfo = static_cast<MediaCodecInfo *>(obj.get());
                    }

                    if (mComponentName.c_str()) {
                        mAnalyticsItem->setCString(kCodecCodec, mComponentName.c_str());
                    }
@@ -1996,11 +1998,14 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
            mReplyID = replyID;
            setState(INITIALIZING);

            sp<RefBase> codecInfo;
            CHECK(msg->findObject("codecInfo", &codecInfo));
            AString name;
            CHECK(msg->findString("name", &name));

            sp<AMessage> format = new AMessage;
            format->setString("componentName", name.c_str());
            format->setObject("codecInfo", codecInfo);
            format->setString("componentName", name);

            mCodec->initiateAllocateComponent(format);
            break;
+2 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ namespace android {

class CCodecBufferChannel;
class InputSurfaceWrapper;
struct MediaCodecInfo;

class CCodec : public CodecBase {
public:
@@ -74,7 +75,7 @@ private:
    void initiateStop();
    void initiateRelease(bool sendCallback = true);

    void allocate(const AString &componentName);
    void allocate(const sp<MediaCodecInfo> &codecInfo);
    void configure(const sp<AMessage> &msg);
    void start();
    void stop();
Loading