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

Commit aab2eea3 authored by Wonsik Kim's avatar Wonsik Kim
Browse files

CCodec: add max B frames support

Bug: 127315857
Test: screenrecord --codec-name c2.android.avc.encoder --bframes 1 /sdcard/a.mp4
Change-Id: Id0f6cf618767b3b23e11122f7abee2d5b125d59c
parent 88665c48
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1644,6 +1644,7 @@ constexpr char C2_PARAMKEY_PICTURE_TYPE[] = "coded.picture-type";
 * frames.
 */
struct C2GopLayerStruct {
    C2GopLayerStruct() : type_((C2Config::picture_type_t)0), count(0) {}
    C2GopLayerStruct(C2Config::picture_type_t type, uint32_t count_)
        : type_(type), count(count_) { }

+21 −0
Original line number Diff line number Diff line
@@ -766,6 +766,11 @@ void CCodec::configure(const sp<AMessage> &msg) {
                    ALOGD("I frame interval is missing, which is required for video encoders.");
                    return BAD_VALUE;
                }
                if (!msg->findInt32(KEY_FRAME_RATE, &i32)
                        && !msg->findFloat(KEY_FRAME_RATE, &flt)) {
                    ALOGD("frame rate is missing, which is required for video encoders.");
                    return BAD_VALUE;
                }
            }
        }

@@ -849,6 +854,22 @@ void CCodec::configure(const sp<AMessage> &msg) {
        if (err != OK) {
            ALOGW("failed to convert configuration to c2 params");
        }

        int32_t maxBframes = 0;
        if ((config->mDomain & Config::IS_ENCODER)
                && (config->mDomain & Config::IS_VIDEO)
                && sdkParams->findInt32(KEY_MAX_B_FRAMES, &maxBframes)
                && maxBframes > 0) {
            std::unique_ptr<C2StreamGopTuning::output> gop =
                C2StreamGopTuning::output::AllocUnique(2 /* flexCount */, 0u /* stream */);
            gop->m.values[0] = { P_FRAME, UINT32_MAX };
            gop->m.values[1] = {
                C2Config::picture_type_t(P_FRAME | B_FRAME),
                uint32_t(maxBframes)
            };
            configUpdate.push_back(std::move(gop));
        }

        err = config->setParameters(comp, configUpdate, C2_DONT_BLOCK);
        if (err != OK) {
            ALOGW("failed to configure c2 params");