Skip to content

Commit

Permalink
Merge pull request #111 from Netflix/feature/AudioChannelIDCheck
Browse files Browse the repository at this point in the history
Added validation for Audio channel mapping
  • Loading branch information
svenkatrav authored Sep 13, 2016
2 parents 7059ee3 + 4e212cb commit 1beacc5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/main/java/com/netflix/imflibrary/IMFConstraints.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -183,26 +185,23 @@ public static HeaderPartitionIMF checkIMFCompliance(MXFOperationalPattern1A.Head
}
else {
//Section 5.3.6.2 st2067-2:2016
List<InterchangeObject.InterchangeObjectBO> audioChannelLabelSubDescriptors = subDescriptors.subList(0, subDescriptors.size()).stream().filter(interchangeObjectBO -> interchangeObjectBO.getClass().getEnclosingClass().equals(AudioChannelLabelSubDescriptor.class)).collect(Collectors.toList());
if (waveAudioEssenceDescriptor.getChannelCount() != audioChannelLabelSubDescriptors.size()) {
Map<Long, AudioChannelLabelSubDescriptor.AudioChannelLabelSubDescriptorBO> audioChannelLabelSubDescriptorMap = headerPartition.getAudioChannelIDToMCASubDescriptorMap();
if (waveAudioEssenceDescriptor.getChannelCount() != audioChannelLabelSubDescriptorMap.size()) {
imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_ESSENCE_COMPONENT_ERROR, IMFErrorLogger.IMFErrors.ErrorLevels.NON_FATAL, IMFConstraints.IMF_ESSENCE_EXCEPTION_PREFIX +
String.format("WaveAudioEssenceDescriptor indicates a channel count of %d, however there are %d AudioChannelLabelSubdescriptors, every audio channel should refer to exactly one AudioChannelLabelSubDescriptor and vice versa.", waveAudioEssenceDescriptor.getChannelCount(), audioChannelLabelSubDescriptors.size()));
String.format("WaveAudioEssenceDescriptor indicates a channel count of %d, however there are %d AudioChannelLabelSubdescriptors, every audio channel should refer to exactly one AudioChannelLabelSubDescriptor and vice versa.", waveAudioEssenceDescriptor.getChannelCount(), audioChannelLabelSubDescriptorMap.size()));
}
for (InterchangeObject.InterchangeObjectBO interchangeObjectBO : audioChannelLabelSubDescriptors) {
MCALabelSubDescriptor.MCALabelSubDescriptorBO mcaLabelSubDescriptorBO = MCALabelSubDescriptor.MCALabelSubDescriptorBO.class.cast(interchangeObjectBO);
for (Long channelID = 1L ; channelID <= waveAudioEssenceDescriptor.getChannelCount() ; channelID++) {
//Section 5.3.6.5 st2067-2:2016
if (mcaLabelSubDescriptorBO.getMCAChannelID() == null) {
if (!audioChannelLabelSubDescriptorMap.containsKey(channelID)) {
imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_ESSENCE_COMPONENT_ERROR, IMFErrorLogger.IMFErrors.ErrorLevels.NON_FATAL, IMFConstraints.IMF_ESSENCE_EXCEPTION_PREFIX +
String.format("WaveAudioEssenceDescriptor refers to a AudioChannelLabelSubdescriptor that does not have its Channel-ID property set %s", mcaLabelSubDescriptorBO.toString()));
String.format("AudioChannelLabelSubdescriptor missing for ChannelID %d", channelID));
}
}
List<InterchangeObject.InterchangeObjectBO> soundFieldGroupLabelSubDescriptors = subDescriptors.subList(0, subDescriptors.size()).stream().filter(interchangeObjectBO -> interchangeObjectBO.getClass().getEnclosingClass().equals(SoundFieldGroupLabelSubDescriptor.class)).collect(Collectors.toList());
//Section 5.3.6.3 st2067-2:2016
if (soundFieldGroupLabelSubDescriptors.size() != 1) {
if (waveAudioEssenceDescriptor.getChannelCount() != audioChannelLabelSubDescriptors.size()) {
imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_ESSENCE_COMPONENT_ERROR, IMFErrorLogger.IMFErrors.ErrorLevels.NON_FATAL, IMFConstraints.IMF_ESSENCE_EXCEPTION_PREFIX +
String.format("WaveAudioEssenceDescriptor refers to %d SoundFieldGroupLabelSubDescriptors exactly 1 is required", soundFieldGroupLabelSubDescriptors.size()));
}
imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_ESSENCE_COMPONENT_ERROR, IMFErrorLogger.IMFErrors.ErrorLevels.NON_FATAL, IMFConstraints.IMF_ESSENCE_EXCEPTION_PREFIX +
String.format("WaveAudioEssenceDescriptor refers to %d SoundFieldGroupLabelSubDescriptors exactly 1 is required", soundFieldGroupLabelSubDescriptors.size()));
}
else {
SoundFieldGroupLabelSubDescriptor.SoundFieldGroupLabelSubDescriptorBO soundFieldGroupLabelSubDescriptorBO = SoundFieldGroupLabelSubDescriptor.SoundFieldGroupLabelSubDescriptorBO.class.cast(soundFieldGroupLabelSubDescriptors.get(0));
Expand All @@ -214,6 +213,21 @@ public static HeaderPartitionIMF checkIMFCompliance(MXFOperationalPattern1A.Head
imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_ESSENCE_COMPONENT_ERROR, IMFErrorLogger.IMFErrors.ErrorLevels.NON_FATAL, IMFConstraints.IMF_ESSENCE_EXCEPTION_PREFIX +
String.format("WaveAudioEssenceDescriptor refers to a SoundFieldGroupLabelSubDescriptor that is missing one/all of MCATitle, MCATitleVersion, MCAAudioContentKind, MCAAudioElementKind, %n%s.", soundFieldGroupLabelSubDescriptorBO.toString()));
}
SoundFieldGroupLabelSubDescriptor soundFieldGroupLabelSubDescriptor = (SoundFieldGroupLabelSubDescriptor)headerPartition.getSoundFieldGroupLabelSubDescriptors()
.get(0);
List<InterchangeObject> audioChannelLabelSubDescriptors = headerPartition.getAudioChannelLabelSubDescriptors();
for (InterchangeObject interchangeObject : audioChannelLabelSubDescriptors) {
AudioChannelLabelSubDescriptor audioChannelLabelSubDescriptor = AudioChannelLabelSubDescriptor.class.cast(interchangeObject);
//Section 5.3.6.3 st2067-2:2016
if(!audioChannelLabelSubDescriptor.getSoundfieldGroupLinkId()
.equals(soundFieldGroupLabelSubDescriptor.getMCALinkId())) {
imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_ESSENCE_COMPONENT_ERROR, IMFErrorLogger.IMFErrors.ErrorLevels.NON_FATAL, IMFConstraints.IMF_ESSENCE_EXCEPTION_PREFIX +
String.format("Audio channel with MCALinkID %s refers to wrong SoundfieldGroupLinkId %s, Should refer to %s", audioChannelLabelSubDescriptor
.getMCALinkId().toString(),
audioChannelLabelSubDescriptor.getSoundfieldGroupLinkId().toString(),
soundFieldGroupLabelSubDescriptor.getMCALinkId().toString()));
}
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/netflix/imflibrary/st0377/HeaderPartition.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -663,6 +664,22 @@ public String getAudioEssenceSpokenLanguage() throws IOException {
return rfc5646SpokenLanguage;
}

/**
* A method that returns the Channel ID to AudioChannelLabelSubDescriptor
* @return Channel ID to AudioChannelLabelSubDescriptor mapping
*/
@Nullable
public Map<Long, AudioChannelLabelSubDescriptor.AudioChannelLabelSubDescriptorBO> getAudioChannelIDToMCASubDescriptorMap() {
List<InterchangeObject.InterchangeObjectBO> subDescriptors = getSubDescriptors();

Map<Long, AudioChannelLabelSubDescriptor.AudioChannelLabelSubDescriptorBO> audioChannelLabelSubDescriptorMap = new HashMap<>();
subDescriptors.stream()
.filter(e -> e.getClass().getEnclosingClass().equals(AudioChannelLabelSubDescriptor.class))
.map(e -> AudioChannelLabelSubDescriptor.AudioChannelLabelSubDescriptorBO.class.cast(e))
.forEach(e -> audioChannelLabelSubDescriptorMap.put(e.getMCAChannelID() == null? 1 : e.getMCAChannelID(), e));
return audioChannelLabelSubDescriptorMap;
}

/**
* Getter for a parsed InterchangeObject by ID
* @param structuralMetadataID identifier for the structural metadata set
Expand Down

0 comments on commit 1beacc5

Please sign in to comment.