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

Commit 9b6b97d7 authored by Praveen Chavan's avatar Praveen Chavan Committed by Linux Build Service Account
Browse files

stagefright: Move B-frame enablement to ACodec

Remove B-frames related code from OMXCodec since
MediaRecorder now uses ACodec.

Calculate nBFrames and nPFrames to configure requisite
number of B-Frames per P-Frame.

CRs-Fixed: 701344
Change-Id: I66f279f42ea79499e9e6b5c4f288ea82eb868dda
parent 2d0d1dfe
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@
#include <OMX_Component.h>
#include <OMX_IndexExt.h>

#include "include/ExtendedUtils.h"
#include "include/avc_utils.h"

#ifdef ENABLE_AV_ENHANCEMENTS
@@ -2471,6 +2472,7 @@ status_t ACodec::setupMPEG4EncoderParameters(const sp<AMessage> &msg) {
        mpeg4type.eProfile = static_cast<OMX_VIDEO_MPEG4PROFILETYPE>(profile);
        mpeg4type.eLevel = static_cast<OMX_VIDEO_MPEG4LEVELTYPE>(level);
    }
    ExtendedUtils::setBFrames(mpeg4type, mComponentName.c_str());

    err = mOMX->setParameter(
            mNode, OMX_IndexParamVideoMpeg4, &mpeg4type, sizeof(mpeg4type));
