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

Commit 8bc34962 authored by Wei Jia's avatar Wei Jia
Browse files

NuPlayerSource: clarify getFormat API and fix its usage.

Test: manually run mediaplayer
Bug: 33818804
Change-Id: I1a4e551493fa9521b3b1159182d446e8a9e7d523
(cherry picked from commit 9737d349)
parent c21b625d
Loading
Loading
Loading
Loading
+17 −7
Original line number Diff line number Diff line
@@ -1338,26 +1338,26 @@ void NuPlayer::onStart(int64_t startPositionUs) {
        flags |= Renderer::FLAG_REAL_TIME;
    }

    sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
    sp<MetaData> videoMeta = mSource->getFormatMeta(false /* audio */);
    if (audioMeta == NULL && videoMeta == NULL) {
    bool hasAudio = (mSource->getFormat(true /* audio */) != NULL);
    bool hasVideo = (mSource->getFormat(false /* audio */) != NULL);
    if (!hasAudio && !hasVideo) {
        ALOGE("no metadata for either audio or video source");
        mSource->stop();
        mSourceStarted = false;
        notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_MALFORMED);
        return;
    }
    ALOGV_IF(audioMeta == NULL, "no metadata for audio source");  // video only stream
    ALOGV_IF(!hasAudio, "no metadata for audio source");  // video only stream

    sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);

    audio_stream_type_t streamType = AUDIO_STREAM_MUSIC;
    if (mAudioSink != NULL) {
        streamType = mAudioSink->getAudioStreamType();
    }

    sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);

    mOffloadAudio =
        canOffloadStream(audioMeta, (videoFormat != NULL), mSource->isStreaming(), streamType)
        canOffloadStream(audioMeta, hasVideo, mSource->isStreaming(), streamType)
                && (mPlaybackSettings.mSpeed == 1.f && mPlaybackSettings.mPitch == 1.f);
    if (mOffloadAudio) {
        flags |= Renderer::FLAG_OFFLOAD_AUDIO;
@@ -1718,6 +1718,16 @@ void NuPlayer::updateVideoSize(
        notifyListener(MEDIA_SET_VIDEO_SIZE, 0, 0);
        return;
    }
    int32_t err = OK;
    inputFormat->findInt32("err", &err);
    if (err == -EWOULDBLOCK) {
        ALOGW("Video meta is not available yet!");
        return;
    }
    if (err != OK) {
        ALOGW("Something is wrong with video meta!");
        return;
    }

    int32_t displayWidth, displayHeight;
    if (outputFormat != NULL) {
+4 −0
Original line number Diff line number Diff line
@@ -77,7 +77,11 @@ struct NuPlayer::Source : public AHandler {
    // an error or ERROR_END_OF_STREAM if not.
    virtual status_t feedMoreTSData() = 0;

    // Returns non-NULL format when the specified track exists.
    // When the format has "err" set to -EWOULDBLOCK, source needs more time to get valid meta data.
    // Returns NULL if the specified track doesn't exist or is invalid;
    virtual sp<AMessage> getFormat(bool audio);

    virtual sp<MetaData> getFormatMeta(bool /* audio */) { return NULL; }
    virtual sp<MetaData> getFileFormatMeta() const { return NULL; }

+1 −2
Original line number Diff line number Diff line
@@ -234,8 +234,7 @@ sp<AMessage> NuPlayer::StreamingSource::getFormat(bool audio) {
    }
    status_t err = convertMetaDataToMessage(meta, &format);
    if (err != OK) { // format may have been cleared on error
        format = new AMessage;
        format->setInt32("err", err);
        return NULL;
    }
    return format;
}