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

Commit ef3dbdbf authored by Dongwon Kang's avatar Dongwon Kang Committed by Android (Google) Code Review
Browse files

Merge "Add OnMediaTimeDiscontinuity notification" into pi-dev

parents eba668ad 47afe0a1
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -59,6 +59,7 @@ enum media_event_type {
    MEDIA_SUBTITLE_DATA     = 201,
    MEDIA_SUBTITLE_DATA     = 201,
    MEDIA_META_DATA         = 202,
    MEDIA_META_DATA         = 202,
    MEDIA_DRM_INFO          = 210,
    MEDIA_DRM_INFO          = 210,
    MEDIA_TIME_DISCONTINUITY = 211,
    MEDIA_AUDIO_ROUTING_CHANGED = 10000,
    MEDIA_AUDIO_ROUTING_CHANGED = 10000,
};
};


+22 −1
Original line number Original line Diff line number Diff line
@@ -220,8 +220,11 @@ void NuPlayer::setUID(uid_t uid) {
    mUID = uid;
    mUID = uid;
}
}


void NuPlayer::setDriver(const wp<NuPlayerDriver> &driver) {
void NuPlayer::init(const wp<NuPlayerDriver> &driver) {
    mDriver = driver;
    mDriver = driver;

    sp<AMessage> notify = new AMessage(kWhatMediaClockNotify, this);
    mMediaClock->setNotificationMessage(notify);
}
}


void NuPlayer::setDataSourceAsync(const sp<IStreamSource> &source) {
void NuPlayer::setDataSourceAsync(const sp<IStreamSource> &source) {
@@ -1425,6 +1428,24 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
            break;
            break;
        }
        }


        case kWhatMediaClockNotify:
        {
            ALOGV("kWhatMediaClockNotify");
            int64_t anchorMediaUs, anchorRealUs;
            float playbackRate;
            CHECK(msg->findInt64("anchor-media-us", &anchorMediaUs));
            CHECK(msg->findInt64("anchor-real-us", &anchorRealUs));
            CHECK(msg->findFloat("playback-rate", &playbackRate));

            Parcel in;
            in.writeInt64(anchorMediaUs);
            in.writeInt64(anchorRealUs);
            in.writeFloat(playbackRate);

            notifyListener(MEDIA_TIME_DISCONTINUITY, 0, 0, &in);
            break;
        }

        default:
        default:
            TRESPASS();
            TRESPASS();
            break;
            break;
+2 −1
Original line number Original line Diff line number Diff line
@@ -39,7 +39,7 @@ struct NuPlayer : public AHandler {


    void setUID(uid_t uid);
    void setUID(uid_t uid);


    void setDriver(const wp<NuPlayerDriver> &driver);
    void init(const wp<NuPlayerDriver> &driver);


    void setDataSourceAsync(const sp<IStreamSource> &source);
    void setDataSourceAsync(const sp<IStreamSource> &source);


@@ -158,6 +158,7 @@ private:
        kWhatSetBufferingSettings       = 'sBuS',
        kWhatSetBufferingSettings       = 'sBuS',
        kWhatPrepareDrm                 = 'pDrm',
        kWhatPrepareDrm                 = 'pDrm',
        kWhatReleaseDrm                 = 'rDrm',
        kWhatReleaseDrm                 = 'rDrm',
        kWhatMediaClockNotify           = 'mckN',
    };
    };


    wp<NuPlayerDriver> mDriver;
    wp<NuPlayerDriver> mDriver;
+1 −1
Original line number Original line Diff line number Diff line
@@ -104,7 +104,7 @@ NuPlayerDriver::NuPlayerDriver(pid_t pid)


    mLooper->registerHandler(mPlayer);
    mLooper->registerHandler(mPlayer);


    mPlayer->setDriver(this);
    mPlayer->init(this);
}
}


