From ee6afe5eb9576da19dd188b3da7dc5abded5b1fa Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 18 Mar 2020 23:56:24 +0000 Subject: [PATCH] Merge AudioDecoderException and VideoDecoderException This is a necessary step for Decoder implementations to support audio and video. MediaCodecRenderer.DecoderException is renamed MediaCodecDecoderException and extends the new DecoderException Issue: #2159 PiperOrigin-RevId: 301698238 --- .../ext/av1/Gav1DecoderException.java | 4 +- .../ext/av1/Libgav1VideoRenderer.java | 9 ++-- .../ext/ffmpeg/FfmpegDecoderException.java | 8 ++-- .../ext/flac/FlacDecoderException.java | 8 ++-- .../ext/opus/OpusDecoderException.java | 8 ++-- .../ext/vp9/LibvpxVideoRenderer.java | 11 ++--- .../ext/vp9/VpxDecoderException.java | 4 +- .../audio/DecoderAudioRenderer.java | 26 +++++----- .../DecoderException.java} | 11 ++--- .../MediaCodecDecoderException.java | 47 +++++++++++++++++++ .../mediacodec/MediaCodecRenderer.java | 28 +---------- .../video/DecoderVideoRenderer.java | 32 ++++++------- .../MediaCodecVideoDecoderException.java | 39 +++++++++++++++ .../video/MediaCodecVideoRenderer.java | 22 ++------- .../video/VideoDecoderException.java | 40 ---------------- .../audio/DecoderAudioRendererTest.java | 13 ++--- .../video/DecoderVideoRendererTest.java | 11 +++-- 17 files changed, 157 insertions(+), 164 deletions(-) rename library/core/src/main/java/com/google/android/exoplayer2/{audio/AudioDecoderException.java => decoder/DecoderException.java} (79%) create mode 100644 library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecDecoderException.java create mode 100644 library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoDecoderException.java delete mode 100644 library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderException.java diff --git a/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Gav1DecoderException.java b/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Gav1DecoderException.java index 9d8692c581..13839f0ceb 100644 --- a/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Gav1DecoderException.java +++ b/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Gav1DecoderException.java @@ -15,10 +15,10 @@ */ package com.google.android.exoplayer2.ext.av1; -import com.google.android.exoplayer2.video.VideoDecoderException; +import com.google.android.exoplayer2.decoder.DecoderException; /** Thrown when a libgav1 decoder error occurs. */ -public final class Gav1DecoderException extends VideoDecoderException { +public final class Gav1DecoderException extends DecoderException { /* package */ Gav1DecoderException(String message) { super(message); diff --git a/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Libgav1VideoRenderer.java b/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Libgav1VideoRenderer.java index c3a936a10f..3c35cf43a2 100644 --- a/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Libgav1VideoRenderer.java +++ b/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Libgav1VideoRenderer.java @@ -26,13 +26,13 @@ import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.PlayerMessage.Target; import com.google.android.exoplayer2.RendererCapabilities; +import com.google.android.exoplayer2.decoder.DecoderException; import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.drm.ExoMediaCrypto; import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.TraceUtil; import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.video.DecoderVideoRenderer; -import com.google.android.exoplayer2.video.VideoDecoderException; import com.google.android.exoplayer2.video.VideoDecoderInputBuffer; import com.google.android.exoplayer2.video.VideoDecoderOutputBuffer; import com.google.android.exoplayer2.video.VideoDecoderOutputBufferRenderer; @@ -141,11 +141,8 @@ public class Libgav1VideoRenderer extends DecoderVideoRenderer { @Override protected SimpleDecoder< - VideoDecoderInputBuffer, - ? extends VideoDecoderOutputBuffer, - ? extends VideoDecoderException> - createDecoder(Format format, @Nullable ExoMediaCrypto mediaCrypto) - throws VideoDecoderException { + VideoDecoderInputBuffer, ? extends VideoDecoderOutputBuffer, ? extends DecoderException> + createDecoder(Format format, @Nullable ExoMediaCrypto mediaCrypto) throws DecoderException { TraceUtil.beginSection("createGav1Decoder"); int initialInputBufferSize = format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE; diff --git a/extensions/ffmpeg/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegDecoderException.java b/extensions/ffmpeg/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegDecoderException.java index d6b5a62450..47d5017350 100644 --- a/extensions/ffmpeg/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegDecoderException.java +++ b/extensions/ffmpeg/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegDecoderException.java @@ -15,12 +15,10 @@ */ package com.google.android.exoplayer2.ext.ffmpeg; -import com.google.android.exoplayer2.audio.AudioDecoderException; +import com.google.android.exoplayer2.decoder.DecoderException; -/** - * Thrown when an FFmpeg decoder error occurs. - */ -public final class FfmpegDecoderException extends AudioDecoderException { +/** Thrown when an FFmpeg decoder error occurs. */ +public final class FfmpegDecoderException extends DecoderException { /* package */ FfmpegDecoderException(String message) { super(message); diff --git a/extensions/flac/src/main/java/com/google/android/exoplayer2/ext/flac/FlacDecoderException.java b/extensions/flac/src/main/java/com/google/android/exoplayer2/ext/flac/FlacDecoderException.java index 95d7f87c05..2c2f56e06b 100644 --- a/extensions/flac/src/main/java/com/google/android/exoplayer2/ext/flac/FlacDecoderException.java +++ b/extensions/flac/src/main/java/com/google/android/exoplayer2/ext/flac/FlacDecoderException.java @@ -15,12 +15,10 @@ */ package com.google.android.exoplayer2.ext.flac; -import com.google.android.exoplayer2.audio.AudioDecoderException; +import com.google.android.exoplayer2.decoder.DecoderException; -/** - * Thrown when an Flac decoder error occurs. - */ -public final class FlacDecoderException extends AudioDecoderException { +/** Thrown when an Flac decoder error occurs. */ +public final class FlacDecoderException extends DecoderException { /* package */ FlacDecoderException(String message) { super(message); diff --git a/extensions/opus/src/main/java/com/google/android/exoplayer2/ext/opus/OpusDecoderException.java b/extensions/opus/src/main/java/com/google/android/exoplayer2/ext/opus/OpusDecoderException.java index 6645086838..8d9cfea763 100644 --- a/extensions/opus/src/main/java/com/google/android/exoplayer2/ext/opus/OpusDecoderException.java +++ b/extensions/opus/src/main/java/com/google/android/exoplayer2/ext/opus/OpusDecoderException.java @@ -15,12 +15,10 @@ */ package com.google.android.exoplayer2.ext.opus; -import com.google.android.exoplayer2.audio.AudioDecoderException; +import com.google.android.exoplayer2.decoder.DecoderException; -/** - * Thrown when an Opus decoder error occurs. - */ -public final class OpusDecoderException extends AudioDecoderException { +/** Thrown when an Opus decoder error occurs. */ +public final class OpusDecoderException extends DecoderException { /* package */ OpusDecoderException(String message) { super(message); diff --git a/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/LibvpxVideoRenderer.java b/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/LibvpxVideoRenderer.java index 0863f512bb..cadf98b005 100644 --- a/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/LibvpxVideoRenderer.java +++ b/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/LibvpxVideoRenderer.java @@ -26,12 +26,12 @@ import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.PlayerMessage.Target; import com.google.android.exoplayer2.RendererCapabilities; +import com.google.android.exoplayer2.decoder.DecoderException; import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.drm.ExoMediaCrypto; import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.TraceUtil; import com.google.android.exoplayer2.video.DecoderVideoRenderer; -import com.google.android.exoplayer2.video.VideoDecoderException; import com.google.android.exoplayer2.video.VideoDecoderInputBuffer; import com.google.android.exoplayer2.video.VideoDecoderOutputBuffer; import com.google.android.exoplayer2.video.VideoDecoderOutputBufferRenderer; @@ -148,11 +148,8 @@ public class LibvpxVideoRenderer extends DecoderVideoRenderer { @Override protected SimpleDecoder< - VideoDecoderInputBuffer, - ? extends VideoDecoderOutputBuffer, - ? extends VideoDecoderException> - createDecoder(Format format, @Nullable ExoMediaCrypto mediaCrypto) - throws VideoDecoderException { + VideoDecoderInputBuffer, ? extends VideoDecoderOutputBuffer, ? extends DecoderException> + createDecoder(Format format, @Nullable ExoMediaCrypto mediaCrypto) throws DecoderException { TraceUtil.beginSection("createVpxDecoder"); int initialInputBufferSize = format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE; @@ -167,7 +164,7 @@ public class LibvpxVideoRenderer extends DecoderVideoRenderer { @Override protected void renderOutputBuffer( VideoDecoderOutputBuffer outputBuffer, long presentationTimeUs, Format outputFormat) - throws VideoDecoderException { + throws DecoderException { if (frameMetadataListener != null) { frameMetadataListener.onVideoFrameAboutToBeRendered( presentationTimeUs, System.nanoTime(), outputFormat, /* mediaFormat= */ null); diff --git a/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/VpxDecoderException.java b/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/VpxDecoderException.java index b2da9a7ff8..686790bc2c 100644 --- a/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/VpxDecoderException.java +++ b/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/VpxDecoderException.java @@ -15,10 +15,10 @@ */ package com.google.android.exoplayer2.ext.vp9; -import com.google.android.exoplayer2.video.VideoDecoderException; +import com.google.android.exoplayer2.decoder.DecoderException; /** Thrown when a libvpx decoder error occurs. */ -public final class VpxDecoderException extends VideoDecoderException { +public final class VpxDecoderException extends DecoderException { /* package */ VpxDecoderException(String message) { super(message); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/DecoderAudioRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/DecoderAudioRenderer.java index b4bf67528b..e3ef5bd698 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/DecoderAudioRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/DecoderAudioRenderer.java @@ -31,6 +31,7 @@ import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.audio.AudioRendererEventListener.EventDispatcher; import com.google.android.exoplayer2.decoder.Decoder; import com.google.android.exoplayer2.decoder.DecoderCounters; +import com.google.android.exoplayer2.decoder.DecoderException; import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.SimpleOutputBuffer; import com.google.android.exoplayer2.drm.DrmSession; @@ -105,7 +106,7 @@ public abstract class DecoderAudioRenderer extends BaseRenderer implements Media private int encoderPadding; @Nullable - private Decoder + private Decoder decoder; @Nullable private DecoderInputBuffer inputBuffer; @@ -260,8 +261,10 @@ public abstract class DecoderAudioRenderer extends BaseRenderer implements Media while (drainOutputBuffer()) {} while (feedInputBuffer()) {} TraceUtil.endSection(); - } catch (AudioDecoderException | AudioSink.ConfigurationException - | AudioSink.InitializationException | AudioSink.WriteException e) { + } catch (DecoderException + | AudioSink.ConfigurationException + | AudioSink.InitializationException + | AudioSink.WriteException e) { throw createRendererException(e, inputFormat); } decoderCounters.ensureUpdated(); @@ -303,12 +306,11 @@ public abstract class DecoderAudioRenderer extends BaseRenderer implements Media * @param mediaCrypto The {@link ExoMediaCrypto} object required for decoding encrypted content. * Maybe null and can be ignored if decoder does not handle encrypted content. * @return The decoder. - * @throws AudioDecoderException If an error occurred creating a suitable decoder. + * @throws DecoderException If an error occurred creating a suitable decoder. */ protected abstract Decoder< - DecoderInputBuffer, ? extends SimpleOutputBuffer, ? extends AudioDecoderException> - createDecoder(Format format, @Nullable ExoMediaCrypto mediaCrypto) - throws AudioDecoderException; + DecoderInputBuffer, ? extends SimpleOutputBuffer, ? extends DecoderException> + createDecoder(Format format, @Nullable ExoMediaCrypto mediaCrypto) throws DecoderException; /** * Returns the format of audio buffers output by the decoder. Will not be called until the first @@ -327,9 +329,9 @@ public abstract class DecoderAudioRenderer extends BaseRenderer implements Media return false; } - private boolean drainOutputBuffer() throws ExoPlaybackException, AudioDecoderException, - AudioSink.ConfigurationException, AudioSink.InitializationException, - AudioSink.WriteException { + private boolean drainOutputBuffer() + throws ExoPlaybackException, DecoderException, AudioSink.ConfigurationException, + AudioSink.InitializationException, AudioSink.WriteException { if (outputBuffer == null) { outputBuffer = decoder.dequeueOutputBuffer(); if (outputBuffer == null) { @@ -374,7 +376,7 @@ public abstract class DecoderAudioRenderer extends BaseRenderer implements Media return false; } - private boolean feedInputBuffer() throws AudioDecoderException, ExoPlaybackException { + private boolean feedInputBuffer() throws DecoderException, ExoPlaybackException { if (decoder == null || decoderReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM || inputStreamEnded) { // We need to reinitialize the decoder or the input stream has ended. @@ -607,7 +609,7 @@ public abstract class DecoderAudioRenderer extends BaseRenderer implements Media eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp, codecInitializedTimestamp - codecInitializingTimestamp); decoderCounters.decoderInitCount++; - } catch (AudioDecoderException e) { + } catch (DecoderException e) { throw createRendererException(e, inputFormat); } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioDecoderException.java b/library/core/src/main/java/com/google/android/exoplayer2/decoder/DecoderException.java similarity index 79% rename from library/core/src/main/java/com/google/android/exoplayer2/audio/AudioDecoderException.java rename to library/core/src/main/java/com/google/android/exoplayer2/decoder/DecoderException.java index ac4f632d62..c07e646f09 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioDecoderException.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/decoder/DecoderException.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.android.exoplayer2.audio; +package com.google.android.exoplayer2.decoder; -/** Thrown when an audio decoder error occurs. */ -public class AudioDecoderException extends Exception { +/** Thrown when a {@link Decoder} error occurs. */ +public class DecoderException extends Exception { /** @param message The detail message for this exception. */ - public AudioDecoderException(String message) { + public DecoderException(String message) { super(message); } @@ -28,8 +28,7 @@ public class AudioDecoderException extends Exception { * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). * A null value is permitted, and indicates that the cause is nonexistent or unknown. */ - public AudioDecoderException(String message, Throwable cause) { + public DecoderException(String message, Throwable cause) { super(message, cause); } - } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecDecoderException.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecDecoderException.java new file mode 100644 index 0000000000..524f8568f7 --- /dev/null +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecDecoderException.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2.mediacodec; + +import android.media.MediaCodec; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; +import com.google.android.exoplayer2.decoder.DecoderException; +import com.google.android.exoplayer2.util.Util; + +/** Thrown when a failure occurs in a {@link MediaCodec} decoder. */ +public class MediaCodecDecoderException extends DecoderException { + + /** The {@link MediaCodecInfo} of the decoder that failed. Null if unknown. */ + @Nullable public final MediaCodecInfo codecInfo; + + /** An optional developer-readable diagnostic information string. May be null. */ + @Nullable public final String diagnosticInfo; + + public MediaCodecDecoderException(Throwable cause, @Nullable MediaCodecInfo codecInfo) { + super("Decoder failed: " + (codecInfo == null ? null : codecInfo.name), cause); + this.codecInfo = codecInfo; + diagnosticInfo = Util.SDK_INT >= 21 ? getDiagnosticInfoV21(cause) : null; + } + + @RequiresApi(21) + @Nullable + private static String getDiagnosticInfoV21(Throwable cause) { + if (cause instanceof MediaCodec.CodecException) { + return ((MediaCodec.CodecException) cause).getDiagnosticInfo(); + } + return 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 e2a67301da..ba14f0e1dd 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 @@ -224,30 +224,6 @@ public abstract class MediaCodecRenderer extends BaseRenderer { } } - /** Thrown when a failure occurs in the decoder. */ - public static class DecoderException extends Exception { - - /** The {@link MediaCodecInfo} of the decoder that failed. Null if unknown. */ - @Nullable public final MediaCodecInfo codecInfo; - - /** An optional developer-readable diagnostic information string. May be null. */ - @Nullable public final String diagnosticInfo; - - public DecoderException(Throwable cause, @Nullable MediaCodecInfo codecInfo) { - super("Decoder failed: " + (codecInfo == null ? null : codecInfo.name), cause); - this.codecInfo = codecInfo; - diagnosticInfo = Util.SDK_INT >= 21 ? getDiagnosticInfoV21(cause) : null; - } - - @RequiresApi(21) - private static String getDiagnosticInfoV21(Throwable cause) { - if (cause instanceof CodecException) { - return ((CodecException) cause).getDiagnosticInfo(); - } - return null; - } - } - /** Indicates no codec operating rate should be set. */ protected static final float CODEC_OPERATING_RATE_UNSET = -1; @@ -926,9 +902,9 @@ public abstract class MediaCodecRenderer extends BaseRenderer { mediaCryptoRequiresSecureDecoder = false; } - protected DecoderException createDecoderException( + protected MediaCodecDecoderException createDecoderException( Throwable cause, @Nullable MediaCodecInfo codecInfo) { - return new DecoderException(cause, codecInfo); + return new MediaCodecDecoderException(cause, codecInfo); } /** Reads into {@link #flagsOnlyBuffer} and returns whether a {@link Format} was read. */ diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/DecoderVideoRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/video/DecoderVideoRenderer.java index cc0a9cdd95..8602bc5a4e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/DecoderVideoRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/DecoderVideoRenderer.java @@ -28,6 +28,7 @@ import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.FormatHolder; import com.google.android.exoplayer2.decoder.Decoder; import com.google.android.exoplayer2.decoder.DecoderCounters; +import com.google.android.exoplayer2.decoder.DecoderException; import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.drm.DrmSession; import com.google.android.exoplayer2.drm.DrmSession.DrmSessionException; @@ -77,9 +78,7 @@ public abstract class DecoderVideoRenderer extends BaseRenderer { private Format inputFormat; private Format outputFormat; private Decoder< - VideoDecoderInputBuffer, - ? extends VideoDecoderOutputBuffer, - ? extends VideoDecoderException> + VideoDecoderInputBuffer, ? extends VideoDecoderOutputBuffer, ? extends DecoderException> decoder; private VideoDecoderInputBuffer inputBuffer; private VideoDecoderOutputBuffer outputBuffer; @@ -179,7 +178,7 @@ public abstract class DecoderVideoRenderer extends BaseRenderer { while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {} while (feedInputBuffer()) {} TraceUtil.endSection(); - } catch (VideoDecoderException e) { + } catch (DecoderException e) { throw createRendererException(e, inputFormat); } decoderCounters.ensureUpdated(); @@ -488,14 +487,11 @@ public abstract class DecoderVideoRenderer extends BaseRenderer { * @param mediaCrypto The {@link ExoMediaCrypto} object required for decoding encrypted content. * May be null and can be ignored if decoder does not handle encrypted content. * @return The decoder. - * @throws VideoDecoderException If an error occurred creating a suitable decoder. + * @throws DecoderException If an error occurred creating a suitable decoder. */ protected abstract Decoder< - VideoDecoderInputBuffer, - ? extends VideoDecoderOutputBuffer, - ? extends VideoDecoderException> - createDecoder(Format format, @Nullable ExoMediaCrypto mediaCrypto) - throws VideoDecoderException; + VideoDecoderInputBuffer, ? extends VideoDecoderOutputBuffer, ? extends DecoderException> + createDecoder(Format format, @Nullable ExoMediaCrypto mediaCrypto) throws DecoderException; /** * Renders the specified output buffer. @@ -506,11 +502,11 @@ public abstract class DecoderVideoRenderer extends BaseRenderer { * @param outputBuffer {@link VideoDecoderOutputBuffer} to render. * @param presentationTimeUs Presentation time in microseconds. * @param outputFormat Output {@link Format}. - * @throws VideoDecoderException If an error occurs when rendering the output buffer. + * @throws DecoderException If an error occurs when rendering the output buffer. */ protected void renderOutputBuffer( VideoDecoderOutputBuffer outputBuffer, long presentationTimeUs, Format outputFormat) - throws VideoDecoderException { + throws DecoderException { lastRenderTimeUs = C.msToUs(SystemClock.elapsedRealtime() * 1000); int bufferMode = outputBuffer.mode; boolean renderSurface = bufferMode == C.VIDEO_OUTPUT_MODE_SURFACE_YUV && surface != null; @@ -538,10 +534,10 @@ public abstract class DecoderVideoRenderer extends BaseRenderer { * * @param outputBuffer {@link VideoDecoderOutputBuffer} to render. * @param surface Output {@link Surface}. - * @throws VideoDecoderException If an error occurs when rendering the output buffer. + * @throws DecoderException If an error occurs when rendering the output buffer. */ protected abstract void renderOutputBufferToSurface( - VideoDecoderOutputBuffer outputBuffer, Surface surface) throws VideoDecoderException; + VideoDecoderOutputBuffer outputBuffer, Surface surface) throws DecoderException; /** * Sets output surface. @@ -651,12 +647,12 @@ public abstract class DecoderVideoRenderer extends BaseRenderer { decoderInitializedTimestamp, decoderInitializedTimestamp - decoderInitializingTimestamp); decoderCounters.decoderInitCount++; - } catch (VideoDecoderException e) { + } catch (DecoderException e) { throw createRendererException(e, inputFormat); } } - private boolean feedInputBuffer() throws VideoDecoderException, ExoPlaybackException { + private boolean feedInputBuffer() throws DecoderException, ExoPlaybackException { if (decoder == null || decoderReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM || inputStreamEnded) { @@ -732,7 +728,7 @@ public abstract class DecoderVideoRenderer extends BaseRenderer { * @throws ExoPlaybackException If an error occurs draining the output buffer. */ private boolean drainOutputBuffer(long positionUs, long elapsedRealtimeUs) - throws ExoPlaybackException, VideoDecoderException { + throws ExoPlaybackException, DecoderException { if (outputBuffer == null) { outputBuffer = decoder.dequeueOutputBuffer(); if (outputBuffer == null) { @@ -774,7 +770,7 @@ public abstract class DecoderVideoRenderer extends BaseRenderer { * @throws ExoPlaybackException If an error occurs processing the output buffer. */ private boolean processOutputBuffer(long positionUs, long elapsedRealtimeUs) - throws ExoPlaybackException, VideoDecoderException { + throws ExoPlaybackException, DecoderException { if (initialPositionUs == C.TIME_UNSET) { initialPositionUs = positionUs; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoDecoderException.java b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoDecoderException.java new file mode 100644 index 0000000000..9846ecdca6 --- /dev/null +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoDecoderException.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2.video; + +import android.media.MediaCodec; +import android.view.Surface; +import androidx.annotation.Nullable; +import com.google.android.exoplayer2.mediacodec.MediaCodecDecoderException; +import com.google.android.exoplayer2.mediacodec.MediaCodecInfo; + +/** Thrown when a failure occurs in a {@link MediaCodec} video decoder. */ +public class MediaCodecVideoDecoderException extends MediaCodecDecoderException { + + /** The {@link System#identityHashCode(Object)} of the surface when the exception occurred. */ + public final int surfaceIdentityHashCode; + + /** Whether the surface was valid when the exception occurred. */ + public final boolean isSurfaceValid; + + public MediaCodecVideoDecoderException( + Throwable cause, @Nullable MediaCodecInfo codecInfo, @Nullable Surface surface) { + super(cause, codecInfo); + surfaceIdentityHashCode = System.identityHashCode(surface); + isSurfaceValid = surface == null || surface.isValid(); + } +} 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 a3a17da8c2..d3a7d5cec6 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 @@ -43,6 +43,7 @@ import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.drm.DrmInitData; import com.google.android.exoplayer2.drm.FrameworkMediaCrypto; +import com.google.android.exoplayer2.mediacodec.MediaCodecDecoderException; import com.google.android.exoplayer2.mediacodec.MediaCodecInfo; import com.google.android.exoplayer2.mediacodec.MediaCodecRenderer; import com.google.android.exoplayer2.mediacodec.MediaCodecSelector; @@ -95,23 +96,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { /** Magic frame render timestamp that indicates the EOS in tunneling mode. */ private static final long TUNNELING_EOS_PRESENTATION_TIME_US = Long.MAX_VALUE; - /** A {@link DecoderException} with additional surface information. */ - public static final class VideoDecoderException extends DecoderException { - - /** The {@link System#identityHashCode(Object)} of the surface when the exception occurred. */ - public final int surfaceIdentityHashCode; - - /** Whether the surface was valid when the exception occurred. */ - public final boolean isSurfaceValid; - - public VideoDecoderException( - Throwable cause, @Nullable MediaCodecInfo codecInfo, @Nullable Surface surface) { - super(cause, codecInfo); - surfaceIdentityHashCode = System.identityHashCode(surface); - isSurfaceValid = surface == null || surface.isValid(); - } - } - private static boolean evaluatedDeviceNeedsSetOutputSurfaceWorkaround; private static boolean deviceNeedsSetOutputSurfaceWorkaround; @@ -1303,9 +1287,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { } @Override - protected DecoderException createDecoderException( + protected MediaCodecDecoderException createDecoderException( Throwable cause, @Nullable MediaCodecInfo codecInfo) { - return new VideoDecoderException(cause, codecInfo, surface); + return new MediaCodecVideoDecoderException(cause, codecInfo, surface); } /** diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderException.java b/library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderException.java deleted file mode 100644 index 68108af636..0000000000 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.android.exoplayer2.video; - -/** Thrown when a video decoder error occurs. */ -public class VideoDecoderException extends Exception { - - /** - * Creates an instance with the given message. - * - * @param message The detail message for this exception. - */ - public VideoDecoderException(String message) { - super(message); - } - - /** - * Creates an instance with the given message and cause. - * - * @param message The detail message for this exception. - * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). - * A null value is permitted, and indicates that the cause is nonexistent or unknown. - */ - public VideoDecoderException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/library/core/src/test/java/com/google/android/exoplayer2/audio/DecoderAudioRendererTest.java b/library/core/src/test/java/com/google/android/exoplayer2/audio/DecoderAudioRendererTest.java index a73e703d51..29f2b65015 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/audio/DecoderAudioRendererTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/audio/DecoderAudioRendererTest.java @@ -29,6 +29,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.RendererConfiguration; +import com.google.android.exoplayer2.decoder.DecoderException; import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.decoder.SimpleOutputBuffer; @@ -65,7 +66,7 @@ public class DecoderAudioRendererTest { @Override protected SimpleDecoder< - DecoderInputBuffer, ? extends SimpleOutputBuffer, ? extends AudioDecoderException> + DecoderInputBuffer, ? extends SimpleOutputBuffer, ? extends DecoderException> createDecoder(Format format, @Nullable ExoMediaCrypto mediaCrypto) { return new FakeDecoder(); } @@ -114,7 +115,7 @@ public class DecoderAudioRendererTest { } private static final class FakeDecoder - extends SimpleDecoder { + extends SimpleDecoder { public FakeDecoder() { super(new DecoderInputBuffer[1], new SimpleOutputBuffer[1]); @@ -136,13 +137,13 @@ public class DecoderAudioRendererTest { } @Override - protected AudioDecoderException createUnexpectedDecodeException(Throwable error) { - return new AudioDecoderException("Unexpected decode error", error); + protected DecoderException createUnexpectedDecodeException(Throwable error) { + return new DecoderException("Unexpected decode error", error); } @Override - protected AudioDecoderException decode(DecoderInputBuffer inputBuffer, - SimpleOutputBuffer outputBuffer, boolean reset) { + protected DecoderException decode( + DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) { if (inputBuffer.isEndOfStream()) { outputBuffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM); } diff --git a/library/core/src/test/java/com/google/android/exoplayer2/video/DecoderVideoRendererTest.java b/library/core/src/test/java/com/google/android/exoplayer2/video/DecoderVideoRendererTest.java index cab0a5b2c8..4e7291a616 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/video/DecoderVideoRendererTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/video/DecoderVideoRendererTest.java @@ -31,6 +31,7 @@ import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.RendererConfiguration; +import com.google.android.exoplayer2.decoder.DecoderException; import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.drm.ExoMediaCrypto; import com.google.android.exoplayer2.testutil.FakeSampleStream; @@ -128,10 +129,10 @@ public final class DecoderVideoRendererTest { protected SimpleDecoder< VideoDecoderInputBuffer, ? extends VideoDecoderOutputBuffer, - ? extends VideoDecoderException> + ? extends DecoderException> createDecoder(Format format, @Nullable ExoMediaCrypto mediaCrypto) { return new SimpleDecoder< - VideoDecoderInputBuffer, VideoDecoderOutputBuffer, VideoDecoderException>( + VideoDecoderInputBuffer, VideoDecoderOutputBuffer, DecoderException>( new VideoDecoderInputBuffer[10], new VideoDecoderOutputBuffer[10]) { @Override protected VideoDecoderInputBuffer createInputBuffer() { @@ -144,13 +145,13 @@ public final class DecoderVideoRendererTest { } @Override - protected VideoDecoderException createUnexpectedDecodeException(Throwable error) { - return new VideoDecoderException("error", error); + protected DecoderException createUnexpectedDecodeException(Throwable error) { + return new DecoderException("error", error); } @Nullable @Override - protected VideoDecoderException decode( + protected DecoderException decode( VideoDecoderInputBuffer inputBuffer, VideoDecoderOutputBuffer outputBuffer, boolean reset) {