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
diff --git a/media/codec2/components/mpeg4_h263/C2SoftMpeg4Enc.cpp b/media/codec2/components/mpeg4_h263/C2SoftMpeg4Enc.cpp
index 95610fa..703033b 100644
--- a/media/codec2/components/mpeg4_h263/C2SoftMpeg4Enc.cpp
+++ b/media/codec2/components/mpeg4_h263/C2SoftMpeg4Enc.cpp
@@ -265,14 +265,16 @@
                 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
-            me.set().level = LEVEL_H263_40;
-#endif
         }
+#else
+        if (!found || (me.v.level != LEVEL_H263_45 && me.v.level > LEVEL_H263_40)) {
+            me.set().level = LEVEL_H263_40;
+        }
+#endif
         return C2R::Ok();
     }
 
@@ -288,18 +290,6 @@
         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 @@
     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 @@
         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) {
diff --git a/media/codec2/components/mpeg4_h263/C2SoftMpeg4Enc.h b/media/codec2/components/mpeg4_h263/C2SoftMpeg4Enc.h
index e5c8ea6..43461fc 100644
--- a/media/codec2/components/mpeg4_h263/C2SoftMpeg4Enc.h
+++ b/media/codec2/components/mpeg4_h263/C2SoftMpeg4Enc.h
@@ -65,7 +65,6 @@
     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;