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

Commit e726e56d authored by Ram Mohan's avatar Ram Mohan
Browse files

C2SoftMpeg4Enc: Let encoder library choose apt profile and level

Encoder libraries tends to adjusts the level information configured
to the necessary value if the configured value does not comply with
encoding settings. But aosp mpeg4/h263 enc fails from instantiation
when the configured profile and level information is not in accordance
with the encoding settings.

So, always configure the max profile and level supported and let
the library choose an apt profile and level to place in the bitstream.

Bug: 277528543
Test: atest android.mediav2.cts.EncoderProfileLevelTest \
      android.media.codec.cts.MediaCodecTest#testVendorParameters

Change-Id: I7a9359ff4417c36caa7780e30f558cadfb7289e7
parent d78c656e
Loading
Loading
Loading
Loading
+6 −17
Original line number Diff line number Diff line
@@ -265,14 +265,16 @@ class C2SoftMpeg4Enc::IntfImpl : public SimpleInterface<void>::BaseParams {
                needsUpdate = true;
            }
        }
        // If not found, set to the highest supported level.
        if (!found) {
        // If not found or exceeds max level, set to the highest supported level.
#ifdef MPEG4
        if (!found || me.v.level > LEVEL_MP4V_2) {
            me.set().level = LEVEL_MP4V_2;
        }
#else
        if (!found || (me.v.level != LEVEL_H263_45 && me.v.level > LEVEL_H263_40)) {
            me.set().level = LEVEL_H263_40;
#endif
        }
#endif
        return C2R::Ok();
    }

@@ -288,18 +290,6 @@ class C2SoftMpeg4Enc::IntfImpl : public SimpleInterface<void>::BaseParams {
        return (uint32_t)c2_max(c2_min(period + 0.5, double(UINT32_MAX)), 1.);
    }

    ProfileLevelType getProfileLevel_l() const {
#ifdef MPEG4
        if (mProfileLevel->level == LEVEL_MP4V_0) return SIMPLE_PROFILE_LEVEL0;
        else if (mProfileLevel->level == LEVEL_MP4V_1) return SIMPLE_PROFILE_LEVEL1;
        return SIMPLE_PROFILE_LEVEL2;  // level == LEVEL_MP4V_2
#else
        // library does not export h263 specific levels. No way to map C2 enums to
        // library specific constants. Return max supported level.
        return CORE_PROFILE_LEVEL2;
#endif
    }

   private:
    std::shared_ptr<C2StreamUsageTuning::input> mUsage;
    std::shared_ptr<C2StreamPictureSizeInfo::input> mSize;
@@ -416,7 +406,7 @@ c2_status_t C2SoftMpeg4Enc::initEncParams() {
    mEncParams->encFrameRate[0] = mFrameRate->value + 0.5;
    mEncParams->rcType = VBR_1;
    mEncParams->vbvDelay = VBV_DELAY;
    mEncParams->profile_level = mProfileLevel;
    mEncParams->profile_level = CORE_PROFILE_LEVEL2;
    mEncParams->packetSize = 32;
    mEncParams->rvlcEnable = PV_OFF;
    mEncParams->numLayers = 1;
@@ -457,7 +447,6 @@ c2_status_t C2SoftMpeg4Enc::initEncoder() {
        mSize = mIntf->getSize_l();
        mBitrate = mIntf->getBitrate_l();
        mFrameRate = mIntf->getFrameRate_l();
        mProfileLevel = mIntf->getProfileLevel_l();
    }
    c2_status_t err = initEncParams();
    if (C2_OK != err) {
+0 −1
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ private:
    std::shared_ptr<C2StreamPictureSizeInfo::input> mSize;
    std::shared_ptr<C2StreamFrameRateInfo::output> mFrameRate;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
    ProfileLevelType mProfileLevel;

    int64_t  mNumInputFrames;
    MP4EncodingMode mEncodeMode;