diff --git a/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java b/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java index 812dee78..4be8fe97 100644 --- a/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java +++ b/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java @@ -58,17 +58,7 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; /** @@ -236,6 +226,25 @@ private static Map> getVirtualTrackResourceMap(@ if (virtualTrackResourceMap.get(uuid) == null) { virtualTrackResourceMap.put(uuid, new ArrayList()); } + /* + Ensure that no two resources use the same ID, unless they are the same resource. ST-2067-3:2020, 6.11.1 + */ + Set resourceIdSet = new HashSet<>(); + Set resourceSet = new HashSet<>(); + for (IMFBaseResourceType baseResource : sequence.getResourceList()) { + String resourceId = baseResource.getId(); + if (!resourceIdSet.contains(resourceId)) { + resourceIdSet.add(resourceId); + resourceSet.add(baseResource); + } else { + if (!resourceSet.contains(baseResource)) { + imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_CPL_ERROR, + IMFErrorLogger.IMFErrors.ErrorLevels.NON_FATAL, String.format("The CPL contains different resources with the same ID %s in virtual track %s", + resourceId, + sequence.getTrackId())); + } + } + } for (IMFBaseResourceType baseResource : sequence.getResourceList()) { /* Ignore track file resource with zero or negative duration */ @@ -579,7 +588,6 @@ public static List getVirtualTrackResourceIDs(@Nonnull Composit return Collections.unmodifiableList(virtualTrackResourceIDs); } - /** * This class is a representation of a Resource SourceEncoding element and trackFileId tuple. */ @@ -1070,6 +1078,4 @@ private Map> createEssenceDescriptorDomNodeMap() { public Map> getEssenceDescriptorDomNodeMap() { return this.essenceDescriptorDomNodeMap; } - - } \ No newline at end of file diff --git a/src/main/java/com/netflix/imflibrary/st2067_2/IMFTrackFileResourceType.java b/src/main/java/com/netflix/imflibrary/st2067_2/IMFTrackFileResourceType.java index 3eabbaa9..03154296 100644 --- a/src/main/java/com/netflix/imflibrary/st2067_2/IMFTrackFileResourceType.java +++ b/src/main/java/com/netflix/imflibrary/st2067_2/IMFTrackFileResourceType.java @@ -109,4 +109,39 @@ public boolean equivalent(IMFBaseResourceType other) return result; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + IMFTrackFileResourceType otherImfTrackFileResourceType = (IMFTrackFileResourceType) o; + boolean result = equivalent(otherImfTrackFileResourceType); + result &= sourceEncoding.equals(otherImfTrackFileResourceType.getSourceEncoding()); + result &= Arrays.equals(hash, otherImfTrackFileResourceType.getHash()); + result &= hashAlgorithm.equals(otherImfTrackFileResourceType.getHashAlgorithm()); + result &= id.equals(otherImfTrackFileResourceType.getId()); + + return result; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash * id.hashCode(); + hash = 31 * hash * trackFileId.hashCode(); + hash = 31 * hash * editRate.hashCode(); + hash = 31 * hash * intrinsicDuration.hashCode(); + hash = 31 * hash * entryPoint.hashCode(); + hash = 31 * hash * sourceDuration.hashCode(); + hash = 31 * hash * repeatCount.hashCode(); + hash = 31 * hash * sourceEncoding.hashCode(); + hash = 31 * hash * Arrays.hashCode(getHash()); + hash = 31 * hash * hashAlgorithm.hashCode(); + return hash; + } + } diff --git a/src/test/resources/TestIMP/Application2/CPL_0eb3d1b9-b77b-4d3f-bbe5-7c69b15dca85_rgba_coding_equation.xml b/src/test/resources/TestIMP/Application2/CPL_0eb3d1b9-b77b-4d3f-bbe5-7c69b15dca85_rgba_coding_equation.xml index 43255c92..e51e546b 100755 --- a/src/test/resources/TestIMP/Application2/CPL_0eb3d1b9-b77b-4d3f-bbe5-7c69b15dca85_rgba_coding_equation.xml +++ b/src/test/resources/TestIMP/Application2/CPL_0eb3d1b9-b77b-4d3f-bbe5-7c69b15dca85_rgba_coding_equation.xml @@ -481,7 +481,7 @@ urn:uuid:61d91654-2650-4abf-abbc-ad2c7f640bf8 - urn:uuid:a5586a0b-1e3f-4c99-9de5-5a66f20cbaf8 + urn:uuid:a5586a0b-1e3f-4c99-9de5-5a66f20cbaf9 60000 1001 40 20