void PulseAudioSystem::setVolumes() { // set attenuation state and volumes if (bAttenuating) { // ensure the volume map is empty, otherwise it may be dangerous to change if (qhVolumes.empty()) { // set the new per-application volumes and store the old ones pa_operation_unref(pa_context_get_sink_input_info_list(pacContext, volume_sink_input_list_callback, this)); } // clear attenuation state and restore normal volumes } else { iRemainingOperations++; pa_operation_unref(pa_context_get_sink_input_info_list(pacContext, restore_sink_input_list_callback, this)); } }
void _cb_state_changed(pa_context *context, void *userdata) { callback_t *callback = (callback_t*)userdata; pa_context_state_t state = pa_context_get_state(context); PACMIXER_LOG("B:server state changed to %d", state); switch(state) { case PA_CONTEXT_READY: pa_context_set_subscribe_callback(context, _cb_event, callback); pa_context_subscribe(context, PA_SUBSCRIPTION_MASK_ALL, NULL, NULL); pa_context_get_sink_input_info_list(context, _cb_sink_input, callback); pa_context_get_sink_info_list(context, _cb_sink, callback); pa_context_get_source_info_list(context, _cb_source, callback); pa_context_get_source_output_info_list(context, _cb_source_output, callback); pa_context_get_card_info_list(context, _cb_card, callback); pa_context_get_server_info(context, _cb_server, callback); ((tstate_callback_func)(callback->state))(callback->self, S_CAME); break; case PA_CONTEXT_FAILED: case PA_CONTEXT_TERMINATED: pa_context_unref(context); ((tstate_callback_func)(callback->state))(callback->self, S_GONE); break; default: break; } }
int main(int argc, const char *argv[]) { pa_mainloop *pa_ml = NULL; pa_mainloop_api *pa_mlapi = NULL; pa_operation *pa_op = NULL; pa_context *pa_ctx = NULL; int pa_ready = 0; int state = 0; pa_ml = pa_mainloop_new(); pa_mlapi = pa_mainloop_get_api(pa_ml); pa_ctx = pa_context_new(pa_mlapi, "deepin"); pa_context_connect(pa_ctx, NULL, 0, NULL); pa_context_set_state_callback(pa_ctx, pa_state_cb, &pa_ready); for (;;) { if (pa_ready == 0) { pa_mainloop_iterate(pa_ml, 1, NULL); continue; } if (pa_ready == 2) { pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); pa_mainloop_free(pa_ml); return -1; } switch (state) { case 0: pa_op = pa_context_get_sink_input_info_list(pa_ctx, pa_sink_input_cb, NULL); state++; break; case 1: if (pa_operation_get_state(pa_op) == PA_OPERATION_DONE) { pa_operation_unref(pa_op); pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); pa_mainloop_free(pa_ml); return 0; } break; default: fprintf(stderr, "in state %d\n", state); return -1; } pa_mainloop_iterate(pa_ml, 1, NULL); } return 0; }
bool SinkInputModel::populate(pa_context *c) { pa_operation *op; op = pa_context_get_sink_input_info_list(c, SinkInputModel::populateSinkInputCallback, this); if (op) { inputsTemp = new QList<SinkInput>; pa_operation_unref(op); op = pa_context_get_client_info_list(c, SinkInputModel::populateClientCallback, this); if (op) { clientsTemp = new QMap<uint32_t, QString>; pa_operation_unref(op); } return true; } return false; }
void Context::contextStateCallback(pa_context *c) { qCDebug(PLASMAPA) << "state callback"; pa_context_state_t state = pa_context_get_state(c); if (state == PA_CONTEXT_READY) { qCDebug(PLASMAPA) << "ready"; // 1. Register for the stream changes (except during probe) if (m_context == c) { pa_context_set_subscribe_callback(c, subscribe_cb, this); if (!PAOperation(pa_context_subscribe(c, (pa_subscription_mask_t) (PA_SUBSCRIPTION_MASK_SINK| PA_SUBSCRIPTION_MASK_SOURCE| PA_SUBSCRIPTION_MASK_CLIENT| PA_SUBSCRIPTION_MASK_SINK_INPUT| PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT| PA_SUBSCRIPTION_MASK_CARD| PA_SUBSCRIPTION_MASK_SERVER), nullptr, nullptr))) { qCWarning(PLASMAPA) << "pa_context_subscribe() failed"; return; } } if (!PAOperation(pa_context_get_sink_info_list(c, sink_cb, this))) { qCWarning(PLASMAPA) << "pa_context_get_sink_info_list() failed"; return; } if (!PAOperation(pa_context_get_source_info_list(c, source_cb, this))) { qCWarning(PLASMAPA) << "pa_context_get_source_info_list() failed"; return; } if (!PAOperation(pa_context_get_client_info_list(c, client_cb, this))) { qCWarning(PLASMAPA) << "pa_context_client_info_list() failed"; return; } if (!PAOperation(pa_context_get_card_info_list(c, card_cb, this))) { qCWarning(PLASMAPA) << "pa_context_get_card_info_list() failed"; return; } if (!PAOperation(pa_context_get_sink_input_info_list(c, sink_input_callback, this))) { qCWarning(PLASMAPA) << "pa_context_get_sink_input_info_list() failed"; return; } if (!PAOperation(pa_context_get_source_output_info_list(c, source_output_cb, this))) { qCWarning(PLASMAPA) << "pa_context_get_source_output_info_list() failed"; return; } if (!PAOperation(pa_context_get_server_info(c, server_cb, this))) { qCWarning(PLASMAPA) << "pa_context_get_server_info() failed"; return; } if (PAOperation(pa_ext_stream_restore_read(c, ext_stream_restore_read_cb, this))) { pa_ext_stream_restore_set_subscribe_cb(c, ext_stream_restore_subscribe_cb, this); PAOperation(pa_ext_stream_restore_subscribe(c, 1, nullptr, this)); } else { qCWarning(PLASMAPA) << "Failed to initialize stream_restore extension"; } } else if (!PA_CONTEXT_IS_GOOD(state)) { qCWarning(PLASMAPA) << "context kaput"; if (m_context) { pa_context_unref(m_context); m_context = nullptr; } reset(); QTimer::singleShot(1000, this, &Context::connectToDaemon); } }
int set_active_port(pa_devicelist_t device, pa_portlist_t port) { pa_mainloop *pa_ml; pa_mainloop_api *pa_mlapi; pa_operation *pa_op; pa_context *pa_ctx; int pa_ready = 0; int state = 0; pa_ml = pa_mainloop_new(); pa_mlapi = pa_mainloop_get_api(pa_ml); pa_ctx = pa_context_new(pa_mlapi, "test"); pa_context_connect(pa_ctx, NULL, 0, NULL); pa_context_set_state_callback(pa_ctx, pa_state_cb, &pa_ready); pa_device_port_t dev_port_set; dev_port_set.device = device; dev_port_set.port = port; pa_clientlist_t clientlist[30]; int i = 0; for (;;) { // We can't do anything until PA is ready, so just iterate the mainloop // and continue if (pa_ready == 0) { pa_mainloop_iterate(pa_ml, 1, NULL); continue; } // We couldn't get a connection to the server, so exit out if (pa_ready == 2) { pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); pa_mainloop_free(pa_ml); return -1; } switch(state) { case 0: // Set source or sink switch(device.type) { case JOAPA_SOURCE: pa_op = pa_context_set_source_port_by_index( pa_ctx, device.index, port.name, set_active_port_cb, &dev_port_set); break; case JOAPA_SINK: pa_op = pa_context_set_sink_port_by_index( pa_ctx, device.index, port.name, set_active_port_cb, &dev_port_set); break; } state++; break; case 1: // get clients using a source or sink if (pa_operation_get_state(pa_op) == PA_OPERATION_DONE) { pa_operation_unref(pa_op); switch(device.type) { case JOAPA_SOURCE: pa_op = pa_context_get_source_output_info_list(pa_ctx, pa_source_info_cb, &clientlist); break; case JOAPA_SINK: pa_op = pa_context_get_sink_input_info_list(pa_ctx, pa_sink_info_cb, &clientlist); break; } state++; } break; case 2: // move the clients to the new source or sink if (pa_operation_get_state(pa_op) == PA_OPERATION_DONE) { pa_operation_unref(pa_op); if(!clientlist[i].initialized) { pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); pa_mainloop_free(pa_ml); return 0; } //printf("CLIENT: %d\n", clientlist[i].index); switch(device.type) { case JOAPA_SOURCE: pa_op = pa_context_move_source_output_by_index( pa_ctx, clientlist[i].index, device.index, set_active_port_cb, NULL); break; case JOAPA_SINK: pa_op = pa_context_move_sink_input_by_index( pa_ctx, clientlist[i].index, device.index, set_active_port_cb, NULL); break; } i++; } break; default: fprintf(stderr, "in state %d\n", state); return -1; } pa_mainloop_iterate(pa_ml, 1, NULL); } }
int main(int argc, char **argv) { int retval = 0; struct timeval timeout, timeout_def; pa_mainloop * ml = pa_mainloop_new(); pa_mainloop_api * api = pa_mainloop_get_api(ml); pa_context_state_t pa_state; pa_context * context = pa_context_new(api, "pa-mixer"); pa_context_connect(context, NULL, 0, NULL); pa_context_set_state_callback(context, pa_state_changed, &pa_state); /* struct sigaction sigint_handler; sigint_handler.sa_handler = handle_sig_int; sigemptyset(&sigint_handler.sa_mask); sigint_handler.sa_flags = 0; sigaction(SIGINT, &sigint_handler, NULL); */ int init_done = 0; initscr(); keypad(stdscr, TRUE); start_color(); curs_set(0); cbreak(); noecho(); init_pair(1, COLOR_WHITE, COLOR_BLACK); init_pair(2, COLOR_WHITE, COLOR_BLUE); fd_set read_set, test_set; FD_ZERO(&read_set); FD_SET(0, &read_set); timeout_def.tv_sec = 0; timeout_def.tv_usec = 1000; view_init(); while(running) { if(pa_state == PA_CONTEXT_UNCONNECTED) { pa_mainloop_iterate(ml, 1, NULL); continue; } if(pa_state == PA_CONTEXT_FAILED || pa_state == PA_CONTEXT_TERMINATED) { running = 0; retval = -1; } if(pa_state == PA_CONTEXT_READY) { if(!init_done) { pa_context_set_subscribe_callback(context, on_event, NULL); pa_context_subscribe(context, PA_SUBSCRIPTION_MASK_ALL, NULL, NULL); pa_context_get_sink_input_info_list(context, on_sink_input_update, context); pa_context_get_sink_info_list(context, on_sink_update, context); } init_done = 1; } test_set = read_set; timeout = timeout_def; int r = select(1, &test_set, NULL, NULL, &timeout); if(r == 0) { /* timeout */ pa_mainloop_iterate(ml, 0, NULL); } if(FD_ISSET(0, &test_set)) { /* stdin ready */ int key = getch(); switch(key) { case KEY_UP: view_select_prev(); view_show(); break; case KEY_DOWN: view_select_next(); view_show(); break; case KEY_LEFT: change_sel_vol(context, VOL_DOWN); break; case KEY_RIGHT: change_sel_vol(context, VOL_UP); break; case 'n': change_sel_vol(context, VOL_NORM); break; case 'm': change_sel_vol(context, VOL_MUTE); break; case 'q': running = 0; break; case KEY_RESIZE: view_show(); refresh(); break; } } } pa_context_disconnect(context); pa_context_unref(context); pa_mainloop_free(ml); endwin(); return retval; }
int main(int argc, char *argv[]) { if (argc != 3) { printf("usage: %s property value\n property: pulseaudio sink-input property (ex:application.name)\n value: the value for the wanted property (ex: \"Quod Libet\")\n", argv[0]); return -1; } pa_mainloop* pa_ml; pa_mainloop_api* pa_mlapi; pa_context* pa_ctx; pa_operation* pa_op; int state = 0; int pa_ready = 0; pa_ml = pa_mainloop_new(); pa_mlapi = pa_mainloop_get_api(pa_ml); pa_ctx = pa_context_new(pa_mlapi, "my_context"); pa_context_connect(pa_ctx, NULL, PA_CONTEXT_NOFLAGS, NULL); pa_context_set_state_callback(pa_ctx, pa_state_cb, &pa_ready); for (;;) { if (pa_ready == 0) { pa_mainloop_iterate(pa_ml, 1, NULL); continue; } if (pa_ready == 2) { pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); pa_mainloop_free(pa_ml); return -1; } switch (state) { case 0: pa_op = pa_context_get_sink_input_info_list(pa_ctx, pa_sink_input_info_cb, (void*)argv); state++; break; case 1: if (pa_operation_get_state(pa_op) == PA_OPERATION_RUNNING) { //printf("PA_OPERATION_RUNNING\n"); } if (pa_operation_get_state(pa_op) == PA_OPERATION_DONE) { // clean pa_operation_unref(pa_op); pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); pa_mainloop_free(pa_ml); return 0; } break; default: // We should never see this state fprintf(stderr, "in state %d\n", state); return -1; } pa_mainloop_iterate(pa_ml, 1, NULL); } printf("we should not be here...\n"); return -1; }