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

Commit 212765f2 authored by Wei Jia's avatar Wei Jia Committed by Android (Google) Code Review
Browse files

Merge "mediaplayer: support dynamic playback rate"

parents 7c4820d2 9816016a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ public:
    virtual status_t        stop() = 0;
    virtual status_t        pause() = 0;
    virtual status_t        isPlaying(bool* state) = 0;
    virtual status_t        setPlaybackRate(float rate) = 0;
    virtual status_t        seekTo(int msec) = 0;
    virtual status_t        getCurrentPosition(int* msec) = 0;
    virtual status_t        getDuration(int* msec) = 0;
+1 −0
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ public:
    virtual status_t    stop() = 0;
    virtual status_t    pause() = 0;
    virtual bool        isPlaying() = 0;
    virtual status_t    setPlaybackRate(float rate) { return INVALID_OPERATION; }
    virtual status_t    seekTo(int msec) = 0;
    virtual status_t    getCurrentPosition(int *msec) = 0;
    virtual status_t    getDuration(int *msec) = 0;
+2 −0
Original line number Diff line number Diff line
@@ -220,6 +220,7 @@ public:
            status_t        stop();
            status_t        pause();
            bool            isPlaying();
            status_t        setPlaybackRate(float rate);
            status_t        getVideoWidth(int *w);
            status_t        getVideoHeight(int *h);
            status_t        seekTo(int msec);
@@ -274,6 +275,7 @@ private:
    int                         mVideoWidth;
    int                         mVideoHeight;
    int                         mAudioSessionId;
    float                       mPlaybackRate;
    float                       mSendLevel;
    struct sockaddr_in          mRetransmitEndpoint;
    bool                        mRetransmitEndpointValid;
+15 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ enum {
    START,
    STOP,
    IS_PLAYING,
    SET_PLAYBACK_RATE,
    PAUSE,
    SEEK_TO,
    GET_CURRENT_POSITION,
@@ -164,6 +165,15 @@ public:
        return reply.readInt32();
    }

    status_t setPlaybackRate(float rate)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
        data.writeFloat(rate);
        remote()->transact(SET_PLAYBACK_RATE, data, &reply);
        return reply.readInt32();
    }

    status_t pause()
    {
        Parcel data, reply;
@@ -426,6 +436,11 @@ status_t BnMediaPlayer::onTransact(
            reply->writeInt32(ret);
            return NO_ERROR;
        } break;
        case SET_PLAYBACK_RATE: {
            CHECK_INTERFACE(IMediaPlayer, data, reply);
            reply->writeInt32(setPlaybackRate(data.readFloat()));
            return NO_ERROR;
        } break;
        case PAUSE: {
            CHECK_INTERFACE(IMediaPlayer, data, reply);
            reply->writeInt32(pause());
+19 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ MediaPlayer::MediaPlayer()
    mLoop = false;
    mLeftVolume = mRightVolume = 1.0;
    mVideoWidth = mVideoHeight = 0;
    mPlaybackRate = 1.0;
    mLockThreadId = 0;
    mAudioSessionId = AudioSystem::newAudioUniqueId();
    AudioSystem::acquireAudioSessionId(mAudioSessionId, -1);
@@ -378,6 +379,24 @@ bool MediaPlayer::isPlaying()
    return false;
}

status_t MediaPlayer::setPlaybackRate(float rate)
{
    ALOGV("setPlaybackRate: %f", rate);
    if (rate <= 0.0) {
        return BAD_VALUE;
    }
    Mutex::Autolock _l(mLock);
    if (mPlayer != 0) {
        if (mPlaybackRate == rate) {
            return NO_ERROR;
        }
        mPlaybackRate = rate;
        return mPlayer->setPlaybackRate(rate);
    }
    ALOGV("setPlaybackRate: no active player");
    return INVALID_OPERATION;
}

status_t MediaPlayer::getVideoWidth(int *w)
{
    ALOGV("getVideoWidth");
Loading