From a235508f60fd8f9ba703bb6fba76b10f222696f4 Mon Sep 17 00:00:00 2001 From: Daniel Hernandez Date: Wed, 14 Jun 2023 10:46:00 -0700 Subject: [PATCH 1/9] Detecting duplicate resource ids for non-identical resource entries. --- .../AbstractApplicationComposition.java | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) 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..65c6311d 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,8 @@ 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.lang.reflect.Field; +import java.util.*; import java.util.stream.Collectors; /** @@ -236,6 +227,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.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,6 +589,10 @@ public static List getVirtualTrackResourceIDs(@Nonnull Composit return Collections.unmodifiableList(virtualTrackResourceIDs); } + public static void validateResourceList(List resourceList, IMFErrorLogger errorLogger) { + + } + /** * This class is a representation of a Resource SourceEncoding element and trackFileId tuple. @@ -1071,5 +1085,20 @@ public Map> getEssenceDescriptorDomNodeMap() { return this.essenceDescriptorDomNodeMap; } + private static List getDifference(Object s1, Object s2) throws IllegalAccessException { + List values = new ArrayList<>(); + for (Field field : s1.getClass().getDeclaredFields()) { + field.setAccessible(true); + Object value1 = field.get(s1); + Object value2 = field.get(s2); + if (value1 != null && value2 != null) { + if (!Objects.equals(value1, value2)) { + values.add(String.valueOf(field.getName()+": "+value1+" -> "+value2)); + } + } + } + return values; + } + } \ No newline at end of file From f0a2cae1d51ce3cc7d3dbca9e41f3f77102e353c Mon Sep 17 00:00:00 2001 From: Daniel Hernandez Date: Wed, 14 Jun 2023 10:47:20 -0700 Subject: [PATCH 2/9] Updating the definition of equality for IMFTrackFileResourceType to not include the hash. If different hashing algorithms are used for different resources, they could result in the same hash value. --- .../st2067_2/IMFTrackFileResourceType.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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..e30fe295 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,33 @@ 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; + return equivalent(otherImfTrackFileResourceType); + } + + @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 * getHash().hashCode(); + // hash = 31 * hash * hashAlgorithm.hashCode(); + return hash; + } + } From 64ba98f8387fae2bce31e928e54459f77624539f Mon Sep 17 00:00:00 2001 From: Daniel Hernandez Date: Wed, 14 Jun 2023 10:47:57 -0700 Subject: [PATCH 3/9] Updating test CPL to keep error count consistent in existing tests. --- ...eb3d1b9-b77b-4d3f-bbe5-7c69b15dca85_rgba_coding_equation.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 585aa3291d126e49bdd517e9a1dbf6f6e55ef48a Mon Sep 17 00:00:00 2001 From: Daniel Hernandez Date: Wed, 14 Jun 2023 10:51:58 -0700 Subject: [PATCH 4/9] Removing utility method used during debugging --- .../AbstractApplicationComposition.java | 17 ----------------- 1 file changed, 17 deletions(-) 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 65c6311d..33a0022c 100644 --- a/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java +++ b/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java @@ -1084,21 +1084,4 @@ private Map> createEssenceDescriptorDomNodeMap() { public Map> getEssenceDescriptorDomNodeMap() { return this.essenceDescriptorDomNodeMap; } - - private static List getDifference(Object s1, Object s2) throws IllegalAccessException { - List values = new ArrayList<>(); - for (Field field : s1.getClass().getDeclaredFields()) { - field.setAccessible(true); - Object value1 = field.get(s1); - Object value2 = field.get(s2); - if (value1 != null && value2 != null) { - if (!Objects.equals(value1, value2)) { - values.add(String.valueOf(field.getName()+": "+value1+" -> "+value2)); - } - } - } - return values; - } - - } \ No newline at end of file From 95d3b6ca21e0c1cbd513c9e7b132c0dd607a7050 Mon Sep 17 00:00:00 2001 From: Daniel Hernandez Date: Wed, 14 Jun 2023 10:54:38 -0700 Subject: [PATCH 5/9] Updating error severity to NON_FATAL --- .../imflibrary/st2067_2/AbstractApplicationComposition.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 33a0022c..5a68e653 100644 --- a/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java +++ b/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java @@ -240,7 +240,7 @@ private static Map> getVirtualTrackResourceMap(@ } else { if (!resourceSet.contains(baseResource)) { imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_CPL_ERROR, - IMFErrorLogger.IMFErrors.ErrorLevels.FATAL, String.format("The CPL contains different resources with the same ID %s in virtual track %s", + IMFErrorLogger.IMFErrors.ErrorLevels.NON_FATAL, String.format("The CPL contains different resources with the same ID %s in virtual track %s", resourceId, sequence.getTrackId())); } From 76d6ff60fba7359e08a4dad7961110eef6fc65b7 Mon Sep 17 00:00:00 2001 From: Daniel Hernandez Date: Wed, 14 Jun 2023 11:03:51 -0700 Subject: [PATCH 6/9] Removing unnecessary import --- .../imflibrary/st2067_2/AbstractApplicationComposition.java | 1 - 1 file changed, 1 deletion(-) 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 5a68e653..5405a626 100644 --- a/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java +++ b/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java @@ -58,7 +58,6 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; -import java.lang.reflect.Field; import java.util.*; import java.util.stream.Collectors; From 8b1675e6545c9cac9c8eb5e2f67e9f8772213988 Mon Sep 17 00:00:00 2001 From: Daniel Hernandez Date: Wed, 14 Jun 2023 11:22:42 -0700 Subject: [PATCH 7/9] Removing draft code --- .../imflibrary/st2067_2/AbstractApplicationComposition.java | 5 ----- 1 file changed, 5 deletions(-) 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 5405a626..4be8fe97 100644 --- a/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java +++ b/src/main/java/com/netflix/imflibrary/st2067_2/AbstractApplicationComposition.java @@ -588,11 +588,6 @@ public static List getVirtualTrackResourceIDs(@Nonnull Composit return Collections.unmodifiableList(virtualTrackResourceIDs); } - public static void validateResourceList(List resourceList, IMFErrorLogger errorLogger) { - - } - - /** * This class is a representation of a Resource SourceEncoding element and trackFileId tuple. */ From 67a6a527a0b408111cde9b9bb0b709af02f77299 Mon Sep 17 00:00:00 2001 From: Daniel Hernandez Date: Fri, 16 Jun 2023 13:04:42 -0700 Subject: [PATCH 8/9] Using all elements except id for equivalence check --- .../imflibrary/st2067_2/IMFTrackFileResourceType.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 e30fe295..c6ce3866 100644 --- a/src/main/java/com/netflix/imflibrary/st2067_2/IMFTrackFileResourceType.java +++ b/src/main/java/com/netflix/imflibrary/st2067_2/IMFTrackFileResourceType.java @@ -119,7 +119,12 @@ public boolean equals(Object o) { return false; } IMFTrackFileResourceType otherImfTrackFileResourceType = (IMFTrackFileResourceType) o; - return equivalent(otherImfTrackFileResourceType); + boolean result = equivalent(otherImfTrackFileResourceType); + result &= sourceEncoding.equals(otherImfTrackFileResourceType.getSourceEncoding()); + result &= Arrays.equals(hash, otherImfTrackFileResourceType.getHash()); + result &= hashAlgorithm.equals(otherImfTrackFileResourceType.getHashAlgorithm()); + + return result; } @Override @@ -133,8 +138,8 @@ public int hashCode() { hash = 31 * hash * sourceDuration.hashCode(); hash = 31 * hash * repeatCount.hashCode(); hash = 31 * hash * sourceEncoding.hashCode(); - // hash = 31 * hash * getHash().hashCode(); - // hash = 31 * hash * hashAlgorithm.hashCode(); + hash = 31 * hash * Arrays.hashCode(getHash()); + hash = 31 * hash * hashAlgorithm.hashCode(); return hash; } From 84bff1909c3c06498ecd76b37edcf13f25048a62 Mon Sep 17 00:00:00 2001 From: Daniel Hernandez Date: Fri, 16 Jun 2023 15:39:34 -0700 Subject: [PATCH 9/9] Using all elements of trackFileResourceType for equals and hashcode --- .../netflix/imflibrary/st2067_2/IMFTrackFileResourceType.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 c6ce3866..03154296 100644 --- a/src/main/java/com/netflix/imflibrary/st2067_2/IMFTrackFileResourceType.java +++ b/src/main/java/com/netflix/imflibrary/st2067_2/IMFTrackFileResourceType.java @@ -123,6 +123,7 @@ public boolean equals(Object o) { result &= sourceEncoding.equals(otherImfTrackFileResourceType.getSourceEncoding()); result &= Arrays.equals(hash, otherImfTrackFileResourceType.getHash()); result &= hashAlgorithm.equals(otherImfTrackFileResourceType.getHashAlgorithm()); + result &= id.equals(otherImfTrackFileResourceType.getId()); return result; } @@ -130,7 +131,7 @@ public boolean equals(Object o) { @Override public int hashCode() { int hash = 7; - // hash = 31 * hash * id.hashCode(); + hash = 31 * hash * id.hashCode(); hash = 31 * hash * trackFileId.hashCode(); hash = 31 * hash * editRate.hashCode(); hash = 31 * hash * intrinsicDuration.hashCode();