def restart_source_bin(self): self.successive_underruns += 1 if self.successive_underruns > 3: sys.stderr.write("Error: Video loss. Too many underruns.\n") sys.exit(1) gst.element_unlink_many(self.source_bin, self.sink_bin) self.source_bin.set_state(gst.STATE_NULL) self.sink_bin.set_state(gst.STATE_READY) self.pipeline.remove(self.source_bin) self.source_bin = None debug("Attempting to recover from video loss: " "Stopping source pipeline and waiting 5s...") time.sleep(5) debug("Restarting source pipeline...") self.source_bin = self.create_source_bin() self.pipeline.add(self.source_bin) gst.element_link_many(self.source_bin, self.sink_bin) self.source_bin.set_state(gst.STATE_PLAYING) self.pipeline.set_state(gst.STATE_PLAYING) debug("Restarted source pipeline") self.underrun_timeout.start() return False # stop the timeout from running again
def _restartSourceBin(self): self._successiveUnderruns += 1 if self._successiveUnderruns > 3: self._debugger.ddebug("Too many underruns.") sys.exit(1) gst.element_unlink_many(self._sourceBin, self._sinkBin) self._sourceBin.set_state(gst.STATE_NULL) self._sinkBin.set_state(gst.STATE_READY) self._pipeline.remove(self._sourceBin) self._sourceBin = None self._debug( "Attempting to recover from video loss: Stopping source pipeline and waiting 5s..." ) time.sleep(5) self._debug("Restarting source pipeline...") self._sourceBin = self._createSourceBin() self._pipeline.add(self._sourceBin) gst.element_link_many(self._sourceBin, self._sinkBin) self._sourceBin.set_state(gst.STATE_PLAYING) self._sinkBin.set_state(gst.STATE_PLAYING) self._pipeline.set_state(gst.STATE_PLAYING) self._startTimestamp = None self._debug("Restarted source pipeline") self._underrunTimeout.start() # stop the timeout from running again return False
def restart_source_bin(self): self.successive_underruns += 1 if self.successive_underruns <= 3: self.test_timeout.cancel() gst.element_unlink_many(self.source_bin, self.sink_bin) self.source_bin.set_state(gst.STATE_NULL) self.sink_bin.set_state(gst.STATE_READY) self.pipeline.remove(self.source_bin) self.source_bin = None debug("Attempting to recover from video loss: " "Stopping source pipeline and waiting 5s...") time.sleep(5) debug("Restarting source pipeline...") self.source_bin = self.create_source_bin() self.pipeline.add(self.source_bin) gst.element_link_many(self.source_bin, self.sink_bin) self.source_bin.set_state(gst.STATE_PLAYING) self.pipeline.set_state(gst.STATE_PLAYING) debug("Restarted source pipeline") self.underrun_timeout.start() self.test_timeout.start() return False # stop the timeout from running again
def unload_videomixer(self): if self.record_video is True: for plugin in self.video_input_plugins: gst.element_unlink_many(self.video_tee, plugin) self.player.remove(plugin) gst.element_unlink_many(self.videomixer, self.video_tee) self.player.remove(self.videomixer)
def unlink_gst(self): if(self.pipeline): self.pipeline.set_state(gst.STATE_NULL) self.pipeline.remove_many(*self.chain) gst.element_unlink_many(*self.chain) for item in self.chain: item = False self.pipeline = False time.sleep(0.01)
def unlink_gst(self): if (self.pipeline): self.pipeline.set_state(gst.STATE_NULL) self.pipeline.remove_many(*self.chain) gst.element_unlink_many(*self.chain) for item in self.chain: item = False self.pipeline = False time.sleep(0.01)
def new_source(self, source): self.__player.lock.acquire() self.set_state(gst.STATE_NULL) gst.element_unlink_many(self.__source, self.__decodebin) self.remove(self.__source) self.__decodebin.new_source() self.__source = source self.add(self.__source) gst.element_link_many(self.__source, self.__decodebin) # self.__source.set_state(gst.STATE_PLAYING) self.set_state(gst.STATE_PLAYING) # self.__player.pipe.set_state(gst.STATE_PLAYING) self.__player.lock.release()
def new_source(self, source): self.__player.lock.acquire() self.set_state(gst.STATE_NULL) # self.unlink_and_dispose() gst.element_unlink_many(self.source, self.__demux) self.remove(self.source) self.__demux.new_source() self.source = source self.add(self.source) gst.element_link_many(self.source, self.__demux) self.set_state(gst.STATE_PLAYING) self.__player.lock.release()
def unlink_gst(self): if 0: if (self.player): self.player.set_state(gst.STATE_NULL) self.player.remove_many(*self.chain) gst.element_unlink_many(*self.chain) for src in self.chain[::-1]: self.player.remove(src) for item in self.chain: item = False self.player = None else: if self.pipeline: self.pipeline.set_state(Gst.State.NULL) self.pipeline = None time.sleep(0.01)
def restart_source_bin(self): gst.element_unlink_many(self.source_bin, self.sink_bin) self.source_bin.set_state(gst.STATE_NULL) self.sink_bin.set_state(gst.STATE_READY) self.pipeline.remove(self.source_bin) self.source_bin = None debug("restart_source_bin: set state NULL; waiting 5s") time.sleep(5) debug("restart_source_bin: about to set state PLAYING") self.source_bin = self.create_source_bin() self.pipeline.add(self.source_bin) gst.element_link_many(self.source_bin, self.sink_bin) self.source_bin.set_state(gst.STATE_PLAYING) self.pipeline.set_state(gst.STATE_PLAYING) debug("restart_source_bin: set state PLAYING") self.underrun_timeout_id = gobject.timeout_add( 10000, self.restart_source_bin) return False # stop the timeout from running again
def stopaudio(self, widget=None, event=None): self.pipeline.set_state(gst.STATE_PAUSED) self.pipeline.set_state(gst.STATE_NULL) try: gst.element_unlink_many(self.alsasrc, self.audiorate, self.filtroaudio, self.hilofiltro, self.audioconvert, self.vorbisenc, self.hiloaudiomuxor, self.oggmux) gst.element_unlink_many(self.oggmux, self.hiloarchivo, self.archivo) self.pipeline.remove(self.oggmux, self.alsasrc, self.audiorate, self.filtroaudio, self.hilofiltro, self.audioconvert, self.vorbisenc, self.hiloaudiomuxor, self.hiloarchivo, self.archivo) except: pass self.estado = None self.set_pipeline()
def stop(self, widget=None, event=None): self.pipeline.set_state(gst.STATE_PAUSED) self.pipeline.set_state(gst.STATE_NULL) try: gst.element_unlink_many(self.multi, self.hiloencodearvideo, self.scale, self.scalecapsfilter, self.colorspace, self.theoraenc, self.hilovideomuxor, self.oggmux) gst.element_unlink_many(self.alsasrc, self.audiorate, self.filtroaudio, self.hilofiltro, self.audioconvert, self.vorbisenc, self.hiloaudiomuxor, self.oggmux) gst.element_unlink_many(self.oggmux, self.hiloarchivo, self.archivo) self.pipeline.remove( self.hiloencodearvideo, self.scale, self.scalecapsfilter, self.colorspace, self.theoraenc, self.hilovideomuxor, self.oggmux, self.alsasrc, self.audiorate, self.filtroaudio, self.hilofiltro, self.audioconvert, self.vorbisenc, self.hiloaudiomuxor, self.hiloarchivo, self.archivo) except: pass self.estado = None self.set_pipeline()
def GStreamerSink(pipeline): """Try to create a GStreamer pipeline: * Try making the pipeline (defaulting to gconfaudiosink or autoaudiosink on Windows). * If it fails, fall back to autoaudiosink. * If that fails, return None Returns the pipeline's description and a list of disconnected elements.""" if not pipeline and not gst.element_factory_find('gconfaudiosink'): pipeline = "autoaudiosink" elif not pipeline or pipeline == "gconf": pipeline = "gconfaudiosink profile=music" try: pipe = [gst.parse_launch(element) for element in pipeline.split('!')] except gobject.GError: print_w(_("Invalid GStreamer output pipeline, trying default.")) try: pipe = [gst.parse_launch("autoaudiosink")] except gobject.GError: pipe = None else: pipeline = "autoaudiosink" if pipe: # In case the last element is linkable with a fakesink # it is not an audiosink, so we append the default pipeline fake = gst.element_factory_make('fakesink') try: gst.element_link_many(pipe[-1], fake) except gst.LinkError: pass else: gst.element_unlink_many(pipe[-1], fake) default, default_text = GStreamerSink("") if default: return pipe + default, pipeline + " ! " + default_text else: print_w(_("Could not create default GStreamer pipeline.")) return pipe, pipeline
def _restartSourceBin(self): self._successiveUnderruns += 1 if self._successiveUnderruns > 3: self._debugger.ddebug("Too many underruns.") sys.exit(1) gst.element_unlink_many(self._sourceBin, self._sinkBin) self._sourceBin.set_state(gst.STATE_NULL) self._sinkBin.set_state(gst.STATE_READY) self._pipeline.remove(self._sourceBin) self._sourceBin = None self._debug("Attempting to recover from video loss: Stopping source pipeline and waiting 5s...") time.sleep(5) self._debug("Restarting source pipeline...") self._sourceBin = self._createSourceBin() self._pipeline.add(self._sourceBin) gst.element_link_many(self._sourceBin, self._sinkBin) self._sourceBin.set_state(gst.STATE_PLAYING) self._sinkBin.set_state(gst.STATE_PLAYING) self._pipeline.set_state(gst.STATE_PLAYING) self._startTimestamp = None self._debug("Restarted source pipeline") self._underrunTimeout.start() # stop the timeout from running again return False
def unload_output_plugins(self): for plugin in self.output_plugins: gst.element_unlink_many(self.video_tee, plugin) gst.element_unlink_many(self.audio_tee, plugin) self.player.remove(plugin)