Loading media/codec2/core/include/C2Enum.h +2 −2 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ private: /// \note this will contain any initialization, which we will remove when converting to lower-case #define _C2_GET_ENUM_NAME(x, y) #x /// mapper to get value of enum #define _C2_GET_ENUM_VALUE(x, type) (_C2EnumConst<type>)x #define _C2_GET_ENUM_VALUE(x, type_) (_C2EnumConst<typename std::underlying_type<type_>::type>)type_::x /// \endcond Loading Loading @@ -106,7 +106,7 @@ public: template<> \ C2FieldDescriptor::NamedValuesType C2FieldDescriptor::namedValuesFor(const name &r __unused) { \ return _C2EnumUtils::sanitizeEnumValues( \ std::vector<C2Value::Primitive> { _C2_MAP(_C2_GET_ENUM_VALUE, type, __VA_ARGS__) }, \ std::vector<C2Value::Primitive> { _C2_MAP(_C2_GET_ENUM_VALUE, name, __VA_ARGS__) }, \ { _C2_MAP(_C2_GET_ENUM_NAME, type, __VA_ARGS__) }, \ prefix); \ } Loading media/codec2/core/include/C2Param.h +8 −0 Original line number Diff line number Diff line Loading @@ -508,6 +508,14 @@ protected: return _mIndex.setPort(output); } /// sets the size of this parameter. inline void setSize(size_t size) { if (size < sizeof(C2Param)) { size = 0; } _mSize = c2_min(size, _mSize); } public: /// invalidate this parameter. There is no recovery from this call; e.g. parameter /// cannot be 'corrected' to be valid. Loading media/codec2/core/include/C2ParamDef.h +8 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,9 @@ public: PARAM_TYPE = CoreIndex | TypeFlags }; // the underlying param struct type typedef S Struct; protected: enum : uint32_t { FLEX_SIZE = 0, Loading Loading @@ -270,6 +273,11 @@ protected: } \ return 0; \ } \ inline void setFlexCount(size_t count) { \ if (count < flexCount()) { \ this->setSize(sizeof(_Type) + _Type::FLEX_SIZE * count); \ } \ } \ /// Mark flexible member variable and make structure flexible. #define FLEX(cls, m) \ Loading media/codec2/tests/C2Param_test.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -2328,6 +2328,17 @@ TEST_F(C2ParamTest, FlexParamOpsTest) { static_assert(std::is_same<decltype(blobValue->m.value), uint8_t[]>::value, "should be uint8_t[]"); EXPECT_EQ(0, memcmp(blobValue->m.value, "ABCD\0", 6)); EXPECT_EQ(6u, blobValue->flexCount()); blobValue->setFlexCount(7u); // increasing the count does not change it EXPECT_EQ(6u, blobValue->flexCount()); blobValue->setFlexCount(2u); // decreasing the count changes it to it EXPECT_EQ(2u, blobValue->flexCount()); blobValue->setFlexCount(0u); // can decrease to 0 and blob remains valid EXPECT_EQ(0u, blobValue->flexCount()); EXPECT_TRUE(*blobValue); blobValue->invalidate(); // flex params can be invalidated => results in 0 size EXPECT_FALSE(*blobValue); EXPECT_EQ(0u, blobValue->size()); std::vector<C2FieldDescriptor> fields = blobValue->FieldList(); EXPECT_EQ(1u, fields.size()); EXPECT_EQ(FD::BLOB, fields.cbegin()->type()); Loading Loading
media/codec2/core/include/C2Enum.h +2 −2 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ private: /// \note this will contain any initialization, which we will remove when converting to lower-case #define _C2_GET_ENUM_NAME(x, y) #x /// mapper to get value of enum #define _C2_GET_ENUM_VALUE(x, type) (_C2EnumConst<type>)x #define _C2_GET_ENUM_VALUE(x, type_) (_C2EnumConst<typename std::underlying_type<type_>::type>)type_::x /// \endcond Loading Loading @@ -106,7 +106,7 @@ public: template<> \ C2FieldDescriptor::NamedValuesType C2FieldDescriptor::namedValuesFor(const name &r __unused) { \ return _C2EnumUtils::sanitizeEnumValues( \ std::vector<C2Value::Primitive> { _C2_MAP(_C2_GET_ENUM_VALUE, type, __VA_ARGS__) }, \ std::vector<C2Value::Primitive> { _C2_MAP(_C2_GET_ENUM_VALUE, name, __VA_ARGS__) }, \ { _C2_MAP(_C2_GET_ENUM_NAME, type, __VA_ARGS__) }, \ prefix); \ } Loading
media/codec2/core/include/C2Param.h +8 −0 Original line number Diff line number Diff line Loading @@ -508,6 +508,14 @@ protected: return _mIndex.setPort(output); } /// sets the size of this parameter. inline void setSize(size_t size) { if (size < sizeof(C2Param)) { size = 0; } _mSize = c2_min(size, _mSize); } public: /// invalidate this parameter. There is no recovery from this call; e.g. parameter /// cannot be 'corrected' to be valid. Loading
media/codec2/core/include/C2ParamDef.h +8 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,9 @@ public: PARAM_TYPE = CoreIndex | TypeFlags }; // the underlying param struct type typedef S Struct; protected: enum : uint32_t { FLEX_SIZE = 0, Loading Loading @@ -270,6 +273,11 @@ protected: } \ return 0; \ } \ inline void setFlexCount(size_t count) { \ if (count < flexCount()) { \ this->setSize(sizeof(_Type) + _Type::FLEX_SIZE * count); \ } \ } \ /// Mark flexible member variable and make structure flexible. #define FLEX(cls, m) \ Loading
media/codec2/tests/C2Param_test.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -2328,6 +2328,17 @@ TEST_F(C2ParamTest, FlexParamOpsTest) { static_assert(std::is_same<decltype(blobValue->m.value), uint8_t[]>::value, "should be uint8_t[]"); EXPECT_EQ(0, memcmp(blobValue->m.value, "ABCD\0", 6)); EXPECT_EQ(6u, blobValue->flexCount()); blobValue->setFlexCount(7u); // increasing the count does not change it EXPECT_EQ(6u, blobValue->flexCount()); blobValue->setFlexCount(2u); // decreasing the count changes it to it EXPECT_EQ(2u, blobValue->flexCount()); blobValue->setFlexCount(0u); // can decrease to 0 and blob remains valid EXPECT_EQ(0u, blobValue->flexCount()); EXPECT_TRUE(*blobValue); blobValue->invalidate(); // flex params can be invalidated => results in 0 size EXPECT_FALSE(*blobValue); EXPECT_EQ(0u, blobValue->size()); std::vector<C2FieldDescriptor> fields = blobValue->FieldList(); EXPECT_EQ(1u, fields.size()); EXPECT_EQ(FD::BLOB, fields.cbegin()->type()); Loading