write a python source plugin?

Oleksandr Lavrushchenko kpykcb at gmail.com
Thu Jul 7 13:46:46 PDT 2011


Hi,

is it possible to use the python bindings to create a source plugin?
>
just yesterday i faced with same question.
And i don't know how, but at first i lost from view most obvious place of
getting information, this is:

- http://cgit.freedesktop.org/gstreamer/gst-python/tree/examples/filesrc.py

But fortunately i found next few very helpful links:

- http://guillaume.segu.in/blog/code/223/useful-paralellism-with-python/
- http://nullege.com/codes/search/gst.PushSrc
- http://svn.annodex.net/keystroke/trunk/textsrc.py

So basically you have to inherit from BaseSrc or PushSrc and implement
do_create method. If your source support seeking than few other also.

On debian testing/unstable PushSrc seems not available in python-gst package
so i inherited BaseSrc.

I imagine something closely related to the imagefreeze plugin:
>   - behave like imagefreeze most of the time (serve static image at
> specified fps)
>

Can't say something here, you may be need to give close attention to clocks
in gstreamer to source at specific fps. Will be glad to hear how you do this
if you will figure this out,

  - change image whenever new image arrives from somewhere else within
> my (python) code.
>
You just need to update you source buffer passed through do_create function.


Here is my code to push text string through udp (this like a little bit
simplified version of filesrc example).

#!/usr/bin/env python
""" Source buf """
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#

import gobject
gobject.threads_init()

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

class Bufsrc(gst.BaseSrc):
    """ Push text """
    #here we register our plugin details
    __gstdetails__ = (
        "bufsrc test plugin",
        "bufsrc.py",
        "Source element that create a buffer",
        "Oleksandr Lavrushchenko <____ at gmail.com>")

    _src_template = gst.PadTemplate ("src",
                                     gst.PAD_SRC,
                                     gst.PAD_ALWAYS,
                                     gst.caps_new_any ())

    __gsttemplates__ = (_src_template,)

    def __init__ (self, *args, **kwargs):
        gst.BaseSrc.__init__(self)
        gst.info('creating srcpad')
        self.src_pad = gst.Pad (self._src_template)
        self.src_pad.use_fixed_caps()

        #self.add_pad (self.src_pad)

    def do_create(self, offset, length):
        buf = gst.Buffer("data\n")
        buf.timestamp = 0
        buf.duration = pow(2, 63) -1
        return gst.FLOW_OK, buf

# Register element class
gobject.type_register(Bufsrc)
gst.element_register(Bufsrc, 'bufsrc', gst.RANK_MARGINAL)

sink = gst.element_factory_make("udpsink", "sink")
sink.set_property("port", 5000)
sink.set_property("host", "127.0.0.1")

pusher = Bufsrc()

player = gst.Pipeline("player")
player.add(pusher, sink)
gst.element_link_many(pusher2, sink)

player.set_state(gst.STATE_PLAYING)

gobject.MainLoop().run()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20110707/eac1cd1e/attachment.htm>


More information about the gstreamer-devel mailing list