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

Commit 96bcfca0 authored by Xin Li's avatar Xin Li Committed by Automerger Merge Worker
Browse files

Merge "Merge QQ3A.200805.001" am: 05dd1900

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/1389219

Change-Id: I312820d88ac612d5d09951388485cb750a85c7ef
parents 588d9b1c 05dd1900
Loading
Loading
Loading
Loading
+58 −28
Original line number Original line Diff line number Diff line
@@ -118,6 +118,7 @@ NuPlayerDriver::~NuPlayerDriver() {
    updateMetrics("destructor");
    updateMetrics("destructor");
    logMetrics("destructor");
    logMetrics("destructor");


    Mutex::Autolock autoLock(mMetricsLock);
    if (mAnalyticsItem != NULL) {
    if (mAnalyticsItem != NULL) {
        delete mAnalyticsItem;
        delete mAnalyticsItem;
        mAnalyticsItem = NULL;
        mAnalyticsItem = NULL;
@@ -131,6 +132,8 @@ status_t NuPlayerDriver::initCheck() {
status_t NuPlayerDriver::setUID(uid_t uid) {
status_t NuPlayerDriver::setUID(uid_t uid) {
    mPlayer->setUID(uid);
    mPlayer->setUID(uid);
    mClientUid = uid;
    mClientUid = uid;

    Mutex::Autolock autoLock(mMetricsLock);
    if (mAnalyticsItem) {
    if (mAnalyticsItem) {
        mAnalyticsItem->setUid(mClientUid);
        mAnalyticsItem->setUid(mClientUid);
    }
    }
@@ -544,10 +547,46 @@ void NuPlayerDriver::updateMetrics(const char *where) {
    }
    }
    ALOGV("updateMetrics(%p) from %s at state %d", this, where, mState);
    ALOGV("updateMetrics(%p) from %s at state %d", this, where, mState);


    // gather the final stats for this record
    // gather the final track statistics for this record
    Vector<sp<AMessage>> trackStats;
    Vector<sp<AMessage>> trackStats;
    mPlayer->getStats(&trackStats);
    mPlayer->getStats(&trackStats);


    // getDuration() uses mLock
    int duration_ms = -1;
    getDuration(&duration_ms);
    mAnalyticsItem->setInt64(kPlayerDuration, duration_ms);

    mPlayer->updateInternalTimers();

    int64_t playingTimeUs;
    int64_t rebufferingTimeUs;
    int32_t rebufferingEvents;
    bool rebufferingAtExit;
    {
        Mutex::Autolock autoLock(mLock);

        playingTimeUs = mPlayingTimeUs;
        rebufferingTimeUs = mRebufferingTimeUs;
        rebufferingEvents = mRebufferingEvents;
        rebufferingAtExit = mRebufferingAtExit;
    }

    // finish the rest of the gathering holding mLock;
    // some of the fields we read are updated under mLock.
    // we also avoid any races within mAnalyticsItem machinery
    Mutex::Autolock autoLock(mMetricsLock);

    mAnalyticsItem->setInt64(kPlayerPlaying, (playingTimeUs+500)/1000 );

    if (mRebufferingEvents != 0) {
        mAnalyticsItem->setInt64(kPlayerRebuffering, (rebufferingTimeUs+500)/1000 );
        mAnalyticsItem->setInt32(kPlayerRebufferingCount, rebufferingEvents);
        mAnalyticsItem->setInt32(kPlayerRebufferingAtExit, rebufferingAtExit);

     }

    mAnalyticsItem->setCString(kPlayerDataSourceType, mPlayer->getDataSourceType());

    if (trackStats.size() > 0) {
    if (trackStats.size() > 0) {
        for (size_t i = 0; i < trackStats.size(); ++i) {
        for (size_t i = 0; i < trackStats.size(); ++i) {
            const sp<AMessage> &stats = trackStats.itemAt(i);
            const sp<AMessage> &stats = trackStats.itemAt(i);
@@ -592,26 +631,6 @@ void NuPlayerDriver::updateMetrics(const char *where) {
            }
            }
        }
        }
    }
    }

    // always provide duration and playing time, even if they have 0/unknown values.

    // getDuration() uses mLock for mutex -- careful where we use it.
    int duration_ms = -1;
    getDuration(&duration_ms);
    mAnalyticsItem->setInt64(kPlayerDuration, duration_ms);

    mPlayer->updateInternalTimers();

    mAnalyticsItem->setInt64(kPlayerPlaying, (mPlayingTimeUs+500)/1000 );

    if (mRebufferingEvents != 0) {
        mAnalyticsItem->setInt64(kPlayerRebuffering, (mRebufferingTimeUs+500)/1000 );
        mAnalyticsItem->setInt32(kPlayerRebufferingCount, mRebufferingEvents);
        mAnalyticsItem->setInt32(kPlayerRebufferingAtExit, mRebufferingAtExit);

    }

    mAnalyticsItem->setCString(kPlayerDataSourceType, mPlayer->getDataSourceType());
}
}




@@ -621,6 +640,9 @@ void NuPlayerDriver::logMetrics(const char *where) {
    }
    }
    ALOGV("logMetrics(%p) from %s at state %d", this, where, mState);
    ALOGV("logMetrics(%p) from %s at state %d", this, where, mState);


    // make sure that the stats are stable while we're writing them.
    Mutex::Autolock autoLock(mMetricsLock);

    if (mAnalyticsItem == NULL || mAnalyticsItem->isEnabled() == false) {
    if (mAnalyticsItem == NULL || mAnalyticsItem->isEnabled() == false) {
        return;
        return;
    }
    }
@@ -779,11 +801,16 @@ status_t NuPlayerDriver::setParameter(


status_t NuPlayerDriver::getParameter(int key, Parcel *reply) {
status_t NuPlayerDriver::getParameter(int key, Parcel *reply) {


    if (key == FOURCC('m','t','r','X') && mAnalyticsItem != NULL) {
    if (key == FOURCC('m','t','r','X')) {
        // mtrX -- a play on 'metrics' (not matrix)
        // mtrX -- a play on 'metrics' (not matrix)
        // gather current info all together, parcel it, and send it back
        // gather current info all together, parcel it, and send it back
        updateMetrics("api");
        updateMetrics("api");

        // ensure mAnalyticsItem stability while writing to parcel
        Mutex::Autolock autoLock(mMetricsLock);
        if (mAnalyticsItem != NULL) {
            mAnalyticsItem->writeToParcel(reply);
            mAnalyticsItem->writeToParcel(reply);
        }
        return OK;
        return OK;
    }
    }


@@ -1007,13 +1034,16 @@ void NuPlayerDriver::notifyListener_l(
            // when we have an error, add it to the analytics for this playback.
            // when we have an error, add it to the analytics for this playback.
            // ext1 is our primary 'error type' value. Only add ext2 when non-zero.
            // ext1 is our primary 'error type' value. Only add ext2 when non-zero.
            // [test against msg is due to fall through from previous switch value]
            // [test against msg is due to fall through from previous switch value]
            if (msg == MEDIA_ERROR && mAnalyticsItem != NULL) {
            if (msg == MEDIA_ERROR) {
                Mutex::Autolock autoLock(mMetricsLock);
                if (mAnalyticsItem != NULL) {
                    mAnalyticsItem->setInt32(kPlayerError, ext1);
                    mAnalyticsItem->setInt32(kPlayerError, ext1);
                    if (ext2 != 0) {
                    if (ext2 != 0) {
                        mAnalyticsItem->setInt32(kPlayerErrorCode, ext2);
                        mAnalyticsItem->setInt32(kPlayerErrorCode, ext2);
                    }
                    }
                    mAnalyticsItem->setCString(kPlayerErrorState, stateString(mState).c_str());
                    mAnalyticsItem->setCString(kPlayerErrorState, stateString(mState).c_str());
                }
                }
            }
            mAtEOS = true;
            mAtEOS = true;
            break;
            break;
        }
        }
+1 −0
Original line number Original line Diff line number Diff line
@@ -142,6 +142,7 @@ private:
    uint32_t mPlayerFlags;
    uint32_t mPlayerFlags;


    MediaAnalyticsItem *mAnalyticsItem;
    MediaAnalyticsItem *mAnalyticsItem;
    mutable Mutex mMetricsLock;
    uid_t mClientUid;
    uid_t mClientUid;


    bool mAtEOS;
    bool mAtEOS;
+0 −2
Original line number Original line Diff line number Diff line
@@ -34,8 +34,6 @@ NuPlayer::NuPlayerStreamListener::NuPlayerStreamListener(
      mTargetHandler(targetHandler),
      mTargetHandler(targetHandler),
      mEOS(false),
      mEOS(false),
      mSendDataNotification(true) {
      mSendDataNotification(true) {
    mSource->setListener(this);

    mMemoryDealer = new MemoryDealer(kNumBuffers * kBufferSize);
    mMemoryDealer = new MemoryDealer(kNumBuffers * kBufferSize);
    for (size_t i = 0; i < kNumBuffers; ++i) {
    for (size_t i = 0; i < kNumBuffers; ++i) {
        sp<IMemory> mem = mMemoryDealer->allocate(kBufferSize);
        sp<IMemory> mem = mMemoryDealer->allocate(kBufferSize);
+1 −0
Original line number Original line Diff line number Diff line
@@ -79,6 +79,7 @@ void NuPlayer::StreamingSource::prepareAsync() {


void NuPlayer::StreamingSource::start() {
void NuPlayer::StreamingSource::start() {
    mStreamListener = new NuPlayerStreamListener(mSource, NULL);
    mStreamListener = new NuPlayerStreamListener(mSource, NULL);
    mSource->setListener(mStreamListener);


    uint32_t sourceFlags = mSource->flags();
    uint32_t sourceFlags = mSource->flags();


+6 −2
Original line number Original line Diff line number Diff line
@@ -409,7 +409,9 @@ decode_vol:
        if (!BitstreamRead1Bits(stream)) return PV_FAIL;
        if (!BitstreamRead1Bits(stream)) return PV_FAIL;


        /* video_object_layer_width (13 bits) */
        /* video_object_layer_width (13 bits) */
        video->displayWidth = video->width = (int) BitstreamReadBits16(stream, 13);
        tmpvar = BitstreamReadBits16(stream, 13);
        if (!tmpvar) return PV_FAIL;
        video->displayWidth = video->width = tmpvar;


        /* round up to a multiple of MB_SIZE.   08/09/2000 */
        /* round up to a multiple of MB_SIZE.   08/09/2000 */
        video->width = (video->width + 15) & -16;
        video->width = (video->width + 15) & -16;
@@ -419,7 +421,9 @@ decode_vol:
        if (!BitstreamRead1Bits(stream)) return PV_FAIL;
        if (!BitstreamRead1Bits(stream)) return PV_FAIL;


        /* video_object_layer_height (13 bits) */
        /* video_object_layer_height (13 bits) */
        video->displayHeight = video->height = (int) BitstreamReadBits16(stream, 13);
        tmpvar = BitstreamReadBits16(stream, 13);
        if (!tmpvar) return PV_FAIL;
        video->displayHeight = video->height = tmpvar;


        /* round up to a multiple of MB_SIZE.   08/09/2000 */
        /* round up to a multiple of MB_SIZE.   08/09/2000 */
        video->height = (video->height + 15) & -16;
        video->height = (video->height + 15) & -16;