pyidentity.py 2.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#!/usr/bin/env python

import pygtk
pygtk.require ("2.0")
import gobject
gobject.threads_init()

import pygst
pygst.require('0.10')
import gst

class PyIdentity(gst.Element):
    _sinkpadtemplate = gst.PadTemplate ("sink",
                                         gst.PAD_SINK,
                                         gst.PAD_ALWAYS,
                                         gst.caps_new_any())
    _srcpadtemplate = gst.PadTemplate ("src",
                                         gst.PAD_SRC,
                                         gst.PAD_ALWAYS,
                                         gst.caps_new_any())

    def __init__(self):
        gst.Element.__init__(self)

        self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink")
        self.sinkpad.set_chain_function(self.chainfunc)
        self.sinkpad.set_event_function(self.eventfunc)
        self.sinkpad.set_getcaps_function(gst.Pad.proxy_getcaps)
        self.sinkpad.set_setcaps_function(gst.Pad.proxy_setcaps)
        self.add_pad (self.sinkpad)

        self.srcpad = gst.Pad(self._srcpadtemplate, "src")

        self.srcpad.set_event_function(self.srceventfunc)
35
        self.srcpad.set_query_function(self.srcqueryfunc)
36 37 38 39 40 41 42 43 44 45 46
        self.srcpad.set_getcaps_function(gst.Pad.proxy_getcaps)
        self.srcpad.set_setcaps_function(gst.Pad.proxy_setcaps)
        self.add_pad (self.srcpad)

    def chainfunc(self, pad, buffer):
        gst.log ("Passing buffer with ts %d" % (buffer.timestamp))
        return self.srcpad.push (buffer)

    def eventfunc(self, pad, event):
        return self.srcpad.push_event (event)
        
47 48
    def srcqueryfunc (self, pad, query):
        return self.sinkpad.query (query)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
    def srceventfunc (self, pad, event):
        return self.sinkpad.push_event (event)

gobject.type_register(PyIdentity)

pipe = gst.Pipeline()
vt = gst.element_factory_make ("videotestsrc")
i1 = PyIdentity()
color = gst.element_factory_make ("ffmpegcolorspace")
scale = gst.element_factory_make ("videoscale")
q1 = gst.element_factory_make ("queue")
i2 = PyIdentity()
sink = gst.element_factory_make ("autovideosink")

pipe.add (vt, i1, q1, i2, color, scale, sink)
gst.element_link_many (vt, i1, q1, i2, color, scale, sink)

pipe.set_state (gst.STATE_PLAYING)

gobject.MainLoop().run()