use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class AudioTagPayloadReader method parsePayload.
@Override
protected boolean parsePayload(ParsableByteArray data, long timeUs) throws ParserException {
if (audioFormat == AUDIO_FORMAT_MP3) {
int sampleSize = data.bytesLeft();
output.sampleData(data, sampleSize);
output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
return true;
} else {
int packetType = data.readUnsignedByte();
if (packetType == AAC_PACKET_TYPE_SEQUENCE_HEADER && !hasOutputFormat) {
// Parse the sequence header.
byte[] audioSpecificConfig = new byte[data.bytesLeft()];
data.readBytes(audioSpecificConfig, 0, audioSpecificConfig.length);
AacUtil.Config aacConfig = AacUtil.parseAudioSpecificConfig(audioSpecificConfig);
Format format = new Format.Builder().setSampleMimeType(MimeTypes.AUDIO_AAC).setCodecs(aacConfig.codecs).setChannelCount(aacConfig.channelCount).setSampleRate(aacConfig.sampleRateHz).setInitializationData(Collections.singletonList(audioSpecificConfig)).build();
output.format(format);
hasOutputFormat = true;
return false;
} else if (audioFormat != AUDIO_FORMAT_AAC || packetType == AAC_PACKET_TYPE_AAC_RAW) {
int sampleSize = data.bytesLeft();
output.sampleData(data, sampleSize);
output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
return true;
} else {
return false;
}
}
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class FlacMetadataReader method readStreamMarker.
/**
* Reads the FLAC stream marker.
*
* @param input Input stream to read the stream marker from.
* @throws ParserException If an error occurs parsing the stream marker. In this case, the
* position of {@code input} is advanced by {@link FlacConstants#STREAM_MARKER_SIZE} bytes.
* @throws IOException If reading from the input fails. In this case, the position is left
* unchanged.
*/
public static void readStreamMarker(ExtractorInput input) throws IOException {
ParsableByteArray scratch = new ParsableByteArray(FlacConstants.STREAM_MARKER_SIZE);
input.readFully(scratch.getData(), 0, FlacConstants.STREAM_MARKER_SIZE);
if (scratch.readUnsignedInt() != STREAM_MARKER) {
throw ParserException.createForMalformedContainer("Failed to read FLAC stream marker.", /* cause= */
null);
}
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class FlacMetadataReader method getFrameStartMarker.
/**
* Returns the frame start marker, consisting of the 2 first bytes of the first frame.
*
* <p>The read position of {@code input} is left unchanged and the peek position is aligned with
* the read position.
*
* @param input Input stream to get the start marker from (starting from the read position).
* @return The frame start marker (which must be the same for all the frames in the stream).
* @throws ParserException If an error occurs parsing the frame start marker.
* @throws IOException If peeking from the input fails.
*/
public static int getFrameStartMarker(ExtractorInput input) throws IOException {
input.resetPeekPosition();
ParsableByteArray scratch = new ParsableByteArray(2);
input.peekFully(scratch.getData(), 0, 2);
int frameStartMarker = scratch.readUnsignedShort();
int syncCode = frameStartMarker >> 2;
if (syncCode != SYNC_CODE) {
input.resetPeekPosition();
throw ParserException.createForMalformedContainer("First frame does not start with sync code.", /* cause= */
null);
}
input.resetPeekPosition();
return frameStartMarker;
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class VorbisUtilTest method verifyVorbisHeaderCapturePattern_withValidHeader_returnsFalse.
@Test
public void verifyVorbisHeaderCapturePattern_withValidHeader_returnsFalse() {
ParsableByteArray header = new ParsableByteArray(new byte[] { 0x01, 'v', 'o', 'r', 'b', 'i', 's' });
try {
VorbisUtil.verifyVorbisHeaderCapturePattern(0x99, header, false);
fail();
} catch (ParserException e) {
assertThat(e.getMessage()).isEqualTo("expected header type 99");
}
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class VorbisUtilTest method verifyVorbisHeaderCapturePattern_withInvalidHeaderQuite_returnsFalse.
@Test
public void verifyVorbisHeaderCapturePattern_withInvalidHeaderQuite_returnsFalse() throws ParserException {
ParsableByteArray header = new ParsableByteArray(new byte[] { 0x01, 'v', 'o', 'r', 'b', 'i', 's' });
assertThat(verifyVorbisHeaderCapturePattern(0x99, header, true)).isFalse();
}
Aggregations