#include #include #include #define INTERVAL 125 #define TEST_NR ((1000/INTERVAL)*3600*72UL) struct context{ pa_context *pa_cxt; GMainLoop *main_loop; }; gboolean set_mute_unmute(struct context *cxt) { static gboolean mute = TRUE; static gint count = 0; pa_operation *o; mute = !mute; count++; o = pa_context_set_sink_mute_by_index(cxt->pa_cxt, 0, mute, NULL, NULL); if (o == NULL) { g_warning ("pa_context_set_sink_mute_by_index() failed: %s", pa_strerror(pa_context_errno(cxt->pa_cxt))); g_main_quit(cxt->main_loop); return FALSE; } if (count == TEST_NR) { g_print("Max test number(=%lu) reached, quit.\n", TEST_NR); g_main_quit(cxt->main_loop); return FALSE; } g_print("\r%10d:\tset to %6s", count, mute ? "mute":"unmute"); pa_operation_unref(o); return TRUE; } int main() { struct context cxt; pa_glib_mainloop *pa_main_loop; int r; pa_main_loop = pa_glib_mainloop_new(NULL); cxt.pa_cxt = pa_context_new(pa_glib_mainloop_get_api(pa_main_loop), "mute-automute-test"); cxt.main_loop = g_main_loop_new(NULL, FALSE); r = pa_context_connect(cxt.pa_cxt, NULL, 0, NULL); if (r) { g_print("Failed to connect PA server.\n"); exit(3); } g_timeout_add(INTERVAL, (GSourceFunc) set_mute_unmute, &cxt); g_main_loop_run(cxt.main_loop); return 0; }