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

Commit 0d98c180 authored by Ray Essick's avatar Ray Essick
Browse files

Improve tracking of 'playing time' metrics

Some field records sometimes showed non-zero frames played, but zero
playback time; a combination that should not be possible. Tracked to
alternate exit conditions that didn't go through the existing 'update
the stat here'.  Now managing time at some other identified possible
paths for playback exit.

Bug: 68273679
Test: manual video playback
Change-Id: I196120c49ec92d2e30d53a6e9eed9c60f1b8f2a7
parent dd97f52b
Loading
Loading
Loading
Loading
+37 −9
Original line number Diff line number Diff line
@@ -182,6 +182,7 @@ NuPlayer::NuPlayer(pid_t pid, const sp<MediaClock> &mediaClock)
      mAudioDecoderGeneration(0),
      mVideoDecoderGeneration(0),
      mRendererGeneration(0),
      mLastStartedPlayingTimeNs(0),
      mPreviousSeekTimeUs(0),
      mAudioEOS(false),
      mVideoEOS(false),
@@ -1309,6 +1310,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
            ALOGV("kWhatReset");

            mResetting = true;
            stopPlaybackTimer("kWhatReset");

            mDeferredActions.push_back(
                    new FlushDecoderAction(
@@ -1449,7 +1451,7 @@ void NuPlayer::onResume() {
        ALOGW("resume called when renderer is gone or not set");
    }

    mLastStartedPlayingTimeNs = systemTime();
    startPlaybackTimer("onresume");
}

status_t NuPlayer::onInstantiateSecureDecoders() {
@@ -1569,12 +1571,43 @@ void NuPlayer::onStart(int64_t startPositionUs, MediaPlayerSeekMode mode) {
        mAudioDecoder->setRenderer(mRenderer);
    }

    mLastStartedPlayingTimeNs = systemTime();
    startPlaybackTimer("onstart");

    postScanSources();
}

void NuPlayer::startPlaybackTimer(const char *where) {
    Mutex::Autolock autoLock(mPlayingTimeLock);
    if (mLastStartedPlayingTimeNs == 0) {
        mLastStartedPlayingTimeNs = systemTime();
        ALOGV("startPlaybackTimer() time %20" PRId64 " (%s)",  mLastStartedPlayingTimeNs, where);
    }
}

void NuPlayer::stopPlaybackTimer(const char *where) {
    Mutex::Autolock autoLock(mPlayingTimeLock);

    ALOGV("stopPlaybackTimer()  time %20" PRId64 " (%s)", mLastStartedPlayingTimeNs, where);

    if (mLastStartedPlayingTimeNs != 0) {
        sp<NuPlayerDriver> driver = mDriver.promote();
        if (driver != NULL) {
            int64_t now = systemTime();
            int64_t played = now - mLastStartedPlayingTimeNs;
            ALOGV("stopPlaybackTimer()  log  %20" PRId64 "", played);

            if (played > 0) {
                driver->notifyMorePlayingTimeUs((played+500)/1000);
            }
        }
        mLastStartedPlayingTimeNs = 0;
    }
}

void NuPlayer::onPause() {

    stopPlaybackTimer("onPause");

    if (mPaused) {
        return;
    }
@@ -1590,13 +1623,6 @@ void NuPlayer::onPause() {
        ALOGW("pause called when renderer is gone or not set");
    }

    sp<NuPlayerDriver> driver = mDriver.promote();
    if (driver != NULL) {
        int64_t now = systemTime();
        int64_t played = now - mLastStartedPlayingTimeNs;

        driver->notifyMorePlayingTimeUs((played+500)/1000);
    }
}

bool NuPlayer::audioDecoderStillNeeded() {
@@ -2223,6 +2249,8 @@ void NuPlayer::performReset() {
    CHECK(mAudioDecoder == NULL);
    CHECK(mVideoDecoder == NULL);

    stopPlaybackTimer("performReset");

    cancelPollDuration();

    ++mScanSourcesGeneration;
+3 −0
Original line number Diff line number Diff line
@@ -178,7 +178,10 @@ private:
    int32_t mVideoDecoderGeneration;
    int32_t mRendererGeneration;

    Mutex mPlayingTimeLock;
    int64_t mLastStartedPlayingTimeNs;
    void stopPlaybackTimer(const char *where);
    void startPlaybackTimer(const char *where);

    int64_t mPreviousSeekTimeUs;