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

Commit 2be50a9d authored by Rentao Li's avatar Rentao Li Committed by Steve Kondik
Browse files

stagefright: Add Awesomeplayer statistics using ExtendedStats

Profile Awesomeplayer statistics using ExtendedStats module.

Change-Id: I31cad6ea0e3c4b86e48c47ae4c706c9574cf6a72
parent 4102de0a
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -26,6 +26,15 @@

#include <OMX_Audio.h>

#include <media/stagefright/ExtendedStats.h>

#define PLAYER_STATS(func, ...) \
    do { \
        if(mPlayerExtendedStats != NULL) { \
            mPlayerExtendedStats->func(__VA_ARGS__);} \
    } \
    while(0)

namespace android {

struct MediaCodecInfo;
@@ -132,6 +141,8 @@ protected:

private:

    sp<PlayerExtendedStats> mPlayerExtendedStats;

    // Make sure mLock is accessible to OMXCodecObserver
    friend class OMXCodecObserver;

+37 −2
Original line number Diff line number Diff line
@@ -266,6 +266,8 @@ AwesomePlayer::AwesomePlayer()
#endif

    reset();

    mPlayerExtendedStats = new PlayerExtendedStats("AwesomePlayer", gettid());
}

AwesomePlayer::~AwesomePlayer() {
@@ -428,7 +430,10 @@ void AwesomePlayer::printFileName(int fd) {
status_t AwesomePlayer::setDataSource(
        int fd, int64_t offset, int64_t length) {
    Mutex::Autolock autoLock(mLock);
    ALOGD("Before reset_l");

    ExtendedStats::AutoProfile autoProfile(STATS_PROFILE_SET_DATA_SOURCE,
                                            mPlayerExtendedStats->getProfileTimes());
    PLAYER_STATS(profileStart, STATS_PROFILE_START_LATENCY);

    reset_l();
    if (fd) {
@@ -554,6 +559,7 @@ status_t AwesomePlayer::setDataSource_l(const sp<MediaExtractor> &extractor) {
            if (success) {
                mDisplayWidth = displayWidth;
                mDisplayHeight = displayHeight;
                PLAYER_STATS(logDimensions, displayWidth, displayHeight);
            }

            {
@@ -695,7 +701,9 @@ void AwesomePlayer::reset_l() {

    mVideoRenderer.clear();

    PLAYER_STATS(notifyEOS);
    modifyFlags(PLAYING, CLEAR);
    PLAYER_STATS(dump);
    printStats();
    if (mVideoSource != NULL) {
        shutdownVideoDecoder_l();
@@ -748,6 +756,7 @@ void AwesomePlayer::reset_l() {
        mStats.mResumeDelayStartUs = -1;
        mStats.mSeekDelayStartUs = -1;
    }
    PLAYER_STATS(reset);

    mWatchForAudioSeekComplete = false;
    mWatchForAudioEOS = false;
@@ -757,6 +766,10 @@ void AwesomePlayer::reset_l() {
}

void AwesomePlayer::notifyListener_l(int msg, int ext1, int ext2) {
    if (msg == MEDIA_SEEK_COMPLETE) {
        PLAYER_STATS(notifySeekDone);
    }

    if ((mListener != NULL) && !mAudioTearDown) {
        sp<MediaPlayerBase> listener = mListener.promote();

@@ -1011,6 +1024,8 @@ void AwesomePlayer::onStreamDone() {
        }
    } else {
        ALOGV("MEDIA_PLAYBACK_COMPLETE");
        PLAYER_STATS(notifyEOS);

        notifyListener_l(MEDIA_PLAYBACK_COMPLETE);

        pause_l(true /* at eos */);
@@ -1028,6 +1043,7 @@ void AwesomePlayer::onStreamDone() {

status_t AwesomePlayer::play() {
    ATRACE_CALL();
    PLAYER_STATS(notifyPlaying, true);

    Mutex::Autolock autoLock(mLock);

@@ -1475,6 +1491,8 @@ void AwesomePlayer::initRenderer_l() {

status_t AwesomePlayer::pause() {
    ATRACE_CALL();
    PLAYER_STATS(notifyPause, mVideoTimeUs/1000);
    ExtendedStats::AutoProfile autoProfile(STATS_PROFILE_PAUSE, mPlayerExtendedStats->getProfileTimes());

    Mutex::Autolock autoLock(mLock);

@@ -1674,6 +1692,9 @@ status_t AwesomePlayer::getPosition(int64_t *positionUs) {
status_t AwesomePlayer::seekTo(int64_t timeUs) {
    ATRACE_CALL();

    ExtendedStats::AutoProfile autoProfile(STATS_PROFILE_SEEK, mPlayerExtendedStats->getProfileTimes());
    PLAYER_STATS(notifySeek, timeUs);

    if (mExtractorFlags & MediaExtractor::CAN_SEEK) {
        Mutex::Autolock autoLock(mLock);
        return seekTo_l(timeUs);
@@ -1922,6 +1943,7 @@ status_t AwesomePlayer::initAudioDecoder() {
    } else {
        // If offloading we still create a OMX decoder as a fall-back
        // but we don't start it
        mAudioTrack->getFormat()->setPointer(ExtendedStats::MEDIA_STATS_FLAG, mPlayerExtendedStats.get());
        mOmxSource = OMXCodec::Create(
                mClient.interface(), mAudioTrack->getFormat(),
                false, // createEncoder
@@ -2078,6 +2100,8 @@ status_t AwesomePlayer::initVideoDecoder(uint32_t flags) {
    }

    ALOGV("initVideoDecoder flags=0x%x", flags);

    mVideoTrack->getFormat()->setPointer(ExtendedStats::MEDIA_STATS_FLAG, mPlayerExtendedStats.get());
    mVideoSource = OMXCodec::Create(
            mClient.interface(), mVideoTrack->getFormat(),
            false, // createEncoder
@@ -2254,6 +2278,7 @@ void AwesomePlayer::onVideoEvent() {
                    seekmode);
        }
        for (;;) {
            PLAYER_STATS(profileStartOnce, STATS_PROFILE_FIRST_BUFFER(true) /* video */);
            status_t err = mVideoSource->read(&mVideoBuffer, &options);
            options.clearSeekTo();

@@ -2370,6 +2395,9 @@ void AwesomePlayer::onVideoEvent() {
    int64_t looperTimeUs = ALooper::GetNowUs();

    if (mFlags & FIRST_FRAME) {
        PLAYER_STATS(profileStop, STATS_PROFILE_START_LATENCY);
        PLAYER_STATS(profileStop, STATS_PROFILE_FIRST_BUFFER(true) /* video */);

        modifyFlags(FIRST_FRAME, CLEAR);
        mSinceLastDropped = 0;
        mTimeSourceDeltaUs = ts->getRealTimeUs() - timeUs;
@@ -2460,6 +2488,7 @@ void AwesomePlayer::onVideoEvent() {

                {
                    Mutex::Autolock autoLock(mStatsLock);
                    PLAYER_STATS(logFrameDropped);
                    ++mStats.mNumVideoFramesDropped;
                    mStats.mConsecutiveFramesDropped++;
                    if (mStats.mConsecutiveFramesDropped == 1){
@@ -2519,6 +2548,7 @@ void AwesomePlayer::onVideoEvent() {
            Mutex::Autolock autoLock(mStatsLock);
            logOnTime(timeUs,nowUs,latenessUs);
            mStats.mTotalFrames++;
            PLAYER_STATS(logFrameRendered);
            mStats.mConsecutiveFramesDropped = 0;
            char value[PROPERTY_VALUE_MAX];
            property_get("persist.debug.sf.statistics", value, "0");
@@ -2974,6 +3004,7 @@ void AwesomePlayer::onPrepareAsyncEvent() {
}

void AwesomePlayer::beginPrepareAsync_l() {
    ExtendedStats::AutoProfile autoProfile(STATS_PROFILE_PREPARE, mPlayerExtendedStats->getProfileTimes());
    if (mFlags & PREPARE_CANCELLED) {
        ALOGI("prepare was cancelled before doing anything");
        abortPrepare(UNKNOWN_ERROR);
@@ -3646,6 +3677,7 @@ status_t AwesomePlayer::suspend() {

        // Shutdown the video decoder
        mVideoRenderer.clear();
        PLAYER_STATS(notifyEOS);
        printStats();
        if (mVideoSource != NULL) {
            shutdownVideoDecoder_l();
@@ -3667,6 +3699,9 @@ status_t AwesomePlayer::suspend() {

status_t AwesomePlayer::resume() {
    ALOGV("resume()");
    PLAYER_STATS(notifyPlaying, true);
    ExtendedStats::AutoProfile autoProfile(STATS_PROFILE_RESUME, mPlayerExtendedStats->getProfileTimes());

    Mutex::Autolock autoLock(mLock);

    // Reconnect the source
+33 −1
Original line number Diff line number Diff line
@@ -490,7 +490,21 @@ sp<MediaSource> OMXCodec::Create(
            }
        }

        //STATS profiling
        PlayerExtendedStats* tempPtr = NULL;
        meta->findPointer(ExtendedStats::MEDIA_STATS_FLAG, (void**)&tempPtr);

        bool isVideo = !strncasecmp("video/", mime, 6);
        if (tempPtr) {
            tempPtr->profileStart(STATS_PROFILE_ALLOCATE_NODE(isVideo));
        }

        status_t err = omx->allocateNode(componentName, observer, &node);

        if (tempPtr) {
            tempPtr->profileStop(STATS_PROFILE_ALLOCATE_NODE(isVideo));
        }

        if (err == OK) {
            ALOGD("Successfully allocated OMX node '%s'", componentName);

@@ -501,7 +515,16 @@ sp<MediaSource> OMXCodec::Create(

            observer->setCodec(codec);

            { //profile configure codec
                ExtendedStats::AutoProfile autoProfile(STATS_PROFILE_CONFIGURE_CODEC(isVideo),
                             tempPtr == NULL ? NULL : tempPtr->getProfileTimes());
                err = codec->configureCodec(meta);
            }

            /* set the stats pointer if we haven't yet and it exists */
            if(codec->mPlayerExtendedStats == NULL && tempPtr)
                codec->mPlayerExtendedStats = tempPtr;

            if (err == OK) {
                return codec;
            }
@@ -1919,6 +1942,12 @@ status_t OMXCodec::allocateBuffers() {
}

status_t OMXCodec::allocateBuffersOnPort(OMX_U32 portIndex) {
    const char* type = portIndex == kPortIndexInput ?
                                    STATS_PROFILE_ALLOCATE_INPUT(mIsVideo) :
                                    STATS_PROFILE_ALLOCATE_OUTPUT(mIsVideo);
    ExtendedStats::AutoProfile autoProfile(type, mPlayerExtendedStats == NULL ? NULL :
                                           mPlayerExtendedStats->getProfileTimes());

    if (mNativeWindow != NULL && portIndex == kPortIndexOutput) {
        return allocateOutputBuffersFromNativeWindow();
    }
@@ -3674,6 +3703,9 @@ bool OMXCodec::drainInputBuffer(BufferInfo *info) {
        int64_t lastBufferTimeUs;
        CHECK(srcBuffer->meta_data()->findInt64(kKeyTime, &lastBufferTimeUs));
        CHECK(lastBufferTimeUs >= 0);

        PLAYER_STATS(logBitRate, srcBuffer->range_length(), lastBufferTimeUs);

        if (mIsEncoder && mIsVideo) {
            mDecodingTimeList.push_back(lastBufferTimeUs);
        }
+10 −0
Original line number Diff line number Diff line
@@ -30,6 +30,14 @@
#include <media/stagefright/MetaData.h>
#include <utils/threads.h>
#include <drm/DrmManagerClient.h>
#include <media/stagefright/ExtendedStats.h>

#define PLAYER_STATS(func, ...) \
    do { \
        if(mPlayerExtendedStats != NULL) { \
            mPlayerExtendedStats->func(__VA_ARGS__);} \
    } \
    while(0)

namespace android {

@@ -116,6 +124,8 @@ private:
    friend struct AwesomeEvent;
    friend struct PreviewPlayer;

    sp<PlayerExtendedStats> mPlayerExtendedStats;

    enum {
        PLAYING             = 0x01,
        LOOPING             = 0x02,