use of androidx.media3.extractor.TrackOutput in project Telegram-FOSS by Telegram-FOSS-Team.
the class DvbSubtitleReader method createTracks.
@Override
public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) {
for (int i = 0; i < outputs.length; i++) {
DvbSubtitleInfo subtitleInfo = subtitleInfos.get(i);
idGenerator.generateNewId();
TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
output.format(Format.createImageSampleFormat(idGenerator.getFormatId(), MimeTypes.APPLICATION_DVBSUBS, null, Format.NO_VALUE, 0, Collections.singletonList(subtitleInfo.initializationData), subtitleInfo.language, null));
outputs[i] = output;
}
}
use of androidx.media3.extractor.TrackOutput in project Telegram-FOSS by Telegram-FOSS-Team.
the class DvbSubtitleReader method consume.
@Override
public void consume(ParsableByteArray data) {
if (writingSample) {
if (bytesToCheck == 2 && !checkNextByte(data, 0x20)) {
// Failed to check data_identifier
return;
}
if (bytesToCheck == 1 && !checkNextByte(data, 0x00)) {
// Check and discard the subtitle_stream_id
return;
}
int dataPosition = data.getPosition();
int bytesAvailable = data.bytesLeft();
for (TrackOutput output : outputs) {
data.setPosition(dataPosition);
output.sampleData(data, bytesAvailable);
}
sampleBytesWritten += bytesAvailable;
}
}
use of androidx.media3.extractor.TrackOutput in project Telegram-FOSS by Telegram-FOSS-Team.
the class WebvttExtractor method buildTrackOutput.
@RequiresNonNull("output")
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;
}
use of androidx.media3.extractor.TrackOutput in project Telegram-FOSS by Telegram-FOSS-Team.
the class WebvttExtractor method processSample.
@RequiresNonNull("output")
private void processSample() throws ParserException {
ParsableByteArray webvttData = new ParsableByteArray(sampleData);
// Validate the first line of the header.
WebvttParserUtil.validateWebvttHeaderLine(webvttData);
// Defaults to use if the header doesn't contain an X-TIMESTAMP-MAP header.
long vttTimestampUs = 0;
long tsTimestampUs = 0;
// Parse the remainder of the header looking for X-TIMESTAMP-MAP.
for (String line = webvttData.readLine(); !TextUtils.isEmpty(line); line = webvttData.readLine()) {
if (line.startsWith("X-TIMESTAMP-MAP")) {
Matcher localTimestampMatcher = LOCAL_TIMESTAMP.matcher(line);
if (!localTimestampMatcher.find()) {
throw new ParserException("X-TIMESTAMP-MAP doesn't contain local timestamp: " + line);
}
Matcher mediaTimestampMatcher = MEDIA_TIMESTAMP.matcher(line);
if (!mediaTimestampMatcher.find()) {
throw new ParserException("X-TIMESTAMP-MAP doesn't contain media timestamp: " + line);
}
vttTimestampUs = WebvttParserUtil.parseTimestampUs(localTimestampMatcher.group(1));
tsTimestampUs = TimestampAdjuster.ptsToUs(Long.parseLong(mediaTimestampMatcher.group(1)));
}
}
// Find the first cue header and parse the start time.
Matcher cueHeaderMatcher = WebvttParserUtil.findNextCueHeader(webvttData);
if (cueHeaderMatcher == null) {
// No cues found. Don't output a sample, but still output a corresponding track.
buildTrackOutput(0);
return;
}
long firstCueTimeUs = WebvttParserUtil.parseTimestampUs(cueHeaderMatcher.group(1));
long sampleTimeUs = timestampAdjuster.adjustTsTimestamp(TimestampAdjuster.usToPts(firstCueTimeUs + tsTimestampUs - vttTimestampUs));
long subsampleOffsetUs = sampleTimeUs - firstCueTimeUs;
// Output the track.
TrackOutput trackOutput = buildTrackOutput(subsampleOffsetUs);
// Output the sample.
sampleDataWrapper.reset(sampleData, sampleSize);
trackOutput.sampleData(sampleDataWrapper, sampleSize);
trackOutput.sampleMetadata(sampleTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
}
use of androidx.media3.extractor.TrackOutput in project media by androidx.
the class FlacExtractorSeekTest method assertFirstFrameAfterSeekContainsTargetSeekTime.
private static void assertFirstFrameAfterSeekContainsTargetSeekTime(String fileName, FakeTrackOutput trackOutput, long targetSeekTimeUs, int firstFrameIndexAfterSeek) throws IOException {
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
int expectedFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
trackOutput.assertSample(firstFrameIndexAfterSeek, expectedTrackOutput.getSampleData(expectedFrameIndex), expectedTrackOutput.getSampleTimeUs(expectedFrameIndex), expectedTrackOutput.getSampleFlags(expectedFrameIndex), expectedTrackOutput.getSampleCryptoData(expectedFrameIndex));
}
Aggregations