def set_source_output_mute(self, idx, mute_state): user_data = p.ctx_success_cb_data() user_data.operation = 'set_source_output_mute'.encode('utf-8') p.pa_context_set_source_output_mute(self.ctx, idx, mute_state, self.ctx_success_cb, p.get_ref(user_data))
def move_source_output_to_default_source(self, idx): user_data = p.ctx_success_cb_data() user_data.operation = 'move_source_output_by_name'.encode('utf-8') p.pa_context_move_source_output_by_name( self.ctx, idx, self.default_source_name.encode(), self.ctx_success_cb, p.get_ref(user_data))
def move_source_output_to_pulseeffects_source(self, idx): user_data = p.ctx_success_cb_data() user_data.operation = 'move_source_output_by_index'.encode('utf-8') p.pa_context_move_source_output_by_index(self.ctx, idx, self.mic_sink_monitor_idx, self.ctx_success_cb, p.get_ref(user_data))
def ctx_notify_cb(self, ctx, user_data): state = p.pa_context_get_state(ctx) if state == p.PA_CONTEXT_UNCONNECTED: self.log.debug(self.log_tag + 'pulseaudio context is unconnected') elif state == p.PA_CONTEXT_CONNECTING: self.log.debug(self.log_tag + 'pulseaudio context is connecting') elif state == p.PA_CONTEXT_AUTHORIZING: self.log.debug(self.log_tag + 'pulseaudio context is authorizing') elif state == p.PA_CONTEXT_SETTING_NAME: self.log.debug(self.log_tag + 'pulseaudio context is setting name') elif state == p.PA_CONTEXT_READY: self.log.debug(self.log_tag + 'pulseaudio context is ready') self.log.debug(self.log_tag + 'connected to server: ' + p.pa_context_get_server(ctx).decode()) self.log.debug(self.log_tag + 'server protocol version: ' + str(p.pa_context_get_server_protocol_version(ctx))) p.pa_context_set_subscribe_callback(ctx, self.subscribe_cb, None) # subscribing to pulseaudio events subscription_mask = p.PA_SUBSCRIPTION_MASK_SINK_INPUT + \ p.PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT + \ p.PA_SUBSCRIPTION_MASK_SOURCE + \ p.PA_SUBSCRIPTION_MASK_SINK + \ p.PA_SUBSCRIPTION_MASK_SERVER udata = p.ctx_success_cb_data() udata.operation = 'subscribe'.encode('utf-8') p.pa_context_subscribe(ctx, subscription_mask, self.ctx_success_cb, p.get_ref(udata)) self.event_ctx_ready.set() elif state == p.PA_CONTEXT_FAILED: self.log.critical(self.log_tag + 'failed to start pulseaudio context') self.log.critical(self.log_tag + 'unferencing pulseaudio context object') p.pa_context_unref(ctx) elif state == p.PA_CONTEXT_TERMINATED: self.log.debug(self.log_tag + 'pulseaudio context terminated') self.event_ctx_terminated.set()
def unload_module(self, module): user_data = p.ctx_success_cb_data() user_data.operation = 'unload_module'.encode('utf-8') p.pa_threaded_mainloop_lock(self.main_loop) o = p.pa_context_unload_module(self.ctx, module, self.ctx_success_cb, p.get_ref(user_data)) 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)
def set_source_output_volume(self, idx, audio_channels, value): cvolume = p.pa_cvolume() cvolume.channels = audio_channels raw_value = int(p.PA_VOLUME_NORM * value / 100) cvolume_ptr = p.pa_cvolume_set(p.get_ref(cvolume), audio_channels, raw_value) user_data = p.ctx_success_cb_data() user_data.operation = 'set_source_output_volume'.encode('utf-8') p.pa_context_set_source_output_volume(self.ctx, idx, cvolume_ptr, self.ctx_success_cb, p.get_ref(user_data))