/* * Iterate the mainloop * * The custom implementation gives better performance than the function * provided by pulse audio, maybe due to the timeout set in prepare ? */ static void pulse_iterate(struct pulse_data *data) { if (pa_mainloop_prepare(data->mainloop, 1000) < 0) { blog(LOG_ERROR, "Unable to prepare main loop"); return; } if (pa_mainloop_poll(data->mainloop) < 0) { blog(LOG_ERROR, "Unable to poll main loop"); return; } if (pa_mainloop_dispatch(data->mainloop) < 0) blog(LOG_ERROR, "Unable to dispatch main loop"); }
static void *conn_thread(void *arg) { struct pulse_conn_t *conn = arg; while(true) { pa_mainloop_prepare(conn->loop, -1); pa_mainloop_poll(conn->loop); if(conn->quit) break; pa_mainloop_dispatch(conn->loop); } return NULL; }
APULSE_EXPORT int pa_mainloop_iterate(pa_mainloop *m, int block, int *retval) { trace_info("F %s m=%p, block=%d\n", __func__, m, block); int err; int timeout = 1000; if (g_queue_peek_head(m->queue)) timeout = 10; err = pa_mainloop_prepare(m, timeout); if (err < 0) return err; err = pa_mainloop_poll(m); if (err < 0) return err; err = pa_mainloop_dispatch(m); return err; }