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

Commit cbe2964f authored by Lajos Molnar's avatar Lajos Molnar Committed by Android Git Automerger
Browse files

am 96beb91b: am 17d0efd1: Merge "stagefright: remove workaround for BQ not...

am 96beb91b: am 17d0efd1: Merge "stagefright: remove workaround for BQ not reporting dropped frames" into mnc-dev

* commit '96beb91b':
  stagefright: remove workaround for BQ not reporting dropped frames
parents 4d3ff58b 96beb91b
Loading
Loading
Loading
Loading
+3 −5
Original line number Original line Diff line number Diff line
@@ -136,7 +136,6 @@ protected:
private:
private:
    enum {
    enum {
        kWhatDrainVideo = 'dVid',
        kWhatDrainVideo = 'dVid',
        kWhatCheckFrameAvailable = 'cFrA',
    };
    };


    // This is a thin wrapper class that lets us listen to
    // This is a thin wrapper class that lets us listen to
@@ -248,9 +247,8 @@ private:
    // onBufferReleasedByOutput releases a buffer back to the input.
    // onBufferReleasedByOutput releases a buffer back to the input.
    void onFrameAvailableFromInput();
    void onFrameAvailableFromInput();


    // Send |bufferItem| to the output for rendering. If this is not the only
    // Send |bufferItem| to the output for rendering.
    // buffer sent for rendering, check for any dropped frames in |checkInUs| us.
    void renderOneBufferItem_l(const BufferItem &bufferItem);
    void renderOneBufferItem_l(const BufferItem &bufferItem, int64_t checkInUs);


    // This implements the onBufferReleased callback from IProducerListener.
    // This implements the onBufferReleased callback from IProducerListener.
    // It gets called from an OutputListener.
    // It gets called from an OutputListener.
