Public feed
#603162
class MergeMuxer(gst.Element): __gstdetails__ = ('MergeMuxer Plugin', "mergemuxer.py", "Combine Multiple MetaDataMuxer'd Streams", "Corey O.") _srcpadtemplate = gst.PadTemplate ("src", gst.PAD_SRC, gst.PAD_ALWAYS, gst.caps_new_any()) _sinkpadtemplate = gst.PadTemplate ('sink%d', gst.PAD_SINK, gst.PAD_REQUEST, gst.caps_new_any()) __gsttemplates__ = (_srcpadtemplate, _sinkpadtemplate) def __init__(self): gst.Element.__init__(self) self.condition = Condition() self.frame_count = 1 self.srcpad = gst.Pad(self._srcpadtemplate) self.add_pad(self.srcpad) self.sink_pad_count = 1 self.buffer_pairs = {} def do_request_new_pad(self, template, name): print "new pad requested w/name:", name #new_name= "sink%d" % self.sink_pad_count #self.sink_pad_count += 1 #pad = gst.Pad(template, new_name) pad = gst.Pad(template, name) self.add_pad(pad) pad.set_chain_function(self.chainfunc) pad.set_event_function(self.eventfunc) return pad def do_release_pad(self, pad): self.remove_pad(pad) def chainfunc(self, pad, buffer): try: pad_name = pad.get_name() caps = buffer.get_caps() if caps == METADATA_CAPS: print 'mergemux pad', pad_name, "storing metadata" self.buffer_pairs[pad_name] = buffer return gst.FLOW_OK else: print 'mergemux pad', pad_name, "incoming video buffer" metadata_buffer = self.buffer_pairs[pad_name] if metadata_buffer == None: # TODO: should post an error to bus here #gerror = gobject.GError() #gerror.message = "" print pad_name, "FLOW ERROR!" return gst.FLOW_ERROR else: metadata = MetaData.from_string(metadata_buffer.data) frame_count = int(metadata.data['frame_count']) while True: self.condition.acquire() print self.get_name(), ":" , frame_count, "==", self.frame_count if frame_count == self.frame_count: print 'mergemux pad', pad_name, 'pushing buffers' self.buffer_pairs[pad_name] = None status = self.srcpad.push(metadata_buffer) if status == gst.FLOW_OK or status == gst.FLOW_NOT_NEGOTIATED: print self.get_name(), "all goes well" status = self.srcpad.push(buffer) else: print self.get_name(), "status =", status self.frame_count += 1 self.condition.notifyAll() self.condition.release() return status else: print 'mergemux pad ', pad_name, ' sleeping...' self.condition.wait() self.condition.notifyAll() self.condition.release() continue except Exception, e: print "ERROR!!! ", e pass def eventfunc(self, pad, event): return self.srcpad.push_event(event)