def testSaveStream(self):
     stream = VideoStream(gst.Caps("video/x-raw-rgb, blah=meh"))
     element = self.formatter._saveStream(stream)
     self.failUnlessEqual(element.tag, "stream")
     self.failUnless("id" in element.attrib)
     self.failUnlessEqual(element.attrib["type"], qual(stream.__class__))
     self.failUnlessEqual(element.attrib["caps"], str(stream.caps))
    def testSaveTrackEffect(self):
        video_stream = VideoStream(gst.Caps("video/x-raw-yuv"))
        audio_stream = AudioStream(gst.Caps("audio/x-raw-int"))

        effect1 = EffectFactory('identity', 'identity')
        effect1.addOutputStream(video_stream)
        effect1.addInputStream(video_stream)

        #It is necessary to had the identity factory to the
        #effect_factories_dictionnary
        self.formatter.avalaible_effects._effect_factories_dict['identity'] =\
                                                                     effect1
        track_effect = TrackEffect(effect1, video_stream,
                start=10 * gst.SECOND, duration=20 * gst.SECOND,
                in_point=5 * gst.SECOND, media_duration=15 * gst.SECOND,
                priority=10)

        track = Track(video_stream)
        track.addTrackObject(track_effect)

        element = self.formatter._saveTrackObject(track_effect)
        self.failUnlessEqual(element.tag, "track-object")
        self.failUnlessEqual(element.attrib["type"],
                qual(track_effect.__class__))
        self.failUnlessEqual(element.attrib["start"], ts(10 * gst.SECOND))
        self.failUnlessEqual(element.attrib["duration"], ts(20 * gst.SECOND))
        self.failUnlessEqual(element.attrib["in_point"], ts(5 * gst.SECOND))
        self.failUnlessEqual(element.attrib["media_duration"],
                ts(15 * gst.SECOND))
        self.failUnlessEqual(element.attrib["priority"], "(int)10")

        effect_element = element.find('effect')
        self.failIfEqual(effect_element, None)
        self.failIfEqual(effect_element.find("factory"), None)
        self.failIfEqual(effect_element.find("gst-element-properties"), None)
Beispiel #3
0
    def _saveTrackObject(self, track_object):
        element = Element("track-object")
        element.attrib["id"] = self._new_element_id()
        element.attrib["type"] = qual(track_object.__class__)
        for attribute in ("start", "duration",
                "in_point", "media_duration"):
            element.attrib[attribute] = \
                    str("(gint64)%s" % getattr(track_object, attribute))

        element.attrib["priority"] = "(int)%s" % track_object.priority

        factory_ref = \
                self._saveFactoryRef(track_object.factory)
        stream_ref = self._saveStreamRef(track_object.stream)

        element.append(factory_ref)
        element.append(stream_ref)
        interpolators = track_object.getInterpolators()
        curves = Element("curves")
        for property, interpolator in interpolators.itervalues():
            curves.append(self._saveInterpolator(interpolator, property))
        element.append(curves)

        self._context.track_objects[track_object] = element

        return element
Beispiel #4
0
    def _saveStream(self, stream):
        element = Element("stream")
        element.attrib["id"] = self._new_element_id()
        element.attrib["type"] = qual(stream.__class__)
        element.attrib["caps"] = str(stream.caps)
        element.attrib["name"] = str(stream.pad_name)

        self._context.streams[stream] = element

        return element
    def testLoadStream(self):
        caps = gst.Caps("video/x-raw-yuv")
        element = Element("stream")
        element.attrib["id"] = "1"
        element.attrib["type"] = "pitivi.stream.VideoStream"
        element.attrib["caps"] = str(caps)

        stream = self.formatter._loadStream(element)
        self.failUnlessEqual(qual(stream.__class__), element.attrib["type"])
        self.failUnlessEqual(str(stream.caps), str(caps))
        self.failUnlessEqual(stream, self.formatter._context.streams["1"])
    def testSaveSource(self):
        video_stream = VideoStream(gst.Caps("video/x-raw-yuv"))
        audio_stream = AudioStream(gst.Caps("audio/x-raw-int"))
        source1 = FileSourceFactory("file1.ogg")
        source1.addOutputStream(video_stream)
        source1.addOutputStream(audio_stream)
        element = self.formatter._saveSource(source1)
        self.failUnlessEqual(element.tag, "source")
        self.failUnlessEqual(element.attrib["type"], qual(source1.__class__))
        self.failUnlessEqual(element.attrib["filename"], "file1.ogg")

        streams = element.find("output-streams")
        self.failUnlessEqual(len(streams), 2)
