Merge "codec2: Fix ambiguity in operator overloads" into main am: 197ad625b4
Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/2956420
Change-Id: I8699e7f7c0c3f72578fdec9e35d0a7f851c07605
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/media/codec2/core/include/C2Param.h b/media/codec2/core/include/C2Param.h
index e938f96..387d2b8 100644
--- a/media/codec2/core/include/C2Param.h
+++ b/media/codec2/core/include/C2Param.h
@@ -427,7 +427,9 @@
inline bool operator==(const C2Param &o) const {
return equals(o) && memcmp(this, &o, _mSize) == 0;
}
+#if __cplusplus < 202002
inline bool operator!=(const C2Param &o) const { return !operator==(o); }
+#endif
/// safe(r) type cast from pointer and size
inline static C2Param* From(void *addr, size_t len) {
diff --git a/media/codec2/core/include/C2ParamDef.h b/media/codec2/core/include/C2ParamDef.h
index 86dfe65..1805464 100644
--- a/media/codec2/core/include/C2ParamDef.h
+++ b/media/codec2/core/include/C2ParamDef.h
@@ -212,6 +212,26 @@
}
};
+/// Define equality (and inequality) operators for params.
+#if __cplusplus < 202002
+
+#define DEFINE_EQUALITY_OPERATORS(_Type, T) \
+ inline bool operator==(const _Type &o) const { \
+ return this->T::operator==(o); \
+ } \
+ inline bool operator!=(const _Type &o) const { \
+ return !operator==(o); \
+ }
+
+#else
+
+#define DEFINE_EQUALITY_OPERATORS(_Type, T) \
+ inline bool operator==(const _Type &o) const { \
+ return this->T::operator==(o); \
+ }
+
+#endif
+
/// Define From() cast operators for params.
#define DEFINE_CAST_OPERATORS(_Type) \
inline static _Type* From(C2Param *other) { \
@@ -404,12 +424,12 @@
/// Specialization for an input port parameter.
struct input : public T, public S,
public _C2StructCheck<S, ParamIndex, T::PARAM_KIND | T::Index::DIR_INPUT> {
- using T::operator!=;
_C2_CORE_INDEX_OVERRIDE(ParamIndex)
/// Wrapper around base structure's constructor.
template<typename ...Args>
inline input(const Args(&... args)) : T(sizeof(_Type), input::PARAM_TYPE), S(args...) { }
+ DEFINE_EQUALITY_OPERATORS(input, T)
DEFINE_CAST_OPERATORS(input)
};
@@ -417,12 +437,12 @@
/// Specialization for an output port parameter.
struct output : public T, public S,
public _C2StructCheck<S, ParamIndex, T::PARAM_KIND | T::Index::DIR_OUTPUT> {
- using T::operator!=;
_C2_CORE_INDEX_OVERRIDE(ParamIndex)
/// Wrapper around base structure's constructor.
template<typename ...Args>
inline output(const Args(&... args)) : T(sizeof(_Type), output::PARAM_TYPE), S(args...) { }
+ DEFINE_EQUALITY_OPERATORS(output, T)
DEFINE_CAST_OPERATORS(output)
};
};
@@ -472,7 +492,6 @@
/// Specialization for an input port parameter.
struct input : public T,
public _C2FlexStructCheck<S, ParamIndex, T::PARAM_KIND | T::Index::DIR_INPUT> {
- using T::operator!=;
private:
/// Wrapper around base structure's constructor while also specifying port/direction.
template<typename ...Args>
@@ -482,6 +501,7 @@
public:
S m; ///< wrapped flexible structure
+ DEFINE_EQUALITY_OPERATORS(input, T)
DEFINE_FLEXIBLE_METHODS(input, S)
DEFINE_CAST_OPERATORS(input)
};
@@ -489,7 +509,6 @@
/// Specialization for an output port parameter.
struct output : public T,
public _C2FlexStructCheck<S, ParamIndex, T::PARAM_KIND | T::Index::DIR_OUTPUT> {
- using T::operator!=;
private:
/// Wrapper around base structure's constructor while also specifying port/direction.
template<typename ...Args>
@@ -499,6 +518,7 @@
public:
S m; ///< wrapped flexible structure
+ DEFINE_EQUALITY_OPERATORS(output, T)
DEFINE_FLEXIBLE_METHODS(output, S)
DEFINE_CAST_OPERATORS(output)
};
@@ -553,7 +573,6 @@
struct input : public T, public S,
public _C2StructCheck<S, ParamIndex,
T::PARAM_KIND | T::Index::IS_STREAM_FLAG | T::Type::DIR_INPUT> {
- using T::operator!=;
_C2_CORE_INDEX_OVERRIDE(ParamIndex)
/// Default constructor. Stream-ID is undefined.
@@ -565,6 +584,7 @@
/// Set stream-id. \retval true if the stream-id was successfully set.
inline bool setStream(unsigned stream) { return C2Param::setStream(stream); }
+ DEFINE_EQUALITY_OPERATORS(input, T)
DEFINE_CAST_OPERATORS(input)
};
@@ -572,7 +592,6 @@
struct output : public T, public S,
public _C2StructCheck<S, ParamIndex,
T::PARAM_KIND | T::Index::IS_STREAM_FLAG | T::Type::DIR_OUTPUT> {
- using T::operator!=;
_C2_CORE_INDEX_OVERRIDE(ParamIndex)
/// Default constructor. Stream-ID is undefined.
@@ -584,6 +603,7 @@
/// Set stream-id. \retval true if the stream-id was successfully set.
inline bool setStream(unsigned stream) { return C2Param::setStream(stream); }
+ DEFINE_EQUALITY_OPERATORS(output, T)
DEFINE_CAST_OPERATORS(output)
};
};
@@ -640,7 +660,6 @@
struct input : public T,
public _C2FlexStructCheck<S, ParamIndex,
T::PARAM_KIND | T::Index::IS_STREAM_FLAG | T::Type::DIR_INPUT> {
- using T::operator!=;
private:
/// Default constructor. Stream-ID is undefined.
inline input(size_t flexCount) : T(_Type::CalcSize(flexCount), input::PARAM_TYPE) { }
@@ -655,6 +674,7 @@
/// Set stream-id. \retval true if the stream-id was successfully set.
inline bool setStream(unsigned stream) { return C2Param::setStream(stream); }
+ DEFINE_EQUALITY_OPERATORS(input, T)
DEFINE_FLEXIBLE_METHODS(input, S)
DEFINE_CAST_OPERATORS(input)
};
@@ -663,7 +683,6 @@
struct output : public T,
public _C2FlexStructCheck<S, ParamIndex,
T::PARAM_KIND | T::Index::IS_STREAM_FLAG | T::Type::DIR_OUTPUT> {
- using T::operator!=;
private:
/// Default constructor. Stream-ID is undefined.
inline output(size_t flexCount) : T(_Type::CalcSize(flexCount), output::PARAM_TYPE) { }
@@ -678,6 +697,7 @@
/// Set stream-id. \retval true if the stream-id was successfully set.
inline bool setStream(unsigned stream) { return C2Param::setStream(stream); }
+ DEFINE_EQUALITY_OPERATORS(output, T)
DEFINE_FLEXIBLE_METHODS(output, S)
DEFINE_CAST_OPERATORS(output)
};
diff --git a/media/codec2/tests/C2ComponentInterface_test.cpp b/media/codec2/tests/C2ComponentInterface_test.cpp
index 67f733d..d1844b0 100644
--- a/media/codec2/tests/C2ComponentInterface_test.cpp
+++ b/media/codec2/tests/C2ComponentInterface_test.cpp
@@ -235,7 +235,7 @@
// |*heapParams[0]| is a parameter value. The size of |heapParams| has to be one.
ASSERT_EQ(1u, heapParams.size());
EXPECT_TRUE(heapParams[0]);
- EXPECT_EQ(*heapParams[0], expected);
+ EXPECT_EQ(*heapParams[0], (C2Param &)(expected));
}
template <typename T> void C2CompIntfTest::querySupportedParam() {