+26 −45
Original line number Original line Diff line number Diff line
@@ -558,8 +558,7 @@ void MediaSync::onDrainVideo_l() {


        // adjust video frame PTS based on vsync
        // adjust video frame PTS based on vsync
        itemRealUs = mFrameScheduler->schedule(itemRealUs * 1000) / 1000;
        itemRealUs = mFrameScheduler->schedule(itemRealUs * 1000) / 1000;
        int64_t oneVsyncUs = (mFrameScheduler->getVsyncPeriod() / 1000);
        int64_t twoVsyncsUs = 2 * (mFrameScheduler->getVsyncPeriod() / 1000);
        int64_t twoVsyncsUs = oneVsyncUs * 2;


        // post 2 display refreshes before rendering is due
        // post 2 display refreshes before rendering is due
        if (itemRealUs <= nowUs + twoVsyncsUs) {
        if (itemRealUs <= nowUs + twoVsyncsUs) {
@@ -570,7 +569,7 @@ void MediaSync::onDrainVideo_l() {


            if (mHasAudio) {
            if (mHasAudio) {
                if (nowUs - itemRealUs <= kMaxAllowedVideoLateTimeUs) {
                if (nowUs - itemRealUs <= kMaxAllowedVideoLateTimeUs) {
                    renderOneBufferItem_l(*bufferItem, nowUs + oneVsyncUs - itemRealUs);
                    renderOneBufferItem_l(*bufferItem);
                } else {
                } else {
                    // too late.
                    // too late.
                    returnBufferToInput_l(
                    returnBufferToInput_l(
@@ -579,7 +578,7 @@ void MediaSync::onDrainVideo_l() {
                }
                }
            } else {
            } else {
                // always render video buffer in video-only mode.
                // always render video buffer in video-only mode.
                renderOneBufferItem_l(*bufferItem, nowUs + oneVsyncUs - itemRealUs);
                renderOneBufferItem_l(*bufferItem);


                // smooth out videos >= 10fps
                // smooth out videos >= 10fps
                mMediaClock->updateAnchor(
                mMediaClock->updateAnchor(
@@ -613,7 +612,7 @@ void MediaSync::onFrameAvailableFromInput() {
    while (mNumOutstandingBuffers > mMaxAcquiredBufferCount
    while (mNumOutstandingBuffers > mMaxAcquiredBufferCount
            && !mIsAbandoned && !mReturnPendingInputFrame) {
            && !mIsAbandoned && !mReturnPendingInputFrame) {
        if (mReleaseCondition.waitRelative(mMutex, kAcquireWaitTimeout) != OK) {
        if (mReleaseCondition.waitRelative(mMutex, kAcquireWaitTimeout) != OK) {
            ALOGI("still waiting to release a buffer before acquire");
            ALOGI_IF(mPlaybackRate != 0.f, "still waiting to release a buffer before acquire");
        }
        }


        // If the sync is abandoned while we are waiting, the release
        // If the sync is abandoned while we are waiting, the release
@@ -670,7 +669,7 @@ void MediaSync::onFrameAvailableFromInput() {
    }
    }
}
}


void MediaSync::renderOneBufferItem_l(const BufferItem &bufferItem, int64_t checkInUs) {
void MediaSync::renderOneBufferItem_l(const BufferItem &bufferItem) {
    IGraphicBufferProducer::QueueBufferInput queueInput(
    IGraphicBufferProducer::QueueBufferInput queueInput(
            bufferItem.mTimestamp,
            bufferItem.mTimestamp,
            bufferItem.mIsAutoTimestamp,
            bufferItem.mIsAutoTimestamp,
@@ -710,12 +709,6 @@ void MediaSync::renderOneBufferItem_l(const BufferItem &bufferItem, int64_t chec
    mBuffersSentToOutput.add(bufferItem.mGraphicBuffer->getId(), bufferItem.mGraphicBuffer);
    mBuffersSentToOutput.add(bufferItem.mGraphicBuffer->getId(), bufferItem.mGraphicBuffer);


    ALOGV("queued buffer %#llx to output", (long long)bufferItem.mGraphicBuffer->getId());
    ALOGV("queued buffer %#llx to output", (long long)bufferItem.mGraphicBuffer->getId());

    // If we have already queued more than one buffer, check for any free buffers in case
    // one of them were dropped - as BQ does not signal onBufferReleased in that case.
    if (mBuffersSentToOutput.size() > 1) {
        (new AMessage(kWhatCheckFrameAvailable, this))->post(checkInUs);
    }
}
}


void MediaSync::onBufferReleasedByOutput(sp<IGraphicBufferProducer> &output) {
void MediaSync::onBufferReleasedByOutput(sp<IGraphicBufferProducer> &output) {
@@ -727,12 +720,7 @@ void MediaSync::onBufferReleasedByOutput(sp<IGraphicBufferProducer> &output) {


    sp<GraphicBuffer> buffer;
    sp<GraphicBuffer> buffer;
    sp<Fence> fence;
    sp<Fence> fence;
    status_t status;
    status_t status = mOutput->detachNextBuffer(&buffer, &fence);
    // NOTE: This is a workaround for a BufferQueue bug where onBufferReleased is
    // called only for released buffers, but not for buffers that were dropped during
    // acquire. Dropped buffers can still be detached as they are on the free list.
    // TODO: remove if released callback happens also for dropped buffers
    while ((status = mOutput->detachNextBuffer(&buffer, &fence)) != NO_MEMORY) {
    ALOGE_IF(status != NO_ERROR, "detaching buffer from output failed (%d)", status);
    ALOGE_IF(status != NO_ERROR, "detaching buffer from output failed (%d)", status);


    if (status == NO_INIT) {
    if (status == NO_INIT) {
@@ -759,7 +747,6 @@ void MediaSync::onBufferReleasedByOutput(sp<IGraphicBufferProducer> &output) {


    returnBufferToInput_l(buffer, fence);
    returnBufferToInput_l(buffer, fence);
}
}
}


void MediaSync::returnBufferToInput_l(
void MediaSync::returnBufferToInput_l(
        const sp<GraphicBuffer> &buffer, const sp<Fence> &fence) {
        const sp<GraphicBuffer> &buffer, const sp<Fence> &fence) {
@@ -829,12 +816,6 @@ void MediaSync::onMessageReceived(const sp<AMessage> &msg) {
            break;
            break;
        }
        }


        case kWhatCheckFrameAvailable:
        {
            onBufferReleasedByOutput(mOutput);
            break;
        }

        default:
        default:
            TRESPASS();
            TRESPASS();
            break;
            break;