[pitivi: 2/7] tests: refactor tests_alpha_passthrough.py. Add more tests.
- From: Edward Hervey <edwardrv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi: 2/7] tests: refactor tests_alpha_passthrough.py. Add more tests.
- Date: Mon, 23 Aug 2010 10:42:25 +0000 (UTC)
commit 045475a99c4e1b8572de61c029eb493c33bad1bb
Author: Alessandro Decina <alessandro d gmail com>
Date: Fri Aug 20 17:43:59 2010 +0200
tests: refactor tests_alpha_passthrough.py. Add more tests.
tests/test_alpha_passthrough.py | 293 ++++++++++++++++++++++-----------------
1 files changed, 169 insertions(+), 124 deletions(-)
---
diff --git a/tests/test_alpha_passthrough.py b/tests/test_alpha_passthrough.py
index 9dfa7bd..c072576 100644
--- a/tests/test_alpha_passthrough.py
+++ b/tests/test_alpha_passthrough.py
@@ -3,6 +3,7 @@
# tests/test_alpha_passthrough.py
#
# Copyright (c) 2010, Robert Swain <robert swain collabora co uk>
+# Copyright (c) 2010, Alessandro Decina <alessandro decina collabora co uk>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -33,37 +34,58 @@ from pitivi.timeline.track import Track, SourceTrackObject, Interpolator
from pitivi.elements.mixer import SmartVideomixerBinPropertyHelper
from pitivi.utils import infinity
+def set_one_keyframe(track_object, value):
+ interpolator = track_object.getInterpolator("alpha")
+ kf = list(interpolator.getKeyframes())[0]
+ interpolator.setKeyframeValue(kf, value)
+
+def set_all_keyframes(track_object, value):
+ interpolator = track_object.getInterpolator("alpha")
+ if interpolator is not None:
+ for kf in interpolator.getKeyframes():
+ if callable(value):
+ val = value()
+ else:
+ val = value
+ interpolator.setKeyframeValue(kf, val)
+
+def yuv(fourcc):
+ caps = gst.Caps("video/x-raw-yuv,format=(fourcc)%s" % fourcc)
+ return VideoStream(caps)
+
+def rgb():
+ caps = gst.Caps("video/x-raw-rgb,bpp=(int)24,depth=(int)24,"
+ "endianness=(int)4321,red_mask=(int)16711680,"
+ "green_mask=(int)65280,blue_mask=(int)255")
+ return VideoStream(caps)
+
+def make_track_object(stream):
+ factory = VideoTestSourceFactory()
+ factory.duration = 15 * gst.SECOND
+ return SourceTrackObject(factory, stream)
+
class TestAlpha(TestCase):
def setUp(self):
# create a pipeline
self.pipeline = gst.Pipeline()
- # define some streams
- streams = []
- streams.append([VideoStream(gst.Caps('video/x-raw-yuv,format=(fourcc)I420')), VideoTestSourceFactory()])
- streams.append([VideoStream(gst.Caps('video/x-raw-yuv,format=(fourcc)Y42B')), VideoTestSourceFactory()])
- streams.append([VideoStream(gst.Caps('video/x-raw-yuv,format=(fourcc)Y444')), VideoTestSourceFactory()])
- streams.append([VideoStream(gst.Caps('video/x-raw-rgb,bpp=(int)24,depth=(int)24,endianness=(int)4321,red_mask=(int)16711680,green_mask=(int)65280,blue_mask=(int)255')), VideoTestSourceFactory()])
- streams.append([VideoStream(gst.Caps('video/x-raw-yuv,format=(fourcc)AYUV')), VideoTestSourceFactory()])
-
- # make a track, make track objects from the streams and add the track objects to the track
- offset = 0
- count = 0
- self.track1 = Track(streams[0][0])
- self.track_objects = []
- for item in streams:
- count += 1
- stream = item[0]
- factory = item[1]
- factory.duration = 15 * gst.SECOND
- factory.addOutputStream(stream)
- track_object = SourceTrackObject(factory, stream)
- self.track_objects.append(track_object)
- if 2 * (count//2) == count:
- track_object.start = offset
- offset += 15 * gst.SECOND
+ self.track1 = Track(yuv("I420"))
+ track_object1 = make_track_object(yuv("I420"))
+ track_object2 = make_track_object(yuv("Y42B"))
+ track_object3 = make_track_object(yuv("Y444"))
+ track_object4 = make_track_object(rgb())
+ track_object5 = make_track_object(yuv("AYUV"))
+
+ for i, track_object in enumerate((track_object1, track_object2,
+ track_object3, track_object4, track_object5)):
self.track1.addTrackObject(track_object)
+ # set priorities from 1 to 5
+ track_object.priority = i + 1
+
+ # track_object5 falls outside (0s, 15s) so it isn't linked to videomixer
+ track_object5.start = 15 * gst.SECOND
+
# make a fakesink for the pipeline and connect it as necessary with a callback
composition = self.track1.composition
fakesink = gst.element_factory_make('fakesink')
@@ -75,121 +97,144 @@ class TestAlpha(TestCase):
self.pipeline.add(composition)
self.pipeline.add(fakesink)
self.pipeline.set_state(gst.STATE_PAUSED)
-
+
# wait for preroll to complete
bus = self.pipeline.get_bus()
- msg = bus.timed_pop_filtered(gst.CLOCK_TIME_NONE, gst.MESSAGE_ASYNC_DONE | gst.MESSAGE_ERROR)
+ msg = bus.timed_pop_filtered(gst.CLOCK_TIME_NONE,
+ gst.MESSAGE_ASYNC_DONE | gst.MESSAGE_ERROR)
if msg.type == gst.MESSAGE_ERROR:
gerror, debug = msg.parse_error()
print "\nError message: %s\nDebug info: %s" % (gerror, debug)
self.failUnlessEqual(msg.type, gst.MESSAGE_ASYNC_DONE)
+ self.svmbin = list(self.track1.mixer.elements())[0]
+
def tearDown(self):
self.pipeline.set_state(gst.STATE_NULL)
TestCase.tearDown(self)
- def testAlphaAggregation(self):
- svmbin = list(self.track1.mixer.elements())[0]
+ def failUnlessAlphaIsSet(self):
+ # check that each SmartVideomixerBin input has alpha set on its
+ # capsfilter
+ for input in self.svmbin.inputs.values():
+ capsfilter = input[2]
+ self.failUnless(capsfilter.props.caps[0].has_key("format"))
+
+ def failUnlessAlphaIsNotSet(self):
+ # check that each SmartVideomixerBin input has alpha _not_ set on its
+ # capsfilter
+ for input in self.svmbin.inputs.values():
+ capsfilter = input[2]
+ self.failIf(capsfilter.props.caps[0].has_key("format"))
+
+ def testKeyframesOnDifferentObjects(self):
+ # no alpha < 1.0 keyframes
+ for track_obj in self.track1.track_objects:
+ set_all_keyframes(track_obj, 1.0)
+ self.failUnlessAlphaIsNotSet()
+
+ track_object1 = self.track1.track_objects[0]
+ track_object2 = self.track1.track_objects[1]
+
+ # one alpha < 1.0 keyframe
+ set_one_keyframe(track_object1, 0.8)
+ self.failUnlessAlphaIsSet()
- # adjust all up to 1.0
+ # two alpha < 1.0 keyframes
+ set_one_keyframe(track_object2, 0.5)
+ self.failUnlessAlphaIsSet()
+
+ # one alpha < 1.0 keyframe
+ set_one_keyframe(track_object1, 1.0)
+ self.failUnlessAlphaIsSet()
+
+ # no alpha < 1.0 keyframes
+ set_one_keyframe(track_object2, 1.0)
+
+ self.failUnlessAlphaIsNotSet()
+
+ def testKeyframesOnSameObject(self):
for track_obj in self.track1.track_objects:
- interpolator = track_obj.getInterpolator("alpha")
- if interpolator is not None:
- for kf in interpolator.getKeyframes():
- interpolator.setKeyframeValue(kf, 1.0)
- # check that each SmartVideomixerBin input has alpha _not_ set on its capsfilter
- for input in svmbin.inputs.values():
- svmbin_input_capsfilter = input[2]
- self.failIf(svmbin_input_capsfilter.props.caps[0].has_key("format"))
-
- # adjust one below 1.0
- obj = self.track1.track_objects[1]
- interpolator = obj.getInterpolator("alpha")
- for kf in interpolator.getKeyframes():
- interpolator.setKeyframeValue(kf, 0.8)
- break
- # check that each SmartVideomixerBin input has alpha set on its capsfilter
- for input in svmbin.inputs.values():
- svmbin_input_capsfilter = input[2]
- self.failUnlessEqual(svmbin_input_capsfilter.props.caps[0]["format"], gst.Fourcc('AYUV'))
-
- # adjust all below 1.0
+ set_all_keyframes(track_obj, 1.0)
+ self.failUnlessAlphaIsNotSet()
+
+ track_object1 = self.track1.track_objects[0]
+ interpolator1 = track_object1.getInterpolator("alpha")
+
+ keyframe1 = interpolator1.newKeyframe(1 * gst.SECOND, 0.8)
+ self.failUnlessAlphaIsSet()
+
+ keyframe2 = interpolator1.newKeyframe(2 * gst.SECOND, 0.5)
+ self.failUnlessAlphaIsSet()
+
+ interpolator1.setKeyframeValue(keyframe1, 1.0)
+ self.failUnlessAlphaIsSet()
+
+ interpolator1.removeKeyframe(keyframe2)
+ self.failUnlessAlphaIsNotSet()
+
+ def testRemoveTrackObjects(self):
for track_obj in self.track1.track_objects:
- interpolator = track_obj.getInterpolator("alpha")
- if interpolator is not None:
- for kf in interpolator.getKeyframes():
- # random() should return a value in the range [0.0, 1.0)
- interpolator.setKeyframeValue(kf, 0.9 * random.random())
- # check that each SmartVideomixerBin input has alpha set on its capsfilter
- for input in svmbin.inputs.values():
- svmbin_input_capsfilter = input[2]
- self.failUnlessEqual(svmbin_input_capsfilter.props.caps[0]["format"], gst.Fourcc('AYUV'))
-
- # adjust first one to 1.0
+ set_all_keyframes(track_obj, 1.0)
+
+ self.failUnlessAlphaIsNotSet()
+
+ track_object1 = self.track1.track_objects[0]
+ track_object2 = self.track1.track_objects[1]
+
+ # set one keyframe below 1.0
+ set_one_keyframe(track_object1, 0.8)
+ self.failUnlessAlphaIsSet()
+
+ # track_object2 has no alpha < 1.0 keyframes, removing it shouldn't
+ # trigger an alpha change
+ self.track1.removeTrackObject(track_object2)
+ self.failUnlessAlphaIsSet()
+
+ # track_object1 does have an alpha < 1.0 keyframe, removing it should
+ # trigger an alpha change
+ self.track1.removeTrackObject(track_object1)
+
+ self.failUnlessAlphaIsNotSet()
+
+ def testRequestPads(self):
+ # requesting a new pad should never trigger an alpha change
+
+ template = gst.PadTemplate("sink_%u", gst.PAD_SINK, gst.PAD_REQUEST,
+ gst.Caps("video/x-raw-yuv;video/x-raw-rgb"))
+
+ for track_obj in self.track1.track_objects:
+ set_all_keyframes(track_obj, 1.0)
+
+ # when unset, should remain unset
+ self.failUnlessAlphaIsNotSet()
+ test_pad1 = self.svmbin.do_request_new_pad(template)
+ self.failUnlessAlphaIsNotSet()
+
obj = self.track1.track_objects[0]
- interpolator = obj.getInterpolator("alpha")
- for kf in interpolator.getKeyframes():
- interpolator.setKeyframeValue(kf, 1.0)
- break
- # check that each SmartVideomixerBin input has alpha set on its capsfilter
- for input in svmbin.inputs.values():
- svmbin_input_capsfilter = input[2]
- self.failUnlessEqual(svmbin_input_capsfilter.props.caps[0]["format"], gst.Fourcc('AYUV'))
-
- # remove a track object
- self.track1.removeTrackObject(self.track1.track_objects[2])
- # check that there are now just 4 track objects
- self.failUnlessEqual(len(self.track1.track_objects), 4)
- # check that each SmartVideomixerBin input has alpha set on its capsfilter
- for input in svmbin.inputs.values():
- svmbin_input_capsfilter = input[2]
- self.failUnlessEqual(svmbin_input_capsfilter.props.caps[0]["format"], gst.Fourcc('AYUV'))
-
- # adjust all up to 1.0 again
+ set_one_keyframe(obj, 0.8)
+
+ # when set, should remain set
+ self.failUnlessAlphaIsSet()
+ test_pad2 = self.svmbin.do_request_new_pad(template)
+ self.failUnlessAlphaIsSet()
+
+ def testTransitions(self):
for track_obj in self.track1.track_objects:
- interpolator = track_obj.getInterpolator("alpha")
- if interpolator is not None:
- for kf in interpolator.getKeyframes():
- interpolator.setKeyframeValue(kf, 1.0)
- # check that each SmartVideomixerBin input has alpha _not_ set on its capsfilter
- for input in svmbin.inputs.values():
- svmbin_input_capsfilter = input[2]
- self.failIf(svmbin_input_capsfilter.props.caps[0].has_key("format"))
-
- # remove a track object
- self.track1.removeTrackObject(self.track1.track_objects[0])
- # check that there is now just 3 track objects
- self.failUnlessEqual(len(self.track1.track_objects), 3)
- # check that each SmartVideomixerBin input has alpha _not_ set on its capsfilter
- for input in svmbin.inputs.values():
- svmbin_input_capsfilter = input[2]
- self.failIf(svmbin_input_capsfilter.props.caps[0].has_key("format"))
-
- # adjust one below 1.0 and test do_request_new_pad()
- obj = self.track1.track_objects[1]
- interpolator = obj.getInterpolator("alpha")
- for kf in interpolator.getKeyframes():
- interpolator.setKeyframeValue(kf, 0.8)
- break
- # check that each SmartVideomixerBin input has alpha set on its capsfilter
- for input in svmbin.inputs.values():
- svmbin_input_capsfilter = input[2]
- self.failUnlessEqual(svmbin_input_capsfilter.props.caps[0]["format"], gst.Fourcc('AYUV'))
- # call do_request_new_pad()
- template = gst.PadTemplate("sink_%u", gst.PAD_SINK, gst.PAD_REQUEST,
- gst.Caps("video/x-raw-yuv;video/x-raw-rgb"))
- test_pad = svmbin.do_request_new_pad(template)
- for input in svmbin.inputs.values():
- svmbin_input_capsfilter = input[2]
- self.failUnlessEqual(svmbin_input_capsfilter.props.caps[0]["format"], gst.Fourcc('AYUV'))
-
- # remove the only track_object with an alpha keyframe
- self.track1.removeTrackObject(obj)
- # check that there is now just 2 track objects
- self.failUnlessEqual(len(self.track1.track_objects), 2)
- # check that each SmartVideomixerBin input has alpha _not_ set on its capsfilter
- for input in svmbin.inputs.values():
- svmbin_input_capsfilter = input[2]
- self.failIf(svmbin_input_capsfilter.props.caps[0].has_key("format"))
+ set_all_keyframes(track_obj, 1.0)
+ self.failUnlessAlphaIsNotSet()
+
+ track_object1 = self.track1.track_objects[0]
+ track_object2 = self.track1.track_objects[1]
+
+ track_object1.start = 0
+ track_object2.start = 10 * gst.SECOND
+ old_priority = track_object2.priority
+ track_object2.priority = track_object1.priority
+ self.track1.updateTransitions()
+ self.failUnlessAlphaIsSet()
+ track_object2.priority = old_priority
+ self.track1.updateTransitions()
+ self.failUnlessAlphaIsNotSet()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]