Throw a ParserException instead of a NullPointerException if the sample table (stbl) is missing a required sample description (stsd).

As per the javadoc for AtomParsers.parseTrack, ParserException should be "thrown if the trak atom can't be parsed."

PiperOrigin-RevId: 499522748
(cherry picked from commit d8ea770e9ba6eed0bdce0b359c54a55be0844fd3)
This commit is contained in:
Googler 2023-01-04 18:35:06 +00:00 committed by christosts
parent 21996be448
commit 4e7ccd7ffd
2 changed files with 10 additions and 1 deletions

View File

@ -17,6 +17,9 @@
for seeking.
* Use theme when loading drawables on API 21+
([#220](https://github.com/androidx/media/issues/220)).
* Throw a ParserException instead of a NullPointerException if the sample
* table (stbl) is missing a required sample description (stsd) when
* parsing trak atoms.
* Audio:
* Use the compressed audio format bitrate to calculate the min buffer size
for `AudioTrack` in direct playbacks (passthrough).

View File

@ -43,6 +43,7 @@ import androidx.media3.extractor.GaplessInfoHolder;
import androidx.media3.extractor.HevcConfig;
import androidx.media3.extractor.OpusUtil;
import androidx.media3.extractor.metadata.mp4.SmtaMetadataEntry;
import androidx.media3.extractor.mp4.Atom.LeafAtom;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints;
@ -308,9 +309,14 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
Pair<Long, String> mdhdData =
parseMdhd(checkNotNull(mdia.getLeafAtomOfType(Atom.TYPE_mdhd)).data);
LeafAtom stsd = stbl.getLeafAtomOfType(Atom.TYPE_stsd);
if (stsd == null) {
throw ParserException.createForMalformedContainer(
"Malformed sample table (stbl) missing sample description (stsd)", /* cause= */ null);
}
StsdData stsdData =
parseStsd(
checkNotNull(stbl.getLeafAtomOfType(Atom.TYPE_stsd)).data,
stsd.data,
tkhdData.id,
tkhdData.rotationDegrees,
mdhdData.second,