use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.
the class FlacMetadataReaderTest method readMetadataBlock_lastMetadataBlock_isTrue.
@Test
public void readMetadataBlock_lastMetadataBlock_isTrue() throws Exception {
ExtractorInput input = buildExtractorInput("media/flac/bear_one_metadata_block.flac");
input.skipFully(FlacConstants.STREAM_MARKER_SIZE);
boolean result = FlacMetadataReader.readMetadataBlock(input, new FlacStreamMetadataHolder(/* flacStreamMetadata= */
null));
assertThat(result).isTrue();
}
use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.
the class FlacFrameReader method checkFrameHeaderFromPeek.
/**
* Checks whether the given FLAC frame header is valid and, if so, writes the frame first sample
* number in {@code sampleNumberHolder}.
*
* <p>The {@code input} peek position is left unchanged.
*
* @param input The input to get the data from, whose peek position must correspond to the frame
* header.
* @param flacStreamMetadata The stream metadata.
* @param frameStartMarker The frame start marker of the stream.
* @param sampleNumberHolder The holder used to contain the sample number.
* @return Whether the frame header is valid.
*/
public static boolean checkFrameHeaderFromPeek(ExtractorInput input, FlacStreamMetadata flacStreamMetadata, int frameStartMarker, SampleNumberHolder sampleNumberHolder) throws IOException {
long originalPeekPosition = input.getPeekPosition();
byte[] frameStartBytes = new byte[2];
input.peekFully(frameStartBytes, 0, 2);
int frameStart = (frameStartBytes[0] & 0xFF) << 8 | (frameStartBytes[1] & 0xFF);
if (frameStart != frameStartMarker) {
input.resetPeekPosition();
input.advancePeekPosition((int) (originalPeekPosition - input.getPosition()));
return false;
}
ParsableByteArray scratch = new ParsableByteArray(FlacConstants.MAX_FRAME_HEADER_SIZE);
System.arraycopy(frameStartBytes, /* srcPos= */
0, scratch.getData(), /* destPos= */
0, /* length= */
2);
int totalBytesPeeked = ExtractorUtil.peekToLength(input, scratch.getData(), 2, FlacConstants.MAX_FRAME_HEADER_SIZE - 2);
scratch.setLimit(totalBytesPeeked);
input.resetPeekPosition();
input.advancePeekPosition((int) (originalPeekPosition - input.getPosition()));
return checkAndReadFrameHeader(scratch, flacStreamMetadata, frameStartMarker, sampleNumberHolder);
}
use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.
the class FlacFrameReader method getFirstSampleNumber.
/**
* Returns the number of the first sample in the given frame.
*
* <p>The read position of {@code input} is left unchanged.
*
* <p>If no exception is thrown, the peek position is aligned with the read position. Otherwise,
* there is no guarantee on the peek position.
*
* @param input Input stream to get the sample number from (starting from the read position).
* @return The frame first sample number.
* @throws ParserException If an error occurs parsing the sample number.
* @throws IOException If peeking from the input fails.
*/
public static long getFirstSampleNumber(ExtractorInput input, FlacStreamMetadata flacStreamMetadata) throws IOException {
input.resetPeekPosition();
input.advancePeekPosition(1);
byte[] blockingStrategyByte = new byte[1];
input.peekFully(blockingStrategyByte, 0, 1);
boolean isBlockSizeVariable = (blockingStrategyByte[0] & 1) == 1;
input.advancePeekPosition(2);
int maxUtf8SampleNumberSize = isBlockSizeVariable ? 7 : 6;
ParsableByteArray scratch = new ParsableByteArray(maxUtf8SampleNumberSize);
int totalBytesPeeked = ExtractorUtil.peekToLength(input, scratch.getData(), 0, maxUtf8SampleNumberSize);
scratch.setLimit(totalBytesPeeked);
input.resetPeekPosition();
SampleNumberHolder sampleNumberHolder = new SampleNumberHolder();
if (!checkAndReadFirstSampleNumber(scratch, flacStreamMetadata, isBlockSizeVariable, sampleNumberHolder)) {
throw ParserException.createForMalformedContainer(/* message= */
null, /* cause= */
null);
}
return sampleNumberHolder.sampleNumber;
}
use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.
the class FlacFrameReaderTest method checkAndReadFrameHeader_validData_isTrue.
@Test
public void checkAndReadFrameHeader_validData_isTrue() throws Exception {
FlacStreamMetadataHolder streamMetadataHolder = new FlacStreamMetadataHolder(/* flacStreamMetadata= */
null);
ExtractorInput input = buildExtractorInputReadingFromFirstFrame("media/flac/bear_one_metadata_block.flac", streamMetadataHolder);
int frameStartMarker = FlacMetadataReader.getFrameStartMarker(input);
ParsableByteArray scratch = new ParsableByteArray(FlacConstants.MAX_FRAME_HEADER_SIZE);
input.read(scratch.getData(), 0, FlacConstants.MAX_FRAME_HEADER_SIZE);
boolean result = FlacFrameReader.checkAndReadFrameHeader(scratch, streamMetadataHolder.flacStreamMetadata, frameStartMarker, new SampleNumberHolder());
assertThat(result).isTrue();
}
use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.
the class FlacFrameReaderTest method checkFrameHeaderFromPeek_validData_isTrue.
@Test
public void checkFrameHeaderFromPeek_validData_isTrue() throws Exception {
FlacStreamMetadataHolder streamMetadataHolder = new FlacStreamMetadataHolder(/* flacStreamMetadata= */
null);
ExtractorInput input = buildExtractorInputReadingFromFirstFrame("media/flac/bear_one_metadata_block.flac", streamMetadataHolder);
int frameStartMarker = FlacMetadataReader.getFrameStartMarker(input);
boolean result = FlacFrameReader.checkFrameHeaderFromPeek(input, streamMetadataHolder.flacStreamMetadata, frameStartMarker, new SampleNumberHolder());
assertThat(result).isTrue();
}
Aggregations