30 Apr 2005 company   » (Master)

What I can do and you can't

I put this in /usr/lib/gstreamer-0.8/python, run gst-register and have a new element available that does what it says.

import gst
import gobject

class ChannelSwap (gst.Element): __gsttemplates__ = ( gst.PadTemplate ("src", gst.PAD_SRC, gst.PAD_ALWAYS, gst.Caps ("audio/x-raw-int, width=16, depth=16, channels=2")), gst.PadTemplate ("sink", gst.PAD_SINK, gst.PAD_ALWAYS, gst.Caps ("audio/x-raw-int, width=16, depth=16, channels=2")) ) __gstdetails__ = ("Channel swapper", "Audio/Filter", "swap left and right channel", "Benjamin Otte <otte@gnome.org>")

def __init__ (self): self.__gobject_init__() self.srcpad = gst.Pad (self.__gsttemplates__[0]) self.srcpad.set_link_function (self.link) self.srcpad.set_getcaps_function (self.getcaps) self.add_pad (self.srcpad) self.sinkpad = gst.Pad (self.__gsttemplates__[1]) self.sinkpad.set_chain_function (self.chain) self.sinkpad.set_link_function (self.link) self.sinkpad.set_getcaps_function (self.getcaps) self.add_pad (self.sinkpad)

def otherpad (self, pad): if self.sinkpad == pad: return self.srcpad else: return self.sinkpad

def link (self, pad, caps): return self.otherpad(pad).try_set_caps (caps)

def getcaps (self, pad): return self.otherpad(pad).get_allowed_caps ()

def chain (self, pad, data): data = data.copy_on_write () for i in range (0, len (data), 4): tmp = data[i:i+2] data[i:i+2] = data[i+2:i+4] data[i+2:i+4] = tmp self.srcpad.push (data)

gobject.type_register (ChannelSwap) gst.element_register (ChannelSwap, "channelswap")

And no, it's not performant. Now to write the mail with the (quite big) patch to the list, so you can do that, too. You can thank jdahlin for making me start hacking on Python btw.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!