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

Commit fe1322b9 authored by Chong Zhang's avatar Chong Zhang Committed by Android (Google) Code Review
Browse files

Merge "Notify GraphicBufferSource to disable framedrop logic" into pi-dev

parents 55c07b0d 6c2d0add
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -567,7 +567,7 @@ ACodec::ACodec()
      mMetadataBuffersToSubmit(0),
      mNumUndequeuedBuffers(0),
      mRepeatFrameDelayUs(-1ll),
      mMaxPtsGapUs(-1ll),
      mMaxPtsGapUs(0ll),
      mMaxFps(-1),
      mFps(-1.0),
      mCaptureFps(-1.0),
@@ -1823,16 +1823,21 @@ status_t ACodec::configureCodec(

        // only allow 32-bit value, since we pass it as U32 to OMX.
        if (!msg->findInt64("max-pts-gap-to-encoder", &mMaxPtsGapUs)) {
            mMaxPtsGapUs = -1ll;
        } else if (mMaxPtsGapUs > INT32_MAX || mMaxPtsGapUs < 0) {
            mMaxPtsGapUs = 0ll;
        } else if (mMaxPtsGapUs > INT32_MAX || mMaxPtsGapUs < INT32_MIN) {
            ALOGW("Unsupported value for max pts gap %lld", (long long) mMaxPtsGapUs);
            mMaxPtsGapUs = -1ll;
            mMaxPtsGapUs = 0ll;
        }

        if (!msg->findFloat("max-fps-to-encoder", &mMaxFps)) {
            mMaxFps = -1;
        }

        // notify GraphicBufferSource to allow backward frames
        if (mMaxPtsGapUs < 0ll) {
            mMaxFps = -1;
        }

        if (!msg->findDouble("time-lapse-fps", &mCaptureFps)) {
            mCaptureFps = -1.0;
        }
@@ -6686,7 +6691,7 @@ status_t ACodec::LoadedState::setupInputSurface() {
        }
    }

    if (mCodec->mMaxPtsGapUs > 0ll) {
    if (mCodec->mMaxPtsGapUs != 0ll) {
        OMX_PARAM_U32TYPE maxPtsGapParams;
        InitOMXParams(&maxPtsGapParams);
        maxPtsGapParams.nPortIndex = kPortIndexInput;
@@ -6703,7 +6708,7 @@ status_t ACodec::LoadedState::setupInputSurface() {
        }
    }

    if (mCodec->mMaxFps > 0) {
    if (mCodec->mMaxFps > 0 || mCodec->mMaxPtsGapUs < 0) {
        err = statusFromBinderStatus(
                mCodec->mGraphicBufferSource->setMaxFps(mCodec->mMaxFps));

+6 −1
Original line number Diff line number Diff line
@@ -34,7 +34,12 @@ FrameDropper::~FrameDropper() {
}

status_t FrameDropper::setMaxFrameRate(float maxFrameRate) {
    if (maxFrameRate <= 0) {
    if (maxFrameRate < 0) {
        mMinIntervalUs = -1ll;
        return OK;
    }

    if (maxFrameRate == 0) {
        ALOGE("framerate should be positive but got %f.", maxFrameRate);
        return BAD_VALUE;
    }
+11 −4
Original line number Diff line number Diff line
@@ -786,11 +786,17 @@ bool GraphicBufferSource::calculateCodecTimestamp_l(
                static_cast<long long>(mPrevFrameUs));
    } else {
        if (timeUs <= mPrevFrameUs) {
            if (mFrameDropper != NULL && mFrameDropper->disabled()) {
                // Warn only, client has disabled frame drop logic possibly for image
                // encoding cases where camera's ZSL mode could send out of order frames.
                ALOGW("Received frame that's going backward in time");
            } else {
                // Drop the frame if it's going backward in time. Bad timestamp
                // could disrupt encoder's rate control completely.
                ALOGW("Dropping frame that's going backward in time");
                return false;
            }
        }

        mPrevFrameUs = timeUs;
    }
@@ -1110,6 +1116,7 @@ status_t GraphicBufferSource::configure(
        mEndOfStream = false;
        mEndOfStreamSent = false;
        mSkipFramesBeforeNs = -1ll;
        mFrameDropper.clear();
        mFrameRepeatIntervalUs = -1ll;
        mRepeatLastFrameGeneration = 0;
        mOutstandingFrameRepeatCount = 0;
+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,9 @@ struct FrameDropper : public RefBase {
    // Returns false if max frame rate has not been set via setMaxFrameRate.
    bool shouldDrop(int64_t timeUs);

    // Returns true if all frame drop logic should be disabled.
    bool disabled() { return (mMinIntervalUs == -1ll); }

protected:
    virtual ~FrameDropper();

+15 −1
Original line number Diff line number Diff line
@@ -149,7 +149,21 @@ public:
    // When set, the sample's timestamp will be adjusted with the timeOffsetUs.
    status_t setTimeOffsetUs(int64_t timeOffsetUs);

    // When set, the max frame rate fed to the encoder will be capped at maxFps.
    /*
     * Set the maximum frame rate on the source.
     *
     * When maxFps is a positive number, it indicates the maximum rate at which
     * the buffers from this source will be sent to the encoder. Excessive
     * frames will be dropped to meet the frame rate requirement.
     *
     * When maxFps is a negative number, any frame drop logic will be disabled
     * and all frames from this source will be sent to the encoder, even when
     * the timestamp goes backwards. Note that some components may still drop
     * out-of-order frames silently, so this usually has to be used in
     * conjunction with OMXNodeInstance::setMaxPtsGapUs() workaround.
     *
     * When maxFps is 0, this call will fail with BAD_VALUE.
     */
    status_t setMaxFps(float maxFps);

    // Sets the time lapse (or slow motion) parameters.
Loading