/** * @param flags A combination of {@code FLAG_*} values that control the behavior of the created * readers. */ public DefaultTsPayloadReaderFactory(@Flags int flags) { this( flags, Collections.singletonList( Format.createTextSampleFormat(null, MimeTypes.APPLICATION_CEA608, 0, null))); }
public static Format createTextSampleFormat( @Nullable String id, String sampleMimeType, @C.SelectionFlags int selectionFlags, @Nullable String language, @Nullable DrmInitData drmInitData) { return createTextSampleFormat( id, sampleMimeType, /* codecs= */ null, /* bitrate= */ NO_VALUE, selectionFlags, language, NO_VALUE, drmInitData, OFFSET_SAMPLE_RELATIVE, Collections.emptyList()); }
Format.createTextSampleFormat( Integer.toString(trackId), mimeType,
private TrackOutput buildTrackOutput(long subsampleOffsetUs) { TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_TEXT); trackOutput.format(Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, null, Format.NO_VALUE, 0, language, null, subsampleOffsetUs)); output.endTracks(); return trackOutput; }
public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) { for (int i = 0; i < outputs.length; i++) { idGenerator.generateNewId(); TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT); Format channelFormat = closedCaptionFormats.get(i); String channelMimeType = channelFormat.sampleMimeType; Assertions.checkArgument(MimeTypes.APPLICATION_CEA608.equals(channelMimeType) || MimeTypes.APPLICATION_CEA708.equals(channelMimeType), "Invalid closed caption mime type provided: " + channelMimeType); String formatId = channelFormat.id != null ? channelFormat.id : idGenerator.getFormatId(); output.format( Format.createTextSampleFormat( formatId, channelMimeType, /* codecs= */ null, /* bitrate= */ Format.NO_VALUE, channelFormat.selectionFlags, channelFormat.language, channelFormat.accessibilityChannel, /* drmInitData= */ null, Format.OFFSET_SAMPLE_RELATIVE, channelFormat.initializationData)); outputs[i] = output; } }
public void createTracks( ExtractorOutput extractorOutput, TsPayloadReader.TrackIdGenerator idGenerator) { for (int i = 0; i < outputs.length; i++) { idGenerator.generateNewId(); TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT); Format channelFormat = closedCaptionFormats.get(i); String channelMimeType = channelFormat.sampleMimeType; Assertions.checkArgument( MimeTypes.APPLICATION_CEA608.equals(channelMimeType) || MimeTypes.APPLICATION_CEA708.equals(channelMimeType), "Invalid closed caption mime type provided: " + channelMimeType); output.format( Format.createTextSampleFormat( idGenerator.getFormatId(), channelMimeType, /* codecs= */ null, /* bitrate= */ Format.NO_VALUE, channelFormat.selectionFlags, channelFormat.language, channelFormat.accessibilityChannel, /* drmInitData= */ null, Format.OFFSET_SAMPLE_RELATIVE, channelFormat.initializationData)); outputs[i] = output; } }
enableCea608Track ? Collections.singletonList( Format.createTextSampleFormat(null, MimeTypes.APPLICATION_CEA608, 0, null)) : Collections.emptyList(); extractor =
Format format = Format.createTextSampleFormat(firstAdaptationSet.id + ":cea608", MimeTypes.APPLICATION_CEA608, 0, null); trackGroups[cea608TrackGroupIndex] = new TrackGroup(format);
@Test public void testSampleWithSeiPayloadParsing() throws Exception { // Enabling the CEA-608 track enables SEI payload parsing. ExtractorFactory extractorFactory = getExtractorFactory( Collections.singletonList( Format.createTextSampleFormat(null, MimeTypes.APPLICATION_CEA608, 0, null))); ExtractorAsserts.assertBehavior(extractorFactory, "mp4/sample_fragmented_sei.mp4"); }
} else if (MimeTypes.APPLICATION_SUBRIP.equals(mimeType)) { type = C.TRACK_TYPE_TEXT; format = Format.createTextSampleFormat(Integer.toString(trackId), mimeType, selectionFlags, language, drmInitData); } else if (MimeTypes.TEXT_SSA.equals(mimeType)) { initializationData.add(SSA_DIALOGUE_FORMAT); initializationData.add(codecPrivate); format = Format.createTextSampleFormat(Integer.toString(trackId), mimeType, null, Format.NO_VALUE, selectionFlags, language, Format.NO_VALUE, drmInitData, Format.OFFSET_SAMPLE_RELATIVE, initializationData);
if (mimeType == null) continue; final Format textFormat = Format.createTextSampleFormat(null, mimeType, SELECTION_FLAG_AUTOSELECT, PlayerHelper.captionLanguageOf(context, subtitle)); final MediaSource textSource = dataSource.getSampleMediaSourceFactory()
@Override public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) { idGenerator.generateNewId(); output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_UNKNOWN); output.format( Format.createTextSampleFormat( idGenerator.getFormatId(), "mime", null, 0, 0, language, null, 0)); }
Format format = Format.createTextSampleFormat(null, timedTextSource.getMimeType(), timedTextSource.getFlag(), null); MediaSource timedTextMediaSource = new SingleSampleMediaSource.Factory(new DefaultDataSourceFactory(mAppContext, Util.getUserAgent(mAppContext, mAppContext.getPackageName())))
int accessibilityChannel, @Nullable DrmInitData drmInitData) { return createTextSampleFormat( id, sampleMimeType, @Nullable DrmInitData drmInitData, long subsampleOffsetUs) { return createTextSampleFormat( id, sampleMimeType,
@Test public void testCustomPesReader() throws Exception { CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(true, false); TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_MULTI_PMT, new TimestampAdjuster(0), factory); FakeExtractorInput input = new FakeExtractorInput.Builder() .setData(TestUtil.getByteArray(RuntimeEnvironment.application, "ts/sample.ts")) .setSimulateIOErrors(false) .setSimulateUnknownLength(false) .setSimulatePartialReads(false) .build(); FakeExtractorOutput output = new FakeExtractorOutput(); tsExtractor.init(output); PositionHolder seekPositionHolder = new PositionHolder(); int readResult = Extractor.RESULT_CONTINUE; while (readResult != Extractor.RESULT_END_OF_INPUT) { readResult = tsExtractor.read(input, seekPositionHolder); if (readResult == Extractor.RESULT_SEEK) { input.setPosition((int) seekPositionHolder.position); } } CustomEsReader reader = factory.esReader; assertThat(reader.packetsRead).isEqualTo(2); TrackOutput trackOutput = reader.getTrackOutput(); assertThat(trackOutput == output.trackOutputs.get(257 /* PID of audio track. */)).isTrue(); assertThat(((FakeTrackOutput) trackOutput).format) .isEqualTo(Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0)); }
@NonNull private Format buildFormat(int streamIndex, @NonNull HtspMessage stream) { return Format.createTextSampleFormat( Integer.toString(streamIndex), MimeTypes.APPLICATION_SUBRIP, C.SELECTION_FLAG_AUTOSELECT, stream.getString("language", "und"), null ); }
@NonNull private MediaSource getMediaSource(VideoInfo videoInfo) { Uri uri = Uri.parse(videoInfo.getUrl()); MediaSource mediaSource = getMediaSourceWithoutSubtitles(uri); // add subtitles if present if (videoInfo.hasSubtitles()) { Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_TTML, C.SELECTION_FLAG_DEFAULT, SUBTITLE_LANGUAGE_ON); MediaSource textMediaSource = new SingleSampleMediaSource.Factory(dataSourceFactory) .setTreatLoadErrorsAsEndOfStream(true) .createMediaSource(Uri.parse(videoInfo.getSubtitleUrl()), textFormat, C.TIME_UNSET); mediaSource = new MergingMediaSource(mediaSource, textMediaSource); } // empty subtitle source to switch to Format emptyTextFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_TTML, C.SELECTION_FLAG_DEFAULT, SUBTITLE_LANGUAGE_OFF); MediaSource emptyTextMediaSource = new SingleSampleMediaSource.Factory(dataSourceFactory) .setTreatLoadErrorsAsEndOfStream(true) .createMediaSource(Uri.EMPTY, emptyTextFormat, 0); mediaSource = new MergingMediaSource(mediaSource, emptyTextMediaSource); return mediaSource; }