Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66d9d061 authored by Rakesh Kumar's avatar Rakesh Kumar Committed by Sungtak Lee
Browse files

codec2: Add support to derive from base class for audio encoders

Test: run cts -m CtsMediaTestCases --test android.media.cts.EncoderTest
Bug: 124962433

Change-Id: I35dfb7e8b87c1d4b356b02cdee5fdd850e1002b1
parent 471dcc99
Loading
Loading
Loading
Loading
+21 −28
Original line number Original line Diff line number Diff line
@@ -29,33 +29,32 @@


namespace android {
namespace android {


class C2SoftAacEnc::IntfImpl : public C2InterfaceHelper {
namespace {
public:
    explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
        : C2InterfaceHelper(helper) {

        setDerivedInstance(this);


        addParameter(
constexpr char COMPONENT_NAME[] = "c2.android.aac.encoder";
                DefineParam(mInputFormat, C2_PARAMKEY_INPUT_STREAM_BUFFER_TYPE)
                .withConstValue(new C2StreamBufferTypeSetting::input(0u, C2BufferData::LINEAR))
                .build());


        addParameter(
}  // namespace
                DefineParam(mOutputFormat, C2_PARAMKEY_OUTPUT_STREAM_BUFFER_TYPE)
                .withConstValue(new C2StreamBufferTypeSetting::output(0u, C2BufferData::LINEAR))
                .build());


