Commit fc26d4ee by aquilescanta Committed by Oliver Woodman

Remove the last deprecated ParserException constructor

PiperOrigin-RevId: 381221669
parent 1cb4fb29
Showing with 168 additions and 102 deletions
......@@ -327,7 +327,8 @@ public class SampleChooserActivity extends AppCompatActivity
reader.nextString(); // Ignore.
break;
default:
throw new ParserException("Unsupported name: " + name);
throw ParserException.createForMalformedManifest(
"Unsupported name: " + name, /* cause= */ null);
}
}
reader.endObject();
......@@ -415,7 +416,8 @@ public class SampleChooserActivity extends AppCompatActivity
reader.endArray();
break;
default:
throw new ParserException("Unsupported attribute name: " + name);
throw ParserException.createForMalformedManifest(
"Unsupported attribute name: " + name, /* cause= */ null);
}
}
reader.endObject();
......
......@@ -148,7 +148,8 @@ import java.nio.ByteBuffer;
public FlacStreamMetadata decodeStreamMetadata() throws IOException {
FlacStreamMetadata streamMetadata = flacDecodeMetadata(nativeDecoderContext);
if (streamMetadata == null) {
throw new ParserException("Failed to decode stream metadata");
throw ParserException.createForMalformedContainer(
"Failed to decode stream metadata", /* cause= */ null);
}
return streamMetadata;
}
......
......@@ -96,18 +96,6 @@ public class ParserException extends IOException {
/** The {@link DataType data type} of the parsed bitstream. */
public final int dataType;
/**
* Creates a new instance.
*
* @param message The detail message for the exception.
* @deprecated Use a factory method which initializes {@link #contentIsMalformed}, and {@link
* #dataType} instead.
*/
@Deprecated
public ParserException(String message) {
this(message, /* cause= */ null, /* contentIsMalformed= */ true, C.DATA_TYPE_UNKNOWN);
}
protected ParserException(
@Nullable String message,
@Nullable Throwable cause,
......
......@@ -229,7 +229,8 @@ public final class AacUtil {
parseGaSpecificConfig(bitArray, audioObjectType, channelConfiguration);
break;
default:
throw new ParserException("Unsupported audio object type: " + audioObjectType);
throw ParserException.createForUnsupportedContainerFeature(
"Unsupported audio object type: " + audioObjectType);
}
switch (audioObjectType) {
case 17:
......@@ -240,7 +241,8 @@ public final class AacUtil {
case 23:
int epConfig = bitArray.readBits(2);
if (epConfig == 2 || epConfig == 3) {
throw new ParserException("Unsupported epConfig: " + epConfig);
throw ParserException.createForUnsupportedContainerFeature(
"Unsupported epConfig: " + epConfig);
}
break;
default:
......
......@@ -1216,7 +1216,8 @@ public final class Util {
public static long parseXsDateTime(String value) throws ParserException {
Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value);
if (!matcher.matches()) {
throw new ParserException("Invalid date/time format: " + value);
throw ParserException.createForMalformedContainer(
"Invalid date/time format: " + value, /* cause= */ null);
}
int timezoneShift;
......
......@@ -237,7 +237,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public void maybeThrowPrepareError() throws IOException {
maybeThrowError();
if (loadingFinished && !prepared) {
throw new ParserException("Loading finished before preparation is complete.");
throw ParserException.createForMalformedContainer(
"Loading finished before preparation is complete.", /* cause= */ null);
}
}
......
......@@ -40,7 +40,8 @@ public final class WebvttParserUtil {
int startPosition = input.getPosition();
if (!isWebvttHeaderLine(input)) {
input.setPosition(startPosition);
throw new ParserException("Expected WEBVTT. Got " + input.readLine());
throw ParserException.createForMalformedContainer(
"Expected WEBVTT. Got " + input.readLine(), /* cause= */ null);
}
}
......
......@@ -23,6 +23,7 @@ import android.util.Base64;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import com.google.common.base.Charsets;
import java.io.IOException;
......@@ -48,12 +49,11 @@ public final class DataSchemeDataSource extends BaseDataSource {
this.dataSpec = dataSpec;
Uri uri = dataSpec.uri;
String scheme = uri.getScheme();
if (!SCHEME_DATA.equals(scheme)) {
throw new ParserException("Unsupported scheme: " + scheme);
}
Assertions.checkArgument(SCHEME_DATA.equals(scheme), "Unsupported scheme: " + scheme);
String[] uriParts = Util.split(uri.getSchemeSpecificPart(), ",");
if (uriParts.length != 2) {
throw new ParserException("Unexpected URI format: " + uri);
throw ParserException.createForMalformedDataOfUnknownType(
"Unexpected URI format: " + uri, /* cause= */ null);
}
String dataString = uriParts[1];
if (uriParts[0].contains(";base64")) {
......
......@@ -108,11 +108,11 @@ public final class DataSchemeDataSourceTest {
}
@Test
public void incorrectScheme() {
public void incorrectScheme() throws IOException {
try {
schemeDataDataSource.open(buildDataSpec("http://www.google.com"));
fail();
} catch (IOException e) {
} catch (IllegalArgumentException e) {
// Expected.
}
}
......
......@@ -1443,7 +1443,8 @@ public final class DashMediaSource extends BaseMediaSource {
try {
Matcher matcher = TIMESTAMP_WITH_TIMEZONE_PATTERN.matcher(firstLine);
if (!matcher.matches()) {
throw new ParserException("Couldn't parse timestamp: " + firstLine);
throw ParserException.createForMalformedManifest(
"Couldn't parse timestamp: " + firstLine, /* cause= */ null);
}
// Parse the timestamp.
String timestampWithoutTimezone = matcher.group(1);
......
......@@ -169,7 +169,8 @@ public class DashManifestParser extends DefaultHandler
// early access.
seenEarlyAccessPeriod = true;
} else {
throw new ParserException("Unable to determine start of period " + periods.size());
throw ParserException.createForMalformedManifest(
"Unable to determine start of period " + periods.size(), /* cause= */ null);
}
} else {
long periodDurationMs = periodWithDurationMs.second;
......@@ -187,12 +188,13 @@ public class DashManifestParser extends DefaultHandler
// If we know the end time of the final period, we can use it as the duration.
durationMs = nextPeriodStartMs;
} else if (!dynamic) {
throw new ParserException("Unable to determine duration of static manifest.");
throw ParserException.createForMalformedManifest(
"Unable to determine duration of static manifest.", /* cause= */ null);
}
}
if (periods.isEmpty()) {
throw new ParserException("No periods found.");
throw ParserException.createForMalformedManifest("No periods found.", /* cause= */ null);
}
return buildMediaPresentationDescription(
......
......@@ -120,7 +120,8 @@ public final class FlacMetadataReader {
ParsableByteArray scratch = new ParsableByteArray(FlacConstants.STREAM_MARKER_SIZE);
input.readFully(scratch.getData(), 0, FlacConstants.STREAM_MARKER_SIZE);
if (scratch.readUnsignedInt() != STREAM_MARKER) {
throw new ParserException("Failed to read FLAC stream marker.");
throw ParserException.createForMalformedContainer(
"Failed to read FLAC stream marker.", /* cause= */ null);
}
}
......@@ -234,7 +235,8 @@ public final class FlacMetadataReader {
int syncCode = frameStartMarker >> 2;
if (syncCode != SYNC_CODE) {
input.resetPeekPosition();
throw new ParserException("First frame does not start with sync code.");
throw ParserException.createForMalformedContainer(
"First frame does not start with sync code.", /* cause= */ null);
}
input.resetPeekPosition();
......
......@@ -241,7 +241,8 @@ public final class VorbisUtil {
length += comments[i].length();
}
if (hasFramingBit && (headerData.readUnsignedByte() & 0x01) == 0) {
throw new ParserException("framing bit expected to be set");
throw ParserException.createForMalformedContainer(
"framing bit expected to be set", /* cause= */ null);
}
length += 1;
return new CommentHeader(vendor, comments, length);
......@@ -263,7 +264,8 @@ public final class VorbisUtil {
if (quiet) {
return false;
} else {
throw new ParserException("too short header: " + header.bytesLeft());
throw ParserException.createForMalformedContainer(
"too short header: " + header.bytesLeft(), /* cause= */ null);
}
}
......@@ -271,7 +273,8 @@ public final class VorbisUtil {
if (quiet) {
return false;
} else {
throw new ParserException("expected header type " + Integer.toHexString(headerType));
throw ParserException.createForMalformedContainer(
"expected header type " + Integer.toHexString(headerType), /* cause= */ null);
}
}
......@@ -284,7 +287,8 @@ public final class VorbisUtil {
if (quiet) {
return false;
} else {
throw new ParserException("expected characters 'vorbis'");
throw ParserException.createForMalformedContainer(
"expected characters 'vorbis'", /* cause= */ null);
}
}
return true;
......@@ -319,7 +323,8 @@ public final class VorbisUtil {
int timeCount = bitArray.readBits(6) + 1;
for (int i = 0; i < timeCount; i++) {
if (bitArray.readBits(16) != 0x00) {
throw new ParserException("placeholder of time domain transforms not zeroed out");
throw ParserException.createForMalformedContainer(
"placeholder of time domain transforms not zeroed out", /* cause= */ null);
}
}
readFloors(bitArray);
......@@ -328,7 +333,8 @@ public final class VorbisUtil {
Mode[] modes = readModes(bitArray);
if (!bitArray.readBit()) {
throw new ParserException("framing bit after modes not set as expected");
throw ParserException.createForMalformedContainer(
"framing bit after modes not set as expected", /* cause= */ null);
}
return modes;
}
......@@ -371,7 +377,8 @@ public final class VorbisUtil {
couplingSteps = 0;
}*/
if (bitArray.readBits(2) != 0x00) {
throw new ParserException("to reserved bits must be zero after mapping coupling steps");
throw ParserException.createForMalformedContainer(
"to reserved bits must be zero after mapping coupling steps", /* cause= */ null);
}
if (submaps > 1) {
for (int j = 0; j < channels; j++) {
......@@ -391,7 +398,8 @@ public final class VorbisUtil {
for (int i = 0; i < residueCount; i++) {
int residueType = bitArray.readBits(16);
if (residueType > 2) {
throw new ParserException("residueType greater than 2 is not decodable");
throw ParserException.createForMalformedContainer(
"residueType greater than 2 is not decodable", /* cause= */ null);
} else {
bitArray.skipBits(24); // begin
bitArray.skipBits(24); // end
......@@ -467,15 +475,17 @@ public final class VorbisUtil {
}
break;
default:
throw new ParserException("floor type greater than 1 not decodable: " + floorType);
throw ParserException.createForMalformedContainer(
"floor type greater than 1 not decodable: " + floorType, /* cause= */ null);
}
}
}
private static CodeBook readBook(VorbisBitArray bitArray) throws ParserException {
if (bitArray.readBits(24) != 0x564342) {
throw new ParserException(
"expected code book to start with [0x56, 0x43, 0x42] at " + bitArray.getPosition());
throw ParserException.createForMalformedContainer(
"expected code book to start with [0x56, 0x43, 0x42] at " + bitArray.getPosition(),
/* cause= */ null);
}
int dimensions = bitArray.readBits(16);
int entries = bitArray.readBits(24);
......@@ -508,7 +518,8 @@ public final class VorbisUtil {
int lookupType = bitArray.readBits(4);
if (lookupType > 2) {
throw new ParserException("lookup type greater than 2 not decodable: " + lookupType);
throw ParserException.createForMalformedContainer(
"lookup type greater than 2 not decodable: " + lookupType, /* cause= */ null);
} else if (lookupType == 1 || lookupType == 2) {
bitArray.skipBits(32); // minimumValue
bitArray.skipBits(32); // deltaValue
......
......@@ -176,7 +176,8 @@ public final class AmrExtractor implements Extractor {
assertInitialized();
if (input.getPosition() == 0) {
if (!readAmrHeader(input)) {
throw new ParserException("Could not find AMR header.");
throw ParserException.createForMalformedContainer(
"Could not find AMR header.", /* cause= */ null);
}
}
maybeOutputFormat();
......@@ -311,7 +312,8 @@ public final class AmrExtractor implements Extractor {
if ((frameHeader & 0x83) > 0) {
// The padding bits are at bit-1 positions in the following pattern: 1000 0011
// Padding bits must be 0.
throw new ParserException("Invalid padding bits for frame header " + frameHeader);
throw ParserException.createForMalformedContainer(
"Invalid padding bits for frame header " + frameHeader, /* cause= */ null);
}
int frameType = (frameHeader >> 3) & 0x0f;
......@@ -320,8 +322,9 @@ public final class AmrExtractor implements Extractor {
private int getFrameSizeInBytes(int frameType) throws ParserException {
if (!isValidFrameType(frameType)) {
throw new ParserException(
"Illegal AMR " + (isWideBand ? "WB" : "NB") + " frame type " + frameType);
throw ParserException.createForMalformedContainer(
"Illegal AMR " + (isWideBand ? "WB" : "NB") + " frame type " + frameType,
/* cause= */ null);
}
return isWideBand ? frameSizeBytesByTypeWb[frameType] : frameSizeBytesByTypeNb[frameType];
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.extractor.flv;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.util.ParsableByteArray;
......@@ -26,7 +27,7 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
public static final class UnsupportedFormatException extends ParserException {
public UnsupportedFormatException(String msg) {
super(msg);
super(msg, /* cause= */ null, /* contentIsMalformed= */ false, C.DATA_TYPE_MEDIA);
}
}
......
......@@ -85,7 +85,8 @@ import org.xmlpull.v1.XmlPullParserFactory;
xpp.setInput(new StringReader(xmpString));
xpp.next();
if (!XmlPullParserUtil.isStartTag(xpp, "x:xmpmeta")) {
throw new ParserException("Couldn't find xmp metadata");
throw ParserException.createForMalformedContainer(
"Couldn't find xmp metadata", /* cause= */ null);
}
long motionPhotoPresentationTimestampUs = C.TIME_UNSET;
List<MotionPhotoDescription.ContainerItem> containerItems = ImmutableList.of();
......
......@@ -114,7 +114,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
return true;
case EbmlProcessor.ELEMENT_TYPE_UNSIGNED_INT:
if (elementContentSize > MAX_INTEGER_ELEMENT_SIZE_BYTES) {
throw new ParserException("Invalid integer size: " + elementContentSize);
throw ParserException.createForMalformedContainer(
"Invalid integer size: " + elementContentSize, /* cause= */ null);
}
processor.integerElement(elementId, readInteger(input, (int) elementContentSize));
elementState = ELEMENT_STATE_READ_ID;
......@@ -122,14 +123,16 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
case EbmlProcessor.ELEMENT_TYPE_FLOAT:
if (elementContentSize != VALID_FLOAT32_ELEMENT_SIZE_BYTES
&& elementContentSize != VALID_FLOAT64_ELEMENT_SIZE_BYTES) {
throw new ParserException("Invalid float size: " + elementContentSize);
throw ParserException.createForMalformedContainer(
"Invalid float size: " + elementContentSize, /* cause= */ null);
}
processor.floatElement(elementId, readFloat(input, (int) elementContentSize));
elementState = ELEMENT_STATE_READ_ID;
return true;
case EbmlProcessor.ELEMENT_TYPE_STRING:
if (elementContentSize > Integer.MAX_VALUE) {
throw new ParserException("String element size: " + elementContentSize);
throw ParserException.createForMalformedContainer(
"String element size: " + elementContentSize, /* cause= */ null);
}
processor.stringElement(elementId, readString(input, (int) elementContentSize));
elementState = ELEMENT_STATE_READ_ID;
......@@ -143,7 +146,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
elementState = ELEMENT_STATE_READ_ID;
break;
default:
throw new ParserException("Invalid element type " + type);
throw ParserException.createForMalformedContainer(
"Invalid element type " + type, /* cause= */ null);
}
}
}
......
......@@ -357,7 +357,8 @@ public final class Mp3Extractor implements Extractor {
// The header doesn't match the candidate header or is invalid. Try the next byte offset.
if (searchedBytes++ == searchLimitBytes) {
if (!sniffing) {
throw new ParserException("Searched too many bytes.");
throw ParserException.createForMalformedContainer(
"Searched too many bytes.", /* cause= */ null);
}
return false;
}
......
......@@ -379,7 +379,8 @@ public class FragmentedMp4Extractor implements Extractor {
}
if (atomSize < atomHeaderBytesRead) {
throw new ParserException("Atom size less than header length (unsupported).");
throw ParserException.createForUnsupportedContainerFeature(
"Atom size less than header length (unsupported).");
}
long atomPosition = input.getPosition() - atomHeaderBytesRead;
......@@ -420,10 +421,12 @@ public class FragmentedMp4Extractor implements Extractor {
}
} else if (shouldParseLeafAtom(atomType)) {
if (atomHeaderBytesRead != Atom.HEADER_SIZE) {
throw new ParserException("Leaf atom defines extended atom size (unsupported).");
throw ParserException.createForUnsupportedContainerFeature(
"Leaf atom defines extended atom size (unsupported).");
}
if (atomSize > Integer.MAX_VALUE) {
throw new ParserException("Leaf atom with length > 2147483647 (unsupported).");
throw ParserException.createForUnsupportedContainerFeature(
"Leaf atom with length > 2147483647 (unsupported).");
}
ParsableByteArray atomData = new ParsableByteArray((int) atomSize);
System.arraycopy(atomHeader.getData(), 0, atomData.getData(), 0, Atom.HEADER_SIZE);
......@@ -431,7 +434,8 @@ public class FragmentedMp4Extractor implements Extractor {
parserState = STATE_READING_ATOM_PAYLOAD;
} else {
if (atomSize > Integer.MAX_VALUE) {
throw new ParserException("Skipping atom with length > 2147483647 (unsupported).");
throw ParserException.createForUnsupportedContainerFeature(
"Skipping atom with length > 2147483647 (unsupported).");
}
atomData = null;
parserState = STATE_READING_ATOM_PAYLOAD;
......@@ -827,11 +831,12 @@ public class FragmentedMp4Extractor implements Extractor {
int sampleCount = saiz.readUnsignedIntToInt();
if (sampleCount > out.sampleCount) {
throw new ParserException(
throw ParserException.createForMalformedContainer(
"Saiz sample count "
+ sampleCount
+ " is greater than fragment sample count"
+ out.sampleCount);
+ out.sampleCount,
/* cause= */ null);
}
int totalSize = 0;
......@@ -870,7 +875,8 @@ public class FragmentedMp4Extractor implements Extractor {
int entryCount = saio.readUnsignedIntToInt();
if (entryCount != 1) {
// We only support one trun element currently, so always expect one entry.
throw new ParserException("Unexpected saio entry count: " + entryCount);
throw ParserException.createForMalformedContainer(
"Unexpected saio entry count: " + entryCount, /* cause= */ null);
}
int version = Atom.parseFullAtomVersion(fullAtom);
......@@ -1055,7 +1061,8 @@ public class FragmentedMp4Extractor implements Extractor {
private static int checkNonNegative(int value) throws ParserException {
if (value < 0) {
throw new ParserException("Unexpected negative value: " + value);
throw ParserException.createForMalformedContainer(
"Unexpected negative value: " + value, /* cause= */ null);
}
return value;
}
......@@ -1089,7 +1096,8 @@ public class FragmentedMp4Extractor implements Extractor {
if ((flags & 0x01 /* override_track_encryption_box_parameters */) != 0) {
// TODO: Implement this.
throw new ParserException("Overriding TrackEncryptionBox parameters is unsupported.");
throw ParserException.createForUnsupportedContainerFeature(
"Overriding TrackEncryptionBox parameters is unsupported.");
}
boolean subsampleEncryption = (flags & 0x02 /* use_subsample_encryption */) != 0;
......@@ -1099,11 +1107,12 @@ public class FragmentedMp4Extractor implements Extractor {
Arrays.fill(out.sampleHasSubsampleEncryptionTable, 0, out.sampleCount, false);
return;
} else if (sampleCount != out.sampleCount) {
throw new ParserException(
throw ParserException.createForMalformedContainer(
"Senc sample count "
+ sampleCount
+ " is different from fragment sample count"
+ out.sampleCount);
+ out.sampleCount,
/* cause= */ null);
}
Arrays.fill(out.sampleHasSubsampleEncryptionTable, 0, sampleCount, subsampleEncryption);
......@@ -1142,7 +1151,8 @@ public class FragmentedMp4Extractor implements Extractor {
sbgp.skipBytes(4); // grouping_type_parameter.
}
if (sbgp.readInt() != 1) { // entry_count.
throw new ParserException("Entry count in sbgp != 1 (unsupported).");
throw ParserException.createForUnsupportedContainerFeature(
"Entry count in sbgp != 1 (unsupported).");
}
sgpd.setPosition(Atom.HEADER_SIZE);
......@@ -1150,13 +1160,15 @@ public class FragmentedMp4Extractor implements Extractor {
sgpd.skipBytes(4); // grouping_type == seig.
if (sgpdVersion == 1) {
if (sgpd.readUnsignedInt() == 0) {
throw new ParserException("Variable length description in sgpd found (unsupported)");
throw ParserException.createForUnsupportedContainerFeature(
"Variable length description in sgpd found (unsupported)");
}
} else if (sgpdVersion >= 2) {
sgpd.skipBytes(4); // default_sample_description_index.
}
if (sgpd.readUnsignedInt() != 1) { // entry_count.
throw new ParserException("Entry count in sgpd != 1 (unsupported).");
throw ParserException.createForUnsupportedContainerFeature(
"Entry count in sgpd != 1 (unsupported).");
}
// CencSampleEncryptionInformationGroupEntry
......@@ -1232,7 +1244,8 @@ public class FragmentedMp4Extractor implements Extractor {
int type = 0x80000000 & firstInt;
if (type != 0) {
throw new ParserException("Unhandled indirect reference");
throw ParserException.createForMalformedContainer(
"Unhandled indirect reference", /* cause= */ null);
}
long referenceDuration = atom.readUnsignedInt();
......@@ -1272,7 +1285,8 @@ public class FragmentedMp4Extractor implements Extractor {
}
int bytesToSkip = (int) (nextDataOffset - input.getPosition());
if (bytesToSkip < 0) {
throw new ParserException("Offset to encryption data was negative.");
throw ParserException.createForMalformedContainer(
"Offset to encryption data was negative.", /* cause= */ null);
}
input.skipFully(bytesToSkip);
nextTrackBundle.fragment.fillEncryptionData(input);
......@@ -1302,7 +1316,8 @@ public class FragmentedMp4Extractor implements Extractor {
// read the header of the next atom.
int bytesToSkip = (int) (endOfMdatPosition - input.getPosition());
if (bytesToSkip < 0) {
throw new ParserException("Offset to end of mdat was negative.");
throw ParserException.createForMalformedContainer(
"Offset to end of mdat was negative.", /* cause= */ null);
}
input.skipFully(bytesToSkip);
enterReadingAtomHeaderState();
......@@ -1380,7 +1395,8 @@ public class FragmentedMp4Extractor implements Extractor {
nalPrefix.setPosition(0);
int nalLengthInt = nalPrefix.readInt();
if (nalLengthInt < 1) {
throw new ParserException("Invalid NAL length");
throw ParserException.createForMalformedContainer(
"Invalid NAL length", /* cause= */ null);
}
sampleCurrentNalBytesRemaining = nalLengthInt - 1;
// Write a start code for the current NAL unit.
......
......@@ -360,7 +360,8 @@ public final class Mp4Extractor implements Extractor, SeekMap {
}
if (atomSize < atomHeaderBytesRead) {
throw new ParserException("Atom size less than header length (unsupported).");
throw ParserException.createForUnsupportedContainerFeature(
"Atom size less than header length (unsupported).");
}
if (shouldParseContainerAtom(atomType)) {
......@@ -598,7 +599,8 @@ public final class Mp4Extractor implements Extractor, SeekMap {
nalLength.setPosition(0);
int nalLengthInt = nalLength.readInt();
if (nalLengthInt < 0) {
throw new ParserException("Invalid NAL length");
throw ParserException.createForMalformedContainer(
"Invalid NAL length", /* cause= */ null);
}
sampleCurrentNalBytesRemaining = nalLengthInt;
// Write a start code for the current NAL unit.
......
......@@ -260,7 +260,7 @@ import java.util.List;
case "Super_SlowMotion_Deflickering_On":
return TYPE_SUPER_SLOW_DEFLICKERING_ON;
default:
throw new ParserException("Invalid SEF name");
throw ParserException.createForMalformedContainer("Invalid SEF name", /* cause= */ null);
}
}
......
......@@ -74,7 +74,8 @@ public class OggExtractor implements Extractor {
checkStateNotNull(output); // Check that init has been called.
if (streamReader == null) {
if (!sniffInternal(input)) {
throw new ParserException("Failed to determine bitstream type");
throw ParserException.createForMalformedContainer(
"Failed to determine bitstream type", /* cause= */ null);
}
input.resetPeekPosition();
}
......
......@@ -140,7 +140,8 @@ import java.io.IOException;
if (quiet) {
return false;
} else {
throw new ParserException("unsupported bit stream revision");
throw ParserException.createForUnsupportedContainerFeature(
"unsupported bit stream revision");
}
}
type = scratch.readUnsignedByte();
......
......@@ -144,7 +144,8 @@ public final class RawCcExtractor implements Extractor {
}
timestampUs = dataScratch.readLong();
} else {
throw new ParserException("Unsupported version number: " + version);
throw ParserException.createForMalformedContainer(
"Unsupported version number: " + version, /* cause= */ null);
}
remainingSampleCount = dataScratch.readUnsignedByte();
......
......@@ -287,7 +287,8 @@ public final class AdtsExtractor implements Extractor {
// Either the stream is malformed OR we're not parsing an ADTS stream.
if (currentFrameSize <= 6) {
hasCalculatedAverageFrameSize = true;
throw new ParserException("Malformed ADTS stream");
throw ParserException.createForMalformedContainer(
"Malformed ADTS stream", /* cause= */ null);
}
totalValidFramesSize += currentFrameSize;
if (++numValidFrames == NUM_FRAMES_FOR_AVERAGE_FRAME_SIZE) {
......
......@@ -443,7 +443,8 @@ public final class TsExtractor implements Extractor {
if (endOfPacket > limit) {
bytesSinceLastSync += syncBytePosition - searchStart;
if (mode == MODE_HLS && bytesSinceLastSync > TS_PACKET_SIZE * 2) {
throw new ParserException("Cannot find sync byte. Most likely not a Transport Stream.");
throw ParserException.createForMalformedContainer(
"Cannot find sync byte. Most likely not a Transport Stream.", /* cause= */ null);
}
} else {
// We have found a packet within the buffer.
......
......@@ -92,7 +92,8 @@ public final class WavExtractor implements Extractor {
WavHeader header = WavHeaderReader.peek(input);
if (header == null) {
// Should only happen if the media wasn't sniffed.
throw new ParserException("Unsupported or unrecognized wav header.");
throw ParserException.createForMalformedContainer(
"Unsupported or unrecognized wav header.", /* cause= */ null);
}
if (header.formatType == WavUtil.TYPE_IMA_ADPCM) {
......@@ -117,7 +118,8 @@ public final class WavExtractor implements Extractor {
@C.PcmEncoding
int pcmEncoding = WavUtil.getPcmEncodingForType(header.formatType, header.bitsPerSample);
if (pcmEncoding == C.ENCODING_INVALID) {
throw new ParserException("Unsupported WAV format type: " + header.formatType);
throw ParserException.createForUnsupportedContainerFeature(
"Unsupported WAV format type: " + header.formatType);
}
outputWriter =
new PassthroughOutputWriter(
......@@ -217,8 +219,9 @@ public final class WavExtractor implements Extractor {
int bytesPerFrame = header.numChannels * header.bitsPerSample / 8;
// Validate the header. Blocks are expected to correspond to single frames.
if (header.blockSize != bytesPerFrame) {
throw new ParserException(
"Expected block size: " + bytesPerFrame + "; got: " + header.blockSize);
throw ParserException.createForMalformedContainer(
"Expected block size: " + bytesPerFrame + "; got: " + header.blockSize,
/* cause= */ null);
}
int constantBitrate = header.frameRateHz * bytesPerFrame * 8;
......@@ -351,8 +354,9 @@ public final class WavExtractor implements Extractor {
int expectedFramesPerBlock =
(((header.blockSize - (4 * numChannels)) * 8) / (header.bitsPerSample * numChannels)) + 1;
if (framesPerBlock != expectedFramesPerBlock) {
throw new ParserException(
"Expected frames per block: " + expectedFramesPerBlock + "; got: " + framesPerBlock);
throw ParserException.createForMalformedContainer(
"Expected frames per block: " + expectedFramesPerBlock + "; got: " + framesPerBlock,
/* cause= */ null);
}
// Calculate the number of blocks we'll need to decode to obtain an output sample of the
......
......@@ -127,7 +127,8 @@ import java.io.IOException;
bytesToSkip = ChunkHeader.SIZE_IN_BYTES + 4;
}
if (bytesToSkip > Integer.MAX_VALUE) {
throw new ParserException("Chunk is too large (~2GB+) to skip; id: " + chunkHeader.id);
throw ParserException.createForUnsupportedContainerFeature(
"Chunk is too large (~2GB+) to skip; id: " + chunkHeader.id);
}
input.skipFully((int) bytesToSkip);
chunkHeader = ChunkHeader.peek(input, scratch);
......
......@@ -278,7 +278,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
public void maybeThrowPrepareError() throws IOException {
maybeThrowError();
if (loadingFinished && !prepared) {
throw new ParserException("Loading finished before preparation is complete.");
throw ParserException.createForMalformedContainer(
"Loading finished before preparation is complete.", /* cause= */ null);
}
}
......
......@@ -153,11 +153,13 @@ public final class WebvttExtractor implements Extractor {
if (line.startsWith("X-TIMESTAMP-MAP")) {
Matcher localTimestampMatcher = LOCAL_TIMESTAMP.matcher(line);
if (!localTimestampMatcher.find()) {
throw new ParserException("X-TIMESTAMP-MAP doesn't contain local timestamp: " + line);
throw ParserException.createForMalformedContainer(
"X-TIMESTAMP-MAP doesn't contain local timestamp: " + line, /* cause= */ null);
}
Matcher mediaTimestampMatcher = MEDIA_TIMESTAMP.matcher(line);
if (!mediaTimestampMatcher.find()) {
throw new ParserException("X-TIMESTAMP-MAP doesn't contain media timestamp: " + line);
throw ParserException.createForMalformedContainer(
"X-TIMESTAMP-MAP doesn't contain media timestamp: " + line, /* cause= */ null);
}
vttTimestampUs =
WebvttParserUtil.parseTimestampUs(
......
......@@ -567,7 +567,9 @@ public final class DefaultHlsPlaylistTracker
processLoadedPlaylist((HlsMediaPlaylist) result, loadEventInfo);
eventDispatcher.loadCompleted(loadEventInfo, C.DATA_TYPE_MANIFEST);
} else {
playlistError = new ParserException("Loaded playlist has unexpected type.");
playlistError =
ParserException.createForMalformedManifest(
"Loaded playlist has unexpected type.", /* cause= */ null);
eventDispatcher.loadError(
loadEventInfo, C.DATA_TYPE_MANIFEST, playlistError, /* wasCanceled= */ true);
}
......
......@@ -286,7 +286,8 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
} finally {
Util.closeQuietly(reader);
}
throw new ParserException("Failed to parse the playlist, could not identify any tags.");
throw ParserException.createForMalformedManifest(
"Failed to parse the playlist, could not identify any tags.", /* cause= */ null);
}
private static boolean checkPlaylistHeader(BufferedReader reader) throws IOException {
......@@ -404,7 +405,8 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
uri =
UriUtil.resolveToUri(baseUri, parseStringAttr(line, REGEX_URI, variableDefinitions));
} else if (!iterator.hasNext()) {
throw new ParserException("#EXT-X-STREAM-INF must be followed by another line");
throw ParserException.createForMalformedManifest(
"#EXT-X-STREAM-INF must be followed by another line", /* cause= */ null);
} else {
// The following line contains #EXT-X-STREAM-INF's URI.
line = replaceVariableReferences(iterator.next(), variableDefinitions);
......@@ -720,9 +722,10 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
}
if (fullSegmentEncryptionKeyUri != null && fullSegmentEncryptionIV == null) {
// See RFC 8216, Section 4.3.2.5.
throw new ParserException(
"The encryption IV attribute must be present when an initialization segment is "
+ "encrypted with METHOD=AES-128.");
throw ParserException.createForMalformedManifest(
"The encryption IV attribute must be present when an initialization segment is"
+ " encrypted with METHOD=AES-128.",
/* cause= */ null);
}
initializationSegment =
new Segment(
......@@ -1199,7 +1202,8 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
if (value != null) {
return value;
} else {
throw new ParserException("Couldn't match " + pattern.pattern() + " in " + line);
throw ParserException.createForMalformedManifest(
"Couldn't match " + pattern.pattern() + " in " + line, /* cause= */ null);
}
}
......
......@@ -82,7 +82,11 @@ public class SsManifestParser implements ParsingLoadable.Parser<SsManifest> {
public static class MissingFieldException extends ParserException {
public MissingFieldException(String fieldName) {
super("Missing required field: " + fieldName);
super(
"Missing required field: " + fieldName,
/* cause= */ null,
/* contentIsMalformed= */ true,
C.DATA_TYPE_MANIFEST);
}
}
......@@ -562,7 +566,8 @@ public class SsManifestParser implements ParsingLoadable.Parser<SsManifest> {
startTime = startTimes.get(chunkIndex - 1) + lastChunkDuration;
} else {
// We don't have the start time, and we're unable to infer it.
throw new ParserException("Unable to infer start time");
throw ParserException.createForMalformedManifest(
"Unable to infer start time", /* cause= */ null);
}
}
chunkIndex++;
......@@ -571,7 +576,8 @@ public class SsManifestParser implements ParsingLoadable.Parser<SsManifest> {
// Handle repeated chunks.
long repeatCount = parseLong(parser, KEY_FRAGMENT_REPEAT_COUNT, 1L);
if (repeatCount > 1 && lastChunkDuration == C.TIME_UNSET) {
throw new ParserException("Repeated chunk with unspecified duration");
throw ParserException.createForMalformedManifest(
"Repeated chunk with unspecified duration", /* cause= */ null);
}
for (int i = 1; i < repeatCount; i++) {
chunkIndex++;
......@@ -613,7 +619,8 @@ public class SsManifestParser implements ParsingLoadable.Parser<SsManifest> {
} else if (KEY_TYPE_TEXT.equalsIgnoreCase(value)) {
return C.TRACK_TYPE_TEXT;
} else {
throw new ParserException("Invalid key value[" + value + "]");
throw ParserException.createForMalformedManifest(
"Invalid key value[" + value + "]", /* cause= */ null);
}
}
throw new MissingFieldException(KEY_TYPE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment