From de1e368d8ac5891e03e664a0ea385b896b48db0b Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Tue, 5 Jan 2016 15:21:14 -0800 Subject: stagefright: Forward-port HFR and HSR support * CAF commit bd42a7ac3a60c0d8a079b4567484c9b006bac8ad upstream Change-Id: I457ccab603647f3139ea2199a544f64ac3d1a214 --- media/libavextensions/stagefright/AVUtils.cpp | 125 ++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) (limited to 'media/libavextensions/stagefright/AVUtils.cpp') diff --git a/media/libavextensions/stagefright/AVUtils.cpp b/media/libavextensions/stagefright/AVUtils.cpp index 35ae36b..298434f 100644 --- a/media/libavextensions/stagefright/AVUtils.cpp +++ b/media/libavextensions/stagefright/AVUtils.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #if defined(QCOM_HARDWARE) || defined(FLAC_OFFLOAD_ENABLED) #include "QCMediaDefs.h" @@ -974,6 +975,130 @@ void AVUtils::setIntraPeriod( return; } +void AVUtils::HFR::setHFRIfEnabled( + const CameraParameters& params, + sp &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 &meta, sp &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 &meta, const int32_t hfrRatio) { + if (hfrRatio > 0) { + meta->setInt32(kKeyHFR, hfrRatio); + } +} + +int32_t AVUtils::HFR::getHFRRatio( + const sp &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; +} + +void AVUtils::extractCustomCameraKeys( + const CameraParameters& params, sp &meta) { + mHFR.setHFRIfEnabled(params, meta); +} + // ----- NO TRESSPASSING BEYOND THIS LINE ------ AVUtils::AVUtils() {} -- cgit v1.1 From 81955306d4d9465b12528da1e56c17eb938e7564 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Tue, 5 Jan 2016 16:20:37 -0800 Subject: stagefright: Only include HFR/HSR on QCOM devices Change-Id: Ib98c9c94cccc902708d25a9b8d81bc54fd6bbf7c --- media/libavextensions/stagefright/AVUtils.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'media/libavextensions/stagefright/AVUtils.cpp') diff --git a/media/libavextensions/stagefright/AVUtils.cpp b/media/libavextensions/stagefright/AVUtils.cpp index 298434f..bdf5eb6 100644 --- a/media/libavextensions/stagefright/AVUtils.cpp +++ b/media/libavextensions/stagefright/AVUtils.cpp @@ -975,6 +975,7 @@ void AVUtils::setIntraPeriod( return; } +#ifdef QCOM_HARDWARE void AVUtils::HFR::setHFRIfEnabled( const CameraParameters& params, sp &meta) { @@ -1093,6 +1094,32 @@ int32_t AVUtils::HFR::getHFRCapabilities( return (maxHFRWidth > 0) && (maxHFRHeight > 0) && (maxHFRFps > 0) && (maxBitRate > 0) ? 1 : -1; } +#else +void AVUtils::HFR::setHFRIfEnabled( + const CameraParameters& /*params*/, + sp & /*meta*/) {} + +status_t AVUtils::HFR::initializeHFR( + const sp & /*meta*/, sp & /*format*/, + int64_t & /*maxFileDurationUs*/, video_encoder /*videoEncoder*/) { + return OK; +} + +void AVUtils::HFR::setHFRRatio( + sp & /*meta*/, const int32_t /*hfrRatio*/) {} + +int32_t AVUtils::HFR::getHFRRatio( + const sp & /*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 &meta) { -- cgit v1.1