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

Commit 30c08634 authored by Johann's avatar Johann
Browse files

Change VP8 encoder bitrate

Allow the bitrate to be updated while the encoder is running.

Bug: 8422347
Change-Id: I8427fe20921b00f92b8f99fe21691709fab354b0
parent 465da60d
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ SoftVPXEncoder::SoftVPXEncoder(const char *name,
      mWidth(176),
      mHeight(144),
      mBitrate(192000),  // in bps
      mBitrateUpdated(false),
      mBitrateControlMode(VPX_VBR),  // variable bitrate
      mFrameDurationUs(33333),  // Defaults to 30 fps
      mDCTPartitions(0),
@@ -536,6 +537,22 @@ OMX_ERRORTYPE SoftVPXEncoder::setConfig(
            return OMX_ErrorNone;
        }

        case OMX_IndexConfigVideoBitrate:
        {
            OMX_VIDEO_CONFIG_BITRATETYPE *params =
                (OMX_VIDEO_CONFIG_BITRATETYPE *)_params;

            if (params->nPortIndex != kOutputPortIndex) {
                return OMX_ErrorBadPortIndex;
            }

            if (mBitrate != params->nEncodeBitrate) {
                mBitrate = params->nEncodeBitrate;
                mBitrateUpdated = true;
            }
            return OMX_ErrorNone;
        }

        default:
            return SimpleSoftOMXComponent::setConfig(index, _params);
    }
@@ -779,6 +796,21 @@ void SoftVPXEncoder::onQueueFilled(OMX_U32 portIndex) {
            mKeyFrameRequested = false;
        }

        if (mBitrateUpdated) {
            mCodecConfiguration->rc_target_bitrate = mBitrate/1000;
            vpx_codec_err_t res = vpx_codec_enc_config_set(mCodecContext,
                                                           mCodecConfiguration);
            if (res != VPX_CODEC_OK) {
                ALOGE("vp8 encoder failed to update bitrate: %s",
                      vpx_codec_err_to_string(res));
                notify(OMX_EventError,
                       OMX_ErrorUndefined,
                       0, // Extra notification data
                       NULL); // Notification data pointer
            }
            mBitrateUpdated = false;
        }

        codec_return = vpx_codec_encode(
                mCodecContext,
                &raw_frame,
+4 −1
Original line number Diff line number Diff line
@@ -128,7 +128,10 @@ private:
    int32_t mHeight;

    // Target bitrate set for the encoder, in bits per second.
    int32_t mBitrate;
    uint32_t mBitrate;

    // If a request for a change it bitrate has been received.
    bool mBitrateUpdated;

    // Bitrate control mode, either constant or variable
    vpx_rc_mode mBitrateControlMode;