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

Commit 1f24b30f authored by Andreas Huber's avatar Andreas Huber
Browse files

Support "pausing" of MediaSources with the effect that they no longer pull on...

Support "pausing" of MediaSources with the effect that they no longer pull on their upstream source until a subsequent read-with-seek.

Change-Id: Ie4153a10ab36c1135f5fcfb572958129d886bcc3
parent 66b89a62
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include <sys/types.h>

#include <media/stagefright/MediaErrors.h>
#include <utils/RefBase.h>

namespace android {
@@ -83,6 +84,13 @@ struct MediaSource : public RefBase {
        int64_t mLatenessUs;
    };

    // Causes this source to suspend pulling data from its upstream source
    // until a subsequent read-with-seek. Currently only supported by
    // OMXCodec.
    virtual status_t pause() {
        return ERROR_UNSUPPORTED;
    }

protected:
    virtual ~MediaSource();

+4 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ struct OMXCodec : public MediaSource,
    virtual status_t read(
            MediaBuffer **buffer, const ReadOptions *options = NULL);

    virtual status_t pause();

    void on_message(const omx_message &msg);

    // from MediaBufferObserver
@@ -144,6 +146,8 @@ private:
    Mutex mLock;
    Condition mAsyncCompletion;

    bool mPaused;

    // A list of indices into mPortStatus[kPortIndexOutput] filled with data.
    List<size_t> mFilledBuffers;
    Condition mBufferFilled;
+19 −1
Original line number Diff line number Diff line
@@ -1145,7 +1145,8 @@ OMXCodec::OMXCodec(
      mNoMoreOutputData(false),
      mOutputPortSettingsHaveChanged(false),
      mSeekTimeUs(-1),
      mLeftOverBuffer(NULL) {
      mLeftOverBuffer(NULL),
      mPaused(false) {
    mPortStatus[kPortIndexInput] = ENABLED;
    mPortStatus[kPortIndexOutput] = ENABLED;

@@ -1735,6 +1736,9 @@ void OMXCodec::onCmdComplete(OMX_COMMANDTYPE cmd, OMX_U32 data) {
                    CODEC_LOGV("Finished flushing both ports, now continuing from"
                         " seek-time.");

                    // We implicitly resume pulling on our upstream source.
                    mPaused = false;

                    drainInputBuffers();
                    fillOutputBuffers();
                }
@@ -2034,6 +2038,10 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) {
        return;
    }

    if (mPaused) {
        return;
    }

    status_t err;

    bool signalEOS = false;
@@ -2554,6 +2562,7 @@ status_t OMXCodec::start(MetaData *) {
    mOutputPortSettingsHaveChanged = false;
    mSeekTimeUs = -1;
    mFilledBuffers.clear();
    mPaused = false;

    return init();
}
@@ -2660,6 +2669,7 @@ status_t OMXCodec::read(
            // There's no reason to trigger the code below, there's
            // nothing to flush yet.
            seeking = false;
            mPaused = false;
        }

        drainInputBuffers();
@@ -3220,6 +3230,14 @@ void OMXCodec::initOutputFormat(const sp<MetaData> &inputFormat) {
    }
}

status_t OMXCodec::pause() {
    Mutex::Autolock autoLock(mLock);

    mPaused = true;

    return OK;
}

////////////////////////////////////////////////////////////////////////////////

status_t QueryCodecs(