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

Commit 7f475c34 authored by Andreas Huber's avatar Andreas Huber
Browse files

RTSP now properly publishes its "seekable" flags after connection

has successfully completed and only then signals that preparation is
complete.

Change-Id: I1a60f718e673fe1462c69369c40eafbed6a14326
parent b81b557d
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -1255,9 +1255,12 @@ void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
    switch (what) {
        case Source::kWhatPrepared:
        {
            int32_t err;
            CHECK(msg->findInt32("err", &err));

            sp<NuPlayerDriver> driver = mDriver.promote();
            if (driver != NULL) {
                driver->notifyPrepareCompleted(OK);
                driver->notifyPrepareCompleted(err);
            }
            break;
        }
@@ -1312,9 +1315,10 @@ void NuPlayer::Source::notifyVideoSizeChanged(int32_t width, int32_t height) {
    notify->post();
}

void NuPlayer::Source::notifyPrepared() {
void NuPlayer::Source::notifyPrepared(status_t err) {
    sp<AMessage> notify = dupNotify();
    notify->setInt32("what", kWhatPrepared);
    notify->setInt32("err", err);
    notify->post();
}

+13 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ namespace android {

NuPlayerDriver::NuPlayerDriver()
    : mState(STATE_IDLE),
      mIsAsyncPrepare(false),
      mAsyncResult(UNKNOWN_ERROR),
      mSetSurfaceInProgress(false),
      mDurationUs(-1),
@@ -160,6 +161,11 @@ status_t NuPlayerDriver::prepare_l() {
    switch (mState) {
        case STATE_UNPREPARED:
            mState = STATE_PREPARING;

            // Make sure we're not posting any notifications, success or
            // failure information is only communicated through our result
            // code.
            mIsAsyncPrepare = false;
            mPlayer->prepareAsync();
            while (mState == STATE_PREPARING) {
                mCondition.wait(mLock);
@@ -176,6 +182,7 @@ status_t NuPlayerDriver::prepareAsync() {
    switch (mState) {
        case STATE_UNPREPARED:
            mState = STATE_PREPARING;
            mIsAsyncPrepare = true;
            mPlayer->prepareAsync();
            return OK;
        default:
@@ -500,9 +507,14 @@ void NuPlayerDriver::notifyPrepareCompleted(status_t err) {
    mAsyncResult = err;

    if (err == OK) {
        if (mIsAsyncPrepare) {
            notifyListener(MEDIA_PREPARED);
        }
        mState = STATE_PREPARED;
    } else {
        if (mIsAsyncPrepare) {
            notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
        }
        mState = STATE_UNPREPARED;
    }

+1 −0
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ private:

    State mState;

    bool mIsAsyncPrepare;
    status_t mAsyncResult;

    // The following are protected through "mLock"
+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ protected:

    void notifyFlagsChanged(uint32_t flags);
    void notifyVideoSizeChanged(int32_t width, int32_t height);
    void notifyPrepared();
    void notifyPrepared(status_t err = OK);

private:
    sp<AMessage> mNotify;
+31 −10
Original line number Diff line number Diff line
@@ -96,16 +96,6 @@ void NuPlayer::RTSPSource::prepareAsync() {

        mHandler->connect();
    }

    notifyVideoSizeChanged(0, 0);

    notifyFlagsChanged(
            FLAG_CAN_PAUSE
            | FLAG_CAN_SEEK_BACKWARD
            | FLAG_CAN_SEEK_FORWARD
            | FLAG_CAN_SEEK);

    notifyPrepared();
}

void NuPlayer::RTSPSource::start() {
@@ -270,12 +260,31 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) {

    switch (what) {
        case MyHandler::kWhatConnected:
        {
            onConnected();

            notifyVideoSizeChanged(0, 0);

            uint32_t flags = 0;

            if (mHandler->isSeekable()) {
                flags = FLAG_CAN_PAUSE | FLAG_CAN_SEEK;

                // Seeking 10secs forward or backward is a very expensive
                // operation for rtsp, so let's not enable that.
                // The user can always use the seek bar.
            }

            notifyFlagsChanged(flags);
            notifyPrepared();
            break;
        }

        case MyHandler::kWhatDisconnected:
        {
            onDisconnected(msg);
            break;
        }

        case MyHandler::kWhatSeekDone:
        {
@@ -520,6 +529,12 @@ void NuPlayer::RTSPSource::onSDPLoaded(const sp<AMessage> &msg) {
    }

    if (err != OK) {
        if (mState == CONNECTING) {
            // We're still in the preparation phase, signal that it
            // failed.
            notifyPrepared(err);
        }

        mState = DISCONNECTED;
        mFinalResult = err;

@@ -537,6 +552,12 @@ void NuPlayer::RTSPSource::onDisconnected(const sp<AMessage> &msg) {
    mLooper->unregisterHandler(mHandler->id());
    mHandler.clear();

    if (mState == CONNECTING) {
        // We're still in the preparation phase, signal that it
        // failed.
        notifyPrepared(err);
    }

    mState = DISCONNECTED;
    mFinalResult = err;

Loading