Beispiel #7
0
    def _saveTrackObject(self, track_object):
        element = Element("track-object")
        element.attrib["id"] = self._new_element_id()
        element.attrib["type"] = qual(track_object.__class__)
        for attribute in ("start", "duration",
                "in_point", "media_duration"):
            element.attrib[attribute] = \
                    str("(gint64)%s" % getattr(track_object, attribute))

        element.attrib["priority"] = "(int)%s" % track_object.priority
        element.attrib["active"] = "(bool)%s" % track_object.active

        if not isinstance(track_object.factory, EffectFactory):
            self._saveSourceTrackObject(track_object, element)
        else:
            self._saveTrackEffect(track_object, element)

        self._context.track_objects[track_object] = element

        return element
Beispiel #8
0
    def _saveObjectFactory(self, factory):
        element = Element("source")
        element.attrib["id"] = self._new_element_id()
        element.attrib["type"] = qual(factory.__class__)
        element.attrib["default_duration"] = str(factory.default_duration)
        element.attrib["duration"] = str(factory.duration)

        input_streams_element = SubElement(element, "input-streams")
        input_streams = factory.getInputStreams()
        for stream in input_streams:
            stream_element = self._saveStream(stream)
            input_streams_element.append(stream_element)

        output_streams_element = SubElement(element, "output-streams")
        output_streams = factory.getOutputStreams()
        for stream in output_streams:
            stream_element = self._saveStream(stream)
            output_streams_element.append(stream_element)

        self._context.factories[factory] = element

        return element
    def testSaveTrackObject(self):
        video_stream = VideoStream(gst.Caps("video/x-raw-yuv"))
        audio_stream = AudioStream(gst.Caps("audio/x-raw-int"))
        source1 = FileSourceFactory("file1.ogg")
        source1.addOutputStream(video_stream)

        # these two calls are needed to populate the context for the -ref
        # elements
        self.formatter._saveSource(source1)
        self.formatter._saveStream(video_stream)

        track_object = SourceTrackObject(source1, video_stream,
                start=10 * gst.SECOND, duration=20 * gst.SECOND,
                in_point=5 * gst.SECOND, media_duration=15 * gst.SECOND,
                priority=10)
        track = Track(video_stream)
        track.addTrackObject(track_object)

        # create an interpolator and insert it into the track object
        fakevol = gst.element_factory_make("volume")
        prop = get_controllable_properties(fakevol)[1][1]
        volcurve = Interpolator(track_object, fakevol, prop)
        track_object.interpolators[prop.name] = (prop, volcurve)

        # add some points to the interpolator 
        value = float(0)
        volcurve.start.setObjectTime(0)
        volcurve.start.value = 0
        for t in xrange(3, 15, 3):
            value = int(t % 2)
            volcurve.newKeyframe(t * gst.SECOND, value)
        volcurve.end.setObjectTime(15 * gst.SECOND)
        volcurve.end.value = 15 % 2

        element = self.formatter._saveTrackObject(track_object)
        self.failUnlessEqual(element.tag, "track-object")
        self.failUnlessEqual(element.attrib["type"],
                qual(track_object.__class__))
        self.failUnlessEqual(element.attrib["start"], ts(10 * gst.SECOND))
        self.failUnlessEqual(element.attrib["duration"], ts(20 * gst.SECOND))
        self.failUnlessEqual(element.attrib["in_point"], ts(5 * gst.SECOND))
        self.failUnlessEqual(element.attrib["media_duration"],
                ts(15 * gst.SECOND))
        self.failUnlessEqual(element.attrib["priority"], "(int)10")

        self.failIfEqual(element.find("factory-ref"), None)
        self.failIfEqual(element.find("stream-ref"), None)

        # find the interpolation keyframes
        curves = element.find("curves")
        self.failIfEqual(curves, None)
        curve = curves.find("curve")
        self.failIfEqual(curve, None)
        self.failUnlessEqual(curve.attrib["property"], "volume")
        
        # compute a dictionary of keyframes
        saved_points = dict(((obj.attrib["time"], (obj.attrib["value"],
            obj.attrib["mode"])) for obj in curve.getiterator("keyframe")))

        # compare this with the expected values
        expected = dict(((str(t * gst.SECOND), ("(gdouble)%s" % (t % 2), "2")) for t in
            xrange(3, 15, 3)))
        self.failUnlessEqual(expected, saved_points)