From 55f7f19d1afb7d30ab48e95d003333393bc0f1f3 Mon Sep 17 00:00:00 2001 From: Wonsik Kim Date: Thu, 24 Oct 2019 12:48:01 -0700 Subject: Adjust to IGraphicBufferSource.aidl removal Bug: 143248118 Bug: 136290435 Test: m checkbuild Change-Id: I19d7de1f2290c36d94bc601ce932b80204689ec6 --- media/sfplugin/CCodec.cpp | 96 ++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 47 deletions(-) (limited to 'media') diff --git a/media/sfplugin/CCodec.cpp b/media/sfplugin/CCodec.cpp index 944a8a5..32f88e1 100644 --- a/media/sfplugin/CCodec.cpp +++ b/media/sfplugin/CCodec.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -35,7 +34,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -54,9 +54,10 @@ namespace android { using namespace std::chrono_literals; using ::android::hardware::graphics::bufferqueue::V1_0::utils::H2BGraphicBufferProducer; using android::base::StringPrintf; -using BGraphicBufferSource = ::android::IGraphicBufferSource; using ::hardware::google::media::c2::V1_0::IInputSurface; +using hardware::media::omx::V1_0::IGraphicBufferSource; + namespace { class CCodecWatchdog : public AHandler { @@ -181,9 +182,10 @@ private: class GraphicBufferSourceWrapper : public InputSurfaceWrapper { public: -// explicit GraphicBufferSourceWrapper(const sp &source) : mSource(source) {} + typedef hardware::media::omx::V1_0::Status OmxStatus; + GraphicBufferSourceWrapper( - const sp &source, + const sp &source, uint32_t width, uint32_t height) : mSource(source), mWidth(width), mHeight(height) { @@ -197,7 +199,9 @@ public: // NOTE: we do not use/pass through color aspects from GraphicBufferSource as we // communicate that directly to the component. - mSource->configure(mNode, mDataSpace); + mSource->configure( + new hardware::media::omx::V1_0::utils::TWOmxNode(mNode), + static_cast(mDataSpace)); return OK; } @@ -215,17 +219,14 @@ public: mNode.clear(); } - status_t GetStatus(const binder::Status &status) { + status_t GetStatus(hardware::Return &&status) { status_t err = OK; if (!status.isOk()) { - err = status.serviceSpecificErrorCode(); - if (err == OK) { - err = status.transactionError(); - if (err == OK) { - // binder status failed, but there is no servie or transaction error - err = UNKNOWN_ERROR; - } - } + err = static_cast(status.withDefault(OmxStatus::UNKNOWN_ERROR)); + } else if (status.isDeadObject()) { + err = DEAD_OBJECT; + } else { + err = UNKNOWN_ERROR; } return err; } @@ -349,7 +350,14 @@ public: err = res; } else { status << " delayUs"; - res = GetStatus(mSource->getStopTimeOffsetUs(&config.mInputDelayUs)); + hardware::Return trans = mSource->getStopTimeOffsetUs( + [&res, &delayUs = config.mInputDelayUs](auto status, auto stopTimeOffsetUs) { + res = static_cast(status); + delayUs = stopTimeOffsetUs; + }); + if (!trans.isOk()) { + res = trans.isDeadObject() ? DEAD_OBJECT : UNKNOWN_ERROR; + } if (res != OK) { status << " (=> " << asString(res) << ")"; } else { @@ -369,7 +377,7 @@ public: } private: - sp mSource; + sp mSource; sp mNode; uint32_t mWidth; uint32_t mHeight; @@ -955,25 +963,25 @@ void CCodec::createInputSurface() { std::shared_ptr persistentSurface(CreateInputSurface()); - if (persistentSurface->getHidlTarget()) { - sp inputSurface = IInputSurface::castFrom( - persistentSurface->getHidlTarget()); - if (!inputSurface) { - ALOGE("Corrupted input surface"); - mCallback->onInputSurfaceCreationFailed(UNKNOWN_ERROR); - return; - } + sp hidlTarget = persistentSurface->getHidlTarget(); + sp inputSurface = IInputSurface::castFrom(hidlTarget); + sp gbs = IGraphicBufferSource::castFrom(hidlTarget); + + if (inputSurface) { err = setupInputSurface(std::make_shared( std::make_shared(inputSurface))); bufferProducer = new H2BGraphicBufferProducer(inputSurface); - } else { + } else if (gbs) { int32_t width = 0; (void)outputFormat->findInt32("width", &width); int32_t height = 0; (void)outputFormat->findInt32("height", &height); - err = setupInputSurface(std::make_shared( - persistentSurface->getBufferSource(), width, height)); + err = setupInputSurface(std::make_shared(gbs, width, height)); bufferProducer = persistentSurface->getBufferProducer(); + } else { + ALOGE("Corrupted input surface"); + mCallback->onInputSurfaceCreationFailed(UNKNOWN_ERROR); + return; } if (err != OK) { @@ -1037,15 +1045,10 @@ void CCodec::setInputSurface(const sp &surface) { inputFormat = config->mInputFormat; outputFormat = config->mOutputFormat; } - auto hidlTarget = surface->getHidlTarget(); - if (hidlTarget) { - sp inputSurface = - IInputSurface::castFrom(hidlTarget); - if (!inputSurface) { - ALOGE("Failed to set input surface: Corrupted surface."); - mCallback->onInputSurfaceDeclined(UNKNOWN_ERROR); - return; - } + sp hidlTarget = surface->getHidlTarget(); + sp inputSurface = IInputSurface::castFrom(hidlTarget); + sp gbs = IGraphicBufferSource::castFrom(hidlTarget); + if (inputSurface) { status_t err = setupInputSurface(std::make_shared( std::make_shared(inputSurface))); if (err != OK) { @@ -1053,18 +1056,22 @@ void CCodec::setInputSurface(const sp &surface) { mCallback->onInputSurfaceDeclined(err); return; } - } else { + } else if (gbs) { int32_t width = 0; (void)outputFormat->findInt32("width", &width); int32_t height = 0; (void)outputFormat->findInt32("height", &height); status_t err = setupInputSurface(std::make_shared( - surface->getBufferSource(), width, height)); + gbs, width, height)); if (err != OK) { ALOGE("Failed to set up input surface: %d", err); mCallback->onInputSurfaceDeclined(err); return; } + } else { + ALOGE("Failed to set input surface: Corrupted surface."); + mCallback->onInputSurfaceDeclined(UNKNOWN_ERROR); + return; } mCallback->onInputSurfaceAccepted(inputFormat, outputFormat); } @@ -1742,25 +1749,20 @@ extern "C" android::PersistentSurface *CreateInputSurface() { android::sp 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 gbp; - android::sp gbs; + android::sp gbs; android::Return transStatus = omx->createInputSurface( [&s, &gbp, &gbs]( OmxStatus status, const android::sp& producer, - const android::sp& source) { + const android::sp& 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 new android::PersistentSurface(new H2BGraphicBufferProducer(gbp), gbs); } return nullptr; -- cgit v1.2.3