From c89cc81b710e7bc5e8f35c56e59cc8f8f99f1a0b Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Thu, 4 Jan 2018 04:31:44 -0800 Subject: [PATCH] Configure MediaCodecs for realtime priority ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=180782164 --- .../audio/MediaCodecAudioRenderer.java | 5 +++-- .../mediacodec/MediaCodecRenderer.java | 20 +++++++++++++++++++ .../video/MediaCodecVideoRenderer.java | 6 +----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java index b4459e42aa4..f73d63616b4 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java @@ -240,14 +240,15 @@ protected boolean allowPassthrough(String mimeType) { protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format, MediaCrypto crypto) { codecNeedsDiscardChannelsWorkaround = codecNeedsDiscardChannelsWorkaround(codecInfo.name); + MediaFormat mediaFormat = getMediaFormatForPlayback(format); if (passthroughEnabled) { // Override the MIME type used to configure the codec if we are using a passthrough decoder. - passthroughMediaFormat = format.getFrameworkMediaFormatV16(); + passthroughMediaFormat = mediaFormat; passthroughMediaFormat.setString(MediaFormat.KEY_MIME, MimeTypes.AUDIO_RAW); codec.configure(passthroughMediaFormat, null, crypto, 0); passthroughMediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType); } else { - codec.configure(format.getFrameworkMediaFormatV16(), null, crypto, 0); + codec.configure(mediaFormat, null, crypto, 0); passthroughMediaFormat = null; } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java index ef7d691c5be..4b1af7e385b 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java @@ -430,6 +430,21 @@ protected final MediaCodecInfo getCodecInfo() { return codecInfo; } + /** + * Returns the framework {@link MediaFormat} that can be used to configure a {@link MediaCodec} + * for decoding the given {@link Format} for playback. + * + * @param format The format of the media. + * @return The framework media format. + */ + protected final MediaFormat getMediaFormatForPlayback(Format format) { + MediaFormat mediaFormat = format.getFrameworkMediaFormatV16(); + if (Util.SDK_INT >= 23) { + configureMediaFormatForPlaybackV23(mediaFormat); + } + return mediaFormat; + } + @Override protected void onEnabled(boolean joining) throws ExoPlaybackException { decoderCounters = new DecoderCounters(); @@ -1108,6 +1123,11 @@ private boolean shouldSkipOutputBuffer(long presentationTimeUs) { return false; } + @TargetApi(23) + private static void configureMediaFormatForPlaybackV23(MediaFormat mediaFormat) { + mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */); + } + /** * Returns whether the decoder is known to fail when flushed. *

diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java index 41e3c970c4f..6900823ebef 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java @@ -906,19 +906,15 @@ protected CodecMaxValues getCodecMaxValues(MediaCodecInfo codecInfo, Format form @SuppressLint("InlinedApi") protected MediaFormat getMediaFormat(Format format, CodecMaxValues codecMaxValues, boolean deviceNeedsAutoFrcWorkaround, int tunnelingAudioSessionId) { - MediaFormat frameworkMediaFormat = format.getFrameworkMediaFormatV16(); - // Set the maximum adaptive video dimensions. + MediaFormat frameworkMediaFormat = getMediaFormatForPlayback(format); frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, codecMaxValues.width); frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, codecMaxValues.height); - // Set the maximum input size. if (codecMaxValues.inputSize != Format.NO_VALUE) { frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxValues.inputSize); } - // Set FRC workaround. if (deviceNeedsAutoFrcWorkaround) { frameworkMediaFormat.setInteger("auto-frc", 0); } - // Configure tunneling if enabled. if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) { configureTunnelingV21(frameworkMediaFormat, tunnelingAudioSessionId); }