Beispiel #1
0
    def __init__(self, source_name, rate, list_sources=False):
        self.source_name = source_name
        self.rate = rate
        self.sources = OrderedDict()
        self._clear_chunk()
        self._list_sources = list_sources

        # Exception raised in a callback, to be re-raised in the main thread
        self._exception = None

        # Wrap callback methods in appropriate ctypefunc instances so
        # that the Pulseaudio C API can call them
        self._context_notify_cb = pa.pa_context_notify_cb_t(self.context_notify_cb)
        self._source_info_cb = pa.pa_source_info_cb_t(self.source_info_cb)
        self._stream_read_cb = pa.pa_stream_request_cb_t(self.stream_read_cb)

        # stream_read_cb() puts finished chunks into this queue
        self._chunks = Queue.Queue()

        # Create the mainloop thread and set our context_notify_cb
        # method to be called when there's updates relating to the
        # connection to Pulseaudio
        _mainloop = pa.pa_threaded_mainloop_new()
        _mainloop_api = pa.pa_threaded_mainloop_get_api(_mainloop)
        context = pa.pa_context_new(_mainloop_api, sys.argv[0])
        pa.pa_context_set_state_callback(context, self._context_notify_cb, None)
        pa.pa_context_connect(context, None, 0, None)
        pa.pa_threaded_mainloop_start(_mainloop)
    def __init__(self, source_name, rate):
        self.source_name = source_name
        self.rate = rate

        self.bufs = []
        self.buf_samples = 0
        
        # Wrap callback methods in appropriate ctypefunc instances so
        # that the Pulseaudio C API can call them
        self._context_notify_cb = P.pa_context_notify_cb_t(self.context_notify_cb)
        self._source_info_cb = P.pa_source_info_cb_t(self.source_info_cb)
        self._stream_read_cb = P.pa_stream_request_cb_t(self.stream_read_cb)

        # stream_read_cb() puts peak samples into this Queue instance
        self._samples = Queue()

        # Create the mainloop thread and set our context_notify_cb
        # method to be called when there's updates relating to the
        # connection to Pulseaudio
        _mainloop = P.pa_threaded_mainloop_new()
        _mainloop_api = P.pa_threaded_mainloop_get_api(_mainloop)
        context = P.pa_context_new(_mainloop_api, 'peak_demo')
        P.pa_context_set_state_callback(context, self._context_notify_cb, None)
        P.pa_context_connect(context, None, 0, None)
        P.pa_threaded_mainloop_start(_mainloop)
    def __init__(self, source_name, rate):
        self.source_name = source_name
        self.rate = rate

        self.bufs = []
        self.buf_samples = 0

        # Wrap callback methods in appropriate ctypefunc instances so
        # that the Pulseaudio C API can call them
        self._context_notify_cb = P.pa_context_notify_cb_t(self.context_notify_cb)
        self._source_info_cb = P.pa_source_info_cb_t(self.source_info_cb)
        self._stream_read_cb = P.pa_stream_request_cb_t(self.stream_read_cb)

        # stream_read_cb() puts peak samples into this Queue instance
        self._samples = Queue()

        # Create the mainloop thread and set our context_notify_cb
        # method to be called when there's updates relating to the
        # connection to Pulseaudio
        _mainloop = P.pa_threaded_mainloop_new()
        _mainloop_api = P.pa_threaded_mainloop_get_api(_mainloop)
        context = P.pa_context_new(_mainloop_api, 'peak_demo')
        P.pa_context_set_state_callback(context, self._context_notify_cb, None)
        P.pa_context_connect(context, None, 0, None)
        P.pa_threaded_mainloop_start(_mainloop)
Beispiel #4
0
	def _main(self):
		self._mainloop = _lib.pa_mainloop_new()
		mainloop_api = _lib.pa_mainloop_get_api(self._mainloop)
		context = _lib.pa_context_new(mainloop_api, "i3companion") # Alt: _with_proplist
		_lib.pa_context_set_state_callback(context, self._context_state_callback, None)
		_lib.pa_context_connect(context, None, _lib.PA_CONTEXT_NOAUTOSPAWN, None)

		_lib.pa_mainloop_run(self._mainloop, None)

		# raw_input('Enter to close\n')

		_lib.pa_context_disconnect(context)
		_lib.pa_context_unref(context)
		# _lib.pa_mainloop_threaded_stop(self._mainloop)
		_lib.pa_mainloop_free(self._mainloop)
Beispiel #5
0
    def _main(self):
        self._mainloop = _lib.pa_mainloop_new()
        mainloop_api = _lib.pa_mainloop_get_api(self._mainloop)
        context = _lib.pa_context_new(mainloop_api,
                                      "i3companion")  # Alt: _with_proplist
        _lib.pa_context_set_state_callback(context,
                                           self._context_state_callback, None)
        _lib.pa_context_connect(context, None, _lib.PA_CONTEXT_NOAUTOSPAWN,
                                None)

        _lib.pa_mainloop_run(self._mainloop, None)

        # raw_input('Enter to close\n')

        _lib.pa_context_disconnect(context)
        _lib.pa_context_unref(context)
        # _lib.pa_mainloop_threaded_stop(self._mainloop)
        _lib.pa_mainloop_free(self._mainloop)