Codec2: Further finalize C2Component APIs.
Changes to go along with framework API change:
Codec2: Finalize C2Component APIs and add C2ComponentFactory
Bug: 64121714
Test: unittest
Change-Id: Ie540e949a98233c73fa9ae29b825947b38532225
diff --git a/C2VDAComponent.cpp b/C2VDAComponent.cpp
index 576f5f6..7322c51 100644
--- a/C2VDAComponent.cpp
+++ b/C2VDAComponent.cpp
@@ -108,7 +108,7 @@
return std::unique_ptr<C2StructDescriptor>(new C2StructDescriptor{ \
paramType::coreIndex, paramType::fieldList, })
-class C2VDAComponentIntf::ParamReflector : public C2ParamReflector {
+class C2VDAComponentStore::ParamReflector : public C2ParamReflector {
public:
virtual std::unique_ptr<C2StructDescriptor> describe(C2Param::BaseIndex coreIndex) override {
switch (coreIndex.coreIndex()) {
@@ -127,10 +127,9 @@
// static
const uint32_t C2VDAComponentIntf::kInputFormatFourcc = V4L2_PIX_FMT_H264_SLICE;
-C2VDAComponentIntf::C2VDAComponentIntf(C2String name, node_id id)
+C2VDAComponentIntf::C2VDAComponentIntf(C2String name, c2_node_id_t id)
: kName(name),
kId(id),
- mParamReflector(std::make_shared<ParamReflector>()),
mDomainInfo(C2DomainVideo),
mOutputColorFormat(0u, kColorFormatYUV420Flexible),
// Support H264 only for now.
@@ -214,15 +213,15 @@
return kName;
}
-node_id C2VDAComponentIntf::getId() const {
+c2_node_id_t C2VDAComponentIntf::getId() const {
return kId;
}
-C2Status C2VDAComponentIntf::query_nb(
+c2_status_t C2VDAComponentIntf::query_nb(
const std::vector<C2Param* const>& stackParams,
const std::vector<C2Param::Index>& heapParamIndices,
std::vector<std::unique_ptr<C2Param>>* const heapParams) const {
- C2Status err = C2_OK;
+ c2_status_t err = C2_OK;
for (C2Param* const param : stackParams) {
if (!param || !*param) {
continue;
@@ -253,10 +252,10 @@
return err;
}
-C2Status C2VDAComponentIntf::config_nb(
+c2_status_t C2VDAComponentIntf::config_nb(
const std::vector<C2Param* const> ¶ms,
std::vector<std::unique_ptr<C2SettingResult>>* const failures) {
- C2Status err = C2_OK;
+ c2_status_t err = C2_OK;
for (C2Param* const param : params) {
uint32_t index = restoreIndex(param);
C2Param* myParam = getParamByIndex(index);
@@ -311,7 +310,7 @@
return err;
}
-C2Status C2VDAComponentIntf::commit_sm(
+c2_status_t C2VDAComponentIntf::commit_sm(
const std::vector<C2Param* const>& params,
std::vector<std::unique_ptr<C2SettingResult>>* const failures) {
UNUSED(params);
@@ -319,29 +318,25 @@
return C2_OMITTED;
}
-C2Status C2VDAComponentIntf::createTunnel_sm(node_id targetComponent) {
+c2_status_t C2VDAComponentIntf::createTunnel_sm(c2_node_id_t targetComponent) {
UNUSED(targetComponent);
return C2_OMITTED; // Tunneling is not supported by now
}
-C2Status C2VDAComponentIntf::releaseTunnel_sm(node_id targetComponent) {
+c2_status_t C2VDAComponentIntf::releaseTunnel_sm(c2_node_id_t targetComponent) {
UNUSED(targetComponent);
return C2_OMITTED; // Tunneling is not supported by now
}
-std::shared_ptr<C2ParamReflector> C2VDAComponentIntf::getParamReflector() const {
- return mParamReflector;
-}
-
-C2Status C2VDAComponentIntf::getSupportedParams(
+c2_status_t C2VDAComponentIntf::querySupportedParams_nb(
std::vector<std::shared_ptr<C2ParamDescriptor>>* const params) const {
params->insert(params->begin(), mParamDescs.begin(), mParamDescs.end());
return C2_OK;
}
-C2Status C2VDAComponentIntf::getSupportedValues(
+c2_status_t C2VDAComponentIntf::querySupportedValues_nb(
std::vector<C2FieldSupportedValuesQuery>& fields) const {
- C2Status err = C2_OK;
+ c2_status_t err = C2_OK;
for (auto& query : fields) {
if (mSupportedValues.count(query.field) == 0) {
query.status = C2_BAD_INDEX;
@@ -423,10 +418,8 @@
////////////////////////////////////////////////////////////////////////////////
C2VDAComponent::C2VDAComponent(C2String name,
- node_id id,
- const std::shared_ptr<C2ComponentListener>& listener)
+ c2_node_id_t id)
: mIntf(std::make_shared<C2VDAComponentIntf>(name, id)),
- mListener(listener),
mThread("C2VDAComponentThread"),
mVDAInitResult(VideoDecodeAcceleratorAdaptor::Result::ILLEGAL_STATE),
mComponentState(ComponentState::UNINITIALIZED),
@@ -507,31 +500,36 @@
mComponentState = ComponentState::UNINITIALIZED;
}
-C2Status C2VDAComponent::queue_nb(std::list<std::unique_ptr<C2Work>>* const items) {
+c2_status_t C2VDAComponent::setListener_sm(const std::shared_ptr<C2Component::Listener> &listener) {
+ mListener = listener;
+ return C2_OMITTED;
+}
+
+c2_status_t C2VDAComponent::queue_nb(std::list<std::unique_ptr<C2Work>>* const items) {
UNUSED(items);
return C2_OMITTED;
}
-C2Status C2VDAComponent::announce_nb(const std::vector<C2WorkOutline>& items) {
+c2_status_t C2VDAComponent::announce_nb(const std::vector<C2WorkOutline>& items) {
UNUSED(items);
return C2_OMITTED; // Tunneling is not supported by now
}
-C2Status C2VDAComponent::flush_sm(
- bool flushThrough, std::list<std::unique_ptr<C2Work>>* const flushedWork) {
- if (flushThrough)
+c2_status_t C2VDAComponent::flush_sm(
+ flush_mode_t mode, std::list<std::unique_ptr<C2Work>>* const flushedWork) {
+ if (mode != FLUSH_COMPONENT)
return C2_OMITTED; // Tunneling is not supported by now
UNUSED(flushedWork);
return C2_OMITTED;
}
-C2Status C2VDAComponent::drain_nb(bool drainThrough) {
- if (drainThrough)
+c2_status_t C2VDAComponent::drain_nb(drain_mode_t mode) {
+ if (mode != DRAIN_COMPONENT)
return C2_OMITTED; // Tunneling is not supported by now
return C2_OMITTED;
}
-C2Status C2VDAComponent::start() {
+c2_status_t C2VDAComponent::start() {
if (mState != State::LOADED) {
return C2_BAD_STATE; // start() is only supported when component is in LOADED state.
}
@@ -551,7 +549,7 @@
return C2_OK;
}
-C2Status C2VDAComponent::stop() {
+c2_status_t C2VDAComponent::stop() {
if (!(mState == State::RUNNING || mState == State::ERROR)) {
return C2_BAD_STATE; // component is already in stopped state.
}
@@ -613,31 +611,56 @@
}
////////////////////////////////////////////////////////////////////////////////
-C2Status C2VDAComponentStore::createComponent(
+C2VDAComponentStore::C2VDAComponentStore()
+ : mParamReflector(std::make_shared<ParamReflector>()) {
+}
+
+C2String C2VDAComponentStore::getName() const {
+ return "android.componentStore.v4l2";
+}
+
+c2_status_t C2VDAComponentStore::createComponent(
C2String name, std::shared_ptr<C2Component>* const component) {
UNUSED(name);
UNUSED(component);
return C2_OMITTED;
}
-C2Status C2VDAComponentStore::createInterface(
+c2_status_t C2VDAComponentStore::createInterface(
C2String name, std::shared_ptr<C2ComponentInterface>* const interface) {
interface->reset(new C2VDAComponentIntf(name, 12345));
return C2_OK;
}
-std::vector<std::unique_ptr<const C2ComponentInfo>> C2VDAComponentStore::getComponents() {
- return std::vector<std::unique_ptr<const C2ComponentInfo>>();
+std::vector<std::shared_ptr<const C2Component::Traits>>
+C2VDAComponentStore::listComponents_sm() const {
+ return std::vector<std::shared_ptr<const C2Component::Traits>>();
}
-C2Status C2VDAComponentStore::copyBuffer(
+c2_status_t C2VDAComponentStore::copyBuffer(
std::shared_ptr<C2GraphicBuffer> src, std::shared_ptr<C2GraphicBuffer> dst) {
UNUSED(src);
UNUSED(dst);
return C2_OMITTED;
}
-C2Status C2VDAComponentStore::query_sm(
+std::shared_ptr<C2ParamReflector> C2VDAComponentStore::getParamReflector() const {
+ return mParamReflector;
+}
+
+c2_status_t C2VDAComponentStore::querySupportedParams_nb(
+ std::vector<std::shared_ptr<C2ParamDescriptor>>* const params) const {
+ UNUSED(params);
+ return C2_OMITTED;
+}
+
+c2_status_t C2VDAComponentStore::querySupportedValues_nb(
+ std::vector<C2FieldSupportedValuesQuery>& fields) const {
+ UNUSED(fields);
+ return C2_OMITTED;
+}
+
+c2_status_t C2VDAComponentStore::query_sm(
const std::vector<C2Param* const>& stackParams,
const std::vector<C2Param::Index>& heapParamIndices,
std::vector<std::unique_ptr<C2Param>>* const heapParams) const {
@@ -647,9 +670,17 @@
return C2_OMITTED;
}
-C2Status C2VDAComponentStore::config_nb(
+c2_status_t C2VDAComponentStore::config_sm(
const std::vector<C2Param* const> ¶ms,
- std::list<std::unique_ptr<C2SettingResult>>* const failures) {
+ std::vector<std::unique_ptr<C2SettingResult>>* const failures) {
+ UNUSED(params);
+ UNUSED(failures);
+ return C2_OMITTED;
+}
+
+c2_status_t C2VDAComponentStore::commit_sm(
+ const std::vector<C2Param* const> ¶ms,
+ std::vector<std::unique_ptr<C2SettingResult>>* const failures) {
UNUSED(params);
UNUSED(failures);
return C2_OMITTED;
diff --git a/C2VDAComponent.h b/C2VDAComponent.h
index 75331a3..0ad5e51 100644
--- a/C2VDAComponent.h
+++ b/C2VDAComponent.h
@@ -31,47 +31,42 @@
class C2VDAComponentIntf : public C2ComponentInterface {
public:
- C2VDAComponentIntf(C2String name, node_id id);
+ C2VDAComponentIntf(C2String name, c2_node_id_t id);
virtual ~C2VDAComponentIntf() {}
// Impementation of C2ComponentInterface interface
virtual C2String getName() const override;
- virtual node_id getId() const override;
- virtual C2Status query_nb(
+ virtual c2_node_id_t getId() const override;
+ virtual c2_status_t query_nb(
const std::vector<C2Param* const> &stackParams,
const std::vector<C2Param::Index> &heapParamIndices,
std::vector<std::unique_ptr<C2Param>>* const heapParams) const override;
- virtual C2Status config_nb(
+ virtual c2_status_t config_nb(
const std::vector<C2Param* const>& params,
std::vector<std::unique_ptr<C2SettingResult>>* const failures) override;
- virtual C2Status commit_sm(
+ virtual c2_status_t commit_sm(
const std::vector<C2Param* const>& params,
std::vector<std::unique_ptr<C2SettingResult>>* const failures) override;
- virtual C2Status createTunnel_sm(node_id targetComponent) override;
- virtual C2Status releaseTunnel_sm(node_id targetComponent) override;
- virtual std::shared_ptr<C2ParamReflector> getParamReflector() const override;
- virtual C2Status getSupportedParams(
+ virtual c2_status_t createTunnel_sm(c2_node_id_t targetComponent) override;
+ virtual c2_status_t releaseTunnel_sm(c2_node_id_t targetComponent) override;
+ virtual c2_status_t querySupportedParams_nb(
std::vector<std::shared_ptr<C2ParamDescriptor>>* const params) const override;
- virtual C2Status getSupportedValues(
+ virtual c2_status_t querySupportedValues_nb(
std::vector<C2FieldSupportedValuesQuery>& fields) const override;
private:
const C2String kName;
- const node_id kId;
+ const c2_node_id_t kId;
//TODO: in the future different codec (h264/vp8/vp9) would be different class inherited from a
// base class. This static const should be moved to each super class.
static const uint32_t kInputFormatFourcc;
- class ParamReflector;
-
C2Param* getParamByIndex(uint32_t index) const;
template<class T>
std::unique_ptr<C2SettingResult> validateVideoSizeConfig(C2Param* c2Param) const;
template<class T>
std::unique_ptr<C2SettingResult> validateUint32Config(C2Param* c2Param) const;
- std::shared_ptr<C2ParamReflector> mParamReflector;
-
// The following parameters are read-only.
// The component domain; should be C2DomainVideo.
@@ -110,17 +105,18 @@
public std::enable_shared_from_this<C2VDAComponent> {
public:
C2VDAComponent(
- C2String name, node_id id, const std::shared_ptr<C2ComponentListener>& listener);
+ C2String name, c2_node_id_t id);
virtual ~C2VDAComponent() override;
// Implementation of C2Component interface
- virtual C2Status queue_nb(std::list<std::unique_ptr<C2Work>>* const items) override;
- virtual C2Status announce_nb(const std::vector<C2WorkOutline>& items) override;
- virtual C2Status flush_sm(
- bool flushThrough, std::list<std::unique_ptr<C2Work>>* const flushedWork) override;
- virtual C2Status drain_nb(bool drainThrough) override;
- virtual C2Status start() override;
- virtual C2Status stop() override;
+ virtual c2_status_t setListener_sm(const std::shared_ptr<Listener>& listener) override;
+ virtual c2_status_t queue_nb(std::list<std::unique_ptr<C2Work>>* const items) override;
+ virtual c2_status_t announce_nb(const std::vector<C2WorkOutline>& items) override;
+ virtual c2_status_t flush_sm(
+ flush_mode_t mode, std::list<std::unique_ptr<C2Work>>* const flushedWork) override;
+ virtual c2_status_t drain_nb(drain_mode_t mode) override;
+ virtual c2_status_t start() override;
+ virtual c2_status_t stop() override;
virtual void reset() override;
virtual void release() override;
virtual std::shared_ptr<C2ComponentInterface> intf() override;
@@ -180,7 +176,7 @@
// The pointer of component interface.
const std::shared_ptr<C2VDAComponentIntf> mIntf;
// The pointer of component listener.
- const std::shared_ptr<C2ComponentListener> mListener;
+ std::shared_ptr<Listener> mListener;
// The main component thread.
base::Thread mThread;
@@ -211,26 +207,45 @@
class C2VDAComponentStore : public C2ComponentStore {
public:
- C2VDAComponentStore() {}
+ C2VDAComponentStore();
~C2VDAComponentStore() override {}
- C2Status createComponent(C2String name,
+ C2String getName() const override;
+
+ c2_status_t createComponent(C2String name,
std::shared_ptr<C2Component>* const component) override;
- C2Status createInterface(C2String name,
+ c2_status_t createInterface(C2String name,
std::shared_ptr<C2ComponentInterface>* const interface) override;
- std::vector<std::unique_ptr<const C2ComponentInfo>> getComponents() override;
+ std::vector<std::shared_ptr<const C2Component::Traits>> listComponents_sm() const override;
- C2Status copyBuffer(std::shared_ptr<C2GraphicBuffer> src,
+ c2_status_t copyBuffer(std::shared_ptr<C2GraphicBuffer> src,
std::shared_ptr<C2GraphicBuffer> dst) override;
- C2Status query_sm(const std::vector<C2Param* const>& stackParams,
+ std::shared_ptr<C2ParamReflector> getParamReflector() const override;
+
+ c2_status_t querySupportedParams_nb(
+ std::vector<std::shared_ptr<C2ParamDescriptor>>* const params) const override;
+
+ c2_status_t querySupportedValues_nb(
+ std::vector<C2FieldSupportedValuesQuery>& fields) const override;
+
+ c2_status_t query_sm(const std::vector<C2Param* const>& stackParams,
const std::vector<C2Param::Index>& heapParamIndices,
std::vector<std::unique_ptr<C2Param>>* const heapParams) const override;
- C2Status config_nb(const std::vector<C2Param* const>& params,
- std::list<std::unique_ptr<C2SettingResult>>* const failures) override;
+ c2_status_t config_sm(const std::vector<C2Param* const>& params,
+ std::vector<std::unique_ptr<C2SettingResult>>* const failures) override;
+
+ c2_status_t commit_sm(const std::vector<C2Param* const>& params,
+ std::vector<std::unique_ptr<C2SettingResult>>* const failures) override;
+
+
+private:
+ class ParamReflector;
+
+ std::shared_ptr<C2ParamReflector> mParamReflector;
};
} // namespace android
diff --git a/tests/C2VDAComponent_test.cpp b/tests/C2VDAComponent_test.cpp
index 8726446..223926b 100644
--- a/tests/C2VDAComponent_test.cpp
+++ b/tests/C2VDAComponent_test.cpp
@@ -25,35 +25,35 @@
return ptr;
}
-class TestListener: public C2ComponentListener {
+class TestListener: public C2Component::Listener {
public:
~TestListener() override {}
- void onWorkDone(std::weak_ptr<C2Component> component,
+ void onWorkDone_nb(std::weak_ptr<C2Component> component,
std::vector<std::unique_ptr<C2Work>> workItems) override {
UNUSED(workItems);
auto comp = component.lock();
- printf("TestListener::onWorkDone from component %s\n",
+ printf("TestListener::onWorkDone_nb from component %s\n",
comp->intf()->getName().c_str());
}
- void onTripped(std::weak_ptr<C2Component> component,
+ void onTripped_nb(std::weak_ptr<C2Component> component,
std::vector<std::shared_ptr<C2SettingResult>> settingResult) override {
UNUSED(settingResult);
auto comp = component.lock();
- printf("TestListener::onTripped from component %s\n",
+ printf("TestListener::onTripped_nb from component %s\n",
comp->intf()->getName().c_str());
}
- void onError(std::weak_ptr<C2Component> component,
+ void onError_nb(std::weak_ptr<C2Component> component,
uint32_t errorCode) override {
auto comp = component.lock();
- printf("TestListener::onError Errno = %u from component %s\n",
+ printf("TestListener::onError_nb Errno = %u from component %s\n",
errorCode, comp->intf()->getName().c_str());
}
};
const C2String testCompName = "v4l2.decoder";
-const node_id testCompNodeId = 12345;
+const c2_node_id_t testCompNodeId = 12345;
const char* MEDIA_MIMETYPE_VIDEO_RAW = "video/raw";
const char* MEDIA_MIMETYPE_VIDEO_AVC = "video/avc";
@@ -62,7 +62,8 @@
protected:
C2VDAComponentTest() {
mListener = std::make_shared<TestListener>();
- mComponent = std::make_shared<C2VDAComponent>(testCompName, testCompNodeId, mListener);
+ mComponent = std::make_shared<C2VDAComponent>(testCompName, testCompNodeId);
+ (void)mComponent->setListener_sm(mListener);
}
~C2VDAComponentTest() override {}
@@ -94,7 +95,7 @@
int32_t heightMin, int32_t heightMax, int32_t heightStep);
std::shared_ptr<C2Component> mComponent;
- std::shared_ptr<C2ComponentListener> mListener;
+ std::shared_ptr<C2Component::Listener> mListener;
std::shared_ptr<C2ComponentInterface> mIntf;
};
@@ -349,13 +350,13 @@
};
ASSERT_EQ(
C2_OK,
- mIntf->getSupportedValues(widthC2FSV));
+ mIntf->querySupportedValues_nb(widthC2FSV));
std::vector<C2FieldSupportedValuesQuery> heightC2FSV = {
C2FieldSupportedValuesQuery::Current(C2ParamField(&videoSize, &C2VideoSizeStreamInfo::mHeight)),
};
ASSERT_EQ(
C2_OK,
- mIntf->getSupportedValues(heightC2FSV));
+ mIntf->querySupportedValues_nb(heightC2FSV));
ASSERT_EQ(1u, widthC2FSV.size());
ASSERT_EQ(C2_OK, widthC2FSV[0].status);
ASSERT_EQ(C2FieldSupportedValues::RANGE, widthC2FSV[0].values.type);
@@ -383,12 +384,12 @@
{ C2ParamField(&maxVideoSizeHint,
&C2MaxVideoSizeHintPortSetting::mWidth), C2FieldSupportedValuesQuery::CURRENT },
};
- mIntf->getSupportedValues(widthC2FSV);
+ mIntf->querySupportedValues_nb(widthC2FSV);
std::vector<C2FieldSupportedValuesQuery> heightC2FSV = {
C2FieldSupportedValuesQuery::Current(C2ParamField(&maxVideoSizeHint,
&C2MaxVideoSizeHintPortSetting::mHeight)),
};
- mIntf->getSupportedValues(heightC2FSV);
+ mIntf->querySupportedValues_nb(heightC2FSV);
ASSERT_EQ(1u, widthC2FSV.size());
ASSERT_EQ(C2_OK, widthC2FSV[0].status);
@@ -417,7 +418,7 @@
};
ASSERT_EQ(
C2_OK,
- mIntf->getSupportedValues(profileValues));
+ mIntf->querySupportedValues_nb(profileValues));
ASSERT_EQ(1u, profileValues.size());
ASSERT_EQ(C2_OK, profileValues[0].status);
@@ -463,16 +464,19 @@
printf("}\n");
}
+// TODO: move this to some component store test
TEST_F(C2VDAComponentTest, ParamReflector) {
+ std::shared_ptr<C2ComponentStore> store(new C2VDAComponentStore());
+
std::vector<std::shared_ptr<C2ParamDescriptor>> params;
- ASSERT_EQ(mIntf->getSupportedParams(¶ms), C2_OK);
+ ASSERT_EQ(mIntf->querySupportedParams_nb(¶ms), C2_OK);
for (const auto& paramDesc : params) {
printf("name: %s\n", paramDesc->name().c_str());
printf(" required: %s\n", paramDesc->isRequired() ? "yes" : "no");
printf(" type: %x\n", paramDesc->type().type());
std::unique_ptr<C2StructDescriptor> desc{
- mIntf->getParamReflector()->describe(paramDesc->type().type())};
+ store->getParamReflector()->describe(paramDesc->type().type())};
if (desc.get())
dumpStruct(*desc);
}
@@ -485,7 +489,7 @@
};
ASSERT_EQ(
C2_OK,
- mIntf->getSupportedValues(profileValues));
+ mIntf->querySupportedValues_nb(profileValues));
ASSERT_EQ(1u, profileValues.size());
ASSERT_EQ(C2_OK, profileValues[0].status);