use of androidx.media3.datasource.DataSource in project media by androidx.
the class ContainerMediaChunk method load.
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public final void load() throws IOException {
if (nextLoadPosition == 0) {
// Configure the output and set it as the target for the extractor wrapper.
BaseMediaChunkOutput output = getOutput();
output.setSampleOffsetUs(sampleOffsetUs);
chunkExtractor.init(getTrackOutputProvider(output), clippedStartTimeUs == C.TIME_UNSET ? C.TIME_UNSET : (clippedStartTimeUs - sampleOffsetUs), clippedEndTimeUs == C.TIME_UNSET ? C.TIME_UNSET : (clippedEndTimeUs - sampleOffsetUs));
}
try {
// Create and open the input.
DataSpec loadDataSpec = dataSpec.subrange(nextLoadPosition);
ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.position, dataSource.open(loadDataSpec));
// Load and decode the sample data.
try {
while (!loadCanceled && chunkExtractor.read(input)) {
}
} finally {
nextLoadPosition = input.getPosition() - dataSpec.position;
}
} finally {
DataSourceUtil.closeQuietly(dataSource);
}
loadCompleted = !loadCanceled;
}
use of androidx.media3.datasource.DataSource in project media by androidx.
the class InitializationChunk method load.
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException {
if (nextLoadPosition == 0) {
chunkExtractor.init(trackOutputProvider, /* startTimeUs= */
C.TIME_UNSET, /* endTimeUs= */
C.TIME_UNSET);
}
try {
// Create and open the input.
DataSpec loadDataSpec = dataSpec.subrange(nextLoadPosition);
ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.position, dataSource.open(loadDataSpec));
// Load and decode the initialization data.
try {
while (!loadCanceled && chunkExtractor.read(input)) {
}
} finally {
nextLoadPosition = input.getPosition() - dataSpec.position;
}
} finally {
DataSourceUtil.closeQuietly(dataSource);
}
}
use of androidx.media3.datasource.DataSource in project media by androidx.
the class IcyDataSource method readMetadata.
/**
* Reads an ICY stream metadata block, passing it to {@link #listener} unless the block is empty.
*
* @return True if the block was extracted, including if its length byte indicated a length of
* zero. False if the end of the stream was reached.
* @throws IOException If an error occurs reading from the wrapped {@link DataSource}.
*/
private boolean readMetadata() throws IOException {
int bytesRead = upstream.read(metadataLengthByteHolder, 0, 1);
if (bytesRead == C.RESULT_END_OF_INPUT) {
return false;
}
int metadataLength = (metadataLengthByteHolder[0] & 0xFF) << 4;
if (metadataLength == 0) {
return true;
}
int offset = 0;
int lengthRemaining = metadataLength;
byte[] metadata = new byte[metadataLength];
while (lengthRemaining > 0) {
bytesRead = upstream.read(metadata, offset, lengthRemaining);
if (bytesRead == C.RESULT_END_OF_INPUT) {
return false;
}
offset += bytesRead;
lengthRemaining -= bytesRead;
}
// Discard trailing zero bytes.
while (metadataLength > 0 && metadata[metadataLength - 1] == 0) {
metadataLength--;
}
if (metadataLength > 0) {
listener.onIcyMetadata(new ParsableByteArray(metadata, metadataLength));
}
return true;
}
use of androidx.media3.datasource.DataSource in project media by androidx.
the class DashMediaSource method prepareSourceInternal.
@Override
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
this.mediaTransferListener = mediaTransferListener;
drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */
Looper.myLooper(), getPlayerId());
if (sideloadedManifest) {
processManifest(false);
} else {
dataSource = manifestDataSourceFactory.createDataSource();
loader = new Loader("DashMediaSource");
handler = Util.createHandlerForCurrentLooper();
startLoadingManifest();
}
}
use of androidx.media3.datasource.DataSource in project media by androidx.
the class DashUtil method loadInitializationData.
private static void loadInitializationData(DataSource dataSource, Representation representation, int baseUrlIndex, ChunkExtractor chunkExtractor, RangedUri requestUri) throws IOException {
DataSpec dataSpec = DashUtil.buildDataSpec(representation, representation.baseUrls.get(baseUrlIndex).url, requestUri, /* flags= */
0);
InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec, representation.format, C.SELECTION_REASON_UNKNOWN, null, /* trackSelectionData */
chunkExtractor);
initializationChunk.load();
}
Aggregations