Skip to content

Commit

Permalink
Add DefaultExtractorsFactory.setTsSubtitleFormats
Browse files Browse the repository at this point in the history
ExoPlayer is unable to detect the presence of subtitle tracks in some
MPEG-TS files that don't fully declare them. It's possible for a
developer to provide the list instead, but doing so is quite awkward
without this helper method. This is consistent for how
`DefaultExtractorsFactory` allows other aspects of the delegate
`Extractor` implementations to be customised.

* Issue: google/ExoPlayer#10175
* Issue: google/ExoPlayer#10505

#minor-release

PiperOrigin-RevId: 490214619
  • Loading branch information
icbaker authored and microkatz committed Nov 22, 2022
1 parent c41a5c8 commit ff48fae
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable;
import androidx.media3.common.FileTypes;
import androidx.media3.common.Format;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.media3.common.util.TimestampAdjuster;
Expand All @@ -44,6 +45,7 @@
import androidx.media3.extractor.ts.TsExtractor;
import androidx.media3.extractor.ts.TsPayloadReader;
import androidx.media3.extractor.wav.WavExtractor;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -128,11 +130,13 @@ public final class DefaultExtractorsFactory implements ExtractorsFactory {
private @Mp3Extractor.Flags int mp3Flags;
private @TsExtractor.Mode int tsMode;
private @DefaultTsPayloadReaderFactory.Flags int tsFlags;
private ImmutableList<Format> tsSubtitleFormats;
private int tsTimestampSearchBytes;

public DefaultExtractorsFactory() {
tsMode = TsExtractor.MODE_SINGLE_PMT;
tsTimestampSearchBytes = TsExtractor.DEFAULT_TIMESTAMP_SEARCH_BYTES;
tsSubtitleFormats = ImmutableList.of();
}

/**
Expand Down Expand Up @@ -303,6 +307,20 @@ public synchronized DefaultExtractorsFactory setTsExtractorFlags(
return this;
}

/**
* Sets a list of subtitle formats to pass to the {@link DefaultTsPayloadReaderFactory} used by
* {@link TsExtractor} instances created by the factory.
*
* @see DefaultTsPayloadReaderFactory#DefaultTsPayloadReaderFactory(int, List)
* @param subtitleFormats The subtitle formats.
* @return The factory, for convenience.
*/
@CanIgnoreReturnValue
public synchronized DefaultExtractorsFactory setTsSubtitleFormats(List<Format> subtitleFormats) {
tsSubtitleFormats = ImmutableList.copyOf(subtitleFormats);
return this;
}

/**
* Sets the number of bytes searched to find a timestamp for {@link TsExtractor} instances created
* by the factory.
Expand Down Expand Up @@ -416,7 +434,12 @@ private void addExtractorsForFileType(@FileTypes.Type int fileType, List<Extract
extractors.add(new PsExtractor());
break;
case FileTypes.TS:
extractors.add(new TsExtractor(tsMode, tsFlags, tsTimestampSearchBytes));
extractors.add(
new TsExtractor(
tsMode,
new TimestampAdjuster(0),
new DefaultTsPayloadReaderFactory(tsFlags, tsSubtitleFormats),
tsTimestampSearchBytes));
break;
case FileTypes.WAV:
extractors.add(new WavExtractor());
Expand Down

0 comments on commit ff48fae

Please sign in to comment.