def testGapFinder(self): timeline_object1 = self.makeTimelineObject() timeline_object2 = self.makeTimelineObject() timeline_object3 = self.makeTimelineObject() timeline_object4 = self.makeTimelineObject() timeline_object1.start = 5 * gst.SECOND timeline_object1.duration = 10 * gst.SECOND timeline_object1.priority = 1 timeline_object2.start = 20 * gst.SECOND timeline_object2.duration = 10 * gst.SECOND timeline_object2.priority = 1 timeline_object3.start = 31 * gst.SECOND timeline_object3.duration = 10 * gst.SECOND timeline_object3.priority = 2 timeline_object4.start = 50 * gst.SECOND timeline_object4.duration = 10 * gst.SECOND timeline_object4.priority = 2 gap_finder = SmallestGapsFinder(set([timeline_object2, timeline_object3])) gap_finder.update(*Gap.findAroundObject(timeline_object2)) gap_finder.update(*Gap.findAroundObject(timeline_object3)) left_gap = gap_finder.left_gap right_gap = gap_finder.right_gap self.failUnlessEqual(left_gap.left_object, timeline_object1) self.failUnlessEqual(left_gap.right_object, timeline_object2) self.failUnlessEqual(left_gap.start, 15 * gst.SECOND) self.failUnlessEqual(left_gap.duration, 5 * gst.SECOND) self.failUnlessEqual(right_gap.left_object, timeline_object3) self.failUnlessEqual(right_gap.right_object, timeline_object4) self.failUnlessEqual(right_gap.start, 41 * gst.SECOND) self.failUnlessEqual(right_gap.duration, 9 * gst.SECOND) # make timeline_object3 and timeline_object4 overlap timeline_object3.duration = 20 * gst.SECOND gap_finder = SmallestGapsFinder(set([timeline_object4])) gap_finder.update(*Gap.findAroundObject(timeline_object4)) left_gap = gap_finder.left_gap right_gap = gap_finder.right_gap self.failUnlessEqual(left_gap, invalid_gap) self.failUnlessEqual(right_gap.left_object, timeline_object4) self.failUnlessEqual(right_gap.right_object, None) self.failUnlessEqual(right_gap.start, 60 * gst.SECOND) self.failUnlessEqual(right_gap.duration, infinity) gap_finder = SmallestGapsFinder(set([timeline_object3])) gap_finder.update(*Gap.findAroundObject(timeline_object3)) left_gap = gap_finder.left_gap right_gap = gap_finder.right_gap self.failUnlessEqual(left_gap.left_object, None) self.failUnlessEqual(left_gap.right_object, timeline_object3) self.failUnlessEqual(left_gap.start, 0 * gst.SECOND) self.failUnlessEqual(left_gap.duration, 31 * gst.SECOND) self.failUnlessEqual(right_gap, invalid_gap)
def testGapFinder(self): timeline_object1 = self.makeTimelineObject() timeline_object2 = self.makeTimelineObject() timeline_object3 = self.makeTimelineObject() timeline_object4 = self.makeTimelineObject() timeline_object1.start = 5 * gst.SECOND timeline_object1.duration = 10 * gst.SECOND timeline_object1.priority = 1 timeline_object2.start = 20 * gst.SECOND timeline_object2.duration = 10 * gst.SECOND timeline_object2.priority = 1 timeline_object3.start = 31 * gst.SECOND timeline_object3.duration = 10 * gst.SECOND timeline_object3.priority = 2 timeline_object4.start = 50 * gst.SECOND timeline_object4.duration = 10 * gst.SECOND timeline_object4.priority = 2 gap_finder = SmallestGapsFinder( set([timeline_object2, timeline_object3])) gap_finder.update(*Gap.findAroundObject(timeline_object2)) gap_finder.update(*Gap.findAroundObject(timeline_object3)) left_gap = gap_finder.left_gap right_gap = gap_finder.right_gap self.failUnlessEqual(left_gap.left_object, timeline_object1) self.failUnlessEqual(left_gap.right_object, timeline_object2) self.failUnlessEqual(left_gap.start, 15 * gst.SECOND) self.failUnlessEqual(left_gap.duration, 5 * gst.SECOND) self.failUnlessEqual(right_gap.left_object, timeline_object3) self.failUnlessEqual(right_gap.right_object, timeline_object4) self.failUnlessEqual(right_gap.start, 41 * gst.SECOND) self.failUnlessEqual(right_gap.duration, 9 * gst.SECOND) # make timeline_object3 and timeline_object4 overlap timeline_object3.duration = 20 * gst.SECOND gap_finder = SmallestGapsFinder(set([timeline_object4])) gap_finder.update(*Gap.findAroundObject(timeline_object4)) left_gap = gap_finder.left_gap right_gap = gap_finder.right_gap self.failUnlessEqual(left_gap, invalid_gap) self.failUnlessEqual(right_gap.left_object, timeline_object4) self.failUnlessEqual(right_gap.right_object, None) self.failUnlessEqual(right_gap.start, 60 * gst.SECOND) self.failUnlessEqual(right_gap.duration, infinity) gap_finder = SmallestGapsFinder(set([timeline_object3])) gap_finder.update(*Gap.findAroundObject(timeline_object3)) left_gap = gap_finder.left_gap right_gap = gap_finder.right_gap self.failUnlessEqual(left_gap.left_object, None) self.failUnlessEqual(left_gap.right_object, timeline_object3) self.failUnlessEqual(left_gap.start, 0 * gst.SECOND) self.failUnlessEqual(left_gap.duration, 31 * gst.SECOND) self.failUnlessEqual(right_gap, invalid_gap)
def testFindAllGaps(self): simple = ((3 * gst.SECOND, 1 * gst.SECOND), (1 * gst.SECOND, 1 * gst.SECOND)) objs = [] for start, duration in simple: obj = self.makeTimelineObject() obj.start = start obj.duration = duration objs.append(obj) result = [(g.start, g.initial_duration) for g in Gap.findAllGaps(objs)] self.assertEquals(result, [ (0 * gst.SECOND, 1 * gst.SECOND), (2 * gst.SECOND, 1 * gst.SECOND), ]) complex = [ (1 * gst.SECOND, 2 * gst.SECOND), (6 * gst.SECOND, 2 * gst.SECOND), (10 * gst.SECOND, 2 * gst.SECOND), (8 * gst.SECOND, 2 * gst.SECOND), (14 * gst.SECOND, 1 * gst.SECOND), (4 * gst.SECOND, 1 * gst.SECOND), ] objs = [] for start, duration in complex: obj = self.makeTimelineObject() obj.start = start obj.duration = duration objs.append(obj) result = [(g.start, g.initial_duration) for g in Gap.findAllGaps(objs)] self.assertEquals(result, [ (0 * gst.SECOND, 1 * gst.SECOND), (3 * gst.SECOND, 1 * gst.SECOND), (5 * gst.SECOND, 1 * gst.SECOND), (12 * gst.SECOND, 2 * gst.SECOND), ]) complex.append((2 * gst.SECOND, 5 * gst.SECOND)) objs = [] for start, duration in complex: obj = self.makeTimelineObject() obj.start = start obj.duration = duration objs.append(obj) result = [(g.start, g.initial_duration) for g in Gap.findAllGaps(objs)] self.assertEquals(result, [ (0 * gst.SECOND, 1 * gst.SECOND), (12 * gst.SECOND, 2 * gst.SECOND), ])
def testGapCmp(self): gap1 = Gap(None, None, start=10, duration=5) gap2 = Gap(None, None, start=10, duration=5) self.failUnlessEqual(gap1, gap2) gap2 = Gap(None, None, start=15, duration=4) self.failUnless(gap1 > gap2) self.failUnless(gap2 < gap1)
def testFindAroundObject(self): timeline_object1 = self.makeTimelineObject() timeline_object2 = self.makeTimelineObject() timeline_object1.start = 5 * gst.SECOND timeline_object1.duration = 10 * gst.SECOND timeline_object2.start = 20 * gst.SECOND timeline_object2.duration = 10 * gst.SECOND left_gap, right_gap = Gap.findAroundObject(timeline_object1) self.failUnlessEqual(left_gap.left_object, None) self.failUnlessEqual(left_gap.right_object, timeline_object1) self.failUnlessEqual(left_gap.start, 0 * gst.SECOND) self.failUnlessEqual(left_gap.duration, 5 * gst.SECOND) self.failUnlessEqual(right_gap.left_object, timeline_object1) self.failUnlessEqual(right_gap.right_object, timeline_object2) self.failUnlessEqual(right_gap.start, 15 * gst.SECOND) self.failUnlessEqual(right_gap.duration, 5 * gst.SECOND) left_gap, right_gap = Gap.findAroundObject(timeline_object2) self.failUnlessEqual(left_gap.left_object, timeline_object1) self.failUnlessEqual(left_gap.right_object, timeline_object2) self.failUnlessEqual(left_gap.start, 15 * gst.SECOND) self.failUnlessEqual(left_gap.duration, 5 * gst.SECOND) self.failUnlessEqual(right_gap.left_object, timeline_object2) self.failUnlessEqual(right_gap.right_object, None) self.failUnlessEqual(right_gap.start, 30 * gst.SECOND) self.failUnlessEqual(right_gap.duration, infinity) # make the objects overlap timeline_object2.start = 10 * gst.SECOND left_gap, right_gap = Gap.findAroundObject(timeline_object1) self.failUnlessEqual(right_gap.left_object, timeline_object1) self.failUnlessEqual(right_gap.right_object, timeline_object2) self.failUnlessEqual(right_gap.start, 15 * gst.SECOND) self.failUnlessEqual(right_gap.duration, -5 * gst.SECOND)
def _updateDefaultSourcesUnchecked(self): for source in self.default_sources: self.debug("removing default source %s", self._sourceDebug(source)) self._shutdownDefaultSource(source) self.composition.remove(source) source.set_state(gst.STATE_NULL) gaps = Gap.findAllGaps(self.track_objects) self.default_sources = [] for gap in gaps: source = self._getDefaultTrackObjectForStream(self.stream) gnl_object = source.gnl_object gnl_object.props.start = gap.start gnl_object.props.duration = gap.initial_duration self.debug("adding default source %s", self._sourceDebug(source.gnl_object)) self.composition.add(gnl_object) self.default_sources.append(gnl_object)
def testFindAllGaps(self): simple = ( (3 * gst.SECOND, 1 * gst.SECOND), (1 * gst.SECOND, 1 * gst.SECOND) ) objs = [] for start, duration in simple: obj = self.makeTimelineObject() obj.start = start obj.duration = duration objs.append(obj) result = [(g.start, g.initial_duration) for g in Gap.findAllGaps(objs)] self.assertEquals(result, [ (0 * gst.SECOND, 1 * gst.SECOND), (2 * gst.SECOND, 1 * gst.SECOND), ]) complex = [ (1 * gst.SECOND, 2 * gst.SECOND), (6 * gst.SECOND, 2 * gst.SECOND), (10 * gst.SECOND, 2 * gst.SECOND), (8 * gst.SECOND, 2 * gst.SECOND), (14 * gst.SECOND, 1 * gst.SECOND), (4 * gst.SECOND, 1 * gst.SECOND), ] objs = [] for start, duration in complex: obj = self.makeTimelineObject() obj.start = start obj.duration = duration objs.append(obj) result = [(g.start, g.initial_duration) for g in Gap.findAllGaps(objs)] self.assertEquals(result, [ (0 * gst.SECOND, 1 * gst.SECOND), (3 * gst.SECOND, 1 * gst.SECOND), (5 * gst.SECOND, 1 * gst.SECOND), (12 * gst.SECOND, 2 * gst.SECOND), ]) complex.append((2 * gst.SECOND, 5 * gst.SECOND)) objs = [] for start, duration in complex: obj = self.makeTimelineObject() obj.start = start obj.duration = duration objs.append(obj) result = [(g.start, g.initial_duration) for g in Gap.findAllGaps(objs)] self.assertEquals(result, [ (0 * gst.SECOND, 1 * gst.SECOND), (12 * gst.SECOND, 2 * gst.SECOND), ])