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

Commit e1618fd1 authored by Lajos Molnar's avatar Lajos Molnar Committed by Automerger Merge Worker
Browse files

Merge changes Ia8e2451f,I474794e6 am: 9c8c0f24 am: a2a0264d am: bb26c50a am: 369aa588

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/1692788

Change-Id: I9923f8c728c2761842e2679276ac3fef732d8b60
parents 352d72ba 369aa588
Loading
Loading
Loading
Loading
+96 −56
Original line number Diff line number Diff line
@@ -230,7 +230,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]) &&
@@ -243,21 +243,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]) &&
@@ -268,19 +267,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)
{
@@ -575,8 +574,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;
@@ -745,34 +756,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;
}

@@ -799,36 +811,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;
}

@@ -1112,6 +1122,36 @@ int MediaProfiles::getCamcorderProfileIndex(int cameraId, camcorder_quality qual
    return index;
}

const MediaProfiles::CamcorderProfile *MediaProfiles::getCamcorderProfile(
            int cameraId, camcorder_quality quality) const {
    int index = getCamcorderProfileIndex(cameraId, quality);
    if (index == -1) {
        ALOGE("The given camcorder profile camera %d quality %d is not found",
            cameraId, quality);
        return nullptr;
    }

    return mCamcorderProfiles[index];
}

std::vector<const MediaProfiles::AudioCodec *>
MediaProfiles::CamcorderProfile::getAudioCodecs() const {
    std::vector<const MediaProfiles::AudioCodec *> res;
    for (const MediaProfiles::AudioCodec &ac : mAudioCodecs) {
        res.push_back(&ac);
    }
    return res;
}

std::vector<const MediaProfiles::VideoCodec *>
MediaProfiles::CamcorderProfile::getVideoCodecs() const {
    std::vector<const MediaProfiles::VideoCodec *> res;
    for (const MediaProfiles::VideoCodec &vc : mVideoCodecs) {
        res.push_back(&vc);
    }
    return res;
}

int MediaProfiles::getCamcorderProfileParamByName(const char *name,
                                                  int cameraId,
                                                  camcorder_quality quality) const
