codec2 hal: add the AIDL adaptation layer [step 2]
Implement AIDL interfaces. Graphic buffer passing and input surface
are not complete yet.
Bug: 251850069
Test: m libcodec2_aidl && m
Change-Id: I71608e2528794106239ebb487d327eb19b062ee1
diff --git a/media/codec2/hal/aidl/Android.bp b/media/codec2/hal/aidl/Android.bp
index b19f78c..a9a00be 100644
--- a/media/codec2/hal/aidl/Android.bp
+++ b/media/codec2/hal/aidl/Android.bp
@@ -50,100 +50,94 @@
}
// DO NOT DEPEND ON THIS DIRECTLY
-// use libcodec2-hidl-defaults instead
-//cc_library {
-// name: "libcodec2_hidl@1.0",
-// vendor_available: true,
-// min_sdk_version: "29",
-// apex_available: [
-// "//apex_available:platform",
-// "com.android.media.swcodec",
-// ],
-//
-// defaults: ["hidl_defaults"],
-//
-// srcs: [
-// "Component.cpp",
-// "ComponentInterface.cpp",
-// "ComponentStore.cpp",
-// "Configurable.cpp",
-// "InputBufferManager.cpp",
-// "InputSurface.cpp",
-// "InputSurfaceConnection.cpp",
-// "types.cpp",
-// ],
-//
-// header_libs: [
-// "libbinder_headers",
-// "libcodec2_hal_common",
-// "libcodec2_internal", // private
-// "libsystem_headers",
-// ],
-//
-// shared_libs: [
-// "android.hardware.graphics.bufferqueue@1.0",
-// "android.hardware.graphics.bufferqueue@2.0",
-// "android.hardware.graphics.common@1.0",
-// "android.hardware.media@1.0",
-// "android.hardware.media.bufferpool@2.0",
-// "android.hardware.media.c2@1.0",
-// "android.hardware.media.omx@1.0",
-// "libbase",
-// "libcodec2",
-// "libcodec2_vndk",
-// "libcodec2_hidl_plugin_stub",
-// "libcutils",
-// "libhidlbase",
-// "liblog",
-// "libstagefright_bufferpool@2.0.1",
-// "libstagefright_bufferqueue_helper_novndk",
-// "libui",
-// "libutils",
-// ],
-//
-// target: {
-// vendor: {
-// exclude_shared_libs: [
-// "libstagefright_bufferqueue_helper_novndk",
-// "libcodec2_hidl_plugin_stub",
-// ],
-// shared_libs: [
-// "libstagefright_bufferqueue_helper",
-// "libcodec2_hidl_plugin",
-// ],
-// },
-// apex: {
-// exclude_shared_libs: [
-// "libcodec2_hidl_plugin",
-// "libcodec2_hidl_plugin_stub",
-// ],
-// },
-// },
-//
-// export_include_dirs: [
-// "include",
-// ],
-//
-// export_shared_lib_headers: [
-// "android.hardware.media.c2@1.0",
-// "libcodec2",
-// "libcodec2_vndk",
-// "libhidlbase",
-// "libstagefright_bufferpool@2.0.1",
-// "libui",
-// ],
-//}
-//
-//// public dependency for Codec 2.0 HAL service implementations
-//cc_defaults {
-// name: "libcodec2-hidl-defaults@1.0",
-// defaults: ["libcodec2-impl-defaults"],
-//
-// shared_libs: [
-// "android.hardware.media.c2@1.0",
-// "libcodec2_hidl@1.0",
-// ],
-//}
+// use libcodec2-aidl-defaults instead
+cc_library {
+ name: "libcodec2_aidl",
+ vendor_available: true,
+ min_sdk_version: "34",
+ apex_available: [
+ "//apex_available:platform",
+ "com.android.media.swcodec",
+ "test_com.android.media.swcodec",
+ ],
+
+ srcs: [
+ "BufferTypes.cpp",
+ "Component.cpp",
+ "ComponentInterface.cpp",
+ "ComponentStore.cpp",
+ "Configurable.cpp",
+ "InputBufferManager.cpp",
+ "ParamTypes.cpp",
+ ],
+
+ header_libs: [
+ "libcodec2_internal", // private
+ ],
+
+ shared_libs: [
+ "android.hardware.common-V2-ndk",
+ "android.hardware.media.bufferpool2-V1-ndk",
+ "android.hardware.media.c2-V1-ndk",
+ "libbase",
+ "libbinder_ndk",
+ "libcodec2",
+ "libcodec2_hal_common",
+ "libcodec2_hidl_plugin_stub",
+ "libcodec2_vndk",
+ "libcutils",
+ "libhidlbase",
+ "liblog",
+ "libstagefright_aidl_bufferpool2",
+ "libstagefright_bufferpool@2.0.1",
+ "libui",
+ "libutils",
+ ],
+
+ static_libs: [
+ "libaidlcommonsupport",
+ ],
+
+ target: {
+ vendor: {
+ exclude_shared_libs: [
+ "libcodec2_hidl_plugin_stub",
+ ],
+ shared_libs: [
+ "libcodec2_hidl_plugin",
+ ],
+ },
+ apex: {
+ exclude_shared_libs: [
+ "libcodec2_hidl_plugin_stub",
+ "libcodec2_hidl_plugin",
+ ],
+ },
+ },
+
+ export_include_dirs: [
+ "include",
+ ],
+
+ export_shared_lib_headers: [
+ "android.hardware.media.c2-V1-ndk",
+ "libcodec2",
+ "libstagefright_bufferpool@2.0.1",
+ "libui",
+ ],
+}
+
+// public dependency for Codec 2.0 HAL service implementations
+cc_defaults {
+ name: "libcodec2-aidl-defaults",
+ min_sdk_version: "34",
+ defaults: ["libcodec2-impl-defaults"],
+
+ shared_libs: [
+ "android.hardware.media.c2-V1-ndk",
+ "libcodec2_aidl",
+ ],
+}
// public dependency for Codec 2.0 HAL client
cc_defaults {
diff --git a/media/codec2/hal/aidl/Component.cpp b/media/codec2/hal/aidl/Component.cpp
index 7994d32..fa18c3e 100644
--- a/media/codec2/hal/aidl/Component.cpp
+++ b/media/codec2/hal/aidl/Component.cpp
@@ -15,40 +15,42 @@
*/
//#define LOG_NDEBUG 0
-#define LOG_TAG "Codec2-Component@1.2"
+#define LOG_TAG "Codec2-Component-Aidl"
#include <android-base/logging.h>
-#include <codec2/hidl/1.2/Component.h>
-#include <codec2/hidl/1.2/ComponentStore.h>
-#include <codec2/hidl/1.2/InputBufferManager.h>
+#include <codec2/aidl/Component.h>
+#include <codec2/aidl/ComponentStore.h>
+#include <codec2/aidl/InputBufferManager.h>
#ifndef __ANDROID_APEX__
#include <FilterWrapper.h>
#endif
-#include <hidl/HidlBinderSupport.h>
+#include <android/binder_auto_utils.h>
+#include <android/binder_interface_utils.h>
#include <utils/Timers.h>
-#include <C2BqBufferPriv.h>
#include <C2Debug.h>
#include <C2PlatformSupport.h>
#include <chrono>
#include <thread>
+namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
-namespace V1_2 {
namespace utils {
-using namespace ::android;
+using ::aidl::android::hardware::common::NativeHandle;
+using ::aidl::android::hardware::media::bufferpool2::IClientManager;
+using ::ndk::ScopedAStatus;
// ComponentListener wrapper
struct Component::Listener : public C2Component::Listener {
- Listener(const sp<Component>& component) :
+ Listener(const std::shared_ptr<Component>& component) :
mComponent(component),
mListener(component->mListener) {
}
@@ -56,9 +58,9 @@
virtual void onError_nb(
std::weak_ptr<C2Component> /* c2component */,
uint32_t errorCode) override {
- sp<IComponentListener> listener = mListener.promote();
+ std::shared_ptr<IComponentListener> listener = mListener.lock();
if (listener) {
- Return<void> transStatus = listener->onError(Status::OK, errorCode);
+ ScopedAStatus transStatus = listener->onError(Status{Status::OK}, errorCode);
if (!transStatus.isOk()) {
LOG(ERROR) << "Component::Listener::onError_nb -- "
<< "transaction failed.";
@@ -70,20 +72,20 @@
std::weak_ptr<C2Component> /* c2component */,
std::vector<std::shared_ptr<C2SettingResult>> c2settingResult
) override {
- sp<IComponentListener> listener = mListener.promote();
+ std::shared_ptr<IComponentListener> listener = mListener.lock();
if (listener) {
- hidl_vec<SettingResult> settingResults(c2settingResult.size());
+ std::vector<SettingResult> settingResults(c2settingResult.size());
size_t ix = 0;
for (const std::shared_ptr<C2SettingResult> &c2result :
c2settingResult) {
if (c2result) {
- if (!objcpy(&settingResults[ix++], *c2result)) {
+ if (!ToAidl(&settingResults[ix++], *c2result)) {
break;
}
}
}
settingResults.resize(ix);
- Return<void> transStatus = listener->onTripped(settingResults);
+ ScopedAStatus transStatus = listener->onTripped(settingResults);
if (!transStatus.isOk()) {
LOG(ERROR) << "Component::Listener::onTripped_nb -- "
<< "transaction failed.";
@@ -106,113 +108,57 @@
}
}
- sp<IComponentListener> listener = mListener.promote();
+ std::shared_ptr<IComponentListener> listener = mListener.lock();
if (listener) {
WorkBundle workBundle;
- sp<Component> strongComponent = mComponent.promote();
- beginTransferBufferQueueBlocks(c2workItems, true);
- if (!objcpy(&workBundle, c2workItems, strongComponent ?
+ std::shared_ptr<Component> strongComponent = mComponent.lock();
+ // TODO
+ // beginTransferBufferQueueBlocks(c2workItems, true);
+ if (!ToAidl(&workBundle, c2workItems, strongComponent ?
&strongComponent->mBufferPoolSender : nullptr)) {
LOG(ERROR) << "Component::Listener::onWorkDone_nb -- "
<< "received corrupted work items.";
- endTransferBufferQueueBlocks(c2workItems, false, true);
+ // TODO
+ // endTransferBufferQueueBlocks(c2workItems, false, true);
return;
}
- Return<void> transStatus = listener->onWorkDone(workBundle);
+ ScopedAStatus transStatus = listener->onWorkDone(workBundle);
if (!transStatus.isOk()) {
LOG(ERROR) << "Component::Listener::onWorkDone_nb -- "
<< "transaction failed.";
- endTransferBufferQueueBlocks(c2workItems, false, true);
+ // TODO
+ // endTransferBufferQueueBlocks(c2workItems, false, true);
return;
}
- endTransferBufferQueueBlocks(c2workItems, true, true);
+ // TODO
+ // endTransferBufferQueueBlocks(c2workItems, true, true);
}
}
protected:
- wp<Component> mComponent;
- wp<IComponentListener> mListener;
+ std::weak_ptr<Component> mComponent;
+ std::weak_ptr<IComponentListener> mListener;
};
-// Component::Sink
-struct Component::Sink : public IInputSink {
- std::shared_ptr<Component> mComponent;
- sp<IConfigurable> mConfigurable;
-
- virtual Return<Status> queue(const WorkBundle& workBundle) override {
- return mComponent->queue(workBundle);
- }
-
- virtual Return<sp<IConfigurable>> getConfigurable() override {
- return mConfigurable;
- }
-
- Sink(const std::shared_ptr<Component>& component);
- virtual ~Sink() override;
-
- // Process-wide map: Component::Sink -> C2Component.
- static std::mutex sSink2ComponentMutex;
- static std::map<IInputSink*, std::weak_ptr<C2Component>> sSink2Component;
-
- static std::shared_ptr<C2Component> findLocalComponent(
- const sp<IInputSink>& sink);
+// Component::DeathContext
+struct Component::DeathContext {
+ std::weak_ptr<Component> mWeakComp;
};
-std::mutex
- Component::Sink::sSink2ComponentMutex{};
-std::map<IInputSink*, std::weak_ptr<C2Component>>
- Component::Sink::sSink2Component{};
-
-Component::Sink::Sink(const std::shared_ptr<Component>& component)
- : mComponent{component},
- mConfigurable{[&component]() -> sp<IConfigurable> {
- Return<sp<IComponentInterface>> ret1 = component->getInterface();
- if (!ret1.isOk()) {
- LOG(ERROR) << "Sink::Sink -- component's transaction failed.";
- return nullptr;
- }
- Return<sp<IConfigurable>> ret2 =
- static_cast<sp<IComponentInterface>>(ret1)->
- getConfigurable();
- if (!ret2.isOk()) {
- LOG(ERROR) << "Sink::Sink -- interface's transaction failed.";
- return nullptr;
- }
- return static_cast<sp<IConfigurable>>(ret2);
- }()} {
- std::lock_guard<std::mutex> lock(sSink2ComponentMutex);
- sSink2Component.emplace(this, component->mComponent);
-}
-
-Component::Sink::~Sink() {
- std::lock_guard<std::mutex> lock(sSink2ComponentMutex);
- sSink2Component.erase(this);
-}
-
-std::shared_ptr<C2Component> Component::Sink::findLocalComponent(
- const sp<IInputSink>& sink) {
- std::lock_guard<std::mutex> lock(sSink2ComponentMutex);
- auto i = sSink2Component.find(sink.get());
- if (i == sSink2Component.end()) {
- return nullptr;
- }
- return i->second.lock();
-}
-
// Component
Component::Component(
const std::shared_ptr<C2Component>& component,
- const sp<IComponentListener>& listener,
- const sp<ComponentStore>& store,
- const sp<::android::hardware::media::bufferpool::V2_0::
- IClientManager>& clientPoolManager)
+ const std::shared_ptr<IComponentListener>& listener,
+ const std::shared_ptr<ComponentStore>& store,
+ const std::shared_ptr<IClientManager>& clientPoolManager)
: mComponent{component},
- mInterface{new ComponentInterface(component->intf(),
- store->getParameterCache())},
+ mInterface{SharedRefBase::make<ComponentInterface>(
+ component->intf(), store->getParameterCache())},
mListener{listener},
mStore{store},
- mBufferPoolSender{clientPoolManager} {
+ mBufferPoolSender{clientPoolManager},
+ mDeathContext(nullptr) {
// Retrieve supported parameters from store
// TODO: We could cache this per component/interface type
mInit = mInterface->status();
@@ -223,11 +169,11 @@
}
// Methods from ::android::hardware::media::c2::V1_1::IComponent
-Return<Status> Component::queue(const WorkBundle& workBundle) {
+ScopedAStatus Component::queue(const WorkBundle& workBundle) {
std::list<std::unique_ptr<C2Work>> c2works;
- if (!objcpy(&c2works, workBundle)) {
- return Status::CORRUPTED;
+ if (!FromAidl(&c2works, workBundle)) {
+ return ScopedAStatus::fromServiceSpecificError(Status::CORRUPTED);
}
// Register input buffers.
@@ -238,10 +184,14 @@
}
}
- return static_cast<Status>(mComponent->queue_nb(&c2works));
+ c2_status_t err = mComponent->queue_nb(&c2works);
+ if (err == C2_OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(err);
}
-Return<void> Component::flush(flush_cb _hidl_cb) {
+ScopedAStatus Component::flush(WorkBundle *flushedWorkBundle) {
std::list<std::unique_ptr<C2Work>> c2flushedWorks;
c2_status_t c2res = mComponent->flush_sm(
C2Component::FLUSH_COMPONENT,
@@ -260,80 +210,29 @@
}
}
- WorkBundle flushedWorkBundle;
- Status res = static_cast<Status>(c2res);
- beginTransferBufferQueueBlocks(c2flushedWorks, true);
+ // TODO
+ // beginTransferBufferQueueBlocks(c2flushedWorks, true);
if (c2res == C2_OK) {
- if (!objcpy(&flushedWorkBundle, c2flushedWorks, &mBufferPoolSender)) {
- res = Status::CORRUPTED;
+ if (!ToAidl(flushedWorkBundle, c2flushedWorks, &mBufferPoolSender)) {
+ c2res = C2_CORRUPTED;
}
}
- _hidl_cb(res, flushedWorkBundle);
- endTransferBufferQueueBlocks(c2flushedWorks, true, true);
- return Void();
+ // TODO
+ // endTransferBufferQueueBlocks(c2flushedWorks, true, true);
+ if (c2res == C2_OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(c2res);
}
-Return<Status> Component::drain(bool withEos) {
- return static_cast<Status>(mComponent->drain_nb(withEos ?
+ScopedAStatus Component::drain(bool withEos) {
+ c2_status_t res = mComponent->drain_nb(withEos ?
C2Component::DRAIN_COMPONENT_WITH_EOS :
- C2Component::DRAIN_COMPONENT_NO_EOS));
-}
-
-Return<Status> Component::setOutputSurface(
- uint64_t blockPoolId,
- const sp<HGraphicBufferProducer2>& surface) {
- std::shared_ptr<C2BlockPool> pool;
- GetCodec2BlockPool(blockPoolId, mComponent, &pool);
- if (pool && pool->getAllocatorId() == C2PlatformAllocatorStore::BUFFERQUEUE) {
- std::shared_ptr<C2BufferQueueBlockPool> bqPool =
- std::static_pointer_cast<C2BufferQueueBlockPool>(pool);
- C2BufferQueueBlockPool::OnRenderCallback cb =
- [this](uint64_t producer, int32_t slot, int64_t nsecs) {
- // TODO: batch this
- hidl_vec<IComponentListener::RenderedFrame> rendered;
- rendered.resize(1);
- rendered[0] = { producer, slot, nsecs };
- (void)mListener->onFramesRendered(rendered).isOk();
- };
- if (bqPool) {
- bqPool->setRenderCallback(cb);
- bqPool->configureProducer(surface);
- }
+ C2Component::DRAIN_COMPONENT_NO_EOS);
+ if (res == C2_OK) {
+ return ScopedAStatus::ok();
}
- return Status::OK;
-}
-
-Return<void> Component::connectToInputSurface(
- const sp<IInputSurface>& inputSurface,
- connectToInputSurface_cb _hidl_cb) {
- Status status;
- sp<IInputSurfaceConnection> connection;
- auto transStatus = inputSurface->connect(
- asInputSink(),
- [&status, &connection](
- Status s, const sp<IInputSurfaceConnection>& c) {
- status = s;
- connection = c;
- }
- );
- _hidl_cb(status, connection);
- return Void();
-}
-
-Return<void> Component::connectToOmxInputSurface(
- const sp<HGraphicBufferProducer1>& producer,
- const sp<::android::hardware::media::omx::V1_0::
- IGraphicBufferSource>& source,
- connectToOmxInputSurface_cb _hidl_cb) {
- (void)producer;
- (void)source;
- (void)_hidl_cb;
- return Void();
-}
-
-Return<Status> Component::disconnectFromInputSurface() {
- // TODO implement
- return Status::OK;
+ return ScopedAStatus::fromServiceSpecificError(res);
}
namespace /* unnamed */ {
@@ -390,130 +289,122 @@
} // unnamed namespace
-Return<void> Component::createBlockPool(
- uint32_t allocatorId,
- createBlockPool_cb _hidl_cb) {
- std::shared_ptr<C2BlockPool> blockPool;
+ScopedAStatus Component::createBlockPool(
+ const IComponent::BlockPoolAllocator &allocator,
+ IComponent::BlockPool *blockPool) {
+ std::shared_ptr<C2BlockPool> c2BlockPool;
+ static constexpr IComponent::BlockPoolAllocator::Tag ALLOCATOR_ID =
+ IComponent::BlockPoolAllocator::allocatorId;
+ static constexpr IComponent::BlockPoolAllocator::Tag IGBA =
+ IComponent::BlockPoolAllocator::igba;
+ c2_status_t status = C2_OK;
+ switch (allocator.getTag()) {
+ case ALLOCATOR_ID:
#ifdef __ANDROID_APEX__
- c2_status_t status = CreateCodec2BlockPool(
- static_cast<C2PlatformAllocatorStore::id_t>(allocatorId),
- mComponent,
- &blockPool);
+ status = CreateCodec2BlockPool(
+ static_cast<::android::C2PlatformAllocatorStore::id_t>(
+ allocator.get<ALLOCATOR_ID>()),
+ mComponent,
+ &c2BlockPool);
#else
- c2_status_t status = ComponentStore::GetFilterWrapper()->createBlockPool(
- static_cast<C2PlatformAllocatorStore::id_t>(allocatorId),
- mComponent,
- &blockPool);
+ status = ComponentStore::GetFilterWrapper()->createBlockPool(
+ static_cast<::android::C2PlatformAllocatorStore::id_t>(
+ allocator.get<ALLOCATOR_ID>()),
+ mComponent,
+ &c2BlockPool);
#endif
- if (status != C2_OK) {
- blockPool = nullptr;
+ if (status != C2_OK) {
+ blockPool = nullptr;
+ }
+ break;
+ case IGBA:
+ // FIXME
+ break;
+ default:
+ break;
}
if (blockPool) {
mBlockPoolsMutex.lock();
- mBlockPools.emplace(blockPool->getLocalId(), blockPool);
+ mBlockPools.emplace(c2BlockPool->getLocalId(), c2BlockPool);
mBlockPoolsMutex.unlock();
} else if (status == C2_OK) {
status = C2_CORRUPTED;
}
- _hidl_cb(static_cast<Status>(status),
- blockPool ? blockPool->getLocalId() : 0,
- new CachedConfigurable(
- std::make_unique<BlockPoolIntf>(blockPool)));
- return Void();
+ blockPool->blockPoolId = c2BlockPool ? c2BlockPool->getLocalId() : 0;
+ blockPool->configurable = SharedRefBase::make<CachedConfigurable>(
+ std::make_unique<BlockPoolIntf>(c2BlockPool));
+ if (status == C2_OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(status);
}
-Return<Status> Component::destroyBlockPool(uint64_t blockPoolId) {
+ScopedAStatus Component::destroyBlockPool(int64_t blockPoolId) {
std::lock_guard<std::mutex> lock(mBlockPoolsMutex);
- return mBlockPools.erase(blockPoolId) == 1 ?
- Status::OK : Status::CORRUPTED;
+ if (mBlockPools.erase(blockPoolId) == 1) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(Status::CORRUPTED);
}
-Return<Status> Component::start() {
- return static_cast<Status>(mComponent->start());
+ScopedAStatus Component::start() {
+ c2_status_t status = mComponent->start();
+ if (status == C2_OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(status);
}
-Return<Status> Component::stop() {
+ScopedAStatus Component::stop() {
InputBufferManager::unregisterFrameData(mListener);
- return static_cast<Status>(mComponent->stop());
+ c2_status_t status = mComponent->stop();
+ if (status == C2_OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(status);
}
-Return<Status> Component::reset() {
- Status status = static_cast<Status>(mComponent->reset());
+ScopedAStatus Component::reset() {
+ c2_status_t status = mComponent->reset();
{
std::lock_guard<std::mutex> lock(mBlockPoolsMutex);
mBlockPools.clear();
}
InputBufferManager::unregisterFrameData(mListener);
- return status;
+ if (status == C2_OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(status);
}
-Return<Status> Component::release() {
- Status status = static_cast<Status>(mComponent->release());
+ScopedAStatus Component::release() {
+ c2_status_t status = mComponent->release();
{
std::lock_guard<std::mutex> lock(mBlockPoolsMutex);
mBlockPools.clear();
}
InputBufferManager::unregisterFrameData(mListener);
- return status;
-}
-
-Return<sp<IComponentInterface>> Component::getInterface() {
- return sp<IComponentInterface>(mInterface);
-}
-
-Return<sp<IInputSink>> Component::asInputSink() {
- std::lock_guard<std::mutex> lock(mSinkMutex);
- if (!mSink) {
- mSink = new Sink(shared_from_this());
+ if (status == C2_OK) {
+ return ScopedAStatus::ok();
}
- return {mSink};
+ return ScopedAStatus::fromServiceSpecificError(status);
}
-Return<void> Component::configureVideoTunnel(
- uint32_t avSyncHwId, configureVideoTunnel_cb _hidl_cb) {
+ScopedAStatus Component::getInterface(
+ std::shared_ptr<IComponentInterface> *intf) {
+ *intf = mInterface;
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus Component::configureVideoTunnel(
+ int32_t avSyncHwId, NativeHandle *handle) {
(void)avSyncHwId;
- _hidl_cb(Status::OMITTED, hidl_handle{});
- return Void();
+ (void)handle;
+ return ScopedAStatus::fromServiceSpecificError(Status::OMITTED);
}
-Return<Status> Component::setOutputSurfaceWithSyncObj(
- uint64_t blockPoolId, const sp<HGraphicBufferProducer2>& surface,
- const SurfaceSyncObj& syncObject) {
- std::shared_ptr<C2BlockPool> pool;
- GetCodec2BlockPool(blockPoolId, mComponent, &pool);
- if (pool && pool->getAllocatorId() == C2PlatformAllocatorStore::BUFFERQUEUE) {
- std::shared_ptr<C2BufferQueueBlockPool> bqPool =
- std::static_pointer_cast<C2BufferQueueBlockPool>(pool);
- C2BufferQueueBlockPool::OnRenderCallback cb =
- [this](uint64_t producer, int32_t slot, int64_t nsecs) {
- // TODO: batch this
- hidl_vec<IComponentListener::RenderedFrame> rendered;
- rendered.resize(1);
- rendered[0] = { producer, slot, nsecs };
- (void)mListener->onFramesRendered(rendered).isOk();
- };
- if (bqPool) {
- const native_handle_t *h = syncObject.syncMemory;
- native_handle_t *syncMemory = h ? native_handle_clone(h) : nullptr;
- uint64_t bqId = syncObject.bqId;
- uint32_t generationId = syncObject.generationId;
- uint64_t consumerUsage = syncObject.consumerUsage;
-
- bqPool->setRenderCallback(cb);
- bqPool->configureProducer(surface, syncMemory, bqId,
- generationId, consumerUsage);
- }
- }
- return Status::OK;
-}
-
-std::shared_ptr<C2Component> Component::findLocalComponent(
- const sp<IInputSink>& sink) {
- return Component::Sink::findLocalComponent(sink);
-}
-
-void Component::initListener(const sp<Component>& self) {
+void Component::initListener(const std::shared_ptr<Component>& self) {
std::shared_ptr<C2Component::Listener> c2listener =
std::make_shared<Listener>(self);
c2_status_t res = mComponent->setListener_vb(c2listener, C2_DONT_BLOCK);
@@ -521,46 +412,38 @@
mInit = res;
}
- struct ListenerDeathRecipient : public HwDeathRecipient {
- ListenerDeathRecipient(const wp<Component>& comp)
- : component{comp} {
- }
+ mDeathRecipient = ::ndk::ScopedAIBinder_DeathRecipient(
+ AIBinder_DeathRecipient_new(OnBinderDied));
+ mDeathContext = new DeathContext{weak_from_this()};
+ AIBinder_DeathRecipient_setOnUnlinked(mDeathRecipient.get(), OnBinderUnlinked);
+ AIBinder_linkToDeath(mListener->asBinder().get(), mDeathRecipient.get(), mDeathContext);
+}
- virtual void serviceDied(
- uint64_t /* cookie */,
- const wp<::android::hidl::base::V1_0::IBase>& /* who */
- ) override {
- auto strongComponent = component.promote();
- if (strongComponent) {
- LOG(INFO) << "Client died ! release the component !!";
- strongComponent->release();
- } else {
- LOG(ERROR) << "Client died ! no component to release !!";
- }
- }
-
- wp<Component> component;
- };
-
- mDeathRecipient = new ListenerDeathRecipient(self);
- Return<bool> transStatus = mListener->linkToDeath(
- mDeathRecipient, 0);
- if (!transStatus.isOk()) {
- LOG(ERROR) << "Listener linkToDeath() transaction failed.";
+// static
+void Component::OnBinderDied(void *cookie) {
+ DeathContext *context = (DeathContext *)cookie;
+ std::shared_ptr<Component> comp = context->mWeakComp.lock();
+ if (comp) {
+ comp->release();
}
- if (!static_cast<bool>(transStatus)) {
- LOG(DEBUG) << "Listener linkToDeath() call failed.";
- }
+}
+
+// static
+void Component::OnBinderUnlinked(void *cookie) {
+ delete (DeathContext *)cookie;
}
Component::~Component() {
InputBufferManager::unregisterFrameData(mListener);
mStore->reportComponentDeath(this);
+ if (mDeathRecipient.get()) {
+ AIBinder_unlinkToDeath(mListener->asBinder().get(), mDeathRecipient.get(), mDeathContext);
+ }
}
} // namespace utils
-} // namespace V1_2
} // namespace c2
} // namespace media
} // namespace hardware
} // namespace android
+} // namespace aidl
diff --git a/media/codec2/hal/aidl/ComponentInterface.cpp b/media/codec2/hal/aidl/ComponentInterface.cpp
index 12078e0..2d812c9 100644
--- a/media/codec2/hal/aidl/ComponentInterface.cpp
+++ b/media/codec2/hal/aidl/ComponentInterface.cpp
@@ -18,28 +18,26 @@
#define LOG_TAG "Codec2-ComponentInterface"
#include <android-base/logging.h>
-#include <codec2/hidl/1.0/Component.h>
-#include <codec2/hidl/1.0/ComponentInterface.h>
-#include <codec2/hidl/1.0/ComponentStore.h>
+#include <android/binder_auto_utils.h>
+#include <codec2/aidl/ComponentInterface.h>
+#include <codec2/aidl/Configurable.h>
-#include <hidl/HidlBinderSupport.h>
#include <utils/Timers.h>
-#include <C2BqBufferPriv.h>
#include <C2Debug.h>
#include <C2PlatformSupport.h>
#include <chrono>
#include <thread>
+namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
-namespace V1_0 {
namespace utils {
-using namespace ::android;
+using ::ndk::ScopedAStatus;
namespace /* unnamed */ {
@@ -89,7 +87,8 @@
const std::shared_ptr<C2ComponentInterface>& intf,
const std::shared_ptr<ParameterCache>& cache)
: mInterface{intf},
- mConfigurable{new CachedConfigurable(std::make_unique<CompIntf>(intf))} {
+ mConfigurable{SharedRefBase::make<CachedConfigurable>(
+ std::make_unique<CompIntf>(intf))} {
mInit = mConfigurable->init(cache);
}
@@ -97,14 +96,16 @@
return mInit;
}
-Return<sp<IConfigurable>> ComponentInterface::getConfigurable() {
- return mConfigurable;
+ScopedAStatus ComponentInterface::getConfigurable(
+ std::shared_ptr<IConfigurable> *configurable) {
+ *configurable = mConfigurable;
+ return ScopedAStatus::ok();
}
} // namespace utils
-} // namespace V1_0
} // namespace c2
} // namespace media
} // namespace hardware
} // namespace android
+} // namespace aidl
diff --git a/media/codec2/hal/aidl/ComponentStore.cpp b/media/codec2/hal/aidl/ComponentStore.cpp
index 9fac5d5..19734c0 100644
--- a/media/codec2/hal/aidl/ComponentStore.cpp
+++ b/media/codec2/hal/aidl/ComponentStore.cpp
@@ -15,15 +15,16 @@
*/
//#define LOG_NDEBUG 0
-#define LOG_TAG "Codec2-ComponentStore@1.2"
+#define LOG_TAG "Codec2-ComponentStore-Aidl"
#include <android-base/logging.h>
-#include <codec2/hidl/1.2/ComponentStore.h>
-#include <codec2/hidl/1.2/InputSurface.h>
-#include <codec2/hidl/1.2/types.h>
+#include <bufferpool2/ClientManager.h>
+#include <codec2/aidl/Component.h>
+#include <codec2/aidl/ComponentInterface.h>
+#include <codec2/aidl/ComponentStore.h>
+#include <codec2/aidl/ParamTypes.h>
#include <android-base/file.h>
-#include <media/stagefright/bqhelper/GraphicBufferSource.h>
#include <utils/Errors.h>
#include <C2PlatformSupport.h>
@@ -43,16 +44,16 @@
#include <FilterWrapper.h>
#endif
+namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
-namespace V1_2 {
namespace utils {
-using namespace ::android;
-using ::android::GraphicBufferSource;
-using namespace ::android::hardware::media::bufferpool::V2_0::implementation;
+using ::android::DefaultFilterPlugin;
+using ::android::FilterWrapper;
+using ::ndk::ScopedAStatus;
namespace /* unnamed */ {
@@ -131,12 +132,13 @@
};
ComponentStore::ComponentStore(const std::shared_ptr<C2ComponentStore>& store)
- : mConfigurable{new CachedConfigurable(std::make_unique<StoreIntf>(store))},
+ : mConfigurable{SharedRefBase::make<CachedConfigurable>(std::make_unique<StoreIntf>(store))},
mParameterCache{std::make_shared<StoreParameterCache>(this)},
mStore{store} {
- std::shared_ptr<C2ComponentStore> platformStore = android::GetCodec2PlatformComponentStore();
- SetPreferredCodec2ComponentStore(store);
+ std::shared_ptr<C2ComponentStore> platformStore =
+ ::android::GetCodec2PlatformComponentStore();
+ ::android::SetPreferredCodec2ComponentStore(store);
// Retrieve struct descriptors
mParamReflector = mStore->getParamReflector();
@@ -194,93 +196,78 @@
}
#endif
-// Methods from ::android::hardware::media::c2::V1_0::IComponentStore
-Return<void> ComponentStore::createComponent(
- const hidl_string& name,
- const sp<IComponentListener>& listener,
- const sp<IClientManager>& pool,
- createComponent_cb _hidl_cb) {
+// Methods from ::aidl::android::hardware::media::c2::IComponentStore
+ScopedAStatus ComponentStore::createComponent(
+ const std::string& name,
+ const std::shared_ptr<IComponentListener>& listener,
+ const std::shared_ptr<IClientManager>& pool,
+ std::shared_ptr<IComponent> *component) {
- sp<Component> component;
std::shared_ptr<C2Component> c2component;
- Status status = static_cast<Status>(
- mStore->createComponent(name, &c2component));
+ c2_status_t status =
+ mStore->createComponent(name, &c2component);
- if (status == Status::OK) {
+ if (status == C2_OK) {
#ifndef __ANDROID_APEX__
c2component = GetFilterWrapper()->maybeWrapComponent(c2component);
#endif
onInterfaceLoaded(c2component->intf());
- component = new Component(c2component, listener, this, pool);
+ std::shared_ptr<Component> comp =
+ SharedRefBase::make<Component>(c2component, listener, shared_from_this(), pool);
+ *component = comp;
if (!component) {
- status = Status::CORRUPTED;
+ status = C2_CORRUPTED;
} else {
- reportComponentBirth(component.get());
- if (component->status() != C2_OK) {
- status = static_cast<Status>(component->status());
+ reportComponentBirth(comp.get());
+ if (comp->status() != C2_OK) {
+ status = comp->status();
} else {
- component->initListener(component);
- if (component->status() != C2_OK) {
- status = static_cast<Status>(component->status());
+ comp->initListener(comp);
+ if (comp->status() != C2_OK) {
+ status = comp->status();
}
}
}
}
- _hidl_cb(status, component);
- return Void();
+ if (status == C2_OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(status);
}
-Return<void> ComponentStore::createInterface(
- const hidl_string& name,
- createInterface_cb _hidl_cb) {
+ScopedAStatus ComponentStore::createInterface(
+ const std::string& name,
+ std::shared_ptr<IComponentInterface> *intf) {
std::shared_ptr<C2ComponentInterface> c2interface;
c2_status_t res = mStore->createInterface(name, &c2interface);
- sp<IComponentInterface> interface;
if (res == C2_OK) {
#ifndef __ANDROID_APEX__
c2interface = GetFilterWrapper()->maybeWrapInterface(c2interface);
#endif
onInterfaceLoaded(c2interface);
- interface = new ComponentInterface(c2interface, mParameterCache);
+ *intf = SharedRefBase::make<ComponentInterface>(c2interface, mParameterCache);
+ return ScopedAStatus::ok();
}
- _hidl_cb(static_cast<Status>(res), interface);
- return Void();
+ return ScopedAStatus::fromServiceSpecificError(res);
}
-Return<void> ComponentStore::listComponents(listComponents_cb _hidl_cb) {
+ScopedAStatus ComponentStore::listComponents(
+ std::vector<IComponentStore::ComponentTraits> *traits) {
std::vector<std::shared_ptr<const C2Component::Traits>> c2traits =
mStore->listComponents();
- hidl_vec<IComponentStore::ComponentTraits> traits(c2traits.size());
+ traits->resize(c2traits.size());
size_t ix = 0;
for (const std::shared_ptr<const C2Component::Traits> &c2trait : c2traits) {
if (c2trait) {
- if (objcpy(&traits[ix], *c2trait)) {
+ if (ToAidl(&traits->at(ix), *c2trait)) {
++ix;
} else {
break;
}
}
}
- traits.resize(ix);
- _hidl_cb(Status::OK, traits);
- return Void();
-}
-
-Return<void> ComponentStore::createInputSurface(createInputSurface_cb _hidl_cb) {
- sp<GraphicBufferSource> source = new GraphicBufferSource();
- if (source->initCheck() != OK) {
- _hidl_cb(Status::CORRUPTED, nullptr);
- return Void();
- }
- using namespace std::placeholders;
- sp<InputSurface> inputSurface = new InputSurface(
- mParameterCache,
- std::make_shared<C2ReflectorHelper>(),
- source->getHGraphicBufferProducer(),
- source);
- _hidl_cb(inputSurface ? Status::OK : Status::NO_MEMORY,
- inputSurface);
- return Void();
+ traits->resize(ix);
+ return ScopedAStatus::ok();
}
void ComponentStore::onInterfaceLoaded(const std::shared_ptr<C2ComponentInterface> &intf) {
@@ -293,15 +280,16 @@
}
}
-Return<void> ComponentStore::getStructDescriptors(
- const hidl_vec<uint32_t>& indices,
- getStructDescriptors_cb _hidl_cb) {
- hidl_vec<StructDescriptor> descriptors(indices.size());
+ScopedAStatus ComponentStore::getStructDescriptors(
+ const std::vector<int32_t>& indices,
+ std::vector<StructDescriptor> *descriptors) {
+ descriptors->resize(indices.size());
size_t dstIx = 0;
- Status res = Status::OK;
+ int32_t res = Status::OK;
for (size_t srcIx = 0; srcIx < indices.size(); ++srcIx) {
std::lock_guard<std::mutex> lock(mStructDescriptorsMutex);
- const C2Param::CoreIndex coreIndex = C2Param::CoreIndex(indices[srcIx]).coreIndex();
+ const C2Param::CoreIndex coreIndex =
+ C2Param::CoreIndex(uint32_t(indices[srcIx])).coreIndex();
const auto item = mStructDescriptors.find(coreIndex);
if (item == mStructDescriptors.end()) {
// not in the cache, and not known to be unsupported, query local reflector
@@ -312,7 +300,7 @@
mUnsupportedStructDescriptors.emplace(coreIndex);
} else {
mStructDescriptors.insert({ coreIndex, structDesc });
- if (objcpy(&descriptors[dstIx], *structDesc)) {
+ if (ToAidl(&descriptors->at(dstIx), *structDesc)) {
++dstIx;
continue;
}
@@ -322,7 +310,7 @@
}
res = Status::NOT_FOUND;
} else if (item->second) {
- if (objcpy(&descriptors[dstIx], *item->second)) {
+ if (ToAidl(&descriptors->at(dstIx), *item->second)) {
++dstIx;
continue;
}
@@ -333,96 +321,31 @@
break;
}
}
- descriptors.resize(dstIx);
- _hidl_cb(res, descriptors);
- return Void();
+ descriptors->resize(dstIx);
+ if (res == Status::OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(res);
}
-Return<sp<IClientManager>> ComponentStore::getPoolClientManager() {
- return ClientManager::getInstance();
+ScopedAStatus ComponentStore::getPoolClientManager(
+ std::shared_ptr<IClientManager> *manager) {
+ using ::aidl::android::hardware::media::bufferpool2::implementation::ClientManager;
+ *manager = ClientManager::getInstance();
+ return ScopedAStatus::ok();
}
-Return<Status> ComponentStore::copyBuffer(const Buffer& src, const Buffer& dst) {
+ScopedAStatus ComponentStore::copyBuffer(const Buffer& src, const Buffer& dst) {
// TODO implement
(void)src;
(void)dst;
- return Status::OMITTED;
+ return ScopedAStatus::fromServiceSpecificError(Status::OMITTED);
}
-Return<sp<IConfigurable>> ComponentStore::getConfigurable() {
- return mConfigurable;
-}
-
-// Methods from ::android::hardware::media::c2::V1_1::IComponentStore
-Return<void> ComponentStore::createComponent_1_1(
- const hidl_string& name,
- const sp<IComponentListener>& listener,
- const sp<IClientManager>& pool,
- createComponent_1_1_cb _hidl_cb) {
-
- sp<Component> component;
- std::shared_ptr<C2Component> c2component;
- Status status = static_cast<Status>(
- mStore->createComponent(name, &c2component));
-
- if (status == Status::OK) {
-#ifndef __ANDROID_APEX__
- c2component = GetFilterWrapper()->maybeWrapComponent(c2component);
-#endif
- onInterfaceLoaded(c2component->intf());
- component = new Component(c2component, listener, this, pool);
- if (!component) {
- status = Status::CORRUPTED;
- } else {
- reportComponentBirth(component.get());
- if (component->status() != C2_OK) {
- status = static_cast<Status>(component->status());
- } else {
- component->initListener(component);
- if (component->status() != C2_OK) {
- status = static_cast<Status>(component->status());
- }
- }
- }
- }
- _hidl_cb(status, component);
- return Void();
-}
-
-// Methods from ::android::hardware::media::c2::V1_2::IComponentStore
-Return<void> ComponentStore::createComponent_1_2(
- const hidl_string& name,
- const sp<IComponentListener>& listener,
- const sp<IClientManager>& pool,
- createComponent_1_2_cb _hidl_cb) {
-
- sp<Component> component;
- std::shared_ptr<C2Component> c2component;
- Status status = static_cast<Status>(
- mStore->createComponent(name, &c2component));
-
- if (status == Status::OK) {
-#ifndef __ANDROID_APEX__
- c2component = GetFilterWrapper()->maybeWrapComponent(c2component);
-#endif
- onInterfaceLoaded(c2component->intf());
- component = new Component(c2component, listener, this, pool);
- if (!component) {
- status = Status::CORRUPTED;
- } else {
- reportComponentBirth(component.get());
- if (component->status() != C2_OK) {
- status = static_cast<Status>(component->status());
- } else {
- component->initListener(component);
- if (component->status() != C2_OK) {
- status = static_cast<Status>(component->status());
- }
- }
- }
- }
- _hidl_cb(status, component);
- return Void();
+ScopedAStatus ComponentStore::getConfigurable(
+ std::shared_ptr<IConfigurable> *configurable) {
+ *configurable = mConfigurable;
+ return ScopedAStatus::ok();
}
// Called from createComponent() after a successful creation of `component`.
@@ -495,16 +418,9 @@
}
// Dumps information when lshal is called.
-Return<void> ComponentStore::debug(
- const hidl_handle& handle,
- const hidl_vec<hidl_string>& /* args */) {
+binder_status_t ComponentStore::dump(
+ int fd, [[maybe_unused]] const char** args, [[maybe_unused]] uint32_t numArgs) {
LOG(INFO) << "debug -- dumping...";
- const native_handle_t *h = handle.getNativeHandle();
- if (!h || h->numFds != 1) {
- LOG(ERROR) << "debug -- dumping failed -- "
- "invalid file descriptor to dump to";
- return Void();
- }
std::ostringstream out;
{ // Populate "out".
@@ -546,17 +462,17 @@
<< mStore->getName() << std::endl;
}
- if (!android::base::WriteStringToFd(out.str(), h->data[0])) {
+ if (!::android::base::WriteStringToFd(out.str(), fd)) {
PLOG(WARNING) << "debug -- dumping failed -- write()";
} else {
LOG(INFO) << "debug -- dumping succeeded";
}
- return Void();
+ return STATUS_OK;
}
} // namespace utils
-} // namespace V1_2
} // namespace c2
} // namespace media
} // namespace hardware
} // namespace android
+} // namespace aidl
diff --git a/media/codec2/hal/aidl/Configurable.cpp b/media/codec2/hal/aidl/Configurable.cpp
index 530576d..0326263 100644
--- a/media/codec2/hal/aidl/Configurable.cpp
+++ b/media/codec2/hal/aidl/Configurable.cpp
@@ -15,23 +15,23 @@
*/
//#define LOG_NDEBUG 0
-#define LOG_TAG "Codec2-Configurable"
+#define LOG_TAG "Codec2-Configurable-Aidl"
#include <android-base/logging.h>
-#include <codec2/hidl/1.0/Configurable.h>
-#include <codec2/hidl/1.0/ComponentStore.h>
-#include <codec2/hidl/1.0/types.h>
+#include <android/binder_auto_utils.h>
+#include <codec2/aidl/Configurable.h>
+#include <codec2/aidl/ParamTypes.h>
#include <C2ParamInternal.h>
+namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
-namespace V1_0 {
namespace utils {
-using namespace ::android;
+using ::ndk::ScopedAStatus;
CachedConfigurable::CachedConfigurable(
std::unique_ptr<ConfigurableC2Intf>&& intf)
@@ -47,19 +47,21 @@
}
// Methods from ::android::hardware::media::c2::V1_0::IConfigurable follow.
-Return<uint32_t> CachedConfigurable::getId() {
- return mIntf->getId();
+
+ScopedAStatus CachedConfigurable::getId(int32_t* id) {
+ *id = mIntf->getId();
+ return ScopedAStatus::ok();
}
-Return<void> CachedConfigurable::getName(getName_cb _hidl_cb) {
- _hidl_cb(mIntf->getName());
- return Void();
+ScopedAStatus CachedConfigurable::getName(std::string* name) {
+ *name = mIntf->getName();
+ return ScopedAStatus::ok();
}
-Return<void> CachedConfigurable::query(
- const hidl_vec<uint32_t>& indices,
+ScopedAStatus CachedConfigurable::query(
+ const std::vector<int32_t>& indices,
bool mayBlock,
- query_cb _hidl_cb) {
+ Params* params) {
typedef C2Param::Index Index;
std::vector<Index> c2heapParamIndices(
(Index*)indices.data(),
@@ -70,27 +72,24 @@
mayBlock ? C2_MAY_BLOCK : C2_DONT_BLOCK,
&c2heapParams);
- hidl_vec<uint8_t> params;
- if (!createParamsBlob(¶ms, c2heapParams)) {
+ if (!CreateParamsBlob(params, c2heapParams)) {
LOG(WARNING) << "query -- invalid output params.";
}
- _hidl_cb(static_cast<Status>(c2res), params);
- return Void();
+ if (c2res == C2_OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(c2res);
}
-Return<void> CachedConfigurable::config(
- const hidl_vec<uint8_t>& inParams,
+ScopedAStatus CachedConfigurable::config(
+ const Params& params,
bool mayBlock,
- config_cb _hidl_cb) {
+ ConfigResult* result) {
// inParams is not writable, so create a copy as config modifies the parameters
- hidl_vec<uint8_t> inParamsCopy = inParams;
std::vector<C2Param*> c2params;
- if (!parseParamsBlob(&c2params, inParamsCopy)) {
+ if (!ParseParamsBlob(&c2params, params)) {
LOG(WARNING) << "config -- invalid input params.";
- _hidl_cb(Status::CORRUPTED,
- hidl_vec<SettingResult>(),
- hidl_vec<uint8_t>());
- return Void();
+ return ScopedAStatus::fromServiceSpecificError(C2_CORRUPTED);
}
// TODO: check if blob was invalid
std::vector<std::unique_ptr<C2SettingResult>> c2failures;
@@ -98,12 +97,12 @@
c2params,
mayBlock ? C2_MAY_BLOCK : C2_DONT_BLOCK,
&c2failures);
- hidl_vec<SettingResult> failures(c2failures.size());
+ result->failures.resize(c2failures.size());
{
size_t ix = 0;
for (const std::unique_ptr<C2SettingResult>& c2result : c2failures) {
if (c2result) {
- if (objcpy(&failures[ix], *c2result)) {
+ if (ToAidl(&result->failures[ix], *c2result)) {
++ix;
} else {
LOG(DEBUG) << "config -- invalid setting results.";
@@ -111,28 +110,29 @@
}
}
}
- failures.resize(ix);
+ result->failures.resize(ix);
}
- hidl_vec<uint8_t> outParams;
- if (!createParamsBlob(&outParams, c2params)) {
+ if (!CreateParamsBlob(&result->params, c2params)) {
LOG(DEBUG) << "config -- invalid output params.";
}
- _hidl_cb((Status)c2res, failures, outParams);
- return Void();
+ if (c2res == C2_OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(c2res);
}
-Return<void> CachedConfigurable::querySupportedParams(
- uint32_t start,
- uint32_t count,
- querySupportedParams_cb _hidl_cb) {
+ScopedAStatus CachedConfigurable::querySupportedParams(
+ int32_t start,
+ int32_t count,
+ std::vector<ParamDescriptor>* paramDesc) {
C2LinearRange request = C2LinearCapacity(mSupportedParams.size()).range(
start, count);
- hidl_vec<ParamDescriptor> params(request.size());
- Status res = Status::OK;
+ paramDesc->resize(request.size());
+ int32_t res = Status::OK;
size_t dstIx = 0;
for (size_t srcIx = request.offset(); srcIx < request.endOffset(); ++srcIx) {
if (mSupportedParams[srcIx]) {
- if (objcpy(¶ms[dstIx], *mSupportedParams[srcIx])) {
+ if (ToAidl(&(*paramDesc)[dstIx], *mSupportedParams[srcIx])) {
++dstIx;
} else {
res = Status::CORRUPTED;
@@ -143,26 +143,28 @@
res = Status::BAD_INDEX;
}
}
- params.resize(dstIx);
- _hidl_cb(res, params);
- return Void();
+ paramDesc->resize(dstIx);
+ if (res == Status::OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(res);
}
-Return<void> CachedConfigurable::querySupportedValues(
- const hidl_vec<FieldSupportedValuesQuery>& inFields,
+ScopedAStatus CachedConfigurable::querySupportedValues(
+ const std::vector<FieldSupportedValuesQuery>& fields,
bool mayBlock,
- querySupportedValues_cb _hidl_cb) {
+ std::vector<FieldSupportedValuesQueryResult>* result) {
std::vector<C2FieldSupportedValuesQuery> c2fields;
{
// C2FieldSupportedValuesQuery objects are restricted in that some
// members are const.
// C2ParamField - required for its constructor - has no constructors
// from fields. Use C2ParamInspector.
- for (const FieldSupportedValuesQuery &query : inFields) {
+ for (const FieldSupportedValuesQuery &query : fields) {
c2fields.emplace_back(_C2ParamInspector::CreateParamField(
- query.field.index,
+ (uint32_t)query.field.index,
query.field.fieldId.offset,
- query.field.fieldId.size),
+ query.field.fieldId.sizeBytes),
query.type == FieldSupportedValuesQuery::Type::POSSIBLE ?
C2FieldSupportedValuesQuery::POSSIBLE :
C2FieldSupportedValuesQuery::CURRENT);
@@ -171,26 +173,28 @@
c2_status_t c2res = mIntf->querySupportedValues(
c2fields,
mayBlock ? C2_MAY_BLOCK : C2_DONT_BLOCK);
- hidl_vec<FieldSupportedValuesQueryResult> outFields(inFields.size());
+ result->resize(fields.size());
size_t dstIx = 0;
- for (const C2FieldSupportedValuesQuery &result : c2fields) {
- if (objcpy(&outFields[dstIx], result)) {
+ for (const C2FieldSupportedValuesQuery &res : c2fields) {
+ if (ToAidl(&(*result)[dstIx], res)) {
++dstIx;
} else {
- outFields.resize(dstIx);
+ result->resize(dstIx);
c2res = C2_CORRUPTED;
LOG(WARNING) << "querySupportedValues -- invalid output params.";
break;
}
}
- _hidl_cb((Status)c2res, outFields);
- return Void();
+ if (c2res == C2_OK) {
+ return ScopedAStatus::ok();
+ }
+ return ScopedAStatus::fromServiceSpecificError(c2res);
}
} // namespace utils
-} // namespace V1_0
} // namespace c2
} // namespace media
} // namespace hardware
} // namespace android
+} // namespace aidl
diff --git a/media/codec2/hal/aidl/InputBufferManager.cpp b/media/codec2/hal/aidl/InputBufferManager.cpp
index 8c0d0a4..5c58155 100644
--- a/media/codec2/hal/aidl/InputBufferManager.cpp
+++ b/media/codec2/hal/aidl/InputBufferManager.cpp
@@ -15,13 +15,12 @@
*/
//#define LOG_NDEBUG 0
-#define LOG_TAG "Codec2-InputBufferManager"
+#define LOG_TAG "Codec2-InputBufferManager-Aidl"
#include <android-base/logging.h>
-#include <codec2/hidl/1.0/InputBufferManager.h>
-#include <codec2/hidl/1.0/types.h>
+#include <codec2/aidl/InputBufferManager.h>
-#include <android/hardware/media/c2/1.0/IComponentListener.h>
+#include <aidl/android/hardware/media/c2/IComponentListener.h>
#include <android-base/logging.h>
#include <C2Buffer.h>
@@ -29,29 +28,29 @@
#include <chrono>
+namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
-namespace V1_0 {
namespace utils {
using namespace ::android;
void InputBufferManager::registerFrameData(
- const sp<IComponentListener>& listener,
+ const std::shared_ptr<IComponentListener>& listener,
const C2FrameData& input) {
getInstance()._registerFrameData(listener, input);
}
void InputBufferManager::unregisterFrameData(
- const wp<IComponentListener>& listener,
+ const std::weak_ptr<IComponentListener>& listener,
const C2FrameData& input) {
getInstance()._unregisterFrameData(listener, input);
}
void InputBufferManager::unregisterFrameData(
- const wp<IComponentListener>& listener) {
+ const std::weak_ptr<IComponentListener>& listener) {
getInstance()._unregisterFrameData(listener);
}
@@ -61,7 +60,7 @@
}
void InputBufferManager::_registerFrameData(
- const sp<IComponentListener>& listener,
+ const std::shared_ptr<IComponentListener>& listener,
const C2FrameData& input) {
uint64_t frameIndex = input.ordinal.frameIndex.peeku();
LOG(VERBOSE) << "InputBufferManager::_registerFrameData -- called with "
@@ -109,13 +108,11 @@
//
// This is called from onWorkDone() and flush().
void InputBufferManager::_unregisterFrameData(
- const wp<IComponentListener>& listener,
+ const std::weak_ptr<IComponentListener>& listener,
const C2FrameData& input) {
uint64_t frameIndex = input.ordinal.frameIndex.peeku();
LOG(VERBOSE) << "InputBufferManager::_unregisterFrameData -- called with "
- << "listener @ 0x" << std::hex << listener.unsafe_get()
- << ", frameIndex = " << std::dec << frameIndex
- << ".";
+ << "frameIndex = " << frameIndex << ".";
std::lock_guard<std::mutex> lock(mMutex);
auto findListener = mTrackedBuffersMap.find(listener);
@@ -134,11 +131,7 @@
if (status != C2_OK) {
LOG(DEBUG) << "InputBufferManager::_unregisterFrameData "
<< "-- unregisterOnDestroyNotify() failed "
- << "(listener @ 0x"
- << std::hex
- << bufferId->listener.unsafe_get()
- << ", frameIndex = "
- << std::dec << bufferId->frameIndex
+ << "(frameIndex = " << bufferId->frameIndex
<< ", bufferIndex = " << bufferId->bufferIndex
<< ") => status = " << status
<< ".";
@@ -173,10 +166,8 @@
// This is called when the component cleans up all input buffers, i.e., when
// reset(), release(), stop() or ~Component() is called.
void InputBufferManager::_unregisterFrameData(
- const wp<IComponentListener>& listener) {
- LOG(VERBOSE) << "InputBufferManager::_unregisterFrameData -- called with "
- << "listener @ 0x" << std::hex << listener.unsafe_get()
- << std::dec << ".";
+ const std::weak_ptr<IComponentListener>& listener) {
+ LOG(VERBOSE) << "InputBufferManager::_unregisterFrameData.";
std::lock_guard<std::mutex> lock(mMutex);
auto findListener = mTrackedBuffersMap.find(listener);
@@ -196,11 +187,7 @@
if (status != C2_OK) {
LOG(DEBUG) << "InputBufferManager::_unregisterFrameData "
<< "-- unregisterOnDestroyNotify() failed "
- << "(listener @ 0x"
- << std::hex
- << bufferId->listener.unsafe_get()
- << ", frameIndex = "
- << std::dec << bufferId->frameIndex
+ << "(frameIndex = " << bufferId->frameIndex
<< ", bufferIndex = " << bufferId->bufferIndex
<< ") => status = " << status
<< ".";
@@ -256,16 +243,14 @@
<< "buf @ 0x" << std::hex << buf
<< ", arg @ 0x" << std::hex << arg
<< std::dec << " -- "
- << "listener @ 0x" << std::hex << bufferId->listener.unsafe_get()
- << ", frameIndex = " << std::dec << bufferId->frameIndex
+ << ", frameIndex = " << bufferId->frameIndex
<< ", bufferIndex = " << bufferId->bufferIndex
<< ".";
auto findListener = mTrackedBuffersMap.find(bufferId->listener);
if (findListener == mTrackedBuffersMap.end()) {
LOG(VERBOSE) << "InputBufferManager::_onBufferDestroyed -- "
<< "received invalid listener: "
- << "listener @ 0x" << std::hex << bufferId->listener.unsafe_get()
- << " (frameIndex = " << std::dec << bufferId->frameIndex
+ << " (frameIndex = " << bufferId->frameIndex
<< ", bufferIndex = " << bufferId->bufferIndex
<< ").";
return;
@@ -278,8 +263,7 @@
LOG(DEBUG) << "InputBufferManager::_onBufferDestroyed -- "
<< "received invalid frame index: "
<< "frameIndex = " << bufferId->frameIndex
- << " (listener @ 0x" << std::hex << bufferId->listener.unsafe_get()
- << ", bufferIndex = " << std::dec << bufferId->bufferIndex
+ << ", bufferIndex = " << bufferId->bufferIndex
<< ").";
return;
}
@@ -291,8 +275,7 @@
<< "received invalid buffer index: "
<< "bufferIndex = " << bufferId->bufferIndex
<< " (frameIndex = " << bufferId->frameIndex
- << ", listener @ 0x" << std::hex << bufferId->listener.unsafe_get()
- << std::dec << ").";
+ << ").";
return;
}
@@ -320,9 +303,9 @@
bool InputBufferManager::processNotifications(nsecs_t* timeToRetryNs) {
struct Notification {
- sp<IComponentListener> listener;
- hidl_vec<IComponentListener::InputBuffer> inputBuffers;
- Notification(const sp<IComponentListener>& l, size_t s)
+ std::shared_ptr<IComponentListener> listener;
+ std::vector<IComponentListener::InputBuffer> inputBuffers;
+ Notification(const std::shared_ptr<IComponentListener>& l, size_t s)
: listener(l), inputBuffers(s) {}
};
std::list<Notification> notifications;
@@ -336,7 +319,7 @@
nsecs_t timeNowNs = systemTime();
for (auto it = mDeathNotifications.begin();
it != mDeathNotifications.end(); ) {
- sp<IComponentListener> listener = it->first.promote();
+ std::shared_ptr<IComponentListener> listener = it->first.lock();
if (!listener) {
++it;
continue;
@@ -371,7 +354,7 @@
// Create the argument for the callback.
notifications.emplace_back(listener, deathNotifications.count);
- hidl_vec<IComponentListener::InputBuffer> &inputBuffers =
+ std::vector<IComponentListener::InputBuffer> &inputBuffers =
notifications.back().inputBuffers;
size_t i = 0;
for (std::pair<const uint64_t, std::vector<size_t>>& p :
@@ -466,11 +449,9 @@
}
} // namespace utils
-} // namespace V1_0
} // namespace c2
} // namespace media
} // namespace hardware
} // namespace android
-
-
+} // namespace aidl
diff --git a/media/codec2/hal/aidl/InputSurface.cpp b/media/codec2/hal/aidl/InputSurface.cpp
deleted file mode 100644
index c3c32e9..0000000
--- a/media/codec2/hal/aidl/InputSurface.cpp
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "Codec2-InputSurface"
-#include <android-base/logging.h>
-
-#include <codec2/hidl/1.0/InputSurface.h>
-#include <codec2/hidl/1.0/InputSurfaceConnection.h>
-
-#include <C2Component.h>
-#include <C2Config.h>
-
-#include <memory>
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace c2 {
-namespace V1_0 {
-namespace utils {
-
-using namespace ::android;
-
-// Derived class of C2InterfaceHelper
-class InputSurface::Interface : public C2InterfaceHelper {
-public:
- explicit Interface(
- const std::shared_ptr<C2ReflectorHelper> &helper)
- : C2InterfaceHelper(helper) {
-
- setDerivedInstance(this);
-
- addParameter(
- DefineParam(mEos, C2_PARAMKEY_INPUT_SURFACE_EOS)
- .withDefault(new C2InputSurfaceEosTuning(false))
- .withFields({C2F(mEos, value).oneOf({true, false})})
- .withSetter(EosSetter)
- .build());
- }
-
- static C2R EosSetter(bool mayBlock, C2P<C2InputSurfaceEosTuning> &me) {
- (void)mayBlock;
- return me.F(me.v.value).validatePossible(me.v.value);
- }
-
- bool eos() const { return mEos->value; }
-
-private:
- std::shared_ptr<C2InputSurfaceEosTuning> mEos;
-};
-
-// Derived class of ConfigurableC2Intf
-class InputSurface::ConfigurableIntf : public ConfigurableC2Intf {
-public:
- ConfigurableIntf(
- const std::shared_ptr<InputSurface::Interface> &intf,
- const sp<GraphicBufferSource> &source)
- : ConfigurableC2Intf("input-surface", 0),
- mIntf(intf),
- mSource(source) {
- }
-
- virtual ~ConfigurableIntf() override = default;
-
- virtual c2_status_t query(
- const std::vector<C2Param::Index> &indices,
- c2_blocking_t mayBlock,
- std::vector<std::unique_ptr<C2Param>>* const params
- ) const override {
- return mIntf->query({}, indices, mayBlock, params);
- }
-
- virtual c2_status_t config(
- const std::vector<C2Param*> ¶ms,
- c2_blocking_t mayBlock,
- std::vector<std::unique_ptr<C2SettingResult>>* const failures
- ) override {
- c2_status_t err = mIntf->config(params, mayBlock, failures);
- if (mIntf->eos()) {
- sp<GraphicBufferSource> source = mSource.promote();
- if (source == nullptr || source->signalEndOfInputStream() != OK) {
- // TODO: put something in |failures|
- err = C2_BAD_VALUE;
- }
- // TODO: reset eos?
- }
- return err;
- }
-
- virtual c2_status_t querySupportedParams(
- std::vector<std::shared_ptr<C2ParamDescriptor>>* const params
- ) const override {
- return mIntf->querySupportedParams(params);
- }
-
- virtual c2_status_t querySupportedValues(
- std::vector<C2FieldSupportedValuesQuery>& fields,
- c2_blocking_t mayBlock) const override {
- return mIntf->querySupportedValues(fields, mayBlock);
- }
-
-private:
- const std::shared_ptr<InputSurface::Interface> mIntf;
- wp<GraphicBufferSource> mSource;
-};
-
-Return<sp<InputSurface::HGraphicBufferProducer>> InputSurface::getGraphicBufferProducer() {
- return mProducer;
-}
-
-Return<sp<IConfigurable>> InputSurface::getConfigurable() {
- return mConfigurable;
-}
-
-Return<void> InputSurface::connect(
- const sp<IInputSink>& sink,
- connect_cb _hidl_cb) {
- Status status;
- sp<InputSurfaceConnection> connection;
- if (!sink) {
- _hidl_cb(Status::BAD_VALUE, nullptr);
- return Void();
- }
- std::shared_ptr<C2Component> comp = Component::findLocalComponent(sink);
- if (comp) {
- connection = new InputSurfaceConnection(mSource, comp, mParameterCache);
- } else {
- connection = new InputSurfaceConnection(mSource, sink, mParameterCache);
- }
- if (!connection->init()) {
- connection = nullptr;
- status = Status::BAD_VALUE;
- } else {
- status = Status::OK;
- }
- _hidl_cb(status, connection);
- return Void();
-}
-
-// Constructor is exclusive to ComponentStore.
-InputSurface::InputSurface(
- const std::shared_ptr<ParameterCache>& cache,
- const std::shared_ptr<C2ReflectorHelper>& reflector,
- const sp<HGraphicBufferProducer>& producer,
- const sp<GraphicBufferSource>& source)
- : mParameterCache{cache},
- mProducer{producer},
- mSource{source},
- mIntf{std::make_shared<Interface>(reflector)},
- mConfigurable{new CachedConfigurable(
- std::make_unique<ConfigurableIntf>(
- mIntf, source))} {
-
- mConfigurable->init(mParameterCache);
-}
-
-} // namespace utils
-} // namespace V1_0
-} // namespace c2
-} // namespace media
-} // namespace hardware
-} // namespace android
-
diff --git a/media/codec2/hal/aidl/InputSurfaceConnection.cpp b/media/codec2/hal/aidl/InputSurfaceConnection.cpp
deleted file mode 100644
index 7c2e014..0000000
--- a/media/codec2/hal/aidl/InputSurfaceConnection.cpp
+++ /dev/null
@@ -1,531 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "Codec2-InputSurfaceConnection"
-#include <android-base/logging.h>
-
-#include <codec2/hidl/1.0/InputSurfaceConnection.h>
-#include <codec2/hidl/1.0/InputSurfaceConnection.h>
-
-#include <memory>
-#include <list>
-#include <mutex>
-#include <atomic>
-
-#include <hidl/HidlSupport.h>
-#include <media/stagefright/bqhelper/ComponentWrapper.h>
-#include <system/graphics.h>
-#include <ui/GraphicBuffer.h>
-#include <utils/Errors.h>
-
-#include <C2.h>
-#include <C2AllocatorGralloc.h>
-#include <C2BlockInternal.h>
-#include <C2Buffer.h>
-#include <C2Component.h>
-#include <C2Config.h>
-#include <C2Debug.h>
-#include <C2PlatformSupport.h>
-#include <C2Work.h>
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace c2 {
-namespace V1_0 {
-namespace utils {
-
-constexpr int32_t kBufferCount = 16;
-
-using namespace ::android;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-
-namespace /* unnamed */ {
-
-class Buffer2D : public C2Buffer {
-public:
- explicit Buffer2D(C2ConstGraphicBlock block) : C2Buffer({ block }) {
- }
-};
-
-} // unnamed namespace
-
-// Derived class of ComponentWrapper for use with
-// GraphicBufferSource::configure().
-//
-struct InputSurfaceConnection::Impl : public ComponentWrapper {
-
- Impl(const sp<GraphicBufferSource>& source,
- const std::shared_ptr<C2Component>& localComp)
- : mSource{source}, mLocalComp{localComp}, mSink{}, mFrameIndex{0} {
- std::shared_ptr<C2ComponentInterface> intf = localComp->intf();
- mSinkName = intf ? intf->getName() : "";
- }
-
- Impl(const sp<GraphicBufferSource>& source,
- const sp<IInputSink>& sink)
- : mSource{source}, mLocalComp{}, mSink{sink}, mFrameIndex{0} {
- Return<sp<IConfigurable>> transResult = sink->getConfigurable();
- if (!transResult.isOk()) {
- LOG(ERROR) << "Remote sink is dead.";
- return;
- }
- mSinkConfigurable =
- static_cast<sp<IConfigurable>>(transResult);
- if (!mSinkConfigurable) {
- LOG(ERROR) << "Remote sink is not configurable.";
- mSinkName = "";
- return;
- }
-
- hidl_string name;
- Return<void> transStatus = mSinkConfigurable->getName(
- [&name](const hidl_string& n) {
- name = n;
- });
- if (!transStatus.isOk()) {
- LOG(ERROR) << "Remote sink's configurable is dead.";
- mSinkName = "";
- return;
- }
- mSinkName = name.c_str();
- }
-
- virtual ~Impl() {
- mSource->stop();
- mSource->release();
- }
-
- bool init() {
- if (mSource == nullptr) {
- return false;
- }
- status_t err = mSource->initCheck();
- if (err != OK) {
- LOG(WARNING) << "Impl::init -- GraphicBufferSource init failed: "
- << "status = " << err << ".";
- return false;
- }
-
- // TODO: read settings properly from the interface
- C2StreamPictureSizeInfo::input inputSize;
- C2StreamUsageTuning::input usage;
- c2_status_t c2Status = queryFromSink({ &inputSize, &usage },
- {},
- C2_MAY_BLOCK,
- nullptr);
- if (c2Status != C2_OK) {
- LOG(WARNING) << "Impl::init -- cannot query information from "
- "the component interface: "
- << "status = " << asString(c2Status) << ".";
- return false;
- }
-
- // TODO: proper color aspect & dataspace
- android_dataspace dataSpace = HAL_DATASPACE_BT709;
-
- // TODO: use the usage read from intf
- // uint32_t grallocUsage =
- // C2AndroidMemoryUsage(C2MemoryUsage(usage.value)).
- // asGrallocUsage();
-
- uint32_t grallocUsage =
- mSinkName.compare(0, 11, "c2.android.") == 0 ?
- GRALLOC_USAGE_SW_READ_OFTEN :
- GRALLOC_USAGE_HW_VIDEO_ENCODER;
-
- err = mSource->configure(
- this, dataSpace, kBufferCount,
- inputSize.width, inputSize.height,
- grallocUsage);
- if (err != OK) {
- LOG(WARNING) << "Impl::init -- GBS configure failed: "
- << "status = " << err << ".";
- return false;
- }
- for (int32_t i = 0; i < kBufferCount; ++i) {
- if (mSource->onInputBufferAdded(i) != OK) {
- LOG(WARNING) << "Impl::init: failed to populate GBS slots.";
- return false;
- }
- }
- if (mSource->start() != OK) {
- LOG(WARNING) << "Impl::init -- GBS failed to start.";
- return false;
- }
- mAllocatorMutex.lock();
- c2_status_t c2err = GetCodec2PlatformAllocatorStore()->fetchAllocator(
- C2AllocatorStore::PLATFORM_START + 1, // GRALLOC
- &mAllocator);
- mAllocatorMutex.unlock();
- if (c2err != OK) {
- LOG(WARNING) << "Impl::init -- failed to fetch gralloc allocator: "
- << "status = " << asString(c2err) << ".";
- return false;
- }
- return true;
- }
-
- // From ComponentWrapper
- virtual status_t submitBuffer(
- int32_t bufferId,
- const sp<GraphicBuffer>& buffer,
- int64_t timestamp,
- int fenceFd) override {
- LOG(VERBOSE) << "Impl::submitBuffer -- bufferId = " << bufferId << ".";
- // TODO: Use fd to construct fence
- (void)fenceFd;
-
- std::shared_ptr<C2GraphicAllocation> alloc;
- C2Handle* handle = WrapNativeCodec2GrallocHandle(
- buffer->handle,
- buffer->width, buffer->height,
- buffer->format, buffer->usage, buffer->stride);
- mAllocatorMutex.lock();
- c2_status_t err = mAllocator->priorGraphicAllocation(handle, &alloc);
- mAllocatorMutex.unlock();
- if (err != OK) {
- native_handle_close(handle);
- native_handle_delete(handle);
- return UNKNOWN_ERROR;
- }
- std::shared_ptr<C2GraphicBlock> block =
- _C2BlockFactory::CreateGraphicBlock(alloc);
-
- std::unique_ptr<C2Work> work(new C2Work);
- work->input.flags = (C2FrameData::flags_t)0;
- work->input.ordinal.timestamp = timestamp;
- work->input.ordinal.frameIndex = mFrameIndex.fetch_add(
- 1, std::memory_order_relaxed);
- work->input.buffers.clear();
- std::shared_ptr<C2Buffer> c2Buffer(
- // TODO: fence
- new Buffer2D(block->share(
- C2Rect(block->width(), block->height()), ::C2Fence())),
- [bufferId, source = mSource](C2Buffer* ptr) {
- delete ptr;
- if (source != nullptr) {
- // TODO: fence
- (void)source->onInputBufferEmptied(bufferId, -1);
- }
- });
- work->input.buffers.push_back(c2Buffer);
- work->worklets.clear();
- work->worklets.emplace_back(new C2Worklet);
- std::list<std::unique_ptr<C2Work>> items;
- items.push_back(std::move(work));
-
- err = queueToSink(&items);
- return (err == C2_OK) ? OK : UNKNOWN_ERROR;
- }
-
- virtual status_t submitEos(int32_t bufferId) override {
- LOG(VERBOSE) << "Impl::submitEos -- bufferId = " << bufferId << ".";
- (void)bufferId;
-
- std::unique_ptr<C2Work> work(new C2Work);
- work->input.flags = (C2FrameData::flags_t)0;
- work->input.ordinal.frameIndex = mFrameIndex.fetch_add(
- 1, std::memory_order_relaxed);
- work->input.buffers.clear();
- work->worklets.clear();
- work->worklets.emplace_back(new C2Worklet);
- std::list<std::unique_ptr<C2Work>> items;
- items.push_back(std::move(work));
-
- c2_status_t err = queueToSink(&items);
- return (err == C2_OK) ? OK : UNKNOWN_ERROR;
- }
-
- virtual void dispatchDataSpaceChanged(
- int32_t dataSpace, int32_t aspects, int32_t pixelFormat) override {
- // TODO
- (void)dataSpace;
- (void)aspects;
- (void)pixelFormat;
- }
-
- // Configurable interface for InputSurfaceConnection::Impl.
- //
- // This class is declared as an inner class so that it will have access to
- // all Impl's members.
- struct ConfigurableIntf : public ConfigurableC2Intf {
- sp<Impl> mConnection;
- ConfigurableIntf(const sp<Impl>& connection)
- : ConfigurableC2Intf{"input-surface-connection", 0},
- mConnection{connection} {}
- virtual c2_status_t config(
- const std::vector<C2Param*> ¶ms,
- c2_blocking_t mayBlock,
- std::vector<std::unique_ptr<C2SettingResult>> *const failures
- ) override;
- virtual c2_status_t query(
- const std::vector<C2Param::Index> &indices,
- c2_blocking_t mayBlock,
- std::vector<std::unique_ptr<C2Param>> *const params) const override;
- virtual c2_status_t querySupportedParams(
- std::vector<std::shared_ptr<C2ParamDescriptor>> *const params
- ) const override;
- virtual c2_status_t querySupportedValues(
- std::vector<C2FieldSupportedValuesQuery> &fields,
- c2_blocking_t mayBlock) const override;
- };
-
-private:
- c2_status_t queryFromSink(
- const std::vector<C2Param*> &stackParams,
- const std::vector<C2Param::Index> &heapParamIndices,
- c2_blocking_t mayBlock,
- std::vector<std::unique_ptr<C2Param>>* const heapParams) {
- if (mLocalComp) {
- std::shared_ptr<C2ComponentInterface> intf = mLocalComp->intf();
- if (intf) {
- return intf->query_vb(stackParams,
- heapParamIndices,
- mayBlock,
- heapParams);
- } else {
- LOG(ERROR) << "queryFromSink -- "
- << "component does not have an interface.";
- return C2_BAD_STATE;
- }
- }
-
- CHECK(mSink) << "-- queryFromSink "
- << "-- connection has no sink.";
- CHECK(mSinkConfigurable) << "-- queryFromSink "
- << "-- sink has no configurable.";
-
- hidl_vec<ParamIndex> indices(
- stackParams.size() + heapParamIndices.size());
- size_t numIndices = 0;
- for (C2Param* const& stackParam : stackParams) {
- if (!stackParam) {
- LOG(DEBUG) << "queryFromSink -- null stack param encountered.";
- continue;
- }
- indices[numIndices++] = static_cast<ParamIndex>(stackParam->index());
- }
- size_t numStackIndices = numIndices;
- for (const C2Param::Index& index : heapParamIndices) {
- indices[numIndices++] =
- static_cast<ParamIndex>(static_cast<uint32_t>(index));
- }
- indices.resize(numIndices);
- if (heapParams) {
- heapParams->reserve(heapParams->size() + numIndices);
- }
- c2_status_t status;
- Return<void> transStatus = mSinkConfigurable->query(
- indices,
- mayBlock == C2_MAY_BLOCK,
- [&status, &numStackIndices, &stackParams, heapParams](
- Status s, const Params& p) {
- status = static_cast<c2_status_t>(s);
- if (status != C2_OK && status != C2_BAD_INDEX) {
- LOG(DEBUG) << "queryFromSink -- call failed: "
- << "status = " << asString(status) << ".";
- return;
- }
- std::vector<C2Param*> paramPointers;
- if (!parseParamsBlob(¶mPointers, p)) {
- LOG(DEBUG) << "queryFromSink -- error while "
- << "parsing params.";
- status = C2_CORRUPTED;
- return;
- }
- size_t i = 0;
- for (auto it = paramPointers.begin();
- it != paramPointers.end(); ) {
- C2Param* paramPointer = *it;
- if (numStackIndices > 0) {
- --numStackIndices;
- if (!paramPointer) {
- LOG(DEBUG) << "queryFromSink -- "
- "null stack param.";
- ++it;
- continue;
- }
- for (; i < stackParams.size() &&
- !stackParams[i]; ) {
- ++i;
- }
- CHECK(i < stackParams.size());
- if (stackParams[i]->index() !=
- paramPointer->index()) {
- LOG(DEBUG) << "queryFromSink -- "
- "param skipped (index = "
- << stackParams[i]->index() << ").";
- stackParams[i++]->invalidate();
- continue;
- }
- if (!stackParams[i++]->updateFrom(*paramPointer)) {
- LOG(DEBUG) << "queryFromSink -- "
- "param update failed (index = "
- << paramPointer->index() << ").";
- }
- } else {
- if (!paramPointer) {
- LOG(DEBUG) << "queryFromSink -- "
- "null heap param.";
- ++it;
- continue;
- }
- if (!heapParams) {
- LOG(WARNING) << "queryFromSink -- "
- "too many stack params.";
- break;
- }
- heapParams->emplace_back(C2Param::Copy(*paramPointer));
- }
- ++it;
- }
- });
- if (!transStatus.isOk()) {
- LOG(ERROR) << "queryFromSink -- transaction failed.";
- return C2_CORRUPTED;
- }
- return status;
- }
-
- c2_status_t queueToSink(std::list<std::unique_ptr<C2Work>>* const items) {
- if (mLocalComp) {
- return mLocalComp->queue_nb(items);
- }
-
- CHECK(mSink) << "-- queueToSink "
- << "-- connection has no sink.";
-
- WorkBundle workBundle;
- if (!objcpy(&workBundle, *items, nullptr)) {
- LOG(ERROR) << "queueToSink -- bad input.";
- return C2_CORRUPTED;
- }
- Return<Status> transStatus = mSink->queue(workBundle);
- if (!transStatus.isOk()) {
- LOG(ERROR) << "queueToSink -- transaction failed.";
- return C2_CORRUPTED;
- }
- c2_status_t status =
- static_cast<c2_status_t>(static_cast<Status>(transStatus));
- if (status != C2_OK) {
- LOG(DEBUG) << "queueToSink -- call failed: "
- << asString(status);
- }
- return status;
- }
-
- sp<GraphicBufferSource> mSource;
- std::shared_ptr<C2Component> mLocalComp;
- sp<IInputSink> mSink;
- sp<IConfigurable> mSinkConfigurable;
- std::string mSinkName;
-
- // Needed for ComponentWrapper implementation
- std::mutex mAllocatorMutex;
- std::shared_ptr<C2Allocator> mAllocator;
- std::atomic_uint64_t mFrameIndex;
-
-};
-
-InputSurfaceConnection::InputSurfaceConnection(
- const sp<GraphicBufferSource>& source,
- const std::shared_ptr<C2Component>& comp,
- const std::shared_ptr<ParameterCache>& cache)
- : mImpl{new Impl(source, comp)},
- mConfigurable{new CachedConfigurable(
- std::make_unique<Impl::ConfigurableIntf>(mImpl))} {
- mConfigurable->init(cache);
-}
-
-InputSurfaceConnection::InputSurfaceConnection(
- const sp<GraphicBufferSource>& source,
- const sp<IInputSink>& sink,
- const std::shared_ptr<ParameterCache>& cache)
- : mImpl{new Impl(source, sink)},
- mConfigurable{new CachedConfigurable(
- std::make_unique<Impl::ConfigurableIntf>(mImpl))} {
- mConfigurable->init(cache);
-}
-
-Return<Status> InputSurfaceConnection::disconnect() {
- std::lock_guard<std::mutex> lock(mImplMutex);
- mImpl = nullptr;
- return Status::OK;
-}
-
-InputSurfaceConnection::~InputSurfaceConnection() {
- mImpl = nullptr;
-}
-
-bool InputSurfaceConnection::init() {
- std::lock_guard<std::mutex> lock(mImplMutex);
- return mImpl->init();
-}
-
-Return<sp<IConfigurable>> InputSurfaceConnection::getConfigurable() {
- return mConfigurable;
-}
-
-// Configurable interface for InputSurfaceConnection::Impl
-c2_status_t InputSurfaceConnection::Impl::ConfigurableIntf::config(
- const std::vector<C2Param*> ¶ms,
- c2_blocking_t mayBlock,
- std::vector<std::unique_ptr<C2SettingResult>> *const failures) {
- // TODO: implement
- (void)params;
- (void)mayBlock;
- (void)failures;
- return C2_OK;
-}
-
-c2_status_t InputSurfaceConnection::Impl::ConfigurableIntf::query(
- const std::vector<C2Param::Index> &indices,
- c2_blocking_t mayBlock,
- std::vector<std::unique_ptr<C2Param>> *const params) const {
- // TODO: implement
- (void)indices;
- (void)mayBlock;
- (void)params;
- return C2_OK;
-}
-
-c2_status_t InputSurfaceConnection::Impl::ConfigurableIntf::querySupportedParams(
- std::vector<std::shared_ptr<C2ParamDescriptor>> *const params) const {
- // TODO: implement
- (void)params;
- return C2_OK;
-}
-
-c2_status_t InputSurfaceConnection::Impl::ConfigurableIntf::querySupportedValues(
- std::vector<C2FieldSupportedValuesQuery> &fields,
- c2_blocking_t mayBlock) const {
- // TODO: implement
- (void)fields;
- (void)mayBlock;
- return C2_OK;
-}
-
-} // namespace utils
-} // namespace V1_0
-} // namespace c2
-} // namespace media
-} // namespace hardware
-} // namespace android
-
diff --git a/media/codec2/hal/aidl/include/codec2/aidl/Component.h b/media/codec2/hal/aidl/include/codec2/aidl/Component.h
index e343655..d5ea92b 100644
--- a/media/codec2/hal/aidl/include/codec2/aidl/Component.h
+++ b/media/codec2/hal/aidl/include/codec2/aidl/Component.h
@@ -14,21 +14,19 @@
* limitations under the License.
*/
-#ifndef CODEC2_HIDL_V1_0_UTILS_COMPONENT_H
-#define CODEC2_HIDL_V1_0_UTILS_COMPONENT_H
+#ifndef CODEC2_AIDL_UTILS_COMPONENT_H
+#define CODEC2_AIDL_UTILS_COMPONENT_H
-#include <codec2/hidl/1.0/ComponentInterface.h>
-#include <codec2/hidl/1.0/Configurable.h>
-#include <codec2/hidl/1.0/types.h>
+#include <codec2/aidl/ComponentInterface.h>
+#include <codec2/aidl/Configurable.h>
+#include <codec2/aidl/BufferTypes.h>
+#include <codec2/aidl/ParamTypes.h>
-#include <android/hardware/media/bufferpool/2.0/IClientManager.h>
-#include <android/hardware/media/c2/1.0/IComponent.h>
-#include <android/hardware/media/c2/1.0/IComponentInterface.h>
-#include <android/hardware/media/c2/1.0/IComponentListener.h>
-#include <android/hardware/media/c2/1.0/IComponentStore.h>
-#include <android/hardware/media/c2/1.0/IInputSink.h>
-#include <hidl/Status.h>
-#include <hwbinder/IBinder.h>
+#include <aidl/android/hardware/media/bufferpool2/IClientManager.h>
+#include <aidl/android/hardware/media/c2/BnComponent.h>
+#include <aidl/android/hardware/media/c2/IComponentInterface.h>
+#include <aidl/android/hardware/media/c2/IComponentListener.h>
+#include <aidl/android/hardware/media/c2/IComponentStore.h>
#include <C2Component.h>
#include <C2Buffer.h>
@@ -38,86 +36,50 @@
#include <memory>
#include <mutex>
+namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
-namespace V1_0 {
namespace utils {
-using ::android::hardware::hidl_array;
-using ::android::hardware::hidl_memory;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::hardware::IBinder;
-using ::android::sp;
-using ::android::wp;
struct ComponentStore;
-struct Component : public IComponent,
+struct Component : public BnComponent,
public std::enable_shared_from_this<Component> {
Component(
const std::shared_ptr<C2Component>&,
- const sp<IComponentListener>& listener,
- const sp<ComponentStore>& store,
- const sp<::android::hardware::media::bufferpool::V2_0::
- IClientManager>& clientPoolManager);
+ const std::shared_ptr<IComponentListener>& listener,
+ const std::shared_ptr<ComponentStore>& store,
+ const std::shared_ptr<bufferpool2::IClientManager>& clientPoolManager);
c2_status_t status() const;
- typedef ::android::hardware::graphics::bufferqueue::V1_0::
- IGraphicBufferProducer HGraphicBufferProducer1;
- typedef ::android::hardware::graphics::bufferqueue::V2_0::
- IGraphicBufferProducer HGraphicBufferProducer2;
-
// Methods from IComponent follow.
- virtual Return<Status> queue(const WorkBundle& workBundle) override;
- virtual Return<void> flush(flush_cb _hidl_cb) override;
- virtual Return<Status> drain(bool withEos) override;
- virtual Return<Status> setOutputSurface(
- uint64_t blockPoolId,
- const sp<HGraphicBufferProducer2>& surface) override;
- virtual Return<void> connectToInputSurface(
- const sp<IInputSurface>& inputSurface,
- connectToInputSurface_cb _hidl_cb) override;
- virtual Return<void> connectToOmxInputSurface(
- const sp<HGraphicBufferProducer1>& producer,
- const sp<::android::hardware::media::omx::V1_0::
- IGraphicBufferSource>& source,
- connectToOmxInputSurface_cb _hidl_cb) override;
- virtual Return<Status> disconnectFromInputSurface() override;
- virtual Return<void> createBlockPool(
- uint32_t allocatorId,
- createBlockPool_cb _hidl_cb) override;
- virtual Return<Status> destroyBlockPool(uint64_t blockPoolId) override;
- virtual Return<Status> start() override;
- virtual Return<Status> stop() override;
- virtual Return<Status> reset() override;
- virtual Return<Status> release() override;
- virtual Return<sp<IComponentInterface>> getInterface() override;
- virtual Return<sp<IInputSink>> asInputSink() override;
-
- // Returns a C2Component associated to the given sink if the sink is indeed
- // a local component. Returns nullptr otherwise.
- //
- // This function is used by InputSurface::connect().
- static std::shared_ptr<C2Component> findLocalComponent(
- const sp<IInputSink>& sink);
+ ::ndk::ScopedAStatus queue(const WorkBundle& workBundle) override;
+ ::ndk::ScopedAStatus flush(WorkBundle *workBundle) override;
+ ::ndk::ScopedAStatus drain(bool withEos) override;
+ ::ndk::ScopedAStatus createBlockPool(
+ const IComponent::BlockPoolAllocator &allocator,
+ IComponent::BlockPool *blockPool) override;
+ ::ndk::ScopedAStatus destroyBlockPool(int64_t blockPoolId) override;
+ ::ndk::ScopedAStatus start() override;
+ ::ndk::ScopedAStatus stop() override;
+ ::ndk::ScopedAStatus reset() override;
+ ::ndk::ScopedAStatus release() override;
+ ::ndk::ScopedAStatus getInterface(
+ std::shared_ptr<IComponentInterface> *intf) override;
+ ::ndk::ScopedAStatus configureVideoTunnel(
+ int32_t avSyncHwId,
+ common::NativeHandle* handle) override;
protected:
c2_status_t mInit;
std::shared_ptr<C2Component> mComponent;
- sp<ComponentInterface> mInterface;
- sp<IComponentListener> mListener;
- sp<ComponentStore> mStore;
- ::android::hardware::media::c2::V1_0::utils::DefaultBufferPoolSender
- mBufferPoolSender;
-
- struct Sink;
- std::mutex mSinkMutex;
- sp<Sink> mSink;
+ std::shared_ptr<ComponentInterface> mInterface;
+ std::shared_ptr<IComponentListener> mListener;
+ std::shared_ptr<ComponentStore> mStore;
+ DefaultBufferPoolSender mBufferPoolSender;
std::mutex mBlockPoolsMutex;
// This map keeps C2BlockPool objects that are created by createBlockPool()
@@ -125,7 +87,7 @@
// destroyBlockPool(), reset() or release(), or by destroying the component.
std::map<uint64_t, std::shared_ptr<C2BlockPool>> mBlockPools;
- void initListener(const sp<Component>& self);
+ void initListener(const std::shared_ptr<Component>& self);
virtual ~Component() override;
@@ -133,15 +95,18 @@
struct Listener;
- using HwDeathRecipient = ::android::hardware::hidl_death_recipient;
- sp<HwDeathRecipient> mDeathRecipient;
+ ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
+ static void OnBinderDied(void *cookie);
+ static void OnBinderUnlinked(void *cookie);
+ struct DeathContext;
+ DeathContext *mDeathContext;
};
} // namespace utils
-} // namespace V1_0
} // namespace c2
} // namespace media
} // namespace hardware
} // namespace android
+} // namespace aidl
-#endif // CODEC2_HIDL_V1_0_UTILS_COMPONENT_H
+#endif // CODEC2_AIDL_UTILS_COMPONENT_H
diff --git a/media/codec2/hal/aidl/include/codec2/aidl/ComponentInterface.h b/media/codec2/hal/aidl/include/codec2/aidl/ComponentInterface.h
index 9102f92..7723bee 100644
--- a/media/codec2/hal/aidl/include/codec2/aidl/ComponentInterface.h
+++ b/media/codec2/hal/aidl/include/codec2/aidl/ComponentInterface.h
@@ -14,14 +14,13 @@
* limitations under the License.
*/
-#ifndef CODEC2_HIDL_V1_0_UTILS_COMPONENT_INTERFACE_H
-#define CODEC2_HIDL_V1_0_UTILS_COMPONENT_INTERFACE_H
+#ifndef CODEC2_AIDL_UTILS_COMPONENT_INTERFACE_H
+#define CODEC2_AIDL_UTILS_COMPONENT_INTERFACE_H
-#include <codec2/hidl/1.0/Configurable.h>
-#include <codec2/hidl/1.0/types.h>
+#include <codec2/aidl/Configurable.h>
+#include <codec2/aidl/ParamTypes.h>
-#include <android/hardware/media/c2/1.0/IComponentInterface.h>
-#include <hidl/Status.h>
+#include <aidl/android/hardware/media/c2/BnComponentInterface.h>
#include <C2Component.h>
#include <C2Buffer.h>
@@ -29,38 +28,35 @@
#include <memory>
+namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
-namespace V1_0 {
namespace utils {
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::sp;
-
struct ComponentStore;
-struct ComponentInterface : public IComponentInterface {
+struct ComponentInterface : public BnComponentInterface {
ComponentInterface(
const std::shared_ptr<C2ComponentInterface>& interface,
const std::shared_ptr<ParameterCache>& cache);
c2_status_t status() const;
- virtual Return<sp<IConfigurable>> getConfigurable() override;
+ ::ndk::ScopedAStatus getConfigurable(
+ std::shared_ptr<IConfigurable> *intf) override;
protected:
std::shared_ptr<C2ComponentInterface> mInterface;
- sp<CachedConfigurable> mConfigurable;
+ std::shared_ptr<CachedConfigurable> mConfigurable;
c2_status_t mInit;
};
} // namespace utils
-} // namespace V1_0
} // namespace c2
} // namespace media
} // namespace hardware
} // namespace android
+} // namespace aidl
-#endif // CODEC2_HIDL_V1_0_UTILS_COMPONENT_INTERFACE_H
+#endif // CODEC2_AIDL_UTILS_COMPONENT_INTERFACE_H
diff --git a/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h b/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h
index 27e2a05..7fc5d2f 100644
--- a/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h
+++ b/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h
@@ -14,16 +14,15 @@
* limitations under the License.
*/
-#ifndef CODEC2_HIDL_V1_0_UTILS_COMPONENTSTORE_H
-#define CODEC2_HIDL_V1_0_UTILS_COMPONENTSTORE_H
+#ifndef CODEC2_AIDL_UTILS_COMPONENTSTORE_H
+#define CODEC2_AIDL_UTILS_COMPONENTSTORE_H
-#include <codec2/hidl/1.0/Component.h>
-#include <codec2/hidl/1.0/ComponentInterface.h>
-#include <codec2/hidl/1.0/Configurable.h>
+#include <android/binder_auto_utils.h>
+#include <codec2/aidl/ComponentInterface.h>
+#include <codec2/aidl/Configurable.h>
-#include <android/hardware/media/bufferpool/2.0/IClientManager.h>
-#include <android/hardware/media/c2/1.0/IComponentStore.h>
-#include <hidl/Status.h>
+#include <aidl/android/hardware/media/bufferpool2/IClientManager.h>
+#include <aidl/android/hardware/media/c2/BnComponentStore.h>
#include <C2Component.h>
#include <C2Param.h>
@@ -38,23 +37,21 @@
namespace android {
class FilterWrapper;
+} // namespace android
+namespace aidl {
+namespace android {
namespace hardware {
namespace media {
namespace c2 {
-namespace V1_0 {
namespace utils {
-using ::android::hardware::media::bufferpool::V2_0::IClientManager;
+struct Component;
-using ::android::hardware::hidl_handle;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::sp;
+using ::aidl::android::hardware::media::bufferpool2::IClientManager;
-struct ComponentStore : public IComponentStore {
+struct ComponentStore : public BnComponentStore,
+ public std::enable_shared_from_this<ComponentStore> {
ComponentStore(const std::shared_ptr<C2ComponentStore>& store);
virtual ~ComponentStore();
@@ -76,38 +73,38 @@
*/
std::shared_ptr<ParameterCache> getParameterCache() const;
- static std::shared_ptr<FilterWrapper> GetFilterWrapper();
+ static std::shared_ptr<::android::FilterWrapper> GetFilterWrapper();
- // Methods from ::android::hardware::media::c2::V1_0::IComponentStore.
- virtual Return<void> createComponent(
- const hidl_string& name,
- const sp<IComponentListener>& listener,
- const sp<IClientManager>& pool,
- createComponent_cb _hidl_cb) override;
- virtual Return<void> createInterface(
- const hidl_string& name,
- createInterface_cb _hidl_cb) override;
- virtual Return<void> listComponents(listComponents_cb _hidl_cb) override;
- virtual Return<void> createInputSurface(
- createInputSurface_cb _hidl_cb) override;
- virtual Return<void> getStructDescriptors(
- const hidl_vec<uint32_t>& indices,
- getStructDescriptors_cb _hidl_cb) override;
- virtual Return<sp<IClientManager>> getPoolClientManager() override;
- virtual Return<Status> copyBuffer(
+ // Methods from ::aidl::android::hardware::media::c2::IComponentStore.
+ virtual ::ndk::ScopedAStatus createComponent(
+ const std::string& name,
+ const std::shared_ptr<IComponentListener>& listener,
+ const std::shared_ptr<IClientManager>& pool,
+ std::shared_ptr<IComponent> *component) override;
+ virtual ::ndk::ScopedAStatus createInterface(
+ const std::string& name,
+ std::shared_ptr<IComponentInterface> *intf) override;
+ virtual ::ndk::ScopedAStatus listComponents(
+ std::vector<IComponentStore::ComponentTraits>* traits) override;
+ virtual ::ndk::ScopedAStatus getStructDescriptors(
+ const std::vector<int32_t>& indices,
+ std::vector<StructDescriptor> *descs) override;
+ virtual ::ndk::ScopedAStatus getPoolClientManager(
+ std::shared_ptr<IClientManager> *manager) override;
+ virtual ::ndk::ScopedAStatus copyBuffer(
const Buffer& src,
const Buffer& dst) override;
- virtual Return<sp<IConfigurable>> getConfigurable() override;
+ virtual ::ndk::ScopedAStatus getConfigurable(
+ std::shared_ptr<IConfigurable> *configurable) override;
/**
* Dumps information when lshal is called.
*/
- virtual Return<void> debug(
- const hidl_handle& handle,
- const hidl_vec<hidl_string>& args) override;
+ virtual binder_status_t dump(
+ int fd, const char** args, uint32_t numArgs) override;
protected:
- sp<CachedConfigurable> mConfigurable;
+ std::shared_ptr<CachedConfigurable> mConfigurable;
struct StoreParameterCache;
std::shared_ptr<StoreParameterCache> mParameterCache;
@@ -153,10 +150,10 @@
};
} // namespace utils
-} // namespace V1_0
} // namespace c2
} // namespace media
} // namespace hardware
} // namespace android
+} // namespace aidl
-#endif // CODEC2_HIDL_V1_0_UTILS_COMPONENTSTORE_H
+#endif // CODEC2_AIDL_UTILS_COMPONENTSTORE_H
diff --git a/media/codec2/hal/aidl/include/codec2/aidl/Configurable.h b/media/codec2/hal/aidl/include/codec2/aidl/Configurable.h
index 8f49a97..6cc2c1b 100644
--- a/media/codec2/hal/aidl/include/codec2/aidl/Configurable.h
+++ b/media/codec2/hal/aidl/include/codec2/aidl/Configurable.h
@@ -14,11 +14,10 @@
* limitations under the License.
*/
-#ifndef CODEC2_HIDL_V1_0_UTILS_CONFIGURABLE_H
-#define CODEC2_HIDL_V1_0_UTILS_CONFIGURABLE_H
+#ifndef CODEC2_AIDL_UTILS_CONFIGURABLE_H
+#define CODEC2_AIDL_UTILS_CONFIGURABLE_H
-#include <android/hardware/media/c2/1.0/IConfigurable.h>
-#include <hidl/Status.h>
+#include <aidl/android/hardware/media/c2/BnConfigurable.h>
#include <C2Component.h>
#include <C2Param.h>
@@ -26,18 +25,13 @@
#include <memory>
+namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
-namespace V1_0 {
namespace utils {
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::sp;
-
struct ComponentStore;
/**
@@ -102,7 +96,7 @@
*
* Note that caching happens
*/
-struct CachedConfigurable : public IConfigurable {
+struct CachedConfigurable : public BnConfigurable {
CachedConfigurable(std::unique_ptr<ConfigurableC2Intf>&& intf);
// Populates mSupportedParams.
@@ -110,29 +104,29 @@
// Methods from ::android::hardware::media::c2::V1_0::IConfigurable
- virtual Return<uint32_t> getId() override;
+ virtual ::ndk::ScopedAStatus getId(int32_t* id) override;
- virtual Return<void> getName(getName_cb _hidl_cb) override;
+ virtual ::ndk::ScopedAStatus getName(std::string* name) override;
- virtual Return<void> query(
- const hidl_vec<uint32_t>& indices,
+ virtual ::ndk::ScopedAStatus query(
+ const std::vector<int32_t>& indices,
bool mayBlock,
- query_cb _hidl_cb) override;
+ Params* params) override;
- virtual Return<void> config(
- const hidl_vec<uint8_t>& inParams,
+ virtual ::ndk::ScopedAStatus config(
+ const ::aidl::android::hardware::media::c2::Params& params,
bool mayBlock,
- config_cb _hidl_cb) override;
+ ConfigResult* result) override;
- virtual Return<void> querySupportedParams(
- uint32_t start,
- uint32_t count,
- querySupportedParams_cb _hidl_cb) override;
+ virtual ::ndk::ScopedAStatus querySupportedParams(
+ int32_t start,
+ int32_t count,
+ std::vector<ParamDescriptor>* paramDesc) override;
- virtual Return<void> querySupportedValues(
- const hidl_vec<FieldSupportedValuesQuery>& inFields,
+ virtual ::ndk::ScopedAStatus querySupportedValues(
+ const std::vector<FieldSupportedValuesQuery>& fields,
bool mayBlock,
- querySupportedValues_cb _hidl_cb) override;
+ std::vector<FieldSupportedValuesQueryResult>* result) override;
protected:
// Common Codec2.0 interface wrapper
@@ -143,11 +137,11 @@
};
} // namespace utils
-} // namespace V1_0
} // namespace c2
} // namespace media
} // namespace hardware
} // namespace android
+} // namespace aidl
-#endif // CODEC2_HIDL_V1_0_UTILS_CONFIGURABLE_H
+#endif // CODEC2_AIDL_UTILS_CONFIGURABLE_H
diff --git a/media/codec2/hal/aidl/include/codec2/aidl/InputBufferManager.h b/media/codec2/hal/aidl/include/codec2/aidl/InputBufferManager.h
index 42fa557..4e107a8 100644
--- a/media/codec2/hal/aidl/include/codec2/aidl/InputBufferManager.h
+++ b/media/codec2/hal/aidl/include/codec2/aidl/InputBufferManager.h
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-#ifndef CODEC2_HIDL_V1_0_UTILS_INPUT_BUFFER_MANAGER_H
-#define CODEC2_HIDL_V1_0_UTILS_INPUT_BUFFER_MANAGER_H
+#ifndef CODEC2_AIDL_UTILS_INPUT_BUFFER_MANAGER_H
+#define CODEC2_AIDL_UTILS_INPUT_BUFFER_MANAGER_H
-#include <android/hardware/media/c2/1.0/IComponentListener.h>
+#include <aidl/android/hardware/media/c2/IComponentListener.h>
#include <utils/Timers.h>
#include <C2Buffer.h>
@@ -27,15 +27,13 @@
#include <map>
#include <thread>
+namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
-namespace V1_0 {
namespace utils {
-using namespace ::android;
-
/**
* InputBufferManager
* ==================
@@ -118,7 +116,7 @@
* \param input Input frame data whose input buffers are to be tracked.
*/
static void registerFrameData(
- const sp<IComponentListener>& listener,
+ const std::shared_ptr<IComponentListener>& listener,
const C2FrameData& input);
/**
@@ -134,7 +132,7 @@
* \param input Previously registered frame data.
*/
static void unregisterFrameData(
- const wp<IComponentListener>& listener,
+ const std::weak_ptr<IComponentListener>& listener,
const C2FrameData& input);
/**
@@ -150,7 +148,7 @@
* \param listener Previously registered listener.
*/
static void unregisterFrameData(
- const wp<IComponentListener>& listener);
+ const std::weak_ptr<IComponentListener>& listener);
/**
* Set the notification interval.
@@ -161,13 +159,13 @@
private:
void _registerFrameData(
- const sp<IComponentListener>& listener,
+ const std::shared_ptr<IComponentListener>& listener,
const C2FrameData& input);
void _unregisterFrameData(
- const wp<IComponentListener>& listener,
+ const std::weak_ptr<IComponentListener>& listener,
const C2FrameData& input);
void _unregisterFrameData(
- const wp<IComponentListener>& listener);
+ const std::weak_ptr<IComponentListener>& listener);
void _setNotificationInterval(nsecs_t notificationIntervalNs);
// The callback function tied to C2Buffer objects.
@@ -184,11 +182,11 @@
// Note that the "key" is bufferIndex according to operator<(). This is
// designed to work with TrackedBuffersMap defined below.
struct TrackedBuffer {
- wp<IComponentListener> listener;
+ std::weak_ptr<IComponentListener> listener;
uint64_t frameIndex;
size_t bufferIndex;
std::weak_ptr<C2Buffer> buffer;
- TrackedBuffer(const wp<IComponentListener>& listener,
+ TrackedBuffer(const std::weak_ptr<IComponentListener>& listener,
uint64_t frameIndex,
size_t bufferIndex,
const std::shared_ptr<C2Buffer>& buffer)
@@ -204,9 +202,10 @@
// However, the value of the innermost map is TrackedBuffer, which also
// contains an extra copy of listener and frameIndex. This is needed
// because onBufferDestroyed() needs to know listener and frameIndex too.
- typedef std::map<wp<IComponentListener>,
+ typedef std::map<std::weak_ptr<IComponentListener>,
std::map<uint64_t,
- std::set<TrackedBuffer*>>> TrackedBuffersMap;
+ std::set<TrackedBuffer*>>,
+ std::owner_less<std::weak_ptr<IComponentListener>>> TrackedBuffersMap;
// Storage for pending (unsent) death notifications for one listener.
// Each pair in member named "indices" are (frameIndex, bufferIndex) from
@@ -261,7 +260,9 @@
// A DeathNotifications object is associated to each listener. An entry in
// this map will be removed if its associated DeathNotifications has count =
// 0 and lastSentNs < systemTime() - mNotificationIntervalNs.
- std::map<wp<IComponentListener>, DeathNotifications> mDeathNotifications;
+ std::map<std::weak_ptr<IComponentListener>,
+ DeathNotifications,
+ std::owner_less<std::weak_ptr<IComponentListener>>> mDeathNotifications;
// Condition variable signaled when an entry is added to mDeathNotifications.
std::condition_variable mOnBufferDestroyed;
@@ -290,11 +291,11 @@
};
} // namespace utils
-} // namespace V1_0
} // namespace c2
} // namespace media
} // namespace hardware
} // namespace android
+} // namespace aidl
-#endif // CODEC2_HIDL_V1_0_UTILS_INPUT_BUFFER_MANAGER_H
+#endif // CODEC2_AIDL_UTILS_INPUT_BUFFER_MANAGER_H
diff --git a/media/codec2/hal/aidl/include/codec2/aidl/InputSurface.h b/media/codec2/hal/aidl/include/codec2/aidl/InputSurface.h
deleted file mode 100644
index 062dcd9..0000000
--- a/media/codec2/hal/aidl/include/codec2/aidl/InputSurface.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CODEC2_HIDL_V1_0_UTILS_INPUTSURFACE_H
-#define CODEC2_HIDL_V1_0_UTILS_INPUTSURFACE_H
-
-#include <codec2/hidl/1.0/ComponentStore.h>
-
-#include <android/hardware/graphics/bufferqueue/2.0/IGraphicBufferProducer.h>
-#include <android/hardware/media/c2/1.0/IInputSink.h>
-#include <android/hardware/media/c2/1.0/IInputSurface.h>
-#include <hidl/Status.h>
-#include <media/stagefright/bqhelper/GraphicBufferSource.h>
-
-#include <util/C2InterfaceHelper.h>
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace c2 {
-namespace V1_0 {
-namespace utils {
-
-using ::android::hardware::hidl_handle;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::sp;
-
-struct InputSurface : public IInputSurface {
-
- typedef ::android::hardware::graphics::bufferqueue::V2_0::
- IGraphicBufferProducer HGraphicBufferProducer;
-
- typedef ::android::
- GraphicBufferSource GraphicBufferSource;
-
- virtual Return<sp<HGraphicBufferProducer>> getGraphicBufferProducer() override;
-
- virtual Return<sp<IConfigurable>> getConfigurable() override;
-
- virtual Return<void> connect(
- const sp<IInputSink>& sink,
- connect_cb _hidl_cb) override;
-
- InputSurface(
- const std::shared_ptr<ParameterCache>& cache,
- const std::shared_ptr<C2ReflectorHelper>& reflector,
- const sp<HGraphicBufferProducer>& base,
- const sp<GraphicBufferSource>& source);
-
-protected:
-
- class Interface;
- class ConfigurableIntf;
-
- std::shared_ptr<ParameterCache> mParameterCache;
- sp<HGraphicBufferProducer> mProducer;
- sp<GraphicBufferSource> mSource;
- std::shared_ptr<Interface> mIntf;
- sp<CachedConfigurable> mConfigurable;
-
- virtual ~InputSurface() override = default;
-};
-
-} // namespace utils
-} // namespace V1_0
-} // namespace c2
-} // namespace media
-} // namespace hardware
-} // namespace android
-
-#endif // CODEC2_HIDL_V1_0_UTILS_INPUTSURFACE_H
diff --git a/media/codec2/hal/aidl/include/codec2/aidl/InputSurfaceConnection.h b/media/codec2/hal/aidl/include/codec2/aidl/InputSurfaceConnection.h
deleted file mode 100644
index 475ce8b..0000000
--- a/media/codec2/hal/aidl/include/codec2/aidl/InputSurfaceConnection.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CODEC2_HIDL_V1_0_UTILS_INPUTSURFACECONNECTION_H
-#define CODEC2_HIDL_V1_0_UTILS_INPUTSURFACECONNECTION_H
-
-#include <codec2/hidl/1.0/Component.h>
-#include <codec2/hidl/1.0/Configurable.h>
-
-#include <android/hardware/media/c2/1.0/IComponent.h>
-#include <android/hardware/media/c2/1.0/IConfigurable.h>
-#include <android/hardware/media/c2/1.0/IInputSurfaceConnection.h>
-
-#include <media/stagefright/bqhelper/GraphicBufferSource.h>
-
-#include <hidl/HidlSupport.h>
-#include <hidl/Status.h>
-
-#include <C2Component.h>
-
-#include <memory>
-#include <mutex>
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace c2 {
-namespace V1_0 {
-namespace utils {
-
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::sp;
-using ::android::GraphicBufferSource;
-
-// An InputSurfaceConnection connects an InputSurface to a sink, which may be an
-// IInputSink or a local C2Component. This can be specified by choosing the
-// corresponding constructor. The reason for distinguishing these two cases is
-// that when an InputSurfaceConnection lives in the same process as the
-// component that processes the buffers, data parceling is not needed.
-struct InputSurfaceConnection : public IInputSurfaceConnection {
-
- virtual Return<Status> disconnect() override;
-
- virtual Return<sp<IConfigurable>> getConfigurable() override;
-
-protected:
-
- InputSurfaceConnection(
- const sp<GraphicBufferSource>& source,
- const std::shared_ptr<C2Component>& comp,
- const std::shared_ptr<ParameterCache>& cache);
-
- InputSurfaceConnection(
- const sp<GraphicBufferSource>& source,
- const sp<IInputSink>& sink,
- const std::shared_ptr<ParameterCache>& cache);
-
- bool init();
-
- friend struct InputSurface;
-
- InputSurfaceConnection() = delete;
- InputSurfaceConnection(const InputSurfaceConnection&) = delete;
- void operator=(const InputSurfaceConnection&) = delete;
-
- struct Impl;
-
- std::mutex mImplMutex;
- sp<Impl> mImpl;
- sp<CachedConfigurable> mConfigurable;
-
- virtual ~InputSurfaceConnection() override;
-};
-
-} // namespace utils
-} // namespace V1_0
-} // namespace c2
-} // namespace media
-} // namespace hardware
-} // namespace android
-
-#endif // CODEC2_HIDL_V1_0_UTILS_INPUTSURFACECONNECTION_H