        addParameter(
class C2SoftAacEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
                DefineParam(mInputMediaType, C2_PARAMKEY_INPUT_MEDIA_TYPE)
public:
                .withConstValue(AllocSharedString<C2PortMediaTypeSetting::input>(
    explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
                        MEDIA_MIMETYPE_AUDIO_RAW))
        : SimpleInterface<void>::BaseParams(
                .build());
                helper,
                COMPONENT_NAME,
                C2Component::KIND_ENCODER,
                C2Component::DOMAIN_AUDIO,
                MEDIA_MIMETYPE_AUDIO_AAC) {
        noPrivateBuffers();
        noInputReferences();
        noOutputReferences();
        noInputLatency();
        noTimeStretch();
        setDerivedInstance(this);


        addParameter(
        addParameter(
                DefineParam(mOutputMediaType, C2_PARAMKEY_OUTPUT_MEDIA_TYPE)
                DefineParam(mAttrib, C2_PARAMKEY_COMPONENT_ATTRIBUTES)
                .withConstValue(AllocSharedString<C2PortMediaTypeSetting::output>(
                .withConstValue(new C2ComponentAttributesSetting(
                        MEDIA_MIMETYPE_AUDIO_AAC))
                    C2Component::ATTRIB_IS_TEMPORAL))
                .build());
                .build());


        addParameter(
        addParameter(
@@ -125,10 +124,6 @@ public:
    }
    }


private:
private:
    std::shared_ptr<C2StreamBufferTypeSetting::input> mInputFormat;
    std::shared_ptr<C2StreamBufferTypeSetting::output> mOutputFormat;
    std::shared_ptr<C2PortMediaTypeSetting::input> mInputMediaType;
    std::shared_ptr<C2PortMediaTypeSetting::output> mOutputMediaType;
    std::shared_ptr<C2StreamSampleRateInfo::input> mSampleRate;
    std::shared_ptr<C2StreamSampleRateInfo::input> mSampleRate;
    std::shared_ptr<C2StreamChannelCountInfo::input> mChannelCount;
    std::shared_ptr<C2StreamChannelCountInfo::input> mChannelCount;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
@@ -136,8 +131,6 @@ private:
    std::shared_ptr<C2StreamProfileLevelInfo::output> mProfileLevel;
    std::shared_ptr<C2StreamProfileLevelInfo::output> mProfileLevel;
};
};


constexpr char COMPONENT_NAME[] = "c2.android.aac.encoder";

C2SoftAacEnc::C2SoftAacEnc(
C2SoftAacEnc::C2SoftAacEnc(
        const char *name,
        const char *name,
        c2_node_id_t id,
        c2_node_id_t id,
+22 −29
Original line number Original line Diff line number Diff line
@@ -27,36 +27,33 @@


namespace android {
namespace android {


namespace {

constexpr char COMPONENT_NAME[] = "c2.android.amrnb.encoder";
constexpr char COMPONENT_NAME[] = "c2.android.amrnb.encoder";


class C2SoftAmrNbEnc::IntfImpl : public C2InterfaceHelper {
}  // namespace


class C2SoftAmrNbEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
public:
public:
    explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
    explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
        : C2InterfaceHelper(helper) {
        : SimpleInterface<void>::BaseParams(
                helper,
                COMPONENT_NAME,
                C2Component::KIND_ENCODER,
                C2Component::DOMAIN_AUDIO,
                MEDIA_MIMETYPE_AUDIO_AMR_NB) {
        noPrivateBuffers();
        noInputReferences();
        noOutputReferences();
        noInputLatency();
        noTimeStretch();
        setDerivedInstance(this);
        setDerivedInstance(this);


        addParameter(
        addParameter(
            DefineParam(mInputFormat, C2_PARAMKEY_INPUT_STREAM_BUFFER_TYPE)
                DefineParam(mAttrib, C2_PARAMKEY_COMPONENT_ATTRIBUTES)
                .withConstValue(
                .withConstValue(new C2ComponentAttributesSetting(
                    new C2StreamBufferTypeSetting::input(0u, C2BufferData::LINEAR))
                    C2Component::ATTRIB_IS_TEMPORAL))
                .build());

        addParameter(
            DefineParam(mOutputFormat, C2_PARAMKEY_OUTPUT_STREAM_BUFFER_TYPE)
                .withConstValue(
                    new C2StreamBufferTypeSetting::output(0u, C2BufferData::LINEAR))
                .build());

        addParameter(
            DefineParam(mInputMediaType, C2_PARAMKEY_INPUT_MEDIA_TYPE)
                .withConstValue(AllocSharedString<C2PortMediaTypeSetting::input>(
                    MEDIA_MIMETYPE_AUDIO_RAW))
                .build());

        addParameter(
            DefineParam(mOutputMediaType, C2_PARAMKEY_OUTPUT_MEDIA_TYPE)
                .withConstValue(AllocSharedString<C2PortMediaTypeSetting::output>(
                    MEDIA_MIMETYPE_AUDIO_AMR_NB))
                .build());
                .build());


        addParameter(
        addParameter(
@@ -92,10 +89,6 @@ class C2SoftAmrNbEnc::IntfImpl : public C2InterfaceHelper {
    uint32_t getBitrate() const { return mBitrate->value; }
    uint32_t getBitrate() const { return mBitrate->value; }


private:
private:
    std::shared_ptr<C2StreamBufferTypeSetting::input> mInputFormat;
    std::shared_ptr<C2StreamBufferTypeSetting::output> mOutputFormat;
    std::shared_ptr<C2PortMediaTypeSetting::input> mInputMediaType;
    std::shared_ptr<C2PortMediaTypeSetting::output> mOutputMediaType;
    std::shared_ptr<C2StreamSampleRateInfo::input> mSampleRate;
    std::shared_ptr<C2StreamSampleRateInfo::input> mSampleRate;
    std::shared_ptr<C2StreamChannelCountInfo::input> mChannelCount;
    std::shared_ptr<C2StreamChannelCountInfo::input> mChannelCount;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
+22 −30
Original line number Original line Diff line number Diff line
@@ -29,36 +29,32 @@


namespace android {
namespace android {


namespace {

constexpr char COMPONENT_NAME[] = "c2.android.amrwb.encoder";
constexpr char COMPONENT_NAME[] = "c2.android.amrwb.encoder";


class C2SoftAmrWbEnc::IntfImpl : public C2InterfaceHelper {
}  // namespace

class C2SoftAmrWbEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
public:
public:
    explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
    explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
        : C2InterfaceHelper(helper) {
        : SimpleInterface<void>::BaseParams(
                helper,
                COMPONENT_NAME,
                C2Component::KIND_ENCODER,
                C2Component::DOMAIN_AUDIO,
                MEDIA_MIMETYPE_AUDIO_AMR_WB) {
        noPrivateBuffers();
        noInputReferences();
        noOutputReferences();
        noInputLatency();
        noTimeStretch();
        setDerivedInstance(this);
        setDerivedInstance(this);


        addParameter(
        addParameter(
            DefineParam(mInputFormat, C2_PARAMKEY_INPUT_STREAM_BUFFER_TYPE)
                DefineParam(mAttrib, C2_PARAMKEY_COMPONENT_ATTRIBUTES)
                .withConstValue(
                .withConstValue(new C2ComponentAttributesSetting(
                    new C2StreamBufferTypeSetting::input(0u, C2BufferData::LINEAR))
                    C2Component::ATTRIB_IS_TEMPORAL))
                .build());

        addParameter(
            DefineParam(mOutputFormat, C2_PARAMKEY_OUTPUT_STREAM_BUFFER_TYPE)
                .withConstValue(
                    new C2StreamBufferTypeSetting::output(0u, C2BufferData::LINEAR))
                .build());

        addParameter(
            DefineParam(mInputMediaType, C2_PARAMKEY_INPUT_MEDIA_TYPE)
                .withConstValue(AllocSharedString<C2PortMediaTypeSetting::input>(
                    MEDIA_MIMETYPE_AUDIO_RAW))
                .build());

        addParameter(
            DefineParam(mOutputMediaType, C2_PARAMKEY_OUTPUT_MEDIA_TYPE)
                .withConstValue(AllocSharedString<C2PortMediaTypeSetting::output>(
                    MEDIA_MIMETYPE_AUDIO_AMR_WB))
                .build());
                .build());


        addParameter(
        addParameter(
@@ -94,10 +90,6 @@ class C2SoftAmrWbEnc::IntfImpl : public C2InterfaceHelper {
    uint32_t getBitrate() const { return mBitrate->value; }
    uint32_t getBitrate() const { return mBitrate->value; }


private:
private:
    std::shared_ptr<C2StreamBufferTypeSetting::input> mInputFormat;
    std::shared_ptr<C2StreamBufferTypeSetting::output> mOutputFormat;
    std::shared_ptr<C2PortMediaTypeSetting::input> mInputMediaType;
    std::shared_ptr<C2PortMediaTypeSetting::output> mOutputMediaType;
    std::shared_ptr<C2StreamSampleRateInfo::input> mSampleRate;
    std::shared_ptr<C2StreamSampleRateInfo::input> mSampleRate;
    std::shared_ptr<C2StreamChannelCountInfo::input> mChannelCount;
    std::shared_ptr<C2StreamChannelCountInfo::input> mChannelCount;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
+22 −23
Original line number Original line Diff line number Diff line
@@ -28,28 +28,32 @@


namespace android {
namespace android {


class C2SoftFlacEnc::IntfImpl : public C2InterfaceHelper {
namespace {

constexpr char COMPONENT_NAME[] = "c2.android.flac.encoder";

}  // namespace

class C2SoftFlacEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
public:
public:
    explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
    explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
        : C2InterfaceHelper(helper) {
        : SimpleInterface<void>::BaseParams(
                helper,
                COMPONENT_NAME,
                C2Component::KIND_ENCODER,
                C2Component::DOMAIN_AUDIO,
                MEDIA_MIMETYPE_AUDIO_FLAC) {
        noPrivateBuffers();
        noInputReferences();
        noOutputReferences();
        noInputLatency();
        noTimeStretch();
        setDerivedInstance(this);
        setDerivedInstance(this);

        addParameter(
        addParameter(
                DefineParam(mInputFormat, C2_PARAMKEY_INPUT_STREAM_BUFFER_TYPE)
                DefineParam(mAttrib, C2_PARAMKEY_COMPONENT_ATTRIBUTES)
                .withConstValue(new C2StreamBufferTypeSetting::input(0u, C2BufferData::LINEAR))
                .withConstValue(new C2ComponentAttributesSetting(
                .build());
                    C2Component::ATTRIB_IS_TEMPORAL))
        addParameter(
                DefineParam(mOutputFormat, C2_PARAMKEY_OUTPUT_STREAM_BUFFER_TYPE)
                .withConstValue(new C2StreamBufferTypeSetting::output(0u, C2BufferData::LINEAR))
                .build());
        addParameter(
                DefineParam(mInputMediaType, C2_PARAMKEY_INPUT_MEDIA_TYPE)
                .withConstValue(AllocSharedString<C2PortMediaTypeSetting::input>(
                        MEDIA_MIMETYPE_AUDIO_RAW))
                .build());
        addParameter(
                DefineParam(mOutputMediaType, C2_PARAMKEY_OUTPUT_MEDIA_TYPE)
                .withConstValue(AllocSharedString<C2PortMediaTypeSetting::output>(
                        MEDIA_MIMETYPE_AUDIO_FLAC))
                .build());
                .build());
        addParameter(
        addParameter(
                DefineParam(mSampleRate, C2_PARAMKEY_SAMPLE_RATE)
                DefineParam(mSampleRate, C2_PARAMKEY_SAMPLE_RATE)
@@ -92,17 +96,12 @@ public:
    int32_t getPcmEncodingInfo() const { return mPcmEncodingInfo->value; }
    int32_t getPcmEncodingInfo() const { return mPcmEncodingInfo->value; }


private:
private:
    std::shared_ptr<C2StreamBufferTypeSetting::input> mInputFormat;
    std::shared_ptr<C2StreamBufferTypeSetting::output> mOutputFormat;
    std::shared_ptr<C2PortMediaTypeSetting::input> mInputMediaType;
    std::shared_ptr<C2PortMediaTypeSetting::output> mOutputMediaType;
    std::shared_ptr<C2StreamSampleRateInfo::input> mSampleRate;
    std::shared_ptr<C2StreamSampleRateInfo::input> mSampleRate;
    std::shared_ptr<C2StreamChannelCountInfo::input> mChannelCount;
    std::shared_ptr<C2StreamChannelCountInfo::input> mChannelCount;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
    std::shared_ptr<C2StreamMaxBufferSizeInfo::input> mInputMaxBufSize;
    std::shared_ptr<C2StreamMaxBufferSizeInfo::input> mInputMaxBufSize;
    std::shared_ptr<C2StreamPcmEncodingInfo::input> mPcmEncodingInfo;
    std::shared_ptr<C2StreamPcmEncodingInfo::input> mPcmEncodingInfo;
};
};
constexpr char COMPONENT_NAME[] = "c2.android.flac.encoder";


C2SoftFlacEnc::C2SoftFlacEnc(
C2SoftFlacEnc::C2SoftFlacEnc(
        const char *name,
        const char *name,
+19 −26
Original line number Original line Diff line number Diff line
@@ -32,35 +32,32 @@ extern "C" {
#define DEFAULT_FRAME_DURATION_MS 20
#define DEFAULT_FRAME_DURATION_MS 20
namespace android {
namespace android {


namespace {

constexpr char COMPONENT_NAME[] = "c2.android.opus.encoder";
constexpr char COMPONENT_NAME[] = "c2.android.opus.encoder";


class C2SoftOpusEnc::IntfImpl : public C2InterfaceHelper {
}  // namespace

class C2SoftOpusEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
public:
public:
    explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
    explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
        : C2InterfaceHelper(helper) {
        : SimpleInterface<void>::BaseParams(

                helper,
                COMPONENT_NAME,
                C2Component::KIND_ENCODER,
                C2Component::DOMAIN_AUDIO,
                MEDIA_MIMETYPE_AUDIO_OPUS) {
        noPrivateBuffers();
        noInputReferences();
        noOutputReferences();
        noInputLatency();
        noTimeStretch();
        setDerivedInstance(this);
        setDerivedInstance(this);


        addParameter(
        addParameter(
                DefineParam(mInputFormat, C2_PARAMKEY_INPUT_STREAM_BUFFER_TYPE)
                DefineParam(mAttrib, C2_PARAMKEY_COMPONENT_ATTRIBUTES)
                .withConstValue(new C2StreamBufferTypeSetting::input(0u, C2BufferData::LINEAR))
                .withConstValue(new C2ComponentAttributesSetting(
                .build());
                    C2Component::ATTRIB_IS_TEMPORAL))

        addParameter(
                DefineParam(mOutputFormat, C2_PARAMKEY_OUTPUT_STREAM_BUFFER_TYPE)
                .withConstValue(new C2StreamBufferTypeSetting::output(0u, C2BufferData::LINEAR))
                .build());

        addParameter(
                DefineParam(mInputMediaType, C2_PARAMKEY_INPUT_MEDIA_TYPE)
                .withConstValue(AllocSharedString<C2PortMediaTypeSetting::input>(
                        MEDIA_MIMETYPE_AUDIO_RAW))
                .build());

        addParameter(
                DefineParam(mOutputMediaType, C2_PARAMKEY_OUTPUT_MEDIA_TYPE)
                .withConstValue(AllocSharedString<C2PortMediaTypeSetting::output>(
                        MEDIA_MIMETYPE_AUDIO_OPUS))
                .build());
                .build());


        addParameter(
        addParameter(
@@ -104,10 +101,6 @@ public:
    uint32_t getComplexity() const { return mComplexity->value; }
    uint32_t getComplexity() const { return mComplexity->value; }


private:
private:
    std::shared_ptr<C2StreamBufferTypeSetting::input> mInputFormat;
    std::shared_ptr<C2StreamBufferTypeSetting::output> mOutputFormat;
    std::shared_ptr<C2PortMediaTypeSetting::input> mInputMediaType;
    std::shared_ptr<C2PortMediaTypeSetting::output> mOutputMediaType;
    std::shared_ptr<C2StreamSampleRateInfo::input> mSampleRate;
    std::shared_ptr<C2StreamSampleRateInfo::input> mSampleRate;
    std::shared_ptr<C2StreamChannelCountInfo::input> mChannelCount;
    std::shared_ptr<C2StreamChannelCountInfo::input> mChannelCount;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;