예제 #1
0
    def source_info_cb(self, context, info, eol, emit_signal):
        if eol == -1:
            self.log.debug(self.log_tag + ' error in source_info_cb')

            p.pa_threaded_mainloop_signal(self.main_loop, 0)
        elif eol == 0 and info:
            self.source_idx = info.contents.index
            self.source_rate = info.contents.sample_spec.rate

            sample_format = info.contents.sample_spec.format
            self.source_format = p.sample_spec_format_name(sample_format)

            name = info.contents.name.decode()

            if (emit_signal and name != 'PulseEffects_apps.monitor'
                    and name != 'PulseEffects_mic.monitor'):
                description = info.contents.description.decode()

                new_sink = {
                    'name': name,
                    'idx': self.source_idx,
                    'description': description
                }

                GLib.idle_add(self.emit, 'source_added', new_sink)
        elif eol == 1:
            p.pa_threaded_mainloop_signal(self.main_loop, 0)
예제 #2
0
    def ctx_success_cb(self, context, success, user_data):
        if user_data:
            data = p.cast_to_struct_ptr(user_data, p.ctx_success_cb_data)

            if data.contents:
                operation = data.contents.operation

                if operation:
                    try:
                        operation = operation.decode('utf-8')

                        if not success:
                            self.log.critical(self.log_tag +
                                              'context operation ' +
                                              operation + ' failed!')

                        if operation == 'unload_module':
                            p.pa_threaded_mainloop_signal(self.main_loop, 0)
                    except UnicodeDecodeError:
                        pass

        elif not success:
            self.log.critical(self.log_tag + 'context operation failed!!')
예제 #3
0
    def sink_info_cb(self, context, info, eol, emit_signal):
        if eol == -1:  # error ocurred. Sink may not exist
            self.sink_is_loaded = False

            p.pa_threaded_mainloop_signal(self.main_loop, 0)
        elif eol == 0 and info:
            self.sink_owner_module = info.contents.owner_module
            self.sink_idx = info.contents.index
            self.sink_rate = info.contents.sample_spec.rate

            sample_format = info.contents.sample_spec.format
            self.sink_format = p.sample_spec_format_name(sample_format)

            self.sink_monitor_name = info.contents.monitor_source_name\
                .decode()

            self.sink_monitor_idx = info.contents.monitor_source

            name = info.contents.name.decode()

            if (emit_signal and name != 'PulseEffects_apps'
                    and name != 'PulseEffects_mic'):
                description = info.contents.description.decode()

                new_sink = {
                    'name': name,
                    'idx': self.sink_idx,
                    'description': description,
                    'monitor_source_name': self.sink_monitor_name
                }

                GLib.idle_add(self.emit, 'sink_added', new_sink)
        elif eol == 1:  # no more objects
            self.sink_is_loaded = True

            p.pa_threaded_mainloop_signal(self.main_loop, 0)
예제 #4
0
    def server_info_cb(self, context, info, emit_signal):
        self.default_sink_name = info.contents.default_sink_name.decode()
        self.default_source_name = info.contents.default_source_name.decode()

        server_version = info.contents.server_version.decode()

        self.log.debug(self.log_tag + 'pulseaudio version: ' + server_version)
        self.log.debug(self.log_tag + 'default pulseaudio source: ' +
                       self.default_source_name)
        self.log.debug(self.log_tag + 'default pulseaudio sink: ' +
                       self.default_sink_name)

        if emit_signal:
            if (self.default_sink_name != 'PulseEffects_apps'
                    and self.use_default_sink):
                GLib.idle_add(self.emit, 'new_default_sink',
                              self.default_sink_name)

            if (self.default_source_name != 'PulseEffects_mic.monitor'
                    and self.use_default_source):
                GLib.idle_add(self.emit, 'new_default_source',
                              self.default_source_name)

        p.pa_threaded_mainloop_signal(self.main_loop, 0)
예제 #5
0
    def source_output_info_cb(self, context, info, eol, user_data):
        if eol == -1:
            p.pa_threaded_mainloop_signal(self.main_loop, 0)
        elif eol == 0 and info:
            idx = info.contents.index
            proplist = info.contents.proplist

            app_name = p.pa_proplist_gets(proplist, b'application.name')
            media_name = p.pa_proplist_gets(proplist, b'media.name')
            media_role = p.pa_proplist_gets(proplist, b'media.role')
            icon_name = p.pa_proplist_gets(proplist, b'application.icon_name')

            if not app_name:
                app_name = ''
            else:
                app_name = app_name.decode()

            if not media_name:
                media_name = ''
            else:
                media_name = media_name.decode()

            if not media_role:
                media_role = ''
            else:
                media_role = media_role.decode()

            if (app_name not in self.app_blacklist
                    and media_name not in self.media_name_blacklist
                    and media_role not in self.media_role_blacklist):
                if not icon_name:
                    icon_name = 'audio-x-generic-symbolic'
                else:
                    icon_name = icon_name.decode()

                connected = False

                if info.contents.source == self.mic_sink_monitor_idx:
                    connected = True

                volume = info.contents.volume
                audio_channels = volume.channels
                mute = info.contents.mute

                max_volume_linear = 100 * \
                    p.pa_cvolume_max(volume) / p.PA_VOLUME_NORM

                resample_method = info.contents.resample_method

                if resample_method:
                    resample_method = resample_method.decode()
                else:
                    resample_method = 'null'

                sample_spec = info.contents.sample_spec
                rate = sample_spec.rate
                sample_format = p.sample_spec_format_name(sample_spec.format)
                buffer_latency = info.contents.buffer_usec
                latency = info.contents.source_usec
                corked = info.contents.corked

                new_output = {
                    'index': idx,
                    'name': app_name,
                    'icon': icon_name,
                    'channels': audio_channels,
                    'volume': max_volume_linear,
                    'rate': rate,
                    'resampler': resample_method,
                    'format': sample_format,
                    'mute': mute,
                    'connected': connected,
                    'buffer_latency': buffer_latency,
                    'latency': latency,
                    'corked': corked
                }

                if user_data == 1:
                    GLib.idle_add(self.emit, 'source_output_added', new_output)
                elif user_data == 2:
                    GLib.idle_add(self.emit, 'source_output_changed',
                                  new_output)

        elif eol == 1:
            p.pa_threaded_mainloop_signal(self.main_loop, 0)
예제 #6
0
    def module_idx_cb(self, context, idx, user_data):
        self.log.debug(self.log_tag + 'sink owner module index: ' + str(idx))

        p.pa_threaded_mainloop_signal(self.main_loop, 0)
예제 #7
0
    def ctx_drain_notify_cb(self, ctx, user_data):
        state = p.pa_context_get_state(ctx)

        if state == p.PA_CONTEXT_READY:
            p.pa_threaded_mainloop_signal(self.main_loop, 0)