@@ -2706,6 +2708,8 @@ status_t ACodec::setupAVCEncoderParameters(const sp<AMessage> &msg) {
        h264type.bDirectSpatialTemporal = OMX_FALSE;
        h264type.nCabacInitIdc = 0;
    }
    ExtendedUtils::setBFrames(h264type, iFrameInterval,
            frameRate, mComponentName.c_str());

    if (h264type.nBFrames != 0) {
        h264type.nAllowedPictureTypes |= OMX_VIDEO_PictureTypeB;
+14 −18
Original line number Diff line number Diff line
@@ -148,24 +148,23 @@ bool ExtendedUtils::ShellProp::isSmoothStreamingEnabled() {
}

void ExtendedUtils::setBFrames(
        OMX_VIDEO_PARAM_MPEG4TYPE &mpeg4type, int32_t &numBFrames,
        const char* componentName) {
        OMX_VIDEO_PARAM_MPEG4TYPE &mpeg4type, const char* componentName) {
    //ignore non QC components
    if (strncmp(componentName, "OMX.qcom.", 9)) {
        return;
    }
    if (mpeg4type.eProfile > OMX_VIDEO_MPEG4ProfileSimple) {
        mpeg4type.nAllowedPictureTypes |= OMX_VIDEO_PictureTypeB;
        mpeg4type.nBFrames = 1;
        mpeg4type.nPFrames /= (mpeg4type.nBFrames + 1);
        numBFrames = mpeg4type.nBFrames;
        mpeg4type.nPFrames = (mpeg4type.nPFrames + kNumBFramesPerPFrame) /
                (kNumBFramesPerPFrame + 1);
        mpeg4type.nBFrames = mpeg4type.nPFrames * kNumBFramesPerPFrame;
    }
    return;
}

void ExtendedUtils::setBFrames(
        OMX_VIDEO_PARAM_AVCTYPE &h264type, int32_t &numBFrames,
        int32_t iFramesInterval, int32_t frameRate, const char* componentName) {
        OMX_VIDEO_PARAM_AVCTYPE &h264type, const int32_t iFramesInterval,
        const int32_t frameRate, const char* componentName) {
    //ignore non QC components
    if (strncmp(componentName, "OMX.qcom.", 9)) {
        return;
@@ -188,12 +187,13 @@ void ExtendedUtils::setBFrames(

    if (h264type.eProfile > OMX_VIDEO_AVCProfileBaseline) {
        h264type.nAllowedPictureTypes |= OMX_VIDEO_PictureTypeB;
        h264type.nBFrames = 1;
        h264type.nPFrames /= (h264type.nBFrames + 1);
        //enable CABAC as default entropy mode for Hihg/Main profiles
        h264type.nPFrames = (h264type.nPFrames + kNumBFramesPerPFrame) /
                (kNumBFramesPerPFrame + 1);
        h264type.nBFrames = h264type.nPFrames * kNumBFramesPerPFrame;

        //enable CABAC as default entropy mode for High/Main profiles
        h264type.bEntropyCodingCABAC = OMX_TRUE;
        h264type.nCabacInitIdc = 0;
        numBFrames = h264type.nBFrames;
    }
    return;
}
@@ -436,19 +436,15 @@ bool ExtendedUtils::ShellProp::isSmoothStreamingEnabled() {
}

void ExtendedUtils::setBFrames(
        OMX_VIDEO_PARAM_MPEG4TYPE &mpeg4type, int32_t &numBFrames,
        const char* componentName) {
        OMX_VIDEO_PARAM_MPEG4TYPE &mpeg4type, const char* componentName) {
    ARG_TOUCH(mpeg4type);
    ARG_TOUCH(numBFrames);
    ARG_TOUCH(componentName);
}

void ExtendedUtils::setBFrames(
        OMX_VIDEO_PARAM_AVCTYPE &h264type, int32_t &numBFrames,
        int32_t iFramesInterval, int32_t frameRate,
        const char* componentName) {
        OMX_VIDEO_PARAM_AVCTYPE &h264type, const int32_t iFramesInterval,
        const int32_t frameRate, const char* componentName) {
    ARG_TOUCH(h264type);
    ARG_TOUCH(numBFrames);
    ARG_TOUCH(iFramesInterval);
    ARG_TOUCH(frameRate);
    ARG_TOUCH(componentName);
+1 −6
Original line number Diff line number Diff line
@@ -1293,7 +1293,6 @@ status_t OMXCodec::setupMPEG4EncoderParameters(const sp<MetaData>& meta) {
    mpeg4type.eProfile = static_cast<OMX_VIDEO_MPEG4PROFILETYPE>(profileLevel.mProfile);
    mpeg4type.eLevel = static_cast<OMX_VIDEO_MPEG4LEVELTYPE>(profileLevel.mLevel);

    ExtendedUtils::setBFrames(mpeg4type, mNumBFrames, mComponentName);
    err = mOMX->setParameter(
            mNode, OMX_IndexParamVideoMpeg4, &mpeg4type, sizeof(mpeg4type));
    CHECK_EQ(err, (status_t)OK);
@@ -1332,9 +1331,7 @@ status_t OMXCodec::setupAVCEncoderParameters(const sp<MetaData>& meta) {
    h264type.eLevel = static_cast<OMX_VIDEO_AVCLEVELTYPE>(profileLevel.mLevel);

    // XXX
    if (ExtendedUtils::isAVCProfileSupported(h264type.eProfile)){
        ALOGI("Profile type is  %d ",h264type.eProfile);
    } else if (h264type.eProfile != OMX_VIDEO_AVCProfileBaseline) {
    if (h264type.eProfile != OMX_VIDEO_AVCProfileBaseline) {
        ALOGW("Use baseline profile instead of %d for AVC recording",
            h264type.eProfile);
        h264type.eProfile = OMX_VIDEO_AVCProfileBaseline;
@@ -1359,8 +1356,6 @@ status_t OMXCodec::setupAVCEncoderParameters(const sp<MetaData>& meta) {
        h264type.nCabacInitIdc = 0;
    }

    ExtendedUtils::setBFrames(
            h264type, mNumBFrames, iFramesInterval, frameRate, mComponentName);
    if (h264type.nBFrames != 0) {
        h264type.nAllowedPictureTypes |= OMX_VIDEO_PictureTypeB;
    }
+6 −3
Original line number Diff line number Diff line
@@ -68,13 +68,16 @@ struct ExtendedUtils {
        static int64_t getMaxAVSyncLateMargin();
    };

    static const int32_t kNumBFramesPerPFrame = 1;

    //set B frames for MPEG4
    static void setBFrames(OMX_VIDEO_PARAM_MPEG4TYPE &mpeg4type, int32_t &numBFrames,
    static void setBFrames(OMX_VIDEO_PARAM_MPEG4TYPE &mpeg4type,
            const char* componentName);

    //set B frames for H264
    static void setBFrames(OMX_VIDEO_PARAM_AVCTYPE &h264type, int32_t &numBFrames,
            int32_t iFramesInterval, int32_t frameRate, const char* componentName);
    static void setBFrames(OMX_VIDEO_PARAM_AVCTYPE &h264type,
            const int32_t iFramesInterval, const int32_t frameRate,
            const char* componentName);

    static bool UseQCHWAACEncoder(audio_encoder Encoder, int32_t Channel,
            int32_t BitRate, int32_t SampleRate);