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

Commit 0523da8f authored by Robert Shih's avatar Robert Shih Committed by Lajos Molnar
Browse files

NuPlayer side support for seamless format switch.

Avoid reinstantiating decoder if seamless format switch is supported.

Bug: 11854054
Change-Id: I2c2be08d6da90cc835ec747d04a76db2313dfc7c
parent 6c8495c8
Loading
Loading
Loading
Loading
+8 −1
Original line number Original line Diff line number Diff line
@@ -988,7 +988,14 @@ status_t NuPlayer::feedDecoderInputData(bool audio, const sp<AMessage> &msg) {
                                    &NuPlayer::performScanSources));
                                    &NuPlayer::performScanSources));
                    }
                    }


                    flushDecoder(audio, formatChange);
                    sp<AMessage> newFormat = mSource->getFormat(audio);
                    sp<Decoder> &decoder = audio ? mAudioDecoder : mVideoDecoder;
                    if (formatChange && !decoder->supportsSeamlessFormatChange(newFormat)) {
                        flushDecoder(audio, /* needShutdown = */ true);
                    } else {
                        flushDecoder(audio, /* needShutdown = */ false);
                        err = OK;
                    }
                } else {
                } else {
                    // This stream is unaffected by the discontinuity
                    // This stream is unaffected by the discontinuity


+61 −0
Original line number Original line Diff line number Diff line
@@ -67,6 +67,7 @@ void NuPlayer::Decoder::configure(const sp<AMessage> &format) {
    // queue.
    // queue.
    bool needDedicatedLooper = !strncasecmp(mime.c_str(), "video/", 6);
    bool needDedicatedLooper = !strncasecmp(mime.c_str(), "video/", 6);


    mFormat = format;
    mCodec = new ACodec;
    mCodec = new ACodec;


    if (needDedicatedLooper && mCodecLooper == NULL) {
    if (needDedicatedLooper && mCodecLooper == NULL) {
@@ -147,5 +148,65 @@ void NuPlayer::Decoder::initiateShutdown() {
    }
    }
}
}


bool NuPlayer::Decoder::supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const {
    if (targetFormat == NULL) {
        return true;
    }

    AString mime;
    if (!targetFormat->findString("mime", &mime)) {
        return false;
    }

    if (!strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_AAC)) {
        // field-by-field comparison
        const char * keys[] = { "channel-count", "sample-rate", "is-adts" };
        for (unsigned int i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) {
            int32_t oldVal, newVal;
            if (!mFormat->findInt32(keys[i], &oldVal) || !targetFormat->findInt32(keys[i], &newVal)
                    || oldVal != newVal) {
                return false;
            }
        }

        sp<ABuffer> oldBuf, newBuf;
        if (mFormat->findBuffer("csd-0", &oldBuf) && targetFormat->findBuffer("csd-0", &newBuf)) {
            if (oldBuf->size() != newBuf->size()) {
                return false;
            }
            return !memcmp(oldBuf->data(), newBuf->data(), oldBuf->size());
        }
    }
    return false;
}

bool NuPlayer::Decoder::supportsSeamlessFormatChange(const sp<AMessage> &targetFormat) const {
    if (mFormat == NULL) {
        return false;
    }

    if (targetFormat == NULL) {
        return true;
    }

    AString oldMime, newMime;
    if (!mFormat->findString("mime", &oldMime)
            || !targetFormat->findString("mime", &newMime)
            || !(oldMime == newMime)) {
        return false;
    }

    bool audio = !strncasecmp(oldMime.c_str(), "audio/", strlen("audio/"));
    bool seamless;
    if (audio) {
        seamless = supportsSeamlessAudioFormatChange(targetFormat);
    } else {
        seamless = mCodec != NULL && mCodec->isConfiguredForAdaptivePlayback();
    }

    ALOGV("%s seamless support for %s", seamless ? "yes" : "no", oldMime.c_str());
    return seamless;
}

}  // namespace android
}  // namespace android
+5 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,8 @@ struct NuPlayer::Decoder : public AHandler {
    void signalResume();
    void signalResume();
    void initiateShutdown();
    void initiateShutdown();


    bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;

protected:
protected:
    virtual ~Decoder();
    virtual ~Decoder();


@@ -49,6 +51,7 @@ private:
    sp<AMessage> mNotify;
    sp<AMessage> mNotify;
    sp<NativeWindowWrapper> mNativeWindow;
    sp<NativeWindowWrapper> mNativeWindow;


    sp<AMessage> mFormat;
    sp<ACodec> mCodec;
    sp<ACodec> mCodec;
    sp<ALooper> mCodecLooper;
    sp<ALooper> mCodecLooper;


@@ -59,6 +62,8 @@ private:


    void onFillThisBuffer(const sp<AMessage> &msg);
    void onFillThisBuffer(const sp<AMessage> &msg);


    bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;

    DISALLOW_EVIL_CONSTRUCTORS(Decoder);
    DISALLOW_EVIL_CONSTRUCTORS(Decoder);
};
};