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

Commit b97e7d63 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "C2: Generate CSD in vp9 encoder" into main am: a4f686d4

parents ba028d56 a4f686d4
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -465,6 +465,7 @@ C2SoftVpxEnc::C2SoftVpxEnc(const char* name, c2_node_id_t id,
      mTemporalPatternIdx(0),
      mLastTimestamp(0x7FFFFFFFFFFFFFFFull),
      mSignalledOutputEos(false),
      mHeaderGenerated(false),
      mSignalledError(false) {
    for (int i = 0; i < MAXTEMPORALLAYERS; i++) {
        mTemporalLayerBitrateRatio[i] = 1.0f;
@@ -494,6 +495,7 @@ void C2SoftVpxEnc::onRelease() {

    // this one is not allocated by us
    mCodecInterface = nullptr;
    mHeaderGenerated = false;
}

c2_status_t C2SoftVpxEnc::onStop() {
@@ -558,6 +560,7 @@ status_t C2SoftVpxEnc::initEncoder() {
          (uint32_t)mBitrateControlMode, mTemporalLayers, mIntf->getSyncFramePeriod(),
          mMinQuantizer, mMaxQuantizer);

    mHeaderGenerated = false;
    mCodecConfiguration = new vpx_codec_enc_cfg_t;
    if (!mCodecConfiguration) goto CleanUp;
    codec_return = vpx_codec_enc_config_default(mCodecInterface,
@@ -873,6 +876,27 @@ void C2SoftVpxEnc::process(
        return;
    }

    // Header generation is limited to Android V and above, as MediaMuxer did not handle
    // CSD for VP9 correctly in Android U and before.
    if (isAtLeastV() && !mHeaderGenerated) {
        vpx_fixed_buf_t* codec_private_data = vpx_codec_get_global_headers(mCodecContext);
        if (codec_private_data) {
            std::unique_ptr<C2StreamInitDataInfo::output> csd =
                    C2StreamInitDataInfo::output::AllocUnique(codec_private_data->sz, 0u);
            if (!csd) {
                ALOGE("CSD allocation failed");
                mSignalledError = true;
                work->result = C2_NO_MEMORY;
                work->workletsProcessed = 1u;
                return;
            }
            memcpy(csd->m.value, codec_private_data->buf, codec_private_data->sz);
            work->worklets.front()->output.configUpdate.push_back(std::move(csd));
            ALOGV("CSD Produced of size %zu bytes", codec_private_data->sz);
        }
        mHeaderGenerated = true;
    }

    const C2ConstGraphicBlock inBuffer =
        inputBuffer->data().graphicBlocks().front();
    if (inBuffer.width() < mSize->width ||
+3 −0
Original line number Diff line number Diff line
@@ -207,6 +207,9 @@ struct C2SoftVpxEnc : public SimpleC2Component {
     // Signalled EOS
     bool mSignalledOutputEos;

     // Header generated
     bool mHeaderGenerated;

     // Signalled Error
     bool mSignalledError;