Пример #1
0
    def subscribe_cb(self, context, event_value, idx, user_data):
        if not idx:
            idx = 0

        event_facility = event_value & p.PA_SUBSCRIPTION_EVENT_FACILITY_MASK

        if event_facility == p.PA_SUBSCRIPTION_EVENT_SINK_INPUT:
            event_type = event_value & p.PA_SUBSCRIPTION_EVENT_TYPE_MASK

            if event_type == p.PA_SUBSCRIPTION_EVENT_NEW:
                p.pa_context_get_sink_input_info(context, idx,
                                                 self.sink_input_info_cb,
                                                 1)  # 1 for new
            elif event_type == p.PA_SUBSCRIPTION_EVENT_CHANGE:
                p.pa_context_get_sink_input_info(context, idx,
                                                 self.sink_input_info_cb,
                                                 2)  # 2 for changes
            elif event_type == p.PA_SUBSCRIPTION_EVENT_REMOVE:
                GLib.idle_add(self.emit, 'sink_input_removed', idx)
        elif event_facility == p.PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT:
            event_type = event_value & p.PA_SUBSCRIPTION_EVENT_TYPE_MASK

            if event_type == p.PA_SUBSCRIPTION_EVENT_NEW:
                p.pa_context_get_source_output_info(context, idx,
                                                    self.source_output_info_cb,
                                                    1)  # 1 for new
            elif event_type == p.PA_SUBSCRIPTION_EVENT_CHANGE:
                p.pa_context_get_source_output_info(context, idx,
                                                    self.source_output_info_cb,
                                                    2)  # 1 for new
            elif event_type == p.PA_SUBSCRIPTION_EVENT_REMOVE:
                GLib.idle_add(self.emit, 'source_output_removed', idx)
        elif event_facility == p.PA_SUBSCRIPTION_EVENT_SOURCE:
            event_type = event_value & p.PA_SUBSCRIPTION_EVENT_TYPE_MASK

            if event_type == p.PA_SUBSCRIPTION_EVENT_NEW:
                p.pa_context_get_source_info_by_index(self.ctx, idx,
                                                      self.source_info_cb,
                                                      1)  # 1 for new
            elif event_type == p.PA_SUBSCRIPTION_EVENT_CHANGE:
                pass
            elif event_type == p.PA_SUBSCRIPTION_EVENT_REMOVE:
                GLib.idle_add(self.emit, 'source_removed', idx)
        elif event_facility == p.PA_SUBSCRIPTION_EVENT_SINK:
            event_type = event_value & p.PA_SUBSCRIPTION_EVENT_TYPE_MASK

            if event_type == p.PA_SUBSCRIPTION_EVENT_NEW:
                p.pa_context_get_sink_info_by_index(self.ctx, idx,
                                                    self.sink_info_cb,
                                                    1)  # 1 for new
            elif event_type == p.PA_SUBSCRIPTION_EVENT_CHANGE:
                pass
            elif event_type == p.PA_SUBSCRIPTION_EVENT_REMOVE:
                GLib.idle_add(self.emit, 'sink_removed', idx)
        elif event_facility == p.PA_SUBSCRIPTION_EVENT_SERVER:
            event_type = event_value & p.PA_SUBSCRIPTION_EVENT_TYPE_MASK

            if event_type == p.PA_SUBSCRIPTION_EVENT_CHANGE:
                p.pa_context_get_server_info(context, self.server_info_cb, 1)
Пример #2
0
    def get_server_info(self):
        o = p.pa_context_get_server_info(self.ctx, self.server_info_cb, None)

        while p.pa_operation_get_state(o) == p.PA_OPERATION_RUNNING:
            pass

        p.pa_operation_unref(o)
Пример #3
0
    def get_server_info(self):
        p.pa_threaded_mainloop_lock(self.main_loop)

        o = p.pa_context_get_server_info(self.ctx, self.server_info_cb, None)

        while p.pa_operation_get_state(o) == p.PA_OPERATION_RUNNING:
            p.pa_threaded_mainloop_wait(self.main_loop)

        p.pa_operation_unref(o)

        p.pa_threaded_mainloop_unlock(self.main_loop)
Пример #4
0
    def __init__(self):
        GObject.GObject.__init__(self)

        self.context_ok = False
        self.default_sink_name = ''
        self.sink_is_loaded = False
        self.sink_owner_module = -1
        self.sink_idx = -1
        self.sink_monitor_name = ''
        self.sink_inputs = []
        self.max_volume = p.PA_VOLUME_NORM

        self.log = logging.getLogger('PulseEffects')

        self.app_blacklist = [
            'PulseEffects', 'pulseeffects', 'gsd-media-keys', 'GNOME Shell',
            'libcanberra', 'gnome-pomodoro'
        ]

        self.media_blacklist = ['pulsesink probe']

        # wrapping callbacks
        self.ctx_cb = p.pa_context_notify_cb_t(self.context_status)
        self.server_info_cb = p.pa_server_info_cb_t(self.server_info)
        self.default_sink_info_cb = p.pa_sink_info_cb_t(self.default_sink_info)
        self.sink_info_cb = p.pa_sink_info_cb_t(self.sink_info)
        self.sink_input_info_cb = p.pa_sink_input_info_cb_t(
            self.sink_input_info)
        self.ctx_success_cb = p.pa_context_success_cb_t(self.ctx_success)
        self.subscribe_cb = p.pa_context_subscribe_cb_t(self.subscribe)

        # creating main loop and context
        self.main_loop = p.pa_threaded_mainloop_new()
        self.main_loop_api = p.pa_threaded_mainloop_get_api(self.main_loop)

        self.ctx = p.pa_context_new(self.main_loop_api, b'PulseEffects')

        p.pa_context_set_state_callback(self.ctx, self.ctx_cb, None)

        p.pa_context_connect(self.ctx, None, 0, None)

        p.pa_threaded_mainloop_start(self.main_loop)

        # waiting context

        while self.context_ok is False:
            pass

        # getting default sink name through server info

        o = p.pa_context_get_server_info(self.ctx, self.server_info_cb, None)

        while p.pa_operation_get_state(o) == p.PA_OPERATION_RUNNING:
            pass

        p.pa_operation_unref(o)

        self.log.info('default pulseaudio sink: ' + self.default_sink_name)

        # getting default sink rate through sink info. We set
        # module-null-sink to the same rate to reduce clock drift

        o = p.pa_context_get_sink_info_by_name(self.ctx,
                                               self.default_sink_name.encode(),
                                               self.default_sink_info_cb, None)

        while p.pa_operation_get_state(o) == p.PA_OPERATION_RUNNING:
            pass

        p.pa_operation_unref(o)

        self.log.info('default pulseaudio sink audio format: ' +
                      str(self.default_sink_format) +
                      '. We will use the same format.')
        self.log.info('default pulseaudio sink sampling rate: ' +
                      str(self.default_sink_rate) +
                      ' Hz. We will use the same rate.')

        # load source sink
        self.load_sink()

        # search sink inputs
        o = p.pa_context_get_sink_input_info_list(self.ctx,
                                                  self.sink_input_info_cb,
                                                  None)

        while p.pa_operation_get_state(o) == p.PA_OPERATION_RUNNING:
            pass

        p.pa_operation_unref(o)

        # subscribing to pulseaudio events
        p.pa_context_set_subscribe_callback(self.ctx, self.subscribe_cb, None)

        p.pa_context_subscribe(self.ctx, p.PA_SUBSCRIPTION_MASK_SINK_INPUT,
                               self.ctx_success_cb, None)