File tree Expand file tree Collapse file tree 6 files changed +40
-7
lines changed
av1/src/main/java/com/google/android/exoplayer2/ext/av1
ffmpeg/src/main/java/com/google/android/exoplayer2/ext/ffmpeg
vp9/src/main/java/com/google/android/exoplayer2/ext/vp9
library/core/src/main/java/com/google/android/exoplayer2 Expand file tree Collapse file tree 6 files changed +40
-7
lines changed Original file line number Diff line number Diff line change @@ -162,4 +162,9 @@ protected void setDecoderOutputMode(@C.VideoOutputMode int outputMode) {
162162 decoder .setOutputMode (outputMode );
163163 }
164164 }
165+
166+ @ Override
167+ protected boolean canKeepCodec (Format oldFormat , Format newFormat ) {
168+ return true ;
169+ }
165170}
Original file line number Diff line number Diff line change @@ -56,7 +56,8 @@ public static boolean isAvailable() {
5656 }
5757
5858 /** Returns the version of the underlying library if available, or null otherwise. */
59- public static @ Nullable String getVersion () {
59+ @ Nullable
60+ public static String getVersion () {
6061 return isAvailable () ? ffmpegGetVersion () : null ;
6162 }
6263
@@ -69,7 +70,7 @@ public static boolean supportsFormat(String mimeType) {
6970 if (!isAvailable ()) {
7071 return false ;
7172 }
72- String codecName = getCodecName (mimeType );
73+ @ Nullable String codecName = getCodecName (mimeType );
7374 if (codecName == null ) {
7475 return false ;
7576 }
@@ -84,7 +85,8 @@ public static boolean supportsFormat(String mimeType) {
8485 * Returns the name of the FFmpeg decoder that could be used to decode the format, or {@code null}
8586 * if it's unsupported.
8687 */
87- /* package */ static @ Nullable String getCodecName (String mimeType ) {
88+ @ Nullable
89+ /* package */ static String getCodecName (String mimeType ) {
8890 switch (mimeType ) {
8991 case MimeTypes .AUDIO_AAC :
9092 return "aac" ;
Original file line number Diff line number Diff line change 2424import com .google .android .exoplayer2 .decoder .Decoder ;
2525import com .google .android .exoplayer2 .drm .ExoMediaCrypto ;
2626import com .google .android .exoplayer2 .util .TraceUtil ;
27+ import com .google .android .exoplayer2 .util .Util ;
2728import com .google .android .exoplayer2 .video .DecoderVideoRenderer ;
2829import com .google .android .exoplayer2 .video .VideoDecoderInputBuffer ;
2930import com .google .android .exoplayer2 .video .VideoDecoderOutputBuffer ;
@@ -113,4 +114,9 @@ protected void setDecoderOutputMode(@C.VideoOutputMode int outputMode) {
113114 }
114115 */
115116 }
117+
118+ @ Override
119+ protected boolean canKeepCodec (Format oldFormat , Format newFormat ) {
120+ return Util .areEqual (oldFormat .sampleMimeType , newFormat .sampleMimeType );
121+ }
116122}
Original file line number Diff line number Diff line change @@ -168,4 +168,9 @@ protected void setDecoderOutputMode(@C.VideoOutputMode int outputMode) {
168168 decoder .setOutputMode (outputMode );
169169 }
170170 }
171+
172+ @ Override
173+ protected boolean canKeepCodec (Format oldFormat , Format newFormat ) {
174+ return true ;
175+ }
171176}
Original file line number Diff line number Diff line change @@ -323,7 +323,7 @@ protected void onAudioTrackSkipSilenceEnabledChanged(boolean skipSilenceEnabled)
323323 *
324324 * @param oldFormat The previous format.
325325 * @param newFormat The new format.
326- * @return True if the existing decoder can be kept.
326+ * @return Whether the existing decoder can be kept.
327327 */
328328 protected boolean canKeepCodec (Format oldFormat , Format newFormat ) {
329329 return false ;
@@ -643,7 +643,9 @@ private void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackE
643643 Format oldFormat = inputFormat ;
644644 inputFormat = newFormat ;
645645
646- if (!canKeepCodec (oldFormat , inputFormat )) {
646+ if (decoder == null ) {
647+ maybeInitDecoder ();
648+ } else if (sourceDrmSession != decoderDrmSession || !canKeepCodec (oldFormat , inputFormat )) {
647649 if (decoderReceivedBuffers ) {
648650 // Signal end of stream and wait for any final output buffers before re-initialization.
649651 decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM ;
@@ -657,7 +659,6 @@ private void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackE
657659
658660 encoderDelay = inputFormat .encoderDelay ;
659661 encoderPadding = inputFormat .encoderPadding ;
660-
661662 eventDispatcher .inputFormatChanged (inputFormat );
662663 }
663664
Original file line number Diff line number Diff line change @@ -379,9 +379,12 @@ protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybac
379379 waitingForFirstSampleInFormat = true ;
380380 Format newFormat = Assertions .checkNotNull (formatHolder .format );
381381 setSourceDrmSession (formatHolder .drmSession );
382+ Format oldFormat = inputFormat ;
382383 inputFormat = newFormat ;
383384
384- if (sourceDrmSession != decoderDrmSession ) {
385+ if (decoder == null ) {
386+ maybeInitDecoder ();
387+ } else if (sourceDrmSession != decoderDrmSession || !canKeepCodec (oldFormat , inputFormat )) {
385388 if (decoderReceivedBuffers ) {
386389 // Signal end of stream and wait for any final output buffers before re-initialization.
387390 decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM ;
@@ -640,6 +643,17 @@ protected final void setOutputBufferRenderer(
640643 */
641644 protected abstract void setDecoderOutputMode (@ C .VideoOutputMode int outputMode );
642645
646+ /**
647+ * Returns whether the existing decoder can be kept for a new format.
648+ *
649+ * @param oldFormat The previous format.
650+ * @param newFormat The new format.
651+ * @return Whether the existing decoder can be kept.
652+ */
653+ protected boolean canKeepCodec (Format oldFormat , Format newFormat ) {
654+ return false ;
655+ }
656+
643657 // Internal methods.
644658
645659 private void setSourceDrmSession (@ Nullable DrmSession session ) {
You can’t perform that action at this time.
0 commit comments