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

Commit 4711827d authored by Lajos Molnar's avatar Lajos Molnar
Browse files

codec2: CCodec plugin CreateInputSurface should create C2 HAL surface

This method is used by framework to determine if CCodec's input
surface will be C2 HAL surface.

Moved compatible surface creation into utility funtion in CCodec.

Bug: 119631295
Change-Id: I17c6338694766075d6efd6b142e13d5b09ff5a78
parent 62d62d69
Loading
Loading
Loading
Loading
+49 −37
Original line number Diff line number Diff line
@@ -943,6 +943,47 @@ void CCodec::initiateCreateInputSurface() {
    (new AMessage(kWhatCreateInputSurface, this))->post();
}

sp<PersistentSurface> CCodec::CreateOmxInputSurface() {
    using namespace android::hardware::media::omx::V1_0;
    using namespace android::hardware::media::omx::V1_0::utils;
    using namespace android::hardware::graphics::bufferqueue::V1_0::utils;
    typedef android::hardware::media::omx::V1_0::Status OmxStatus;
    android::sp<IOmx> omx = IOmx::getService();
    typedef android::hardware::graphics::bufferqueue::V1_0::
            IGraphicBufferProducer HGraphicBufferProducer;
    typedef android::hardware::media::omx::V1_0::
            IGraphicBufferSource HGraphicBufferSource;
    OmxStatus s;
    android::sp<HGraphicBufferProducer> gbp;
    android::sp<HGraphicBufferSource> gbs;
    android::Return<void> transStatus = omx->createInputSurface(
            [&s, &gbp, &gbs](
                    OmxStatus status,
                    const android::sp<HGraphicBufferProducer>& producer,
                    const android::sp<HGraphicBufferSource>& source) {
                s = status;
                gbp = producer;
                gbs = source;
            });
    if (transStatus.isOk() && s == OmxStatus::OK) {
        return new PersistentSurface(
                new H2BGraphicBufferProducer(gbp),
                sp<::android::IGraphicBufferSource>(new LWGraphicBufferSource(gbs)));
    }

    return nullptr;
}

sp<PersistentSurface> CCodec::CreateCompatibleInputSurface() {
    sp<PersistentSurface> surface(CreateInputSurface());

    if (surface == nullptr) {
        surface = CreateOmxInputSurface();
    }

    return surface;
}

void CCodec::createInputSurface() {
    status_t err;
    sp<IGraphicBufferProducer> bufferProducer;
@@ -955,7 +996,7 @@ void CCodec::createInputSurface() {
        outputFormat = config->mOutputFormat;
    }

    std::shared_ptr<PersistentSurface> persistentSurface(CreateInputSurface());
    sp<PersistentSurface> persistentSurface = CreateCompatibleInputSurface();

    if (persistentSurface->getHidlTarget()) {
        sp<IInputSurface> hidlInputSurface = IInputSurface::castFrom(
@@ -1727,46 +1768,17 @@ extern "C" android::CodecBase *CreateCodec() {
    return new android::CCodec;
}

// Create Codec 2.0 input surface
extern "C" android::PersistentSurface *CreateInputSurface() {
    // Attempt to create a Codec2's input surface.
    std::shared_ptr<android::Codec2Client::InputSurface> inputSurface =
            android::Codec2Client::CreateInputSurface();
    if (inputSurface) {
    if (!inputSurface) {
        return nullptr;
    }
    return new android::PersistentSurface(
            inputSurface->getGraphicBufferProducer(),
            static_cast<android::sp<android::hidl::base::V1_0::IBase>>(
            inputSurface->getHalInterface()));
}
    // Fall back to OMX.
    using namespace android::hardware::media::omx::V1_0;
    using namespace android::hardware::media::omx::V1_0::utils;
    using namespace android::hardware::graphics::bufferqueue::V1_0::utils;
    typedef android::hardware::media::omx::V1_0::Status OmxStatus;
    android::sp<IOmx> omx = IOmx::getService();
    typedef android::hardware::graphics::bufferqueue::V1_0::
            IGraphicBufferProducer HGraphicBufferProducer;
    typedef android::hardware::media::omx::V1_0::
            IGraphicBufferSource HGraphicBufferSource;
    OmxStatus s;
    android::sp<HGraphicBufferProducer> gbp;
    android::sp<HGraphicBufferSource> gbs;
    android::Return<void> transStatus = omx->createInputSurface(
            [&s, &gbp, &gbs](
                    OmxStatus status,
                    const android::sp<HGraphicBufferProducer>& producer,
                    const android::sp<HGraphicBufferSource>& source) {
                s = status;
                gbp = producer;
                gbs = source;
            });
    if (transStatus.isOk() && s == OmxStatus::OK) {
        return new android::PersistentSurface(
                new H2BGraphicBufferProducer(gbp),
                sp<::android::IGraphicBufferSource>(
                    new LWGraphicBufferSource(gbs)));
    }

    return nullptr;
}
+10 −0
Original line number Diff line number Diff line
@@ -90,6 +90,16 @@ private:
    void flush();
    void release(bool sendCallback);

    /**
     * Creates an input surface for the current device configuration compatible with CCodec.
     * This could be backed by the C2 HAL or the OMX HAL.
     */
    static sp<PersistentSurface> CreateCompatibleInputSurface();

    /// Creates an input surface to the OMX HAL
    static sp<PersistentSurface> CreateOmxInputSurface();

    /// handle a create input surface call
    void createInputSurface();
    void setInputSurface(const sp<PersistentSurface> &surface);
    status_t setupInputSurface(const std::shared_ptr<InputSurfaceWrapper> &surface);