Esempio n. 1
0
	def tearDown(self):
		if not self._toreDownAlready:
			self._logger.debug("Tearing down...")

			self._busListener.stop()

			stateChange, state, pending = self._pipeline.get_state(1)
			# if it's still trying to change to another state, the following two calls will
			# block so just kill all of it
			if stateChange != Gst.StateChangeReturn.ASYNC:
				self._pipeline.set_state(Gst.State.NULL)
				Gst.deinit()

			self._videoSrcBin = None
			self._videoEncBin = None
			self._photoCaptureBin = None
			self._bus = None

			self._toreDownAlready = True

			if self._mainLop.is_running():
				self._mainLop.quit()

			self._busListener.join()
			self._logger.debug("Tearing down completed")
Esempio n. 2
0
	def tearDown(self):
		if not self._toreDownAlready:
			self._logger.debug("Tearing down...")

			self._busListener.stop()

			stateChange, state, pending = self._pipeline.get_state(1)
			# if it's still trying to change to another state, the following two calls will
			# block so just kill all of it
			if stateChange != Gst.StateChangeReturn.ASYNC:
				self._pipeline.set_state(Gst.State.NULL)
				Gst.deinit()

			self._videoSrcBin = None
			self._videoEncBin = None
			self._photoCaptureBin = None
			self._bus = None

			self._toreDownAlready = True

			if self._mainLop.is_running():
				self._mainLop.quit()

			self._busListener.join()
			self._logger.debug("Tearing down completed")
Esempio n. 3
0
 def on_destroy(self, event):
     print("on video destroy")
     # print("clearVideo:")
     # self.playflag = "clear"
     # to prevent racing conditions when closing the window while playing
     # self.player.set_state(Gst.State.NULL)
     self.pipeline.set_state(Gst.State.NULL)
     Gst.deinit()
def gst_sample_capture(content):
    #create the empty pipeline
    alsasrc = Gst.ElementFactory.make("alsasrc", "alsa_src");
    capsfilter = Gst.ElementFactory.make("capsfilter", "caps_filter");
    wavenc = Gst.ElementFactory.make("wavenc", "wav_enc");
    filesink = Gst.ElementFactory.make("filesink", "file_sink");
    pipeline = Gst.Pipeline.new("audio_capture_stream");

    if not pipeline or not alsasrc or not capsfilter or not wavenc or not filesink:
        print("Create pipeline/alsasrc/capsfilter/wavenc/filesink element failed.")
        sys.exit(1)

    #set properties to the elements
    alsasrc.set_property("device","hw:0,0")
    alsasrc.set_property("num-buffers",1000)
    alsasrc.set_property("buffer-time",10000) 
    caps=Gst.Caps.new_empty_simple("audio/x-raw")
    capsfilter.set_property("caps",caps)
    filesink.set_property("location",content)
    
    #Build the pipeline. Add elements to the pipeline and link them
    pipeline.add(alsasrc)
    pipeline.add(capsfilter)
    pipeline.add(wavenc)
    pipeline.add(filesink)

    if not alsasrc.link(capsfilter):
        print("ERROR: Could not link alsasrc to capsfilter")
        sys.exit(1)
    if not capsfilter.link(wavenc):
        print("ERROR: Could not link capsfilter to wavenc")
        sys.exit(1)
    if not wavenc.link(filesink):
        print("ERROR: Could not link wavenc to filesink")
        sys.exit(1)

    pipeline.set_state(Gst.State.PLAYING)
    print("Start");

    bus = pipeline.get_bus()
    bus_id = bus.add_signal_watch()
    msg = bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE,Gst.MessageType.ERROR | Gst.MessageType.EOS)
    if msg:
        t = msg.type
        if t == Gst.MessageType.ERROR:
            err, dbg = msg.parse_error()
            print("ERROR:", msg.src.get_name(), ":", err.message)
            if dbg:
                print("debugging info:", dbg)
        elif t == Gst.MessageType.EOS:
            print("Stop end-Of-Stream reached")
        else:
            print("ERROR: Unexpected message received.")

    pipeline.set_state(Gst.State.NULL)
    Gst.Object.unref(bus)
    Gst.deinit()
    sys.exit(1)
Esempio n. 5
0
 def free_resources (self):
     """
         frees static memory resources before quitting app;
     """
     # do garbage collection first
     self.on_garbage_collection()
     # then free all static memory resources
     Gst.deinit()
     # debugging session
     tron("freed static memory resources.")
def gst_sample_playback(content):
    # Create the empty pipeline 
    pipeline = Gst.Pipeline.new("audio playback")
    filesrc = Gst.ElementFactory.make("filesrc", "file_src")
    wavparse = Gst.ElementFactory.make("wavparse", "wav_parse");
    alsasink = Gst.ElementFactory.make("alsasink", "alsa_sink");

    if not pipeline or not filesrc or not wavparse or not alsasink:
        print("Create pipeline/filesrc/wavparse/alsasink element failed.")
        sys.exit(1)

    #set properties to the elements
    filesrc.set_property('location',content)
    alsasink.set_property('device',"hw:0,0")

    #Build pipeline
    #Add elements to the pipeline and link them
    pipeline.add(filesrc)
    pipeline.add(wavparse)
    pipeline.add(alsasink)

    if not filesrc.link(wavparse):
        print("ERROR: Could not link filesrc to wavparse")
        sys.exit(1)
    if not wavparse.link(alsasink):
        print("ERROR: Could not link wavparse to alsasink")
        sys.exit(1)

    pipeline.set_state(Gst.State.PLAYING)
    print("Start");
    bus = pipeline.get_bus()
    bus_id = bus.add_signal_watch()
    msg = bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE,Gst.MessageType.ERROR | Gst.MessageType.EOS)

    if msg:
        t = msg.type
        if t == Gst.MessageType.ERROR:
            err, dbg = msg.parse_error()
            print("ERROR:", msg.src.get_name(), ":", err.message)
            if dbg:
                print("debugging info:", dbg)
        elif t == Gst.MessageType.EOS:
            print("Stop end-Of-Stream reached")
        else:
            print("ERROR: Unexpected message received.")

    pipeline.set_state(Gst.State.NULL)
    Gst.Object.unref(bus)
    Gst.deinit()
    sys.exit(1)
