static struct pa_io_event* stdio_event = NULL;
+/* A shortcut for terminating the application */
static void quit(int ret) {
assert(mainloop_api);
mainloop_api->quit(mainloop_api, ret);
}
+/* Write some data to the stream */
static void do_stream_write(size_t length) {
size_t l;
assert(length);
}
}
+/* This is called whenever new data may be written to the stream */
static void stream_write_callback(struct pa_stream *s, size_t length, void *userdata) {
assert(s && length);
do_stream_write(length);
}
+/* This is called whenever new data may is available */
static void stream_read_callback(struct pa_stream *s, const void*data, size_t length, void *userdata) {
assert(s && data && length);
buffer_index = 0;
}
+/* This routine is called whenever the stream state changes */
static void stream_state_callback(struct pa_stream *s, void *userdata) {
assert(s);
}
}
+/* This is called whenever the context status changes */
static void context_state_callback(struct pa_context *c, void *userdata) {
static const struct pa_sample_spec ss = {
.format = PA_SAMPLE_S16LE,
}
}
+/* Connection draining complete */
static void context_drain_complete(struct pa_context*c, void *userdata) {
pa_context_disconnect(c);
}
+/* Stream draining complete */
static void stream_drain_complete(struct pa_stream*s, int success, void *userdata) {
struct pa_operation *o;
}
}
+/* New data on STDIN **/
static void stdin_callback(struct pa_mainloop_api*a, struct pa_io_event *e, int fd, enum pa_io_event_flags f, void *userdata) {
size_t l, w = 0;
ssize_t r;
do_stream_write(w);
}
+/* Some data may be written to STDOUT */
static void stdout_callback(struct pa_mainloop_api*a, struct pa_io_event *e, int fd, enum pa_io_event_flags f, void *userdata) {
ssize_t r;
assert(a == mainloop_api && e && stdio_event == e);
}
}
+/* UNIX signal to quit recieved */
static void exit_signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) {
fprintf(stderr, "Got SIGINT, exiting.\n");
quit(0);
}
+/* Show the current playback latency */
static void stream_get_latency_callback(struct pa_stream *s, uint32_t latency, void *userdata) {
assert(s);
fprintf(stderr, "Current latency is %u usecs.\n", latency);
}
+/* Someone requested that the latency is shown */
static void sigusr1_signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) {
if (mode != PLAYBACK)
return;
if (!(bn = strrchr(argv[0], '/')))
bn = argv[0];
+ else
+ bn++;
if (strstr(bn, "rec") || strstr(bn, "mon"))
mode = RECORD;
mode = PLAYBACK;
fprintf(stderr, "Opening a %s stream.\n", mode == RECORD ? "recording" : "playback");
-
+
+ /* Set up a new main loop */
if (!(m = pa_mainloop_new())) {
fprintf(stderr, "pa_mainloop_new() failed.\n");
goto quit;
fprintf(stderr, "source_io() failed.\n");
goto quit;
}
-
- if (!(context = pa_context_new(mainloop_api, argv[0]))) {
+
+ /* Create a new connection context */
+ if (!(context = pa_context_new(mainloop_api, bn))) {
fprintf(stderr, "pa_context_new() failed.\n");
goto quit;
}
pa_context_set_state_callback(context, context_state_callback, NULL);
+ /* Connect the context */
pa_context_connect(context, NULL);
+ /* Run the main loop */
if (pa_mainloop_run(m, &ret) < 0) {
fprintf(stderr, "pa_mainloop_run() failed.\n");
goto quit;