use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class VorbisUtilTest method verifyVorbisHeaderCapturePattern_withInvalidPattern_returnsFalse.
@Test
public void verifyVorbisHeaderCapturePattern_withInvalidPattern_returnsFalse() {
ParsableByteArray header = new ParsableByteArray(new byte[] { 0x01, 'x', 'v', 'o', 'r', 'b', 'i', 's' });
try {
VorbisUtil.verifyVorbisHeaderCapturePattern(0x01, header, false);
fail();
} catch (ParserException e) {
assertThat(e.getMessage()).isEqualTo("expected characters 'vorbis'");
}
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class AmrExtractorNonParameterizedTest method read_amrNb_returnParserException_forInvalidFrameHeader.
@Test
public void read_amrNb_returnParserException_forInvalidFrameHeader() throws IOException {
AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
byte[] invalidHeaderFrame = newNarrowBandAmrFrameWithType(4);
// The padding bits are at bit-1 positions in the following pattern: 1000 0011
// Padding bits must be 0.
invalidHeaderFrame[0] = (byte) (invalidHeaderFrame[0] | 0b01111101);
byte[] data = joinData(amrSignatureNb(), invalidHeaderFrame);
FakeExtractorInput input = fakeExtractorInputWithData(data);
try {
amrExtractor.read(input, new PositionHolder());
fail();
} catch (ParserException e) {
// expected
}
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class AmrExtractorNonParameterizedTest method read_amrWb_returnParserException_forInvalidFrameHeader.
@Test
public void read_amrWb_returnParserException_forInvalidFrameHeader() throws IOException {
AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
byte[] invalidHeaderFrame = newWideBandAmrFrameWithType(6);
// The padding bits are at bit-1 positions in the following pattern: 1000 0011
// Padding bits must be 0.
invalidHeaderFrame[0] = (byte) (invalidHeaderFrame[0] | 0b01111110);
byte[] data = joinData(amrSignatureWb(), invalidHeaderFrame);
FakeExtractorInput input = fakeExtractorInputWithData(data);
try {
amrExtractor.read(input, new PositionHolder());
fail();
} catch (ParserException e) {
// expected
}
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class WebvttExtractor method processSample.
@RequiresNonNull("output")
private void processSample() throws ParserException {
ParsableByteArray webvttData = new ParsableByteArray(sampleData);
// Validate the first line of the header.
WebvttParserUtil.validateWebvttHeaderLine(webvttData);
// Defaults to use if the header doesn't contain an X-TIMESTAMP-MAP header.
long vttTimestampUs = 0;
long tsTimestampUs = 0;
// Parse the remainder of the header looking for X-TIMESTAMP-MAP.
for (String line = webvttData.readLine(); !TextUtils.isEmpty(line); line = webvttData.readLine()) {
if (line.startsWith("X-TIMESTAMP-MAP")) {
Matcher localTimestampMatcher = LOCAL_TIMESTAMP.matcher(line);
if (!localTimestampMatcher.find()) {
throw ParserException.createForMalformedContainer("X-TIMESTAMP-MAP doesn't contain local timestamp: " + line, /* cause= */
null);
}
Matcher mediaTimestampMatcher = MEDIA_TIMESTAMP.matcher(line);
if (!mediaTimestampMatcher.find()) {
throw ParserException.createForMalformedContainer("X-TIMESTAMP-MAP doesn't contain media timestamp: " + line, /* cause= */
null);
}
vttTimestampUs = WebvttParserUtil.parseTimestampUs(Assertions.checkNotNull(localTimestampMatcher.group(1)));
tsTimestampUs = TimestampAdjuster.ptsToUs(Long.parseLong(Assertions.checkNotNull(mediaTimestampMatcher.group(1))));
}
}
// Find the first cue header and parse the start time.
Matcher cueHeaderMatcher = WebvttParserUtil.findNextCueHeader(webvttData);
if (cueHeaderMatcher == null) {
// No cues found. Don't output a sample, but still output a corresponding track.
buildTrackOutput(0);
return;
}
long firstCueTimeUs = WebvttParserUtil.parseTimestampUs(Assertions.checkNotNull(cueHeaderMatcher.group(1)));
long sampleTimeUs = timestampAdjuster.adjustTsTimestamp(TimestampAdjuster.usToWrappedPts(firstCueTimeUs + tsTimestampUs - vttTimestampUs));
long subsampleOffsetUs = sampleTimeUs - firstCueTimeUs;
// Output the track.
TrackOutput trackOutput = buildTrackOutput(subsampleOffsetUs);
// Output the sample.
sampleDataWrapper.reset(sampleData, sampleSize);
trackOutput.sampleData(sampleDataWrapper, sampleSize);
trackOutput.sampleMetadata(sampleTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class WebvttDecoder method decode.
@Override
protected Subtitle decode(byte[] bytes, int length, boolean reset) throws SubtitleDecoderException {
parsableWebvttData.reset(bytes, length);
List<WebvttCssStyle> definedStyles = new ArrayList<>();
// Validate the first line of the header, and skip the remainder.
try {
WebvttParserUtil.validateWebvttHeaderLine(parsableWebvttData);
} catch (ParserException e) {
throw new SubtitleDecoderException(e);
}
while (!TextUtils.isEmpty(parsableWebvttData.readLine())) {
}
int event;
List<WebvttCueInfo> cueInfos = new ArrayList<>();
while ((event = getNextEvent(parsableWebvttData)) != EVENT_END_OF_FILE) {
if (event == EVENT_COMMENT) {
skipComment(parsableWebvttData);
} else if (event == EVENT_STYLE_BLOCK) {
if (!cueInfos.isEmpty()) {
throw new SubtitleDecoderException("A style block was found after the first cue.");
}
// Consume the "STYLE" header.
parsableWebvttData.readLine();
definedStyles.addAll(cssParser.parseBlock(parsableWebvttData));
} else if (event == EVENT_CUE) {
@Nullable WebvttCueInfo cueInfo = WebvttCueParser.parseCue(parsableWebvttData, definedStyles);
if (cueInfo != null) {
cueInfos.add(cueInfo);
}
}
}
return new WebvttSubtitle(cueInfos);
}
Aggregations