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

Commit 50ab4f7e authored by Sungtak Lee's avatar Sungtak Lee
Browse files

PersistentSurface: support HAL input surface

1. Support C2AIDL input surface from PersistentSurface for future uses.
2. Change the header only PersistentSurface to a shared library.
3. Remove the unused old c2inputsurface from CCodec.

BYPASS_IGBP_IGBC_API_REASON=support the new C2AIDL inputsurface

Bug: 201479783
Flag: EXEMPT sysprop debug.stagefright.c2inputsurface instead
Test: presubmit
Change-Id: I47d229b388c49adc8889e1fd326397d61b1280c0
parent d5424126
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ cc_binary {
        "libutils",
        "libbinder",
        "libstagefright_foundation",
        "libstagefright_persistentsurface",
        "libjpeg",
        "libui",
        "libgui",
+1 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ cc_library_shared {
        "libstagefright_codecbase",
        "libstagefright_graphicbuffersource_aidl",
        "libstagefright_foundation",
        "libstagefright_persistentsurface",
        "libstagefright_surface_utils",
        "libstagefright_xmlparser",
        "libui",
+36 −50
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@
#include <aidl/android/media/IAidlGraphicBufferSource.h>
#include <aidl/android/media/IAidlBufferSource.h>
#include <android/IOMXBufferSource.h>
#include <android/hardware/media/c2/1.0/IInputSurface.h>
#include <android/hardware/media/omx/1.0/IGraphicBufferSource.h>
#include <android/hardware/media/omx/1.0/IOmx.h>
#include <android-base/properties.h>
@@ -75,7 +74,6 @@ namespace android {
using namespace std::chrono_literals;
using ::android::hardware::graphics::bufferqueue::V1_0::utils::H2BGraphicBufferProducer;
using android::base::StringPrintf;
using ::android::hardware::media::c2::V1_0::IInputSurface;
using ::aidl::android::media::IAidlBufferSource;
using ::aidl::android::media::IAidlNode;
using ::android::media::AidlGraphicBufferSource;
@@ -1955,7 +1953,8 @@ void CCodec::createInputSurface() {
    }

    sp<PersistentSurface> persistentSurface = CreateCompatibleInputSurface();
    if (persistentSurface->isTargetAidl()) {
    PersistentSurface::SurfaceType surfaceType = persistentSurface->getType();
    if (surfaceType == PersistentSurface::TYPE_AIDLSOURCE) {
        ::ndk::SpAIBinder aidlTarget = persistentSurface->getAidlTarget();
        std::shared_ptr<AGraphicBufferSource> gbs = AGraphicBufferSource::fromBinder(aidlTarget);
        if (gbs) {
@@ -1971,18 +1970,11 @@ void CCodec::createInputSurface() {
            mCallback->onInputSurfaceCreationFailed(UNKNOWN_ERROR);
            return;
        }
    } else {
    } else if (surfaceType == PersistentSurface::TYPE_HIDLSOURCE) {
        sp<hidl::base::V1_0::IBase> hidlTarget = persistentSurface->getHidlTarget();
        sp<IInputSurface> hidlInputSurface = IInputSurface::castFrom(hidlTarget);
        sp<HGraphicBufferSource> gbs = HGraphicBufferSource::castFrom(hidlTarget);

        if (hidlInputSurface) {
            std::shared_ptr<Codec2Client::InputSurface> inputSurface =
                    std::make_shared<Codec2Client::InputSurface>(hidlInputSurface);
            err = setupInputSurface(std::make_shared<C2InputSurfaceWrapper>(
                    inputSurface));
            bufferProducer = inputSurface->getGraphicBufferProducer();
        } else if (gbs) {
        if (gbs) {
            int32_t width = 0;
            (void)outputFormat->findInt32("width", &width);
            int32_t height = 0;
@@ -1991,10 +1983,15 @@ void CCodec::createInputSurface() {
                    gbs, width, height, usage));
            bufferProducer = persistentSurface->getBufferProducer();
        } else {
            ALOGE("Corrupted input surface");
            ALOGE("Corrupted input surface(hidl)");
            mCallback->onInputSurfaceCreationFailed(UNKNOWN_ERROR);
            return;
        }
    } else {
        // TODO: support hal inputsurface.
        ALOGE("Corrupted input surface(invalid %d)", (int)surfaceType);
        mCallback->onInputSurfaceCreationFailed(UNKNOWN_ERROR);
        return;
    }

    if (err != OK) {
@@ -2089,7 +2086,9 @@ void CCodec::setInputSurface(const sp<PersistentSurface> &surface) {
        outputFormat = config->mOutputFormat;
        usage = config->mISConfig ? config->mISConfig->mUsage : 0;
    }
    if (surface->isTargetAidl()) {

    PersistentSurface::SurfaceType surfaceType = surface->getType();
    if (surfaceType == PersistentSurface::TYPE_AIDLSOURCE) {
        ::ndk::SpAIBinder aidlTarget = surface->getAidlTarget();
        std::shared_ptr<AGraphicBufferSource> gbs = AGraphicBufferSource::fromBinder(aidlTarget);
        if (gbs) {
@@ -2110,19 +2109,10 @@ void CCodec::setInputSurface(const sp<PersistentSurface> &surface) {
            mCallback->onInputSurfaceDeclined(UNKNOWN_ERROR);
            return;
        }
    } else {
    } else if (surfaceType == PersistentSurface::TYPE_HIDLSOURCE) {
        sp<hidl::base::V1_0::IBase> hidlTarget = surface->getHidlTarget();
        sp<IInputSurface> inputSurface = IInputSurface::castFrom(hidlTarget);
        sp<HGraphicBufferSource> gbs = HGraphicBufferSource::castFrom(hidlTarget);
        if (inputSurface) {
            status_t err = setupInputSurface(std::make_shared<C2InputSurfaceWrapper>(
                    std::make_shared<Codec2Client::InputSurface>(inputSurface)));
            if (err != OK) {
                ALOGE("Failed to set up input surface: %d", err);
                mCallback->onInputSurfaceDeclined(err);
                return;
            }
        } else if (gbs) {
        if (gbs) {
            int32_t width = 0;
            (void)outputFormat->findInt32("width", &width);
            int32_t height = 0;
@@ -2130,15 +2120,20 @@ void CCodec::setInputSurface(const sp<PersistentSurface> &surface) {
            status_t err = setupInputSurface(std::make_shared<HGraphicBufferSourceWrapper>(
                    gbs, width, height, usage));
            if (err != OK) {
                ALOGE("Failed to set up input surface: %d", err);
                ALOGE("Failed to set up input surface(hidl): %d", err);
                mCallback->onInputSurfaceDeclined(err);
                return;
            }
        } else {
            ALOGE("Failed to set input surface: Corrupted surface.");
            ALOGE("Failed to set input surface(hidl): Corrupted surface.");
            mCallback->onInputSurfaceDeclined(UNKNOWN_ERROR);
            return;
        }
    } else {
        // TODO: support hal inputsurface.
        ALOGE("Failed to set input surface(invalid %d): Corrupted surface.", (int)surfaceType);
        mCallback->onInputSurfaceDeclined(UNKNOWN_ERROR);
        return;
    }
    // Formats can change after setupInputSurface
    sp<AMessage> inputFormat;
@@ -3135,10 +3130,6 @@ void CCodec::initiateReleaseIfStuck() {
// static
PersistentSurface *CCodec::CreateInputSurface() {
    using namespace android;
    // Attempt to create a Codec2's input surface.
    std::shared_ptr<Codec2Client::InputSurface> inputSurface =
            Codec2Client::CreateInputSurface();
    if (!inputSurface) {
    if (property_get_int32("debug.stagefright.c2inputsurface", 0) == -1) {
        sp<IGraphicBufferProducer> gbp;
        sp<AidlGraphicBufferSource> gbs = new AidlGraphicBufferSource();
@@ -3157,11 +3148,6 @@ PersistentSurface *CCodec::CreateInputSurface() {
        return nullptr;
    }
}
    return new PersistentSurface(
            inputSurface->getGraphicBufferProducer(),
            static_cast<sp<android::hidl::base::V1_0::IBase>>(
            inputSurface->getHalInterface()));
}

class IntfCache {
public:
+1 −0
Original line number Diff line number Diff line
@@ -421,6 +421,7 @@ cc_library {
        "libmedia_codeclist",
        "libmedia_omx",
        "libstagefright_foundation",
        "libstagefright_persistentsurface",
        "libutils",
    ],

+39 −0
Original line number Diff line number Diff line
@@ -79,6 +79,44 @@ cc_library_shared {
    },
}

cc_library_shared {
    name: "libstagefright_persistentsurface",

    export_include_dirs: ["include"],

    srcs: [
        "PersistentSurface.cpp",
    ],

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

    header_libs: [
        "libstagefright_foundation_headers",
    ],

    shared_libs: [
        "android.hardware.media.c2-V1-ndk",
        "android.hidl.token@1.0-utils",
        "libbinder",
        "libbinder_ndk",
        "libgui",
        "liblog",
        "libnativewindow",
        "libutils",
    ],

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

cc_library_static {
    name: "libstagefright_mpeg2extractor",
    apex_available: [
@@ -316,6 +354,7 @@ cc_library {
        "libstagefright_foundation",
        "libstagefright_framecapture_utils",
        "libstagefright_omx_utils",
        "libstagefright_persistentsurface",
        "libui",
        "libutils",
        "packagemanager_aidl-cpp",
Loading