mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
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 (in27caeb8038and94e45eb4adrespectively). 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
This commit is contained in:
parent
e10f96d6a6
commit
7ca26f898d
1 changed files with 34 additions and 3 deletions
|
|
@ -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.
|
||||
*
|
||||
* <p>Only supports formats supported by {@link DefaultSubtitleParserFactory}.
|
||||
* <p>Supports formats supported by {@link DefaultSubtitleParserFactory} as well as the following:
|
||||
*
|
||||
* <ul>
|
||||
* <li>Cea608 ({@link Cea608Decoder})
|
||||
* <li>Cea708 ({@link Cea708Decoder})
|
||||
* </ul>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue