From a9617af29c2c760c8e439d390ef02f0b4e055a6b Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 15 Mar 2017 06:44:11 -0700 Subject: [PATCH] Use fast surface switching on API level 23+ when possible ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=150185483 --- .../video/MediaCodecVideoRenderer.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java b/library/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java index 280f0042114..059628e0c80 100644 --- a/library/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java +++ b/library/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java @@ -298,13 +298,18 @@ public void handleMessage(int messageType, Object message) throws ExoPlaybackExc } private void setSurface(Surface surface) throws ExoPlaybackException { - // We only need to release and reinitialize the codec if the surface has changed. + // We only need to update the codec if the surface has changed. if (this.surface != surface) { this.surface = surface; int state = getState(); if (state == STATE_ENABLED || state == STATE_STARTED) { - releaseCodec(); - maybeInitCodec(); + MediaCodec codec = getCodec(); + if (Util.SDK_INT >= 23 && codec != null && surface != null) { + setOutputSurfaceV23(codec, surface); + } else { + releaseCodec(); + maybeInitCodec(); + } } } // Clear state so that we always call the event listener with the video size and when a frame @@ -589,6 +594,11 @@ private static MediaFormat getMediaFormat(Format format, CodecMaxValues codecMax return frameworkMediaFormat; } + @TargetApi(23) + private static void setOutputSurfaceV23(MediaCodec codec, Surface surface) { + codec.setOutputSurface(surface); + } + @TargetApi(21) private static void configureTunnelingV21(MediaFormat mediaFormat, int tunnelingAudioSessionId) { mediaFormat.setFeatureEnabled(CodecCapabilities.FEATURE_TunneledPlayback, true);