Esempio n. 7
0
 def quit(self):
     """
         Quit lollypop
     """
     if Lp.scanner.is_locked():
         Lp.scanner.stop()
         GLib.idle_add(self.quit)
         return
     try:
         Lp.sql.execute("VACUUM")
     except Exception as e:
         print("Application::quit(): ", e)
     Lp.window.destroy()
     Lp.sql.close()
     Gst.deinit()
Esempio n. 8
0
 def quit(self):
     """
         Quit lollypop
     """
     if self.scanner.is_locked():
         self.scanner.stop()
         GLib.idle_add(self.quit)
         return
     try:
         with SqlCursor(self.db) as sql:
             sql.execute('VACUUM')
         with SqlCursor(self.playlists) as sql:
             sql.execute('VACUUM')
         with SqlCursor(Radios()) as sql:
             sql.execute('VACUUM')
     except Exception as e:
         print("Application::quit(): ", e)
     self.window.destroy()
     Gst.deinit()
Esempio n. 9
0
 def quit(self):
     """
         Quit lollypop
     """
     if self.scanner.is_locked():
         self.scanner.stop()
         GLib.idle_add(self.quit)
         return
     try:
         with SqlCursor(self.db) as sql:
             sql.execute('VACUUM')
         with SqlCursor(self.playlists) as sql:
             sql.execute('VACUUM')
         with SqlCursor(Radios()) as sql:
             sql.execute('VACUUM')
     except Exception as e:
         print("Application::quit(): ", e)
     self.window.destroy()
     Gst.deinit()
Esempio n. 10
0
    def testNotDeinitialized(self):
        Gst.init(None)

        assert (Gst.Caps.from_string("audio/x-raw"))
        assert (Gst.Structure.from_string("audio/x-raw"))
        assert (Gst.ElementFactory.make("identity", None))

        Gst.deinit()
        if sys.version_info >= (3, 0):
            assert_type = Gst.NotInitialized
        else:
            assert_type = TypeError

        with self.assertRaises(assert_type):
            Gst.Caps.from_string("audio/x-raw")

        with self.assertRaises(assert_type):
            Gst.Structure.from_string("audio/x-raw")

        with self.assertRaises(assert_type):
            Gst.ElementFactory.make("identity", None)
Esempio n. 11
0
    def testNotDeinitialized(self):
        Gst.init(None)

        assert(Gst.Caps.from_string("audio/x-raw"))
        assert(Gst.Structure.from_string("audio/x-raw"))
        assert(Gst.ElementFactory.make("identity", None))

        Gst.deinit()
        if sys.version_info >= (3, 0):
            assert_type = Gst.NotInitialized
        else:
            assert_type = TypeError

        with self.assertRaises(assert_type):
            Gst.Caps.from_string("audio/x-raw")

        with self.assertRaises(assert_type):
            Gst.Structure.from_string("audio/x-raw")

        with self.assertRaises(assert_type):
            Gst.ElementFactory.make("identity", None)
Esempio n. 12
0
 def quit(self):
     """
         Quit lollypop
     """
     if Lp.scanner.is_locked():
         Lp.scanner.stop()
         GLib.idle_add(self.quit)
         return
     try:
         Lp.sql.execute('VACUUM')
         sql_p = Lp.playlists.get_cursor()
         sql_p.execute('VACUUM')
         sql_p.close()
         radios = Radios()
         sql_r = radios.get_cursor()
         sql_r.execute('VACUUM')
         sql_r.close()
     except Exception as e:
         print("Application::quit(): ", e)
     Lp.window.destroy()
     Lp.sql.close()
     Gst.deinit()
Esempio n. 13
0
    if not avdec_mp3.link(pulsesink):
        print("ERROR: Could not link avdec_mp3 to pulsesink")
        sys.exit(1)
else:
    print("Format not supported\n")
    sys.exit(1)

pipeline.set_state(Gst.State.PLAYING)
print("audio playback started")
bus = pipeline.get_bus()
bus_id = bus.add_signal_watch()
msg = bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE,
                             Gst.MessageType.ERROR | Gst.MessageType.EOS)

if msg:
    t = msg.type
    if t == Gst.MessageType.ERROR:
        err, dbg = msg.parse_error()
        print("ERROR:", msg.src.get_name(), ":", err.message)
        if dbg:
            print("debugging info:", dbg)
    elif t == Gst.MessageType.EOS:
        print("End-Of-Stream reached stoped")
    else:
        print("ERROR: Unexpected message received.")

pipeline.set_state(Gst.State.NULL)
Gst.Object.unref(bus)
Gst.deinit()