use of androidx.media3.extractor.TrackOutput in project ExoPlayer by google.
the class SingleSampleMediaChunk method load.
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException {
BaseMediaChunkOutput output = getOutput();
output.setSampleOffsetUs(0);
TrackOutput trackOutput = output.track(0, trackType);
trackOutput.format(sampleFormat);
try {
// Create and open the input.
DataSpec loadDataSpec = dataSpec.subrange(nextLoadPosition);
long length = dataSource.open(loadDataSpec);
if (length != C.LENGTH_UNSET) {
length += nextLoadPosition;
}
ExtractorInput extractorInput = new DefaultExtractorInput(dataSource, nextLoadPosition, length);
// Load the sample data.
int result = 0;
while (result != C.RESULT_END_OF_INPUT) {
nextLoadPosition += result;
result = trackOutput.sampleData(extractorInput, Integer.MAX_VALUE, true);
}
int sampleSize = (int) nextLoadPosition;
trackOutput.sampleMetadata(startTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
} finally {
DataSourceUtil.closeQuietly(dataSource);
}
loadCompleted = true;
}
use of androidx.media3.extractor.TrackOutput in project ExoPlayer by google.
the class OutputConsumerAdapterV30 method onSampleDataFound.
@Override
public void onSampleDataFound(int trackIndex, MediaParser.InputReader sampleData) throws IOException {
ensureSpaceForTrackIndex(trackIndex);
scratchDataReaderAdapter.input = sampleData;
TrackOutput trackOutput = trackOutputs.get(trackIndex);
if (trackOutput == null) {
trackOutput = extractorOutput.track(trackIndex, C.TRACK_TYPE_UNKNOWN);
trackOutputs.set(trackIndex, trackOutput);
}
trackOutput.sampleData(scratchDataReaderAdapter, (int) sampleData.getLength(), /* allowEndOfInput= */
true);
}
use of androidx.media3.extractor.TrackOutput in project ExoPlayer by google.
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 ExoPlayer by google.
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(new Format.Builder().setId(idGenerator.getFormatId()).setSampleMimeType(MimeTypes.APPLICATION_DVBSUBS).setInitializationData(Collections.singletonList(subtitleInfo.initializationData)).setLanguage(subtitleInfo.language).build());
outputs[i] = output;
}
}
use of androidx.media3.extractor.TrackOutput in project ExoPlayer by google.
the class SeiReader method createTracks.
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);
@Nullable 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(new Format.Builder().setId(formatId).setSampleMimeType(channelMimeType).setSelectionFlags(channelFormat.selectionFlags).setLanguage(channelFormat.language).setAccessibilityChannel(channelFormat.accessibilityChannel).setInitializationData(channelFormat.initializationData).build());
outputs[i] = output;
}
}
Aggregations