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

Commit f71daba4 authored by Andreas Huber's avatar Andreas Huber
Browse files

Enable early termination of the prefetcher's preparation phase.

Change-Id: I929ac9b0fd0b6ebd98c1bc56be18ac8f8378d48c
related-to-bug: 2537407
parent b43bdf41
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -1106,6 +1106,13 @@ void AwesomePlayer::abortPrepare(status_t err) {
    mPreparedCondition.broadcast();
}

// static
bool AwesomePlayer::ContinuePreparation(void *cookie) {
    AwesomePlayer *me = static_cast<AwesomePlayer *>(cookie);

    return (me->mFlags & PREPARE_CANCELLED) == 0;
}

void AwesomePlayer::onPrepareAsyncEvent() {
    sp<Prefetcher> prefetcher;

@@ -1161,10 +1168,22 @@ void AwesomePlayer::onPrepareAsyncEvent() {
        }

        LOGI("calling prefetcher->prepare()");
        prefetcher->prepare();
        LOGV("prefetcher is done preparing");
        status_t result =
            prefetcher->prepare(&AwesomePlayer::ContinuePreparation, this);

        prefetcher.clear();

        if (result == OK) {
            LOGV("prefetcher is done preparing");
        } else {
            Mutex::Autolock autoLock(mLock);

            CHECK_EQ(result, -EINTR);

            LOGI("prefetcher->prepare() was cancelled early.");
            abortPrepare(UNKNOWN_ERROR);
            return;
        }
    }

    Mutex::Autolock autoLock(mLock);
+8 −1
Original line number Diff line number Diff line
@@ -220,12 +220,19 @@ int64_t Prefetcher::getCachedDurationUs(bool *noMoreData) {
    return minCacheDurationUs < 0 ? 0 : minCacheDurationUs;
}

status_t Prefetcher::prepare() {
status_t Prefetcher::prepare(
        bool (*continueFunc)(void *cookie), void *cookie) {
    // Fill the cache.

    int64_t duration;
    bool noMoreData;
    do {
        usleep(100000);

        if (continueFunc && !(*continueFunc)(cookie)) {
            return -EINTR;
        }

        duration = getCachedDurationUs(&noMoreData);
    } while (!noMoreData && duration < 2000000ll);

+2 −0
Original line number Diff line number Diff line
@@ -222,6 +222,8 @@ private:

    status_t finishSetDataSource_l();

    static bool ContinuePreparation(void *cookie);

    AwesomePlayer(const AwesomePlayer &);
    AwesomePlayer &operator=(const AwesomePlayer &);
};
+6 −1
Original line number Diff line number Diff line
@@ -36,7 +36,12 @@ struct Prefetcher : public RefBase {

    int64_t getCachedDurationUs(bool *noMoreData = NULL);

    status_t prepare();
    // If provided (non-NULL), "continueFunc" will be called repeatedly
    // while preparing and preparation will finish early if it returns
    // false. In this case "-EINTR" is returned as a result.
    status_t prepare(
            bool (*continueFunc)(void *cookie) = NULL,
            void *cookie = NULL);

protected:
    virtual ~Prefetcher();