@@ -1128,15 +1168,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;
+174 −80
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 {
@@ -99,6 +101,176 @@ public:
     */
    static MediaProfiles* getInstance();

    /**
     * Configuration for a video encoder.
     */
    struct VideoCodec {
    public:
        /**
         * Constructs a video encoder configuration.
         *
         * @param codec codec type
         * @param bitrate bitrate in bps
         * @param frameWidth frame width in pixels
         * @param frameHeight frame height in pixels
         * @param frameRate frame rate in fps
         */
        VideoCodec(video_encoder codec, int bitrate, int frameWidth, int frameHeight, int frameRate)
            : mCodec(codec),
              mBitRate(bitrate),
              mFrameWidth(frameWidth),
              mFrameHeight(frameHeight),
              mFrameRate(frameRate) {
        }

        VideoCodec(const VideoCodec&) = default;

        ~VideoCodec() {}

        /** Returns the codec type. */
        video_encoder getCodec() const {
            return mCodec;
        }

        /** Returns the bitrate in bps. */
        int getBitrate() const {
            return mBitRate;
        }

        /** Returns the frame width in pixels. */
        int getFrameWidth() const {
            return mFrameWidth;
        }

        /** Returns the frame height in pixels. */
        int getFrameHeight() const {
            return mFrameHeight;
        }

        /** Returns the frame rate in fps. */
        int getFrameRate() const {
            return mFrameRate;
        }

    private:
        video_encoder mCodec;
        int mBitRate;
        int mFrameWidth;
        int mFrameHeight;
        int mFrameRate;
        friend class MediaProfiles;
    };

    /**
     * Configuration for an audio encoder.
     */
    struct AudioCodec {
    public:
        /**
         * Constructs an audio encoder configuration.
         *
         * @param codec codec type
         * @param bitrate bitrate in bps
         * @param sampleRate sample rate in Hz
         * @param channels number of channels
         */
        AudioCodec(audio_encoder codec, int bitrate, int sampleRate, int channels)
            : mCodec(codec),
              mBitRate(bitrate),
              mSampleRate(sampleRate),
              mChannels(channels) {
        }

        AudioCodec(const AudioCodec&) = default;

        ~AudioCodec() {}

        /** Returns the codec type. */
        audio_encoder getCodec() const {
            return mCodec;
        }

        /** Returns the bitrate in bps. */
        int getBitrate() const {
            return mBitRate;
        }

        /** Returns the sample rate in Hz. */
        int getSampleRate() const {
            return mSampleRate;
        }

        /** Returns the number of channels. */
        int getChannels() const {
            return mChannels;
        }

    private:
        audio_encoder mCodec;
        int mBitRate;
        int mSampleRate;
        int mChannels;
        friend class MediaProfiles;
    };

    /**
     * Configuration for a camcorder profile/encoder profiles object.
     */
    struct CamcorderProfile {
        /**
         *  Returns on ordered list of the video codec configurations in
         *  decreasing preference. The returned object is only valid
         *  during the lifetime of this object.
         */
        std::vector<const VideoCodec *> getVideoCodecs() const;

        /**
         *  Returns on ordered list of the audio codec configurations in
         *  decreasing preference. The returned object is only valid
         *  during the lifetime of this object.
         */
        std::vector<const AudioCodec *> getAudioCodecs() const;

        /** Returns the default duration in seconds. */
        int getDuration() const {
            return mDuration;
        }

        /** Returns the preferred file format. */
        int getFileFormat() const {
            return mFileFormat;
        }

        CamcorderProfile(const CamcorderProfile& copy) = default;

        ~CamcorderProfile() = default;

    private:
        /**
         * Constructs an empty object with no audio/video profiles.
         */
        CamcorderProfile()
            : mCameraId(0),
              mFileFormat(OUTPUT_FORMAT_THREE_GPP),
              mQuality(CAMCORDER_QUALITY_HIGH),
              mDuration(0) {}

        int mCameraId;
        output_format mFileFormat;
        camcorder_quality mQuality;
        int mDuration;
        std::vector<VideoCodec> mVideoCodecs;
        std::vector<AudioCodec> mAudioCodecs;
        friend class MediaProfiles;
    };

    /**
     * Returns the CamcorderProfile object for the given camera at
     * the given quality level, or null if it does not exist.
     */
    const CamcorderProfile *getCamcorderProfile(
            int cameraId, camcorder_quality quality) const;

    /**
     * Returns the value for the given param name for the given camera at
     * the given quality level, or -1 if error.
@@ -202,84 +374,6 @@ private:
    MediaProfiles() {}                               // Dummy default constructor
    ~MediaProfiles();                                // Don't delete me

    struct VideoCodec {
        VideoCodec(video_encoder codec, int bitRate, int frameWidth, int frameHeight, int frameRate)
            : mCodec(codec),
              mBitRate(bitRate),
              mFrameWidth(frameWidth),
              mFrameHeight(frameHeight),
              mFrameRate(frameRate) {}

        VideoCodec(const VideoCodec& copy) {
            mCodec = copy.mCodec;
            mBitRate = copy.mBitRate;
            mFrameWidth = copy.mFrameWidth;
            mFrameHeight = copy.mFrameHeight;
            mFrameRate = copy.mFrameRate;
        }

        ~VideoCodec() {}

        video_encoder mCodec;
        int mBitRate;
        int mFrameWidth;
        int mFrameHeight;
        int mFrameRate;
    };

    struct AudioCodec {
        AudioCodec(audio_encoder codec, int bitRate, int sampleRate, int channels)
            : mCodec(codec),
              mBitRate(bitRate),
              mSampleRate(sampleRate),
              mChannels(channels) {}

        AudioCodec(const AudioCodec& copy) {
            mCodec = copy.mCodec;
            mBitRate = copy.mBitRate;
            mSampleRate = copy.mSampleRate;
            mChannels = copy.mChannels;
        }

        ~AudioCodec() {}

        audio_encoder mCodec;
        int mBitRate;
        int mSampleRate;
        int mChannels;
    };

    struct CamcorderProfile {
        CamcorderProfile()
            : 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);
        }

        ~CamcorderProfile() {
            delete mVideoCodec;
            delete mAudioCodec;
        }

        int mCameraId;
        output_format mFileFormat;
        camcorder_quality mQuality;
        int mDuration;
        VideoCodec *mVideoCodec;
        AudioCodec *mAudioCodec;
    };

    struct VideoEncoderCap {
        // Ugly constructor
        VideoEncoderCap(video_encoder codec,
@@ -365,8 +459,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);