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

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

Merge "Support for a "preparation" state that can take care of lengthy"

parents 27243b75 57cea553
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -106,6 +106,26 @@ void NuPlayer::GenericSource::initFromDataSource(
NuPlayer::GenericSource::~GenericSource() {
}

void NuPlayer::GenericSource::prepareAsync() {
    if (mVideoTrack.mSource != NULL) {
        sp<MetaData> meta = mVideoTrack.mSource->getFormat();

        int32_t width, height;
        CHECK(meta->findInt32(kKeyWidth, &width));
        CHECK(meta->findInt32(kKeyHeight, &height));

        notifyVideoSizeChanged(width, height);
    }

    notifyFlagsChanged(
            FLAG_CAN_PAUSE
            | FLAG_CAN_SEEK_BACKWARD
            | FLAG_CAN_SEEK_FORWARD
            | FLAG_CAN_SEEK);

    notifyPrepared();
}

void NuPlayer::GenericSource::start() {
    ALOGI("start");

@@ -262,8 +282,4 @@ void NuPlayer::GenericSource::readBuffer(
    }
}

uint32_t NuPlayer::GenericSource::flags() const {
    return FLAG_SEEKABLE;
}

}  // namespace android
+2 −2
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ struct NuPlayer::GenericSource : public NuPlayer::Source {
            const sp<AMessage> &notify,
            int fd, int64_t offset, int64_t length);

    virtual void prepareAsync();

    virtual void start();

    virtual status_t feedMoreTSData();
@@ -51,8 +53,6 @@ struct NuPlayer::GenericSource : public NuPlayer::Source {
    virtual status_t getDuration(int64_t *durationUs);
    virtual status_t seekTo(int64_t seekTimeUs);

    virtual uint32_t flags() const;

protected:
    virtual ~GenericSource();

+21 −14
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ NuPlayer::HTTPLiveSource::~HTTPLiveSource() {
    }
}

