Skip to content

Commit

Permalink
Fixed a bug where IAB tracks were returning zero duration.
Browse files Browse the repository at this point in the history
Duration logic is no longer conditional to the Sequence type. Only TrackFileResource sequences are currently supported. Other subtypes may require more specialized logic.
  • Loading branch information
davidt-netflix committed Jun 5, 2020
1 parent 5bdc3c4 commit ea92c29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/main/java/com/netflix/imflibrary/st2067_2/Composition.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,10 @@ public List<? extends IMFBaseResourceType> getResourceList() {
*/
public long getDurationInTrackEditRateUnits(){
long duration = 0L;
if(this.getSequenceTypeEnum().equals(SequenceTypeEnum.MainImageSequence)
|| this.getSequenceTypeEnum().equals(SequenceTypeEnum.MainAudioSequence)){

for(IMFBaseResourceType imfBaseResourceType : this.resources){
IMFTrackFileResourceType imfTrackFileResourceType = IMFTrackFileResourceType.class.cast(imfBaseResourceType);
duration += imfTrackFileResourceType.getSourceDuration().longValue() * imfTrackFileResourceType.getRepeatCount().longValue();
for(IMFBaseResourceType imfBaseResourceType : this.resources){
// Only handle TrackFileResource sequences currently
if (imfBaseResourceType instanceof IMFTrackFileResourceType) {
duration += imfBaseResourceType.getSourceDuration().longValue() * imfBaseResourceType.getRepeatCount().longValue();
}
}
return duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.netflix.imflibrary.IMFErrorLogger;
import com.netflix.imflibrary.IMFErrorLoggerImpl;
import com.netflix.imflibrary.st2067_2.ApplicationComposition;
import com.netflix.imflibrary.st2067_2.ApplicationCompositionFactory;
import com.netflix.imflibrary.st2067_2.Composition;
import org.testng.Assert;
import org.testng.annotations.Test;
import testUtils.TestHelper;
Expand Down Expand Up @@ -156,4 +158,16 @@ public void compositionNegativeTestWrongSubDescriptorValues() throws IOException
ApplicationCompositionFactory.getApplicationComposition(inputFile, imfErrorLogger);
Assert.assertEquals(imfErrorLogger.getErrors().size(), 4);
}

@Test
public void correctDurationTest() throws IOException {
File inputFile = TestHelper.findResourceByPath
("TestIMP/IAB/CPL/IAB_CPL_valid_iabsequence.xml");
IMFErrorLogger imfErrorLogger = new IMFErrorLoggerImpl();
ApplicationComposition composition = ApplicationCompositionFactory.getApplicationComposition(inputFile, imfErrorLogger);
Composition.VirtualTrack iabTrack = composition.getVirtualTracks().stream().filter(vt -> vt.getSequenceTypeEnum() == Composition.SequenceTypeEnum.IABSequence).findFirst().orElse(null);
Assert.assertNotNull(iabTrack);
Assert.assertNotEquals(iabTrack.getDuration(), 0L);
Assert.assertNotEquals(iabTrack.getDurationInTrackEditRateUnits(), 0L);
}
}

0 comments on commit ea92c29

Please sign in to comment.