aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2021-03-30 01:06:15 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2021-03-30 01:06:15 +0000
commitc8808b85d2804c4b092757f047388a2689763dd1 (patch)
treecfa37de9ed9c440eb4617744f8e0fdcae150984a
parent253a83b03ea680986399e761e767c12b56166de4 (diff)
parent50e77c4f67e2c15ec5fa4f8d9604f5d7abf65725 (diff)
downloadv4l2_codec2-c8808b85d2804c4b092757f047388a2689763dd1.tar.gz
Snap for 7243396 from 50e77c4f67e2c15ec5fa4f8d9604f5d7abf65725 to sc-release
Change-Id: I8c78f3f707c7059f23be54627da3a23fbdd7695b
-rw-r--r--README.md9
-rw-r--r--components/Android.bp4
-rw-r--r--components/V4L2ComponentFactory.cpp103
-rw-r--r--components/V4L2ComponentStore.cpp (renamed from store/V4L2ComponentStore.cpp)45
-rw-r--r--components/include/v4l2_codec2/components/V4L2ComponentFactory.h39
-rw-r--r--components/include/v4l2_codec2/components/V4L2ComponentStore.h (renamed from store/include/v4l2_codec2/store/V4L2ComponentStore.h)24
-rw-r--r--service/Android.bp2
-rw-r--r--service/service.cpp2
-rw-r--r--store/Android.bp39
9 files changed, 100 insertions, 167 deletions
diff --git a/README.md b/README.md
index 44c88bb..e7ce74b 100644
--- a/README.md
+++ b/README.md
@@ -6,14 +6,11 @@
Core V4L2 API and codec utilities, ported from Chromium project.
* common/
-Common helper classes for both components/ and store/.
+Common helper classes for components.
* components/
-The C2Component implementations based on V4L2 API.
-
-* store/
-The implementation of C2ComponentStore. It is used for creating all the
-C2Components implemented at components/ folder.
+The C2Component implementations based on V4L2 API, and the implementation of
+C2ComponentStore for creating all the C2Components.
* service/
The Codec2's V4L2 IComponentStore service. The service initiates the component
diff --git a/components/Android.bp b/components/Android.bp
index c683cb0..9b39a22 100644
--- a/components/Android.bp
+++ b/components/Android.bp
@@ -18,8 +18,9 @@ cc_library {
srcs: [
"VideoFrame.cpp",
"VideoFramePool.cpp",
- "V4L2Decoder.cpp",
"V4L2ComponentFactory.cpp",
+ "V4L2ComponentStore.cpp",
+ "V4L2Decoder.cpp",
"V4L2DecodeComponent.cpp",
"V4L2DecodeInterface.cpp",
"V4L2EncodeComponent.cpp",
@@ -43,7 +44,6 @@ cc_library {
"libsfplugin_ccodec_utils",
"libstagefright_bufferqueue_helper",
"libstagefright_foundation",
- "libv4l2_codec2_store",
"libui",
],
static_libs: [
diff --git a/components/V4L2ComponentFactory.cpp b/components/V4L2ComponentFactory.cpp
index 049edce..a3f8837 100644
--- a/components/V4L2ComponentFactory.cpp
+++ b/components/V4L2ComponentFactory.cpp
@@ -5,71 +5,57 @@
//#define LOG_NDEBUG 0
#define LOG_TAG "V4L2ComponentFactory"
-#include <string>
+#include <v4l2_codec2/components/V4L2ComponentFactory.h>
-#include <C2ComponentFactory.h>
-#include <SimpleC2Interface.h>
#include <codec2/hidl/1.0/InputBufferManager.h>
#include <log/log.h>
-#include <util/C2InterfaceHelper.h>
#include <v4l2_codec2/common/V4L2ComponentCommon.h>
#include <v4l2_codec2/components/V4L2DecodeComponent.h>
#include <v4l2_codec2/components/V4L2DecodeInterface.h>
#include <v4l2_codec2/components/V4L2EncodeComponent.h>
#include <v4l2_codec2/components/V4L2EncodeInterface.h>
-#include <v4l2_codec2/store/V4L2ComponentStore.h>
namespace android {
-class V4L2ComponentFactory : public C2ComponentFactory {
-public:
- V4L2ComponentFactory(const char* componentName, bool isEncoder);
- ~V4L2ComponentFactory() override;
-
- // Implementation of C2ComponentFactory.
- c2_status_t createComponent(c2_node_id_t id, std::shared_ptr<C2Component>* const component,
- ComponentDeleter deleter) override;
- c2_status_t createInterface(c2_node_id_t id,
- std::shared_ptr<C2ComponentInterface>* const interface,
- InterfaceDeleter deleter) override;
-
-private:
- const std::string mComponentName;
- const bool mIsEncoder;
- std::shared_ptr<C2ReflectorHelper> mReflector;
-};
-
-V4L2ComponentFactory::V4L2ComponentFactory(const char* componentName, bool isEncoder)
- : mComponentName(componentName), mIsEncoder(isEncoder) {
- auto componentStore = V4L2ComponentStore::Create();
- if (componentStore == nullptr) {
- ALOGE("Could not create V4L2ComponentStore.");
- return;
+// static
+std::unique_ptr<V4L2ComponentFactory> V4L2ComponentFactory::create(
+ const std::string& componentName, std::shared_ptr<C2ReflectorHelper> reflector) {
+ ALOGV("%s(%s)", __func__, componentName.c_str());
+
+ if (!android::V4L2ComponentName::isValid(componentName.c_str())) {
+ ALOGE("Invalid component name: %s", componentName.c_str());
+ return nullptr;
}
- mReflector = std::static_pointer_cast<C2ReflectorHelper>(componentStore->getParamReflector());
-
- {
- using namespace ::android::hardware::media::c2::V1_0;
- // To minimize IPC, we generally want the codec2 framework to release and
- // recycle input buffers when the corresponding work item is done. However,
- // sometimes it is necessary to provide more input to unblock a decoder.
- //
- // Optimally we would configure this on a per-context basis. However, the
- // InputBufferManager is a process-wide singleton, so we need to configure it
- // pessimistically. Basing the interval on frame timing can be suboptimal if
- // the decoded output isn't being displayed, but that's not a primary use case
- // and few videos will actually rely on this behavior.
- constexpr nsecs_t kMinFrameIntervalNs = 1000000000ull / 60;
- uint32_t delayCount = 0;
- for (auto c : kAllCodecs) {
- delayCount = std::max(delayCount, V4L2DecodeInterface::getOutputDelay(c));
- }
- utils::InputBufferManager::setNotificationInterval(delayCount * kMinFrameIntervalNs / 2);
+ if (reflector == nullptr) {
+ ALOGE("reflector is null");
+ return nullptr;
}
+
+ bool isEncoder = android::V4L2ComponentName::isEncoder(componentName.c_str());
+ return std::make_unique<V4L2ComponentFactory>(componentName, isEncoder, std::move(reflector));
}
-V4L2ComponentFactory::~V4L2ComponentFactory() = default;
+V4L2ComponentFactory::V4L2ComponentFactory(const std::string& componentName, bool isEncoder,
+ std::shared_ptr<C2ReflectorHelper> reflector)
+ : mComponentName(componentName), mIsEncoder(isEncoder), mReflector(std::move(reflector)) {
+ using namespace ::android::hardware::media::c2::V1_0;
+ // To minimize IPC, we generally want the codec2 framework to release and
+ // recycle input buffers when the corresponding work item is done. However,
+ // sometimes it is necessary to provide more input to unblock a decoder.
+ //
+ // Optimally we would configure this on a per-context basis. However, the
+ // InputBufferManager is a process-wide singleton, so we need to configure it
+ // pessimistically. Basing the interval on frame timing can be suboptimal if
+ // the decoded output isn't being displayed, but that's not a primary use case
+ // and few videos will actually rely on this behavior.
+ constexpr nsecs_t kMinFrameIntervalNs = 1000000000ull / 60;
+ uint32_t delayCount = 0;
+ for (auto c : kAllCodecs) {
+ delayCount = std::max(delayCount, V4L2DecodeInterface::getOutputDelay(c));
+ }
+ utils::InputBufferManager::setNotificationInterval(delayCount * kMinFrameIntervalNs / 2);
+}
c2_status_t V4L2ComponentFactory::createComponent(c2_node_id_t id,
std::shared_ptr<C2Component>* const component,
@@ -118,22 +104,3 @@ c2_status_t V4L2ComponentFactory::createInterface(
}
} // namespace android
-
-__attribute__((cfi_canonical_jump_table)) extern "C" ::C2ComponentFactory* CreateCodec2Factory(
- const char* componentName) {
- ALOGV("%s(%s)", __func__, componentName);
-
- if (!android::V4L2ComponentName::isValid(componentName)) {
- ALOGE("Invalid component name: %s", componentName);
- return nullptr;
- }
-
- bool isEncoder = android::V4L2ComponentName::isEncoder(componentName);
- return new android::V4L2ComponentFactory(componentName, isEncoder);
-}
-
-__attribute__((cfi_canonical_jump_table)) extern "C" void DestroyCodec2Factory(
- ::C2ComponentFactory* factory) {
- ALOGV("%s()", __func__);
- delete factory;
-}
diff --git a/store/V4L2ComponentStore.cpp b/components/V4L2ComponentStore.cpp
index 7132341..4004ce5 100644
--- a/store/V4L2ComponentStore.cpp
+++ b/components/V4L2ComponentStore.cpp
@@ -5,9 +5,8 @@
//#define LOG_NDEBUG 0
#define LOG_TAG "V4L2ComponentStore"
-#include <v4l2_codec2/store/V4L2ComponentStore.h>
+#include <v4l2_codec2/components/V4L2ComponentStore.h>
-#include <dlfcn.h>
#include <stdint.h>
#include <memory>
@@ -19,13 +18,10 @@
#include <media/stagefright/foundation/MediaDefs.h>
#include <v4l2_codec2/common/V4L2ComponentCommon.h>
+#include <v4l2_codec2/components/V4L2ComponentFactory.h>
namespace android {
namespace {
-const char* kLibPath = "libv4l2_codec2_components.so";
-const char* kCreateFactoryFuncName = "CreateCodec2Factory";
-const char* kDestroyFactoryFuncName = "DestroyCodec2Factory";
-
const uint32_t kComponentRank = 0x80;
std::string getMediaTypeFromComponentName(const std::string& name) {
@@ -57,32 +53,12 @@ std::shared_ptr<C2ComponentStore> V4L2ComponentStore::Create() {
std::shared_ptr<C2ComponentStore> store = platformStore.lock();
if (store != nullptr) return store;
- void* libHandle = dlopen(kLibPath, RTLD_NOW | RTLD_NODELETE);
- if (!libHandle) {
- ALOGE("Failed to load library: %s", kLibPath);
- return nullptr;
- }
-
- auto createFactoryFunc = (CreateV4L2FactoryFunc)dlsym(libHandle, kCreateFactoryFuncName);
- auto destroyFactoryFunc = (DestroyV4L2FactoryFunc)dlsym(libHandle, kDestroyFactoryFuncName);
- if (!createFactoryFunc || !destroyFactoryFunc) {
- ALOGE("Failed to load functions: %s, %s", kCreateFactoryFuncName, kDestroyFactoryFuncName);
- dlclose(libHandle);
- return nullptr;
- }
-
- store = std::shared_ptr<C2ComponentStore>(
- new V4L2ComponentStore(libHandle, createFactoryFunc, destroyFactoryFunc));
+ store = std::shared_ptr<C2ComponentStore>(new V4L2ComponentStore());
platformStore = store;
return store;
}
-V4L2ComponentStore::V4L2ComponentStore(void* libHandle, CreateV4L2FactoryFunc createFactoryFunc,
- DestroyV4L2FactoryFunc destroyFactoryFunc)
- : mLibHandle(libHandle),
- mCreateFactoryFunc(createFactoryFunc),
- mDestroyFactoryFunc(destroyFactoryFunc),
- mReflector(std::make_shared<C2ReflectorHelper>()) {
+V4L2ComponentStore::V4L2ComponentStore() : mReflector(std::make_shared<C2ReflectorHelper>()) {
ALOGV("%s()", __func__);
}
@@ -90,10 +66,7 @@ V4L2ComponentStore::~V4L2ComponentStore() {
ALOGV("%s()", __func__);
std::lock_guard<std::mutex> lock(mCachedFactoriesLock);
- for (const auto& kv : mCachedFactories) mDestroyFactoryFunc(kv.second);
mCachedFactories.clear();
-
- dlclose(mLibHandle);
}
C2String V4L2ComponentStore::getName() const {
@@ -189,16 +162,18 @@ c2_status_t V4L2ComponentStore::querySupportedValues_sm(
std::lock_guard<std::mutex> lock(mCachedFactoriesLock);
const auto it = mCachedFactories.find(name);
- if (it != mCachedFactories.end()) return it->second;
+ if (it != mCachedFactories.end()) return it->second.get();
- ::C2ComponentFactory* factory = mCreateFactoryFunc(name.c_str());
+ std::unique_ptr<::C2ComponentFactory> factory = V4L2ComponentFactory::create(
+ name, std::static_pointer_cast<C2ReflectorHelper>(getParamReflector()));
if (factory == nullptr) {
ALOGE("Failed to create factory for %s", name.c_str());
return nullptr;
}
- mCachedFactories.emplace(name, factory);
- return factory;
+ auto ret = factory.get();
+ mCachedFactories.emplace(name, std::move(factory));
+ return ret;
}
std::shared_ptr<const C2Component::Traits> V4L2ComponentStore::GetTraits(const C2String& name) {
diff --git a/components/include/v4l2_codec2/components/V4L2ComponentFactory.h b/components/include/v4l2_codec2/components/V4L2ComponentFactory.h
new file mode 100644
index 0000000..fc6abea
--- /dev/null
+++ b/components/include/v4l2_codec2/components/V4L2ComponentFactory.h
@@ -0,0 +1,39 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_FACTORY_H
+#define ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_FACTORY_H
+
+#include <memory>
+#include <string>
+
+#include <C2ComponentFactory.h>
+#include <util/C2InterfaceHelper.h>
+
+namespace android {
+
+class V4L2ComponentFactory : public C2ComponentFactory {
+public:
+ static std::unique_ptr<V4L2ComponentFactory> create(
+ const std::string& componentName, std::shared_ptr<C2ReflectorHelper> reflector);
+ V4L2ComponentFactory(const std::string& componentName, bool isEncoder,
+ std::shared_ptr<C2ReflectorHelper> reflector);
+ ~V4L2ComponentFactory() override = default;
+
+ // Implementation of C2ComponentFactory.
+ c2_status_t createComponent(c2_node_id_t id, std::shared_ptr<C2Component>* const component,
+ ComponentDeleter deleter) override;
+ c2_status_t createInterface(c2_node_id_t id,
+ std::shared_ptr<C2ComponentInterface>* const interface,
+ InterfaceDeleter deleter) override;
+
+private:
+ const std::string mComponentName;
+ const bool mIsEncoder;
+ std::shared_ptr<C2ReflectorHelper> mReflector;
+};
+
+} // namespace android
+
+#endif // ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_FACTORY_H
diff --git a/store/include/v4l2_codec2/store/V4L2ComponentStore.h b/components/include/v4l2_codec2/components/V4L2ComponentStore.h
index 8013f55..bfec407 100644
--- a/store/include/v4l2_codec2/store/V4L2ComponentStore.h
+++ b/components/include/v4l2_codec2/components/V4L2ComponentStore.h
@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef ANDROID_V4L2_CODEC2_STORE_V4L2_COMPONENT_STORE_H
-#define ANDROID_V4L2_CODEC2_STORE_V4L2_COMPONENT_STORE_H
+#ifndef ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_STORE_H
+#define ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_STORE_H
#include <map>
#include <mutex>
-#include <android-base/thread_annotations.h>
#include <C2Component.h>
#include <C2ComponentFactory.h>
+#include <android-base/thread_annotations.h>
#include <util/C2InterfaceHelper.h>
namespace android {
@@ -41,27 +41,21 @@ public:
std::vector<C2FieldSupportedValuesQuery>& fields) const override;
private:
- using CreateV4L2FactoryFunc = ::C2ComponentFactory* (*)(const char* /* componentName */);
- using DestroyV4L2FactoryFunc = void (*)(::C2ComponentFactory*);
-
- V4L2ComponentStore(void* libHandle, CreateV4L2FactoryFunc createFactoryFunc,
- DestroyV4L2FactoryFunc destroyFactoryFunc);
+ V4L2ComponentStore();
::C2ComponentFactory* GetFactory(const C2String& name);
std::shared_ptr<const C2Component::Traits> GetTraits(const C2String& name);
- void* mLibHandle;
- CreateV4L2FactoryFunc mCreateFactoryFunc;
- DestroyV4L2FactoryFunc mDestroyFactoryFunc;
-
std::shared_ptr<C2ReflectorHelper> mReflector;
std::mutex mCachedFactoriesLock;
- std::map<C2String, ::C2ComponentFactory*> mCachedFactories GUARDED_BY(mCachedFactoriesLock);
+ std::map<C2String, std::unique_ptr<::C2ComponentFactory>> mCachedFactories
+ GUARDED_BY(mCachedFactoriesLock);
std::mutex mCachedTraitsLock;
- std::map<C2String, std::shared_ptr<const C2Component::Traits>> mCachedTraits GUARDED_BY(mCachedTraitsLock);
+ std::map<C2String, std::shared_ptr<const C2Component::Traits>> mCachedTraits
+ GUARDED_BY(mCachedTraitsLock);
};
} // namespace android
-#endif // ANDROID_V4L2_CODEC2_STORE_V4L2_COMPONENT_STORE_H
+#endif // ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_STORE_H
diff --git a/service/Android.bp b/service/Android.bp
index 939efb7..29ee3ff 100644
--- a/service/Android.bp
+++ b/service/Android.bp
@@ -22,7 +22,7 @@ cc_binary {
],
shared_libs: [
- "libv4l2_codec2_store",
+ "libv4l2_codec2_components",
"libavservices_minijail_vendor",
"libchrome",
"libcutils",
diff --git a/service/service.cpp b/service/service.cpp
index 357d98a..616e641 100644
--- a/service/service.cpp
+++ b/service/service.cpp
@@ -12,7 +12,7 @@
#include <log/log.h>
#include <minijail.h>
-#include <v4l2_codec2/store/V4L2ComponentStore.h>
+#include <v4l2_codec2/components/V4L2ComponentStore.h>
// Default policy for codec2.0 service.
static constexpr char kBaseSeccompPolicyPath[] =
diff --git a/store/Android.bp b/store/Android.bp
deleted file mode 100644
index fabe77f..0000000
--- a/store/Android.bp
+++ /dev/null
@@ -1,39 +0,0 @@
-package {
- // See: http://go/android-license-faq
- // A large-scale-change added 'default_applicable_licenses' to import
- // all of the 'license_kinds' from "external_v4l2_codec2_license"
- // to get the below license kinds:
- // SPDX-license-identifier-BSD
- default_applicable_licenses: ["external_v4l2_codec2_license"],
-}
-
-cc_library_shared {
- name: "libv4l2_codec2_store",
- vendor: true,
-
- defaults: [
- "libcodec2-impl-defaults",
- ],
-
- srcs: [
- "V4L2ComponentStore.cpp",
- ],
- export_include_dirs: [
- "include",
- ],
-
- shared_libs: [
- "libcutils",
- "liblog",
- "libstagefright_foundation",
- ],
- static_libs: [
- "libv4l2_codec2_common",
- ],
-
- cflags: [
- "-Werror",
- "-Wall",
- "-Wthread-safety", // Check thread annotation at build time.
- ],
-}