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

Commit f888cedf authored by xiaoqiny's avatar xiaoqiny Committed by Steve Kondik
Browse files

libstagefright: handle error when B-frame is sent to MPEG4Writer

Without this patch, writing B-frame to MediaMuxer will be blocked and
cannot return a result. This may cause an endless progress bar shown in
gallery when triming or muting some videos.

Change-Id: Ib9f902a57da470c0357ec68aab00a35fbb26fb77
CRs-Fixed: 521005
parent 0ecd6fb6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -56,6 +56,8 @@ public:
    // deep copy, such that after pushBuffer return, the buffer can be re-used.
    status_t pushBuffer(MediaBuffer *buffer);

    virtual void notifyError(status_t err);

private:
    Mutex mAdapterLock;
    // Make sure the read() wait for the incoming buffer.
@@ -68,6 +70,8 @@ private:
    bool mStarted;
    sp<MetaData> mOutputFormat;

    status_t mStatus;

    DISALLOW_EVIL_CONSTRUCTORS(MediaAdapter);
};

+1 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ protected:
private:
    friend class MediaBufferGroup;
    friend class OMXDecoder;
    friend class MediaAdapter;

    // For use by OMXDecoder, reference count must be 1, drop reference
    // count to 0 without signalling the observer.
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ struct MediaSource : public virtual RefBase {
    virtual status_t read(
            MediaBuffer **buffer, const ReadOptions *options = NULL) = 0;

    virtual void notifyError(status_t) {}
    // Options that modify read() behaviour. The default is to
    // a) not request a seek
    // b) not be late, i.e. lateness_us = 0
+3 −1
Original line number Diff line number Diff line
@@ -2452,7 +2452,9 @@ status_t MPEG4Writer::Track::threadEntry() {
            ALOGE("timestampUs %" PRId64 " < lastTimestampUs %" PRId64 " for %s track",
                timestampUs, lastTimestampUs, trackName);
            copy->release();
            return UNKNOWN_ERROR;
            err = UNKNOWN_ERROR;
            mSource->notifyError(err);
            return err;
        }

        // if the duration is different for this sample, see if it is close enough to the previous
+16 −2
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ namespace android {
MediaAdapter::MediaAdapter(const sp<MetaData> &meta)
    : mCurrentMediaBuffer(NULL),
      mStarted(false),
      mOutputFormat(meta) {
      mOutputFormat(meta),
      mStatus(OK) {
}

MediaAdapter::~MediaAdapter() {
@@ -51,6 +52,9 @@ status_t MediaAdapter::stop() {
        // If stop() happens immediately after a pushBuffer(), we should
        // clean up the mCurrentMediaBuffer
        if (mCurrentMediaBuffer != NULL) {
            mCurrentMediaBuffer->setObserver(this);
            mCurrentMediaBuffer->claim();
            mCurrentMediaBuffer->setObserver(0);
            mCurrentMediaBuffer->release();
            mCurrentMediaBuffer = NULL;
        }
@@ -113,13 +117,23 @@ status_t MediaAdapter::pushBuffer(MediaBuffer *buffer) {
        ALOGE("pushBuffer called before start");
        return INVALID_OPERATION;
    }
    if (mStatus != OK) {
        ALOGE("pushBuffer called when MediaAdapter in error status");
        return mStatus;
    }
    mCurrentMediaBuffer = buffer;
    mBufferReadCond.signal();

    ALOGV("wait for the buffer returned @ pushBuffer! %p", buffer);
    mBufferReturnedCond.wait(mAdapterLock);

    return OK;
    return mStatus;
}

void MediaAdapter::notifyError(status_t err) {
    Mutex::Autolock autoLock(mAdapterLock);
    mStatus = err;
    mBufferReturnedCond.signal();
}

}  // namespace android