From 7ca26f898d4b4791d1a91cff136352ea13e917be Mon Sep 17 00:00:00 2001 From: ibaker Date: Tue, 19 Dec 2023 06:28:45 -0800 Subject: [PATCH] Fix 'legacy' CEA-608 and CEA-708 to use the `Decoder` impls We deliberately left `Cea608Decoder` and `Cea708Decoder` intact when creating the respective `SubtitleParser` implementations (in https://github.com/androidx/media/commit/27caeb8038675afee922c16ce2ef93689ed03121 and https://github.com/androidx/media/commit/94e45eb4ad57a8d31746ed40bdcb10d35053adbb respectively). However we didn't correctly change the behaviour of `SubtitleDecoderFactory.DEFAULT` in order to use these 'legacy' implementations. We firstly left the `Cea608Decoder` instantiation **after** the `DefaultSubtitleParserFactory.supportsFormat()` check, meaning that code would never be reached (since `supportsFormat` now returns true for CEA-608). Then in the second change (which was supposed to only be about CEA-708) we removed all instantiations of **both** `Cea608Decoder` and `Cea708Decoder`. This change puts the decoder instantiations back and moves them above the `DefaultSubtitleParserFactory.supportsFormat` check, meaning they will be used in preference to `DelegatingSubtitleDecoder`. This resolves the immediately-disappearing subtitles tracked by Issue: androidx/media#904. PiperOrigin-RevId: 592217937 --- .../text/SubtitleDecoderFactory.java | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/SubtitleDecoderFactory.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/SubtitleDecoderFactory.java index 7339720ece..24d7cab070 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/SubtitleDecoderFactory.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/SubtitleDecoderFactory.java @@ -17,10 +17,16 @@ package androidx.media3.exoplayer.text; import androidx.annotation.Nullable; import androidx.media3.common.Format; +import androidx.media3.common.MimeTypes; import androidx.media3.common.util.UnstableApi; import androidx.media3.extractor.text.DefaultSubtitleParserFactory; import androidx.media3.extractor.text.SubtitleDecoder; import androidx.media3.extractor.text.SubtitleParser; +import androidx.media3.extractor.text.cea.Cea608Decoder; +import androidx.media3.extractor.text.cea.Cea608Parser; +import androidx.media3.extractor.text.cea.Cea708Decoder; +import androidx.media3.extractor.text.cea.Cea708Parser; +import java.util.Objects; /** A factory for {@link SubtitleDecoder} instances. */ @UnstableApi @@ -47,7 +53,12 @@ public interface SubtitleDecoderFactory { /** * Default {@link SubtitleDecoderFactory} implementation. * - *

Only supports formats supported by {@link DefaultSubtitleParserFactory}. + *

Supports formats supported by {@link DefaultSubtitleParserFactory} as well as the following: + * + *

*/ SubtitleDecoderFactory DEFAULT = new SubtitleDecoderFactory() { @@ -56,17 +67,37 @@ public interface SubtitleDecoderFactory { @Override public boolean supportsFormat(Format format) { - return delegate.supportsFormat(format); + @Nullable String mimeType = format.sampleMimeType; + return delegate.supportsFormat(format) + || Objects.equals(mimeType, MimeTypes.APPLICATION_CEA608) + || Objects.equals(mimeType, MimeTypes.APPLICATION_MP4CEA608) + || Objects.equals(mimeType, MimeTypes.APPLICATION_CEA708); } @Override public SubtitleDecoder createDecoder(Format format) { + @Nullable String mimeType = format.sampleMimeType; + if (mimeType != null) { + switch (mimeType) { + case MimeTypes.APPLICATION_CEA608: + case MimeTypes.APPLICATION_MP4CEA608: + return new Cea608Decoder( + new Cea608Parser( + mimeType, + format.accessibilityChannel, + Cea608Parser.MIN_DATA_CHANNEL_TIMEOUT_MS)); + case MimeTypes.APPLICATION_CEA708: + return new Cea708Decoder( + new Cea708Parser(format.accessibilityChannel, format.initializationData)); + default: + break; + } + } if (delegate.supportsFormat(format)) { SubtitleParser subtitleParser = delegate.create(format); return new DelegatingSubtitleDecoder( subtitleParser.getClass().getSimpleName() + "Decoder", subtitleParser); } - @Nullable String mimeType = format.sampleMimeType; throw new IllegalArgumentException( "Attempted to create decoder for unsupported MIME type: " + mimeType); }