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

Commit 147113ee authored by Andreas Huber's avatar Andreas Huber Committed by Android (Google) Code Review
Browse files

Merge "The audio track was accidentally not participating in the prefetch...

Merge "The audio track was accidentally not participating in the prefetch since it wasn't started at the time prepare() was called. Also, properly report the cached duration even near the end when the source has no more data to fetch."
parents 156c4354 dc9927d4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public:
    // Return time in us.
    virtual int64_t getRealTimeUs();

    status_t start();
    status_t start(bool sourceAlreadyStarted = false);

    void pause();
    void resume();
+7 −4
Original line number Diff line number Diff line
@@ -55,15 +55,18 @@ void AudioPlayer::setSource(const sp<MediaSource> &source) {
    mSource = source;
}

status_t AudioPlayer::start() {
status_t AudioPlayer::start(bool sourceAlreadyStarted) {
    CHECK(!mStarted);
    CHECK(mSource != NULL);

    status_t err = mSource->start();
    status_t err;
    if (!sourceAlreadyStarted) {
        err = mSource->start();

        if (err != OK) {
            return err;
        }
    }

    sp<MetaData> format = mSource->getFormat();
    const char *mime;
+10 −1
Original line number Diff line number Diff line
@@ -410,6 +410,9 @@ void AwesomePlayer::onBufferingUpdate() {

    if (mDurationUs >= 0) {
        int64_t cachedDurationUs = mPrefetcher->getCachedDurationUs();

        LOGV("cache holds %.2f secs worth of data.", cachedDurationUs / 1E6);

        int64_t positionUs = 0;
        if (mVideoSource != NULL) {
            positionUs = mVideoTimeUs;
@@ -486,7 +489,11 @@ status_t AwesomePlayer::play_l() {
            if (mAudioSink != NULL) {
                mAudioPlayer = new AudioPlayer(mAudioSink);
                mAudioPlayer->setSource(mAudioSource);
                status_t err = mAudioPlayer->start();

                // We've already started the MediaSource in order to enable
                // the prefetcher to read its data.
                status_t err = mAudioPlayer->start(
                        true /* sourceAlreadyStarted */);

                if (err != OK) {
                    delete mAudioPlayer;
@@ -734,6 +741,8 @@ status_t AwesomePlayer::initAudioDecoder() {
        }
    }

    mAudioSource->start();

    return mAudioSource != NULL ? OK : UNKNOWN_ERROR;
}

+7 −8
Original line number Diff line number Diff line
@@ -195,6 +195,7 @@ int64_t Prefetcher::getCachedDurationUs(bool *noMoreData) {

    int64_t minCacheDurationUs = -1;
    ssize_t minIndex = -1;
    bool anySourceActive = false;
    for (size_t i = 0; i < mSources.size(); ++i) {
        int64_t cacheDurationUs;
        sp<PrefetchedSource> source = mSources[i].promote();
@@ -202,8 +203,8 @@ int64_t Prefetcher::getCachedDurationUs(bool *noMoreData) {
            continue;
        }

        if (!source->getCacheDurationUs(&cacheDurationUs)) {
            continue;
        if (source->getCacheDurationUs(&cacheDurationUs)) {
            anySourceActive = true;
        }

        if (minIndex < 0 || cacheDurationUs < minCacheDurationUs) {
@@ -213,7 +214,7 @@ int64_t Prefetcher::getCachedDurationUs(bool *noMoreData) {
    }

    if (noMoreData) {
        *noMoreData = minCacheDurationUs < 0;
        *noMoreData = !anySourceActive;
    }

    return minCacheDurationUs < 0 ? 0 : minCacheDurationUs;
@@ -226,7 +227,7 @@ status_t Prefetcher::prepare() {
    bool noMoreData;
    do {
        duration = getCachedDurationUs(&noMoreData);
    } while (!noMoreData && duration < kMaxCacheDurationUs);
    } while (!noMoreData && duration < 2000000ll);

    return OK;
}
@@ -326,14 +327,12 @@ sp<MetaData> PrefetchedSource::getFormat() {
bool PrefetchedSource::getCacheDurationUs(int64_t *durationUs) {
    Mutex::Autolock autoLock(mLock);

    if (!mStarted || mReachedEOS) {
        *durationUs = 0;
    *durationUs = mCacheDurationUs;

    if (!mStarted || mReachedEOS) {
        return false;
    }

    *durationUs = mCacheDurationUs;

    return true;
}