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

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

Merge "Instead of allocating the decoder instances in response to a call to...

Merge "Instead of allocating the decoder instances in response to a call to setDataSource, postpone allocation to the preparation phase where it belongs."
parents 7299c416 3ac94efc
Loading
Loading
Loading
Loading
+61 −33
Original line number Diff line number Diff line
@@ -297,14 +297,12 @@ status_t AwesomePlayer::setDataSource_l(const sp<MediaExtractor> &extractor) {
        CHECK(meta->findCString(kKeyMIMEType, &mime));

        if (!haveVideo && !strncasecmp(mime, "video/", 6)) {
            if (setVideoSource(extractor->getTrack(i)) == OK) {
            setVideoSource(extractor->getTrack(i));
            haveVideo = true;
            }
        } else if (!haveAudio && !strncasecmp(mime, "audio/", 6)) {
            if (setAudioSource(extractor->getTrack(i)) == OK) {
            setAudioSource(extractor->getTrack(i));
            haveAudio = true;
        }
        }

        if (haveAudio && haveVideo) {
            break;
@@ -331,6 +329,9 @@ void AwesomePlayer::reset_l() {
    }
    mPrefetcher.clear();

    mAudioTrack.clear();
    mVideoTrack.clear();

    // Shutdown audio first, so that the respone to the reset request
    // appears to happen instantaneously as far as the user is concerned
    // If we did this later, audio would continue playing while we
@@ -699,32 +700,34 @@ status_t AwesomePlayer::getVideoDimensions(
    return OK;
}

status_t AwesomePlayer::setAudioSource(sp<MediaSource> source) {
    if (source == NULL) {
        return UNKNOWN_ERROR;
    }
void AwesomePlayer::setAudioSource(sp<MediaSource> source) {
    CHECK(source != NULL);

    if (mPrefetcher != NULL) {
        source = mPrefetcher->addSource(source);
    }

    sp<MetaData> meta = source->getFormat();
    mAudioTrack = source;
}

status_t AwesomePlayer::initAudioDecoder() {
    sp<MetaData> meta = mAudioTrack->getFormat();

    const char *mime;
    CHECK(meta->findCString(kKeyMIMEType, &mime));

    if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RAW)) {
        mAudioSource = source;
        mAudioSource = mAudioTrack;
    } else {
        mAudioSource = OMXCodec::Create(
                mClient.interface(), source->getFormat(),
                mClient.interface(), mAudioTrack->getFormat(),
                false, // createEncoder
                source);
                mAudioTrack);
    }

    if (mAudioSource != NULL) {
        int64_t durationUs;
        if (source->getFormat()->findInt64(kKeyDuration, &durationUs)) {
        if (mAudioTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
            if (mDurationUs < 0 || durationUs > mDurationUs) {
                mDurationUs = durationUs;
            }
@@ -734,30 +737,32 @@ status_t AwesomePlayer::setAudioSource(sp<MediaSource> source) {
    return mAudioSource != NULL ? OK : UNKNOWN_ERROR;
}

status_t AwesomePlayer::setVideoSource(sp<MediaSource> source) {
    if (source == NULL) {
        return UNKNOWN_ERROR;
    }
void AwesomePlayer::setVideoSource(sp<MediaSource> source) {
    CHECK(source != NULL);

    if (mPrefetcher != NULL) {
        source = mPrefetcher->addSource(source);
    }

    mVideoTrack = source;
}

status_t AwesomePlayer::initVideoDecoder() {
    mVideoSource = OMXCodec::Create(
            mClient.interface(), source->getFormat(),
            mClient.interface(), mVideoTrack->getFormat(),
            false, // createEncoder
            source);
            mVideoTrack);

    if (mVideoSource != NULL) {
        int64_t durationUs;
        if (source->getFormat()->findInt64(kKeyDuration, &durationUs)) {
        if (mVideoTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
            if (mDurationUs < 0 || durationUs > mDurationUs) {
                mDurationUs = durationUs;
            }
        }

        CHECK(source->getFormat()->findInt32(kKeyWidth, &mVideoWidth));
        CHECK(source->getFormat()->findInt32(kKeyHeight, &mVideoHeight));
        CHECK(mVideoTrack->getFormat()->findInt32(kKeyWidth, &mVideoWidth));
        CHECK(mVideoTrack->getFormat()->findInt32(kKeyHeight, &mVideoHeight));

        mVideoSource->start();
    }
@@ -1045,14 +1050,9 @@ status_t AwesomePlayer::finishSetDataSource_l() {
    return setDataSource_l(extractor);
}

void AwesomePlayer::onPrepareAsyncEvent() {
    {
        Mutex::Autolock autoLock(mLock);

        if (mUri.size() > 0) {
            status_t err = finishSetDataSource_l();
void AwesomePlayer::abortPrepare(status_t err) {
    CHECK(err != OK);

            if (err != OK) {
    if (mIsAsyncPrepare) {
        notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
    }
@@ -1061,7 +1061,17 @@ void AwesomePlayer::onPrepareAsyncEvent() {
    mFlags &= ~PREPARING;
    mAsyncPrepareEvent = NULL;
    mPreparedCondition.broadcast();
}

void AwesomePlayer::onPrepareAsyncEvent() {
    {
        Mutex::Autolock autoLock(mLock);

        if (mUri.size() > 0) {
            status_t err = finishSetDataSource_l();

            if (err != OK) {
                abortPrepare(err);
                return;
            }
        }
@@ -1081,6 +1091,24 @@ void AwesomePlayer::onPrepareAsyncEvent() {

    Mutex::Autolock autoLock(mLock);

    if (mVideoTrack != NULL && mVideoSource == NULL) {
        status_t err = initVideoDecoder();

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

    if (mAudioTrack != NULL && mAudioSource == NULL) {
        status_t err = initAudioDecoder();

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

    if (mIsAsyncPrepare) {
        if (mVideoWidth < 0 || mVideoHeight < 0) {
            notifyListener_l(MEDIA_SET_VIDEO_SIZE, 0, 0);
+9 −2
Original line number Diff line number Diff line
@@ -112,10 +112,12 @@ private:

    sp<DataSource> mFileSource;

    sp<MediaSource> mVideoTrack;
    sp<MediaSource> mVideoSource;
    sp<AwesomeRenderer> mVideoRenderer;
    bool mVideoRendererIsPreview;

    sp<MediaSource> mAudioTrack;
    sp<MediaSource> mAudioSource;
    AudioPlayer *mAudioPlayer;
    int64_t mDurationUs;
@@ -199,8 +201,11 @@ private:

    void cancelPlayerEvents(bool keepBufferingGoing = false);

    status_t setAudioSource(sp<MediaSource> source);
    status_t setVideoSource(sp<MediaSource> source);
    void setAudioSource(sp<MediaSource> source);
    status_t initAudioDecoder();

    void setVideoSource(sp<MediaSource> source);
    status_t initVideoDecoder();

    void onStreamDone();

@@ -210,6 +215,8 @@ private:
    void onBufferingUpdate();
    void onCheckAudioStatus();
    void onPrepareAsyncEvent();
    void abortPrepare(status_t err);

    status_t finishSetDataSource_l();

    AwesomePlayer(const AwesomePlayer &);