Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: detect duplicate resource ids in virtual track #350

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -236,6 +226,25 @@ private static Map<UUID, List<IMFBaseResourceType>> getVirtualTrackResourceMap(@
if (virtualTrackResourceMap.get(uuid) == null) {
virtualTrackResourceMap.put(uuid, new ArrayList<IMFBaseResourceType>());
}
/*
Ensure that no two resources use the same ID, unless they are the same resource. ST-2067-3:2020, 6.11.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on this statement the equals and hashcode methods for the resource should include all the elements defined in the resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the PR so that the equals and hashcode methods include all elements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would interpret 6.11.1 as meaning that Resource IDs are unique throughout the entire composition:
"No two Resouces shall have the same ID value unless they are identical."

It looks like this check is limited to detecting duplicates only within the same Sequence.
As a practical matter, that is generally good enough. But I believe there are other possible scenarios that this check would still miss.

*/
Set<String> resourceIdSet = new HashSet<>();
Set<IMFBaseResourceType> 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 */
Expand Down Expand Up @@ -579,7 +588,6 @@ public static List<ResourceIdTuple> getVirtualTrackResourceIDs(@Nonnull Composit
return Collections.unmodifiableList(virtualTrackResourceIDs);
}


/**
* This class is a representation of a Resource SourceEncoding element and trackFileId tuple.
*/
Expand Down Expand Up @@ -1070,6 +1078,4 @@ private Map<UUID, List<Node>> createEssenceDescriptorDomNodeMap() {
public Map<UUID, List<Node>> getEssenceDescriptorDomNodeMap() {
return this.essenceDescriptorDomNodeMap;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@
<TrackFileId>urn:uuid:61d91654-2650-4abf-abbc-ad2c7f640bf8</TrackFileId>
</Resource>
<Resource xsi:type="TrackFileResourceType">
<Id>urn:uuid:a5586a0b-1e3f-4c99-9de5-5a66f20cbaf8</Id>
<Id>urn:uuid:a5586a0b-1e3f-4c99-9de5-5a66f20cbaf9</Id>
<EditRate>60000 1001</EditRate>
<IntrinsicDuration>40</IntrinsicDuration>
<EntryPoint>20</EntryPoint>
Expand Down