def setElement(self, element, properties={}, ignore=['name']): """ Set given element on Widget, with optional properties """ gst.info("element:%s, properties:%s" % (element, properties)) self.element = element self.ignore = ignore self.properties = {} #key:name, value:widget self._addWidgets(properties)
def parseEvent(self, buffer): """ Take in a 12-byte string and extract out the command to see if it's an audio command. """ CMD = 'B' SRC = 'B' cmd = unpack(CMD, buffer[0:1])[0] if cmd != self.AUDIO_BCAST_CMD: gst.info("Parsing Events, CMD IS NOT :" + str(self.AUDIO_BCAST_CMD) + ' CMD IS:' + str(cmd)) return "" #data = np.fromstring(buffer[4:], dtype=np.int16) #print data #datas = data.astype(np.float) #scaled = (data * 1) # .astype(np.int16) #scaled = scaled.astype(">h") #scaled = np.array([0, 2**15-1, 0, 2**15-1], dtype=np.int16) #buffer_out = scaled.tostring() #gst.error("HELLO") # %s" % data) buffer_out = buffer[4:] return buffer_out
def run(self): self.gstBus = self.args[0] self.cb = self.args[1] self.gstBus.add_signal_watch() self.gstBus.connect('message', self.cb) self.loop = gobject.MainLoop() gst.info('Running gst listener thread') self.loop.run()
def __init__(self, dvbsrc, *args): gst.Element.__init__(self) gst.info('creating sinkpad') pad = gst.Pad(self._sinkpadtemplate, "sink") pad.set_chain_function(self.chainfunc) self.add_pad(pad) self.buffer = {} self.parse_args = args self.dvbsrc = dvbsrc
def _new_decoded_pad_cb(self, dbin, pad, is_last): # Does the file contain got audio or video ? caps = pad.get_caps() gst.info("caps:%s" % caps.to_string()) if "audio" in caps.to_string(): self.is_audio = True elif "video" in caps.to_string(): self.is_video = True else: self.warning("got a different caps.. %s" % caps.to_string()) return if is_last and not self.is_video and not self.is_audio: self.debug("is last, not video or audio") self._finished(False) return # we connect a fakesink to the new pad... pad.info("adding queue->fakesink") fakesink = gst.element_factory_make( "fakesink", "fakesink%d-%s" % (self.sinknumber, "audio" in caps.to_string() and "audio" or "video") ) self.sinknumber += 1 queue = gst.element_factory_make("queue") # we want the queue to buffer up to the specified amount of data # before outputting. This enables us to cope with formats # that don't create their source pads straight away, # but instead wait for the first buffer of that stream. # The specified time must be greater than the input file # frame interleave for the discoverer to work properly. queue.props.min_threshold_time = int(self._max_interleave * gst.SECOND) queue.props.max_size_time = int(2 * self._max_interleave * gst.SECOND) queue.props.max_size_bytes = 0 # If durations are bad on the buffers (common for video decoders), we'll # never reach the min_threshold_time or max_size_time. So, set a # max size in buffers, and if reached, disable the min_threshold_time. # This ensures we don't fail to discover with various ffmpeg # demuxers/decoders that provide bogus (or no) duration. queue.props.max_size_buffers = int(100 * self._max_interleave) def _disable_min_threshold_cb(queue): queue.props.min_threshold_time = 0 queue.disconnect(signal_id) signal_id = queue.connect("overrun", _disable_min_threshold_cb) self.add(fakesink, queue) queue.link(fakesink) sinkpad = fakesink.get_pad("sink") queuepad = queue.get_pad("sink") # ... and connect a callback for when the caps are fixed sinkpad.connect("notify::caps", self._notify_caps_cb) if pad.link(queuepad): pad.warning("##### Couldn't link pad to queue") queue.set_state(gst.STATE_PLAYING) fakesink.set_state(gst.STATE_PLAYING) gst.info("finished here")
def playEpisode (self, view, episode): gst.info('Playing episode ' + episode.title) mrl = episode.getUri(self.getConnectionSpeed()) if mrl: gst.log('Playing uri ' + mrl) self.totem.action_set_mrl_and_play(mrl, None) #self.totem.action_remote(totem.REMOTE_COMMAND_ENQUEUE, mrl) #self.totem.action_remote(totem.REMOTE_COMMAND_PLAY, mrl) else: gst.error('No uri for episode ' + episode.title)
def stop(self): self.player.set_state(gst.STATE_NULL) gst.info("stopped player") self.playing = False if self._temp_location: try: os.unlink(self._temp_location) except OSError: pass self._temp_location = ''
def __init__(self): gst.Element.__init__(self) gst.info("Creating CCN Sink") self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink") gst.info("Adding sinkpad to self") self.add_pad(self.sinkpad) self.sinkpad.set_chain_function(self.chainfunc) self.sinkpad.set_event_function(self.eventfunc)
def set_property(self, name, value): if name == 'ip': self.ip = value elif name == 'user': self.user = value elif name == "pwd": self.pwd = value elif name == "on" and value: self.audio = KaicongAudio(self.ip, user=self.user, pwd=self.pwd) self.audio.connect() gst.info("Connected audio")
def seek_end(self): event = gst.event_new_seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_END, -1, gst.SEEK_TYPE_NONE, 0) res = self.pipeline.send_event(event) if res: gst.info("setting new stream time to 0") else: gst.error("seek to end failed")
def play(self): gst.info("playing...") self.player.set_state(gst.STATE_PLAYING) #Start FadeIn if len(sys.argv) > 3: if float(sys.argv[3]) > 0: self.player.set_property('volume', 0) self.FadeIn(float(sys.argv[3]),1) else: self.player.set_property('volume', 1) else: self.player.set_property('volume', 1)
def stop(self): self.percentage = None self.text = None self.cursec = None self.duration = None self.togo = None self.artist_name = None self.track_name = None self.numalbum = None self.status = "End" self.src.set_state(gst.STATE_NULL) gst.info("stopped player")
def on_message(self, bus, message): t = message.type if t == gst.MESSAGE_ERROR: err, debug = message.parse_error() print "Error: %s" % err, debug self.stop() elif t == gst.MESSAGE_EOS: gst.info("File playback completed") ok,moved = self.cb_eos() if ok: gst.debug('eos callback completed, moved queue %d places' % moved) else: gst.warning('eos callback failed!')
def stop(self): #FadeOut if len(sys.argv) > 3: if float(sys.argv[4]) > 0: self.FadeOut(float(sys.argv[4]),0) else: self.player.set_property('volume', 0) else: self.player.set_property('volume', 0) #End FadeOut gst.info("stopped") self.player.set_state(gst.STATE_NULL) self.playmode = False
def seek(self, location): gst.debug("seeking to %r" % location) event = gst.event_new_seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, location, gst.SEEK_TYPE_NONE, 0) res = self.player.send_event(event) if res: gst.info("setting new stream time to 0") self.player.set_new_stream_time(0L) else: gst.error("seek to %r failed" % location)
def main(args): dev = int(sys.argv[1]) gobject.type_register(SomaAudioEventFilter) audioSrc = gst.element_factory_make('somaeventsource', 'SomaEventSource') #audioSrc = gst.element_factory_make('audiotestsrc', "test src") gst.info('About to create SomaAudioFilter') #somaAudioEventFilter = PyIdentity() somaAudioEventFilter = SomaAudioEventFilter() print "Created somaAudioEventFilter" somaAudioEventFilter.set_audio_src(dev) pipeline = gst.Pipeline() pipeline.add(audioSrc) pipeline.add(somaAudioEventFilter) finalSink = gst.element_factory_make("pulsesink") #finalSink = gst.element_factory_make("filesink") #finalSink.set_property("location", '/tmp/somaeventsourcetest.dat') pipeline.add(finalSink) ac = gst.element_factory_make("audioconvert") ars = gst.element_factory_make("audioresample") queue = gst.element_factory_make("queue") queue.set_property("max-size-buffers", 10000) pipeline.add(queue) pipeline.add(ac) pipeline.add(ars) ## caps = gst.Caps("audio/x-raw-int,rate=44100") ## filter = gst.element_factory_make("capsfilter", "filter") ## filter.set_property("caps", caps) ## pipeline.add(filter) gst.element_link_many(audioSrc, somaAudioEventFilter, queue, ac, ars, finalSink) #gst.element_link_many(audioSrc,somaAudioEventFilter, ars, filter, finalSink) #gst.element_link_many(audioSrc,somaAudioEventFilter, queue, finalSink) #gst.element_link_many(audioSrc, finalSink) #gst.element_link_many(audioSrc,somaAudioEventFilter, finalSink) print "somaAudioFilter linked to finalSink" print "Pipeline setup, setting STATE to PLAYING" pipeline.set_state(gst.STATE_PLAYING) gobject.MainLoop().run()
def seek(self, location): """ @param location: time to seek to, in nanoseconds """ gst.debug("seeking to %r" % location) event = gst.event_new_seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, location, gst.SEEK_TYPE_NONE, 0) res = self.pipeline.send_event(event) if res: gst.info("setting new stream time to 0") # self.pipeline.set_start_time(0L) else: gst.error("seek to %r failed" % location)
def fast_forward(self): """ Here we will fast forward the stream for as many times as this is called """ if self.rate < 8.0: self.rate = self.rate*2.0 event = gst.event_new_seek(self.rate, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, self.query_position()[0], gst.SEEK_TYPE_NONE, 0) res = self.player.send_event(event) if res: gst.info("fast forwarding at rate: %f" % self.rate) self.player.set_new_stream_time(0L) else: gst.error("change rate to %f failed" % self.rate) return
def slow_motion(self): """ Here we will slow motion the stream for as many times as this is called """ self.rate = self.rate/2.0 event = gst.event_new_seek(self.rate, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, self.query_position()[0], gst.SEEK_TYPE_NONE, 0) res = self.player.send_event(event) if res: gst.info("slowing playback to rate: %f" % self.rate) self.player.set_new_stream_time(0L) else: gst.error("change rate to %f failed" % self.rate) return
def __init__(self): gst.Element.__init__(self) gst.info('creating srcpadpad') self.srcpad = gst.Pad(self._srcpadtemplate, "src") gst.info('adding srcpad to self') self.add_pad(self.srcpad) self.srcpad.set_getcaps_function(self.src_getcaps_function) self.srcpad.set_setcaps_function(self.src_setcaps_function) gst.info('creating sinkpad') self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink") gst.info('adding sinkpad to self') self.add_pad(self.sinkpad) self.sinkpad.set_getcaps_function(self.sink_getcaps_function) self.sinkpad.set_setcaps_function(self.sink_setcaps_function) gst.info('setting chain/event functions') self.sinkpad.set_chain_function(self.chainfunc) self.sinkpad.set_event_function(self.eventfunc)
def __init__(self, fun=None): gst.Element.__init__(self) gst.info('creating sinkpad') self.fun = fun self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink") gst.info('adding sinkpad to self') self.add_pad(self.sinkpad) self.srcpad = gst.Pad(self._srcpadtemplate, "src") gst.info('adding srcpad to self') self.add_pad(self.srcpad) gst.info('setting chain/event functions') self.sinkpad.set_chain_function(self.chainfunc) self.sinkpad.set_event_function(self.eventfunc)
def play(self, track=None, activate_item=-1): # self.player.set_state(gst.STATE_NULL) # gst.info("stopped player") if self.status == "paused" and track == None: track = self.cur_playing self.increment_counter(self.artist_counter, track['artist_id']) self.increment_counter(self.album_counter, track['album_id']) self.increment_counter(self.track_counter, track['id']) if track['stream'] == "query": track['stream'] = self.pyjama.jamendo.stream(track['id']) if track['duration'] == 0: #GET FROM JAMENDO track['duration'] = 60*59 self.last_played = self.cur_playing self.cur_playing = track if self.status != "paused": self.stop() try: self.set_location(track['stream']) except: print "error" gst.info("playing player") self.player.set_state(gst.STATE_PLAYING) self.playing = True self.status = "Playing" track['pos'] = activate_item ev = self.pyjama.Events ev.raise_event('nowplaying', track) # ev.raise_event('nowplaying', artist = track['artist_name'], album = track['album_name'], track = track['name'], icon = img) #self.pyjama.notification(_("Now playing"), "<b><i>%s</i></b>:\n%s" % (track['artist_name'], track['name']), icon = img, size =) if activate_item > -1: self.pyjama.setplaylist(activate_item)
def play(self): """ Change the stream state to playing or simply change its playing rate to normal rate """ if self.rate != 1.0: self.rate = 1.0 event = gst.event_new_seek(self.rate, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, self.query_position()[0], gst.SEEK_TYPE_NONE, 0) res = self.player.send_event(event) if res: gst.info("slowing playback to rate: %f" % self.rate) self.player.set_new_stream_time(0L) else: gst.error("change rate to %f failed" % self.rate) else: gst.info("playing player") self.player.set_state(gst.STATE_PLAYING) self.playing = True return
def chainfunc(self, pad, buffer): """ This is the primary function that takes in event buffers and emits audio buffers. """ buffer_out = "" nEvents = len(buffer)/12; gst.info("somaEventFilter.chainfunc length of Buffer IN:" + str(len(buffer)) + ' with nEvents:' + str(nEvents)) if len(buffer) % 12 != 0: gst.warn( "Error: nEvents % 12 !=0") return "" for i in range(nEvents): buffer_out = buffer_out + (self.parseEvent( buffer[ (i*12) : (i*12)+12 ] )) buf = gst.Buffer(buffer_out) caps = self.srccaps buf.set_caps(caps) gst.info("returning %d samples" % len(buffer)) return self.srcpad.push(buf)
def __init__(self): gst.Element.__init__(self) gst.info('creating srcpadpad') self.srcpad = gst.Pad(self._srcpadtemplate, "src") gst.info('adding srcpad to self') self.add_pad(self.srcpad) self.srcpad.set_getcaps_function(self.src_getcaps_function) self.srcpad.set_setcaps_function(self.src_setcaps_function) gst.info('creating sinkpad') self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink") gst.info('adding sinkpad to self') self.add_pad(self.sinkpad) self.sinkpad.set_getcaps_function(self.sink_getcaps_function) self.sinkpad.set_setcaps_function(self.sink_setcaps_function) gst.info('setting chain/event functions') self.sinkpad.set_chain_function(self.chainfunc) self.sinkpad.set_event_function(self.eventfunc) self.srccaps = gst.caps_from_string('audio/x-raw-int,rate=32000,channels=1,endianness=1234,width=16,depth=16,signed=true') self.AUDIO_BCAST_CMD = 0x18; self.lastvalue = 0
def run(self): # arg list: cb,src,port=555 assert(len(self.args) == 3) self.threadID = 1 self.cb = self.args[0] self.src = self.args[1] self.port = self.args[2] self.context = None self.server = None self.name = 'Listener' gst.debug('%s listener thread starting....' % self.src) if self.src == 'zmq': # zmq_init self.context = zmq.Context() self.server = self.context.socket(zmq.REP) self.server.bind('tcp://*:%d' % self.port) print 'zmq listener running on port %d' % self.port # run loop while not self.stop_request.is_set(): gst.info('Waiting for %s input...' % self.src) if(self.src == 'zmq'): msg = self.server.recv() else: msg = raw_input('Command:') gst.info('Rx: %s' % msg) ans = self.cb(msg) gst.debug('Callback exe completed') if(self.src == 'zmq'): self.server.send(ans) gst.debug('Answer sent to client: %s' % ans) # zmq_deinit if self.context != None: gst.debug('Cleaning up zmq') if self.server != None: self.server.close() self.context.term()
def __init__(self): gst.Element.__init__(self) gst.info('creating sinkpad') self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink") gst.info('adding sinkpad to self') self.add_pad(self.sinkpad) gst.info('setting chain/event functions') self.sinkpad.set_chain_function(self.chainfunc) self.sinkpad.set_event_function(self.eventfunc)
def __init__(self, matrix): print("init") gst.BaseSink.__init__(self) self.matrix = matrix gst.info('creating sinkpad') # self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink") gst.info('adding sinkpad to self') #self.add_pad(self.sinkpad) self.set_sync(True) gst.info('setting chain/event functions') #self.sinkpad.set_chain_function(self.chainfunc) self.sinkpad.set_event_function(self.eventfunc)
def __init__(self): gst.Element.__init__(self) gst.info('creating pads') self.srcpad = gst.Pad(self._srcpadtemplate, "src") self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink") gst.info('adding pads to self') self.add_pad(self.srcpad) self.add_pad(self.sinkpad) gst.info('setting chain/event functions') #self.srcpad.set_chain_function(self.src_chainfunc) #self.srcpad.set_event_function(self.src_eventfunc) self.sinkpad.set_chain_function(self.sink_chainfunc) self.sinkpad.set_event_function(self.sink_eventfunc) self.time_cb = None self.interval = 60 self._calc_next()
def play(self): gst.info("playing player") self.player.set_state(gst.STATE_PLAYING) self.playing = True
def pause(self): gst.info("pausing player") self.player.set_state(gst.STATE_PAUSED) self.playing = False
def stop(self): self.player.set_state(gst.STATE_NULL) gst.info("stopped player")
def play(self): self.playing = True gst.info("playing player") self.pipeline.set_state(gst.STATE_PLAYING)
def pause(self): gst.info("pausing _player0") self._pipeline.set_state(gst.STATE_PAUSED) self._is_playing = False
def __init__(self, matrix): gst.BaseSink.__init__(self) self.matrix = matrix self.set_sync(True) gst.info('setting chain/event functions')
def stop(self): self._pipeline.set_state(gst.STATE_NULL) gst.info("stopped _player0")
self.sinkpad.set_chain_function(self.chainfunc) self.sinkpad.set_event_function(self.eventfunc) def chainfunc(self, pad, buffer): self.info("%s timestamp(buffer):%d" % (pad, buffer.timestamp)) return gst.FLOW_OK def eventfunc(self, pad, event): self.info("%s event:%r" % (pad, event.type)) return True gobject.type_register(MySink) # # Code to test the MySink class # src = gst.element_factory_make('fakesrc') gst.info('About to create MySink') sink = MySink() pipeline = gst.Pipeline() pipeline.add(src, sink) src.link(sink) pipeline.set_state(gst.STATE_PLAYING) gobject.MainLoop().run()
def stop(self): self.pipeline.set_state(gst.STATE_NULL) gst.info("stopped player") self.playing = False
def Stop(self): gst.info("stopping player") self._playbin.set_state(gst.STATE_READY) gst.info("stopped player")
def Pause(self): gst.info("pausing player") self._playbin.set_state(gst.STATE_PAUSED)
def Play(self): gst.info("playing player") self._playbin.set_state(gst.STATE_PLAYING)