use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.
the class TransformerActivity method playMediaItem.
@RequiresNonNull({ "playerView", "debugTextView" })
private void playMediaItem(MediaItem mediaItem) {
playerView.setPlayer(null);
releasePlayer();
ExoPlayer player = new ExoPlayer.Builder(/* context= */
this).build();
playerView.setPlayer(player);
player.setMediaItem(mediaItem);
player.play();
player.prepare();
this.player = player;
debugTextViewHelper = new DebugTextViewHelper(player, debugTextView);
debugTextViewHelper.start();
}
use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.
the class FlacExtractor method handlePendingSeek.
@RequiresNonNull("binarySearchSeeker")
private int handlePendingSeek(ExtractorInput input, PositionHolder seekPosition, ParsableByteArray outputBuffer, OutputFrameHolder outputFrameHolder, TrackOutput trackOutput) throws IOException {
int seekResult = binarySearchSeeker.handlePendingSeek(input, seekPosition);
ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;
if (seekResult == RESULT_CONTINUE && outputByteBuffer.limit() > 0) {
outputSample(outputBuffer, outputByteBuffer.limit(), outputFrameHolder.timeUs, trackOutput);
}
return seekResult;
}
use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.
the class MpegAudioReader method readHeaderRemainder.
/**
* Attempts to read the remaining two bytes of the frame header.
*
* <p>If a frame header is read in full then the state is changed to {@link #STATE_READING_FRAME},
* the media format is output if this has not previously occurred, the four header bytes are
* output as sample data, and the position of the source is advanced to the byte that immediately
* follows the header.
*
* <p>If a frame header is read in full but cannot be parsed then the state is changed to {@link
* #STATE_READING_HEADER}.
*
* <p>If a frame header is not read in full then the position of the source is advanced to the
* limit, and the method should be called again with the next source to continue the read.
*
* @param source The source from which to read.
*/
@RequiresNonNull("output")
private void readHeaderRemainder(ParsableByteArray source) {
int bytesToRead = min(source.bytesLeft(), HEADER_SIZE - frameBytesRead);
source.readBytes(headerScratch.getData(), frameBytesRead, bytesToRead);
frameBytesRead += bytesToRead;
if (frameBytesRead < HEADER_SIZE) {
// We haven't read the whole header yet.
return;
}
headerScratch.setPosition(0);
boolean parsedHeader = header.setForHeaderData(headerScratch.readInt());
if (!parsedHeader) {
// We thought we'd located a frame header, but we hadn't.
frameBytesRead = 0;
state = STATE_READING_HEADER;
return;
}
frameSize = header.frameSize;
if (!hasOutputFormat) {
frameDurationUs = (C.MICROS_PER_SECOND * header.samplesPerFrame) / header.sampleRate;
Format format = new Format.Builder().setId(formatId).setSampleMimeType(header.mimeType).setMaxInputSize(MpegAudioUtil.MAX_FRAME_SIZE_BYTES).setChannelCount(header.channels).setSampleRate(header.sampleRate).setLanguage(language).build();
output.format(format);
hasOutputFormat = true;
}
headerScratch.setPosition(0);
output.sampleData(headerScratch, HEADER_SIZE);
state = STATE_READING_FRAME;
}
use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.
the class StreamReader method readPayload.
@RequiresNonNull({ "trackOutput", "oggSeeker", "extractorOutput" })
private int readPayload(ExtractorInput input, PositionHolder seekPosition) throws IOException {
long position = oggSeeker.read(input);
if (position >= 0) {
seekPosition.position = position;
return Extractor.RESULT_SEEK;
} else if (position < -1) {
onSeekEnd(-(position + 2));
}
if (!seekMapSet) {
SeekMap seekMap = checkStateNotNull(oggSeeker.createSeekMap());
extractorOutput.seekMap(seekMap);
seekMapSet = true;
}
if (lengthOfReadPacket > 0 || oggPacket.populate(input)) {
lengthOfReadPacket = 0;
ParsableByteArray payload = oggPacket.getPayload();
long granulesInPacket = preparePayload(payload);
if (granulesInPacket >= 0 && currentGranule + granulesInPacket >= targetGranule) {
// calculate time and send payload data to codec
long timeUs = convertGranuleToTime(currentGranule);
trackOutput.sampleData(payload, payload.limit());
trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, payload.limit(), 0, null);
targetGranule = -1;
}
currentGranule += granulesInPacket;
} else {
state = STATE_END_OF_INPUT;
return Extractor.RESULT_END_OF_INPUT;
}
return Extractor.RESULT_CONTINUE;
}
use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.
the class Ac3Reader method parseHeader.
/**
* Parses the sample header.
*/
@RequiresNonNull("output")
private void parseHeader() {
headerScratchBits.setPosition(0);
SyncFrameInfo frameInfo = Ac3Util.parseAc3SyncframeInfo(headerScratchBits);
if (format == null || frameInfo.channelCount != format.channelCount || frameInfo.sampleRate != format.sampleRate || !Util.areEqual(frameInfo.mimeType, format.sampleMimeType)) {
format = new Format.Builder().setId(formatId).setSampleMimeType(frameInfo.mimeType).setChannelCount(frameInfo.channelCount).setSampleRate(frameInfo.sampleRate).setLanguage(language).build();
output.format(format);
}
sampleSize = frameInfo.frameSize;
// In this class a sample is an access unit (syncframe in AC-3), but Format#sampleRate
// specifies the number of PCM audio samples per second.
sampleDurationUs = C.MICROS_PER_SECOND * frameInfo.sampleCount / format.sampleRate;
}
Aggregations