void NuPlayer::HTTPLiveSource::start() {
void NuPlayer::HTTPLiveSource::prepareAsync() {
    mLiveLooper = new ALooper;
    mLiveLooper->setName("http live");
    mLiveLooper->start();
@@ -81,6 +81,26 @@ void NuPlayer::HTTPLiveSource::start() {
            mURL.c_str(), mExtraHeaders.isEmpty() ? NULL : &mExtraHeaders);

    mTSParser = new ATSParser;

    notifyVideoSizeChanged(0, 0);

    uint32_t flags = FLAG_CAN_PAUSE;
    if (mLiveSession->isSeekable()) {
        flags |= FLAG_CAN_SEEK;
        flags |= FLAG_CAN_SEEK_BACKWARD;
        flags |= FLAG_CAN_SEEK_FORWARD;
    }

    if (mLiveSession->hasDynamicDuration()) {
        flags |= FLAG_DYNAMIC_DURATION;
    }

    notifyFlagsChanged(flags);

    notifyPrepared();
}

void NuPlayer::HTTPLiveSource::start() {
}

sp<MetaData> NuPlayer::HTTPLiveSource::getFormatMeta(bool audio) {
@@ -194,18 +214,5 @@ status_t NuPlayer::HTTPLiveSource::seekTo(int64_t seekTimeUs) {
    return OK;
}

uint32_t NuPlayer::HTTPLiveSource::flags() const {
    uint32_t flags = 0;
    if (mLiveSession->isSeekable()) {
        flags |= FLAG_SEEKABLE;
    }

    if (mLiveSession->hasDynamicDuration()) {
        flags |= FLAG_DYNAMIC_DURATION;
    }

    return flags;
}

}  // namespace android
+1 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ struct NuPlayer::HTTPLiveSource : public NuPlayer::Source {
            bool uidValid = false,
            uid_t uid = 0);

    virtual void prepareAsync();
    virtual void start();

    virtual status_t feedMoreTSData();
@@ -43,8 +44,6 @@ struct NuPlayer::HTTPLiveSource : public NuPlayer::Source {
    virtual status_t getDuration(int64_t *durationUs);
    virtual status_t seekTo(int64_t seekTimeUs);

    virtual uint32_t flags() const;

protected:
    virtual ~HTTPLiveSource();

+90 −7
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ private:

NuPlayer::NuPlayer()
    : mUIDValid(false),
      mSourceFlags(0),
      mVideoIsAVC(false),
      mAudioEOS(false),
      mVideoEOS(false),
@@ -142,7 +143,7 @@ void NuPlayer::setDriver(const wp<NuPlayerDriver> &driver) {
    mDriver = driver;
}

void NuPlayer::setDataSource(const sp<IStreamSource> &source) {
void NuPlayer::setDataSourceAsync(const sp<IStreamSource> &source) {
    sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());

    sp<AMessage> notify = new AMessage(kWhatSourceNotify, id());
@@ -174,7 +175,7 @@ static bool IsHTTPLiveURL(const char *url) {
    return false;
}

void NuPlayer::setDataSource(
void NuPlayer::setDataSourceAsync(
        const char *url, const KeyedVector<String8, String8> *headers) {
    sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
    size_t len = strlen(url);
@@ -199,7 +200,7 @@ void NuPlayer::setDataSource(
    msg->post();
}

void NuPlayer::setDataSource(int fd, int64_t offset, int64_t length) {
void NuPlayer::setDataSourceAsync(int fd, int64_t offset, int64_t length) {
    sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());

    sp<AMessage> notify = new AMessage(kWhatSourceNotify, id());
@@ -209,6 +210,10 @@ void NuPlayer::setDataSource(int fd, int64_t offset, int64_t length) {
    msg->post();
}

void NuPlayer::prepareAsync() {
    (new AMessage(kWhatPrepare, id()))->post();
}

void NuPlayer::setVideoSurfaceTextureAsync(
        const sp<IGraphicBufferProducer> &bufferProducer) {
    sp<AMessage> msg = new AMessage(kWhatSetVideoNativeWindow, id());
@@ -287,6 +292,18 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
            mSource = static_cast<Source *>(obj.get());

            looper()->registerHandler(mSource);

            CHECK(mDriver != NULL);
            sp<NuPlayerDriver> driver = mDriver.promote();
            if (driver != NULL) {
                driver->notifySetDataSourceCompleted(OK);
            }
            break;
        }

        case kWhatPrepare:
        {
            mSource->prepareAsync();
            break;
        }

@@ -403,9 +420,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
                    && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
                // This is the first time we've found anything playable.

                uint32_t flags = mSource->flags();

                if (flags & Source::FLAG_DYNAMIC_DURATION) {
                if (mSourceFlags & Source::FLAG_DYNAMIC_DURATION) {
                    schedulePollDuration();
                }
            }
@@ -730,7 +745,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {

        case kWhatSourceNotify:
        {
            TRESPASS();  // TBD
            onSourceNotify(msg);
            break;
        }

@@ -1233,8 +1248,76 @@ void NuPlayer::performSetSurface(const sp<NativeWindowWrapper> &wrapper) {
    }
}

void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
    int32_t what;
    CHECK(msg->findInt32("what", &what));

    switch (what) {
        case Source::kWhatPrepared:
        {
            sp<NuPlayerDriver> driver = mDriver.promote();
            if (driver != NULL) {
                driver->notifyPrepareCompleted(OK);
            }
            break;
        }

        case Source::kWhatFlagsChanged:
        {
            uint32_t flags;
            CHECK(msg->findInt32("flags", (int32_t *)&flags));

            if ((mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
                    && (!(flags & Source::FLAG_DYNAMIC_DURATION))) {
                cancelPollDuration();
            } else if (!(mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
                    && (flags & Source::FLAG_DYNAMIC_DURATION)
                    && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
                schedulePollDuration();
            }

            mSourceFlags = flags;
            break;
        }

        case Source::kWhatVideoSizeChanged:
        {
            int32_t width, height;
            CHECK(msg->findInt32("width", &width));
            CHECK(msg->findInt32("height", &height));

            notifyListener(MEDIA_SET_VIDEO_SIZE, width, height);
            break;
        }

        default:
            TRESPASS();
    }
}

////////////////////////////////////////////////////////////////////////////////

void NuPlayer::Source::notifyFlagsChanged(uint32_t flags) {
    sp<AMessage> notify = dupNotify();
    notify->setInt32("what", kWhatFlagsChanged);
    notify->setInt32("flags", flags);
    notify->post();
}

void NuPlayer::Source::notifyVideoSizeChanged(int32_t width, int32_t height) {
    sp<AMessage> notify = dupNotify();
    notify->setInt32("what", kWhatVideoSizeChanged);
    notify->setInt32("width", width);
    notify->setInt32("height", height);
    notify->post();
}

void NuPlayer::Source::notifyPrepared() {
    sp<AMessage> notify = dupNotify();
    notify->setInt32("what", kWhatPrepared);
    notify->post();
}

void NuPlayer::Source::onMessageReceived(const sp<AMessage> &msg) {
    TRESPASS();
}
Loading