Add nullness checks

This commit is contained in:
rohks 2023-12-11 09:35:46 +00:00 committed by Rohit Singh
parent 2da1bb1877
commit 44b2071ee0
4 changed files with 6 additions and 12 deletions

View file

@ -15,6 +15,7 @@
*/ */
package androidx.media3.extractor; package androidx.media3.extractor;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static java.lang.annotation.ElementType.TYPE_USE; import static java.lang.annotation.ElementType.TYPE_USE;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
@ -72,7 +73,6 @@ public final class MpeghUtil {
frameBytes = C.LENGTH_UNSET; frameBytes = C.LENGTH_UNSET;
mainStreamLabel = C.INDEX_UNSET; mainStreamLabel = C.INDEX_UNSET;
mpegh3daProfileLevelIndication = C.INDEX_UNSET; mpegh3daProfileLevelIndication = C.INDEX_UNSET;
compatibleSetIndication = null;
} }
/** /**
@ -555,8 +555,9 @@ public final class MpeghUtil {
data.skipBits(4); // reserved data.skipBits(4); // reserved
mpegh3daConfig.compatibleProfileLevelSet = new byte[numCompatibleSets]; mpegh3daConfig.compatibleProfileLevelSet = new byte[numCompatibleSets];
for (int idx = 0; idx < numCompatibleSets; idx++) { for (int idx = 0; idx < numCompatibleSets; idx++) {
mpegh3daConfig.compatibleProfileLevelSet[idx] = (byte) data.readBits(8); checkNotNull(mpegh3daConfig.compatibleProfileLevelSet)[idx] = (byte) data.readBits(8);
} }
} else { } else {
data.skipBits(C.BITS_PER_BYTE * usacConfigExtLength); data.skipBits(C.BITS_PER_BYTE * usacConfigExtLength);
} }
@ -812,7 +813,6 @@ public final class MpeghUtil {
mpegh3daProfileLevelIndication = C.INDEX_UNSET; mpegh3daProfileLevelIndication = C.INDEX_UNSET;
samplingFrequency = C.RATE_UNSET_INT; samplingFrequency = C.RATE_UNSET_INT;
standardFrameSamples = C.LENGTH_UNSET; standardFrameSamples = C.LENGTH_UNSET;
compatibleProfileLevelSet = null;
} }
} }
} }

View file

@ -66,34 +66,29 @@ public final class DefaultTsPayloadReaderFactory implements TsPayloadReader.Fact
* synchronization samples (key-frames). * synchronization samples (key-frames).
*/ */
public static final int FLAG_ALLOW_NON_IDR_KEYFRAMES = 1; public static final int FLAG_ALLOW_NON_IDR_KEYFRAMES = 1;
/** /**
* Prevents the creation of {@link AdtsReader} and {@link LatmReader} instances. This flag should * Prevents the creation of {@link AdtsReader} and {@link LatmReader} instances. This flag should
* be enabled if the transport stream contains no packets for an AAC elementary stream that is * be enabled if the transport stream contains no packets for an AAC elementary stream that is
* declared in the PMT. * declared in the PMT.
*/ */
public static final int FLAG_IGNORE_AAC_STREAM = 1 << 1; public static final int FLAG_IGNORE_AAC_STREAM = 1 << 1;
/** /**
* Prevents the creation of {@link H264Reader} instances. This flag should be enabled if the * Prevents the creation of {@link H264Reader} instances. This flag should be enabled if the
* transport stream contains no packets for an H.264 elementary stream that is declared in the * transport stream contains no packets for an H.264 elementary stream that is declared in the
* PMT. * PMT.
*/ */
public static final int FLAG_IGNORE_H264_STREAM = 1 << 2; public static final int FLAG_IGNORE_H264_STREAM = 1 << 2;
/** /**
* When extracting H.264 samples, whether to split the input stream into access units (samples) * When extracting H.264 samples, whether to split the input stream into access units (samples)
* based on slice headers. This flag should be disabled if the stream contains access unit * based on slice headers. This flag should be disabled if the stream contains access unit
* delimiters (AUDs). * delimiters (AUDs).
*/ */
public static final int FLAG_DETECT_ACCESS_UNITS = 1 << 3; public static final int FLAG_DETECT_ACCESS_UNITS = 1 << 3;
/** /**
* Prevents the creation of {@link SectionPayloadReader}s for splice information sections * Prevents the creation of {@link SectionPayloadReader}s for splice information sections
* (SCTE-35). * (SCTE-35).
*/ */
public static final int FLAG_IGNORE_SPLICE_INFO_STREAM = 1 << 4; public static final int FLAG_IGNORE_SPLICE_INFO_STREAM = 1 << 4;
/** /**
* Whether the list of {@code closedCaptionFormats} passed to {@link * Whether the list of {@code closedCaptionFormats} passed to {@link
* DefaultTsPayloadReaderFactory#DefaultTsPayloadReaderFactory(int, List)} should be used in spite * DefaultTsPayloadReaderFactory#DefaultTsPayloadReaderFactory(int, List)} should be used in spite
@ -101,7 +96,6 @@ public final class DefaultTsPayloadReaderFactory implements TsPayloadReader.Fact
* closedCaptionFormats} will be ignored if the PMT contains closed captions service descriptors. * closedCaptionFormats} will be ignored if the PMT contains closed captions service descriptors.
*/ */
public static final int FLAG_OVERRIDE_CAPTION_DESCRIPTORS = 1 << 5; public static final int FLAG_OVERRIDE_CAPTION_DESCRIPTORS = 1 << 5;
/** /**
* Sets whether HDMV DTS audio streams will be handled. If this flag is set, SCTE subtitles will * Sets whether HDMV DTS audio streams will be handled. If this flag is set, SCTE subtitles will
* not be detected, as they share the same elementary stream type as HDMV DTS. * not be detected, as they share the same elementary stream type as HDMV DTS.

View file

@ -15,6 +15,7 @@
*/ */
package androidx.media3.extractor.ts; package androidx.media3.extractor.ts;
import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.extractor.ts.TsPayloadReader.FLAG_DATA_ALIGNMENT_INDICATOR; import static androidx.media3.extractor.ts.TsPayloadReader.FLAG_DATA_ALIGNMENT_INDICATOR;
import static androidx.media3.extractor.ts.TsPayloadReader.FLAG_RANDOM_ACCESS_INDICATOR; import static androidx.media3.extractor.ts.TsPayloadReader.FLAG_RANDOM_ACCESS_INDICATOR;
@ -59,7 +60,7 @@ public final class MpeghReader implements ElementaryStreamReader {
public MpeghReader() { public MpeghReader() {
dataBuffer = new ParsableByteArray(0); dataBuffer = new ParsableByteArray(0);
dataBitBuffer = new ParsableBitArray(); dataBitBuffer = new ParsableBitArray();
clearDataBuffer(); rapPending = true;
timeUs = C.TIME_UNSET; timeUs = C.TIME_UNSET;
timeUsPending = C.TIME_UNSET; timeUsPending = C.TIME_UNSET;
prevFrameInfo = new MpeghUtil.FrameInfo(); prevFrameInfo = new MpeghUtil.FrameInfo();
@ -110,6 +111,7 @@ public final class MpeghReader implements ElementaryStreamReader {
@Override @Override
public void packetFinished(boolean isEndOfInput) { public void packetFinished(boolean isEndOfInput) {
checkStateNotNull(output); // Asserts that createTracks has been called.
// try to find the sync packet and adjust the data buffer if necessary // try to find the sync packet and adjust the data buffer if necessary
maybeFindSync(); maybeFindSync();

View file

@ -81,10 +81,8 @@ public final class TsExtractor implements Extractor {
/** Behave as defined in ISO/IEC 13818-1. */ /** Behave as defined in ISO/IEC 13818-1. */
public static final int MODE_MULTI_PMT = 0; public static final int MODE_MULTI_PMT = 0;
/** Assume only one PMT will be contained in the stream, even if more are declared by the PAT. */ /** Assume only one PMT will be contained in the stream, even if more are declared by the PAT. */
public static final int MODE_SINGLE_PMT = 1; public static final int MODE_SINGLE_PMT = 1;
/** /**
* Enable single PMT mode, map {@link TrackOutput}s by their type (instead of PID) and ignore * Enable single PMT mode, map {@link TrackOutput}s by their type (instead of PID) and ignore
* continuity counters. * continuity counters.