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

Commit b0aeb8b6 authored by Lajos Molnar's avatar Lajos Molnar
Browse files

MediaProfiles: allow multiple codecs per profile.

Rework to use vectors for audio/video profiles. This allows XML to
list multiple audio/video codec parameters for each profile.

Bug: 171673898
Test: atest CamcorderProfileTest
Change-Id: I474794e606e1210e9c16c376b664268a7a57ddfb
parent 156236bb
Loading
Loading
Loading
Loading
+66 −56
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@ MediaProfiles::findTagForName(const MediaProfiles::NameToTagMap *map, size_t nMa
    return tag;
}

/*static*/ MediaProfiles::VideoCodec*
/*static*/ void
MediaProfiles::createVideoCodec(const char **atts, MediaProfiles *profiles)
{
    CHECK(!strcmp("codec",     atts[0]) &&
@@ -242,21 +242,20 @@ MediaProfiles::createVideoCodec(const char **atts, MediaProfiles *profiles)
    const int codec = findTagForName(sVideoEncoderNameMap, nMappings, atts[1]);
    if (codec == -1) {
        ALOGE("MediaProfiles::createVideoCodec failed to locate codec %s", atts[1]);
      return nullptr;
        return;
    }

    MediaProfiles::VideoCodec *videoCodec =
        new MediaProfiles::VideoCodec(static_cast<video_encoder>(codec),
            atoi(atts[3]), atoi(atts[5]), atoi(atts[7]), atoi(atts[9]));
    logVideoCodec(*videoCodec);
    VideoCodec videoCodec {
            static_cast<video_encoder>(codec),
            atoi(atts[3]), atoi(atts[5]), atoi(atts[7]), atoi(atts[9]) };
    logVideoCodec(videoCodec);

    size_t nCamcorderProfiles;
    CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1);
    profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mVideoCodec = videoCodec;
    return videoCodec;
    profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mVideoCodecs.emplace_back(videoCodec);
}

/*static*/ MediaProfiles::AudioCodec*
/*static*/ void
MediaProfiles::createAudioCodec(const char **atts, MediaProfiles *profiles)
{
    CHECK(!strcmp("codec",      atts[0]) &&
@@ -267,19 +266,19 @@ MediaProfiles::createAudioCodec(const char **atts, MediaProfiles *profiles)
    const int codec = findTagForName(sAudioEncoderNameMap, nMappings, atts[1]);
    if (codec == -1) {
        ALOGE("MediaProfiles::createAudioCodec failed to locate codec %s", atts[1]);
      return nullptr;
        return;
    }

    MediaProfiles::AudioCodec *audioCodec =
        new MediaProfiles::AudioCodec(static_cast<audio_encoder>(codec),
            atoi(atts[3]), atoi(atts[5]), atoi(atts[7]));
    logAudioCodec(*audioCodec);
    AudioCodec audioCodec {
            static_cast<audio_encoder>(codec),
            atoi(atts[3]), atoi(atts[5]), atoi(atts[7]) };
    logAudioCodec(audioCodec);

    size_t nCamcorderProfiles;
    CHECK((nCamcorderProfiles = profiles->mCamcorderProfiles.size()) >= 1);
    profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mAudioCodec = audioCodec;
    return audioCodec;
    profiles->mCamcorderProfiles[nCamcorderProfiles - 1]->mAudioCodecs.emplace_back(audioCodec);
}

/*static*/ MediaProfiles::AudioDecoderCap*
MediaProfiles::createAudioDecoderCap(const char **atts)
{
@@ -574,8 +573,20 @@ void MediaProfiles::checkAndAddRequiredProfilesIfNecessary() {
    initRequiredProfileRefs(mCameraIds);

    for (size_t i = 0, n = mCamcorderProfiles.size(); i < n; ++i) {
        int product = mCamcorderProfiles[i]->mVideoCodec->mFrameWidth *
                      mCamcorderProfiles[i]->mVideoCodec->mFrameHeight;
        // ensure at least one video and audio profile is added
        if (mCamcorderProfiles[i]->mVideoCodecs.size() == 0) {
            mCamcorderProfiles[i]->mVideoCodecs.emplace_back(
                    VIDEO_ENCODER_H263, 192000 /* bitrate */,
                    176 /* width */, 144 /* height */, 20 /* frameRate */);
        }
        if (mCamcorderProfiles[i]->mAudioCodecs.size() == 0) {
            mCamcorderProfiles[i]->mAudioCodecs.emplace_back(
                    AUDIO_ENCODER_AMR_NB, 12200 /* bitrate */,
                    8000 /* sampleRate */, 1 /* channels */);
        }

        int product = mCamcorderProfiles[i]->mVideoCodecs[0].mFrameWidth *
                      mCamcorderProfiles[i]->mVideoCodecs[0].mFrameHeight;

        camcorder_quality quality = mCamcorderProfiles[i]->mQuality;
        int cameraId = mCamcorderProfiles[i]->mCameraId;
@@ -744,34 +755,35 @@ MediaProfiles::createDefaultVideoEncoders(MediaProfiles *profiles)
/*static*/ MediaProfiles::CamcorderProfile*
MediaProfiles::createDefaultCamcorderTimeLapseQcifProfile(camcorder_quality quality)
{
    MediaProfiles::VideoCodec *videoCodec =
        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 1000000, 176, 144, 20);

    AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
    CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
    profile->mCameraId = 0;
    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
    profile->mQuality = quality;
    profile->mDuration = 60;
    profile->mVideoCodec = videoCodec;
    profile->mAudioCodec = audioCodec;
    profile->mVideoCodecs.emplace_back(
            VIDEO_ENCODER_H263, 1000000 /* bitrate */,
            176 /* width */, 144 /* height */, 20 /* frameRate */);
    profile->mAudioCodecs.emplace_back(
            AUDIO_ENCODER_AMR_NB, 12200 /* bitrate */,
            8000 /* sampleRate */, 1 /* channels */);

    return profile;
}

/*static*/ MediaProfiles::CamcorderProfile*
MediaProfiles::createDefaultCamcorderTimeLapse480pProfile(camcorder_quality quality)
{
    MediaProfiles::VideoCodec *videoCodec =
        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 20000000, 720, 480, 20);

    AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
    CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
    profile->mCameraId = 0;
    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
    profile->mQuality = quality;
    profile->mDuration = 60;
    profile->mVideoCodec = videoCodec;
    profile->mAudioCodec = audioCodec;
    profile->mVideoCodecs.emplace_back(
            VIDEO_ENCODER_H263, 20000000 /* bitrate */,
            720 /* width */, 480 /* height */, 20 /* frameRate */);
    profile->mAudioCodecs.emplace_back(
            AUDIO_ENCODER_AMR_NB, 12200 /* bitrate */,
            8000 /* sampleRate */, 1 /* channels */);
    return profile;
}

@@ -798,36 +810,34 @@ MediaProfiles::createDefaultCamcorderTimeLapseHighProfiles(
/*static*/ MediaProfiles::CamcorderProfile*
MediaProfiles::createDefaultCamcorderQcifProfile(camcorder_quality quality)
{
    MediaProfiles::VideoCodec *videoCodec =
        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 192000, 176, 144, 20);

    MediaProfiles::AudioCodec *audioCodec =
        new MediaProfiles::AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);

    MediaProfiles::CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
    CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
    profile->mCameraId = 0;
    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
    profile->mQuality = quality;
    profile->mDuration = 30;
    profile->mVideoCodec = videoCodec;
    profile->mAudioCodec = audioCodec;
    profile->mVideoCodecs.emplace_back(
            VIDEO_ENCODER_H263, 192000 /* bitrate */,
            176 /* width */, 144 /* height */, 20 /* frameRate */);
    profile->mAudioCodecs.emplace_back(
            AUDIO_ENCODER_AMR_NB, 12200 /* bitrate */,
            8000 /* sampleRate */, 1 /* channels */);
    return profile;
}

/*static*/ MediaProfiles::CamcorderProfile*
MediaProfiles::createDefaultCamcorderCifProfile(camcorder_quality quality)
{
    MediaProfiles::VideoCodec *videoCodec =
        new MediaProfiles::VideoCodec(VIDEO_ENCODER_H263, 360000, 352, 288, 20);

    AudioCodec *audioCodec = new AudioCodec(AUDIO_ENCODER_AMR_NB, 12200, 8000, 1);
    CamcorderProfile *profile = new MediaProfiles::CamcorderProfile;
    profile->mCameraId = 0;
    profile->mFileFormat = OUTPUT_FORMAT_THREE_GPP;
    profile->mQuality = quality;
    profile->mDuration = 60;
    profile->mVideoCodec = videoCodec;
    profile->mAudioCodec = audioCodec;
    profile->mVideoCodecs.emplace_back(
            VIDEO_ENCODER_H263, 360000 /* bitrate */,
            352 /* width */, 288 /* height */, 20 /* frameRate */);
    profile->mAudioCodecs.emplace_back(
            AUDIO_ENCODER_AMR_NB, 12200 /* bitrate */,
            8000 /* sampleRate */, 1 /* channels */);
    return profile;
}

@@ -1127,15 +1137,15 @@ int MediaProfiles::getCamcorderProfileParamByName(const char *name,

    if (!strcmp("duration", name)) return mCamcorderProfiles[index]->mDuration;
    if (!strcmp("file.format", name)) return mCamcorderProfiles[index]->mFileFormat;
    if (!strcmp("vid.codec", name)) return mCamcorderProfiles[index]->mVideoCodec->mCodec;
    if (!strcmp("vid.width", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameWidth;
    if (!strcmp("vid.height", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameHeight;
    if (!strcmp("vid.bps", name)) return mCamcorderProfiles[index]->mVideoCodec->mBitRate;
    if (!strcmp("vid.fps", name)) return mCamcorderProfiles[index]->mVideoCodec->mFrameRate;
    if (!strcmp("aud.codec", name)) return mCamcorderProfiles[index]->mAudioCodec->mCodec;
    if (!strcmp("aud.bps", name)) return mCamcorderProfiles[index]->mAudioCodec->mBitRate;
    if (!strcmp("aud.ch", name)) return mCamcorderProfiles[index]->mAudioCodec->mChannels;
    if (!strcmp("aud.hz", name)) return mCamcorderProfiles[index]->mAudioCodec->mSampleRate;
    if (!strcmp("vid.codec", name)) return mCamcorderProfiles[index]->mVideoCodecs[0].mCodec;
    if (!strcmp("vid.width", name)) return mCamcorderProfiles[index]->mVideoCodecs[0].mFrameWidth;
    if (!strcmp("vid.height", name)) return mCamcorderProfiles[index]->mVideoCodecs[0].mFrameHeight;
    if (!strcmp("vid.bps", name)) return mCamcorderProfiles[index]->mVideoCodecs[0].mBitRate;
    if (!strcmp("vid.fps", name)) return mCamcorderProfiles[index]->mVideoCodecs[0].mFrameRate;
    if (!strcmp("aud.codec", name)) return mCamcorderProfiles[index]->mAudioCodecs[0].mCodec;
    if (!strcmp("aud.bps", name)) return mCamcorderProfiles[index]->mAudioCodecs[0].mBitRate;
    if (!strcmp("aud.ch", name)) return mCamcorderProfiles[index]->mAudioCodecs[0].mChannels;
    if (!strcmp("aud.hz", name)) return mCamcorderProfiles[index]->mAudioCodecs[0].mSampleRate;

    ALOGE("The given camcorder profile param id %d name %s is not found", cameraId, name);
    return -1;
+10 −20
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@
#include <utils/threads.h>
#include <media/mediarecorder.h>

#include <vector>

namespace android {

enum camcorder_quality {
@@ -252,30 +254,18 @@ private:
            : mCameraId(0),
              mFileFormat(OUTPUT_FORMAT_THREE_GPP),
              mQuality(CAMCORDER_QUALITY_HIGH),
              mDuration(0),
              mVideoCodec(0),
              mAudioCodec(0) {}

        CamcorderProfile(const CamcorderProfile& copy) {
            mCameraId = copy.mCameraId;
            mFileFormat = copy.mFileFormat;
            mQuality = copy.mQuality;
            mDuration = copy.mDuration;
            mVideoCodec = new VideoCodec(*copy.mVideoCodec);
            mAudioCodec = new AudioCodec(*copy.mAudioCodec);
        }
              mDuration(0) {}

        ~CamcorderProfile() {
            delete mVideoCodec;
            delete mAudioCodec;
        }
        CamcorderProfile(const CamcorderProfile& copy) = default;

        ~CamcorderProfile() = default;

        int mCameraId;
        output_format mFileFormat;
        camcorder_quality mQuality;
        int mDuration;
        VideoCodec *mVideoCodec;
        AudioCodec *mAudioCodec;
        std::vector<VideoCodec> mVideoCodecs;
        std::vector<AudioCodec> mAudioCodecs;
    };

    struct VideoEncoderCap {
@@ -363,8 +353,8 @@ private:
    // from the xml
    static MediaProfiles* createInstanceFromXmlFile(const char *xml);
    static output_format createEncoderOutputFileFormat(const char **atts);
    static VideoCodec* createVideoCodec(const char **atts, MediaProfiles *profiles);
    static AudioCodec* createAudioCodec(const char **atts, MediaProfiles *profiles);
    static void createVideoCodec(const char **atts, MediaProfiles *profiles);
    static void createAudioCodec(const char **atts, MediaProfiles *profiles);
    static AudioDecoderCap* createAudioDecoderCap(const char **atts);
    static VideoDecoderCap* createVideoDecoderCap(const char **atts);
    static VideoEncoderCap* createVideoEncoderCap(const char **atts);