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

Commit 3359c672 authored by Ray Essick's avatar Ray Essick Committed by android-build-merger
Browse files

Rework NuPlayer::getStats() synchronization

am: fcb8fd35

Change-Id: I9e8a5da50f1cab16daba29475f52beb3c127a213
parents 34e09e4a fcb8fd35
Loading
Loading
Loading
Loading
+13 −29
Original line number Diff line number Diff line
@@ -1120,6 +1120,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
            } else if (what == DecoderBase::kWhatShutdownCompleted) {
                ALOGV("%s shutdown completed", audio ? "audio" : "video");
                if (audio) {
                    Mutex::Autolock autoLock(mDecoderLock);
                    mAudioDecoder.clear();
                    mAudioDecoderError = false;
                    ++mAudioDecoderGeneration;
@@ -1127,6 +1128,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
                    CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER);
                    mFlushingAudio = SHUT_DOWN;
                } else {
                    Mutex::Autolock autoLock(mDecoderLock);
                    mVideoDecoder.clear();
                    mVideoDecoderError = false;
                    ++mVideoDecoderGeneration;
@@ -1447,29 +1449,6 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
            break;
        }

        case kWhatGetStats:
        {
            ALOGV("kWhatGetStats");

            Vector<sp<AMessage>> *trackStats;
            CHECK(msg->findPointer("trackstats", (void**)&trackStats));

            trackStats->clear();
            if (mVideoDecoder != NULL) {
                trackStats->push_back(mVideoDecoder->getStats());
            }
            if (mAudioDecoder != NULL) {
                trackStats->push_back(mAudioDecoder->getStats());
            }

            // respond for synchronization
            sp<AMessage> response = new AMessage;
            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));
            response->postReply(replyID);
            break;
        }

        default:
            TRESPASS();
            break;
@@ -1817,6 +1796,7 @@ void NuPlayer::restartAudio(
          (long long)currentPositionUs, forceNonOffload, needsToCreateAudioDecoder);
    if (mAudioDecoder != NULL) {
        mAudioDecoder->pause();
        Mutex::Autolock autoLock(mDecoderLock);
        mAudioDecoder.clear();
        mAudioDecoderError = false;
        ++mAudioDecoderGeneration;
@@ -1935,6 +1915,8 @@ status_t NuPlayer::instantiateDecoder(
        }
    }

    Mutex::Autolock autoLock(mDecoderLock);

    if (audio) {
        sp<AMessage> notify = new AMessage(kWhatAudioNotify, this);
        ++mAudioDecoderGeneration;
@@ -2236,13 +2218,15 @@ status_t NuPlayer::getCurrentPosition(int64_t *mediaUs) {
void NuPlayer::getStats(Vector<sp<AMessage> > *trackStats) {
    CHECK(trackStats != NULL);

    ALOGV("NuPlayer::getStats()");
    sp<AMessage> msg = new AMessage(kWhatGetStats, this);
    msg->setPointer("trackstats", trackStats);
    trackStats->clear();

    sp<AMessage> response;
    (void) msg->postAndAwaitResponse(&response);
    // response is for synchronization, ignore contents
    Mutex::Autolock autoLock(mDecoderLock);
    if (mVideoDecoder != NULL) {
        trackStats->push_back(mVideoDecoder->getStats());
    }
    if (mAudioDecoder != NULL) {
        trackStats->push_back(mAudioDecoder->getStats());
    }
}

sp<MetaData> NuPlayer::getFileMeta() {
+1 −1
Original line number Diff line number Diff line
@@ -159,7 +159,6 @@ private:
        kWhatPrepareDrm                 = 'pDrm',
        kWhatReleaseDrm                 = 'rDrm',
        kWhatMediaClockNotify           = 'mckN',
        kWhatGetStats                   = 'gSts',
    };

    wp<NuPlayerDriver> mDriver;
@@ -175,6 +174,7 @@ private:
    sp<DecoderBase> mVideoDecoder;
    bool mOffloadAudio;
    sp<DecoderBase> mAudioDecoder;
    Mutex mDecoderLock;  // guard |mAudioDecoder| and |mVideoDecoder|.
    sp<CCDecoder> mCCDecoder;
    sp<Renderer> mRenderer;
    sp<ALooper> mRendererLooper;