Search in sources :

Example 16 with TrackOutput

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;
    }
}
Also used : DvbSubtitleInfo(com.google.android.exoplayer2.extractor.ts.TsPayloadReader.DvbSubtitleInfo) TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput)

Example 17 with TrackOutput

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;
    }
}
Also used : TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput)

Example 18 with TrackOutput

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;
}
Also used : TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 19 with 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);
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) ParserException(com.google.android.exoplayer2.ParserException) Matcher(java.util.regex.Matcher) TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 20 with TrackOutput

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));
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput)

Aggregations

FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)70 Test (org.junit.Test)61 SeekMap (androidx.media3.extractor.SeekMap)60 Uri (android.net.Uri)50 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)38 FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)31 TrackOutput (androidx.media3.extractor.TrackOutput)19 Nullable (androidx.annotation.Nullable)13 Format (androidx.media3.common.Format)11 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)11 Format (com.google.android.exoplayer2.Format)8 FakeExtractorInput (androidx.media3.test.utils.FakeExtractorInput)5 ParserException (com.google.android.exoplayer2.ParserException)5 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)5 ParsableByteArray (androidx.media3.common.util.ParsableByteArray)4 SeekPoint (androidx.media3.extractor.SeekPoint)4 Metadata (androidx.media3.common.Metadata)3 Cue (androidx.media3.common.text.Cue)3 DefaultExtractorInput (androidx.media3.extractor.DefaultExtractorInput)3 ExtractorInput (androidx.media3.extractor.ExtractorInput)3