mirror of
https://github.com/samsonjs/media.git
synced 2026-04-07 11:35:46 +00:00
Only parse common-encryption sinf boxes
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=172124807
This commit is contained in:
parent
2fee010938
commit
cad88512f5
2 changed files with 21 additions and 10 deletions
|
|
@ -1064,8 +1064,8 @@ import java.util.List;
|
|||
Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive");
|
||||
int childAtomType = parent.readInt();
|
||||
if (childAtomType == Atom.TYPE_sinf) {
|
||||
Pair<Integer, TrackEncryptionBox> result = parseSinfFromParent(parent, childPosition,
|
||||
childAtomSize);
|
||||
Pair<Integer, TrackEncryptionBox> result = parseCommonEncryptionSinfFromParent(parent,
|
||||
childPosition, childAtomSize);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1075,8 +1075,8 @@ import java.util.List;
|
|||
return null;
|
||||
}
|
||||
|
||||
private static Pair<Integer, TrackEncryptionBox> parseSinfFromParent(ParsableByteArray parent,
|
||||
int position, int size) {
|
||||
/* package */ static Pair<Integer, TrackEncryptionBox> parseCommonEncryptionSinfFromParent(
|
||||
ParsableByteArray parent, int position, int size) {
|
||||
int childPosition = position + Atom.HEADER_SIZE;
|
||||
int schemeInformationBoxPosition = C.POSITION_UNSET;
|
||||
int schemeInformationBoxSize = 0;
|
||||
|
|
@ -1090,7 +1090,7 @@ import java.util.List;
|
|||
dataFormat = parent.readInt();
|
||||
} else if (childAtomType == Atom.TYPE_schm) {
|
||||
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);
|
||||
} else if (childAtomType == Atom.TYPE_schi) {
|
||||
schemeInformationBoxPosition = childPosition;
|
||||
|
|
@ -1099,7 +1099,8 @@ import java.util.List;
|
|||
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(schemeInformationBoxPosition != C.POSITION_UNSET,
|
||||
"schi atom is mandatory");
|
||||
|
|
|
|||
|
|
@ -40,22 +40,32 @@ public final class AtomParsersTest {
|
|||
private static final byte[] SIXTEEN_BIT_STZ2 = Util.getBytesFromHexString(ATOM_HEADER + "00000010"
|
||||
+ SAMPLE_COUNT + "0001000200030004");
|
||||
|
||||
@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() {
|
||||
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
|
||||
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
|
||||
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);
|
||||
assertThat(box.getSampleCount()).isEqualTo(4);
|
||||
assertThat(box.isFixedSampleSize()).isFalse();
|
||||
|
|
|
|||
Loading…
Reference in a new issue