diff options
author | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2016-01-14 22:14:14 +0100 |
---|---|---|
committer | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2016-01-14 22:14:14 +0100 |
commit | 998f3a696f0d671832624637c771e3bda3e0c9f5 (patch) | |
tree | 67c89508c2eaad57389ffac29d673a09bc8bfaba /media/libavextensions/stagefright | |
parent | 1c47b26b1ae695c355e4ec0c317716a397588206 (diff) | |
parent | 8ad656861c764ea4f8bf8539cb568b01edbf647d (diff) | |
download | frameworks_av-replicant-6.0-alpha-0001.zip frameworks_av-replicant-6.0-alpha-0001.tar.gz frameworks_av-replicant-6.0-alpha-0001.tar.bz2 |
Merge branch 'cm-13.0' of https://github.com/CyanogenMod/android_frameworks_av into replicant-6.0replicant-6.0-alpha-0001
Diffstat (limited to 'media/libavextensions/stagefright')
-rw-r--r-- | media/libavextensions/stagefright/AVExtensions.h | 70 | ||||
-rw-r--r-- | media/libavextensions/stagefright/AVUtils.cpp | 152 |
2 files changed, 217 insertions, 5 deletions
diff --git a/media/libavextensions/stagefright/AVExtensions.h b/media/libavextensions/stagefright/AVExtensions.h index f14d217..b0e4bb5 100644 --- a/media/libavextensions/stagefright/AVExtensions.h +++ b/media/libavextensions/stagefright/AVExtensions.h @@ -36,10 +36,10 @@ #include <media/mediarecorder.h> #include <media/IOMX.h> #include <media/AudioParameter.h> +#include <media/stagefright/MetaData.h> namespace android { -class MetaData; class MediaExtractor; class MPEG4Writer; struct ABuffer; @@ -153,15 +153,21 @@ struct AVUtils { uint64_t /*eAacProfile*/); virtual void extractCustomCameraKeys( - const CameraParameters& /*params*/, sp<MetaData> &/*meta*/) {} + const CameraParameters& /*params*/, sp<MetaData> &/*meta*/); virtual void printFileName(int /*fd*/) {} virtual void addDecodingTimesFromBatch(MediaBuffer * /*buf*/, List<int64_t> &/*decodeTimeQueue*/) {} virtual bool useQCHWEncoder(const sp<AMessage> &, AString &) { return false; } - virtual bool canDeferRelease(const sp<MetaData> &/*meta*/) { return false; } - virtual void setDeferRelease(sp<MetaData> &/*meta*/) {} + virtual bool canDeferRelease(const sp<MetaData> &meta) { + int32_t deferRelease = false; + return meta->findInt32(kKeyCanDeferRelease, &deferRelease) && deferRelease; + } + + virtual void setDeferRelease(sp<MetaData> &meta) { + meta->setInt32(kKeyCanDeferRelease, true); + } struct HEVCMuxer { @@ -226,12 +232,66 @@ struct AVUtils { int nPFrames, int nBFrames, const sp<IOMX> OMXhandle, IOMX::node_id nodeID); + /* + * This class is a placeholder for the set of methods used + * to enable HFR (High Frame Rate) Recording + * + * HFR is a slow-motion recording feature where framerate + * is increased at capture, but file is composed to play + * back at normal rate, giving a net result of slow-motion. + * If HFR factor = N + * framerate (at capture and encoder) = N * actual value + * bitrate = N * actual value + * (as the encoder still gets actual timestamps) + * timeStamps (at composition) = actual value + * timeScale (at composition) = actual value / N + * (when parser re-generates timestamps, they will be + * up-scaled by factor N, which results in slow-motion) + * + * HSR is a high-framerate recording variant where timestamps + * are not meddled with, yielding a video mux'ed at captured + * fps + */ + struct HFR { + // set kKeyHFR when 'video-hfr' paramater is enabled + // or set kKeyHSR when 'video-hsr' paramater is enabled + virtual void setHFRIfEnabled( + const CameraParameters& params, sp<MetaData> &meta); + + // recalculate file-duration when HFR is enabled + virtual status_t initializeHFR( + const sp<MetaData> &meta, sp<AMessage> &format, + int64_t &maxFileDurationUs, video_encoder videoEncoder); + + virtual void setHFRRatio( + sp<MetaData> &meta, const int32_t hfrRatio); + + virtual int32_t getHFRRatio( + const sp<MetaData> &meta); + + protected: + HFR() {}; + virtual ~HFR() {}; + friend struct AVUtils; + + private: + // Query supported capabilities from target-specific profiles + virtual int32_t getHFRCapabilities( + video_encoder codec, + int& maxHFRWidth, int& maxHFRHeight, int& maxHFRFps, + int& maxBitrate); + }; + virtual inline HFR& HFRUtils() { + return mHFR; + } + private: HEVCMuxer mHEVCMuxer; + HFR mHFR; // ----- NO TRESSPASSING BEYOND THIS LINE ------ DECLARE_LOADABLE_SINGLETON(AVUtils); -}; +}; } #endif // _AV_EXTENSIONS__H_ diff --git a/media/libavextensions/stagefright/AVUtils.cpp b/media/libavextensions/stagefright/AVUtils.cpp index 35ae36b..bdf5eb6 100644 --- a/media/libavextensions/stagefright/AVUtils.cpp +++ b/media/libavextensions/stagefright/AVUtils.cpp @@ -41,6 +41,7 @@ #include <media/stagefright/MediaCodec.h> #include <media/stagefright/MPEG4Writer.h> #include <media/stagefright/Utils.h> +#include <media/MediaProfiles.h> #if defined(QCOM_HARDWARE) || defined(FLAC_OFFLOAD_ENABLED) #include "QCMediaDefs.h" @@ -974,6 +975,157 @@ void AVUtils::setIntraPeriod( return; } +#ifdef QCOM_HARDWARE +void AVUtils::HFR::setHFRIfEnabled( + const CameraParameters& params, + sp<MetaData> &meta) { + const char *hfrParam = params.get("video-hfr"); + int32_t hfr = -1; + if (hfrParam != NULL) { + hfr = atoi(hfrParam); + if (hfr > 0) { + ALOGI("Enabling HFR @ %d fps", hfr); + meta->setInt32(kKeyHFR, hfr); + return; + } else { + ALOGI("Invalid HFR rate specified : %d", hfr); + } + } + + const char *hsrParam = params.get("video-hsr"); + int32_t hsr = -1; + if (hsrParam != NULL ) { + hsr = atoi(hsrParam); + if (hsr > 0) { + ALOGI("Enabling HSR @ %d fps", hsr); + meta->setInt32(kKeyHSR, hsr); + } else { + ALOGI("Invalid HSR rate specified : %d", hfr); + } + } +} + +status_t AVUtils::HFR::initializeHFR( + const sp<MetaData> &meta, sp<AMessage> &format, + int64_t & /*maxFileDurationUs*/, video_encoder videoEncoder) { + status_t retVal = OK; + + int32_t hsr = 0; + if (meta->findInt32(kKeyHSR, &hsr) && hsr > 0) { + ALOGI("HSR cue found. Override encode fps to %d", hsr); + format->setInt32("frame-rate", hsr); + return retVal; + } + + int32_t hfr = 0; + if (!meta->findInt32(kKeyHFR, &hfr) || (hfr <= 0)) { + ALOGW("Invalid HFR rate specified"); + return retVal; + } + + int32_t width = 0, height = 0; + CHECK(meta->findInt32(kKeyWidth, &width)); + CHECK(meta->findInt32(kKeyHeight, &height)); + + int maxW, maxH, MaxFrameRate, maxBitRate = 0; + if (getHFRCapabilities(videoEncoder, + maxW, maxH, MaxFrameRate, maxBitRate) < 0) { + ALOGE("Failed to query HFR target capabilities"); + return ERROR_UNSUPPORTED; + } + + if ((width * height * hfr) > (maxW * maxH * MaxFrameRate)) { + ALOGE("HFR request [%d x %d @%d fps] exceeds " + "[%d x %d @%d fps]. Will stay disabled", + width, height, hfr, maxW, maxH, MaxFrameRate); + return ERROR_UNSUPPORTED; + } + + int32_t frameRate = 0, bitRate = 0; + CHECK(meta->findInt32(kKeyFrameRate, &frameRate)); + CHECK(format->findInt32("bitrate", &bitRate)); + + if (frameRate) { + // scale the bitrate proportional to the hfr ratio + // to maintain quality, but cap it to max-supported. + bitRate = (hfr * bitRate) / frameRate; + bitRate = bitRate > maxBitRate ? maxBitRate : bitRate; + format->setInt32("bitrate", bitRate); + + int32_t hfrRatio = hfr / frameRate; + format->setInt32("frame-rate", hfr); + format->setInt32("hfr-ratio", hfrRatio); + } else { + ALOGE("HFR: Invalid framerate"); + return BAD_VALUE; + } + + return retVal; +} + +void AVUtils::HFR::setHFRRatio( + sp<MetaData> &meta, const int32_t hfrRatio) { + if (hfrRatio > 0) { + meta->setInt32(kKeyHFR, hfrRatio); + } +} + +int32_t AVUtils::HFR::getHFRRatio( + const sp<MetaData> &meta) { + int32_t hfrRatio = 0; + meta->findInt32(kKeyHFR, &hfrRatio); + return hfrRatio ? hfrRatio : 1; +} + +int32_t AVUtils::HFR::getHFRCapabilities( + video_encoder codec, + int& maxHFRWidth, int& maxHFRHeight, int& maxHFRFps, + int& maxBitRate) { + maxHFRWidth = maxHFRHeight = maxHFRFps = maxBitRate = 0; + MediaProfiles *profiles = MediaProfiles::getInstance(); + + if (profiles) { + maxHFRWidth = profiles->getVideoEncoderParamByName("enc.vid.hfr.width.max", codec); + maxHFRHeight = profiles->getVideoEncoderParamByName("enc.vid.hfr.height.max", codec); + maxHFRFps = profiles->getVideoEncoderParamByName("enc.vid.hfr.mode.max", codec); + maxBitRate = profiles->getVideoEncoderParamByName("enc.vid.bps.max", codec); + } + + return (maxHFRWidth > 0) && (maxHFRHeight > 0) && + (maxHFRFps > 0) && (maxBitRate > 0) ? 1 : -1; +} +#else +void AVUtils::HFR::setHFRIfEnabled( + const CameraParameters& /*params*/, + sp<MetaData> & /*meta*/) {} + +status_t AVUtils::HFR::initializeHFR( + const sp<MetaData> & /*meta*/, sp<AMessage> & /*format*/, + int64_t & /*maxFileDurationUs*/, video_encoder /*videoEncoder*/) { + return OK; +} + +void AVUtils::HFR::setHFRRatio( + sp<MetaData> & /*meta*/, const int32_t /*hfrRatio*/) {} + +int32_t AVUtils::HFR::getHFRRatio( + const sp<MetaData> & /*meta */) { + return 1; +} + +int32_t AVUtils::HFR::getHFRCapabilities( + video_encoder /*codec*/, + int& /*maxHFRWidth*/, int& /*maxHFRHeight*/, int& /*maxHFRFps*/, + int& /*maxBitRate*/) { + return -1; +} +#endif + +void AVUtils::extractCustomCameraKeys( + const CameraParameters& params, sp<MetaData> &meta) { + mHFR.setHFRIfEnabled(params, meta); +} + // ----- NO TRESSPASSING BEYOND THIS LINE ------ AVUtils::AVUtils() {} |