Loading media/libmedia/MediaProfiles.cpp +96 −56 Original line number Diff line number Diff line Loading @@ -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]) && Loading @@ -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]) && Loading @@ -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) { Loading Loading @@ -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; Loading Loading @@ -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; } Loading @@ -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; } Loading Loading @@ -1111,6 +1121,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 Loading @@ -1127,15 +1167,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; Loading media/libmedia/include/media/MediaProfiles.h +174 −80 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include <utils/threads.h> #include <media/mediarecorder.h> #include <vector> namespace android { enum camcorder_quality { Loading Loading @@ -97,6 +99,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. Loading Loading @@ -200,84 +372,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, Loading Loading @@ -363,8 +457,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); Loading Loading
media/libmedia/MediaProfiles.cpp +96 −56 Original line number Diff line number Diff line Loading @@ -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]) && Loading @@ -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]) && Loading @@ -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) { Loading Loading @@ -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; Loading Loading @@ -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; } Loading @@ -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; } Loading Loading @@ -1111,6 +1121,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 Loading @@ -1127,15 +1167,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; Loading
media/libmedia/include/media/MediaProfiles.h +174 −80 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include <utils/threads.h> #include <media/mediarecorder.h> #include <vector> namespace android { enum camcorder_quality { Loading Loading @@ -97,6 +99,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. Loading Loading @@ -200,84 +372,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, Loading Loading @@ -363,8 +457,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); Loading