summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWonsik Kim <wonsik@google.com>2024-06-11 03:35:49 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-06-11 03:35:49 +0000
commit5a5ab97bc7681dfaff4b3850f5fad482e784cdfe (patch)
treefa1da0ea24977c4a49051a209723ce48a5e37f50
parentc63115238d4c3f832115b5033f890ed5716aa19b (diff)
parent700f152a809562872535d8bfff6b5ad0f014fb97 (diff)
downloadav-main.tar.gz
Merge "FilterWrapper: propagate ParamReflectors to the wrapper component" into mainHEADmastermain
-rw-r--r--media/codec2/hal/aidl/ComponentStore.cpp43
-rw-r--r--media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h5
-rw-r--r--media/codec2/hal/hidl/1.0/utils/ComponentStore.cpp29
-rw-r--r--media/codec2/hal/hidl/1.0/utils/include/codec2/hidl/1.0/ComponentStore.h5
-rw-r--r--media/codec2/hal/hidl/1.1/utils/ComponentStore.cpp29
-rw-r--r--media/codec2/hal/hidl/1.1/utils/include/codec2/hidl/1.1/ComponentStore.h5
-rw-r--r--media/codec2/hal/hidl/1.2/utils/ComponentStore.cpp29
-rw-r--r--media/codec2/hal/hidl/1.2/utils/include/codec2/hidl/1.2/ComponentStore.h5
-rw-r--r--media/codec2/hal/plugin/FilterWrapper.cpp7
-rw-r--r--media/codec2/hal/plugin/FilterWrapperStub.cpp4
-rw-r--r--media/codec2/hal/plugin/internal/FilterWrapper.h4
-rw-r--r--media/codec2/hal/plugin/samples/SampleFilterPlugin.cpp78
12 files changed, 193 insertions, 50 deletions
diff --git a/media/codec2/hal/aidl/ComponentStore.cpp b/media/codec2/hal/aidl/ComponentStore.cpp
index b95c09efd6..ea4d045780 100644
--- a/media/codec2/hal/aidl/ComponentStore.cpp
+++ b/media/codec2/hal/aidl/ComponentStore.cpp
@@ -36,7 +36,7 @@
#include <ostream>
#include <sstream>
-#ifndef __ANDROID_APEX__
+#ifndef __ANDROID_APEX__ // Filters are not supported for APEX modules
#include <codec2/hidl/plugin/FilterPlugin.h>
#include <dlfcn.h>
#include <C2Config.h>
@@ -51,7 +51,7 @@ namespace media {
namespace c2 {
namespace utils {
-#ifndef __ANDROID_APEX__
+#ifndef __ANDROID_APEX__ // Filters are not supported for APEX modules
using ::android::DefaultFilterPlugin;
using ::android::FilterWrapper;
#endif
@@ -144,7 +144,15 @@ ComponentStore::ComponentStore(const std::shared_ptr<C2ComponentStore>& store)
::android::SetPreferredCodec2ComponentStore(store);
// Retrieve struct descriptors
- mParamReflector = mStore->getParamReflector();
+ mParamReflectors.push_back(mStore->getParamReflector());
+#ifndef __ANDROID_APEX__ // Filters are not supported for APEX modules
+ std::shared_ptr<C2ParamReflector> paramReflector =
+ GetFilterWrapper()->getParamReflector();
+ if (paramReflector != nullptr) {
+ ALOGD("[%s] added param reflector from filter wrapper", mStore->getName().c_str());
+ mParamReflectors.push_back(paramReflector);
+ }
+#endif
// Retrieve supported parameters from store
using namespace std::placeholders;
@@ -173,8 +181,7 @@ c2_status_t ComponentStore::validateSupportedParams(
std::lock_guard<std::mutex> lock(mStructDescriptorsMutex);
auto it = mStructDescriptors.find(coreIndex);
if (it == mStructDescriptors.end()) {
- std::shared_ptr<C2StructDescriptor> structDesc =
- mParamReflector->describe(coreIndex);
+ std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
if (!structDesc) {
// All supported params must be described
res = C2_BAD_INDEX;
@@ -189,7 +196,7 @@ std::shared_ptr<ParameterCache> ComponentStore::getParameterCache() const {
return mParameterCache;
}
-#ifndef __ANDROID_APEX__
+#ifndef __ANDROID_APEX__ // Filters are not supported for APEX modules
// static
std::shared_ptr<FilterWrapper> ComponentStore::GetFilterWrapper() {
constexpr const char kPluginPath[] = "libc2filterplugin.so";
@@ -221,8 +228,13 @@ std::shared_ptr<MultiAccessUnitInterface> ComponentStore::tryCreateMultiAccessUn
}
}
if (!isComponentSupportsLargeAudioFrame) {
+ // TODO - b/342269852: MultiAccessUnitInterface also needs to take multiple
+ // param reflectors. Currently filters work on video domain only,
+ // and the MultiAccessUnitHelper is only enabled on audio domain;
+ // thus we pass the component's param reflector, which is mParamReflectors[0].
multiAccessUnitIntf = std::make_shared<MultiAccessUnitInterface>(
- c2interface, std::static_pointer_cast<C2ReflectorHelper>(mParamReflector));
+ c2interface,
+ std::static_pointer_cast<C2ReflectorHelper>(mParamReflectors[0]));
}
}
}
@@ -250,7 +262,7 @@ ScopedAStatus ComponentStore::createComponent(
mStore->createComponent(name, &c2component);
if (status == C2_OK) {
-#ifndef __ANDROID_APEX__
+#ifndef __ANDROID_APEX__ // Filters are not supported for APEX modules
c2component = GetFilterWrapper()->maybeWrapComponent(c2component);
#endif
onInterfaceLoaded(c2component->intf());
@@ -284,7 +296,7 @@ ScopedAStatus ComponentStore::createInterface(
std::shared_ptr<C2ComponentInterface> c2interface;
c2_status_t res = mStore->createInterface(name, &c2interface);
if (res == C2_OK) {
-#ifndef __ANDROID_APEX__
+#ifndef __ANDROID_APEX__ // Filters are not supported for APEX modules
c2interface = GetFilterWrapper()->maybeWrapInterface(c2interface);
#endif
onInterfaceLoaded(c2interface);
@@ -347,8 +359,7 @@ ScopedAStatus ComponentStore::getStructDescriptors(
if (item == mStructDescriptors.end()) {
// not in the cache, and not known to be unsupported, query local reflector
if (!mUnsupportedStructDescriptors.count(coreIndex)) {
- std::shared_ptr<C2StructDescriptor> structDesc =
- mParamReflector->describe(coreIndex);
+ std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
if (!structDesc) {
mUnsupportedStructDescriptors.emplace(coreIndex);
} else {
@@ -401,6 +412,16 @@ ScopedAStatus ComponentStore::getConfigurable(
return ScopedAStatus::ok();
}
+std::shared_ptr<C2StructDescriptor> ComponentStore::describe(const C2Param::CoreIndex &index) {
+ for (const std::shared_ptr<C2ParamReflector> &reflector : mParamReflectors) {
+ std::shared_ptr<C2StructDescriptor> desc = reflector->describe(index);
+ if (desc) {
+ return desc;
+ }
+ }
+ return nullptr;
+}
+
// Called from createComponent() after a successful creation of `component`.
void ComponentStore::reportComponentBirth(Component* component) {
ComponentStatus componentStatus;
diff --git a/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h b/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h
index 746e1bfc5c..b2158a61a5 100644
--- a/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h
+++ b/media/codec2/hal/aidl/include/codec2/aidl/ComponentStore.h
@@ -118,7 +118,7 @@ protected:
c2_status_t mInit;
std::shared_ptr<C2ComponentStore> mStore;
- std::shared_ptr<C2ParamReflector> mParamReflector;
+ std::vector<std::shared_ptr<C2ParamReflector>> mParamReflectors;
std::map<C2Param::CoreIndex, std::shared_ptr<C2StructDescriptor>> mStructDescriptors;
std::set<C2Param::CoreIndex> mUnsupportedStructDescriptors;
@@ -135,6 +135,9 @@ protected:
mutable std::mutex mComponentRosterMutex;
std::map<Component*, ComponentStatus> mComponentRoster;
+ // describe from mParamReflectors
+ std::shared_ptr<C2StructDescriptor> describe(const C2Param::CoreIndex &index);
+
// Called whenever Component is created.
void reportComponentBirth(Component* component);
// Called only from the destructor of Component.
diff --git a/media/codec2/hal/hidl/1.0/utils/ComponentStore.cpp b/media/codec2/hal/hidl/1.0/utils/ComponentStore.cpp
index 988ab6f9eb..1ba1889681 100644
--- a/media/codec2/hal/hidl/1.0/utils/ComponentStore.cpp
+++ b/media/codec2/hal/hidl/1.0/utils/ComponentStore.cpp
@@ -139,7 +139,15 @@ ComponentStore::ComponentStore(const std::shared_ptr<C2ComponentStore>& store)
SetPreferredCodec2ComponentStore(store);
// Retrieve struct descriptors
- mParamReflector = mStore->getParamReflector();
+ mParamReflectors.push_back(mStore->getParamReflector());
+#ifndef __ANDROID_APEX__
+ std::shared_ptr<C2ParamReflector> paramReflector =
+ GetFilterWrapper()->getParamReflector();
+ if (paramReflector != nullptr) {
+ ALOGD("[%s] added param reflector from filter wrapper", mStore->getName().c_str());
+ mParamReflectors.push_back(paramReflector);
+ }
+#endif
// Retrieve supported parameters from store
using namespace std::placeholders;
@@ -168,8 +176,7 @@ c2_status_t ComponentStore::validateSupportedParams(
std::lock_guard<std::mutex> lock(mStructDescriptorsMutex);
auto it = mStructDescriptors.find(coreIndex);
if (it == mStructDescriptors.end()) {
- std::shared_ptr<C2StructDescriptor> structDesc =
- mParamReflector->describe(coreIndex);
+ std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
if (!structDesc) {
// All supported params must be described
res = C2_BAD_INDEX;
@@ -217,7 +224,8 @@ std::shared_ptr<MultiAccessUnitInterface> ComponentStore::tryCreateMultiAccessUn
}
if (!isComponentSupportsLargeAudioFrame) {
multiAccessUnitIntf = std::make_shared<MultiAccessUnitInterface>(
- c2interface, std::static_pointer_cast<C2ReflectorHelper>(mParamReflector));
+ c2interface,
+ std::static_pointer_cast<C2ReflectorHelper>(mParamReflectors[0]));
}
}
}
@@ -339,8 +347,7 @@ Return<void> ComponentStore::getStructDescriptors(
if (item == mStructDescriptors.end()) {
// not in the cache, and not known to be unsupported, query local reflector
if (!mUnsupportedStructDescriptors.count(coreIndex)) {
- std::shared_ptr<C2StructDescriptor> structDesc =
- mParamReflector->describe(coreIndex);
+ std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
if (!structDesc) {
mUnsupportedStructDescriptors.emplace(coreIndex);
} else {
@@ -386,6 +393,16 @@ Return<sp<IConfigurable>> ComponentStore::getConfigurable() {
return mConfigurable;
}
+std::shared_ptr<C2StructDescriptor> ComponentStore::describe(const C2Param::CoreIndex &index) {
+ for (const std::shared_ptr<C2ParamReflector> &reflector : mParamReflectors) {
+ std::shared_ptr<C2StructDescriptor> desc = reflector->describe(index);
+ if (desc) {
+ return desc;
+ }
+ }
+ return nullptr;
+}
+
// Called from createComponent() after a successful creation of `component`.
void ComponentStore::reportComponentBirth(Component* component) {
ComponentStatus componentStatus;
diff --git a/media/codec2/hal/hidl/1.0/utils/include/codec2/hidl/1.0/ComponentStore.h b/media/codec2/hal/hidl/1.0/utils/include/codec2/hidl/1.0/ComponentStore.h
index b5d85da239..44b8ec1956 100644
--- a/media/codec2/hal/hidl/1.0/utils/include/codec2/hidl/1.0/ComponentStore.h
+++ b/media/codec2/hal/hidl/1.0/utils/include/codec2/hidl/1.0/ComponentStore.h
@@ -117,9 +117,12 @@ protected:
// Does bookkeeping for an interface that has been loaded.
void onInterfaceLoaded(const std::shared_ptr<C2ComponentInterface> &intf);
+ // describe from mParamReflectors
+ std::shared_ptr<C2StructDescriptor> describe(const C2Param::CoreIndex &index);
+
c2_status_t mInit;
std::shared_ptr<C2ComponentStore> mStore;
- std::shared_ptr<C2ParamReflector> mParamReflector;
+ std::vector<std::shared_ptr<C2ParamReflector>> mParamReflectors;
std::map<C2Param::CoreIndex, std::shared_ptr<C2StructDescriptor>> mStructDescriptors;
std::set<C2Param::CoreIndex> mUnsupportedStructDescriptors;
diff --git a/media/codec2/hal/hidl/1.1/utils/ComponentStore.cpp b/media/codec2/hal/hidl/1.1/utils/ComponentStore.cpp
index 46af809831..1b869581d6 100644
--- a/media/codec2/hal/hidl/1.1/utils/ComponentStore.cpp
+++ b/media/codec2/hal/hidl/1.1/utils/ComponentStore.cpp
@@ -139,7 +139,15 @@ ComponentStore::ComponentStore(const std::shared_ptr<C2ComponentStore>& store)
SetPreferredCodec2ComponentStore(store);
// Retrieve struct descriptors
- mParamReflector = mStore->getParamReflector();
+ mParamReflectors.push_back(mStore->getParamReflector());
+#ifndef __ANDROID_APEX__
+ std::shared_ptr<C2ParamReflector> paramReflector =
+ GetFilterWrapper()->getParamReflector();
+ if (paramReflector != nullptr) {
+ ALOGD("[%s] added param reflector from filter wrapper", mStore->getName().c_str());
+ mParamReflectors.push_back(paramReflector);
+ }
+#endif
// Retrieve supported parameters from store
using namespace std::placeholders;
@@ -168,8 +176,7 @@ c2_status_t ComponentStore::validateSupportedParams(
std::lock_guard<std::mutex> lock(mStructDescriptorsMutex);
auto it = mStructDescriptors.find(coreIndex);
if (it == mStructDescriptors.end()) {
- std::shared_ptr<C2StructDescriptor> structDesc =
- mParamReflector->describe(coreIndex);
+ std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
if (!structDesc) {
// All supported params must be described
res = C2_BAD_INDEX;
@@ -218,7 +225,8 @@ std::shared_ptr<MultiAccessUnitInterface> ComponentStore::tryCreateMultiAccessUn
if (!isComponentSupportsLargeAudioFrame) {
multiAccessUnitIntf = std::make_shared<MultiAccessUnitInterface>(
- c2interface, std::static_pointer_cast<C2ReflectorHelper>(mParamReflector));
+ c2interface,
+ std::static_pointer_cast<C2ReflectorHelper>(mParamReflectors[0]));
}
}
}
@@ -340,8 +348,7 @@ Return<void> ComponentStore::getStructDescriptors(
if (item == mStructDescriptors.end()) {
// not in the cache, and not known to be unsupported, query local reflector
if (!mUnsupportedStructDescriptors.count(coreIndex)) {
- std::shared_ptr<C2StructDescriptor> structDesc =
- mParamReflector->describe(coreIndex);
+ std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
if (!structDesc) {
mUnsupportedStructDescriptors.emplace(coreIndex);
} else {
@@ -423,6 +430,16 @@ Return<void> ComponentStore::createComponent_1_1(
return Void();
}
+std::shared_ptr<C2StructDescriptor> ComponentStore::describe(const C2Param::CoreIndex &index) {
+ for (const std::shared_ptr<C2ParamReflector> &reflector : mParamReflectors) {
+ std::shared_ptr<C2StructDescriptor> desc = reflector->describe(index);
+ if (desc) {
+ return desc;
+ }
+ }
+ return nullptr;
+}
+
// Called from createComponent() after a successful creation of `component`.
void ComponentStore::reportComponentBirth(Component* component) {
ComponentStatus componentStatus;
diff --git a/media/codec2/hal/hidl/1.1/utils/include/codec2/hidl/1.1/ComponentStore.h b/media/codec2/hal/hidl/1.1/utils/include/codec2/hidl/1.1/ComponentStore.h
index 85862a9f61..52d2945874 100644
--- a/media/codec2/hal/hidl/1.1/utils/include/codec2/hidl/1.1/ComponentStore.h
+++ b/media/codec2/hal/hidl/1.1/utils/include/codec2/hidl/1.1/ComponentStore.h
@@ -125,9 +125,12 @@ protected:
// Does bookkeeping for an interface that has been loaded.
void onInterfaceLoaded(const std::shared_ptr<C2ComponentInterface> &intf);
+ // describe from mParamReflectors
+ std::shared_ptr<C2StructDescriptor> describe(const C2Param::CoreIndex &index);
+
c2_status_t mInit;
std::shared_ptr<C2ComponentStore> mStore;
- std::shared_ptr<C2ParamReflector> mParamReflector;
+ std::vector<std::shared_ptr<C2ParamReflector>> mParamReflectors;
std::map<C2Param::CoreIndex, std::shared_ptr<C2StructDescriptor>> mStructDescriptors;
std::set<C2Param::CoreIndex> mUnsupportedStructDescriptors;
diff --git a/media/codec2/hal/hidl/1.2/utils/ComponentStore.cpp b/media/codec2/hal/hidl/1.2/utils/ComponentStore.cpp
index f89c83586f..2e0386f485 100644
--- a/media/codec2/hal/hidl/1.2/utils/ComponentStore.cpp
+++ b/media/codec2/hal/hidl/1.2/utils/ComponentStore.cpp
@@ -139,7 +139,15 @@ ComponentStore::ComponentStore(const std::shared_ptr<C2ComponentStore>& store)
SetPreferredCodec2ComponentStore(store);
// Retrieve struct descriptors
- mParamReflector = mStore->getParamReflector();
+ mParamReflectors.push_back(mStore->getParamReflector());
+#ifndef __ANDROID_APEX__
+ std::shared_ptr<C2ParamReflector> paramReflector =
+ GetFilterWrapper()->getParamReflector();
+ if (paramReflector != nullptr) {
+ ALOGD("[%s] added param reflector from filter wrapper", mStore->getName().c_str());
+ mParamReflectors.push_back(paramReflector);
+ }
+#endif
// Retrieve supported parameters from store
using namespace std::placeholders;
@@ -168,8 +176,7 @@ c2_status_t ComponentStore::validateSupportedParams(
std::lock_guard<std::mutex> lock(mStructDescriptorsMutex);
auto it = mStructDescriptors.find(coreIndex);
if (it == mStructDescriptors.end()) {
- std::shared_ptr<C2StructDescriptor> structDesc =
- mParamReflector->describe(coreIndex);
+ std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
if (!structDesc) {
// All supported params must be described
res = C2_BAD_INDEX;
@@ -217,7 +224,8 @@ std::shared_ptr<MultiAccessUnitInterface> ComponentStore::tryCreateMultiAccessUn
}
if (!isComponentSupportsLargeAudioFrame) {
multiAccessUnitIntf = std::make_shared<MultiAccessUnitInterface>(
- c2interface, std::static_pointer_cast<C2ReflectorHelper>(mParamReflector));
+ c2interface,
+ std::static_pointer_cast<C2ReflectorHelper>(mParamReflectors[0]));
}
}
}
@@ -338,8 +346,7 @@ Return<void> ComponentStore::getStructDescriptors(
if (item == mStructDescriptors.end()) {
// not in the cache, and not known to be unsupported, query local reflector
if (!mUnsupportedStructDescriptors.count(coreIndex)) {
- std::shared_ptr<C2StructDescriptor> structDesc =
- mParamReflector->describe(coreIndex);
+ std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
if (!structDesc) {
mUnsupportedStructDescriptors.emplace(coreIndex);
} else {
@@ -457,6 +464,16 @@ Return<void> ComponentStore::createComponent_1_2(
return Void();
}
+std::shared_ptr<C2StructDescriptor> ComponentStore::describe(const C2Param::CoreIndex &index) {
+ for (const std::shared_ptr<C2ParamReflector> &reflector : mParamReflectors) {
+ std::shared_ptr<C2StructDescriptor> desc = reflector->describe(index);
+ if (desc) {
+ return desc;
+ }
+ }
+ return nullptr;
+}
+
// Called from createComponent() after a successful creation of `component`.
void ComponentStore::reportComponentBirth(Component* component) {
ComponentStatus componentStatus;
diff --git a/media/codec2/hal/hidl/1.2/utils/include/codec2/hidl/1.2/ComponentStore.h b/media/codec2/hal/hidl/1.2/utils/include/codec2/hidl/1.2/ComponentStore.h
index c08fce4c67..1b209e27fd 100644
--- a/media/codec2/hal/hidl/1.2/utils/include/codec2/hidl/1.2/ComponentStore.h
+++ b/media/codec2/hal/hidl/1.2/utils/include/codec2/hidl/1.2/ComponentStore.h
@@ -132,9 +132,12 @@ protected:
// Does bookkeeping for an interface that has been loaded.
void onInterfaceLoaded(const std::shared_ptr<C2ComponentInterface> &intf);
+ // describe from mParamReflectors
+ std::shared_ptr<C2StructDescriptor> describe(const C2Param::CoreIndex &index);
+
c2_status_t mInit;
std::shared_ptr<C2ComponentStore> mStore;
- std::shared_ptr<C2ParamReflector> mParamReflector;
+ std::vector<std::shared_ptr<C2ParamReflector>> mParamReflectors;
std::map<C2Param::CoreIndex, std::shared_ptr<C2StructDescriptor>> mStructDescriptors;
std::set<C2Param::CoreIndex> mUnsupportedStructDescriptors;
diff --git a/media/codec2/hal/plugin/FilterWrapper.cpp b/media/codec2/hal/plugin/FilterWrapper.cpp
index b92615034a..ab6e3eb43f 100644
--- a/media/codec2/hal/plugin/FilterWrapper.cpp
+++ b/media/codec2/hal/plugin/FilterWrapper.cpp
@@ -1012,4 +1012,11 @@ c2_status_t FilterWrapper::queryParamsForPreviousComponent(
return mPlugin->queryParamsForPreviousComponent(intf, params);
}
+std::shared_ptr<C2ParamReflector> FilterWrapper::getParamReflector() {
+ if (mInit != OK) {
+ return nullptr;
+ }
+ return mStore->getParamReflector();
+}
+
} // namespace android
diff --git a/media/codec2/hal/plugin/FilterWrapperStub.cpp b/media/codec2/hal/plugin/FilterWrapperStub.cpp
index 3fd54095ae..a21f6d0735 100644
--- a/media/codec2/hal/plugin/FilterWrapperStub.cpp
+++ b/media/codec2/hal/plugin/FilterWrapperStub.cpp
@@ -57,4 +57,8 @@ c2_status_t FilterWrapper::createBlockPool(
return CreateCodec2BlockPool(allocatorParam, component, pool);
}
+std::shared_ptr<C2ParamReflector> FilterWrapper::getParamReflector() {
+ return nullptr;
+}
+
} // namespace android
diff --git a/media/codec2/hal/plugin/internal/FilterWrapper.h b/media/codec2/hal/plugin/internal/FilterWrapper.h
index dcffb5cd30..c27901e4ff 100644
--- a/media/codec2/hal/plugin/internal/FilterWrapper.h
+++ b/media/codec2/hal/plugin/internal/FilterWrapper.h
@@ -104,6 +104,10 @@ public:
const std::shared_ptr<C2ComponentInterface> &intf,
std::vector<std::unique_ptr<C2Param>> *params);
+ /**
+ * Return the param reflector of the filter plugin store.
+ */
+ std::shared_ptr<C2ParamReflector> getParamReflector();
private:
status_t mInit;
std::unique_ptr<Plugin> mPlugin;
diff --git a/media/codec2/hal/plugin/samples/SampleFilterPlugin.cpp b/media/codec2/hal/plugin/samples/SampleFilterPlugin.cpp
index b5383ad584..47412b7868 100644
--- a/media/codec2/hal/plugin/samples/SampleFilterPlugin.cpp
+++ b/media/codec2/hal/plugin/samples/SampleFilterPlugin.cpp
@@ -37,6 +37,19 @@ typedef C2StreamParam<C2Info, C2ColorAspectsStruct,
kParamIndexColorAspects | C2Param::CoreIndex::IS_REQUEST_FLAG>
C2StreamColorAspectsRequestInfo;
+// In practice the vendor parameters will be defined in a separate header file,
+// but for the purpose of this sample, we just define it here.
+
+// Vendor-specific type index for filters start from this value. 0x7000 is added to
+// avoid conflict with existing vendor type indices.
+constexpr uint32_t kTypeIndexFilterStart = C2Param::TYPE_INDEX_VENDOR_START + 0x7000;
+// Answer to the Ultimate Question of Life, the Universe, and Everything
+// (Reference to The Hitchhiker's Guide to the Galaxy by Douglas Adams)
+constexpr uint32_t kParamIndexVendorUltimateAnswer = kTypeIndexFilterStart + 0;
+typedef C2StreamParam<C2Info, C2Int32Value, kParamIndexVendorUltimateAnswer>
+ C2StreamVendorUltimateAnswerInfo;
+constexpr char C2_PARAMKEY_VENDOR_ULTIMATE_ANSWER[] = "ultimate-answer";
+
namespace android {
using namespace std::literals::chrono_literals;
@@ -49,10 +62,9 @@ public:
static const std::string NAME;
static const FilterPlugin_V1::Descriptor DESCRIPTOR;
- explicit Interface(c2_node_id_t id)
+ Interface(c2_node_id_t id, const std::shared_ptr<C2ReflectorHelper> &reflector)
: mId(id),
- mReflector(std::make_shared<C2ReflectorHelper>()),
- mHelper(mReflector) {
+ mHelper(reflector) {
}
~Interface() override = default;
C2String getName() const override { return NAME; }
@@ -126,7 +138,6 @@ public:
}
private:
const c2_node_id_t mId;
- std::shared_ptr<C2ReflectorHelper> mReflector;
struct Helper : public C2InterfaceHelper {
explicit Helper(std::shared_ptr<C2ReflectorHelper> reflector)
: C2InterfaceHelper(reflector) {
@@ -266,6 +277,15 @@ public:
.build());
addParameter(
+ DefineParam(mVendorUltimateAnswerInfo, C2_PARAMKEY_VENDOR_ULTIMATE_ANSWER)
+ .withDefault(new C2StreamVendorUltimateAnswerInfo::input(0u))
+ .withFields({
+ C2F(mVendorUltimateAnswerInfo, value).any(),
+ })
+ .withSetter(VendorUltimateAnswerSetter)
+ .build());
+
+ addParameter(
DefineParam(mOutputColorAspectInfo, C2_PARAMKEY_COLOR_ASPECTS)
.withDefault(new C2StreamColorAspectsInfo::output(0u))
.withFields({
@@ -336,6 +356,15 @@ public:
return C2R::Ok();
}
+ static C2R VendorUltimateAnswerSetter(
+ bool mayBlock,
+ C2P<C2StreamVendorUltimateAnswerInfo::input> &me) {
+ (void)mayBlock;
+ ALOGI("Answer to the Ultimate Question of Life, the Universe, and Everything "
+ "set to %d", me.v.value);
+ return C2R::Ok();
+ }
+
std::shared_ptr<C2ApiFeaturesSetting> mApiFeatures;
std::shared_ptr<C2ComponentNameSetting> mName;
@@ -362,11 +391,13 @@ public:
std::shared_ptr<C2StreamColorAspectsInfo::input> mInputColorAspectInfo;
std::shared_ptr<C2StreamColorAspectsInfo::output> mOutputColorAspectInfo;
std::shared_ptr<C2StreamColorAspectsRequestInfo::output> mColorAspectRequestInfo;
+
+ std::shared_ptr<C2StreamVendorUltimateAnswerInfo::input> mVendorUltimateAnswerInfo;
} mHelper;
};
- explicit SampleToneMappingFilter(c2_node_id_t id)
- : mIntf(std::make_shared<Interface>(id)) {
+ SampleToneMappingFilter(c2_node_id_t id, const std::shared_ptr<C2ReflectorHelper> &reflector)
+ : mIntf(std::make_shared<Interface>(id, reflector)) {
}
~SampleToneMappingFilter() override {
if (mProcessingThread.joinable()) {
@@ -802,7 +833,10 @@ const std::string SampleToneMappingFilter::Interface::NAME = "c2.sample.tone-map
// static
const FilterPlugin_V1::Descriptor SampleToneMappingFilter::Interface::DESCRIPTOR = {
// controlParams
- { C2StreamColorAspectsRequestInfo::output::PARAM_TYPE },
+ {
+ C2StreamColorAspectsRequestInfo::output::PARAM_TYPE,
+ C2StreamVendorUltimateAnswerInfo::input::PARAM_TYPE,
+ },
// affectedParams
{
C2StreamHdrStaticInfo::output::PARAM_TYPE,
@@ -815,7 +849,7 @@ public:
SampleC2ComponentStore()
: mReflector(std::make_shared<C2ReflectorHelper>()),
mIntf(mReflector),
- mFactories(CreateFactories()) {
+ mFactories(CreateFactories(mReflector)) {
}
~SampleC2ComponentStore() = default;
@@ -892,36 +926,46 @@ private:
template <class T>
struct ComponentFactoryImpl : public ComponentFactory {
public:
- ComponentFactoryImpl(const std::shared_ptr<const C2Component::Traits> &traits)
- : ComponentFactory(traits) {
+ ComponentFactoryImpl(
+ const std::shared_ptr<const C2Component::Traits> &traits,
+ const std::shared_ptr<C2ReflectorHelper> &reflector)
+ : ComponentFactory(traits),
+ mReflector(reflector) {
}
~ComponentFactoryImpl() override = default;
c2_status_t createComponent(
c2_node_id_t id,
std::shared_ptr<C2Component>* const component) const override {
- *component = std::make_shared<T>(id);
+ *component = std::make_shared<T>(id, mReflector);
return C2_OK;
}
c2_status_t createInterface(
c2_node_id_t id,
std::shared_ptr<C2ComponentInterface>* const interface) const override {
- *interface = std::make_shared<typename T::Interface>(id);
+ *interface = std::make_shared<typename T::Interface>(id, mReflector);
return C2_OK;
}
+ private:
+ std::shared_ptr<C2ReflectorHelper> mReflector;
};
template <class T>
- static void AddFactory(std::map<C2String, std::unique_ptr<ComponentFactory>> *factories) {
- std::shared_ptr<C2ComponentInterface> intf{new typename T::Interface(0)};
+ static void AddFactory(
+ std::map<C2String, std::unique_ptr<ComponentFactory>> *factories,
+ const std::shared_ptr<C2ReflectorHelper> &reflector) {
+ std::shared_ptr<C2ComponentInterface> intf{new typename T::Interface(0, reflector)};
std::shared_ptr<C2Component::Traits> traits(new (std::nothrow) C2Component::Traits);
CHECK(C2InterfaceUtils::FillTraitsFromInterface(traits.get(), intf))
<< "Failed to fill traits from interface";
- factories->emplace(traits->name, new ComponentFactoryImpl<T>(traits));
+ factories->emplace(
+ traits->name,
+ new ComponentFactoryImpl<T>(traits, reflector));
}
- static std::map<C2String, std::unique_ptr<ComponentFactory>> CreateFactories() {
+ static std::map<C2String, std::unique_ptr<ComponentFactory>> CreateFactories(
+ const std::shared_ptr<C2ReflectorHelper> &reflector) {
std::map<C2String, std::unique_ptr<ComponentFactory>> factories;
- AddFactory<SampleToneMappingFilter>(&factories);
+ AddFactory<SampleToneMappingFilter>(&factories, reflector);
return factories;
}