Skip to content

Commit

Permalink
Fix 'legacy' CEA-608 and CEA-708 to use the Decoder impls
Browse files Browse the repository at this point in the history
We deliberately left `Cea608Decoder` and `Cea708Decoder` intact when
creating the respective `SubtitleParser` implementations (in
27caeb8
and
94e45eb
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: #904.
PiperOrigin-RevId: 592217937
  • Loading branch information
icbaker authored and copybara-github committed Dec 19, 2023
1 parent e10f96d commit 7ca26f8
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@

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
Expand All @@ -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() {
Expand All @@ -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);
}
Expand Down

0 comments on commit 7ca26f8

Please sign in to comment.