def sink_input_info(self, context, info, eol, user_data): if info: idx = info.contents.index connected_sink_idx = info.contents.sink proplist = info.contents.proplist app_name = p.pa_proplist_gets(proplist, b'application.name') media_name = p.pa_proplist_gets(proplist, b'media.name') 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 (app_name not in self.app_blacklist and media_name not in self.media_blacklist): connected = False if not icon_name: icon_name = 'audio-x-generic-symbolic' else: icon_name = icon_name.decode() if connected_sink_idx == self.sink_idx: connected = True volume = info.contents.volume audio_channels = volume.channels 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 = self.get_sample_spec_format(sample_spec.format) new_input = [ idx, app_name, media_name, icon_name, audio_channels, max_volume_linear, rate, resample_method, sample_format, connected ] if user_data == 1: GLib.idle_add(self.emit, 'sink_input_added', new_input) elif user_data == 2: GLib.idle_add(self.emit, 'sink_input_changed', new_input)
def sink_input_info(self, context, info, eol, user_data): if eol == -1: for s in self.sink_inputs: if s[0] == user_data: self.sink_inputs.remove(s) GLib.idle_add(self.emit, 'sink_inputs_changed') break if info: idx = info.contents.index connected_sink_idx = info.contents.sink proplist = info.contents.proplist app_name = p.pa_proplist_gets(proplist, b'application.name') media_name = p.pa_proplist_gets(proplist, b'media.name') 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 icon_name: icon_name = 'audio-x-generic-symbolic' else: icon_name = icon_name.decode() if (app_name not in self.app_blacklist and media_name not in self.media_blacklist): connected = False if connected_sink_idx == self.sink_idx: connected = True new_input = [idx, app_name, media_name, icon_name, connected] list_idx = 0 have_this_input = False for s in self.sink_inputs: if s[0] == idx: have_this_input = True break list_idx = list_idx + 1 if have_this_input: # update sink input self.sink_inputs[list_idx] = new_input else: self.sink_inputs.append(new_input) if eol == 1: GLib.idle_add(self.emit, 'sink_inputs_changed')
def source_output_info(self, context, info, eol, user_data): if 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') 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 (app_name not in self.app_blacklist and media_name not in self.media_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 = self.get_sample_spec_format(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)