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

Commit bb644123 authored by Wonsik Kim's avatar Wonsik Kim
Browse files

DO NOT MERGE Separate libstagefright_{ccodec|codecbase} from libstagefright

Bug: 74403547
Test: adb shell am instrument -e size small -w 'android.media.cts/android.support.test.runner.AndroidJUnitRunner'
Change-Id: I2f57f08a17f1a14d431dd6aa1904bf50d1c6c378
parent ca35ad0a
Loading
Loading
Loading
Loading
+7 −26
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>
@@ -6346,37 +6345,19 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {

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

    Vector<AString> matchingCodecs;
    Vector<AString> owners;

    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;
+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: [
+16 −10
Original line number Diff line number Diff line
@@ -259,20 +259,26 @@ 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());
void CCodec::allocate(const sp<MediaCodecInfo> &codecInfo) {
    if (codecInfo == nullptr) {
        mCallback->onError(UNKNOWN_ERROR, ACTION_CODE_FATAL);
        return;
    }
    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(
            componentName.c_str(), &comp);
@@ -812,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: {
+20 −5
Original line number Diff line number Diff line
@@ -603,6 +603,8 @@ status_t MediaCodec::init(const AString &name) {
        return NAME_NOT_FOUND;
    }

    mCodecInfo.clear();

    bool secureCodec = false;
    AString tmp = name;
    if (tmp.endsWith(".secure")) {
@@ -614,17 +616,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) {
@@ -651,6 +660,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) {
@@ -1972,11 +1984,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