Search in sources :

Example 21 with DecoderReuseEvaluation

use of com.google.android.exoplayer2.decoder.DecoderReuseEvaluation in project ExoPlayer by google.

the class MediaCodecInfo method canReuseCodec.

/**
 * Evaluates whether it's possible to reuse an instance of this decoder that's currently decoding
 * {@code oldFormat} to decode {@code newFormat} instead.
 *
 * <p>For adaptation to succeed, the codec must also be configured with maximum values that are
 * compatible with the new format.
 *
 * @param oldFormat The format being decoded.
 * @param newFormat The new format.
 * @return The result of the evaluation.
 */
public DecoderReuseEvaluation canReuseCodec(Format oldFormat, Format newFormat) {
    @DecoderDiscardReasons int discardReasons = 0;
    if (!Util.areEqual(oldFormat.sampleMimeType, newFormat.sampleMimeType)) {
        discardReasons |= DISCARD_REASON_MIME_TYPE_CHANGED;
    }
    if (isVideo) {
        if (oldFormat.rotationDegrees != newFormat.rotationDegrees) {
            discardReasons |= DISCARD_REASON_VIDEO_ROTATION_CHANGED;
        }
        if (!adaptive && (oldFormat.width != newFormat.width || oldFormat.height != newFormat.height)) {
            discardReasons |= DISCARD_REASON_VIDEO_RESOLUTION_CHANGED;
        }
        if (!Util.areEqual(oldFormat.colorInfo, newFormat.colorInfo)) {
            discardReasons |= DISCARD_REASON_VIDEO_COLOR_INFO_CHANGED;
        }
        if (needsAdaptationReconfigureWorkaround(name) && !oldFormat.initializationDataEquals(newFormat)) {
            discardReasons |= DISCARD_REASON_WORKAROUND;
        }
        if (discardReasons == 0) {
            return new DecoderReuseEvaluation(name, oldFormat, newFormat, oldFormat.initializationDataEquals(newFormat) ? REUSE_RESULT_YES_WITHOUT_RECONFIGURATION : REUSE_RESULT_YES_WITH_RECONFIGURATION, /* discardReasons= */
            0);
        }
    } else {
        if (oldFormat.channelCount != newFormat.channelCount) {
            discardReasons |= DISCARD_REASON_AUDIO_CHANNEL_COUNT_CHANGED;
        }
        if (oldFormat.sampleRate != newFormat.sampleRate) {
            discardReasons |= DISCARD_REASON_AUDIO_SAMPLE_RATE_CHANGED;
        }
        if (oldFormat.pcmEncoding != newFormat.pcmEncoding) {
            discardReasons |= DISCARD_REASON_AUDIO_ENCODING_CHANGED;
        }
        // without reconfiguration or flushing.
        if (discardReasons == 0 && MimeTypes.AUDIO_AAC.equals(mimeType)) {
            @Nullable Pair<Integer, Integer> oldCodecProfileLevel = MediaCodecUtil.getCodecProfileAndLevel(oldFormat);
            @Nullable Pair<Integer, Integer> newCodecProfileLevel = MediaCodecUtil.getCodecProfileAndLevel(newFormat);
            if (oldCodecProfileLevel != null && newCodecProfileLevel != null) {
                int oldProfile = oldCodecProfileLevel.first;
                int newProfile = newCodecProfileLevel.first;
                if (oldProfile == CodecProfileLevel.AACObjectXHE && newProfile == CodecProfileLevel.AACObjectXHE) {
                    return new DecoderReuseEvaluation(name, oldFormat, newFormat, REUSE_RESULT_YES_WITHOUT_RECONFIGURATION, /* discardReasons= */
                    0);
                }
            }
        }
        if (!oldFormat.initializationDataEquals(newFormat)) {
            discardReasons |= DISCARD_REASON_INITIALIZATION_DATA_CHANGED;
        }
        if (needsAdaptationFlushWorkaround(mimeType)) {
            discardReasons |= DISCARD_REASON_WORKAROUND;
        }
        if (discardReasons == 0) {
            return new DecoderReuseEvaluation(name, oldFormat, newFormat, REUSE_RESULT_YES_WITH_FLUSH, /* discardReasons= */
            0);
        }
    }
    return new DecoderReuseEvaluation(name, oldFormat, newFormat, REUSE_RESULT_NO, discardReasons);
}
Also used : DecoderReuseEvaluation(com.google.android.exoplayer2.decoder.DecoderReuseEvaluation) DecoderDiscardReasons(com.google.android.exoplayer2.decoder.DecoderReuseEvaluation.DecoderDiscardReasons) Point(android.graphics.Point) Nullable(androidx.annotation.Nullable)

Aggregations

DecoderReuseEvaluation (com.google.android.exoplayer2.decoder.DecoderReuseEvaluation)19 Format (com.google.android.exoplayer2.Format)11 Test (org.junit.Test)11 Nullable (androidx.annotation.Nullable)4 DecoderDiscardReasons (com.google.android.exoplayer2.decoder.DecoderReuseEvaluation.DecoderDiscardReasons)4 SuppressLint (android.annotation.SuppressLint)2 Point (android.graphics.Point)2 CallSuper (androidx.annotation.CallSuper)2 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)2 MediaFormat (android.media.MediaFormat)1