Commit cad88512 by olly Committed by Oliver Woodman

Only parse common-encryption sinf boxes

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172124807
parent 2fee0109
...@@ -1064,8 +1064,8 @@ import java.util.List; ...@@ -1064,8 +1064,8 @@ import java.util.List;
Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive"); Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive");
int childAtomType = parent.readInt(); int childAtomType = parent.readInt();
if (childAtomType == Atom.TYPE_sinf) { if (childAtomType == Atom.TYPE_sinf) {
Pair<Integer, TrackEncryptionBox> result = parseSinfFromParent(parent, childPosition, Pair<Integer, TrackEncryptionBox> result = parseCommonEncryptionSinfFromParent(parent,
childAtomSize); childPosition, childAtomSize);
if (result != null) { if (result != null) {
return result; return result;
} }
...@@ -1075,8 +1075,8 @@ import java.util.List; ...@@ -1075,8 +1075,8 @@ import java.util.List;
return null; return null;
} }
private static Pair<Integer, TrackEncryptionBox> parseSinfFromParent(ParsableByteArray parent, /* package */ static Pair<Integer, TrackEncryptionBox> parseCommonEncryptionSinfFromParent(
int position, int size) { ParsableByteArray parent, int position, int size) {
int childPosition = position + Atom.HEADER_SIZE; int childPosition = position + Atom.HEADER_SIZE;
int schemeInformationBoxPosition = C.POSITION_UNSET; int schemeInformationBoxPosition = C.POSITION_UNSET;
int schemeInformationBoxSize = 0; int schemeInformationBoxSize = 0;
...@@ -1090,7 +1090,7 @@ import java.util.List; ...@@ -1090,7 +1090,7 @@ import java.util.List;
dataFormat = parent.readInt(); dataFormat = parent.readInt();
} else if (childAtomType == Atom.TYPE_schm) { } else if (childAtomType == Atom.TYPE_schm) {
parent.skipBytes(4); parent.skipBytes(4);
// scheme_type field. Defined in ISO/IEC 23001-7:2016, section 4.1. // Common encryption scheme_type values are defined in ISO/IEC 23001-7:2016, section 4.1.
schemeType = parent.readString(4); schemeType = parent.readString(4);
} else if (childAtomType == Atom.TYPE_schi) { } else if (childAtomType == Atom.TYPE_schi) {
schemeInformationBoxPosition = childPosition; schemeInformationBoxPosition = childPosition;
...@@ -1099,7 +1099,8 @@ import java.util.List; ...@@ -1099,7 +1099,8 @@ import java.util.List;
childPosition += childAtomSize; childPosition += childAtomSize;
} }
if (schemeType != null) { if (C.CENC_TYPE_cenc.equals(schemeType) || C.CENC_TYPE_cbc1.equals(schemeType)
|| C.CENC_TYPE_cens.equals(schemeType) || C.CENC_TYPE_cbcs.equals(schemeType)) {
Assertions.checkArgument(dataFormat != null, "frma atom is mandatory"); Assertions.checkArgument(dataFormat != null, "frma atom is mandatory");
Assertions.checkArgument(schemeInformationBoxPosition != C.POSITION_UNSET, Assertions.checkArgument(schemeInformationBoxPosition != C.POSITION_UNSET,
"schi atom is mandatory"); "schi atom is mandatory");
......
...@@ -41,21 +41,31 @@ public final class AtomParsersTest { ...@@ -41,21 +41,31 @@ public final class AtomParsersTest {
+ SAMPLE_COUNT + "0001000200030004"); + SAMPLE_COUNT + "0001000200030004");
@Test @Test
public void testParseCommonEncryptionSinfFromParentIgnoresUnknownSchemeType() {
byte[] cencSinf = new byte[] {
0, 0, 0, 24, 115, 105, 110, 102, // size (4), 'sinf' (4)
0, 0, 0, 16, 115, 99, 104, 109, // size (4), 'schm' (4)
0, 0, 0, 0, 88, 88, 88, 88}; // version (1), flags (3), 'xxxx' (4)
assertThat(AtomParsers.parseCommonEncryptionSinfFromParent(
new ParsableByteArray(cencSinf), 0, cencSinf.length)).isNull();
}
@Test
public void testStz2Parsing4BitFieldSize() { public void testStz2Parsing4BitFieldSize() {
verifyParsing(new Atom.LeafAtom(Atom.TYPE_stsz, new ParsableByteArray(FOUR_BIT_STZ2))); verifyStz2Parsing(new Atom.LeafAtom(Atom.TYPE_stsz, new ParsableByteArray(FOUR_BIT_STZ2)));
} }
@Test @Test
public void testStz2Parsing8BitFieldSize() { public void testStz2Parsing8BitFieldSize() {
verifyParsing(new Atom.LeafAtom(Atom.TYPE_stsz, new ParsableByteArray(EIGHT_BIT_STZ2))); verifyStz2Parsing(new Atom.LeafAtom(Atom.TYPE_stsz, new ParsableByteArray(EIGHT_BIT_STZ2)));
} }
@Test @Test
public void testStz2Parsing16BitFieldSize() { public void testStz2Parsing16BitFieldSize() {
verifyParsing(new Atom.LeafAtom(Atom.TYPE_stsz, new ParsableByteArray(SIXTEEN_BIT_STZ2))); verifyStz2Parsing(new Atom.LeafAtom(Atom.TYPE_stsz, new ParsableByteArray(SIXTEEN_BIT_STZ2)));
} }
private void verifyParsing(Atom.LeafAtom stz2Atom) { private static void verifyStz2Parsing(Atom.LeafAtom stz2Atom) {
AtomParsers.Stz2SampleSizeBox box = new AtomParsers.Stz2SampleSizeBox(stz2Atom); AtomParsers.Stz2SampleSizeBox box = new AtomParsers.Stz2SampleSizeBox(stz2Atom);
assertThat(box.getSampleCount()).isEqualTo(4); assertThat(box.getSampleCount()).isEqualTo(4);
assertThat(box.isFixedSampleSize()).isFalse(); assertThat(box.isFixedSampleSize()).isFalse();
......
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