NuPlayerDriver::~NuPlayerDriver() {
NuPlayerDriver::~NuPlayerDriver() {
+34 −12
Original line number Original line Diff line number Diff line
@@ -70,11 +70,9 @@ void MediaClock::reset() {
        it->mNotify->post();
        it->mNotify->post();
        it = mTimers.erase(it);
        it = mTimers.erase(it);
    }
    }
    mAnchorTimeMediaUs = -1;
    mAnchorTimeRealUs = -1;
    mMaxTimeMediaUs = INT64_MAX;
    mMaxTimeMediaUs = INT64_MAX;
    mStartingTimeMediaUs = -1;
    mStartingTimeMediaUs = -1;
    mPlaybackRate = 1.0;
    updateAnchorTimesAndPlaybackRate_l(-1, -1, 1.0);
    ++mGeneration;
    ++mGeneration;
}
}


@@ -85,8 +83,7 @@ void MediaClock::setStartingTimeMedia(int64_t startingTimeMediaUs) {


void MediaClock::clearAnchor() {
void MediaClock::clearAnchor() {
    Mutex::Autolock autoLock(mLock);
    Mutex::Autolock autoLock(mLock);
    mAnchorTimeMediaUs = -1;
    updateAnchorTimesAndPlaybackRate_l(-1, -1, mPlaybackRate);
    mAnchorTimeRealUs = -1;
}
}


void MediaClock::updateAnchor(
void MediaClock::updateAnchor(
@@ -118,8 +115,7 @@ void MediaClock::updateAnchor(
            return;
            return;
        }
        }
    }
    }
    mAnchorTimeRealUs = nowUs;
    updateAnchorTimesAndPlaybackRate_l(nowMediaUs, nowUs, mPlaybackRate);
    mAnchorTimeMediaUs = nowMediaUs;


    ++mGeneration;
    ++mGeneration;
    processTimers_l();
    processTimers_l();
@@ -139,13 +135,12 @@ void MediaClock::setPlaybackRate(float rate) {
    }
    }


    int64_t nowUs = ALooper::GetNowUs();
    int64_t nowUs = ALooper::GetNowUs();
    mAnchorTimeMediaUs += (nowUs - mAnchorTimeRealUs) * (double)mPlaybackRate;
    int64_t nowMediaUs = mAnchorTimeMediaUs + (nowUs - mAnchorTimeRealUs) * (double)mPlaybackRate;
    if (mAnchorTimeMediaUs < 0) {
    if (nowMediaUs < 0) {
        ALOGW("setRate: anchor time should not be negative, set to 0.");
        ALOGW("setRate: anchor time should not be negative, set to 0.");
        mAnchorTimeMediaUs = 0;
        nowMediaUs = 0;
    }
    }
    mAnchorTimeRealUs = nowUs;
    updateAnchorTimesAndPlaybackRate_l(nowMediaUs, nowUs, rate);
    mPlaybackRate = rate;


    if (rate > 0.0) {
    if (rate > 0.0) {
        ++mGeneration;
        ++mGeneration;
@@ -313,4 +308,31 @@ void MediaClock::processTimers_l() {
    msg->post(nextLapseRealUs);
    msg->post(nextLapseRealUs);
}
}


void MediaClock::updateAnchorTimesAndPlaybackRate_l(int64_t anchorTimeMediaUs,
        int64_t anchorTimeRealUs, float playbackRate) {
    if (mAnchorTimeMediaUs != anchorTimeMediaUs
            || mAnchorTimeRealUs != anchorTimeRealUs
            || mPlaybackRate != playbackRate) {
        mAnchorTimeMediaUs = anchorTimeMediaUs;
        mAnchorTimeRealUs = anchorTimeRealUs;
        mPlaybackRate = playbackRate;
        notifyDiscontinuity_l();
    }
}

void MediaClock::setNotificationMessage(const sp<AMessage> &msg) {
    Mutex::Autolock autoLock(mLock);
    mNotify = msg;
}

void MediaClock::notifyDiscontinuity_l() {
    if (mNotify != nullptr) {
        sp<AMessage> msg = mNotify->dup();
        msg->setInt64("anchor-media-us", mAnchorTimeMediaUs);
        msg->setInt64("anchor-real-us", mAnchorTimeRealUs);
        msg->setFloat("playback-rate", mPlaybackRate);
        msg->post();
    }
}

}  // namespace android
}  // namespace android
Loading