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

Commit 67b6dccf authored by Wei Jia's avatar Wei Jia
Browse files

mediaplayer: add precise argument to seek function

Test: compiles
Bug: 32557491
Change-Id: Id8c3a938edd5a0b34a9b33e86a4dbff32cf10c98
parent 2aa19a96
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public:
    virtual status_t        setSyncSettings(const AVSyncSettings& sync, float videoFpsHint) = 0;
    virtual status_t        getSyncSettings(AVSyncSettings* sync /* nonnull */,
                                            float* videoFps /* nonnull */) = 0;
    virtual status_t        seekTo(int msec) = 0;
    virtual status_t        seekTo(int msec, bool precise = false) = 0;
    virtual status_t        getCurrentPosition(int* msec) = 0;
    virtual status_t        getDuration(int* msec) = 0;
    virtual status_t        reset() = 0;
+1 −1
Original line number Diff line number Diff line
@@ -205,7 +205,7 @@ public:
        *videoFps = -1.f;
        return OK;
    }
    virtual status_t    seekTo(int msec) = 0;
    virtual status_t    seekTo(int msec, bool precise = false) = 0;
    virtual status_t    getCurrentPosition(int *msec) = 0;
    virtual status_t    getDuration(int *msec) = 0;
    virtual status_t    reset() = 0;
+4 −2
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ public:
                                    float* videoFps /* nonnull */);
            status_t        getVideoWidth(int *w);
            status_t        getVideoHeight(int *h);
            status_t        seekTo(int msec);
            status_t        seekTo(int msec, bool precise = false);
            status_t        getCurrentPosition(int *msec);
            status_t        getDuration(int *msec);
            status_t        reset();
@@ -257,7 +257,7 @@ public:

private:
            void            clear_l();
            status_t        seekTo_l(int msec);
            status_t        seekTo_l(int msec, bool precise);
            status_t        prepareAsync_l();
            status_t        getDuration_l(int *msec);
            status_t        attachNewPlayer(const sp<IMediaPlayer>& player);
@@ -274,7 +274,9 @@ private:
    void*                       mCookie;
    media_player_states         mCurrentState;
    int                         mCurrentPosition;
    bool                        mCurrentSeekPrecise;
    int                         mSeekPosition;
    int                         mSeekPrecise;
    bool                        mPrepareSync;
    status_t                    mPrepareStatus;
    audio_stream_type_t         mStreamType;
+5 −2
Original line number Diff line number Diff line
@@ -246,11 +246,12 @@ public:
        return reply.readInt32();
    }

    status_t seekTo(int msec)
    status_t seekTo(int msec, bool precise)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
        data.writeInt32(msec);
        data.writeBool(precise);
        remote()->transact(SEEK_TO, data, &reply);
        return reply.readInt32();
    }
@@ -573,7 +574,9 @@ status_t BnMediaPlayer::onTransact(
        } break;
        case SEEK_TO: {
            CHECK_INTERFACE(IMediaPlayer, data, reply);
            reply->writeInt32(seekTo(data.readInt32()));
            int msec = data.readInt32();
            bool precise = data.readBool();
            reply->writeInt32(seekTo(msec, precise));
            return NO_ERROR;
        } break;
        case GET_CURRENT_POSITION: {
+17 −9
Original line number Diff line number Diff line
@@ -55,7 +55,9 @@ MediaPlayer::MediaPlayer()
    mStreamType = AUDIO_STREAM_MUSIC;
    mAudioAttributesParcel = NULL;
    mCurrentPosition = -1;
    mCurrentSeekPrecise = false;
    mSeekPosition = -1;
    mSeekPrecise = false;
    mCurrentState = MEDIA_PLAYER_IDLE;
    mPrepareSync = false;
    mPrepareStatus = NO_ERROR;
@@ -100,7 +102,9 @@ void MediaPlayer::disconnect()
void MediaPlayer::clear_l()
{
    mCurrentPosition = -1;
    mCurrentSeekPrecise = false;
    mSeekPosition = -1;
    mSeekPrecise = false;
    mVideoWidth = mVideoHeight = 0;
    mRetransmitEndpointValid = false;
}
@@ -508,9 +512,9 @@ status_t MediaPlayer::getDuration(int *msec)
    return getDuration_l(msec);
}

status_t MediaPlayer::seekTo_l(int msec)
status_t MediaPlayer::seekTo_l(int msec, bool precise)
{
    ALOGV("seekTo %d", msec);
    ALOGV("seekTo (%d, %d)", msec, precise);
    if ((mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED |
            MEDIA_PLAYER_PAUSED |  MEDIA_PLAYER_PLAYBACK_COMPLETE) ) ) {
        if ( msec < 0 ) {
@@ -537,12 +541,14 @@ status_t MediaPlayer::seekTo_l(int msec)

        // cache duration
        mCurrentPosition = msec;
        mCurrentSeekPrecise = precise;
        if (mSeekPosition < 0) {
            mSeekPosition = msec;
            return mPlayer->seekTo(msec);
            mSeekPrecise = precise;
            return mPlayer->seekTo(msec, precise);
        }
        else {
            ALOGV("Seek in progress - queue up seekTo[%d]", msec);
            ALOGV("Seek in progress - queue up seekTo[%d, %d]", msec, precise);
            return NO_ERROR;
        }
    }
@@ -551,11 +557,11 @@ status_t MediaPlayer::seekTo_l(int msec)
    return INVALID_OPERATION;
}

status_t MediaPlayer::seekTo(int msec)
status_t MediaPlayer::seekTo(int msec, bool precise)
{
    mLockThreadId = getThreadId();
    Mutex::Autolock _l(mLock);
    status_t result = seekTo_l(msec);
    status_t result = seekTo_l(msec, precise);
    mLockThreadId = 0;

    return result;
@@ -869,14 +875,16 @@ void MediaPlayer::notify(int msg, int ext1, int ext2, const Parcel *obj)
        break;
    case MEDIA_SEEK_COMPLETE:
        ALOGV("Received seek complete");
        if (mSeekPosition != mCurrentPosition) {
            ALOGV("Executing queued seekTo(%d)", mSeekPosition);
        if (mSeekPosition != mCurrentPosition || (!mSeekPrecise && mCurrentSeekPrecise)) {
            ALOGV("Executing queued seekTo(%d, %d)", mCurrentPosition, mCurrentSeekPrecise);
            mSeekPosition = -1;
            seekTo_l(mCurrentPosition);
            mSeekPrecise = false;
            seekTo_l(mCurrentPosition, mCurrentSeekPrecise);
        }
        else {
            ALOGV("All seeks complete - return to regularly scheduled program");
            mCurrentPosition = mSeekPosition = -1;
            mCurrentSeekPrecise = mSeekPrecise = false;
        }
        break;
    case MEDIA_BUFFERING_UPDATE:
Loading