From: <cni...@ya...> - 2007-02-20 14:56:54
|
Hi, I'm a newbie in this list, so sorry if I'm not pointing my question in the right place. My problem is that I'm trying to link a source and a filter in a pipeline through python without any success. I could link them with version 0.8.x of gstreamer, but the change of version from 0.8.x to 0.10.x took some changes in the python bindings API, and the function set_get_function of gst.Pad has been removed, so I don't know how to link the stages. The code of my source (FileSource.py) stage (based on the filesrc.py example) is: import sys import gobject import gst import pickle class FileSource(gst.Element): blocksize = 4096 fd = None file = "" data = "" hash = False ohash = {} #srcpad = None def __init__(self, name): self.__gobject_init__() self.curoffset = 0 self.set_name(name) def set_property(self, name, value): if name == 'location': self.file = value self.fd = open(self.file, 'r') self.ohash['file'] = self.file #self.curoffset += len(self.ohash) elif name == 'blocksize': self.blocksize = value elif name == 'hash': if value.lower() == "true": self.hash = True def do_create(self, offset, size): #if offset != self.curoffset: # self.fd.seek(offset, 0) if self.blocksize == 0: data = self.fd.read() else: data = self.fd.read(self.blocksize) if data: self.ohash['data'] = data self.curoffset += len(data) return gst.FLOW_OK, gst.Buffer(self.ohash) else: return gst.FLOW_UNEXPECTED, None gobject.type_register(FileSource) The code of my filter stage is: import sys import gobject import gst import pickle class DataFilter( gst.Element ): callbackfunc = None n_buffer = 0 data = None def __init__( self, name ): self.__gobject_init__() gst.Element.__init__( self ) self.set_name( name ) sinkpadtempl = gst.PadTemplate( "sinkpadtemplate", gst.PAD_SINK, gst.PAD_ALWAYS, gst.caps_new_any() ) self.snkpad = gst.Pad( sinkpadtempl, "snk" ) self.snkpad.set_chain_function( self.chainfunc ) self.add_pad( self.snkpad ) srcpadtempl = gst.PadTemplate( "srcpadtemplate", gst.PAD_SRC, gst.PAD_ALWAYS, gst.caps_new_any() ) self.srcpad = gst.Pad( srcpadtempl, "src" ) self.srcpad.set_event_function( self.eventfunc ) self.add_pad( self.srcpad ) #self.connect( 'eos', self.eosfunc ) self.callbackfunc = lambda x: x def chainfunc( self, pad, buffer ): data = buffer.get_data() #print "data (%s): %s" % (str(type(data)), str(data)) #print "self.data (%s): %s" % (str(type(self.data)), str(self.data)) if data: self.data = data self.srcpad.send_event( gst.Event(gst.EVENT_EOS) ) return gst.FLOW_OK def eventfunc(self, pad, event): if pad == self.srcpad: if event.type == gst.EVENT_EOS: self.n_buffer += 1 elif event.type == gst.EVENT_FLUSH: result = self.callbackfunc( self.data ) self.srcpad.push( gst.Buffer( result ) ) #print "Event ...: %s event:%r" % (pad, event.type) self.info("%s event:%r" % (pad, event.type)) return True def set_property (self, name, value): if name == "callback": self.callbackfunc = value gobject.type_register( DataFilter ) Before the change of version from 0.8.x to 0.10.x, my source code was: import sys import gobject import gst import pickle class FileSource(gst.Element): blocksize = 4096 fd = None file = "" data = "" hash = False ohash = {} #srcpad = None def __init__(self, name): self.__gobject_init__() self.curoffset = 0 self.set_name(name) self.srcpad = gst.Pad('src', gst.PAD_SRC) self.srcpad.set_get_function(self.srcpad_get) self.add_pad(self.srcpad) def set_property(self, name, value): if name == 'location': self.file = value self.fd = open(self.file, 'r') self.ohash['file'] = self.file #self.curoffset += len(self.ohash) elif name == 'blocksize': self.blocksize = value elif name == 'hash': if value.lower() == "true": self.hash = True def srcpad_get(self, pad): data = self.fd.read(self.blocksize) if data: buffer = gst.Buffer(pickle.dumps(data)) return buffer else: self.set_eos() return gst.Event(gst.EVENT_EOS) gobject.type_register(FileSource) To link the stages, of course I'm doing: pipeline = gst.Pipeline('pipeline') filesrc = FileSource("FileSource") filter = DataFilter("datafilter") gst.element_link_many(filesrc, filter) pipeline.set_state(gst.STATE_PLAYING) while self.pipeline.iterate(): pass pipeline.set_state(gst.STATE_NULL) Can anyone tell me what's wrong with my new source stage? How could I replace the set_get_function with any other doing the same tasks? Regards. Carlos Niharra López ______________________________________________ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com |