Skip to content

Commit

Permalink
Added test cases for parsing and authoring CPLs adhering to the 2020 …
Browse files Browse the repository at this point in the history
…version of the IMF spec.

Fixed a bug when serializing CPLs that referenced Core Constraints 2020
  • Loading branch information
davidt-netflix committed Aug 6, 2020
1 parent 86d753c commit 6d5cc46
Show file tree
Hide file tree
Showing 6 changed files with 762 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ else if (virtualTrack instanceof IMFMarkerVirtualTrack)
return Collections.unmodifiableList(trackResourceList);
}

// TODO- Refactor this and consolidate all marshall/unmarshall logic into CompositionModel_st2067_2_2016.java
private void serializeCPLToXML(org.smpte_ra.schemas.st2067_2_2016.CompositionPlaylistType cplRoot, File outputFile) throws IOException, JAXBException, SAXException{

int numErrors = imfErrorLogger.getNumberOfErrors();
Expand All @@ -306,18 +307,22 @@ private void serializeCPLToXML(org.smpte_ra.schemas.st2067_2_2016.CompositionPla
InputStream dcmlSchemaAsAStream = contextClassLoader.getResourceAsStream("org/smpte_ra/schemas/st0433_2008/dcmlTypes/dcmlTypes.xsd");
InputStream cplSchemaAsAStream = contextClassLoader.getResourceAsStream("org/smpte_ra/schemas/st2067_3_2016/imf-cpl-20160411.xsd");
InputStream coreConstraintsSchemaAsAStream = contextClassLoader.getResourceAsStream("org/smpte_ra/schemas/st2067_2_2016/imf-core-constraints-20160411.xsd");
InputStream xsd_core_constraints_2020 = contextClassLoader.getResourceAsStream("org/smpte_ra/schemas/st2067_2_2020/imf-core-constraints-2020.xsd");
OutputStream outputStream = new FileOutputStream(outputFile)
)
{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI );
StreamSource[] schemaSources = new StreamSource[4];
StreamSource[] schemaSources = new StreamSource[5];
schemaSources[0] = new StreamSource(dsigSchemaAsAStream);
schemaSources[1] = new StreamSource(dcmlSchemaAsAStream);
schemaSources[2] = new StreamSource(cplSchemaAsAStream);
schemaSources[3] = new StreamSource(coreConstraintsSchemaAsAStream);
schemaSources[4] = new StreamSource(xsd_core_constraints_2020);
Schema schema = schemaFactory.newSchema(schemaSources);

JAXBContext jaxbContext = JAXBContext.newInstance("org.smpte_ra.schemas.st2067_2_2016");
JAXBContext jaxbContext = JAXBContext.newInstance(
org.smpte_ra.schemas.st2067_2_2016.ObjectFactory.class, // 2016 CPL and Core constraints
org.smpte_ra.schemas.st2067_2_2020.ObjectFactory.class); // 2020 Core constraints also use 2016 CPL
Marshaller marshaller = jaxbContext.createMarshaller();
ValidationEventHandlerImpl validationEventHandler = new ValidationEventHandlerImpl(true);
marshaller.setEventHandler(validationEventHandler);
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/com/netflix/imflibrary/st2067_2/CompositionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,35 @@ public void compositionWithMultipleApplicationIdentificationFullyNegativeTest()
ApplicationCompositionFactory.getApplicationComposition(inputFile, imfErrorLogger);
Assert.assertEquals(imfErrorLogger.getErrors().size(), 2);
}

@Test
public void composition2020Test() throws IOException {
File inputFile = TestHelper.findResourceByPath
("TestIMP/IMF-2020/CPL-2020_updated-core-constraints.xml");
IMFErrorLogger imfErrorLogger = new IMFErrorLoggerImpl();
ApplicationComposition applicationComposition = ApplicationCompositionFactory.getApplicationComposition(inputFile, imfErrorLogger);
Assert.assertEquals(imfErrorLogger.getErrors().size(), 0);
Assert.assertEquals(applicationComposition.getCoreConstraintsSchema(), CoreConstraints.NAMESPACE_IMF_2020);
}

@Test
public void composition2020WithoutAudioTrackTest() throws IOException {
File inputFile = TestHelper.findResourceByPath
("TestIMP/IMF-2020/CPL-2020_no-audio-track.xml");
IMFErrorLogger imfErrorLogger = new IMFErrorLoggerImpl();
ApplicationComposition applicationComposition = ApplicationCompositionFactory.getApplicationComposition(inputFile, imfErrorLogger);
Assert.assertEquals(imfErrorLogger.getErrors().size(), 0);
Assert.assertEquals(applicationComposition.getCoreConstraintsSchema(), CoreConstraints.NAMESPACE_IMF_2020);
}

@Test
public void composition2016WithoutAudioTrackNegativeTest() throws IOException {
File inputFile = TestHelper.findResourceByPath
("TestIMP/IMF-2020/CPL-2016_no-audio-track.xml");
IMFErrorLogger imfErrorLogger = new IMFErrorLoggerImpl();
ApplicationComposition applicationComposition = ApplicationCompositionFactory.getApplicationComposition(inputFile, imfErrorLogger);
Assert.assertTrue(imfErrorLogger.getErrors().stream().anyMatch(e ->
e.getErrorCode() == IMFErrorLogger.IMFErrors.ErrorCodes.IMF_CORE_CONSTRAINTS_ERROR));
Assert.assertNull(applicationComposition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.netflix.imflibrary.st0377.header.GenericPackage;
import com.netflix.imflibrary.st0377.header.Preface;
import com.netflix.imflibrary.st0377.header.SourcePackage;
import com.netflix.imflibrary.st2067_2.Application2ExtendedComposition;
import com.netflix.imflibrary.st2067_2.ApplicationComposition;
import com.netflix.imflibrary.st2067_2.ApplicationCompositionFactory;
import com.netflix.imflibrary.utils.ByteArrayByteRangeProvider;
Expand Down Expand Up @@ -76,6 +77,10 @@ private Object[][] getCplList() {
{"TestIMP/Netflix_Sony_Plugfest_2015/CPL_BLACKL_202_HD_REC709_178_ENG_fe8cf2f4-1bcd-4145-8f72-6775af4038c4.xml", "2016", false, 0},
{"TestIMP/Netflix_Sony_Plugfest_2015/CPL_BLACKL_202_HD_REC709_178_ENG_fe8cf2f4-1bcd-4145-8f72-6775af4038c4_duplicate_source_encoding_element.xml", "2016", false, 0},
{"TestIMP/IAB/CompleteIMP/CPL_e0265fda-cb35-4e35-a4e4-4f44d82d2a52.xml", "2016", false, 0},
{"TestIMP/IMF-2020/CPL-2020_no-audio-track.xml", "2020", false, 0},
{"TestIMP/IMF-2020/CPL-2020_no-audio-track.xml", "2016", false, 1},
{"TestIMP/Netflix_Sony_Plugfest_2015/CPL_BLACKL_202_HD_REC709_178_ENG_fe8cf2f4-1bcd-4145-8f72-6775af4038c4.xml", "2020", true, 1},
{"TestIMP/Netflix_Sony_Plugfest_2015/CPL_BLACKL_202_HD_REC709_178_ENG_fe8cf2f4-1bcd-4145-8f72-6775af4038c4.xml", "2020", false, 0},
};
}

Expand Down Expand Up @@ -105,15 +110,23 @@ private void buildIMPAndValidate(ApplicationComposition applicationComposition,
"Netflix",
applicationComposition.getVirtualTracks(),
applicationComposition.getEditRate(),
"http://www.smpte-ra.org/schemas/2067-21/2016",
Application2ExtendedComposition.SCHEMA_URI_APP2E_2016,
buildTrackFileMetadataMap(imfErrorLogger),
tempDir);
} else if (schemaVersion.equals("2020")) {
IMPBuilder.buildIMP_2016("IMP",
"Netflix",
applicationComposition.getVirtualTracks(),
applicationComposition.getEditRate(),
Application2ExtendedComposition.SCHEMA_URI_APP2E_2020,
buildTrackFileMetadataMap(imfErrorLogger),
tempDir);
} else if (schemaVersion.equals("2013")) {
IMPBuilder.buildIMP_2013("IMP",
"Netflix",
applicationComposition.getVirtualTracks(),
applicationComposition.getEditRate(),
"http://www.smpte-ra.org/schemas/2067-21/2016",
Application2ExtendedComposition.SCHEMA_URI_APP2E_2014,
buildTrackFileMetadataMap(imfErrorLogger),
tempDir);
}
Expand All @@ -123,7 +136,16 @@ private void buildIMPAndValidate(ApplicationComposition applicationComposition,
"Netflix",
applicationComposition.getVirtualTracks(),
applicationComposition.getEditRate(),
"http://www.smpte-ra.org/schemas/2067-21/2016",
Application2ExtendedComposition.SCHEMA_URI_APP2E_2016,
buildTrackFileInfoMap(imfErrorLogger),
tempDir,
applicationComposition.getEssenceDescriptorDomNodeMap());
} else if (schemaVersion.equals("2020")) {
IMPBuilder.buildIMP_2016("IMP",
"Netflix",
applicationComposition.getVirtualTracks(),
applicationComposition.getEditRate(),
Application2ExtendedComposition.SCHEMA_URI_APP2E_2020,
buildTrackFileInfoMap(imfErrorLogger),
tempDir,
applicationComposition.getEssenceDescriptorDomNodeMap());
Expand All @@ -132,7 +154,7 @@ private void buildIMPAndValidate(ApplicationComposition applicationComposition,
"Netflix",
applicationComposition.getVirtualTracks(),
applicationComposition.getEditRate(),
"http://www.smpte-ra.org/schemas/2067-21/2016",
Application2ExtendedComposition.SCHEMA_URI_APP2E_2014,
buildTrackFileInfoMap(imfErrorLogger),
tempDir,
applicationComposition.getEssenceDescriptorDomNodeMap());
Expand Down
Loading

0 comments on commit 6d5cc46

Please sign in to comment.