summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
l---------src/utils/Makefile1
-rw-r--r--src/utils/pabrowse.c154
-rw-r--r--src/utils/pacat.c1007
-rw-r--r--src/utils/pacmd.c276
-rw-r--r--src/utils/pactl.c1621
-rwxr-xr-x[-rw-r--r--]src/utils/padsp5
-rw-r--r--src/utils/padsp.c918
-rw-r--r--src/utils/paplay.c432
-rw-r--r--src/utils/pasuspender.c314
-rw-r--r--src/utils/pax11publish.c137
-rwxr-xr-xsrc/utils/qpaeq560
11 files changed, 3844 insertions, 1581 deletions
diff --git a/src/utils/Makefile b/src/utils/Makefile
deleted file mode 120000
index c110232d..00000000
--- a/src/utils/Makefile
+++ /dev/null
@@ -1 +0,0 @@
-../pulse/Makefile \ No newline at end of file
diff --git a/src/utils/pabrowse.c b/src/utils/pabrowse.c
deleted file mode 100644
index 450182f5..00000000
--- a/src/utils/pabrowse.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/* $Id$ */
-
-/***
- This file is part of PulseAudio.
-
- PulseAudio is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
- or (at your option) any later version.
-
- PulseAudio is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with PulseAudio; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <assert.h>
-#include <signal.h>
-
-#include <pulse/pulseaudio.h>
-#include <pulse/browser.h>
-
-static void exit_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
- fprintf(stderr, "Got signal, exiting\n");
- m->quit(m, 0);
-}
-
-static void dump_server(const pa_browse_info *i) {
- char t[16];
-
- if (i->cookie)
- snprintf(t, sizeof(t), "0x%08x", *i->cookie);
-
- printf("server: %s\n"
- "server-version: %s\n"
- "user-name: %s\n"
- "fqdn: %s\n"
- "cookie: %s\n",
- i->server,
- i->server_version ? i->server_version : "n/a",
- i->user_name ? i->user_name : "n/a",
- i->fqdn ? i->fqdn : "n/a",
- i->cookie ? t : "n/a");
-}
-
-static void dump_device(const pa_browse_info *i) {
- char ss[PA_SAMPLE_SPEC_SNPRINT_MAX];
-
- if (i->sample_spec)
- pa_sample_spec_snprint(ss, sizeof(ss), i->sample_spec);
-
- printf("device: %s\n"
- "description: %s\n"
- "sample spec: %s\n",
- i->device,
- i->description ? i->description : "n/a",
- i->sample_spec ? ss : "n/a");
-
-}
-
-static void browser_callback(pa_browser *b, pa_browse_opcode_t c, const pa_browse_info *i, void *userdata) {
- assert(b && i);
-
- switch (c) {
-
- case PA_BROWSE_NEW_SERVER:
- printf("\n=> new server <%s>\n", i->name);
- dump_server(i);
- break;
-
- case PA_BROWSE_NEW_SINK:
- printf("\n=> new sink <%s>\n", i->name);
- dump_server(i);
- dump_device(i);
- break;
-
- case PA_BROWSE_NEW_SOURCE:
- printf("\n=> new source <%s>\n", i->name);
- dump_server(i);
- dump_device(i);
- break;
-
- case PA_BROWSE_REMOVE_SERVER:
- printf("\n=> removed server <%s>\n", i->name);
- break;
-
- case PA_BROWSE_REMOVE_SINK:
- printf("\n=> removed sink <%s>\n", i->name);
- break;
-
- case PA_BROWSE_REMOVE_SOURCE:
- printf("\n=> removed source <%s>\n", i->name);
- break;
-
- default:
- ;
- }
-}
-
-static void error_callback(pa_browser *b, const char *s, void *userdata) {
- pa_mainloop_api*m = userdata;
-
- fprintf(stderr, "Failure: %s\n", s);
- m->quit(m, 1);
-}
-
-int main(int argc, char *argv[]) {
- pa_mainloop *mainloop = NULL;
- pa_browser *browser = NULL;
- int ret = 1, r;
- const char *s;
-
- if (!(mainloop = pa_mainloop_new()))
- goto finish;
-
- r = pa_signal_init(pa_mainloop_get_api(mainloop));
- assert(r == 0);
- pa_signal_new(SIGINT, exit_signal_callback, NULL);
- pa_signal_new(SIGTERM, exit_signal_callback, NULL);
- signal(SIGPIPE, SIG_IGN);
-
- if (!(browser = pa_browser_new_full(pa_mainloop_get_api(mainloop), PA_BROWSE_FOR_SERVERS|PA_BROWSE_FOR_SINKS|PA_BROWSE_FOR_SOURCES, &s))) {
- fprintf(stderr, "pa_browse_new_full(): %s\n", s);
- goto finish;
- }
-
- pa_browser_set_callback(browser, browser_callback, NULL);
- pa_browser_set_error_callback(browser, error_callback, pa_mainloop_get_api(mainloop));
-
- ret = 0;
- pa_mainloop_run(mainloop, &ret);
-
-finish:
-
- if (browser)
- pa_browser_unref(browser);
-
- if (mainloop) {
- pa_signal_done();
- pa_mainloop_free(mainloop);
- }
-
- return ret;
-}
diff --git a/src/utils/pacat.c b/src/utils/pacat.c
index 10edd71d..323f071b 100644
--- a/src/utils/pacat.c
+++ b/src/utils/pacat.c
@@ -1,18 +1,19 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+ Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -32,14 +33,23 @@
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
+#include <locale.h>
+#include <sndfile.h>
+
+#include <pulse/i18n.h>
#include <pulse/pulseaudio.h>
+#include <pulse/rtclock.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/log.h>
+#include <pulsecore/sndfile-util.h>
+#include <pulsecore/core-util.h>
#define TIME_EVENT_USEC 50000
-#if PA_API_VERSION != 9
-#error Invalid PulseAudio API version
-#endif
+#define CLEAR_LINE "\x1B[K"
static enum { RECORD, PLAYBACK } mode = PLAYBACK;
@@ -52,47 +62,112 @@ static size_t buffer_length = 0, buffer_index = 0;
static pa_io_event* stdio_event = NULL;
-static char *stream_name = NULL, *client_name = NULL, *device = NULL;
+static pa_proplist *proplist = NULL;
+static char *device = NULL;
-static int verbose = 0;
+static SNDFILE* sndfile = NULL;
+
+static pa_bool_t verbose = FALSE;
static pa_volume_t volume = PA_VOLUME_NORM;
+static pa_bool_t volume_is_set = FALSE;
static pa_sample_spec sample_spec = {
.format = PA_SAMPLE_S16LE,
.rate = 44100,
.channels = 2
};
+static pa_bool_t sample_spec_set = FALSE;
static pa_channel_map channel_map;
-static int channel_map_set = 0;
+static pa_bool_t channel_map_set = FALSE;
+
+static sf_count_t (*readf_function)(SNDFILE *_sndfile, void *ptr, sf_count_t frames) = NULL;
+static sf_count_t (*writef_function)(SNDFILE *_sndfile, const void *ptr, sf_count_t frames) = NULL;
+
+static pa_stream_flags_t flags = 0;
+
+static size_t latency = 0, process_time = 0;
+static int32_t latency_msec = 0, process_time_msec = 0;
+
+static pa_bool_t raw = TRUE;
+static int file_format = -1;
/* A shortcut for terminating the application */
static void quit(int ret) {
- assert(mainloop_api);
+ pa_assert(mainloop_api);
mainloop_api->quit(mainloop_api, ret);
}
+/* Connection draining complete */
+static void context_drain_complete(pa_context*c, void *userdata) {
+ pa_context_disconnect(c);
+}
+
+/* Stream draining complete */
+static void stream_drain_complete(pa_stream*s, int success, void *userdata) {
+ pa_operation *o = NULL;
+
+ if (!success) {
+ pa_log(_("Failed to drain stream: %s"), pa_strerror(pa_context_errno(context)));
+ quit(1);
+ }
+
+ if (verbose)
+ pa_log(_("Playback stream drained."));
+
+ pa_stream_disconnect(stream);
+ pa_stream_unref(stream);
+ stream = NULL;
+
+ if (!(o = pa_context_drain(context, context_drain_complete, NULL)))
+ pa_context_disconnect(context);
+ else {
+ pa_operation_unref(o);
+ if (verbose)
+ pa_log(_("Draining connection to server."));
+ }
+}
+
+/* Start draining */
+static void start_drain(void) {
+
+ if (stream) {
+ pa_operation *o;
+
+ pa_stream_set_write_callback(stream, NULL, NULL);
+
+ if (!(o = pa_stream_drain(stream, stream_drain_complete, NULL))) {
+ pa_log(_("pa_stream_drain(): %s"), pa_strerror(pa_context_errno(context)));
+ quit(1);
+ return;
+ }
+
+ pa_operation_unref(o);
+ } else
+ quit(0);
+}
+
/* Write some data to the stream */
static void do_stream_write(size_t length) {
size_t l;
- assert(length);
+ pa_assert(length);
if (!buffer || !buffer_length)
return;
-
+
l = length;
if (l > buffer_length)
l = buffer_length;
-
+
if (pa_stream_write(stream, (uint8_t*) buffer + buffer_index, l, NULL, 0, PA_SEEK_RELATIVE) < 0) {
- fprintf(stderr, "pa_stream_write() failed: %s\n", pa_strerror(pa_context_errno(context)));
+ pa_log(_("pa_stream_write() failed: %s"), pa_strerror(pa_context_errno(context)));
quit(1);
return;
}
-
+
buffer_length -= l;
buffer_index += l;
-
+
if (!buffer_length) {
pa_xfree(buffer);
buffer = NULL;
@@ -102,51 +177,138 @@ static void do_stream_write(size_t length) {
/* This is called whenever new data may be written to the stream */
static void stream_write_callback(pa_stream *s, size_t length, void *userdata) {
- assert(s && length);
+ pa_assert(s);
+ pa_assert(length > 0);
- if (stdio_event)
- mainloop_api->io_enable(stdio_event, PA_IO_EVENT_INPUT);
+ if (raw) {
+ pa_assert(!sndfile);
- if (!buffer)
- return;
+ if (stdio_event)
+ mainloop_api->io_enable(stdio_event, PA_IO_EVENT_INPUT);
+
+ if (!buffer)
+ return;
+
+ do_stream_write(length);
+
+ } else {
+ sf_count_t bytes;
+ void *data;
+
+ pa_assert(sndfile);
+
+ for (;;) {
+ size_t data_length = length;
- do_stream_write(length);
+ if (pa_stream_begin_write(s, &data, &data_length) < 0) {
+ pa_log(_("pa_stream_begin_write() failed: %s"), pa_strerror(pa_context_errno(context)));
+ quit(1);
+ return;
+ }
+
+ if (readf_function) {
+ size_t k = pa_frame_size(&sample_spec);
+
+ if ((bytes = readf_function(sndfile, data, (sf_count_t) (data_length/k))) > 0)
+ bytes *= (sf_count_t) k;
+
+ } else
+ bytes = sf_read_raw(sndfile, data, (sf_count_t) data_length);
+
+ if (bytes > 0)
+ pa_stream_write(s, data, (size_t) bytes, NULL, 0, PA_SEEK_RELATIVE);
+ else
+ pa_stream_cancel_write(s);
+
+ /* EOF? */
+ if (bytes < (sf_count_t) data_length) {
+ start_drain();
+ break;
+ }
+
+ /* Request fulfilled */
+ if ((size_t) bytes >= length)
+ break;
+
+ length -= bytes;
+ }
+ }
}
/* This is called whenever new data may is available */
static void stream_read_callback(pa_stream *s, size_t length, void *userdata) {
- const void *data;
- assert(s && length);
- if (stdio_event)
- mainloop_api->io_enable(stdio_event, PA_IO_EVENT_OUTPUT);
+ pa_assert(s);
+ pa_assert(length > 0);
- if (pa_stream_peek(s, &data, &length) < 0) {
- fprintf(stderr, "pa_stream_peek() failed: %s\n", pa_strerror(pa_context_errno(context)));
- quit(1);
- return;
- }
-
- assert(data && length);
+ if (raw) {
+ pa_assert(!sndfile);
- if (buffer) {
- fprintf(stderr, "Buffer overrun, dropping incoming data\n");
- if (pa_stream_drop(s) < 0) {
- fprintf(stderr, "pa_stream_drop() failed: %s\n", pa_strerror(pa_context_errno(context)));
- quit(1);
+ if (stdio_event)
+ mainloop_api->io_enable(stdio_event, PA_IO_EVENT_OUTPUT);
+
+ while (pa_stream_readable_size(s) > 0) {
+ const void *data;
+
+ if (pa_stream_peek(s, &data, &length) < 0) {
+ pa_log(_("pa_stream_peek() failed: %s"), pa_strerror(pa_context_errno(context)));
+ quit(1);
+ return;
+ }
+
+ pa_assert(data);
+ pa_assert(length > 0);
+
+ if (buffer) {
+ buffer = pa_xrealloc(buffer, buffer_length + length);
+ memcpy((uint8_t*) buffer + buffer_length, data, length);
+ buffer_length += length;
+ } else {
+ buffer = pa_xmalloc(length);
+ memcpy(buffer, data, length);
+ buffer_length = length;
+ buffer_index = 0;
+ }
+
+ pa_stream_drop(s);
}
- return;
- }
- buffer = pa_xmalloc(buffer_length = length);
- memcpy(buffer, data, length);
- buffer_index = 0;
- pa_stream_drop(s);
+ } else {
+ pa_assert(sndfile);
+
+ while (pa_stream_readable_size(s) > 0) {
+ sf_count_t bytes;
+ const void *data;
+
+ if (pa_stream_peek(s, &data, &length) < 0) {
+ pa_log(_("pa_stream_peek() failed: %s"), pa_strerror(pa_context_errno(context)));
+ quit(1);
+ return;
+ }
+
+ pa_assert(data);
+ pa_assert(length > 0);
+
+ if (writef_function) {
+ size_t k = pa_frame_size(&sample_spec);
+
+ if ((bytes = writef_function(sndfile, data, (sf_count_t) (length/k))) > 0)
+ bytes *= (sf_count_t) k;
+
+ } else
+ bytes = sf_write_raw(sndfile, data, (sf_count_t) length);
+
+ if (bytes < (sf_count_t) length)
+ quit(1);
+
+ pa_stream_drop(s);
+ }
+ }
}
/* This routine is called whenever the stream state changes */
static void stream_state_callback(pa_stream *s, void *userdata) {
- assert(s);
+ pa_assert(s);
switch (pa_stream_get_state(s)) {
case PA_STREAM_CREATING:
@@ -154,130 +316,199 @@ static void stream_state_callback(pa_stream *s, void *userdata) {
break;
case PA_STREAM_READY:
+
if (verbose) {
const pa_buffer_attr *a;
-
- fprintf(stderr, "Stream successfully created.\n");
+ char cmt[PA_CHANNEL_MAP_SNPRINT_MAX], sst[PA_SAMPLE_SPEC_SNPRINT_MAX];
+
+ pa_log(_("Stream successfully created."));
if (!(a = pa_stream_get_buffer_attr(s)))
- fprintf(stderr, "pa_stream_get_buffer_attr() failed: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s))));
+ pa_log(_("pa_stream_get_buffer_attr() failed: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s))));
else {
if (mode == PLAYBACK)
- fprintf(stderr, "Buffer metrics: maxlength=%u, tlength=%u, prebuf=%u, minreq=%u\n", a->maxlength, a->tlength, a->prebuf, a->minreq);
+ pa_log(_("Buffer metrics: maxlength=%u, tlength=%u, prebuf=%u, minreq=%u"), a->maxlength, a->tlength, a->prebuf, a->minreq);
else {
- assert(mode == RECORD);
- fprintf(stderr, "Buffer metrics: maxlength=%u, fragsize=%u\n", a->maxlength, a->fragsize);
+ pa_assert(mode == RECORD);
+ pa_log(_("Buffer metrics: maxlength=%u, fragsize=%u"), a->maxlength, a->fragsize);
}
-
}
+ pa_log(_("Using sample spec '%s', channel map '%s'."),
+ pa_sample_spec_snprint(sst, sizeof(sst), pa_stream_get_sample_spec(s)),
+ pa_channel_map_snprint(cmt, sizeof(cmt), pa_stream_get_channel_map(s)));
+
+ pa_log(_("Connected to device %s (%u, %ssuspended)."),
+ pa_stream_get_device_name(s),
+ pa_stream_get_device_index(s),
+ pa_stream_is_suspended(s) ? "" : "not ");
}
-
+
break;
-
+
case PA_STREAM_FAILED:
default:
- fprintf(stderr, "Stream error: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s))));
+ pa_log(_("Stream error: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s))));
quit(1);
}
}
+static void stream_suspended_callback(pa_stream *s, void *userdata) {
+ pa_assert(s);
+
+ if (verbose) {
+ if (pa_stream_is_suspended(s))
+ pa_log(_("Stream device suspended.%s"), CLEAR_LINE);
+ else
+ pa_log(_("Stream device resumed.%s"), CLEAR_LINE);
+ }
+}
+
+static void stream_underflow_callback(pa_stream *s, void *userdata) {
+ pa_assert(s);
+
+ if (verbose)
+ pa_log(_("Stream underrun.%s"), CLEAR_LINE);
+}
+
+static void stream_overflow_callback(pa_stream *s, void *userdata) {
+ pa_assert(s);
+
+ if (verbose)
+ pa_log(_("Stream overrun.%s"), CLEAR_LINE);
+}
+
+static void stream_started_callback(pa_stream *s, void *userdata) {
+ pa_assert(s);
+
+ if (verbose)
+ pa_log(_("Stream started.%s"), CLEAR_LINE);
+}
+
+static void stream_moved_callback(pa_stream *s, void *userdata) {
+ pa_assert(s);
+
+ if (verbose)
+ pa_log(_("Stream moved to device %s (%u, %ssuspended).%s"), pa_stream_get_device_name(s), pa_stream_get_device_index(s), pa_stream_is_suspended(s) ? "" : _("not "), CLEAR_LINE);
+}
+
+static void stream_buffer_attr_callback(pa_stream *s, void *userdata) {
+ pa_assert(s);
+
+ if (verbose)
+ pa_log(_("Stream buffer attributes changed.%s"), CLEAR_LINE);
+}
+
+static void stream_event_callback(pa_stream *s, const char *name, pa_proplist *pl, void *userdata) {
+ char *t;
+
+ pa_assert(s);
+ pa_assert(name);
+ pa_assert(pl);
+
+ t = pa_proplist_to_string_sep(pl, ", ");
+ pa_log("Got event '%s', properties '%s'", name, t);
+ pa_xfree(t);
+}
+
/* This is called whenever the context status changes */
static void context_state_callback(pa_context *c, void *userdata) {
- assert(c);
+ pa_assert(c);
switch (pa_context_get_state(c)) {
case PA_CONTEXT_CONNECTING:
case PA_CONTEXT_AUTHORIZING:
case PA_CONTEXT_SETTING_NAME:
break;
-
+
case PA_CONTEXT_READY: {
- int r;
-
- assert(c && !stream);
+ pa_buffer_attr buffer_attr;
+
+ pa_assert(c);
+ pa_assert(!stream);
if (verbose)
- fprintf(stderr, "Connection established.\n");
+ pa_log(_("Connection established.%s"), CLEAR_LINE);
- if (!(stream = pa_stream_new(c, stream_name, &sample_spec, channel_map_set ? &channel_map : NULL))) {
- fprintf(stderr, "pa_stream_new() failed: %s\n", pa_strerror(pa_context_errno(c)));
+ if (!(stream = pa_stream_new_with_proplist(c, NULL, &sample_spec, &channel_map, proplist))) {
+ pa_log(_("pa_stream_new() failed: %s"), pa_strerror(pa_context_errno(c)));
goto fail;
}
pa_stream_set_state_callback(stream, stream_state_callback, NULL);
pa_stream_set_write_callback(stream, stream_write_callback, NULL);
pa_stream_set_read_callback(stream, stream_read_callback, NULL);
+ pa_stream_set_suspended_callback(stream, stream_suspended_callback, NULL);
+ pa_stream_set_moved_callback(stream, stream_moved_callback, NULL);
+ pa_stream_set_underflow_callback(stream, stream_underflow_callback, NULL);
+ pa_stream_set_overflow_callback(stream, stream_overflow_callback, NULL);
+ pa_stream_set_started_callback(stream, stream_started_callback, NULL);
+ pa_stream_set_event_callback(stream, stream_event_callback, NULL);
+ pa_stream_set_buffer_attr_callback(stream, stream_buffer_attr_callback, NULL);
+
+ pa_zero(buffer_attr);
+ buffer_attr.maxlength = (uint32_t) -1;
+ buffer_attr.prebuf = (uint32_t) -1;
+
+ if (latency_msec > 0) {
+ buffer_attr.fragsize = buffer_attr.tlength = pa_usec_to_bytes(latency_msec * PA_USEC_PER_MSEC, &sample_spec);
+ flags |= PA_STREAM_ADJUST_LATENCY;
+ } else if (latency > 0) {
+ buffer_attr.fragsize = buffer_attr.tlength = (uint32_t) latency;
+ flags |= PA_STREAM_ADJUST_LATENCY;
+ } else
+ buffer_attr.fragsize = buffer_attr.tlength = (uint32_t) -1;
+
+ if (process_time_msec > 0) {
+ buffer_attr.minreq = pa_usec_to_bytes(process_time_msec * PA_USEC_PER_MSEC, &sample_spec);
+ } else if (process_time > 0)
+ buffer_attr.minreq = (uint32_t) process_time;
+ else
+ buffer_attr.minreq = (uint32_t) -1;
if (mode == PLAYBACK) {
pa_cvolume cv;
- if ((r = pa_stream_connect_playback(stream, device, NULL, 0, pa_cvolume_set(&cv, sample_spec.channels, volume), NULL)) < 0) {
- fprintf(stderr, "pa_stream_connect_playback() failed: %s\n", pa_strerror(pa_context_errno(c)));
+ if (pa_stream_connect_playback(stream, device, &buffer_attr, flags, volume_is_set ? pa_cvolume_set(&cv, sample_spec.channels, volume) : NULL, NULL) < 0) {
+ pa_log(_("pa_stream_connect_playback() failed: %s"), pa_strerror(pa_context_errno(c)));
goto fail;
}
-
+
} else {
- if ((r = pa_stream_connect_record(stream, device, NULL, 0)) < 0) {
- fprintf(stderr, "pa_stream_connect_record() failed: %s\n", pa_strerror(pa_context_errno(c)));
+ if (pa_stream_connect_record(stream, device, &buffer_attr, flags) < 0) {
+ pa_log(_("pa_stream_connect_record() failed: %s"), pa_strerror(pa_context_errno(c)));
goto fail;
}
}
-
+
break;
}
-
+
case PA_CONTEXT_TERMINATED:
quit(0);
break;
case PA_CONTEXT_FAILED:
default:
- fprintf(stderr, "Connection failure: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c)));
goto fail;
}
return;
-
+
fail:
quit(1);
-
-}
-/* Connection draining complete */
-static void context_drain_complete(pa_context*c, void *userdata) {
- pa_context_disconnect(c);
-}
-
-/* Stream draining complete */
-static void stream_drain_complete(pa_stream*s, int success, void *userdata) {
- pa_operation *o;
-
- if (!success) {
- fprintf(stderr, "Failed to drain stream: %s\n", pa_strerror(pa_context_errno(context)));
- quit(1);
- }
-
- if (verbose)
- fprintf(stderr, "Playback stream drained.\n");
-
- pa_stream_disconnect(stream);
- pa_stream_unref(stream);
- stream = NULL;
-
- if (!(o = pa_context_drain(context, context_drain_complete, NULL)))
- pa_context_disconnect(context);
- else {
- if (verbose)
- fprintf(stderr, "Draining connection to server.\n");
- }
}
/* New data on STDIN **/
static void stdin_callback(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
size_t l, w = 0;
ssize_t r;
- assert(a == mainloop_api && e && stdio_event == e);
+
+ pa_assert(a == mainloop_api);
+ pa_assert(e);
+ pa_assert(stdio_event == e);
if (buffer) {
mainloop_api->io_enable(stdio_event, PA_IO_EVENT_NULL);
@@ -286,25 +517,18 @@ static void stdin_callback(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_even
if (!stream || pa_stream_get_state(stream) != PA_STREAM_READY || !(l = w = pa_stream_writable_size(stream)))
l = 4096;
-
+
buffer = pa_xmalloc(l);
if ((r = read(fd, buffer, l)) <= 0) {
if (r == 0) {
- pa_operation *o;
-
if (verbose)
- fprintf(stderr, "Got EOF.\n");
-
- if (!(o = pa_stream_drain(stream, stream_drain_complete, NULL))) {
- fprintf(stderr, "pa_stream_drain(): %s\n", pa_strerror(pa_context_errno(context)));
- quit(1);
- return;
- }
+ pa_log(_("Got EOF."));
+
+ start_drain();
- pa_operation_unref(o);
} else {
- fprintf(stderr, "read() failed: %s\n", strerror(errno));
+ pa_log(_("read() failed: %s"), strerror(errno));
quit(1);
}
@@ -313,7 +537,7 @@ static void stdin_callback(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_even
return;
}
- buffer_length = r;
+ buffer_length = (uint32_t) r;
buffer_index = 0;
if (w)
@@ -323,17 +547,20 @@ static void stdin_callback(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_even
/* Some data may be written to STDOUT */
static void stdout_callback(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
ssize_t r;
- assert(a == mainloop_api && e && stdio_event == e);
+
+ pa_assert(a == mainloop_api);
+ pa_assert(e);
+ pa_assert(stdio_event == e);
if (!buffer) {
mainloop_api->io_enable(stdio_event, PA_IO_EVENT_NULL);
return;
}
- assert(buffer_length);
-
+ pa_assert(buffer_length);
+
if ((r = write(fd, (uint8_t*) buffer+buffer_index, buffer_length)) <= 0) {
- fprintf(stderr, "write() failed: %s\n", strerror(errno));
+ pa_log(_("write() failed: %s"), strerror(errno));
quit(1);
mainloop_api->io_free(stdio_event);
@@ -341,8 +568,8 @@ static void stdout_callback(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_eve
return;
}
- buffer_length -= r;
- buffer_index += r;
+ buffer_length -= (uint32_t) r;
+ buffer_index += (uint32_t) r;
if (!buffer_length) {
pa_xfree(buffer);
@@ -354,76 +581,92 @@ static void stdout_callback(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_eve
/* UNIX signal to quit recieved */
static void exit_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
if (verbose)
- fprintf(stderr, "Got signal, exiting.\n");
+ pa_log(_("Got signal, exiting."));
quit(0);
}
/* Show the current latency */
static void stream_update_timing_callback(pa_stream *s, int success, void *userdata) {
- pa_usec_t latency, usec;
+ pa_usec_t l, usec;
int negative = 0;
-
- assert(s);
+
+ pa_assert(s);
if (!success ||
pa_stream_get_time(s, &usec) < 0 ||
- pa_stream_get_latency(s, &latency, &negative) < 0) {
- fprintf(stderr, "Failed to get latency: %s\n", pa_strerror(pa_context_errno(context)));
+ pa_stream_get_latency(s, &l, &negative) < 0) {
+ pa_log(_("Failed to get latency: %s"), pa_strerror(pa_context_errno(context)));
quit(1);
return;
}
- fprintf(stderr, "Time: %0.3f sec; Latency: %0.0f usec. \r",
+ fprintf(stderr, _("Time: %0.3f sec; Latency: %0.0f usec."),
(float) usec / 1000000,
- (float) latency * (negative?-1:1));
+ (float) l * (negative?-1.0f:1.0f));
+ fprintf(stderr, " \r");
}
+#ifdef SIGUSR1
/* Someone requested that the latency is shown */
static void sigusr1_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
if (!stream)
return;
-
+
pa_operation_unref(pa_stream_update_timing_info(stream, stream_update_timing_callback, NULL));
}
+#endif
-static void time_event_callback(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) {
- struct timeval next;
-
+static void time_event_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
if (stream && pa_stream_get_state(stream) == PA_STREAM_READY) {
pa_operation *o;
if (!(o = pa_stream_update_timing_info(stream, stream_update_timing_callback, NULL)))
- fprintf(stderr, "pa_stream_update_timing_info() failed: %s\n", pa_strerror(pa_context_errno(context)));
+ pa_log(_("pa_stream_update_timing_info() failed: %s"), pa_strerror(pa_context_errno(context)));
else
pa_operation_unref(o);
}
- pa_gettimeofday(&next);
- pa_timeval_add(&next, TIME_EVENT_USEC);
-
- m->time_restart(e, &next);
+ pa_context_rttime_restart(context, e, pa_rtclock_now() + TIME_EVENT_USEC);
}
static void help(const char *argv0) {
- printf("%s [options]\n\n"
- " -h, --help Show this help\n"
- " --version Show version\n\n"
- " -r, --record Create a connection for recording\n"
- " -p, --playback Create a connection for playback\n\n"
- " -v, --verbose Enable verbose operations\n\n"
- " -s, --server=SERVER The name of the server to connect to\n"
- " -d, --device=DEVICE The name of the sink/source to connect to\n"
- " -n, --client-name=NAME How to call this client on the server\n"
- " --stream-name=NAME How to call this stream on the server\n"
- " --volume=VOLUME Specify the initial (linear) volume in range 0...65536\n"
- " --rate=SAMPLERATE The sample rate in Hz (defaults to 44100)\n"
- " --format=SAMPLEFORMAT The sample type, one of s16le, s16be, u8, float32le,\n"
- " float32be, ulaw, alaw (defaults to s16ne)\n"
- " --channels=CHANNELS The number of channels, 1 for mono, 2 for stereo\n"
- " (defaults to 2)\n"
- " --channel-map=CHANNELMAP Channel map to use instead of the default\n",
- argv0);
+ printf(_("%s [options]\n\n"
+ " -h, --help Show this help\n"
+ " --version Show version\n\n"
+ " -r, --record Create a connection for recording\n"
+ " -p, --playback Create a connection for playback\n\n"
+ " -v, --verbose Enable verbose operations\n\n"
+ " -s, --server=SERVER The name of the server to connect to\n"
+ " -d, --device=DEVICE The name of the sink/source to connect to\n"
+ " -n, --client-name=NAME How to call this client on the server\n"
+ " --stream-name=NAME How to call this stream on the server\n"
+ " --volume=VOLUME Specify the initial (linear) volume in range 0...65536\n"
+ " --rate=SAMPLERATE The sample rate in Hz (defaults to 44100)\n"
+ " --format=SAMPLEFORMAT The sample type, one of s16le, s16be, u8, float32le,\n"
+ " float32be, ulaw, alaw, s32le, s32be, s24le, s24be,\n"
+ " s24-32le, s24-32be (defaults to s16ne)\n"
+ " --channels=CHANNELS The number of channels, 1 for mono, 2 for stereo\n"
+ " (defaults to 2)\n"
+ " --channel-map=CHANNELMAP Channel map to use instead of the default\n"
+ " --fix-format Take the sample format from the sink the stream is\n"
+ " being connected to.\n"
+ " --fix-rate Take the sampling rate from the sink the stream is\n"
+ " being connected to.\n"
+ " --fix-channels Take the number of channels and the channel map\n"
+ " from the sink the stream is being connected to.\n"
+ " --no-remix Don't upmix or downmix channels.\n"
+ " --no-remap Map channels by index instead of name.\n"
+ " --latency=BYTES Request the specified latency in bytes.\n"
+ " --process-time=BYTES Request the specified process time per request in bytes.\n"
+ " --latency-msec=MSEC Request the specified latency in msec.\n"
+ " --process-time-msec=MSEC Request the specified process time per request in msec.\n"
+ " --property=PROPERTY=VALUE Set the specified property to the specified value.\n"
+ " --raw Record/play raw PCM data.\n"
+ " --passthrough passthrough data \n"
+ " --file-format[=FFORMAT] Record/play formatted PCM data.\n"
+ " --list-file-formats List available file formats.\n")
+ , argv0);
}
enum {
@@ -434,41 +677,81 @@ enum {
ARG_SAMPLEFORMAT,
ARG_CHANNELS,
ARG_CHANNELMAP,
+ ARG_FIX_FORMAT,
+ ARG_FIX_RATE,
+ ARG_FIX_CHANNELS,
+ ARG_NO_REMAP,
+ ARG_NO_REMIX,
+ ARG_LATENCY,
+ ARG_PROCESS_TIME,
+ ARG_RAW,
+ ARG_PASSTHROUGH,
+ ARG_PROPERTY,
+ ARG_FILE_FORMAT,
+ ARG_LIST_FILE_FORMATS,
+ ARG_LATENCY_MSEC,
+ ARG_PROCESS_TIME_MSEC
};
int main(int argc, char *argv[]) {
pa_mainloop* m = NULL;
- int ret = 1, r, c;
+ int ret = 1, c;
char *bn, *server = NULL;
pa_time_event *time_event = NULL;
+ const char *filename = NULL;
static const struct option long_options[] = {
- {"record", 0, NULL, 'r'},
- {"playback", 0, NULL, 'p'},
- {"device", 1, NULL, 'd'},
- {"server", 1, NULL, 's'},
- {"client-name", 1, NULL, 'n'},
- {"stream-name", 1, NULL, ARG_STREAM_NAME},
- {"version", 0, NULL, ARG_VERSION},
- {"help", 0, NULL, 'h'},
- {"verbose", 0, NULL, 'v'},
- {"volume", 1, NULL, ARG_VOLUME},
- {"rate", 1, NULL, ARG_SAMPLERATE},
- {"format", 1, NULL, ARG_SAMPLEFORMAT},
- {"channels", 1, NULL, ARG_CHANNELS},
- {"channel-map", 1, NULL, ARG_CHANNELMAP},
- {NULL, 0, NULL, 0}
+ {"record", 0, NULL, 'r'},
+ {"playback", 0, NULL, 'p'},
+ {"device", 1, NULL, 'd'},
+ {"server", 1, NULL, 's'},
+ {"client-name", 1, NULL, 'n'},
+ {"stream-name", 1, NULL, ARG_STREAM_NAME},
+ {"version", 0, NULL, ARG_VERSION},
+ {"help", 0, NULL, 'h'},
+ {"verbose", 0, NULL, 'v'},
+ {"volume", 1, NULL, ARG_VOLUME},
+ {"rate", 1, NULL, ARG_SAMPLERATE},
+ {"format", 1, NULL, ARG_SAMPLEFORMAT},
+ {"channels", 1, NULL, ARG_CHANNELS},
+ {"channel-map", 1, NULL, ARG_CHANNELMAP},
+ {"fix-format", 0, NULL, ARG_FIX_FORMAT},
+ {"fix-rate", 0, NULL, ARG_FIX_RATE},
+ {"fix-channels", 0, NULL, ARG_FIX_CHANNELS},
+ {"no-remap", 0, NULL, ARG_NO_REMAP},
+ {"no-remix", 0, NULL, ARG_NO_REMIX},
+ {"latency", 1, NULL, ARG_LATENCY},
+ {"process-time", 1, NULL, ARG_PROCESS_TIME},
+ {"property", 1, NULL, ARG_PROPERTY},
+ {"raw", 0, NULL, ARG_RAW},
+ {"passthrough", 0, NULL, ARG_PASSTHROUGH},
+ {"file-format", 2, NULL, ARG_FILE_FORMAT},
+ {"list-file-formats", 0, NULL, ARG_LIST_FILE_FORMATS},
+ {"latency-msec", 1, NULL, ARG_LATENCY_MSEC},
+ {"process-time-msec", 1, NULL, ARG_PROCESS_TIME_MSEC},
+ {NULL, 0, NULL, 0}
};
- if (!(bn = strrchr(argv[0], '/')))
- bn = argv[0];
- else
- bn++;
+ setlocale(LC_ALL, "");
+ bindtextdomain(GETTEXT_PACKAGE, PULSE_LOCALEDIR);
+
+ bn = pa_path_get_filename(argv[0]);
- if (strstr(bn, "rec") || strstr(bn, "mon"))
+ if (strstr(bn, "play")) {
+ mode = PLAYBACK;
+ raw = FALSE;
+ } else if (strstr(bn, "record")) {
mode = RECORD;
- else if (strstr(bn, "cat") || strstr(bn, "play"))
+ raw = FALSE;
+ } else if (strstr(bn, "cat")) {
mode = PLAYBACK;
+ raw = TRUE;
+ } if (strstr(bn, "rec") || strstr(bn, "mon")) {
+ mode = RECORD;
+ raw = TRUE;
+ }
+
+ proplist = pa_proplist_new();
while ((c = getopt_long(argc, argv, "rpd:s:n:hv", long_options, NULL)) != -1) {
@@ -477,9 +760,14 @@ int main(int argc, char *argv[]) {
help(bn);
ret = 0;
goto quit;
-
+
case ARG_VERSION:
- printf("pacat "PACKAGE_VERSION"\nCompiled with libpulse %s\nLinked with libpulse %s\n", pa_get_headers_version(), pa_get_library_version());
+ printf(_("pacat %s\n"
+ "Compiled with libpulse %s\n"
+ "Linked with libpulse %s\n"),
+ PACKAGE_VERSION,
+ pa_get_headers_version(),
+ pa_get_library_version());
ret = 0;
goto quit;
@@ -501,15 +789,35 @@ int main(int argc, char *argv[]) {
server = pa_xstrdup(optarg);
break;
- case 'n':
- pa_xfree(client_name);
- client_name = pa_xstrdup(optarg);
+ case 'n': {
+ char *t;
+
+ if (!(t = pa_locale_to_utf8(optarg)) ||
+ pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, t) < 0) {
+
+ pa_log(_("Invalid client name '%s'"), t ? t : optarg);
+ pa_xfree(t);
+ goto quit;
+ }
+
+ pa_xfree(t);
break;
+ }
+
+ case ARG_STREAM_NAME: {
+ char *t;
- case ARG_STREAM_NAME:
- pa_xfree(stream_name);
- stream_name = pa_xstrdup(optarg);
+ if (!(t = pa_locale_to_utf8(optarg)) ||
+ pa_proplist_sets(proplist, PA_PROP_MEDIA_NAME, t) < 0) {
+
+ pa_log(_("Invalid stream name '%s'"), t ? t : optarg);
+ pa_xfree(t);
+ goto quit;
+ }
+
+ pa_xfree(t);
break;
+ }
case 'v':
verbose = 1;
@@ -517,139 +825,320 @@ int main(int argc, char *argv[]) {
case ARG_VOLUME: {
int v = atoi(optarg);
- volume = v < 0 ? 0 : v;
+ volume = v < 0 ? 0U : (pa_volume_t) v;
+ volume_is_set = TRUE;
break;
}
- case ARG_CHANNELS:
- sample_spec.channels = atoi(optarg);
+ case ARG_CHANNELS:
+ sample_spec.channels = (uint8_t) atoi(optarg);
+ sample_spec_set = TRUE;
break;
case ARG_SAMPLEFORMAT:
sample_spec.format = pa_parse_sample_format(optarg);
+ sample_spec_set = TRUE;
break;
case ARG_SAMPLERATE:
- sample_spec.rate = atoi(optarg);
+ sample_spec.rate = (uint32_t) atoi(optarg);
+ sample_spec_set = TRUE;
break;
case ARG_CHANNELMAP:
if (!pa_channel_map_parse(&channel_map, optarg)) {
- fprintf(stderr, "Invalid channel map\n");
+ pa_log(_("Invalid channel map '%s'"), optarg);
goto quit;
}
- channel_map_set = 1;
+ channel_map_set = TRUE;
break;
-
+
+ case ARG_FIX_CHANNELS:
+ flags |= PA_STREAM_FIX_CHANNELS;
+ break;
+
+ case ARG_FIX_RATE:
+ flags |= PA_STREAM_FIX_RATE;
+ break;
+
+ case ARG_FIX_FORMAT:
+ flags |= PA_STREAM_FIX_FORMAT;
+ break;
+
+ case ARG_NO_REMIX:
+ flags |= PA_STREAM_NO_REMIX_CHANNELS;
+ break;
+
+ case ARG_NO_REMAP:
+ flags |= PA_STREAM_NO_REMAP_CHANNELS;
+ break;
+
+ case ARG_LATENCY:
+ if (((latency = (size_t) atoi(optarg))) <= 0) {
+ pa_log(_("Invalid latency specification '%s'"), optarg);
+ goto quit;
+ }
+ break;
+
+ case ARG_PROCESS_TIME:
+ if (((process_time = (size_t) atoi(optarg))) <= 0) {
+ pa_log(_("Invalid process time specification '%s'"), optarg);
+ goto quit;
+ }
+ break;
+
+ case ARG_LATENCY_MSEC:
+ if (((latency_msec = (int32_t) atoi(optarg))) <= 0) {
+ pa_log(_("Invalid latency specification '%s'"), optarg);
+ goto quit;
+ }
+ break;
+
+ case ARG_PROCESS_TIME_MSEC:
+ if (((process_time_msec = (int32_t) atoi(optarg))) <= 0) {
+ pa_log(_("Invalid process time specification '%s'"), optarg);
+ goto quit;
+ }
+ break;
+
+ case ARG_PROPERTY: {
+ char *t;
+
+ if (!(t = pa_locale_to_utf8(optarg)) ||
+ pa_proplist_setp(proplist, t) < 0) {
+
+ pa_xfree(t);
+ pa_log(_("Invalid property '%s'"), optarg);
+ goto quit;
+ }
+
+ pa_xfree(t);
+ break;
+ }
+
+ case ARG_RAW:
+ raw = TRUE;
+ break;
+
+ case ARG_PASSTHROUGH:
+ flags |= PA_STREAM_PASSTHROUGH;
+ break;
+
+ case ARG_FILE_FORMAT:
+ if (optarg) {
+ if ((file_format = pa_sndfile_format_from_string(optarg)) < 0) {
+ pa_log(_("Unknown file format %s."), optarg);
+ goto quit;
+ }
+ }
+
+ raw = FALSE;
+ break;
+
+ case ARG_LIST_FILE_FORMATS:
+ pa_sndfile_dump_formats();
+ ret = 0;
+ goto quit;
+
default:
goto quit;
}
}
if (!pa_sample_spec_valid(&sample_spec)) {
- fprintf(stderr, "Invalid sample specification\n");
+ pa_log(_("Invalid sample specification"));
goto quit;
}
- if (channel_map_set && channel_map.channels != sample_spec.channels) {
- fprintf(stderr, "Channel map doesn't match sample specification\n");
+ if (optind+1 == argc) {
+ int fd;
+
+ filename = argv[optind];
+
+ if ((fd = pa_open_cloexec(argv[optind], mode == PLAYBACK ? O_RDONLY : O_WRONLY|O_TRUNC|O_CREAT, 0666)) < 0) {
+ pa_log(_("open(): %s"), strerror(errno));
+ goto quit;
+ }
+
+ if (dup2(fd, mode == PLAYBACK ? STDIN_FILENO : STDOUT_FILENO) < 0) {
+ pa_log(_("dup2(): %s"), strerror(errno));
+ goto quit;
+ }
+
+ pa_close(fd);
+
+ } else if (optind+1 <= argc) {
+ pa_log(_("Too many arguments."));
goto quit;
}
-
- if (verbose) {
- char t[PA_SAMPLE_SPEC_SNPRINT_MAX];
- pa_sample_spec_snprint(t, sizeof(t), &sample_spec);
- fprintf(stderr, "Opening a %s stream with sample specification '%s'.\n", mode == RECORD ? "recording" : "playback", t);
- }
- if (!(optind >= argc)) {
- if (optind+1 == argc) {
- int fd;
-
- if ((fd = open(argv[optind], mode == PLAYBACK ? O_RDONLY : O_WRONLY|O_TRUNC|O_CREAT, 0666)) < 0) {
- fprintf(stderr, "open(): %s\n", strerror(errno));
+ if (!raw) {
+ SF_INFO sfi;
+ pa_zero(sfi);
+
+ if (mode == RECORD) {
+ /* This might patch up the sample spec */
+ if (pa_sndfile_write_sample_spec(&sfi, &sample_spec) < 0) {
+ pa_log(_("Failed to generate sample specification for file."));
goto quit;
}
-
- if (dup2(fd, mode == PLAYBACK ? 0 : 1) < 0) {
- fprintf(stderr, "dup2(): %s\n", strerror(errno));
- goto quit;
+
+ if (file_format <= 0) {
+ char *extension;
+ if (filename && (extension = strrchr(filename, '.')))
+ file_format = pa_sndfile_format_from_string(extension+1);
+ if (file_format <= 0)
+ file_format = SF_FORMAT_WAV;
+ /* Transparently upgrade classic .wav to wavex for multichannel audio */
+ if (file_format == SF_FORMAT_WAV &&
+ (sample_spec.channels > 2 ||
+ (channel_map_set &&
+ !(sample_spec.channels == 1 && channel_map.map[0] == PA_CHANNEL_POSITION_MONO) &&
+ !(sample_spec.channels == 2 && channel_map.map[0] == PA_CHANNEL_POSITION_LEFT
+ && channel_map.map[1] == PA_CHANNEL_POSITION_RIGHT))))
+ file_format = SF_FORMAT_WAVEX;
}
-
- close(fd);
- if (!stream_name)
- stream_name = pa_xstrdup(argv[optind]);
-
- } else {
- fprintf(stderr, "Too many arguments.\n");
+ sfi.format |= file_format;
+ }
+
+ if (!(sndfile = sf_open_fd(mode == RECORD ? STDOUT_FILENO : STDIN_FILENO,
+ mode == RECORD ? SFM_WRITE : SFM_READ,
+ &sfi, 0))) {
+ pa_log(_("Failed to open audio file."));
goto quit;
}
+
+ if (mode == PLAYBACK) {
+ if (sample_spec_set)
+ pa_log(_("Warning: specified sample specification will be overwritten with specification from file."));
+
+ if (pa_sndfile_read_sample_spec(sndfile, &sample_spec) < 0) {
+ pa_log(_("Failed to determine sample specification from file."));
+ goto quit;
+ }
+ sample_spec_set = TRUE;
+
+ if (!channel_map_set) {
+ /* Allow the user to overwrite the channel map on the command line */
+ if (pa_sndfile_read_channel_map(sndfile, &channel_map) < 0) {
+ if (sample_spec.channels > 2)
+ pa_log(_("Warning: Failed to determine channel map from file."));
+ } else
+ channel_map_set = TRUE;
+ }
+ }
+ }
+
+ if (!channel_map_set)
+ pa_channel_map_init_extend(&channel_map, sample_spec.channels, PA_CHANNEL_MAP_DEFAULT);
+
+ if (!pa_channel_map_compatible(&channel_map, &sample_spec)) {
+ pa_log(_("Channel map doesn't match sample specification"));
+ goto quit;
}
- if (!client_name)
- client_name = pa_xstrdup(bn);
+ if (!raw) {
+ pa_proplist *sfp;
+
+ if (mode == PLAYBACK)
+ readf_function = pa_sndfile_readf_function(&sample_spec);
+ else {
+ if (pa_sndfile_write_channel_map(sndfile, &channel_map) < 0)
+ pa_log(_("Warning: failed to write channel map to file."));
+
+ writef_function = pa_sndfile_writef_function(&sample_spec);
+ }
+
+ /* Fill in libsndfile prop list data */
+ sfp = pa_proplist_new();
+ pa_sndfile_init_proplist(sndfile, sfp);
+ pa_proplist_update(proplist, PA_UPDATE_MERGE, sfp);
+ pa_proplist_free(sfp);
+ }
+
+ if (verbose) {
+ char tss[PA_SAMPLE_SPEC_SNPRINT_MAX], tcm[PA_CHANNEL_MAP_SNPRINT_MAX];
+
+ pa_log(_("Opening a %s stream with sample specification '%s' and channel map '%s'."),
+ mode == RECORD ? _("recording") : _("playback"),
+ pa_sample_spec_snprint(tss, sizeof(tss), &sample_spec),
+ pa_channel_map_snprint(tcm, sizeof(tcm), &channel_map));
+ }
- if (!stream_name)
- stream_name = pa_xstrdup(client_name);
+ /* Fill in client name if none was set */
+ if (!pa_proplist_contains(proplist, PA_PROP_APPLICATION_NAME)) {
+ char *t;
+
+ if ((t = pa_locale_to_utf8(bn))) {
+ pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, t);
+ pa_xfree(t);
+ }
+ }
+
+ /* Fill in media name if none was set */
+ if (!pa_proplist_contains(proplist, PA_PROP_MEDIA_NAME)) {
+ const char *t;
+
+ if ((t = filename) ||
+ (t = pa_proplist_gets(proplist, PA_PROP_APPLICATION_NAME)))
+ pa_proplist_sets(proplist, PA_PROP_MEDIA_NAME, t);
+ }
/* Set up a new main loop */
if (!(m = pa_mainloop_new())) {
- fprintf(stderr, "pa_mainloop_new() failed.\n");
+ pa_log(_("pa_mainloop_new() failed."));
goto quit;
}
mainloop_api = pa_mainloop_get_api(m);
- r = pa_signal_init(mainloop_api);
- assert(r == 0);
+ pa_assert_se(pa_signal_init(mainloop_api) == 0);
pa_signal_new(SIGINT, exit_signal_callback, NULL);
pa_signal_new(SIGTERM, exit_signal_callback, NULL);
#ifdef SIGUSR1
pa_signal_new(SIGUSR1, sigusr1_signal_callback, NULL);
#endif
-#ifdef SIGPIPE
- signal(SIGPIPE, SIG_IGN);
-#endif
-
- if (!(stdio_event = mainloop_api->io_new(mainloop_api,
- mode == PLAYBACK ? STDIN_FILENO : STDOUT_FILENO,
- mode == PLAYBACK ? PA_IO_EVENT_INPUT : PA_IO_EVENT_OUTPUT,
- mode == PLAYBACK ? stdin_callback : stdout_callback, NULL))) {
- fprintf(stderr, "io_new() failed.\n");
- goto quit;
+ pa_disable_sigpipe();
+
+ if (raw) {
+ if (!(stdio_event = mainloop_api->io_new(mainloop_api,
+ mode == PLAYBACK ? STDIN_FILENO : STDOUT_FILENO,
+ mode == PLAYBACK ? PA_IO_EVENT_INPUT : PA_IO_EVENT_OUTPUT,
+ mode == PLAYBACK ? stdin_callback : stdout_callback, NULL))) {
+ pa_log(_("io_new() failed."));
+ goto quit;
+ }
}
/* Create a new connection context */
- if (!(context = pa_context_new(mainloop_api, client_name))) {
- fprintf(stderr, "pa_context_new() failed.\n");
+ if (!(context = pa_context_new_with_proplist(mainloop_api, NULL, proplist))) {
+ pa_log(_("pa_context_new() failed."));
goto quit;
}
pa_context_set_state_callback(context, context_state_callback, NULL);
/* Connect the context */
- pa_context_connect(context, server, 0, NULL);
+ if (pa_context_connect(context, server, 0, NULL) < 0) {
+ pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context)));
+ goto quit;
+ }
if (verbose) {
- struct timeval tv;
-
- pa_gettimeofday(&tv);
- pa_timeval_add(&tv, TIME_EVENT_USEC);
-
- if (!(time_event = mainloop_api->time_new(mainloop_api, &tv, time_event_callback, NULL))) {
- fprintf(stderr, "time_new() failed.\n");
+ if (!(time_event = pa_context_rttime_new(context, pa_rtclock_now() + TIME_EVENT_USEC, time_event_callback, NULL))) {
+ pa_log(_("pa_context_rttime_new() failed."));
goto quit;
}
}
/* Run the main loop */
if (pa_mainloop_run(m, &ret) < 0) {
- fprintf(stderr, "pa_mainloop_run() failed.\n");
+ pa_log(_("pa_mainloop_run() failed."));
goto quit;
}
-
+
quit:
if (stream)
pa_stream_unref(stream);
@@ -658,15 +1147,15 @@ quit:
pa_context_unref(context);
if (stdio_event) {
- assert(mainloop_api);
+ pa_assert(mainloop_api);
mainloop_api->io_free(stdio_event);
}
if (time_event) {
- assert(mainloop_api);
+ pa_assert(mainloop_api);
mainloop_api->time_free(time_event);
}
-
+
if (m) {
pa_signal_done();
pa_mainloop_free(m);
@@ -676,8 +1165,12 @@ quit:
pa_xfree(server);
pa_xfree(device);
- pa_xfree(client_name);
- pa_xfree(stream_name);
-
+
+ if (sndfile)
+ sf_close(sndfile);
+
+ if (proplist)
+ pa_proplist_free(proplist);
+
return ret;
}
diff --git a/src/utils/pacmd.c b/src/utils/pacmd.c
index fe8038e0..f0779802 100644
--- a/src/utils/pacmd.c
+++ b/src/utils/pacmd.c
@@ -1,18 +1,18 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -25,162 +25,240 @@
#include <assert.h>
#include <signal.h>
-#include <sys/select.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/un.h>
+#include <locale.h>
-#include <pulse/error.h>
#include <pulse/util.h>
+#include <pulse/xmalloc.h>
+#include <pulse/i18n.h>
+#include <pulsecore/poll.h>
+#include <pulsecore/macro.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
#include <pulsecore/pid.h>
-int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char*argv[]) {
- pid_t pid ;
+int main(int argc, char*argv[]) {
+ pid_t pid;
int fd = -1;
int ret = 1, i;
struct sockaddr_un sa;
- char ibuf[256], obuf[256];
+ char ibuf[PIPE_BUF], obuf[PIPE_BUF];
size_t ibuf_index, ibuf_length, obuf_index, obuf_length;
- fd_set ifds, ofds;
+ char *cli;
+ pa_bool_t ibuf_eof, obuf_eof, ibuf_closed, obuf_closed;
+ struct pollfd pollfd[3];
+ struct pollfd *watch_socket, *watch_stdin, *watch_stdout;
+
+ int stdin_type = 0, stdout_type = 0, fd_type = 0;
- if (pa_pid_file_check_running(&pid) < 0) {
- pa_log(__FILE__": no PulseAudio daemon running");
+ setlocale(LC_ALL, "");
+ bindtextdomain(GETTEXT_PACKAGE, PULSE_LOCALEDIR);
+
+ if (pa_pid_file_check_running(&pid, "pulseaudio") < 0) {
+ pa_log(_("No PulseAudio daemon running, or not running as session daemon."));
goto fail;
}
- if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
- pa_log(__FILE__": socket(PF_UNIX, SOCK_STREAM, 0): %s", strerror(errno));
+ if ((fd = pa_socket_cloexec(PF_UNIX, SOCK_STREAM, 0)) < 0) {
+ pa_log(_("socket(PF_UNIX, SOCK_STREAM, 0): %s"), strerror(errno));
goto fail;
}
- memset(&sa, 0, sizeof(sa));
+ pa_zero(sa);
sa.sun_family = AF_UNIX;
- pa_runtime_path("cli", sa.sun_path, sizeof(sa.sun_path));
+
+ if (!(cli = pa_runtime_path("cli")))
+ goto fail;
+
+ pa_strlcpy(sa.sun_path, cli, sizeof(sa.sun_path));
+ pa_xfree(cli);
for (i = 0; i < 5; i++) {
int r;
-
+
if ((r = connect(fd, (struct sockaddr*) &sa, sizeof(sa))) < 0 && (errno != ECONNREFUSED && errno != ENOENT)) {
- pa_log(__FILE__": connect(): %s", strerror(errno));
+ pa_log(_("connect(): %s"), strerror(errno));
goto fail;
}
-
+
if (r >= 0)
break;
- if (pa_pid_file_kill(SIGUSR2, NULL) < 0) {
- pa_log(__FILE__": failed to kill PulseAudio daemon.");
+ if (pa_pid_file_kill(SIGUSR2, NULL, "pulseaudio") < 0) {
+ pa_log(_("Failed to kill PulseAudio daemon."));
goto fail;
}
- pa_msleep(50);
+ pa_msleep(300);
}
if (i >= 5) {
- pa_log(__FILE__": daemon not responding.");
+ pa_log(_("Daemon not responding."));
goto fail;
}
ibuf_index = ibuf_length = obuf_index = obuf_length = 0;
+ ibuf_eof = obuf_eof = ibuf_closed = obuf_closed = FALSE;
+ if (argc > 1) {
+ for (i = 1; i < argc; i++) {
+ size_t k;
- FD_ZERO(&ifds);
- FD_SET(0, &ifds);
- FD_SET(fd, &ifds);
+ k = PA_MIN(sizeof(ibuf) - ibuf_length, strlen(argv[i]));
+ memcpy(ibuf + ibuf_length, argv[i], k);
+ ibuf_length += k;
+
+ if (ibuf_length < sizeof(ibuf)) {
+ ibuf[ibuf_length] = i < argc-1 ? ' ' : '\n';
+ ibuf_length++;
+ }
+ }
+
+ ibuf_eof = TRUE;
+ }
- FD_ZERO(&ofds);
-
for (;;) {
- if (select(FD_SETSIZE, &ifds, &ofds, NULL, NULL) < 0) {
- pa_log(__FILE__": select(): %s", strerror(errno));
- goto fail;
+ struct pollfd *p;
+
+ if (ibuf_eof &&
+ obuf_eof &&
+ ibuf_length <= 0 &&
+ obuf_length <= 0)
+ break;
+
+ if (ibuf_length <= 0 && ibuf_eof && !ibuf_closed) {
+ shutdown(fd, SHUT_WR);
+ ibuf_closed = TRUE;
}
- if (FD_ISSET(0, &ifds)) {
- ssize_t r;
- assert(!ibuf_length);
-
- if ((r = read(0, ibuf, sizeof(ibuf))) <= 0) {
- if (r == 0)
- break;
-
- pa_log(__FILE__": read(): %s", strerror(errno));
- goto fail;
- }
-
- ibuf_length = (size_t) r;
- ibuf_index = 0;
+ if (obuf_length <= 0 && obuf_eof && !obuf_closed) {
+ shutdown(fd, SHUT_RD);
+ obuf_closed = TRUE;
}
-
- if (FD_ISSET(fd, &ifds)) {
- ssize_t r;
- assert(!obuf_length);
-
- if ((r = read(fd, obuf, sizeof(obuf))) <= 0) {
- if (r == 0)
- break;
-
- pa_log(__FILE__": read(): %s", strerror(errno));
- goto fail;
- }
- obuf_length = (size_t) r;
- obuf_index = 0;
+ pa_zero(pollfd);
+
+ p = pollfd;
+
+ if (ibuf_length > 0 || (!obuf_eof && obuf_length <= 0)) {
+ watch_socket = p++;
+ watch_socket->fd = fd;
+ watch_socket->events =
+ (ibuf_length > 0 ? POLLOUT : 0) |
+ (!obuf_eof && obuf_length <= 0 ? POLLIN : 0);
+ } else
+ watch_socket = NULL;
+
+ if (!ibuf_eof && ibuf_length <= 0) {
+ watch_stdin = p++;
+ watch_stdin->fd = STDIN_FILENO;
+ watch_stdin->events = POLLIN;
+ } else
+ watch_stdin = NULL;
+
+ if (obuf_length > 0) {
+ watch_stdout = p++;
+ watch_stdout->fd = STDOUT_FILENO;
+ watch_stdout->events = POLLOUT;
+ } else
+ watch_stdout = NULL;
+
+ if (pa_poll(pollfd, p-pollfd, -1) < 0) {
+
+ if (errno == EINTR)
+ continue;
+
+ pa_log(_("poll(): %s"), strerror(errno));
+ goto fail;
}
- if (FD_ISSET(1, &ofds)) {
- ssize_t r;
- assert(obuf_length);
-
- if ((r = write(1, obuf + obuf_index, obuf_length)) < 0) {
- pa_log(__FILE__": write(): %s", strerror(errno));
- goto fail;
- }
-
- obuf_length -= (size_t) r;
- obuf_index += obuf_index;
+ if (watch_stdin) {
+ if (watch_stdin->revents & POLLIN) {
+ ssize_t r;
+ pa_assert(ibuf_length <= 0);
+ if ((r = pa_read(STDIN_FILENO, ibuf, sizeof(ibuf), &stdin_type)) <= 0) {
+ if (r < 0) {
+ pa_log(_("read(): %s"), strerror(errno));
+ goto fail;
+ }
+
+ ibuf_eof = TRUE;
+ } else {
+ ibuf_length = (size_t) r;
+ ibuf_index = 0;
+ }
+ } else if (watch_stdin->revents & POLLHUP)
+ ibuf_eof = TRUE;
}
- if (FD_ISSET(fd, &ofds)) {
- ssize_t r;
- assert(ibuf_length);
-
- if ((r = write(fd, ibuf + ibuf_index, ibuf_length)) < 0) {
- pa_log(__FILE__": write(): %s", strerror(errno));
- goto fail;
- }
-
- ibuf_length -= (size_t) r;
- ibuf_index += obuf_index;
+ if (watch_socket) {
+ if (watch_socket->revents & POLLIN) {
+ ssize_t r;
+ pa_assert(obuf_length <= 0);
+
+ if ((r = pa_read(fd, obuf, sizeof(obuf), &fd_type)) <= 0) {
+ if (r < 0) {
+ pa_log(_("read(): %s"), strerror(errno));
+ goto fail;
+ }
+ obuf_eof = TRUE;
+ } else {
+ obuf_length = (size_t) r;
+ obuf_index = 0;
+ }
+ } else if (watch_socket->revents & POLLHUP)
+ obuf_eof = TRUE;
}
- FD_ZERO(&ifds);
- FD_ZERO(&ofds);
-
- if (obuf_length <= 0)
- FD_SET(fd, &ifds);
- else
- FD_SET(1, &ofds);
-
- if (ibuf_length <= 0)
- FD_SET(0, &ifds);
- else
- FD_SET(fd, &ofds);
+ if (watch_stdout) {
+ if (watch_stdout->revents & POLLHUP) {
+ obuf_eof = TRUE;
+ obuf_length = 0;
+ } else if (watch_stdout->revents & POLLOUT) {
+ ssize_t r;
+ pa_assert(obuf_length > 0);
+
+ if ((r = pa_write(STDOUT_FILENO, obuf + obuf_index, obuf_length, &stdout_type)) < 0) {
+ pa_log(_("write(): %s"), strerror(errno));
+ goto fail;
+ }
+
+ obuf_length -= (size_t) r;
+ obuf_index += obuf_index;
+ }
+ }
+
+ if (watch_socket) {
+ if (watch_socket->revents & POLLHUP) {
+ ibuf_eof = TRUE;
+ ibuf_length = 0;
+ } if (watch_socket->revents & POLLOUT) {
+ ssize_t r;
+ pa_assert(ibuf_length > 0);
+
+ if ((r = pa_write(fd, ibuf + ibuf_index, ibuf_length, &fd_type)) < 0) {
+ pa_log(_("write(): %s"), strerror(errno));
+ goto fail;
+ }
+
+ ibuf_length -= (size_t) r;
+ ibuf_index += obuf_index;
+ }
+ }
}
-
ret = 0;
-
+
fail:
if (fd >= 0)
- close(fd);
-
+ pa_close(fd);
+
return ret;
}
diff --git a/src/utils/pactl.c b/src/utils/pactl.c
index 25ef324d..e6f9c175 100644
--- a/src/utils/pactl.c
+++ b/src/utils/pactl.c
@@ -1,18 +1,18 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -30,125 +30,204 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
-#include <limits.h>
#include <getopt.h>
+#include <locale.h>
#include <sndfile.h>
+#include <pulse/i18n.h>
#include <pulse/pulseaudio.h>
-#if PA_API_VERSION != 9
-#error Invalid PulseAudio API version
-#endif
-
-#define BUFSIZE 1024
+#include <pulsecore/macro.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/log.h>
+#include <pulsecore/sndfile-util.h>
static pa_context *context = NULL;
static pa_mainloop_api *mainloop_api = NULL;
-static char *device = NULL, *sample_name = NULL;
+static char
+ *list_type = NULL,
+ *sample_name = NULL,
+ *sink_name = NULL,
+ *source_name = NULL,
+ *module_name = NULL,
+ *module_args = NULL,
+ *card_name = NULL,
+ *profile_name = NULL,
+ *port_name = NULL;
+
+static uint32_t
+ sink_input_idx = PA_INVALID_INDEX,
+ source_output_idx = PA_INVALID_INDEX;
+
+static pa_bool_t short_list_format = FALSE;
+static uint32_t module_index;
+static pa_bool_t suspend;
+static pa_bool_t mute;
+static pa_volume_t volume;
+static enum volume_flags {
+ VOL_UINT = 0,
+ VOL_PERCENT = 1,
+ VOL_LINEAR = 2,
+ VOL_DECIBEL = 3,
+ VOL_ABSOLUTE = 0 << 4,
+ VOL_RELATIVE = 1 << 4,
+} volume_flags;
+
+static pa_proplist *proplist = NULL;
static SNDFILE *sndfile = NULL;
static pa_stream *sample_stream = NULL;
static pa_sample_spec sample_spec;
+static pa_channel_map channel_map;
static size_t sample_length = 0;
-
static int actions = 1;
-static int nl = 0;
+static pa_bool_t nl = FALSE;
static enum {
NONE,
EXIT,
STAT,
+ INFO,
UPLOAD_SAMPLE,
PLAY_SAMPLE,
REMOVE_SAMPLE,
- LIST
+ LIST,
+ MOVE_SINK_INPUT,
+ MOVE_SOURCE_OUTPUT,
+ LOAD_MODULE,
+ UNLOAD_MODULE,
+ SUSPEND_SINK,
+ SUSPEND_SOURCE,
+ SET_CARD_PROFILE,
+ SET_SINK_PORT,
+ SET_SOURCE_PORT,
+ SET_SINK_VOLUME,
+ SET_SOURCE_VOLUME,
+ SET_SINK_INPUT_VOLUME,
+ SET_SOURCE_OUTPUT_VOLUME,
+ SET_SINK_MUTE,
+ SET_SOURCE_MUTE,
+ SET_SINK_INPUT_MUTE,
+ SUBSCRIBE
} action = NONE;
static void quit(int ret) {
- assert(mainloop_api);
+ pa_assert(mainloop_api);
mainloop_api->quit(mainloop_api, ret);
}
-
static void context_drain_complete(pa_context *c, void *userdata) {
pa_context_disconnect(c);
}
static void drain(void) {
pa_operation *o;
+
if (!(o = pa_context_drain(context, context_drain_complete, NULL)))
pa_context_disconnect(context);
else
pa_operation_unref(o);
}
-
static void complete_action(void) {
- assert(actions > 0);
+ pa_assert(actions > 0);
if (!(--actions))
drain();
}
static void stat_callback(pa_context *c, const pa_stat_info *i, void *userdata) {
- char s[128];
+ char s[PA_BYTES_SNPRINT_MAX];
if (!i) {
- fprintf(stderr, "Failed to get statistics: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Failed to get statistics: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
pa_bytes_snprint(s, sizeof(s), i->memblock_total_size);
- printf("Currently in use: %u blocks containing %s bytes total.\n", i->memblock_total, s);
+ printf(_("Currently in use: %u blocks containing %s bytes total.\n"), i->memblock_total, s);
pa_bytes_snprint(s, sizeof(s), i->memblock_allocated_size);
- printf("Allocated during whole lifetime: %u blocks containing %s bytes total.\n", i->memblock_allocated, s);
+ printf(_("Allocated during whole lifetime: %u blocks containing %s bytes total.\n"), i->memblock_allocated, s);
pa_bytes_snprint(s, sizeof(s), i->scache_size);
- printf("Sample cache size: %s\n", s);
-
+ printf(_("Sample cache size: %s\n"), s);
+
complete_action();
}
static void get_server_info_callback(pa_context *c, const pa_server_info *i, void *useerdata) {
- char s[PA_SAMPLE_SPEC_SNPRINT_MAX];
-
+ char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
+
if (!i) {
- fprintf(stderr, "Failed to get server information: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Failed to get server information: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
- pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec);
-
- printf("User name: %s\n"
- "Host Name: %s\n"
- "Server Name: %s\n"
- "Server Version: %s\n"
- "Default Sample Specification: %s\n"
- "Default Sink: %s\n"
- "Default Source: %s\n"
- "Cookie: %08x\n",
+ printf(_("Server String: %s\n"
+ "Library Protocol Version: %u\n"
+ "Server Protocol Version: %u\n"
+ "Is Local: %s\n"
+ "Client Index: %u\n"
+ "Tile Size: %zu\n"),
+ pa_context_get_server(c),
+ pa_context_get_protocol_version(c),
+ pa_context_get_server_protocol_version(c),
+ pa_yes_no(pa_context_is_local(c)),
+ pa_context_get_index(c),
+ pa_context_get_tile_size(c, NULL));
+
+ pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec);
+ pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map);
+
+ printf(_("User Name: %s\n"
+ "Host Name: %s\n"
+ "Server Name: %s\n"
+ "Server Version: %s\n"
+ "Default Sample Specification: %s\n"
+ "Default Channel Map: %s\n"
+ "Default Sink: %s\n"
+ "Default Source: %s\n"
+ "Cookie: %04x:%04x\n"),
i->user_name,
i->host_name,
i->server_name,
i->server_version,
- s,
+ ss,
+ cm,
i->default_sink_name,
i->default_source_name,
- i->cookie);
+ i->cookie >> 16,
+ i->cookie & 0xFFFFU);
complete_action();
}
static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) {
- char s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
-
+
+ static const char *state_table[] = {
+ [1+PA_SINK_INVALID_STATE] = "n/a",
+ [1+PA_SINK_RUNNING] = "RUNNING",
+ [1+PA_SINK_IDLE] = "IDLE",
+ [1+PA_SINK_SUSPENDED] = "SUSPENDED"
+ };
+
+ char
+ s[PA_SAMPLE_SPEC_SNPRINT_MAX],
+ cv[PA_CVOLUME_SNPRINT_MAX],
+ cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX],
+ v[PA_VOLUME_SNPRINT_MAX],
+ vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
+ cm[PA_CHANNEL_MAP_SNPRINT_MAX],
+ f[PA_FORMAT_INFO_SNPRINT_MAX];
+ char *pl;
+
if (is_last < 0) {
- fprintf(stderr, "Failed to get sink information: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
@@ -157,45 +236,109 @@ static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_
complete_action();
return;
}
-
- assert(i);
- if (nl)
+ pa_assert(i);
+
+ if (nl && !short_list_format)
printf("\n");
- nl = 1;
-
- printf("*** Sink #%u ***\n"
- "Name: %s\n"
- "Driver: %s\n"
- "Description: %s\n"
- "Sample Specification: %s\n"
- "Channel Map: %s\n"
- "Owner Module: %u\n"
- "Volume: %s\n"
- "Monitor Source: %u\n"
- "Latency: %0.0f usec\n"
- "Flags: %s%s%s\n",
+ nl = TRUE;
+
+ if (short_list_format) {
+ printf("%u\t%s\t%s\t%s\t%s\n",
+ i->index,
+ i->name,
+ pa_strnull(i->driver),
+ pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
+ state_table[1+i->state]);
+ return;
+ }
+
+ printf(_("Sink #%u\n"
+ "\tState: %s\n"
+ "\tName: %s\n"
+ "\tDescription: %s\n"
+ "\tDriver: %s\n"
+ "\tSample Specification: %s\n"
+ "\tChannel Map: %s\n"
+ "\tOwner Module: %u\n"
+ "\tMute: %s\n"
+ "\tVolume: %s%s%s\n"
+ "\t balance %0.2f\n"
+ "\tBase Volume: %s%s%s\n"
+ "\tMonitor Source: %s\n"
+ "\tLatency: %0.0f usec, configured %0.0f usec\n"
+ "\tFlags: %s%s%s%s%s%s\n"
+ "\tProperties:\n\t\t%s\n"),
i->index,
+ state_table[1+i->state],
i->name,
- i->driver,
- i->description,
+ pa_strnull(i->description),
+ pa_strnull(i->driver),
pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
i->owner_module,
- i->mute ? "muted" : pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
- i->monitor_source,
- (double) i->latency,
+ pa_yes_no(i->mute),
+ pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
+ i->flags & PA_SINK_DECIBEL_VOLUME ? "\n\t " : "",
+ i->flags & PA_SINK_DECIBEL_VOLUME ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume) : "",
+ pa_cvolume_get_balance(&i->volume, &i->channel_map),
+ pa_volume_snprint(v, sizeof(v), i->base_volume),
+ i->flags & PA_SINK_DECIBEL_VOLUME ? "\n\t " : "",
+ i->flags & PA_SINK_DECIBEL_VOLUME ? pa_sw_volume_snprint_dB(vdb, sizeof(vdb), i->base_volume) : "",
+ pa_strnull(i->monitor_source_name),
+ (double) i->latency, (double) i->configured_latency,
+ i->flags & PA_SINK_HARDWARE ? "HARDWARE " : "",
+ i->flags & PA_SINK_NETWORK ? "NETWORK " : "",
+ i->flags & PA_SINK_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
i->flags & PA_SINK_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
+ i->flags & PA_SINK_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
i->flags & PA_SINK_LATENCY ? "LATENCY " : "",
- i->flags & PA_SINK_HARDWARE ? "HARDWARE" : "");
+ pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
+
+ pa_xfree(pl);
+
+ if (i->ports) {
+ pa_sink_port_info **p;
+ printf(_("\tPorts:\n"));
+ for (p = i->ports; *p; p++)
+ printf("\t\t%s: %s (priority. %u)\n", (*p)->name, (*p)->description, (*p)->priority);
+ }
+
+ if (i->active_port)
+ printf(_("\tActive Port: %s\n"),
+ i->active_port->name);
+
+ if (i->formats) {
+ uint8_t j;
+
+ printf(_("\tFormats:\n"));
+ for (j = 0; j < i->n_formats; j++)
+ printf("\t\t%s\n", pa_format_info_snprint(f, sizeof(f), i->formats[j]));
+ }
}
static void get_source_info_callback(pa_context *c, const pa_source_info *i, int is_last, void *userdata) {
- char s[PA_SAMPLE_SPEC_SNPRINT_MAX], t[32], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
+
+ static const char *state_table[] = {
+ [1+PA_SOURCE_INVALID_STATE] = "n/a",
+ [1+PA_SOURCE_RUNNING] = "RUNNING",
+ [1+PA_SOURCE_IDLE] = "IDLE",
+ [1+PA_SOURCE_SUSPENDED] = "SUSPENDED"
+ };
+
+ char
+ s[PA_SAMPLE_SPEC_SNPRINT_MAX],
+ cv[PA_CVOLUME_SNPRINT_MAX],
+ cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX],
+ v[PA_VOLUME_SNPRINT_MAX],
+ vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
+ cm[PA_CHANNEL_MAP_SNPRINT_MAX],
+ f[PA_FORMAT_INFO_SNPRINT_MAX];
+ char *pl;
if (is_last < 0) {
- fprintf(stderr, "Failed to get source information: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
@@ -204,47 +347,94 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
complete_action();
return;
}
-
- assert(i);
- if (nl)
+ pa_assert(i);
+
+ if (nl && !short_list_format)
printf("\n");
- nl = 1;
-
- snprintf(t, sizeof(t), "%u", i->monitor_of_sink);
-
- printf("*** Source #%u ***\n"
- "Name: %s\n"
- "Driver: %s\n"
- "Description: %s\n"
- "Sample Specification: %s\n"
- "Channel Map: %s\n"
- "Owner Module: %u\n"
- "Volume: %s\n"
- "Monitor of Sink: %s\n"
- "Latency: %0.0f usec\n"
- "Flags: %s%s%s\n",
+ nl = TRUE;
+
+ if (short_list_format) {
+ printf("%u\t%s\t%s\t%s\t%s\n",
+ i->index,
+ i->name,
+ pa_strnull(i->driver),
+ pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
+ state_table[1+i->state]);
+ return;
+ }
+
+ printf(_("Source #%u\n"
+ "\tState: %s\n"
+ "\tName: %s\n"
+ "\tDescription: %s\n"
+ "\tDriver: %s\n"
+ "\tSample Specification: %s\n"
+ "\tChannel Map: %s\n"
+ "\tOwner Module: %u\n"
+ "\tMute: %s\n"
+ "\tVolume: %s%s%s\n"
+ "\t balance %0.2f\n"
+ "\tBase Volume: %s%s%s\n"
+ "\tMonitor of Sink: %s\n"
+ "\tLatency: %0.0f usec, configured %0.0f usec\n"
+ "\tFlags: %s%s%s%s%s%s\n"
+ "\tProperties:\n\t\t%s\n"),
i->index,
- i->driver,
+ state_table[1+i->state],
i->name,
- i->description,
+ pa_strnull(i->description),
+ pa_strnull(i->driver),
pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
i->owner_module,
- i->mute ? "muted" : pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
- i->monitor_of_sink != PA_INVALID_INDEX ? t : "no",
- (double) i->latency,
+ pa_yes_no(i->mute),
+ pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
+ i->flags & PA_SOURCE_DECIBEL_VOLUME ? "\n\t " : "",
+ i->flags & PA_SOURCE_DECIBEL_VOLUME ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume) : "",
+ pa_cvolume_get_balance(&i->volume, &i->channel_map),
+ pa_volume_snprint(v, sizeof(v), i->base_volume),
+ i->flags & PA_SOURCE_DECIBEL_VOLUME ? "\n\t " : "",
+ i->flags & PA_SOURCE_DECIBEL_VOLUME ? pa_sw_volume_snprint_dB(vdb, sizeof(vdb), i->base_volume) : "",
+ i->monitor_of_sink_name ? i->monitor_of_sink_name : _("n/a"),
+ (double) i->latency, (double) i->configured_latency,
+ i->flags & PA_SOURCE_HARDWARE ? "HARDWARE " : "",
+ i->flags & PA_SOURCE_NETWORK ? "NETWORK " : "",
+ i->flags & PA_SOURCE_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
i->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
+ i->flags & PA_SOURCE_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
i->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
- i->flags & PA_SOURCE_HARDWARE ? "HARDWARE" : "");
+ pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
+ pa_xfree(pl);
+
+ if (i->ports) {
+ pa_source_port_info **p;
+
+ printf(_("\tPorts:\n"));
+ for (p = i->ports; *p; p++)
+ printf("\t\t%s: %s (priority. %u)\n", (*p)->name, (*p)->description, (*p)->priority);
+ }
+
+ if (i->active_port)
+ printf(_("\tActive Port: %s\n"),
+ i->active_port->name);
+
+ if (i->formats) {
+ uint8_t j;
+
+ printf(_("\tFormats:\n"));
+ for (j = 0; j < i->n_formats; j++)
+ printf("\t\t%s\n", pa_format_info_snprint(f, sizeof(f), i->formats[j]));
+ }
}
static void get_module_info_callback(pa_context *c, const pa_module_info *i, int is_last, void *userdata) {
char t[32];
+ char *pl;
if (is_last < 0) {
- fprintf(stderr, "Failed to get module information: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
@@ -253,32 +443,40 @@ static void get_module_info_callback(pa_context *c, const pa_module_info *i, int
complete_action();
return;
}
-
- assert(i);
- if (nl)
+ pa_assert(i);
+
+ if (nl && !short_list_format)
printf("\n");
- nl = 1;
-
- snprintf(t, sizeof(t), "%u", i->n_used);
-
- printf("*** Module #%u ***\n"
- "Name: %s\n"
- "Argument: %s\n"
- "Usage counter: %s\n"
- "Auto unload: %s\n",
+ nl = TRUE;
+
+ pa_snprintf(t, sizeof(t), "%u", i->n_used);
+
+ if (short_list_format) {
+ printf("%u\t%s\t%s\t\n", i->index, i->name, i->argument ? i->argument : "");
+ return;
+ }
+
+ printf(_("Module #%u\n"
+ "\tName: %s\n"
+ "\tArgument: %s\n"
+ "\tUsage counter: %s\n"
+ "\tProperties:\n\t\t%s\n"),
i->index,
i->name,
- i->argument,
- i->n_used != PA_INVALID_INDEX ? t : "n/a",
- i->auto_unload ? "yes" : "no");
+ i->argument ? i->argument : "",
+ i->n_used != PA_INVALID_INDEX ? t : _("n/a"),
+ pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
+
+ pa_xfree(pl);
}
static void get_client_info_callback(pa_context *c, const pa_client_info *i, int is_last, void *userdata) {
char t[32];
+ char *pl;
if (is_last < 0) {
- fprintf(stderr, "Failed to get client information: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Failed to get client information: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
@@ -287,30 +485,95 @@ static void get_client_info_callback(pa_context *c, const pa_client_info *i, int
complete_action();
return;
}
-
- assert(i);
- if (nl)
+ pa_assert(i);
+
+ if (nl && !short_list_format)
+ printf("\n");
+ nl = TRUE;
+
+ pa_snprintf(t, sizeof(t), "%u", i->owner_module);
+
+ if (short_list_format) {
+ printf("%u\t%s\t%s\n",
+ i->index,
+ pa_strnull(i->driver),
+ pa_strnull(pa_proplist_gets(i->proplist, PA_PROP_APPLICATION_PROCESS_BINARY)));
+ return;
+ }
+
+ printf(_("Client #%u\n"
+ "\tDriver: %s\n"
+ "\tOwner Module: %s\n"
+ "\tProperties:\n\t\t%s\n"),
+ i->index,
+ pa_strnull(i->driver),
+ i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
+ pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
+
+ pa_xfree(pl);
+}
+
+static void get_card_info_callback(pa_context *c, const pa_card_info *i, int is_last, void *userdata) {
+ char t[32];
+ char *pl;
+
+ if (is_last < 0) {
+ pa_log(_("Failed to get card information: %s"), pa_strerror(pa_context_errno(c)));
+ complete_action();
+ return;
+ }
+
+ if (is_last) {
+ complete_action();
+ return;
+ }
+
+ pa_assert(i);
+
+ if (nl && !short_list_format)
printf("\n");
- nl = 1;
-
- snprintf(t, sizeof(t), "%u", i->owner_module);
-
- printf("*** Client #%u ***\n"
- "Name: %s\n"
- "Driver: %s\n"
- "Owner Module: %s\n",
+ nl = TRUE;
+
+ pa_snprintf(t, sizeof(t), "%u", i->owner_module);
+
+ if (short_list_format) {
+ printf("%u\t%s\t%s\n", i->index, i->name, pa_strnull(i->driver));
+ return;
+ }
+
+ printf(_("Card #%u\n"
+ "\tName: %s\n"
+ "\tDriver: %s\n"
+ "\tOwner Module: %s\n"
+ "\tProperties:\n\t\t%s\n"),
i->index,
i->name,
- i->driver,
- i->owner_module != PA_INVALID_INDEX ? t : "n/a");
+ pa_strnull(i->driver),
+ i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
+ pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
+
+ if (i->profiles) {
+ pa_card_profile_info *p;
+
+ printf(_("\tProfiles:\n"));
+ for (p = i->profiles; p->name; p++)
+ printf("\t\t%s: %s (sinks: %u, sources: %u, priority. %u)\n", p->name, p->description, p->n_sinks, p->n_sources, p->priority);
+ }
+
+ if (i->active_profile)
+ printf(_("\tActive Profile: %s\n"),
+ i->active_profile->name);
+
+ pa_xfree(pl);
}
static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) {
- char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
+ char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], f[PA_FORMAT_INFO_SNPRINT_MAX];
+ char *pl;
if (is_last < 0) {
- fprintf(stderr, "Failed to get sink input information: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
@@ -319,48 +582,68 @@ static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info
complete_action();
return;
}
-
- assert(i);
- if (nl)
+ pa_assert(i);
+
+ if (nl && !short_list_format)
printf("\n");
- nl = 1;
-
- snprintf(t, sizeof(t), "%u", i->owner_module);
- snprintf(k, sizeof(k), "%u", i->client);
-
- printf("*** Sink Input #%u ***\n"
- "Name: %s\n"
- "Driver: %s\n"
- "Owner Module: %s\n"
- "Client: %s\n"
- "Sink: %u\n"
- "Sample Specification: %s\n"
- "Channel Map: %s\n"
- "Volume: %s\n"
- "Buffer Latency: %0.0f usec\n"
- "Sink Latency: %0.0f usec\n"
- "Resample method: %s\n",
+ nl = TRUE;
+
+ pa_snprintf(t, sizeof(t), "%u", i->owner_module);
+ pa_snprintf(k, sizeof(k), "%u", i->client);
+
+ if (short_list_format) {
+ printf("%u\t%u\t%s\t%s\t%s\n",
+ i->index,
+ i->sink,
+ i->client != PA_INVALID_INDEX ? k : "-",
+ pa_strnull(i->driver),
+ pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec));
+ return;
+ }
+
+ printf(_("Sink Input #%u\n"
+ "\tDriver: %s\n"
+ "\tOwner Module: %s\n"
+ "\tClient: %s\n"
+ "\tSink: %u\n"
+ "\tSample Specification: %s\n"
+ "\tChannel Map: %s\n"
+ "\tFormat: %s\n"
+ "\tMute: %s\n"
+ "\tVolume: %s\n"
+ "\t %s\n"
+ "\t balance %0.2f\n"
+ "\tBuffer Latency: %0.0f usec\n"
+ "\tSink Latency: %0.0f usec\n"
+ "\tResample method: %s\n"
+ "\tProperties:\n\t\t%s\n"),
i->index,
- i->name,
- i->driver,
- i->owner_module != PA_INVALID_INDEX ? t : "n/a",
- i->client != PA_INVALID_INDEX ? k : "n/a",
+ pa_strnull(i->driver),
+ i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
+ i->client != PA_INVALID_INDEX ? k : _("n/a"),
i->sink,
pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
+ pa_format_info_snprint(f, sizeof(f), i->format),
+ pa_yes_no(i->mute),
pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
+ pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume),
+ pa_cvolume_get_balance(&i->volume, &i->channel_map),
(double) i->buffer_usec,
(double) i->sink_usec,
- i->resample_method ? i->resample_method : "n/a");
-}
+ i->resample_method ? i->resample_method : _("n/a"),
+ pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
+ pa_xfree(pl);
+}
static void get_source_output_info_callback(pa_context *c, const pa_source_output_info *i, int is_last, void *userdata) {
- char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
+ char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], f[PA_FORMAT_INFO_SNPRINT_MAX];
+ char *pl;
if (is_last < 0) {
- fprintf(stderr, "Failed to get source output information: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
@@ -369,46 +652,69 @@ static void get_source_output_info_callback(pa_context *c, const pa_source_outpu
complete_action();
return;
}
-
- assert(i);
- if (nl)
+ pa_assert(i);
+
+ if (nl && !short_list_format)
printf("\n");
- nl = 1;
-
-
- snprintf(t, sizeof(t), "%u", i->owner_module);
- snprintf(k, sizeof(k), "%u", i->client);
-
- printf("*** Source Output #%u ***\n"
- "Name: %s\n"
- "Driver: %s\n"
- "Owner Module: %s\n"
- "Client: %s\n"
- "Source: %u\n"
- "Sample Specification: %s\n"
- "Channel Map: %s\n"
- "Buffer Latency: %0.0f usec\n"
- "Source Latency: %0.0f usec\n"
- "Resample method: %s\n",
+ nl = TRUE;
+
+
+ pa_snprintf(t, sizeof(t), "%u", i->owner_module);
+ pa_snprintf(k, sizeof(k), "%u", i->client);
+
+ if (short_list_format) {
+ printf("%u\t%u\t%s\t%s\t%s\n",
+ i->index,
+ i->source,
+ i->client != PA_INVALID_INDEX ? k : "-",
+ pa_strnull(i->driver),
+ pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec));
+ return;
+ }
+
+ printf(_("Source Output #%u\n"
+ "\tDriver: %s\n"
+ "\tOwner Module: %s\n"
+ "\tClient: %s\n"
+ "\tSource: %u\n"
+ "\tSample Specification: %s\n"
+ "\tChannel Map: %s\n"
+ "\tFormat: %s\n"
+ "\tMute: %s\n"
+ "\tVolume: %s\n"
+ "\t %s\n"
+ "\t balance %0.2f\n"
+ "\tBuffer Latency: %0.0f usec\n"
+ "\tSource Latency: %0.0f usec\n"
+ "\tResample method: %s\n"
+ "\tProperties:\n\t\t%s\n"),
i->index,
- i->name,
- i->driver,
- i->owner_module != PA_INVALID_INDEX ? t : "n/a",
- i->client != PA_INVALID_INDEX ? k : "n/a",
+ pa_strnull(i->driver),
+ i->owner_module != PA_INVALID_INDEX ? t : _("n/a"),
+ i->client != PA_INVALID_INDEX ? k : _("n/a"),
i->source,
pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
+ pa_format_info_snprint(f, sizeof(f), i->format),
+ pa_yes_no(i->mute),
+ pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
+ pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume),
+ pa_cvolume_get_balance(&i->volume, &i->channel_map),
(double) i->buffer_usec,
(double) i->source_usec,
- i->resample_method ? i->resample_method : "n/a");
+ i->resample_method ? i->resample_method : _("n/a"),
+ pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
+
+ pa_xfree(pl);
}
static void get_sample_info_callback(pa_context *c, const pa_sample_info *i, int is_last, void *userdata) {
- char t[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
+ char t[PA_BYTES_SNPRINT_MAX], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
+ char *pl;
if (is_last < 0) {
- fprintf(stderr, "Failed to get sample information: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Failed to get sample information: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
@@ -417,91 +723,180 @@ static void get_sample_info_callback(pa_context *c, const pa_sample_info *i, int
complete_action();
return;
}
-
- assert(i);
- if (nl)
+ pa_assert(i);
+
+ if (nl && !short_list_format)
printf("\n");
- nl = 1;
+ nl = TRUE;
-
pa_bytes_snprint(t, sizeof(t), i->bytes);
-
- printf("*** Sample #%u ***\n"
- "Name: %s\n"
- "Volume: %s\n"
- "Sample Specification: %s\n"
- "Channel Map: %s\n"
- "Duration: %0.1fs\n"
- "Size: %s\n"
- "Lazy: %s\n"
- "Filename: %s\n",
+
+ if (short_list_format) {
+ printf("%u\t%s\t%s\t%0.3f\n",
+ i->index,
+ i->name,
+ pa_sample_spec_valid(&i->sample_spec) ? pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec) : "-",
+ (double) i->duration/1000000.0);
+ return;
+ }
+
+ printf(_("Sample #%u\n"
+ "\tName: %s\n"
+ "\tSample Specification: %s\n"
+ "\tChannel Map: %s\n"
+ "\tVolume: %s\n"
+ "\t %s\n"
+ "\t balance %0.2f\n"
+ "\tDuration: %0.1fs\n"
+ "\tSize: %s\n"
+ "\tLazy: %s\n"
+ "\tFilename: %s\n"
+ "\tProperties:\n\t\t%s\n"),
i->index,
i->name,
+ pa_sample_spec_valid(&i->sample_spec) ? pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec) : _("n/a"),
+ pa_sample_spec_valid(&i->sample_spec) ? pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map) : _("n/a"),
pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
- pa_sample_spec_valid(&i->sample_spec) ? pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec) : "n/a",
- pa_sample_spec_valid(&i->sample_spec) ? pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map) : "n/a",
- (double) i->duration/1000000,
+ pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume),
+ pa_cvolume_get_balance(&i->volume, &i->channel_map),
+ (double) i->duration/1000000.0,
t,
- i->lazy ? "yes" : "no",
- i->filename ? i->filename : "n/a");
+ pa_yes_no(i->lazy),
+ i->filename ? i->filename : _("n/a"),
+ pl = pa_proplist_to_string_sep(i->proplist, "\n\t\t"));
+
+ pa_xfree(pl);
+}
+
+static void simple_callback(pa_context *c, int success, void *userdata) {
+ if (!success) {
+ pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c)));
+ quit(1);
+ return;
+ }
+
+ complete_action();
+}
+
+static void index_callback(pa_context *c, uint32_t idx, void *userdata) {
+ if (idx == PA_INVALID_INDEX) {
+ pa_log(_("Failure: %s"), pa_strerror(pa_context_errno(c)));
+ quit(1);
+ return;
+ }
+
+ printf("%u\n", idx);
+
+ complete_action();
}
-static void get_autoload_info_callback(pa_context *c, const pa_autoload_info *i, int is_last, void *userdata) {
+static void volume_relative_adjust(pa_cvolume *cv) {
+ pa_assert((volume_flags & VOL_RELATIVE) == VOL_RELATIVE);
+
+ /* Relative volume change is additive in case of UINT or PERCENT
+ * and multiplicative for LINEAR or DECIBEL */
+ if ((volume_flags & 0x0F) == VOL_UINT || (volume_flags & 0x0F) == VOL_PERCENT) {
+ pa_volume_t v = pa_cvolume_avg(cv);
+ v = v + volume < PA_VOLUME_NORM ? PA_VOLUME_MUTED : v + volume - PA_VOLUME_NORM;
+ pa_cvolume_set(cv, 1, v);
+ }
+ if ((volume_flags & 0x0F) == VOL_LINEAR || (volume_flags & 0x0F) == VOL_DECIBEL) {
+ pa_sw_cvolume_multiply_scalar(cv, cv, volume);
+ }
+}
+
+static void get_sink_volume_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) {
+ pa_cvolume cv;
+
if (is_last < 0) {
- fprintf(stderr, "Failed to get autoload information: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
- if (is_last) {
- complete_action();
+ if (is_last)
+ return;
+
+ pa_assert(i);
+
+ cv = i->volume;
+ volume_relative_adjust(&cv);
+ pa_operation_unref(pa_context_set_sink_volume_by_name(c, sink_name, &cv, simple_callback, NULL));
+}
+
+static void get_source_volume_callback(pa_context *c, const pa_source_info *i, int is_last, void *userdata) {
+ pa_cvolume cv;
+
+ if (is_last < 0) {
+ pa_log(_("Failed to get source information: %s"), pa_strerror(pa_context_errno(c)));
+ quit(1);
return;
}
-
- assert(i);
- if (nl)
- printf("\n");
- nl = 1;
+ if (is_last)
+ return;
- printf("*** Autoload Entry #%u ***\n"
- "Name: %s\n"
- "Type: %s\n"
- "Module: %s\n"
- "Argument: %s\n",
- i->index,
- i->name,
- i->type == PA_AUTOLOAD_SINK ? "sink" : "source",
- i->module,
- i->argument);
+ pa_assert(i);
+
+ cv = i->volume;
+ volume_relative_adjust(&cv);
+ pa_operation_unref(pa_context_set_source_volume_by_name(c, source_name, &cv, simple_callback, NULL));
}
-static void simple_callback(pa_context *c, int success, void *userdata) {
- if (!success) {
- fprintf(stderr, "Failure: %s\n", pa_strerror(pa_context_errno(c)));
+static void get_sink_input_volume_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) {
+ pa_cvolume cv;
+
+ if (is_last < 0) {
+ pa_log(_("Failed to get sink input information: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
return;
}
- complete_action();
+ if (is_last)
+ return;
+
+ pa_assert(i);
+
+ cv = i->volume;
+ volume_relative_adjust(&cv);
+ pa_operation_unref(pa_context_set_sink_input_volume(c, sink_input_idx, &cv, simple_callback, NULL));
+}
+
+static void get_source_output_volume_callback(pa_context *c, const pa_source_output_info *o, int is_last, void *userdata) {
+ pa_cvolume cv;
+
+ if (is_last < 0) {
+ pa_log(_("Failed to get source output information: %s"), pa_strerror(pa_context_errno(c)));
+ quit(1);
+ return;
+ }
+
+ if (is_last)
+ return;
+
+ pa_assert(o);
+
+ cv = o->volume;
+ volume_relative_adjust(&cv);
+ pa_operation_unref(pa_context_set_source_output_volume(c, source_output_idx, &cv, simple_callback, NULL));
}
static void stream_state_callback(pa_stream *s, void *userdata) {
- assert(s);
+ pa_assert(s);
switch (pa_stream_get_state(s)) {
case PA_STREAM_CREATING:
case PA_STREAM_READY:
break;
-
+
case PA_STREAM_TERMINATED:
drain();
break;
-
+
case PA_STREAM_FAILED:
default:
- fprintf(stderr, "Failed to upload sample: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s))));
+ pa_log(_("Failed to upload sample: %s"), pa_strerror(pa_context_errno(pa_stream_get_context(s))));
quit(1);
}
}
@@ -509,31 +904,93 @@ static void stream_state_callback(pa_stream *s, void *userdata) {
static void stream_write_callback(pa_stream *s, size_t length, void *userdata) {
sf_count_t l;
float *d;
- assert(s && length && sndfile);
+ pa_assert(s && length && sndfile);
d = pa_xmalloc(length);
- assert(sample_length >= length);
- l = length/pa_frame_size(&sample_spec);
+ pa_assert(sample_length >= length);
+ l = (sf_count_t) (length/pa_frame_size(&sample_spec));
if ((sf_readf_float(sndfile, d, l)) != l) {
pa_xfree(d);
- fprintf(stderr, "Premature end of file\n");
+ pa_log(_("Premature end of file"));
quit(1);
+ return;
}
-
+
pa_stream_write(s, d, length, pa_xfree, 0, PA_SEEK_RELATIVE);
sample_length -= length;
- if (sample_length <= 0) {
+ if (sample_length <= 0) {
pa_stream_set_write_callback(sample_stream, NULL, NULL);
pa_stream_finish_upload(sample_stream);
}
}
+static const char *subscription_event_type_to_string(pa_subscription_event_type_t t) {
+
+ switch (t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) {
+
+ case PA_SUBSCRIPTION_EVENT_NEW:
+ return _("new");
+
+ case PA_SUBSCRIPTION_EVENT_CHANGE:
+ return _("change");
+
+ case PA_SUBSCRIPTION_EVENT_REMOVE:
+ return _("remove");
+ }
+
+ return _("unknown");
+}
+
+static const char *subscription_event_facility_to_string(pa_subscription_event_type_t t) {
+
+ switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
+
+ case PA_SUBSCRIPTION_EVENT_SINK:
+ return _("sink");
+
+ case PA_SUBSCRIPTION_EVENT_SOURCE:
+ return _("source");
+
+ case PA_SUBSCRIPTION_EVENT_SINK_INPUT:
+ return _("sink-input");
+
+ case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT:
+ return _("source-output");
+
+ case PA_SUBSCRIPTION_EVENT_MODULE:
+ return _("module");
+
+ case PA_SUBSCRIPTION_EVENT_CLIENT:
+ return _("client");
+
+ case PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE:
+ return _("sample-cache");
+
+ case PA_SUBSCRIPTION_EVENT_SERVER:
+ return _("server");
+
+ case PA_SUBSCRIPTION_EVENT_CARD:
+ return _("server");
+ }
+
+ return _("unknown");
+}
+
+static void context_subscribe_callback(pa_context *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
+ pa_assert(c);
+
+ printf(_("Event '%s' on %s #%u\n"),
+ subscription_event_type_to_string(t),
+ subscription_event_facility_to_string(t),
+ idx);
+}
+
static void context_state_callback(pa_context *c, void *userdata) {
- assert(c);
+ pa_assert(c);
switch (pa_context_get_state(c)) {
case PA_CONTEXT_CONNECTING:
case PA_CONTEXT_AUTHORIZING:
@@ -543,13 +1000,15 @@ static void context_state_callback(pa_context *c, void *userdata) {
case PA_CONTEXT_READY:
switch (action) {
case STAT:
- actions = 2;
pa_operation_unref(pa_context_stat(c, stat_callback, NULL));
+ break;
+
+ case INFO:
pa_operation_unref(pa_context_get_server_info(c, get_server_info_callback, NULL));
break;
- case PLAY_SAMPLE:
- pa_operation_unref(pa_context_play_sample(c, sample_name, device, PA_VOLUME_NORM, simple_callback, NULL));
+ case PLAY_SAMPLE:
+ pa_operation_unref(pa_context_play_sample(c, sample_name, sink_name, PA_VOLUME_NORM, simple_callback, NULL));
break;
case REMOVE_SAMPLE:
@@ -558,31 +1017,164 @@ static void context_state_callback(pa_context *c, void *userdata) {
case UPLOAD_SAMPLE:
sample_stream = pa_stream_new(c, sample_name, &sample_spec, NULL);
- assert(sample_stream);
-
+ pa_assert(sample_stream);
+
pa_stream_set_state_callback(sample_stream, stream_state_callback, NULL);
pa_stream_set_write_callback(sample_stream, stream_write_callback, NULL);
pa_stream_connect_upload(sample_stream, sample_length);
break;
-
+
case EXIT:
- pa_operation_unref(pa_context_exit_daemon(c, NULL, NULL));
- drain();
+ pa_operation_unref(pa_context_exit_daemon(c, simple_callback, NULL));
+ break;
case LIST:
- actions = 8;
- pa_operation_unref(pa_context_get_module_info_list(c, get_module_info_callback, NULL));
- pa_operation_unref(pa_context_get_sink_info_list(c, get_sink_info_callback, NULL));
- pa_operation_unref(pa_context_get_source_info_list(c, get_source_info_callback, NULL));
- pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, NULL));
- pa_operation_unref(pa_context_get_source_output_info_list(c, get_source_output_info_callback, NULL));
- pa_operation_unref(pa_context_get_client_info_list(c, get_client_info_callback, NULL));
- pa_operation_unref(pa_context_get_sample_info_list(c, get_sample_info_callback, NULL));
- pa_operation_unref(pa_context_get_autoload_info_list(c, get_autoload_info_callback, NULL));
+ if (list_type) {
+ if (pa_streq(list_type, "modules"))
+ pa_operation_unref(pa_context_get_module_info_list(c, get_module_info_callback, NULL));
+ else if (pa_streq(list_type, "sinks"))
+ pa_operation_unref(pa_context_get_sink_info_list(c, get_sink_info_callback, NULL));
+ else if (pa_streq(list_type, "sources"))
+ pa_operation_unref(pa_context_get_source_info_list(c, get_source_info_callback, NULL));
+ else if (pa_streq(list_type, "sink-inputs"))
+ pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, NULL));
+ else if (pa_streq(list_type, "source-outputs"))
+ pa_operation_unref(pa_context_get_source_output_info_list(c, get_source_output_info_callback, NULL));
+ else if (pa_streq(list_type, "clients"))
+ pa_operation_unref(pa_context_get_client_info_list(c, get_client_info_callback, NULL));
+ else if (pa_streq(list_type, "samples"))
+ pa_operation_unref(pa_context_get_sample_info_list(c, get_sample_info_callback, NULL));
+ else if (pa_streq(list_type, "cards"))
+ pa_operation_unref(pa_context_get_card_info_list(c, get_card_info_callback, NULL));
+ else
+ pa_assert_not_reached();
+ } else {
+ actions = 8;
+ pa_operation_unref(pa_context_get_module_info_list(c, get_module_info_callback, NULL));
+ pa_operation_unref(pa_context_get_sink_info_list(c, get_sink_info_callback, NULL));
+ pa_operation_unref(pa_context_get_source_info_list(c, get_source_info_callback, NULL));
+ pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, NULL));
+ pa_operation_unref(pa_context_get_source_output_info_list(c, get_source_output_info_callback, NULL));
+ pa_operation_unref(pa_context_get_client_info_list(c, get_client_info_callback, NULL));
+ pa_operation_unref(pa_context_get_sample_info_list(c, get_sample_info_callback, NULL));
+ pa_operation_unref(pa_context_get_card_info_list(c, get_card_info_callback, NULL));
+ }
+ break;
+
+ case MOVE_SINK_INPUT:
+ pa_operation_unref(pa_context_move_sink_input_by_name(c, sink_input_idx, sink_name, simple_callback, NULL));
+ break;
+
+ case MOVE_SOURCE_OUTPUT:
+ pa_operation_unref(pa_context_move_source_output_by_name(c, source_output_idx, source_name, simple_callback, NULL));
+ break;
+
+ case LOAD_MODULE:
+ pa_operation_unref(pa_context_load_module(c, module_name, module_args, index_callback, NULL));
+ break;
+
+ case UNLOAD_MODULE:
+ pa_operation_unref(pa_context_unload_module(c, module_index, simple_callback, NULL));
+ break;
+
+ case SUSPEND_SINK:
+ if (sink_name)
+ pa_operation_unref(pa_context_suspend_sink_by_name(c, sink_name, suspend, simple_callback, NULL));
+ else
+ pa_operation_unref(pa_context_suspend_sink_by_index(c, PA_INVALID_INDEX, suspend, simple_callback, NULL));
+ break;
+
+ case SUSPEND_SOURCE:
+ if (source_name)
+ pa_operation_unref(pa_context_suspend_source_by_name(c, source_name, suspend, simple_callback, NULL));
+ else
+ pa_operation_unref(pa_context_suspend_source_by_index(c, PA_INVALID_INDEX, suspend, simple_callback, NULL));
+ break;
+
+ case SET_CARD_PROFILE:
+ pa_operation_unref(pa_context_set_card_profile_by_name(c, card_name, profile_name, simple_callback, NULL));
+ break;
+
+ case SET_SINK_PORT:
+ pa_operation_unref(pa_context_set_sink_port_by_name(c, sink_name, port_name, simple_callback, NULL));
+ break;
+
+ case SET_SOURCE_PORT:
+ pa_operation_unref(pa_context_set_source_port_by_name(c, source_name, port_name, simple_callback, NULL));
+ break;
+
+ case SET_SINK_MUTE:
+ pa_operation_unref(pa_context_set_sink_mute_by_name(c, sink_name, mute, simple_callback, NULL));
+ break;
+
+ case SET_SOURCE_MUTE:
+ pa_operation_unref(pa_context_set_source_mute_by_name(c, source_name, mute, simple_callback, NULL));
+ break;
+
+ case SET_SINK_INPUT_MUTE:
+ pa_operation_unref(pa_context_set_sink_input_mute(c, sink_input_idx, mute, simple_callback, NULL));
+ break;
+
+ case SET_SINK_VOLUME:
+ if ((volume_flags & VOL_RELATIVE) == VOL_RELATIVE) {
+ pa_operation_unref(pa_context_get_sink_info_by_name(c, sink_name, get_sink_volume_callback, NULL));
+ } else {
+ pa_cvolume v;
+ pa_cvolume_set(&v, 1, volume);
+ pa_operation_unref(pa_context_set_sink_volume_by_name(c, sink_name, &v, simple_callback, NULL));
+ }
+ break;
+
+ case SET_SOURCE_VOLUME:
+ if ((volume_flags & VOL_RELATIVE) == VOL_RELATIVE) {
+ pa_operation_unref(pa_context_get_source_info_by_name(c, source_name, get_source_volume_callback, NULL));
+ } else {
+ pa_cvolume v;
+ pa_cvolume_set(&v, 1, volume);
+ pa_operation_unref(pa_context_set_source_volume_by_name(c, source_name, &v, simple_callback, NULL));
+ }
+ break;
+
+ case SET_SINK_INPUT_VOLUME:
+ if ((volume_flags & VOL_RELATIVE) == VOL_RELATIVE) {
+ pa_operation_unref(pa_context_get_sink_input_info(c, sink_input_idx, get_sink_input_volume_callback, NULL));
+ } else {
+ pa_cvolume v;
+ pa_cvolume_set(&v, 1, volume);
+ pa_operation_unref(pa_context_set_sink_input_volume(c, sink_input_idx, &v, simple_callback, NULL));
+ }
+ break;
+
+ case SET_SOURCE_OUTPUT_VOLUME:
+ if ((volume_flags & VOL_RELATIVE) == VOL_RELATIVE) {
+ pa_operation_unref(pa_context_get_source_output_info(c, source_output_idx, get_source_output_volume_callback, NULL));
+ } else {
+ pa_cvolume v;
+ pa_cvolume_set(&v, 1, volume);
+ pa_operation_unref(pa_context_set_source_output_volume(c, source_output_idx, &v, simple_callback, NULL));
+ }
+ break;
+
+ case SUBSCRIBE:
+ pa_context_set_subscribe_callback(c, context_subscribe_callback, NULL);
+
+ pa_operation_unref(pa_context_subscribe(
+ c,
+ PA_SUBSCRIPTION_MASK_SINK|
+ PA_SUBSCRIPTION_MASK_SOURCE|
+ PA_SUBSCRIPTION_MASK_SINK_INPUT|
+ PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT|
+ PA_SUBSCRIPTION_MASK_MODULE|
+ PA_SUBSCRIPTION_MASK_CLIENT|
+ PA_SUBSCRIPTION_MASK_SAMPLE_CACHE|
+ PA_SUBSCRIPTION_MASK_SERVER|
+ PA_SUBSCRIPTION_MASK_CARD,
+ NULL,
+ NULL));
break;
default:
- assert(0);
+ pa_assert_not_reached();
}
break;
@@ -592,38 +1184,116 @@ static void context_state_callback(pa_context *c, void *userdata) {
case PA_CONTEXT_FAILED:
default:
- fprintf(stderr, "Connection failure: %s\n", pa_strerror(pa_context_errno(c)));
+ pa_log(_("Connection failure: %s"), pa_strerror(pa_context_errno(c)));
quit(1);
}
}
static void exit_signal_callback(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) {
- fprintf(stderr, "Got SIGINT, exiting.\n");
+ pa_log(_("Got SIGINT, exiting."));
quit(0);
}
+static int parse_volume(const char *vol_spec, pa_volume_t *vol, enum volume_flags *vol_flags) {
+ double v;
+ char *vs;
+
+ pa_assert(vol_spec);
+ pa_assert(vol);
+ pa_assert(vol_flags);
+
+ vs = pa_xstrdup(vol_spec);
+
+ *vol_flags = (pa_startswith(vs, "+") || pa_startswith(vs, "-")) ? VOL_RELATIVE : VOL_ABSOLUTE;
+ if (strchr(vs, '.'))
+ *vol_flags |= VOL_LINEAR;
+ if (pa_endswith(vs, "%")) {
+ *vol_flags |= VOL_PERCENT;
+ vs[strlen(vs)-1] = 0;
+ }
+ if (pa_endswith(vs, "db") || pa_endswith(vs, "dB")) {
+ *vol_flags |= VOL_DECIBEL;
+ vs[strlen(vs)-2] = 0;
+ }
+
+ if (pa_atod(vs, &v) < 0) {
+ pa_log(_("Invalid volume specification"));
+ pa_xfree(vs);
+ return -1;
+ }
+
+ pa_xfree(vs);
+
+ if ((*vol_flags & VOL_RELATIVE) == VOL_RELATIVE) {
+ if ((*vol_flags & 0x0F) == VOL_UINT)
+ v += (double) PA_VOLUME_NORM;
+ if ((*vol_flags & 0x0F) == VOL_PERCENT)
+ v += 100.0;
+ if ((*vol_flags & 0x0F) == VOL_LINEAR)
+ v += 1.0;
+ }
+ if ((*vol_flags & 0x0F) == VOL_PERCENT)
+ v = v * (double) PA_VOLUME_NORM / 100;
+ if ((*vol_flags & 0x0F) == VOL_LINEAR)
+ v = pa_sw_volume_from_linear(v);
+ if ((*vol_flags & 0x0F) == VOL_DECIBEL)
+ v = pa_sw_volume_from_dB(v);
+
+ if (!PA_VOLUME_IS_VALID((pa_volume_t) v)) {
+ pa_log(_("Volume outside permissible range.\n"));
+ return -1;
+ }
+
+ *vol = (pa_volume_t) v;
+
+ return 0;
+}
+
static void help(const char *argv0) {
- printf("%s [options] stat\n"
- "%s [options] list\n"
- "%s [options] exit\n"
- "%s [options] upload-sample FILENAME [NAME]\n"
- "%s [options] play-sample NAME [SINK]\n"
- "%s [options] remove-sample NAME\n\n"
- " -h, --help Show this help\n"
- " --version Show version\n\n"
- " -s, --server=SERVER The name of the server to connect to\n"
- " -n, --client-name=NAME How to call this client on the server\n",
- argv0, argv0, argv0, argv0, argv0, argv0);
+ printf(_("%s [options] stat\n"
+ "%s [options] info\n"
+ "%s [options] list [short] [TYPE]\n"
+ "%s [options] exit\n"
+ "%s [options] upload-sample FILENAME [NAME]\n"
+ "%s [options] play-sample NAME [SINK]\n"
+ "%s [options] remove-sample NAME\n"
+ "%s [options] move-sink-input SINKINPUT SINK\n"
+ "%s [options] move-source-output SOURCEOUTPUT SOURCE\n"
+ "%s [options] load-module NAME [ARGS ...]\n"
+ "%s [options] unload-module MODULE\n"
+ "%s [options] suspend-sink SINK 1|0\n"
+ "%s [options] suspend-source SOURCE 1|0\n"
+ "%s [options] set-card-profile CARD PROFILE\n"
+ "%s [options] set-sink-port SINK PORT\n"
+ "%s [options] set-source-port SOURCE PORT\n"
+ "%s [options] set-sink-volume SINK VOLUME\n"
+ "%s [options] set-source-volume SOURCE VOLUME\n"
+ "%s [options] set-sink-input-volume SINKINPUT VOLUME\n"
+ "%s [options] set-source-output-volume SOURCEOUTPUT VOLUME\n"
+ "%s [options] set-sink-mute SINK 1|0\n"
+ "%s [options] set-source-mute SOURCE 1|0\n"
+ "%s [options] set-sink-input-mute SINKINPUT 1|0\n"
+ "%s [options] subscribe\n\n"
+ " -h, --help Show this help\n"
+ " --version Show version\n\n"
+ " -s, --server=SERVER The name of the server to connect to\n"
+ " -n, --client-name=NAME How to call this client on the server\n"),
+ argv0, argv0, argv0, argv0, argv0,
+ argv0, argv0, argv0, argv0, argv0,
+ argv0, argv0, argv0, argv0, argv0,
+ argv0, argv0, argv0, argv0, argv0,
+ argv0, argv0, argv0, argv0);
}
-enum { ARG_VERSION = 256 };
+enum {
+ ARG_VERSION = 256
+};
int main(int argc, char *argv[]) {
- pa_mainloop* m = NULL;
- char tmp[PATH_MAX];
- int ret = 1, r, c;
- char *server = NULL, *client_name = NULL, *bn;
+ pa_mainloop *m = NULL;
+ int ret = 1, c;
+ char *server = NULL, *bn;
static const struct option long_options[] = {
{"server", 1, NULL, 's'},
@@ -633,20 +1303,27 @@ int main(int argc, char *argv[]) {
{NULL, 0, NULL, 0}
};
- if (!(bn = strrchr(argv[0], '/')))
- bn = argv[0];
- else
- bn++;
-
+ setlocale(LC_ALL, "");
+ bindtextdomain(GETTEXT_PACKAGE, PULSE_LOCALEDIR);
+
+ bn = pa_path_get_filename(argv[0]);
+
+ proplist = pa_proplist_new();
+
while ((c = getopt_long(argc, argv, "s:n:h", long_options, NULL)) != -1) {
switch (c) {
case 'h' :
help(bn);
ret = 0;
goto quit;
-
+
case ARG_VERSION:
- printf("pactl "PACKAGE_VERSION"\nCompiled with libpulse %s\nLinked with libpulse %s\n", pa_get_headers_version(), pa_get_library_version());
+ printf(_("pactl %s\n"
+ "Compiled with libpulse %s\n"
+ "Linked with libpulse %s\n"),
+ PACKAGE_VERSION,
+ pa_get_headers_version(),
+ pa_get_library_version());
ret = 0;
goto quit;
@@ -655,114 +1332,377 @@ int main(int argc, char *argv[]) {
server = pa_xstrdup(optarg);
break;
- case 'n':
- pa_xfree(client_name);
- client_name = pa_xstrdup(optarg);
+ case 'n': {
+ char *t;
+
+ if (!(t = pa_locale_to_utf8(optarg)) ||
+ pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, t) < 0) {
+
+ pa_log(_("Invalid client name '%s'"), t ? t : optarg);
+ pa_xfree(t);
+ goto quit;
+ }
+
+ pa_xfree(t);
break;
+ }
default:
goto quit;
}
}
- if (!client_name)
- client_name = pa_xstrdup(bn);
-
if (optind < argc) {
- if (!strcmp(argv[optind], "stat"))
+ if (pa_streq(argv[optind], "stat"))
action = STAT;
- else if (!strcmp(argv[optind], "exit"))
+
+ else if (pa_streq(argv[optind], "info"))
+ action = INFO;
+
+ else if (pa_streq(argv[optind], "exit"))
action = EXIT;
- else if (!strcmp(argv[optind], "list"))
+
+ else if (pa_streq(argv[optind], "list")) {
action = LIST;
- else if (!strcmp(argv[optind], "upload-sample")) {
- struct SF_INFO sfinfo;
+
+ for (int i = optind+1; i < argc; i++){
+ if (pa_streq(argv[i], "modules") || pa_streq(argv[i], "clients") ||
+ pa_streq(argv[i], "sinks") || pa_streq(argv[i], "sink-inputs") ||
+ pa_streq(argv[i], "sources") || pa_streq(argv[i], "source-outputs") ||
+ pa_streq(argv[i], "samples") || pa_streq(argv[i], "cards")) {
+ list_type = pa_xstrdup(argv[i]);
+ } else if (pa_streq(argv[i], "short")) {
+ short_list_format = TRUE;
+ } else {
+ pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, clients, samples, cards");
+ goto quit;
+ }
+ }
+
+ } else if (pa_streq(argv[optind], "upload-sample")) {
+ struct SF_INFO sfi;
action = UPLOAD_SAMPLE;
if (optind+1 >= argc) {
- fprintf(stderr, "Please specify a sample file to load\n");
+ pa_log(_("Please specify a sample file to load"));
goto quit;
}
if (optind+2 < argc)
sample_name = pa_xstrdup(argv[optind+2]);
else {
- char *f = strrchr(argv[optind+1], '/');
- size_t n;
- if (f)
- f++;
- else
- f = argv[optind];
-
- n = strcspn(f, ".");
- strncpy(tmp, f, n);
- tmp[n] = 0;
- sample_name = pa_xstrdup(tmp);
- }
-
- memset(&sfinfo, 0, sizeof(sfinfo));
- if (!(sndfile = sf_open(argv[optind+1], SFM_READ, &sfinfo))) {
- fprintf(stderr, "Failed to open sound file.\n");
- goto quit;
- }
-
- sample_spec.format = PA_SAMPLE_FLOAT32;
- sample_spec.rate = sfinfo.samplerate;
- sample_spec.channels = sfinfo.channels;
-
- sample_length = sfinfo.frames*pa_frame_size(&sample_spec);
- } else if (!strcmp(argv[optind], "play-sample")) {
+ char *f = pa_path_get_filename(argv[optind+1]);
+ sample_name = pa_xstrndup(f, strcspn(f, "."));
+ }
+
+ pa_zero(sfi);
+ if (!(sndfile = sf_open(argv[optind+1], SFM_READ, &sfi))) {
+ pa_log(_("Failed to open sound file."));
+ goto quit;
+ }
+
+ if (pa_sndfile_read_sample_spec(sndfile, &sample_spec) < 0) {
+ pa_log(_("Failed to determine sample specification from file."));
+ goto quit;
+ }
+ sample_spec.format = PA_SAMPLE_FLOAT32;
+
+ if (pa_sndfile_read_channel_map(sndfile, &channel_map) < 0) {
+ if (sample_spec.channels > 2)
+ pa_log(_("Warning: Failed to determine sample specification from file."));
+ pa_channel_map_init_extend(&channel_map, sample_spec.channels, PA_CHANNEL_MAP_DEFAULT);
+ }
+
+ pa_assert(pa_channel_map_compatible(&channel_map, &sample_spec));
+ sample_length = (size_t) sfi.frames*pa_frame_size(&sample_spec);
+
+ } else if (pa_streq(argv[optind], "play-sample")) {
action = PLAY_SAMPLE;
- if (optind+1 >= argc) {
- fprintf(stderr, "You have to specify a sample name to play\n");
+ if (argc != optind+2 && argc != optind+3) {
+ pa_log(_("You have to specify a sample name to play"));
goto quit;
}
sample_name = pa_xstrdup(argv[optind+1]);
if (optind+2 < argc)
- device = pa_xstrdup(argv[optind+2]);
-
- } else if (!strcmp(argv[optind], "remove-sample")) {
+ sink_name = pa_xstrdup(argv[optind+2]);
+
+ } else if (pa_streq(argv[optind], "remove-sample")) {
action = REMOVE_SAMPLE;
- if (optind+1 >= argc) {
- fprintf(stderr, "You have to specify a sample name to remove\n");
+ if (argc != optind+2) {
+ pa_log(_("You have to specify a sample name to remove"));
goto quit;
}
sample_name = pa_xstrdup(argv[optind+1]);
+
+ } else if (pa_streq(argv[optind], "move-sink-input")) {
+ action = MOVE_SINK_INPUT;
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a sink input index and a sink"));
+ goto quit;
+ }
+
+ sink_input_idx = (uint32_t) atoi(argv[optind+1]);
+ sink_name = pa_xstrdup(argv[optind+2]);
+
+ } else if (pa_streq(argv[optind], "move-source-output")) {
+ action = MOVE_SOURCE_OUTPUT;
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a source output index and a source"));
+ goto quit;
+ }
+
+ source_output_idx = (uint32_t) atoi(argv[optind+1]);
+ source_name = pa_xstrdup(argv[optind+2]);
+
+ } else if (pa_streq(argv[optind], "load-module")) {
+ int i;
+ size_t n = 0;
+ char *p;
+
+ action = LOAD_MODULE;
+
+ if (argc <= optind+1) {
+ pa_log(_("You have to specify a module name and arguments."));
+ goto quit;
+ }
+
+ module_name = argv[optind+1];
+
+ for (i = optind+2; i < argc; i++)
+ n += strlen(argv[i])+1;
+
+ if (n > 0) {
+ p = module_args = pa_xmalloc(n);
+
+ for (i = optind+2; i < argc; i++)
+ p += sprintf(p, "%s%s", p == module_args ? "" : " ", argv[i]);
+ }
+
+ } else if (pa_streq(argv[optind], "unload-module")) {
+ action = UNLOAD_MODULE;
+
+ if (argc != optind+2) {
+ pa_log(_("You have to specify a module index"));
+ goto quit;
+ }
+
+ module_index = (uint32_t) atoi(argv[optind+1]);
+
+ } else if (pa_streq(argv[optind], "suspend-sink")) {
+ action = SUSPEND_SINK;
+
+ if (argc > optind+3 || optind+1 >= argc) {
+ pa_log(_("You may not specify more than one sink. You have to specify a boolean value."));
+ goto quit;
+ }
+
+ suspend = pa_parse_boolean(argv[argc-1]);
+
+ if (argc > optind+2)
+ sink_name = pa_xstrdup(argv[optind+1]);
+
+ } else if (pa_streq(argv[optind], "suspend-source")) {
+ action = SUSPEND_SOURCE;
+
+ if (argc > optind+3 || optind+1 >= argc) {
+ pa_log(_("You may not specify more than one source. You have to specify a boolean value."));
+ goto quit;
+ }
+
+ suspend = pa_parse_boolean(argv[argc-1]);
+
+ if (argc > optind+2)
+ source_name = pa_xstrdup(argv[optind+1]);
+ } else if (pa_streq(argv[optind], "set-card-profile")) {
+ action = SET_CARD_PROFILE;
+
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a card name/index and a profile name"));
+ goto quit;
+ }
+
+ card_name = pa_xstrdup(argv[optind+1]);
+ profile_name = pa_xstrdup(argv[optind+2]);
+
+ } else if (pa_streq(argv[optind], "set-sink-port")) {
+ action = SET_SINK_PORT;
+
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a sink name/index and a port name"));
+ goto quit;
+ }
+
+ sink_name = pa_xstrdup(argv[optind+1]);
+ port_name = pa_xstrdup(argv[optind+2]);
+
+ } else if (pa_streq(argv[optind], "set-source-port")) {
+ action = SET_SOURCE_PORT;
+
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a source name/index and a port name"));
+ goto quit;
+ }
+
+ source_name = pa_xstrdup(argv[optind+1]);
+ port_name = pa_xstrdup(argv[optind+2]);
+
+ } else if (pa_streq(argv[optind], "set-sink-volume")) {
+ action = SET_SINK_VOLUME;
+
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a sink name/index and a volume"));
+ goto quit;
+ }
+
+ sink_name = pa_xstrdup(argv[optind+1]);
+
+ if (parse_volume(argv[optind+2], &volume, &volume_flags) < 0)
+ goto quit;
+
+ } else if (pa_streq(argv[optind], "set-source-volume")) {
+ action = SET_SOURCE_VOLUME;
+
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a source name/index and a volume"));
+ goto quit;
+ }
+
+ source_name = pa_xstrdup(argv[optind+1]);
+
+ if (parse_volume(argv[optind+2], &volume, &volume_flags) < 0)
+ goto quit;
+
+ } else if (pa_streq(argv[optind], "set-sink-input-volume")) {
+ action = SET_SINK_INPUT_VOLUME;
+
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a sink input index and a volume"));
+ goto quit;
+ }
+
+ if (pa_atou(argv[optind+1], &sink_input_idx) < 0) {
+ pa_log(_("Invalid sink input index"));
+ goto quit;
+ }
+
+ if (parse_volume(argv[optind+2], &volume, &volume_flags) < 0)
+ goto quit;
+
+ } else if (pa_streq(argv[optind], "set-source-output-volume")) {
+ action = SET_SOURCE_OUTPUT_VOLUME;
+
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a source output index and a volume"));
+ goto quit;
+ }
+
+ if (pa_atou(argv[optind+1], &source_output_idx) < 0) {
+ pa_log(_("Invalid source output index"));
+ goto quit;
+ }
+
+ if (parse_volume(argv[optind+2], &volume, &volume_flags) < 0)
+ goto quit;
+
+ } else if (pa_streq(argv[optind], "set-sink-mute")) {
+ int b;
+ action = SET_SINK_MUTE;
+
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a sink name/index and a mute boolean"));
+ goto quit;
+ }
+
+ if ((b = pa_parse_boolean(argv[optind+2])) < 0) {
+ pa_log(_("Invalid mute specification"));
+ goto quit;
+ }
+
+ sink_name = pa_xstrdup(argv[optind+1]);
+ mute = b;
+
+ } else if (pa_streq(argv[optind], "set-source-mute")) {
+ int b;
+ action = SET_SOURCE_MUTE;
+
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a source name/index and a mute boolean"));
+ goto quit;
+ }
+
+ if ((b = pa_parse_boolean(argv[optind+2])) < 0) {
+ pa_log(_("Invalid mute specification"));
+ goto quit;
+ }
+
+ source_name = pa_xstrdup(argv[optind+1]);
+ mute = b;
+
+ } else if (pa_streq(argv[optind], "set-sink-input-mute")) {
+ int b;
+ action = SET_SINK_INPUT_MUTE;
+
+ if (argc != optind+3) {
+ pa_log(_("You have to specify a sink input index and a mute boolean"));
+ goto quit;
+ }
+
+ if (pa_atou(argv[optind+1], &sink_input_idx) < 0) {
+ pa_log(_("Invalid sink input index specification"));
+ goto quit;
+ }
+
+ if ((b = pa_parse_boolean(argv[optind+2])) < 0) {
+ pa_log(_("Invalid mute specification"));
+ goto quit;
+ }
+
+ mute = b;
+
+ } else if (pa_streq(argv[optind], "subscribe"))
+
+ action = SUBSCRIBE;
+
+ else if (pa_streq(argv[optind], "help")) {
+ help(bn);
+ ret = 0;
+ goto quit;
}
}
if (action == NONE) {
- fprintf(stderr, "No valid command specified.\n");
+ pa_log(_("No valid command specified."));
goto quit;
}
if (!(m = pa_mainloop_new())) {
- fprintf(stderr, "pa_mainloop_new() failed.\n");
+ pa_log(_("pa_mainloop_new() failed."));
goto quit;
}
mainloop_api = pa_mainloop_get_api(m);
- r = pa_signal_init(mainloop_api);
- assert(r == 0);
+ pa_assert_se(pa_signal_init(mainloop_api) == 0);
pa_signal_new(SIGINT, exit_signal_callback, NULL);
-#ifdef SIGPIPE
- signal(SIGPIPE, SIG_IGN);
-#endif
-
- if (!(context = pa_context_new(mainloop_api, client_name))) {
- fprintf(stderr, "pa_context_new() failed.\n");
+ pa_signal_new(SIGTERM, exit_signal_callback, NULL);
+ pa_disable_sigpipe();
+
+ if (!(context = pa_context_new_with_proplist(mainloop_api, NULL, proplist))) {
+ pa_log(_("pa_context_new() failed."));
goto quit;
}
pa_context_set_state_callback(context, context_state_callback, NULL);
- pa_context_connect(context, server, 0, NULL);
+ if (pa_context_connect(context, server, 0, NULL) < 0) {
+ pa_log(_("pa_context_connect() failed: %s"), pa_strerror(pa_context_errno(context)));
+ goto quit;
+ }
if (pa_mainloop_run(m, &ret) < 0) {
- fprintf(stderr, "pa_mainloop_run() failed.\n");
+ pa_log(_("pa_mainloop_run() failed."));
goto quit;
}
@@ -777,13 +1717,22 @@ quit:
pa_signal_done();
pa_mainloop_free(m);
}
-
- if (sndfile)
- sf_close(sndfile);
pa_xfree(server);
- pa_xfree(device);
+ pa_xfree(list_type);
pa_xfree(sample_name);
+ pa_xfree(sink_name);
+ pa_xfree(source_name);
+ pa_xfree(module_args);
+ pa_xfree(card_name);
+ pa_xfree(profile_name);
+ pa_xfree(port_name);
+
+ if (sndfile)
+ sf_close(sndfile);
+
+ if (proplist)
+ pa_proplist_free(proplist);
return ret;
}
diff --git a/src/utils/padsp b/src/utils/padsp
index bae5a728..4fe175c2 100644..100755
--- a/src/utils/padsp
+++ b/src/utils/padsp
@@ -1,9 +1,10 @@
#!/bin/sh
-# $Id$
-#
# This file is part of PulseAudio.
#
+# Copyright 2006 Lennart Poettering
+# Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+#
# PulseAudio is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
diff --git a/src/utils/padsp.c b/src/utils/padsp.c
index 32cb5f9a..ab9d18a3 100644
--- a/src/utils/padsp.c
+++ b/src/utils/padsp.c
@@ -1,18 +1,19 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2006 Lennart Poettering
+ Copyright 2006-2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -50,8 +51,18 @@
#endif
#include <pulse/pulseaudio.h>
+#include <pulse/gccmacro.h>
#include <pulsecore/llist.h>
-#include <pulsecore/gccmacro.h>
+#include <pulsecore/core-util.h>
+
+/* On some systems SIOCINQ isn't defined, but FIONREAD is just an alias */
+#if !defined(SIOCINQ) && defined(FIONREAD)
+# define SIOCINQ FIONREAD
+#endif
+
+/* make sure gcc doesn't redefine open and friends as macros */
+#undef open
+#undef open64
typedef enum {
FD_INFO_MIXER,
@@ -64,7 +75,7 @@ struct fd_info {
pthread_mutex_t mutex;
int ref;
int unusable;
-
+
fd_info_type_t type;
int app_fd, thread_fd;
@@ -76,6 +87,8 @@ struct fd_info {
pa_context *context;
pa_stream *play_stream;
pa_stream *rec_stream;
+ int play_precork;
+ int rec_precork;
pa_io_event *io_event;
pa_io_event_flags_t io_flags;
@@ -88,7 +101,9 @@ struct fd_info {
pa_cvolume sink_volume, source_volume;
uint32_t sink_index, source_index;
int volume_modify_count;
-
+
+ int optr_n_blocks;
+
PA_LLIST_FIELDS(fd_info);
};
@@ -103,10 +118,20 @@ static PA_LLIST_HEAD(fd_info, fd_infos) = NULL;
static int (*_ioctl)(int, int, void*) = NULL;
static int (*_close)(int) = NULL;
static int (*_open)(const char *, int, mode_t) = NULL;
+static int (*___open_2)(const char *, int) = NULL;
static FILE* (*_fopen)(const char *path, const char *mode) = NULL;
+static int (*_stat)(const char *, struct stat *) = NULL;
+#ifdef _STAT_VER
+static int (*___xstat)(int, const char *, struct stat *) = NULL;
+#endif
#ifdef HAVE_OPEN64
static int (*_open64)(const char *, int, mode_t) = NULL;
+static int (*___open64_2)(const char *, int) = NULL;
static FILE* (*_fopen64)(const char *path, const char *mode) = NULL;
+static int (*_stat64)(const char *, struct stat64 *) = NULL;
+#ifdef _STAT_VER
+static int (*___xstat64)(int, const char *, struct stat64 *) = NULL;
+#endif
#endif
static int (*_fclose)(FILE *f) = NULL;
static int (*_access)(const char *, int) = NULL;
@@ -134,6 +159,14 @@ do { \
pthread_mutex_unlock(&func_mutex); \
} while(0)
+#define LOAD___OPEN_2_FUNC() \
+do { \
+ pthread_mutex_lock(&func_mutex); \
+ if (!___open_2) \
+ ___open_2 = (int (*)(const char *, int)) dlsym_fn(RTLD_NEXT, "__open_2"); \
+ pthread_mutex_unlock(&func_mutex); \
+} while(0)
+
#define LOAD_OPEN64_FUNC() \
do { \
pthread_mutex_lock(&func_mutex); \
@@ -142,6 +175,14 @@ do { \
pthread_mutex_unlock(&func_mutex); \
} while(0)
+#define LOAD___OPEN64_2_FUNC() \
+do { \
+ pthread_mutex_lock(&func_mutex); \
+ if (!___open64_2) \
+ ___open64_2 = (int (*)(const char *, int)) dlsym_fn(RTLD_NEXT, "__open64_2"); \
+ pthread_mutex_unlock(&func_mutex); \
+} while(0)
+
#define LOAD_CLOSE_FUNC() \
do { \
pthread_mutex_lock(&func_mutex); \
@@ -158,6 +199,38 @@ do { \
pthread_mutex_unlock(&func_mutex); \
} while(0)
+#define LOAD_STAT_FUNC() \
+do { \
+ pthread_mutex_lock(&func_mutex); \
+ if (!_stat) \
+ _stat = (int (*)(const char *, struct stat *)) dlsym_fn(RTLD_NEXT, "stat"); \
+ pthread_mutex_unlock(&func_mutex); \
+} while(0)
+
+#define LOAD_STAT64_FUNC() \
+do { \
+ pthread_mutex_lock(&func_mutex); \
+ if (!_stat64) \
+ _stat64 = (int (*)(const char *, struct stat64 *)) dlsym_fn(RTLD_NEXT, "stat64"); \
+ pthread_mutex_unlock(&func_mutex); \
+} while(0)
+
+#define LOAD_XSTAT_FUNC() \
+do { \
+ pthread_mutex_lock(&func_mutex); \
+ if (!___xstat) \
+ ___xstat = (int (*)(int, const char *, struct stat *)) dlsym_fn(RTLD_NEXT, "__xstat"); \
+ pthread_mutex_unlock(&func_mutex); \
+} while(0)
+
+#define LOAD_XSTAT64_FUNC() \
+do { \
+ pthread_mutex_lock(&func_mutex); \
+ if (!___xstat64) \
+ ___xstat64 = (int (*)(int, const char *, struct stat64 *)) dlsym_fn(RTLD_NEXT, "__xstat64"); \
+ pthread_mutex_unlock(&func_mutex); \
+} while(0)
+
#define LOAD_FOPEN_FUNC() \
do { \
pthread_mutex_lock(&func_mutex); \
@@ -184,32 +257,32 @@ do { \
#define CONTEXT_CHECK_DEAD_GOTO(i, label) do { \
if (!(i)->context || pa_context_get_state((i)->context) != PA_CONTEXT_READY) { \
- debug(DEBUG_LEVEL_NORMAL, __FILE__": Not connected: %s", (i)->context ? pa_strerror(pa_context_errno((i)->context)) : "NULL"); \
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": Not connected: %s\n", (i)->context ? pa_strerror(pa_context_errno((i)->context)) : "NULL"); \
goto label; \
} \
-} while(0);
+} while(0)
#define PLAYBACK_STREAM_CHECK_DEAD_GOTO(i, label) do { \
if (!(i)->context || pa_context_get_state((i)->context) != PA_CONTEXT_READY || \
!(i)->play_stream || pa_stream_get_state((i)->play_stream) != PA_STREAM_READY) { \
- debug(DEBUG_LEVEL_NORMAL, __FILE__": Not connected: %s", (i)->context ? pa_strerror(pa_context_errno((i)->context)) : "NULL"); \
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": Not connected: %s\n", (i)->context ? pa_strerror(pa_context_errno((i)->context)) : "NULL"); \
goto label; \
} \
-} while(0);
+} while(0)
#define RECORD_STREAM_CHECK_DEAD_GOTO(i, label) do { \
if (!(i)->context || pa_context_get_state((i)->context) != PA_CONTEXT_READY || \
!(i)->rec_stream || pa_stream_get_state((i)->rec_stream) != PA_STREAM_READY) { \
- debug(DEBUG_LEVEL_NORMAL, __FILE__": Not connected: %s", (i)->context ? pa_strerror(pa_context_errno((i)->context)) : "NULL"); \
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": Not connected: %s\n", (i)->context ? pa_strerror(pa_context_errno((i)->context)) : "NULL"); \
goto label; \
} \
-} while(0);
+} while(0)
static void debug(int level, const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
-#define DEBUG_LEVEL_ALWAYS 0
-#define DEBUG_LEVEL_NORMAL 1
-#define DEBUG_LEVEL_VERBOSE 2
+#define DEBUG_LEVEL_ALWAYS 0
+#define DEBUG_LEVEL_NORMAL 1
+#define DEBUG_LEVEL_VERBOSE 2
static void debug(int level, const char *format, ...) {
va_list ap;
@@ -241,26 +314,25 @@ static int padsp_disabled(void) {
* -> disable /dev/dsp emulation, bit 2 -> disable /dev/sndstat
* emulation, bit 3 -> disable /dev/mixer emulation. Hence a value
* of 7 disables padsp entirely. */
-
+
pthread_mutex_lock(&func_mutex);
if (!sym_resolved) {
sym = (int*) dlsym(RTLD_DEFAULT, "__padsp_disabled__");
sym_resolved = 1;
-
}
pthread_mutex_unlock(&func_mutex);
if (!sym)
return 0;
-
+
return *sym;
}
static int dsp_cloak_enable(void) {
if (padsp_disabled() & 1)
return 0;
-
- if (getenv("PADSP_NO_DSP"))
+
+ if (getenv("PADSP_NO_DSP") || getenv("PULSE_INTERNAL"))
return 0;
return 1;
@@ -270,7 +342,7 @@ static int sndstat_cloak_enable(void) {
if (padsp_disabled() & 2)
return 0;
- if (getenv("PADSP_NO_SNDSTAT"))
+ if (getenv("PADSP_NO_SNDSTAT") || getenv("PULSE_INTERNAL"))
return 0;
return 1;
@@ -280,7 +352,7 @@ static int mixer_cloak_enable(void) {
if (padsp_disabled() & 4)
return 0;
- if (getenv("PADSP_NO_MIXER"))
+ if (getenv("PADSP_NO_MIXER") || getenv("PULSE_INTERNAL"))
return 0;
return 1;
@@ -295,7 +367,7 @@ static int function_enter(void) {
/* Avoid recursive calls */
static pthread_once_t recursion_key_once = PTHREAD_ONCE_INIT;
pthread_once(&recursion_key_once, recursion_key_alloc);
-
+
if (pthread_getspecific(recursion_key))
return 0;
@@ -313,10 +385,10 @@ static void fd_info_free(fd_info *i) {
debug(DEBUG_LEVEL_NORMAL, __FILE__": freeing fd info (fd=%i)\n", i->app_fd);
dsp_drain(i);
-
+
if (i->mainloop)
pa_threaded_mainloop_stop(i->mainloop);
-
+
if (i->play_stream) {
pa_stream_disconnect(i->play_stream);
pa_stream_unref(i->play_stream);
@@ -331,7 +403,7 @@ static void fd_info_free(fd_info *i) {
pa_context_disconnect(i->context);
pa_context_unref(i->context);
}
-
+
if (i->mainloop)
pa_threaded_mainloop_free(i->mainloop);
@@ -353,7 +425,7 @@ static void fd_info_free(fd_info *i) {
static fd_info *fd_info_ref(fd_info *i) {
assert(i);
-
+
pthread_mutex_lock(&i->mutex);
assert(i->ref >= 1);
i->ref++;
@@ -369,7 +441,7 @@ static void fd_info_unref(fd_info *i) {
pthread_mutex_lock(&i->mutex);
assert(i->ref >= 1);
r = --i->ref;
- debug(DEBUG_LEVEL_VERBOSE, __FILE__": ref--, now %i\n", i->ref);
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": ref--, now %i\n", i->ref);
pthread_mutex_unlock(&i->mutex);
if (r <= 0)
@@ -397,7 +469,7 @@ static void context_state_cb(pa_context *c, void *userdata) {
static void reset_params(fd_info *i) {
assert(i);
-
+
i->sample_spec.format = PA_SAMPLE_U8;
i->sample_spec.channels = 1;
i->sample_spec.rate = 8000;
@@ -406,15 +478,16 @@ static void reset_params(fd_info *i) {
}
static const char *client_name(char *buf, size_t n) {
- char p[PATH_MAX];
+ char *p;
const char *e;
if ((e = getenv("PADSP_CLIENT_NAME")))
return e;
-
- if (pa_get_binary_name(p, sizeof(p)))
+
+ if ((p = pa_get_binary_name_malloc())) {
snprintf(buf, n, "OSS Emulation[%s]", p);
- else
+ pa_xfree(p);
+ } else
snprintf(buf, n, "OSS");
return buf;
@@ -433,7 +506,7 @@ static void atfork_prepare(void) {
fd_info *i;
debug(DEBUG_LEVEL_NORMAL, __FILE__": atfork_prepare() enter\n");
-
+
function_enter();
pthread_mutex_lock(&fd_infos_mutex);
@@ -445,13 +518,12 @@ static void atfork_prepare(void) {
pthread_mutex_lock(&func_mutex);
-
debug(DEBUG_LEVEL_NORMAL, __FILE__": atfork_prepare() exit\n");
}
static void atfork_parent(void) {
fd_info *i;
-
+
debug(DEBUG_LEVEL_NORMAL, __FILE__": atfork_parent() enter\n");
pthread_mutex_unlock(&func_mutex);
@@ -464,19 +536,19 @@ static void atfork_parent(void) {
pthread_mutex_unlock(&fd_infos_mutex);
function_exit();
-
+
debug(DEBUG_LEVEL_NORMAL, __FILE__": atfork_parent() exit\n");
}
static void atfork_child(void) {
fd_info *i;
-
+
debug(DEBUG_LEVEL_NORMAL, __FILE__": atfork_child() enter\n");
/* We do only the bare minimum to get all fds closed */
pthread_mutex_init(&func_mutex, NULL);
pthread_mutex_init(&fd_infos_mutex, NULL);
-
+
for (i = fd_infos; i; i = i->next) {
pthread_mutex_init(&i->mutex, NULL);
@@ -497,12 +569,14 @@ static void atfork_child(void) {
}
if (i->app_fd >= 0) {
- close(i->app_fd);
+ LOAD_CLOSE_FUNC();
+ _close(i->app_fd);
i->app_fd = -1;
}
if (i->thread_fd >= 0) {
- close(i->thread_fd);
+ LOAD_CLOSE_FUNC();
+ _close(i->thread_fd);
i->thread_fd = -1;
}
@@ -549,7 +623,7 @@ static fd_info* fd_info_new(fd_info_type_t type, int *_errno) {
signal(SIGPIPE, SIG_IGN); /* Yes, ugly as hell */
pthread_once(&install_atfork_once, install_atfork);
-
+
if (!(i = malloc(sizeof(fd_info)))) {
*_errno = ENOMEM;
goto fail;
@@ -562,6 +636,8 @@ static fd_info* fd_info_new(fd_info_type_t type, int *_errno) {
i->context = NULL;
i->play_stream = NULL;
i->rec_stream = NULL;
+ i->play_precork = 0;
+ i->rec_precork = 0;
i->io_event = NULL;
i->io_flags = 0;
pthread_mutex_init(&i->mutex, NULL);
@@ -574,6 +650,7 @@ static fd_info* fd_info_new(fd_info_type_t type, int *_errno) {
i->volume_modify_count = 0;
i->sink_index = (uint32_t) -1;
i->source_index = (uint32_t) -1;
+ i->optr_n_blocks = 0;
PA_LLIST_INIT(fd_info, i);
reset_params(i);
@@ -630,12 +707,12 @@ static fd_info* fd_info_new(fd_info_type_t type, int *_errno) {
unlock_and_fail:
pa_threaded_mainloop_unlock(i->mainloop);
-
+
fail:
if (i)
fd_info_unref(i);
-
+
return NULL;
}
@@ -663,7 +740,7 @@ static fd_info* fd_info_find(int fd) {
fd_info *i;
pthread_mutex_lock(&fd_infos_mutex);
-
+
for (i = fd_infos; i; i = i->next)
if (i->app_fd == fd && !i->unusable) {
fd_info_ref(i);
@@ -671,7 +748,7 @@ static fd_info* fd_info_find(int fd) {
}
pthread_mutex_unlock(&fd_infos_mutex);
-
+
return i;
}
@@ -692,7 +769,7 @@ static void fix_metrics(fd_info *i) {
/* Number of fragments set? */
if (i->n_fragments < 2) {
if (i->fragment_size > 0) {
- i->n_fragments = pa_bytes_per_second(&i->sample_spec) / 2 / i->fragment_size;
+ i->n_fragments = (unsigned) (pa_bytes_per_second(&i->sample_spec) / 2 / i->fragment_size);
if (i->n_fragments < 2)
i->n_fragments = 2;
} else
@@ -808,7 +885,7 @@ static int fd_info_copy_data(fd_info *i, int force) {
return -1;
}
- if (pa_stream_write(i->play_stream, i->buf, r, free, 0, PA_SEEK_RELATIVE) < 0) {
+ if (pa_stream_write(i->play_stream, i->buf, (size_t) r, free, 0LL, PA_SEEK_RELATIVE) < 0) {
debug(DEBUG_LEVEL_NORMAL, __FILE__": pa_stream_write(): %s\n", pa_strerror(pa_context_errno(i->context)));
return -1;
}
@@ -816,7 +893,7 @@ static int fd_info_copy_data(fd_info *i, int force) {
i->buf = NULL;
assert(n >= (size_t) r);
- n -= r;
+ n -= (size_t) r;
}
if (n >= i->fragment_size)
@@ -860,7 +937,7 @@ static int fd_info_copy_data(fd_info *i, int force) {
}
assert((size_t)r <= len - i->rec_offset);
- i->rec_offset += r;
+ i->rec_offset += (size_t) r;
if (i->rec_offset == len) {
if (pa_stream_drop(i->rec_stream) < 0) {
@@ -871,7 +948,7 @@ static int fd_info_copy_data(fd_info *i, int force) {
}
assert(n >= (size_t) r);
- n -= r;
+ n -= (size_t) r;
}
if (n >= i->fragment_size)
@@ -887,6 +964,10 @@ static int fd_info_copy_data(fd_info *i, int force) {
api->io_enable(i->io_event, i->io_flags);
}
+ /* So, we emptied the socket now, let's tell dsp_empty_socket()
+ * about this */
+ pa_threaded_mainloop_signal(i->mainloop, 0);
+
return 0;
}
@@ -899,9 +980,21 @@ static void stream_state_cb(pa_stream *s, void * userdata) {
case PA_STREAM_READY:
debug(DEBUG_LEVEL_NORMAL, __FILE__": stream established.\n");
break;
-
+
case PA_STREAM_FAILED:
- debug(DEBUG_LEVEL_NORMAL, __FILE__": pa_stream_connect_playback() failed: %s\n", pa_strerror(pa_context_errno(i->context)));
+ if (s == i->play_stream) {
+ debug(DEBUG_LEVEL_NORMAL,
+ __FILE__": pa_stream_connect_playback() failed: %s\n",
+ pa_strerror(pa_context_errno(i->context)));
+ pa_stream_unref(i->play_stream);
+ i->play_stream = NULL;
+ } else if (s == i->rec_stream) {
+ debug(DEBUG_LEVEL_NORMAL,
+ __FILE__": pa_stream_connect_record() failed: %s\n",
+ pa_strerror(pa_context_errno(i->context)));
+ pa_stream_unref(i->rec_stream);
+ i->rec_stream = NULL;
+ }
fd_info_shutdown(i);
break;
@@ -914,8 +1007,8 @@ static void stream_state_cb(pa_stream *s, void * userdata) {
static int create_playback_stream(fd_info *i) {
pa_buffer_attr attr;
- int n;
-
+ int n, flags;
+
assert(i);
fix_metrics(i);
@@ -930,21 +1023,26 @@ static int create_playback_stream(fd_info *i) {
pa_stream_set_latency_update_callback(i->play_stream, stream_latency_update_cb, i);
memset(&attr, 0, sizeof(attr));
- attr.maxlength = i->fragment_size * (i->n_fragments+1);
- attr.tlength = i->fragment_size * i->n_fragments;
- attr.prebuf = i->fragment_size;
- attr.minreq = i->fragment_size;
-
- if (pa_stream_connect_playback(i->play_stream, NULL, &attr, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL) < 0) {
+ attr.maxlength = (uint32_t) (i->fragment_size * (i->n_fragments+1));
+ attr.tlength = (uint32_t) (i->fragment_size * i->n_fragments);
+ attr.prebuf = (uint32_t) i->fragment_size;
+ attr.minreq = (uint32_t) i->fragment_size;
+
+ flags = PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_EARLY_REQUESTS;
+ if (i->play_precork) {
+ flags |= PA_STREAM_START_CORKED;
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": creating stream corked\n");
+ }
+ if (pa_stream_connect_playback(i->play_stream, NULL, &attr, flags, NULL, NULL) < 0) {
debug(DEBUG_LEVEL_NORMAL, __FILE__": pa_stream_connect_playback() failed: %s\n", pa_strerror(pa_context_errno(i->context)));
goto fail;
}
- n = i->fragment_size;
+ n = (int) i->fragment_size;
setsockopt(i->app_fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n));
- n = i->fragment_size;
+ n = (int) i->fragment_size;
setsockopt(i->thread_fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n));
-
+
return 0;
fail:
@@ -953,8 +1051,8 @@ fail:
static int create_record_stream(fd_info *i) {
pa_buffer_attr attr;
- int n;
-
+ int n, flags;
+
assert(i);
fix_metrics(i);
@@ -969,19 +1067,24 @@ static int create_record_stream(fd_info *i) {
pa_stream_set_latency_update_callback(i->rec_stream, stream_latency_update_cb, i);
memset(&attr, 0, sizeof(attr));
- attr.maxlength = i->fragment_size * (i->n_fragments+1);
- attr.fragsize = i->fragment_size;
-
- if (pa_stream_connect_record(i->rec_stream, NULL, &attr, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE) < 0) {
- debug(DEBUG_LEVEL_NORMAL, __FILE__": pa_stream_connect_playback() failed: %s\n", pa_strerror(pa_context_errno(i->context)));
+ attr.maxlength = (uint32_t) (i->fragment_size * (i->n_fragments+1));
+ attr.fragsize = (uint32_t) i->fragment_size;
+
+ flags = PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE;
+ if (i->rec_precork) {
+ flags |= PA_STREAM_START_CORKED;
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": creating stream corked\n");
+ }
+ if (pa_stream_connect_record(i->rec_stream, NULL, &attr, flags) < 0) {
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": pa_stream_connect_record() failed: %s\n", pa_strerror(pa_context_errno(i->context)));
goto fail;
}
- n = i->fragment_size;
+ n = (int) i->fragment_size;
setsockopt(i->app_fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n));
- n = i->fragment_size;
+ n = (int) i->fragment_size;
setsockopt(i->thread_fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n));
-
+
return 0;
fail:
@@ -995,12 +1098,21 @@ static void free_streams(fd_info *i) {
pa_stream_disconnect(i->play_stream);
pa_stream_unref(i->play_stream);
i->play_stream = NULL;
+ i->io_flags |= PA_IO_EVENT_INPUT;
}
if (i->rec_stream) {
pa_stream_disconnect(i->rec_stream);
pa_stream_unref(i->rec_stream);
i->rec_stream = NULL;
+ i->io_flags |= PA_IO_EVENT_OUTPUT;
+ }
+
+ if (i->io_event) {
+ pa_mainloop_api *api;
+
+ api = pa_threaded_mainloop_get_api(i->mainloop);
+ api->io_enable(i->io_event, i->io_flags);
}
}
@@ -1008,7 +1120,7 @@ static void io_event_cb(pa_mainloop_api *api, pa_io_event *e, int fd, pa_io_even
fd_info *i = userdata;
pa_threaded_mainloop_signal(i->mainloop, 0);
-
+
if (flags & PA_IO_EVENT_INPUT) {
if (!i->play_stream) {
@@ -1018,7 +1130,7 @@ static void io_event_cb(pa_mainloop_api *api, pa_io_event *e, int fd, pa_io_even
if (fd_info_copy_data(i, 0) < 0)
goto fail;
}
-
+
} else if (flags & PA_IO_EVENT_OUTPUT) {
if (!i->rec_stream) {
@@ -1033,7 +1145,7 @@ static void io_event_cb(pa_mainloop_api *api, pa_io_event *e, int fd, pa_io_even
goto fail;
return;
-
+
fail:
/* We can't do anything better than removing the event source */
fd_info_shutdown(i);
@@ -1083,7 +1195,7 @@ static int dsp_open(int flags, int *_errno) {
if (!(i->io_event = api->io_new(api, i->thread_fd, i->io_flags, io_event_cb, i)))
goto fail;
-
+
pa_threaded_mainloop_unlock(i->mainloop);
debug(DEBUG_LEVEL_NORMAL, __FILE__": dsp_open() succeeded, fd=%i\n", i->app_fd);
@@ -1091,7 +1203,7 @@ static int dsp_open(int flags, int *_errno) {
fd_info_add_to_list(i);
ret = i->app_fd;
fd_info_unref(i);
-
+
return ret;
fail:
@@ -1099,7 +1211,7 @@ fail:
if (i)
fd_info_unref(i);
-
+
*_errno = EIO;
debug(DEBUG_LEVEL_NORMAL, __FILE__": dsp_open() failed\n");
@@ -1110,7 +1222,7 @@ fail:
static void sink_info_cb(pa_context *context, const pa_sink_info *si, int eol, void *userdata) {
fd_info *i = userdata;
- if (!si && eol < 0) {
+ if (!si || eol < 0) {
i->operation_success = 0;
pa_threaded_mainloop_signal(i->mainloop, 0);
return;
@@ -1121,7 +1233,7 @@ static void sink_info_cb(pa_context *context, const pa_sink_info *si, int eol, v
if (!pa_cvolume_equal(&i->sink_volume, &si->volume))
i->volume_modify_count++;
-
+
i->sink_volume = si->volume;
i->sink_index = si->index;
@@ -1132,7 +1244,7 @@ static void sink_info_cb(pa_context *context, const pa_sink_info *si, int eol, v
static void source_info_cb(pa_context *context, const pa_source_info *si, int eol, void *userdata) {
fd_info *i = userdata;
- if (!si && eol < 0) {
+ if (!si || eol < 0) {
i->operation_success = 0;
pa_threaded_mainloop_signal(i->mainloop, 0);
return;
@@ -1143,7 +1255,7 @@ static void source_info_cb(pa_context *context, const pa_source_info *si, int eo
if (!pa_cvolume_equal(&i->source_volume, &si->volume))
i->volume_modify_count++;
-
+
i->source_volume = si->volume;
i->source_index = si->index;
@@ -1176,13 +1288,13 @@ static int mixer_open(int flags, int *_errno) {
debug(DEBUG_LEVEL_NORMAL, __FILE__": mixer_open()\n");
- if (!(i = fd_info_new(FD_INFO_MIXER, _errno)))
+ if (!(i = fd_info_new(FD_INFO_MIXER, _errno)))
return -1;
-
+
pa_threaded_mainloop_lock(i->mainloop);
pa_context_set_subscribe_callback(i->context, subscribe_cb, i);
-
+
if (!(o = pa_context_subscribe(i->context, PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SOURCE, context_success_cb, i))) {
debug(DEBUG_LEVEL_NORMAL, __FILE__": Failed to subscribe to events: %s", pa_strerror(pa_context_errno(i->context)));
*_errno = EIO;
@@ -1257,7 +1369,7 @@ static int mixer_open(int flags, int *_errno) {
fd_info_add_to_list(i);
ret = i->app_fd;
fd_info_unref(i);
-
+
return ret;
fail:
@@ -1268,7 +1380,7 @@ fail:
if (i)
fd_info_unref(i);
-
+
*_errno = EIO;
debug(DEBUG_LEVEL_NORMAL, __FILE__": mixer_open() failed\n");
@@ -1300,16 +1412,18 @@ static int sndstat_open(int flags, int *_errno) {
"Mixers:\n"
"0: PulseAudio Virtual OSS\n";
- char fn[] = "/tmp/padsp-sndstat-XXXXXX";
+ char *fn;
mode_t u;
int fd = -1;
int e;
+ fn = pa_sprintf_malloc("%s" PA_PATH_SEP "padsp-sndstat-XXXXXX", pa_get_temp_dir());
+
debug(DEBUG_LEVEL_NORMAL, __FILE__": sndstat_open()\n");
-
+
if (flags != O_RDONLY
#ifdef O_LARGEFILE
- && flags != (O_RDONLY|O_LARGEFILE)
+ && flags != (O_RDONLY|O_LARGEFILE)
#endif
) {
*_errno = EACCES;
@@ -1329,6 +1443,7 @@ static int sndstat_open(int flags, int *_errno) {
}
unlink(fn);
+ pa_xfree(fn);
if (write(fd, sndstat, sizeof(sndstat) -1) != sizeof(sndstat)-1) {
*_errno = errno;
@@ -1345,55 +1460,82 @@ static int sndstat_open(int flags, int *_errno) {
return fd;
fail:
+ pa_xfree(fn);
if (fd >= 0)
close(fd);
return -1;
}
-int open(const char *filename, int flags, ...) {
- va_list args;
- mode_t mode = 0;
+static int real_open(const char *filename, int flags, mode_t mode) {
int r, _errno = 0;
- debug(DEBUG_LEVEL_VERBOSE, __FILE__": open(%s)\n", filename);
-
- va_start(args, flags);
- if (flags & O_CREAT) {
- if (sizeof(mode_t) < sizeof(int))
- mode = va_arg(args, int);
- else
- mode = va_arg(args, mode_t);
- }
- va_end(args);
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": open(%s)\n", filename?filename:"NULL");
if (!function_enter()) {
LOAD_OPEN_FUNC();
return _open(filename, flags, mode);
}
- if (dsp_cloak_enable() && (strcmp(filename, "/dev/dsp") == 0 || strcmp(filename, "/dev/adsp") == 0)) {
+ if (filename && dsp_cloak_enable() && (pa_streq(filename, "/dev/dsp") || pa_streq(filename, "/dev/adsp") || pa_streq(filename, "/dev/audio")))
r = dsp_open(flags, &_errno);
- } else if (mixer_cloak_enable() && strcmp(filename, "/dev/mixer") == 0) {
+ else if (filename && mixer_cloak_enable() && pa_streq(filename, "/dev/mixer"))
r = mixer_open(flags, &_errno);
- } else if (sndstat_cloak_enable() && strcmp(filename, "/dev/sndstat") == 0) {
+ else if (filename && sndstat_cloak_enable() && pa_streq(filename, "/dev/sndstat"))
r = sndstat_open(flags, &_errno);
- } else {
+ else {
function_exit();
LOAD_OPEN_FUNC();
return _open(filename, flags, mode);
}
function_exit();
-
+
if (_errno)
errno = _errno;
-
+
return r;
}
+int open(const char *filename, int flags, ...) {
+ va_list args;
+ mode_t mode = 0;
+
+ if (flags & O_CREAT) {
+ va_start(args, flags);
+ if (sizeof(mode_t) < sizeof(int))
+ mode = (mode_t) va_arg(args, int);
+ else
+ mode = va_arg(args, mode_t);
+ va_end(args);
+ }
+
+ return real_open(filename, flags, mode);
+}
+
+static pa_bool_t is_audio_device_node(const char *path) {
+ return
+ pa_streq(path, "/dev/dsp") ||
+ pa_streq(path, "/dev/adsp") ||
+ pa_streq(path, "/dev/audio") ||
+ pa_streq(path, "/dev/sndstat") ||
+ pa_streq(path, "/dev/mixer");
+}
+
+int __open_2(const char *filename, int flags) {
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": __open_2(%s)\n", filename?filename:"NULL");
+
+ if ((flags & O_CREAT) ||
+ !filename ||
+ !is_audio_device_node(filename)) {
+ LOAD___OPEN_2_FUNC();
+ return ___open_2(filename, flags);
+ }
+ return real_open(filename, flags, 0);
+}
+
static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno) {
int ret = -1;
-
+
switch (request) {
case SOUND_MIXER_READ_DEVMASK :
debug(DEBUG_LEVEL_NORMAL, __FILE__": SOUND_MIXER_READ_DEVMASK\n");
@@ -1406,7 +1548,7 @@ static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno
*(int*) argp = SOUND_MASK_IGAIN;
break;
-
+
case SOUND_MIXER_READ_STEREODEVS:
debug(DEBUG_LEVEL_NORMAL, __FILE__": SOUND_MIXER_READ_STEREODEVS\n");
@@ -1417,7 +1559,7 @@ static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno
if (i->source_volume.channels > 1)
*(int*) argp |= SOUND_MASK_IGAIN;
pa_threaded_mainloop_unlock(i->mainloop);
-
+
break;
case SOUND_MIXER_READ_RECSRC:
@@ -1435,7 +1577,7 @@ static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno
*(int*) argp = 0;
break;
-
+
case SOUND_MIXER_READ_PCM:
case SOUND_MIXER_READ_IGAIN: {
pa_cvolume *v;
@@ -1454,7 +1596,7 @@ static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno
*(int*) argp =
((v->values[0]*100/PA_VOLUME_NORM)) |
- ((v->values[v->channels > 1 ? 1 : 0]*100/PA_VOLUME_NORM) << 8);
+ ((v->values[v->channels > 1 ? 1 : 0]*100/PA_VOLUME_NORM) << 8);
pa_threaded_mainloop_unlock(i->mainloop);
@@ -1465,14 +1607,14 @@ static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno
case SOUND_MIXER_WRITE_IGAIN: {
pa_cvolume v, *pv;
- if (request == SOUND_MIXER_READ_PCM)
+ if (request == SOUND_MIXER_WRITE_PCM)
debug(DEBUG_LEVEL_NORMAL, __FILE__": SOUND_MIXER_WRITE_PCM\n");
else
debug(DEBUG_LEVEL_NORMAL, __FILE__": SOUND_MIXER_WRITE_IGAIN\n");
pa_threaded_mainloop_lock(i->mainloop);
- if (request == SOUND_MIXER_READ_PCM) {
+ if (request == SOUND_MIXER_WRITE_PCM) {
v = i->sink_volume;
pv = &i->sink_volume;
} else {
@@ -1486,10 +1628,10 @@ static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno
if (!pa_cvolume_equal(pv, &v)) {
pa_operation *o;
- if (request == SOUND_MIXER_READ_PCM)
- o = pa_context_set_sink_volume_by_index(i->context, i->sink_index, pv, NULL, NULL);
+ if (request == SOUND_MIXER_WRITE_PCM)
+ o = pa_context_set_sink_volume_by_index(i->context, i->sink_index, pv, context_success_cb, i);
else
- o = pa_context_set_source_volume_by_index(i->context, i->source_index, pv, NULL, NULL);
+ o = pa_context_set_source_volume_by_index(i->context, i->source_index, pv, context_success_cb, i);
if (!o)
debug(DEBUG_LEVEL_NORMAL, __FILE__":Failed set volume: %s", pa_strerror(pa_context_errno(i->context)));
@@ -1498,23 +1640,23 @@ static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno
i->operation_success = 0;
while (pa_operation_get_state(o) != PA_OPERATION_DONE) {
CONTEXT_CHECK_DEAD_GOTO(i, exit_loop);
-
+
pa_threaded_mainloop_wait(i->mainloop);
}
exit_loop:
-
+
if (!i->operation_success)
debug(DEBUG_LEVEL_NORMAL, __FILE__": Failed to set volume: %s\n", pa_strerror(pa_context_errno(i->context)));
pa_operation_unref(o);
}
-
+
/* We don't wait for completion here */
i->volume_modify_count++;
}
-
+
pa_threaded_mainloop_unlock(i->mainloop);
-
+
break;
}
@@ -1531,7 +1673,7 @@ static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno
pa_threaded_mainloop_unlock(i->mainloop);
break;
}
-
+
default:
debug(DEBUG_LEVEL_NORMAL, __FILE__": unknown ioctl 0x%08lx\n", request);
@@ -1540,44 +1682,44 @@ static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno
}
ret = 0;
-
+
fail:
-
+
return ret;
}
static int map_format(int *fmt, pa_sample_spec *ss) {
-
+
switch (*fmt) {
case AFMT_MU_LAW:
ss->format = PA_SAMPLE_ULAW;
break;
-
+
case AFMT_A_LAW:
ss->format = PA_SAMPLE_ALAW;
break;
-
+
case AFMT_S8:
*fmt = AFMT_U8;
/* fall through */
case AFMT_U8:
ss->format = PA_SAMPLE_U8;
break;
-
+
case AFMT_U16_BE:
*fmt = AFMT_S16_BE;
/* fall through */
case AFMT_S16_BE:
ss->format = PA_SAMPLE_S16BE;
break;
-
+
case AFMT_U16_LE:
*fmt = AFMT_S16_LE;
/* fall through */
case AFMT_S16_LE:
ss->format = PA_SAMPLE_S16LE;
break;
-
+
default:
ss->format = PA_SAMPLE_S16NE;
*fmt = AFMT_S16_NE;
@@ -1649,14 +1791,14 @@ static int dsp_flush_socket(fd_info *i) {
static int dsp_empty_socket(fd_info *i) {
#ifdef SIOCINQ
int ret = -1;
-
+
/* Empty the socket */
for (;;) {
int l;
-
+
if (i->thread_fd < 0)
break;
-
+
if (ioctl(i->thread_fd, SIOCINQ, &l) < 0) {
debug(DEBUG_LEVEL_NORMAL, __FILE__": SIOCINQ: %s\n", strerror(errno));
break;
@@ -1666,7 +1808,7 @@ static int dsp_empty_socket(fd_info *i) {
ret = 0;
break;
}
-
+
pa_threaded_mainloop_wait(i->mainloop);
}
@@ -1683,19 +1825,19 @@ static int dsp_drain(fd_info *i) {
if (!i->mainloop)
return 0;
-
+
debug(DEBUG_LEVEL_NORMAL, __FILE__": Draining.\n");
pa_threaded_mainloop_lock(i->mainloop);
if (dsp_empty_socket(i) < 0)
goto fail;
-
+
if (!i->play_stream)
goto fail;
debug(DEBUG_LEVEL_NORMAL, __FILE__": Really draining.\n");
-
+
if (!(o = pa_stream_drain(i->play_stream, stream_success_cb, i))) {
debug(DEBUG_LEVEL_NORMAL, __FILE__": pa_stream_drain(): %s\n", pa_strerror(pa_context_errno(i->context)));
goto fail;
@@ -1704,7 +1846,7 @@ static int dsp_drain(fd_info *i) {
i->operation_success = 0;
while (pa_operation_get_state(o) != PA_OPERATION_DONE) {
PLAYBACK_STREAM_CHECK_DEAD_GOTO(i, fail);
-
+
pa_threaded_mainloop_wait(i->mainloop);
}
@@ -1714,15 +1856,15 @@ static int dsp_drain(fd_info *i) {
}
r = 0;
-
+
fail:
-
+
if (o)
pa_operation_unref(o);
pa_threaded_mainloop_unlock(i->mainloop);
- return 0;
+ return r;
}
static int dsp_trigger(fd_info *i) {
@@ -1738,7 +1880,7 @@ static int dsp_trigger(fd_info *i) {
goto fail;
debug(DEBUG_LEVEL_NORMAL, __FILE__": Triggering.\n");
-
+
if (!(o = pa_stream_trigger(i->play_stream, stream_success_cb, i))) {
debug(DEBUG_LEVEL_NORMAL, __FILE__": pa_stream_trigger(): %s\n", pa_strerror(pa_context_errno(i->context)));
goto fail;
@@ -1747,7 +1889,7 @@ static int dsp_trigger(fd_info *i) {
i->operation_success = 0;
while (!pa_operation_get_state(o) != PA_OPERATION_DONE) {
PLAYBACK_STREAM_CHECK_DEAD_GOTO(i, fail);
-
+
pa_threaded_mainloop_wait(i->mainloop);
}
@@ -1757,24 +1899,72 @@ static int dsp_trigger(fd_info *i) {
}
r = 0;
-
+
fail:
-
+
if (o)
pa_operation_unref(o);
pa_threaded_mainloop_unlock(i->mainloop);
- return 0;
+ return r;
+}
+
+static int dsp_cork(fd_info *i, pa_stream *s, int b) {
+ pa_operation *o = NULL;
+ int r = -1;
+
+ pa_threaded_mainloop_lock(i->mainloop);
+
+ if (!(o = pa_stream_cork(s, b, stream_success_cb, i))) {
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": pa_stream_cork(): %s\n", pa_strerror(pa_context_errno(i->context)));
+ goto fail;
+ }
+
+ i->operation_success = 0;
+ while (!pa_operation_get_state(o) != PA_OPERATION_DONE) {
+ if (s == i->play_stream)
+ PLAYBACK_STREAM_CHECK_DEAD_GOTO(i, fail);
+ else if (s == i->rec_stream)
+ RECORD_STREAM_CHECK_DEAD_GOTO(i, fail);
+
+ pa_threaded_mainloop_wait(i->mainloop);
+ }
+
+ if (!i->operation_success) {
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": pa_stream_cork(): %s\n", pa_strerror(pa_context_errno(i->context)));
+ goto fail;
+ }
+
+ r = 0;
+
+fail:
+
+ if (o)
+ pa_operation_unref(o);
+
+ pa_threaded_mainloop_unlock(i->mainloop);
+
+ return r;
}
static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno) {
int ret = -1;
-
+
+ if (i->thread_fd == -1) {
+ /*
+ * We've encountered some fatal error and are just waiting
+ * for a close.
+ */
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": got ioctl 0x%08lx in fatal error state\n", request);
+ *_errno = EIO;
+ return -1;
+ }
+
switch (request) {
case SNDCTL_DSP_SETFMT: {
debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_SETFMT: %i\n", *(int*) argp);
-
+
pa_threaded_mainloop_lock(i->mainloop);
if (*(int*) argp == AFMT_QUERY)
@@ -1787,12 +1977,12 @@ static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno)
pa_threaded_mainloop_unlock(i->mainloop);
break;
}
-
+
case SNDCTL_DSP_SPEED: {
pa_sample_spec ss;
int valid;
char t[256];
-
+
debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_SPEED: %i\n", *(int*) argp);
pa_threaded_mainloop_lock(i->mainloop);
@@ -1804,7 +1994,7 @@ static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno)
i->sample_spec = ss;
free_streams(i);
}
-
+
debug(DEBUG_LEVEL_NORMAL, __FILE__": ss: %s\n", pa_sample_spec_snprint(t, sizeof(t), &i->sample_spec));
pa_threaded_mainloop_unlock(i->mainloop);
@@ -1816,24 +2006,24 @@ static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno)
break;
}
-
+
case SNDCTL_DSP_STEREO:
debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_STEREO: %i\n", *(int*) argp);
-
+
pa_threaded_mainloop_lock(i->mainloop);
-
+
i->sample_spec.channels = *(int*) argp ? 2 : 1;
free_streams(i);
-
+
pa_threaded_mainloop_unlock(i->mainloop);
return 0;
case SNDCTL_DSP_CHANNELS: {
pa_sample_spec ss;
int valid;
-
+
debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_CHANNELS: %i\n", *(int*) argp);
-
+
pa_threaded_mainloop_lock(i->mainloop);
ss = i->sample_spec;
@@ -1843,7 +2033,7 @@ static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno)
i->sample_spec = ss;
free_streams(i);
}
-
+
pa_threaded_mainloop_unlock(i->mainloop);
if (!valid) {
@@ -1861,17 +2051,17 @@ static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno)
fix_metrics(i);
*(int*) argp = i->fragment_size;
-
+
pa_threaded_mainloop_unlock(i->mainloop);
-
+
break;
case SNDCTL_DSP_SETFRAGMENT:
- debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_SETFRAGMENT: 0x%8x\n", *(int*) argp);
-
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_SETFRAGMENT: 0x%08x\n", *(int*) argp);
+
pa_threaded_mainloop_lock(i->mainloop);
-
- i->fragment_size = 1 << (*(int*) argp);
+
+ i->fragment_size = 1 << ((*(int*) argp) & 31);
i->n_fragments = (*(int*) argp) >> 16;
/* 0x7FFF means that we can set whatever we like */
@@ -1879,30 +2069,30 @@ static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno)
i->n_fragments = 12;
free_streams(i);
-
+
pa_threaded_mainloop_unlock(i->mainloop);
-
+
break;
-
+
case SNDCTL_DSP_GETCAPS:
debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_CAPS\n");
-
- *(int*) argp = DSP_CAP_DUPLEX
+
+ *(int*) argp = DSP_CAP_DUPLEX | DSP_CAP_TRIGGER
#ifdef DSP_CAP_MULTI
- | DSP_CAP_MULTI
+ | DSP_CAP_MULTI
#endif
- ;
+ ;
break;
case SNDCTL_DSP_GETODELAY: {
int l;
-
+
debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_GETODELAY\n");
-
+
pa_threaded_mainloop_lock(i->mainloop);
*(int*) argp = 0;
-
+
for (;;) {
pa_usec_t usec;
@@ -1920,10 +2110,10 @@ static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno)
pa_threaded_mainloop_wait(i->mainloop);
}
-
+
exit_loop:
-#ifdef SIOCINQ
+#ifdef SIOCINQ
if (ioctl(i->thread_fd, SIOCINQ, &l) < 0)
debug(DEBUG_LEVEL_NORMAL, __FILE__": SIOCINQ failed: %s\n", strerror(errno));
else
@@ -1938,38 +2128,76 @@ static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno)
break;
}
-
+
case SNDCTL_DSP_RESET: {
debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_RESET\n");
-
+
pa_threaded_mainloop_lock(i->mainloop);
free_streams(i);
dsp_flush_socket(i);
- reset_params(i);
-
+
+ i->optr_n_blocks = 0;
+
pa_threaded_mainloop_unlock(i->mainloop);
break;
}
-
+
case SNDCTL_DSP_GETFMTS: {
debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_GETFMTS\n");
-
+
*(int*) argp = AFMT_MU_LAW|AFMT_A_LAW|AFMT_U8|AFMT_S16_LE|AFMT_S16_BE;
break;
}
case SNDCTL_DSP_POST:
debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_POST\n");
-
- if (dsp_trigger(i) < 0)
+
+ if (dsp_trigger(i) < 0)
+ *_errno = EIO;
+ break;
+
+ case SNDCTL_DSP_GETTRIGGER:
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_GETTRIGGER\n");
+
+ *(int*) argp = 0;
+ if (!i->play_precork)
+ *(int*) argp |= PCM_ENABLE_OUTPUT;
+ if (!i->rec_precork)
+ *(int*) argp |= PCM_ENABLE_INPUT;
+
+ break;
+
+ case SNDCTL_DSP_SETTRIGGER:
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_SETTRIGGER: 0x%08x\n", *(int*) argp);
+
+ if (!i->io_event) {
*_errno = EIO;
+ break;
+ }
+
+ i->play_precork = !((*(int*) argp) & PCM_ENABLE_OUTPUT);
+
+ if (i->play_stream) {
+ if (dsp_cork(i, i->play_stream, !((*(int*) argp) & PCM_ENABLE_OUTPUT)) < 0)
+ *_errno = EIO;
+ if (dsp_trigger(i) < 0)
+ *_errno = EIO;
+ }
+
+ i->rec_precork = !((*(int*) argp) & PCM_ENABLE_INPUT);
+
+ if (i->rec_stream) {
+ if (dsp_cork(i, i->rec_stream, !((*(int*) argp) & PCM_ENABLE_INPUT)) < 0)
+ *_errno = EIO;
+ }
+
break;
- case SNDCTL_DSP_SYNC:
+ case SNDCTL_DSP_SYNC:
debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_SYNC\n");
-
- if (dsp_drain(i) < 0)
+
+ if (dsp_drain(i) < 0)
*_errno = EIO;
break;
@@ -2035,16 +2263,86 @@ static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno)
break;
}
+ case SOUND_PCM_READ_RATE:
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": SOUND_PCM_READ_RATE\n");
+
+ pa_threaded_mainloop_lock(i->mainloop);
+ *(int*) argp = i->sample_spec.rate;
+ pa_threaded_mainloop_unlock(i->mainloop);
+ break;
+
+ case SOUND_PCM_READ_CHANNELS:
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": SOUND_PCM_READ_CHANNELS\n");
+
+ pa_threaded_mainloop_lock(i->mainloop);
+ *(int*) argp = i->sample_spec.channels;
+ pa_threaded_mainloop_unlock(i->mainloop);
+ break;
+
+ case SOUND_PCM_READ_BITS:
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": SOUND_PCM_READ_BITS\n");
+
+ pa_threaded_mainloop_lock(i->mainloop);
+ *(int*) argp = pa_sample_size(&i->sample_spec)*8;
+ pa_threaded_mainloop_unlock(i->mainloop);
+ break;
+
+ case SNDCTL_DSP_GETOPTR: {
+ count_info *info;
+
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_GETOPTR\n");
+
+ info = (count_info*) argp;
+ memset(info, 0, sizeof(*info));
+
+ pa_threaded_mainloop_lock(i->mainloop);
+
+ for (;;) {
+ pa_usec_t usec;
+
+ PLAYBACK_STREAM_CHECK_DEAD_GOTO(i, exit_loop2);
+
+ if (pa_stream_get_time(i->play_stream, &usec) >= 0) {
+ size_t k = pa_usec_to_bytes(usec, &i->sample_spec);
+ int m;
+
+ info->bytes = (int) k;
+ m = k / i->fragment_size;
+ info->blocks = m - i->optr_n_blocks;
+ i->optr_n_blocks = m;
+
+ break;
+ }
+
+ if (pa_context_errno(i->context) != PA_ERR_NODATA) {
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": pa_stream_get_latency(): %s\n", pa_strerror(pa_context_errno(i->context)));
+ break;
+ }
+
+ pa_threaded_mainloop_wait(i->mainloop);
+ }
+
+ exit_loop2:
+
+ pa_threaded_mainloop_unlock(i->mainloop);
+
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": GETOPTR bytes=%i, blocks=%i, ptr=%i\n", info->bytes, info->blocks, info->ptr);
+
+ break;
+ }
+
case SNDCTL_DSP_GETIPTR:
debug(DEBUG_LEVEL_NORMAL, __FILE__": invalid ioctl SNDCTL_DSP_GETIPTR\n");
goto inval;
- case SNDCTL_DSP_GETOPTR:
- debug(DEBUG_LEVEL_NORMAL, __FILE__": invalid ioctl SNDCTL_DSP_GETOPTR\n");
- goto inval;
+ case SNDCTL_DSP_SETDUPLEX:
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": SNDCTL_DSP_SETDUPLEX\n");
+ /* this is a no-op */
+ break;
default:
- debug(DEBUG_LEVEL_NORMAL, __FILE__": unknown ioctl 0x%08lx\n", request);
+ /* Mixer ioctls are valid on /dev/dsp aswell */
+ return mixer_ioctl(i, request, argp, _errno);
inval:
*_errno = EINVAL;
@@ -2052,13 +2350,17 @@ inval:
}
ret = 0;
-
+
fail:
-
+
return ret;
}
+#ifdef sun
+int ioctl(int fd, int request, ...) {
+#else
int ioctl(int fd, unsigned long request, ...) {
+#endif
fd_info *i;
va_list args;
void *argp;
@@ -2085,14 +2387,14 @@ int ioctl(int fd, unsigned long request, ...) {
r = mixer_ioctl(i, request, argp, &_errno);
else
r = dsp_ioctl(i, request, argp, &_errno);
-
+
fd_info_unref(i);
if (_errno)
errno = _errno;
function_exit();
-
+
return r;
}
@@ -2114,24 +2416,23 @@ int close(int fd) {
fd_info_remove_from_list(i);
fd_info_unref(i);
-
+
function_exit();
return 0;
}
int access(const char *pathname, int mode) {
- debug(DEBUG_LEVEL_VERBOSE, __FILE__": access(%s)\n", pathname);
- if (strcmp(pathname, "/dev/dsp") != 0 &&
- strcmp(pathname, "/dev/adsp") != 0 &&
- strcmp(pathname, "/dev/sndstat") != 0 &&
- strcmp(pathname, "/dev/mixer") != 0) {
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": access(%s)\n", pathname?pathname:"NULL");
+
+ if (!pathname ||
+ !is_audio_device_node(pathname)) {
LOAD_ACCESS_FUNC();
return _access(pathname, mode);
}
- if (mode & (W_OK | X_OK)) {
+ if (mode & X_OK) {
debug(DEBUG_LEVEL_NORMAL, __FILE__": access(%s, %x) = EACCESS\n", pathname, mode);
errno = EACCES;
return -1;
@@ -2142,43 +2443,189 @@ int access(const char *pathname, int mode) {
return 0;
}
+int stat(const char *pathname, struct stat *buf) {
#ifdef HAVE_OPEN64
+ struct stat64 parent;
+#else
+ struct stat parent;
+#endif
+ int ret;
+
+ if (!pathname ||
+ !buf ||
+ !is_audio_device_node(pathname)) {
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": stat(%s)\n", pathname?pathname:"NULL");
+ LOAD_STAT_FUNC();
+ return _stat(pathname, buf);
+ }
+
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": stat(%s)\n", pathname);
+
+#ifdef _STAT_VER
+#ifdef HAVE_OPEN64
+ ret = __xstat64(_STAT_VER, "/dev", &parent);
+#else
+ ret = __xstat(_STAT_VER, "/dev", &parent);
+#endif
+#else
+#ifdef HAVE_OPEN64
+ ret = stat64("/dev", &parent);
+#else
+ ret = stat("/dev", &parent);
+#endif
+#endif
+
+ if (ret) {
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": unable to stat \"/dev\"\n");
+ return -1;
+ }
+
+ buf->st_dev = parent.st_dev;
+ buf->st_ino = 0xDEADBEEF; /* FIXME: Can we do this in a safe way? */
+ buf->st_mode = S_IFCHR | S_IRUSR | S_IWUSR;
+ buf->st_nlink = 1;
+ buf->st_uid = getuid();
+ buf->st_gid = getgid();
+ buf->st_rdev = 0x0E03; /* FIXME: Linux specific */
+ buf->st_size = 0;
+ buf->st_atime = 1181557705;
+ buf->st_mtime = 1181557705;
+ buf->st_ctime = 1181557705;
+ buf->st_blksize = 1;
+ buf->st_blocks = 0;
+
+ return 0;
+}
+
+#ifdef HAVE_OPEN64
+
+int stat64(const char *pathname, struct stat64 *buf) {
+ struct stat oldbuf;
+ int ret;
+
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": stat64(%s)\n", pathname?pathname:"NULL");
+
+ if (!pathname ||
+ !buf ||
+ !is_audio_device_node(pathname)) {
+ LOAD_STAT64_FUNC();
+ return _stat64(pathname, buf);
+ }
+
+ ret = stat(pathname, &oldbuf);
+ if (ret)
+ return ret;
+
+ buf->st_dev = oldbuf.st_dev;
+ buf->st_ino = oldbuf.st_ino;
+ buf->st_mode = oldbuf.st_mode;
+ buf->st_nlink = oldbuf.st_nlink;
+ buf->st_uid = oldbuf.st_uid;
+ buf->st_gid = oldbuf.st_gid;
+ buf->st_rdev = oldbuf.st_rdev;
+ buf->st_size = oldbuf.st_size;
+ buf->st_atime = oldbuf.st_atime;
+ buf->st_mtime = oldbuf.st_mtime;
+ buf->st_ctime = oldbuf.st_ctime;
+ buf->st_blksize = oldbuf.st_blksize;
+ buf->st_blocks = oldbuf.st_blocks;
+
+ return 0;
+}
int open64(const char *filename, int flags, ...) {
va_list args;
mode_t mode = 0;
- debug(DEBUG_LEVEL_VERBOSE, __FILE__": open64(%s)\n", filename);
-
- va_start(args, flags);
- if (flags & O_CREAT)
- mode = va_arg(args, mode_t);
- va_end(args);
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": open64(%s)\n", filename?filename:"NULL");
+
+ if (flags & O_CREAT) {
+ va_start(args, flags);
+ if (sizeof(mode_t) < sizeof(int))
+ mode = va_arg(args, int);
+ else
+ mode = va_arg(args, mode_t);
+ va_end(args);
+ }
- if (strcmp(filename, "/dev/dsp") != 0 &&
- strcmp(filename, "/dev/adsp") != 0 &&
- strcmp(filename, "/dev/sndstat") != 0 &&
- strcmp(filename, "/dev/mixer") != 0) {
+ if (!filename ||
+ !is_audio_device_node(filename)) {
LOAD_OPEN64_FUNC();
return _open64(filename, flags, mode);
}
- return open(filename, flags, mode);
+ return real_open(filename, flags, mode);
+}
+
+int __open64_2(const char *filename, int flags) {
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": __open64_2(%s)\n", filename?filename:"NULL");
+
+ if ((flags & O_CREAT) ||
+ !filename ||
+ !is_audio_device_node(filename)) {
+ LOAD___OPEN64_2_FUNC();
+ return ___open64_2(filename, flags);
+ }
+
+ return real_open(filename, flags, 0);
+}
+
+#endif
+
+#ifdef _STAT_VER
+
+int __xstat(int ver, const char *pathname, struct stat *buf) {
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": __xstat(%s)\n", pathname?pathname:"NULL");
+
+ if (!pathname ||
+ !buf ||
+ !is_audio_device_node(pathname)) {
+ LOAD_XSTAT_FUNC();
+ return ___xstat(ver, pathname, buf);
+ }
+
+ if (ver != _STAT_VER) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ return stat(pathname, buf);
+}
+
+#ifdef HAVE_OPEN64
+
+int __xstat64(int ver, const char *pathname, struct stat64 *buf) {
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": __xstat64(%s)\n", pathname?pathname:"NULL");
+
+ if (!pathname ||
+ !buf ||
+ !is_audio_device_node(pathname)) {
+ LOAD_XSTAT64_FUNC();
+ return ___xstat64(ver, pathname, buf);
+ }
+
+ if (ver != _STAT_VER) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ return stat64(pathname, buf);
}
#endif
+#endif
+
FILE* fopen(const char *filename, const char *mode) {
FILE *f = NULL;
int fd;
mode_t m;
-
- debug(DEBUG_LEVEL_VERBOSE, __FILE__": fopen(%s)\n", filename);
- if (strcmp(filename, "/dev/dsp") != 0 &&
- strcmp(filename, "/dev/adsp") != 0 &&
- strcmp(filename, "/dev/sndstat") != 0 &&
- strcmp(filename, "/dev/mixer") != 0) {
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": fopen(%s)\n", filename?filename:"NULL");
+
+ if (!filename ||
+ !mode ||
+ !is_audio_device_node(filename)) {
LOAD_FOPEN_FUNC();
return _fopen(filename, mode);
}
@@ -2199,14 +2646,14 @@ FILE* fopen(const char *filename, const char *mode) {
if ((((mode[1] == 'b') || (mode[1] == 't')) && (mode[2] == '+')) || (mode[1] == '+'))
m = O_RDWR;
- if ((fd = open(filename, m)) < 0)
+ if ((fd = real_open(filename, m, 0)) < 0)
return NULL;
if (!(f = fdopen(fd, mode))) {
close(fd);
return NULL;
}
-
+
return f;
}
@@ -2214,12 +2661,11 @@ FILE* fopen(const char *filename, const char *mode) {
FILE *fopen64(const char *filename, const char *mode) {
- debug(DEBUG_LEVEL_VERBOSE, __FILE__": fopen64(%s)\n", filename);
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": fopen64(%s)\n", filename?filename:"NULL");
- if (strcmp(filename, "/dev/dsp") != 0 &&
- strcmp(filename, "/dev/adsp") != 0 &&
- strcmp(filename, "/dev/sndstat") != 0 &&
- strcmp(filename, "/dev/mixer") != 0) {
+ if (!filename ||
+ !mode ||
+ !is_audio_device_node(filename)) {
LOAD_FOPEN64_FUNC();
return _fopen64(filename, mode);
}
@@ -2250,9 +2696,9 @@ int fclose(FILE *f) {
/* Dirty trick to avoid that the fd is not freed twice, once by us
* and once by the real fclose() */
i->app_fd = -1;
-
+
fd_info_unref(i);
-
+
function_exit();
LOAD_FCLOSE_FUNC();
diff --git a/src/utils/paplay.c b/src/utils/paplay.c
deleted file mode 100644
index 7b34016c..00000000
--- a/src/utils/paplay.c
+++ /dev/null
@@ -1,432 +0,0 @@
-/* $Id$ */
-
-/***
- This file is part of PulseAudio.
-
- PulseAudio is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
- or (at your option) any later version.
-
- PulseAudio is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with PulseAudio; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <signal.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <getopt.h>
-#include <locale.h>
-
-#include <sndfile.h>
-
-#include <pulse/pulseaudio.h>
-
-#if PA_API_VERSION != 9
-#error Invalid PulseAudio API version
-#endif
-
-static pa_context *context = NULL;
-static pa_stream *stream = NULL;
-static pa_mainloop_api *mainloop_api = NULL;
-
-static char *stream_name = NULL, *client_name = NULL, *device = NULL;
-
-static int verbose = 0;
-static pa_volume_t volume = PA_VOLUME_NORM;
-
-static SNDFILE* sndfile = NULL;
-
-static pa_sample_spec sample_spec = { 0, 0, 0 };
-static pa_channel_map channel_map;
-static int channel_map_set = 0;
-
-static sf_count_t (*readf_function)(SNDFILE *_sndfile, void *ptr, sf_count_t frames) = NULL;
-
-/* A shortcut for terminating the application */
-static void quit(int ret) {
- assert(mainloop_api);
- mainloop_api->quit(mainloop_api, ret);
-}
-
-/* Connection draining complete */
-static void context_drain_complete(pa_context*c, void *userdata) {
- pa_context_disconnect(c);
-}
-
-/* Stream draining complete */
-static void stream_drain_complete(pa_stream*s, int success, void *userdata) {
- pa_operation *o;
-
- if (!success) {
- fprintf(stderr, "Failed to drain stream: %s\n", pa_strerror(pa_context_errno(context)));
- quit(1);
- }
-
- if (verbose)
- fprintf(stderr, "Playback stream drained.\n");
-
- pa_stream_disconnect(stream);
- pa_stream_unref(stream);
- stream = NULL;
-
- if (!(o = pa_context_drain(context, context_drain_complete, NULL)))
- pa_context_disconnect(context);
- else {
- pa_operation_unref(o);
-
- if (verbose)
- fprintf(stderr, "Draining connection to server.\n");
- }
-}
-
-/* This is called whenever new data may be written to the stream */
-static void stream_write_callback(pa_stream *s, size_t length, void *userdata) {
- sf_count_t bytes;
- void *data;
- assert(s && length);
-
- if (!sndfile)
- return;
-
- data = pa_xmalloc(length);
-
- if (readf_function) {
- size_t k = pa_frame_size(&sample_spec);
-
- if ((bytes = readf_function(sndfile, data, length/k)) > 0)
- bytes *= k;
-
- } else
- bytes = sf_read_raw(sndfile, data, length);
-
- if (bytes > 0)
- pa_stream_write(s, data, bytes, pa_xfree, 0, PA_SEEK_RELATIVE);
- else
- pa_xfree(data);
-
- if (bytes < length) {
- sf_close(sndfile);
- sndfile = NULL;
- pa_operation_unref(pa_stream_drain(s, stream_drain_complete, NULL));
- }
-}
-
-/* This routine is called whenever the stream state changes */
-static void stream_state_callback(pa_stream *s, void *userdata) {
- assert(s);
-
- switch (pa_stream_get_state(s)) {
- case PA_STREAM_CREATING:
- case PA_STREAM_TERMINATED:
- break;
-
- case PA_STREAM_READY:
- if (verbose)
- fprintf(stderr, "Stream successfully created\n");
- break;
-
- case PA_STREAM_FAILED:
- default:
- fprintf(stderr, "Stream errror: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s))));
- quit(1);
- }
-}
-
-/* This is called whenever the context status changes */
-static void context_state_callback(pa_context *c, void *userdata) {
- assert(c);
-
- switch (pa_context_get_state(c)) {
- case PA_CONTEXT_CONNECTING:
- case PA_CONTEXT_AUTHORIZING:
- case PA_CONTEXT_SETTING_NAME:
- break;
-
- case PA_CONTEXT_READY: {
- pa_cvolume cv;
-
- assert(c && !stream);
-
- if (verbose)
- fprintf(stderr, "Connection established.\n");
-
- stream = pa_stream_new(c, stream_name, &sample_spec, channel_map_set ? &channel_map : NULL);
- assert(stream);
-
- pa_stream_set_state_callback(stream, stream_state_callback, NULL);
- pa_stream_set_write_callback(stream, stream_write_callback, NULL);
- pa_stream_connect_playback(stream, device, NULL, 0, pa_cvolume_set(&cv, sample_spec.channels, volume), NULL);
-
- break;
- }
-
- case PA_CONTEXT_TERMINATED:
- quit(0);
- break;
-
- case PA_CONTEXT_FAILED:
- default:
- fprintf(stderr, "Connection failure: %s\n", pa_strerror(pa_context_errno(c)));
- quit(1);
- }
-}
-
-/* UNIX signal to quit recieved */
-static void exit_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
- if (verbose)
- fprintf(stderr, "Got SIGINT, exiting.\n");
- quit(0);
-
-}
-
-static void help(const char *argv0) {
-
- printf("%s [options] [FILE]\n\n"
- " -h, --help Show this help\n"
- " --version Show version\n\n"
- " -v, --verbose Enable verbose operations\n\n"
- " -s, --server=SERVER The name of the server to connect to\n"
- " -d, --device=DEVICE The name of the sink/source to connect to\n"
- " -n, --client-name=NAME How to call this client on the server\n"
- " --stream-name=NAME How to call this stream on the server\n"
- " --volume=VOLUME Specify the initial (linear) volume in range 0...65536\n"
- " --channel-map=CHANNELMAP Set the channel map to the use\n",
- argv0);
-}
-
-enum {
- ARG_VERSION = 256,
- ARG_STREAM_NAME,
- ARG_VOLUME,
- ARG_CHANNELMAP
-};
-
-int main(int argc, char *argv[]) {
- pa_mainloop* m = NULL;
- int ret = 1, r, c;
- char *bn, *server = NULL;
- const char *filename;
- SF_INFO sfinfo;
-
- static const struct option long_options[] = {
- {"device", 1, NULL, 'd'},
- {"server", 1, NULL, 's'},
- {"client-name", 1, NULL, 'n'},
- {"stream-name", 1, NULL, ARG_STREAM_NAME},
- {"version", 0, NULL, ARG_VERSION},
- {"help", 0, NULL, 'h'},
- {"verbose", 0, NULL, 'v'},
- {"volume", 1, NULL, ARG_VOLUME},
- {"channel-map", 1, NULL, ARG_CHANNELMAP},
- {NULL, 0, NULL, 0}
- };
-
- setlocale(LC_ALL, "");
-
- if (!(bn = strrchr(argv[0], '/')))
- bn = argv[0];
- else
- bn++;
-
- while ((c = getopt_long(argc, argv, "d:s:n:hv", long_options, NULL)) != -1) {
-
- switch (c) {
- case 'h' :
- help(bn);
- ret = 0;
- goto quit;
-
- case ARG_VERSION:
- printf("paplay "PACKAGE_VERSION"\nCompiled with libpulse %s\nLinked with libpulse %s\n", pa_get_headers_version(), pa_get_library_version());
- ret = 0;
- goto quit;
-
- case 'd':
- pa_xfree(device);
- device = pa_xstrdup(optarg);
- break;
-
- case 's':
- pa_xfree(server);
- server = pa_xstrdup(optarg);
- break;
-
- case 'n':
- pa_xfree(client_name);
- client_name = pa_xstrdup(optarg);
- break;
-
- case ARG_STREAM_NAME:
- pa_xfree(stream_name);
- stream_name = pa_xstrdup(optarg);
- break;
-
- case 'v':
- verbose = 1;
- break;
-
- case ARG_VOLUME: {
- int v = atoi(optarg);
- volume = v < 0 ? 0 : v;
- break;
- }
-
- case ARG_CHANNELMAP:
- if (!pa_channel_map_parse(&channel_map, optarg)) {
- fprintf(stderr, "Invalid channel map\n");
- goto quit;
- }
-
- channel_map_set = 1;
- break;
-
- default:
- goto quit;
- }
- }
-
- filename = optind < argc ? argv[optind] : "STDIN";
-
- memset(&sfinfo, 0, sizeof(sfinfo));
-
- if (optind < argc)
- sndfile = sf_open(filename, SFM_READ, &sfinfo);
- else
- sndfile = sf_open_fd(STDIN_FILENO, SFM_READ, &sfinfo, 0);
-
- if (!sndfile) {
- fprintf(stderr, "Failed to open file '%s'\n", filename);
- goto quit;
- }
-
- sample_spec.rate = sfinfo.samplerate;
- sample_spec.channels = sfinfo.channels;
-
- readf_function = NULL;
-
- switch (sfinfo.format & 0xFF) {
- case SF_FORMAT_PCM_16:
- case SF_FORMAT_PCM_U8:
- case SF_FORMAT_PCM_S8:
- sample_spec.format = PA_SAMPLE_S16NE;
- readf_function = (sf_count_t (*)(SNDFILE *_sndfile, void *ptr, sf_count_t frames)) sf_readf_short;
- break;
-
- case SF_FORMAT_ULAW:
- sample_spec.format = PA_SAMPLE_ULAW;
- break;
-
- case SF_FORMAT_ALAW:
- sample_spec.format = PA_SAMPLE_ALAW;
- break;
-
- case SF_FORMAT_FLOAT:
- case SF_FORMAT_DOUBLE:
- default:
- sample_spec.format = PA_SAMPLE_FLOAT32NE;
- readf_function = (sf_count_t (*)(SNDFILE *_sndfile, void *ptr, sf_count_t frames)) sf_readf_float;
- break;
- }
-
- assert(pa_sample_spec_valid(&sample_spec));
-
- if (channel_map_set && channel_map.channels != sample_spec.channels) {
- fprintf(stderr, "Channel map doesn't match file.\n");
- goto quit;
- }
-
- if (!client_name) {
- client_name = pa_locale_to_utf8(bn);
- if (!client_name)
- client_name = pa_utf8_filter(bn);
- }
-
- if (!stream_name) {
- const char *n;
-
- n = sf_get_string(sndfile, SF_STR_TITLE);
-
- if (!n)
- n = filename;
-
- stream_name = pa_locale_to_utf8(n);
- if (!stream_name)
- stream_name = pa_utf8_filter(n);
- }
-
- if (verbose) {
- char t[PA_SAMPLE_SPEC_SNPRINT_MAX];
- pa_sample_spec_snprint(t, sizeof(t), &sample_spec);
- fprintf(stderr, "Using sample spec '%s'\n", t);
- }
-
- /* Set up a new main loop */
- if (!(m = pa_mainloop_new())) {
- fprintf(stderr, "pa_mainloop_new() failed.\n");
- goto quit;
- }
-
- mainloop_api = pa_mainloop_get_api(m);
-
- r = pa_signal_init(mainloop_api);
- assert(r == 0);
- pa_signal_new(SIGINT, exit_signal_callback, NULL);
-#ifdef SIGPIPE
- signal(SIGPIPE, SIG_IGN);
-#endif
-
- /* Create a new connection context */
- if (!(context = pa_context_new(mainloop_api, client_name))) {
- 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, server, 0, NULL);
-
- /* Run the main loop */
- if (pa_mainloop_run(m, &ret) < 0) {
- fprintf(stderr, "pa_mainloop_run() failed.\n");
- goto quit;
- }
-
-quit:
- if (stream)
- pa_stream_unref(stream);
-
- if (context)
- pa_context_unref(context);
-
- if (m) {
- pa_signal_done();
- pa_mainloop_free(m);
- }
-
- pa_xfree(server);
- pa_xfree(device);
- pa_xfree(client_name);
- pa_xfree(stream_name);
-
- if (sndfile)
- sf_close(sndfile);
-
- return ret;
-}
diff --git a/src/utils/pasuspender.c b/src/utils/pasuspender.c
new file mode 100644
index 00000000..e1ee2512
--- /dev/null
+++ b/src/utils/pasuspender.c
@@ -0,0 +1,314 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2004-2006 Lennart Poettering
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <signal.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <locale.h>
+
+#ifdef __linux__
+#include <sys/prctl.h>
+#endif
+
+#include <pulse/i18n.h>
+#include <pulse/pulseaudio.h>
+#include <pulsecore/macro.h>
+
+static pa_context *context = NULL;
+static pa_mainloop_api *mainloop_api = NULL;
+static char **child_argv = NULL;
+static int child_argc = 0;
+static pid_t child_pid = (pid_t) -1;
+static int child_ret = 0;
+static int dead = 1;
+
+static void quit(int ret) {
+ pa_assert(mainloop_api);
+ mainloop_api->quit(mainloop_api, ret);
+}
+
+
+static void context_drain_complete(pa_context *c, void *userdata) {
+ pa_context_disconnect(c);
+}
+
+static void drain(void) {
+ pa_operation *o;
+
+ if (!(o = pa_context_drain(context, context_drain_complete, NULL)))
+ pa_context_disconnect(context);
+ else
+ pa_operation_unref(o);
+}
+
+static void start_child(void) {
+
+ if ((child_pid = fork()) < 0) {
+
+ fprintf(stderr, _("fork(): %s\n"), strerror(errno));
+ quit(1);
+
+ } else if (child_pid == 0) {
+ /* Child */
+
+#ifdef __linux__
+ prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0);
+#endif
+
+ if (execvp(child_argv[0], child_argv) < 0)
+ fprintf(stderr, _("execvp(): %s\n"), strerror(errno));
+
+ _exit(1);
+
+ } else {
+
+ /* parent */
+ dead = 0;
+ }
+}
+
+static void suspend_complete(pa_context *c, int success, void *userdata) {
+ static int n = 0;
+
+ n++;
+
+ if (!success) {
+ fprintf(stderr, _("Failure to suspend: %s\n"), pa_strerror(pa_context_errno(c)));
+ quit(1);
+ return;
+ }
+
+ if (n >= 2)
+ start_child();
+}
+
+static void resume_complete(pa_context *c, int success, void *userdata) {
+ static int n = 0;
+
+ n++;
+
+ if (!success) {
+ fprintf(stderr, _("Failure to resume: %s\n"), pa_strerror(pa_context_errno(c)));
+ quit(1);
+ return;
+ }
+
+ if (n >= 2)
+ drain(); /* drain and quit */
+}
+
+static void context_state_callback(pa_context *c, void *userdata) {
+ pa_assert(c);
+
+ switch (pa_context_get_state(c)) {
+ case PA_CONTEXT_CONNECTING:
+ case PA_CONTEXT_AUTHORIZING:
+ case PA_CONTEXT_SETTING_NAME:
+ break;
+
+ case PA_CONTEXT_READY:
+ if (pa_context_is_local(c)) {
+ pa_operation_unref(pa_context_suspend_sink_by_index(c, PA_INVALID_INDEX, 1, suspend_complete, NULL));
+ pa_operation_unref(pa_context_suspend_source_by_index(c, PA_INVALID_INDEX, 1, suspend_complete, NULL));
+ } else {
+ fprintf(stderr, _("WARNING: Sound server is not local, not suspending.\n"));
+ start_child();
+ }
+
+ break;
+
+ case PA_CONTEXT_TERMINATED:
+ quit(0);
+ break;
+
+ case PA_CONTEXT_FAILED:
+ default:
+ fprintf(stderr, _("Connection failure: %s\n"), pa_strerror(pa_context_errno(c)));
+
+ pa_context_unref(context);
+ context = NULL;
+
+ if (child_pid == (pid_t) -1)
+ /* not started yet, then we do it now */
+ start_child();
+ else if (dead)
+ /* already started, and dead, so let's quit */
+ quit(1);
+
+ break;
+ }
+}
+
+static void sigint_callback(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) {
+ fprintf(stderr, _("Got SIGINT, exiting.\n"));
+ quit(0);
+}
+
+static void sigchld_callback(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) {
+ int status = 0;
+ pid_t p;
+
+ p = waitpid(-1, &status, WNOHANG);
+
+ if (p != child_pid)
+ return;
+
+ dead = 1;
+
+ if (WIFEXITED(status))
+ child_ret = WEXITSTATUS(status);
+ else if (WIFSIGNALED(status)) {
+ fprintf(stderr, _("WARNING: Child process terminated by signal %u\n"), WTERMSIG(status));
+ child_ret = 1;
+ }
+
+ if (context) {
+ if (pa_context_is_local(context)) {
+ /* A context is around, so let's resume */
+ pa_operation_unref(pa_context_suspend_sink_by_index(context, PA_INVALID_INDEX, 0, resume_complete, NULL));
+ pa_operation_unref(pa_context_suspend_source_by_index(context, PA_INVALID_INDEX, 0, resume_complete, NULL));
+ } else
+ drain();
+ } else
+ /* Hmm, no context here, so let's terminate right away */
+ quit(0);
+}
+
+static void help(const char *argv0) {
+
+ printf(_("%s [options] ... \n\n"
+ " -h, --help Show this help\n"
+ " --version Show version\n"
+ " -s, --server=SERVER The name of the server to connect to\n\n"),
+ argv0);
+}
+
+enum {
+ ARG_VERSION = 256
+};
+
+int main(int argc, char *argv[]) {
+ pa_mainloop* m = NULL;
+ int c, ret = 1;
+ char *server = NULL, *bn;
+
+ static const struct option long_options[] = {
+ {"server", 1, NULL, 's'},
+ {"version", 0, NULL, ARG_VERSION},
+ {"help", 0, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(GETTEXT_PACKAGE, PULSE_LOCALEDIR);
+
+ bn = pa_path_get_filename(argv[0]);
+
+ while ((c = getopt_long(argc, argv, "s:h", long_options, NULL)) != -1) {
+ switch (c) {
+ case 'h' :
+ help(bn);
+ ret = 0;
+ goto quit;
+
+ case ARG_VERSION:
+ printf(_("pasuspender %s\n"
+ "Compiled with libpulse %s\n"
+ "Linked with libpulse %s\n"),
+ PACKAGE_VERSION,
+ pa_get_headers_version(),
+ pa_get_library_version());
+ ret = 0;
+ goto quit;
+
+ case 's':
+ pa_xfree(server);
+ server = pa_xstrdup(optarg);
+ break;
+
+ default:
+ goto quit;
+ }
+ }
+
+ child_argv = argv + optind;
+ child_argc = argc - optind;
+
+ if (child_argc <= 0) {
+ help(bn);
+ ret = 0;
+ goto quit;
+ }
+
+ if (!(m = pa_mainloop_new())) {
+ fprintf(stderr, _("pa_mainloop_new() failed.\n"));
+ goto quit;
+ }
+
+ pa_assert_se(mainloop_api = pa_mainloop_get_api(m));
+ pa_assert_se(pa_signal_init(mainloop_api) == 0);
+ pa_signal_new(SIGINT, sigint_callback, NULL);
+ pa_signal_new(SIGCHLD, sigchld_callback, NULL);
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_IGN);
+#endif
+
+ 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);
+ pa_context_connect(context, server, PA_CONTEXT_NOAUTOSPAWN, NULL);
+
+ if (pa_mainloop_run(m, &ret) < 0) {
+ fprintf(stderr, _("pa_mainloop_run() failed.\n"));
+ goto quit;
+ }
+
+quit:
+ if (context)
+ pa_context_unref(context);
+
+ if (m) {
+ pa_signal_done();
+ pa_mainloop_free(m);
+ }
+
+ pa_xfree(server);
+
+ if (!dead)
+ kill(child_pid, SIGTERM);
+
+ return ret == 0 ? child_ret : ret;
+}
diff --git a/src/utils/pax11publish.c b/src/utils/pax11publish.c
index 2a0d21d6..41361a15 100644
--- a/src/utils/pax11publish.c
+++ b/src/utils/pax11publish.c
@@ -1,18 +1,18 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -25,13 +25,14 @@
#include <stdio.h>
#include <getopt.h>
-#include <string.h>
#include <assert.h>
+#include <locale.h>
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
+#include <xcb/xcb.h>
#include <pulse/util.h>
+#include <pulse/i18n.h>
+#include <pulse/client-conf.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
@@ -39,25 +40,27 @@
#include <pulsecore/native-common.h>
#include <pulsecore/x11prop.h>
-#include "../pulse/client-conf.h"
int main(int argc, char *argv[]) {
const char *dname = NULL, *sink = NULL, *source = NULL, *server = NULL, *cookie_file = PA_NATIVE_COOKIE_FILE;
- int c, ret = 1;
- Display *d = NULL;
+ int c, ret = 1, screen = 0;
+ xcb_connection_t *xcb = NULL;
enum { DUMP, EXPORT, IMPORT, REMOVE } mode = DUMP;
+ setlocale(LC_ALL, "");
+ bindtextdomain(GETTEXT_PACKAGE, PULSE_LOCALEDIR);
+
while ((c = getopt(argc, argv, "deiD:S:O:I:c:hr")) != -1) {
switch (c) {
case 'D' :
dname = optarg;
break;
case 'h':
- printf("%s [-D display] [-S server] [-O sink] [-I source] [-c file] [-d|-e|-i|-r]\n\n"
+ printf(_("%s [-D display] [-S server] [-O sink] [-I source] [-c file] [-d|-e|-i|-r]\n\n"
" -d Show current PulseAudio data attached to X11 display (default)\n"
" -e Export local PulseAudio data to X11 display\n"
" -i Import PulseAudio data from X11 display to local environment variables and cookie file.\n"
- " -r Remove PulseAudio data from X11 display\n",
+ " -r Remove PulseAudio data from X11 display\n"),
pa_path_get_filename(argv[0]));
ret = 0;
goto finish;
@@ -86,50 +89,55 @@ int main(int argc, char *argv[]) {
server = optarg;
break;
default:
- fprintf(stderr, "Failed to parse command line.\n");
+ fprintf(stderr, _("Failed to parse command line.\n"));
goto finish;
}
}
- if (!(d = XOpenDisplay(dname))) {
- pa_log(__FILE__": XOpenDisplay() failed");
+ if (!(xcb = xcb_connect(dname, &screen))) {
+ pa_log(_("xcb_connect() failed"));
+ goto finish;
+ }
+
+ if (xcb_connection_has_error(xcb)) {
+ pa_log(_("xcb_connection_has_error() returned true"));
goto finish;
}
switch (mode) {
case DUMP: {
char t[1024];
- if (pa_x11_get_prop(d, "PULSE_SERVER", t, sizeof(t)))
- printf("Server: %s\n", t);
- if (pa_x11_get_prop(d, "PULSE_SOURCE", t, sizeof(t)))
- printf("Source: %s\n", t);
- if (pa_x11_get_prop(d, "PULSE_SINK", t, sizeof(t)))
- printf("Sink: %s\n", t);
- if (pa_x11_get_prop(d, "PULSE_COOKIE", t, sizeof(t)))
- printf("Cookie: %s\n", t);
+ if (pa_x11_get_prop(xcb, screen, "PULSE_SERVER", t, sizeof(t)))
+ printf(_("Server: %s\n"), t);
+ if (pa_x11_get_prop(xcb, screen, "PULSE_SOURCE", t, sizeof(t)))
+ printf(_("Source: %s\n"), t);
+ if (pa_x11_get_prop(xcb, screen, "PULSE_SINK", t, sizeof(t)))
+ printf(_("Sink: %s\n"), t);
+ if (pa_x11_get_prop(xcb, screen, "PULSE_COOKIE", t, sizeof(t)))
+ printf(_("Cookie: %s\n"), t);
break;
}
-
+
case IMPORT: {
char t[1024];
- if (pa_x11_get_prop(d, "PULSE_SERVER", t, sizeof(t)))
+ if (pa_x11_get_prop(xcb, screen, "PULSE_SERVER", t, sizeof(t)))
printf("PULSE_SERVER='%s'\nexport PULSE_SERVER\n", t);
- if (pa_x11_get_prop(d, "PULSE_SOURCE", t, sizeof(t)))
+ if (pa_x11_get_prop(xcb, screen, "PULSE_SOURCE", t, sizeof(t)))
printf("PULSE_SOURCE='%s'\nexport PULSE_SOURCE\n", t);
- if (pa_x11_get_prop(d, "PULSE_SINK", t, sizeof(t)))
+ if (pa_x11_get_prop(xcb, screen, "PULSE_SINK", t, sizeof(t)))
printf("PULSE_SINK='%s'\nexport PULSE_SINK\n", t);
- if (pa_x11_get_prop(d, "PULSE_COOKIE", t, sizeof(t))) {
+ if (pa_x11_get_prop(xcb, screen, "PULSE_COOKIE", t, sizeof(t))) {
uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
size_t l;
if ((l = pa_parsehex(t, cookie, sizeof(cookie))) != sizeof(cookie)) {
- fprintf(stderr, "Failed to parse cookie data\n");
+ fprintf(stderr, _("Failed to parse cookie data\n"));
goto finish;
}
if (pa_authkey_save(cookie_file, cookie, l) < 0) {
- fprintf(stderr, "Failed to save cookie data\n");
+ fprintf(stderr, _("Failed to save cookie data\n"));
goto finish;
}
}
@@ -144,77 +152,78 @@ int main(int argc, char *argv[]) {
assert(conf);
if (pa_client_conf_load(conf, NULL) < 0) {
- fprintf(stderr, "Failed to load client configuration file.\n");
+ fprintf(stderr, _("Failed to load client configuration file.\n"));
goto finish;
}
if (pa_client_conf_env(conf) < 0) {
- fprintf(stderr, "Failed to read environment configuration data.\n");
+ fprintf(stderr, _("Failed to read environment configuration data.\n"));
goto finish;
}
- pa_x11_del_prop(d, "PULSE_SERVER");
- pa_x11_del_prop(d, "PULSE_SINK");
- pa_x11_del_prop(d, "PULSE_SOURCE");
- pa_x11_del_prop(d, "PULSE_ID");
- pa_x11_del_prop(d, "PULSE_COOKIE");
-
+ pa_x11_del_prop(xcb, screen, "PULSE_SERVER");
+ pa_x11_del_prop(xcb, screen, "PULSE_SINK");
+ pa_x11_del_prop(xcb, screen, "PULSE_SOURCE");
+ pa_x11_del_prop(xcb, screen, "PULSE_ID");
+ pa_x11_del_prop(xcb, screen, "PULSE_COOKIE");
+
if (server)
- pa_x11_set_prop(d, "PULSE_SERVER", server);
+ pa_x11_set_prop(xcb, screen, "PULSE_SERVER", server);
else if (conf->default_server)
- pa_x11_set_prop(d, "PULSE_SERVER", conf->default_server);
+ pa_x11_set_prop(xcb, screen, "PULSE_SERVER", conf->default_server);
else {
char hn[256];
if (!pa_get_fqdn(hn, sizeof(hn))) {
- fprintf(stderr, "Failed to get FQDN.\n");
+ fprintf(stderr, _("Failed to get FQDN.\n"));
goto finish;
}
-
- pa_x11_set_prop(d, "PULSE_SERVER", hn);
+
+ pa_x11_set_prop(xcb, screen, "PULSE_SERVER", hn);
}
if (sink)
- pa_x11_set_prop(d, "PULSE_SINK", sink);
+ pa_x11_set_prop(xcb, screen, "PULSE_SINK", sink);
else if (conf->default_sink)
- pa_x11_set_prop(d, "PULSE_SINK", conf->default_sink);
+ pa_x11_set_prop(xcb, screen, "PULSE_SINK", conf->default_sink);
if (source)
- pa_x11_set_prop(d, "PULSE_SOURCE", source);
+ pa_x11_set_prop(xcb, screen, "PULSE_SOURCE", source);
if (conf->default_source)
- pa_x11_set_prop(d, "PULSE_SOURCE", conf->default_source);
+ pa_x11_set_prop(xcb, screen, "PULSE_SOURCE", conf->default_source);
pa_client_conf_free(conf);
-
+
if (pa_authkey_load_auto(cookie_file, cookie, sizeof(cookie)) < 0) {
- fprintf(stderr, "Failed to load cookie data\n");
+ fprintf(stderr, _("Failed to load cookie data\n"));
goto finish;
}
- pa_x11_set_prop(d, "PULSE_COOKIE", pa_hexstr(cookie, sizeof(cookie), hx, sizeof(hx)));
+ pa_x11_set_prop(xcb, screen, "PULSE_COOKIE", pa_hexstr(cookie, sizeof(cookie), hx, sizeof(hx)));
break;
}
case REMOVE:
- pa_x11_del_prop(d, "PULSE_SERVER");
- pa_x11_del_prop(d, "PULSE_SINK");
- pa_x11_del_prop(d, "PULSE_SOURCE");
- pa_x11_del_prop(d, "PULSE_ID");
- pa_x11_del_prop(d, "PULSE_COOKIE");
+ pa_x11_del_prop(xcb, screen, "PULSE_SERVER");
+ pa_x11_del_prop(xcb, screen, "PULSE_SINK");
+ pa_x11_del_prop(xcb, screen, "PULSE_SOURCE");
+ pa_x11_del_prop(xcb, screen, "PULSE_ID");
+ pa_x11_del_prop(xcb, screen, "PULSE_COOKIE");
+ pa_x11_del_prop(xcb, screen, "PULSE_SESSION_ID");
break;
-
+
default:
- fprintf(stderr, "No yet implemented.\n");
+ fprintf(stderr, _("Not yet implemented.\n"));
goto finish;
}
ret = 0;
-
+
finish:
- if (d) {
- XSync(d, False);
- XCloseDisplay(d);
+ if (xcb) {
+ xcb_flush(xcb);
+ xcb_disconnect(xcb);
}
-
+
return ret;
}
diff --git a/src/utils/qpaeq b/src/utils/qpaeq
new file mode 100755
index 00000000..a8a9fda8
--- /dev/null
+++ b/src/utils/qpaeq
@@ -0,0 +1,560 @@
+#!/usr/bin/env python
+# qpaeq is a equalizer interface for pulseaudio's equalizer sinks
+# Copyright (C) 2009 Jason Newton <nevion@gmail.com
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+import os,math,sys
+try:
+ import PyQt4,sip
+ from PyQt4 import QtGui,QtCore
+ import dbus.mainloop.qt
+ import dbus
+except ImportError,e:
+ print 'There was an error importing need libraries'
+ print 'Make sure you haveqt4 and dbus forthon installed'
+ print 'The error that occured was'
+ print '\t%s' %(str(e))
+ import sys
+ sys.exit(-1)
+
+from functools import partial
+
+import signal
+signal.signal(signal.SIGINT, signal.SIG_DFL)
+SYNC_TIMEOUT = 4*1000
+
+CORE_PATH = "/org/pulseaudio/core1"
+CORE_IFACE = "org.PulseAudio.Core1"
+def connect():
+ try:
+ if 'PULSE_DBUS_SERVER' in os.environ:
+ address = os.environ['PULSE_DBUS_SERVER']
+ else:
+ bus = dbus.SessionBus() # Should be UserBus, but D-Bus doesn't implement that yet.
+ server_lookup = bus.get_object('org.PulseAudio1', '/org/pulseaudio/server_lookup1')
+ address = server_lookup.Get('org.PulseAudio.ServerLookup1', 'Address', dbus_interface='org.freedesktop.DBus.Properties')
+ return dbus.connection.Connection(address)
+ except Exception,e:
+ print 'There was an error connecting to pulseaudio, please make sure you have the pulseaudio dbus'
+ print 'and equalizer modules loaded, exiting...'
+ import sys
+ sys.exit(-1)
+
+
+#TODO: signals: sink Filter changed, sink reconfigured (window size) (sink iface)
+#TODO: manager signals: new sink, removed sink, new profile, removed profile
+#TODO: add support for changing of window_size 1000-fft_size (adv option)
+#TODO: reconnect support loop 1 second trying to reconnect
+#TODO: just resample the filters for profiles when loading to different sizes
+#TODO: add preamp
+prop_iface='org.freedesktop.DBus.Properties'
+eq_iface='org.PulseAudio.Ext.Equalizing1.Equalizer'
+device_iface='org.PulseAudio.Core1.Device'
+class QPaeq(QtGui.QWidget):
+ manager_path='/org/pulseaudio/equalizing1'
+ manager_iface='org.PulseAudio.Ext.Equalizing1.Manager'
+ core_iface='org.PulseAudio.Core1'
+ core_path='/org/pulseaudio/core1'
+ def __init__(self):
+ QtGui.QWidget.__init__(self)
+ self.setWindowTitle('qpaeq')
+ self.slider_widget=None
+ self.sink_name=None
+ self.filter_state=None
+
+ self.create_layout()
+
+ self.set_connection()
+ self.connect_to_sink(self.sinks[0])
+ self.set_callbacks()
+ self.setMinimumSize(self.sizeHint())
+
+ def create_layout(self):
+ self.main_layout=QtGui.QVBoxLayout()
+ self.setLayout(self.main_layout)
+ toprow_layout=QtGui.QHBoxLayout()
+ sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
+ sizePolicy.setHorizontalStretch(0)
+ sizePolicy.setVerticalStretch(0)
+ #sizePolicy.setHeightForWidth(self.profile_box.sizePolicy().hasHeightForWidth())
+
+ toprow_layout.addWidget(QtGui.QLabel('Sink'))
+ self.sink_box = QtGui.QComboBox()
+ self.sink_box.setSizePolicy(sizePolicy)
+ self.sink_box.setDuplicatesEnabled(False)
+ self.sink_box.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
+ #self.sink_box.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
+ toprow_layout.addWidget(self.sink_box)
+
+ toprow_layout.addWidget(QtGui.QLabel('Channel'))
+ self.channel_box = QtGui.QComboBox()
+ self.channel_box.setSizePolicy(sizePolicy)
+ toprow_layout.addWidget(self.channel_box)
+
+ toprow_layout.addWidget(QtGui.QLabel('Preset'))
+ self.profile_box = QtGui.QComboBox()
+ self.profile_box.setSizePolicy(sizePolicy)
+ self.profile_box.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
+ #self.profile_box.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
+ toprow_layout.addWidget(self.profile_box)
+
+ large_icon_size=self.style().pixelMetric(QtGui.QStyle.PM_LargeIconSize)
+ large_icon_size=QtCore.QSize(large_icon_size,large_icon_size)
+ save_profile=QtGui.QToolButton()
+ save_profile.setIcon(self.style().standardIcon(QtGui.QStyle.SP_DriveFDIcon))
+ save_profile.setIconSize(large_icon_size)
+ save_profile.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
+ save_profile.clicked.connect(self.save_profile)
+ remove_profile=QtGui.QToolButton()
+ remove_profile.setIcon(self.style().standardIcon(QtGui.QStyle.SP_TrashIcon))
+ remove_profile.setIconSize(large_icon_size)
+ remove_profile.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
+ remove_profile.clicked.connect(self.remove_profile)
+ toprow_layout.addWidget(save_profile)
+ toprow_layout.addWidget(remove_profile)
+
+ reset_button = QtGui.QPushButton('Reset')
+ reset_button.clicked.connect(self.reset)
+ toprow_layout.addStretch()
+ toprow_layout.addWidget(reset_button)
+ self.layout().addLayout(toprow_layout)
+
+ self.profile_box.activated.connect(self.load_profile)
+ self.channel_box.activated.connect(self.select_channel)
+ def connect_to_sink(self,name):
+ #TODO: clear slots for profile buttons
+
+ #flush any pending saves for other sinks
+ if self.filter_state is not None:
+ self.filter_state.flush_state()
+ sink=self.connection.get_object(object_path=name)
+ self.sink_props=dbus.Interface(sink,dbus_interface=prop_iface)
+ self.sink=dbus.Interface(sink,dbus_interface=eq_iface)
+ self.filter_state=FilterState(sink)
+ #sample_rate,filter_rate,channels,channel)
+
+ self.channel_box.clear()
+ self.channel_box.addItem('All',self.filter_state.channels)
+ for i in xrange(self.filter_state.channels):
+ self.channel_box.addItem('%d' %(i+1,),i)
+ self.setMinimumSize(self.sizeHint())
+
+ self.set_slider_widget(SliderArray(self.filter_state))
+
+ self.sink_name=name
+ #set the signal listener for this sink
+ core=self._get_core()
+ #temporary hack until signal filtering works properly
+ core.ListenForSignal('',[dbus.ObjectPath(self.sink_name),dbus.ObjectPath(self.manager_path)])
+ #for x in ['FilterChanged']:
+ # core.ListenForSignal("%s.%s" %(self.eq_iface,x),[dbus.ObjectPath(self.sink_name)])
+ #core.ListenForSignal(self.eq_iface,[dbus.ObjectPath(self.sink_name)])
+ self.sink.connect_to_signal('FilterChanged',self.read_filter)
+
+ def set_slider_widget(self,widget):
+ layout=self.layout()
+ if self.slider_widget is not None:
+ i=layout.indexOf(self.slider_widget)
+ layout.removeWidget(self.slider_widget)
+ self.slider_widget.deleteLater()
+ layout.insertWidget(i,self.slider_widget)
+ else:
+ layout.addWidget(widget)
+ self.slider_widget=widget
+ self.read_filter()
+ def _get_core(self):
+ core_obj=self.connection.get_object(object_path=self.core_path)
+ core=dbus.Interface(core_obj,dbus_interface=self.core_iface)
+ return core
+ def sink_added(self,sink):
+ #TODO: preserve selected sink
+ self.update_sinks()
+ def sink_removed(self,sink):
+ #TODO: preserve selected sink, try connecting to backup otherwise
+ if sink==self.sink_name:
+ #connect to new sink?
+ pass
+ self.update_sinks()
+ def save_profile(self):
+ #popup dialog box for name
+ current=self.profile_box.currentIndex()
+ profile,ok=QtGui.QInputDialog.getItem(self,'Preset Name','Preset',self.profiles,current)
+ if not ok or profile=='':
+ return
+ if profile in self.profiles:
+ mbox=QtGui.QMessageBox(self)
+ mbox.setText('%s preset already exists'%(profile,))
+ mbox.setInformativeText('Do you want to save over it?')
+ mbox.setStandardButtons(mbox.Save|mbox.Discard|mbox.Cancel)
+ mbox.setDefaultButton(mbox.Save)
+ ret=mbox.exec_()
+ if ret!=mbox.Save:
+ return
+ self.sink.SaveProfile(self.filter_state.channel,dbus.String(profile))
+ if self.filter_state.channel==self.filter_state.channels:
+ for x in range(1,self.filter_state.channels):
+ self.sink.LoadProfile(x,dbus.String(profile))
+ def remove_profile(self):
+ #find active profile name, remove it
+ profile=self.profile_box.currentText()
+ manager=dbus.Interface(self.manager_obj,dbus_interface=self.manager_iface)
+ manager.RemoveProfile(dbus.String(profile))
+ def load_profile(self,x):
+ profile=self.profile_box.itemText(x)
+ self.filter_state.load_profile(profile)
+ def select_channel(self,x):
+ self.filter_state.channel = self.channel_box.itemData(x).toPyObject()
+ self._set_profile_name()
+ self.filter_state.readback()
+
+ #TODO: add back in preamp!
+ #print frequencies
+ #main_layout.addLayout(self.create_slider(partial(self.update_coefficient,0),
+ # 'Preamp')[0]
+ #)
+ def set_connection(self):
+ self.connection=connect()
+ self.manager_obj=self.connection.get_object(object_path=self.manager_path)
+ manager_props=dbus.Interface(self.manager_obj,dbus_interface=prop_iface)
+ self.sinks=manager_props.Get(self.manager_iface,'EqualizedSinks')
+ def set_callbacks(self):
+ manager=dbus.Interface(self.manager_obj,dbus_interface=self.manager_iface)
+ manager.connect_to_signal('ProfilesChanged',self.update_profiles)
+ manager.connect_to_signal('SinkAdded',self.sink_added)
+ manager.connect_to_signal('SinkRemoved',self.sink_removed)
+ #self._get_core().ListenForSignal(self.manager_iface,[])
+ #self._get_core().ListenForSignal(self.manager_iface,[dbus.ObjectPath(self.manager_path)])
+ #core=self._get_core()
+ #for x in ['ProfilesChanged','SinkAdded','SinkRemoved']:
+ # core.ListenForSignal("%s.%s" %(self.manager_iface,x),[dbus.ObjectPath(self.manager_path)])
+ self.update_profiles()
+ self.update_sinks()
+ def update_profiles(self):
+ #print 'update profiles called!'
+ manager_props=dbus.Interface(self.manager_obj,dbus_interface=prop_iface)
+ self.profiles=manager_props.Get(self.manager_iface,'Profiles')
+ self.profile_box.blockSignals(True)
+ self.profile_box.clear()
+ self.profile_box.addItems(self.profiles)
+ self.profile_box.blockSignals(False)
+ self._set_profile_name()
+ def update_sinks(self):
+ self.sink_box.blockSignals(True)
+ self.sink_box.clear()
+ for x in self.sinks:
+ sink=self.connection.get_object(object_path=x)
+ sink_props=dbus.Interface(sink,dbus_interface=prop_iface)
+ simple_name=sink_props.Get(device_iface,'Name')
+ self.sink_box.addItem(simple_name,x)
+ self.sink_box.blockSignals(False)
+ self.sink_box.setMinimumSize(self.sink_box.sizeHint())
+ def read_filter(self):
+ #print self.filter_frequencies
+ self.filter_state.readback()
+ def reset(self):
+ coefs=dbus.Array([1/math.sqrt(2.0)]*(self.filter_state.filter_rate//2+1))
+ preamp=1.0
+ self.filter_state.set_filter(preamp,coefs)
+ def _set_profile_name(self):
+ self.profile_box.blockSignals(True)
+ profile_name=self.sink.BaseProfile(self.filter_state.channel)
+ if profile_name is not None:
+ i=self.profile_box.findText(profile_name)
+ if i>=0:
+ self.profile_box.setCurrentIndex(i)
+ self.profile_box.blockSignals(False)
+
+
+class SliderArray(QtGui.QWidget):
+ def __init__(self,filter_state,parent=None):
+ super(SliderArray,self).__init__(parent)
+ #self.setStyleSheet('padding: 0px; border-width: 0px; margin: 0px;')
+ #self.setStyleSheet('font-size: 7pt; font-family: monospace;'+outline%('blue'))
+ self.filter_state=filter_state
+ self.setLayout(QtGui.QHBoxLayout())
+ self.sub_array=None
+ self.set_sub_array(SliderArraySub(self.filter_state))
+ self.inhibit_resize=0
+ def set_sub_array(self,widget):
+ if self.sub_array is not None:
+ self.layout().removeWidget(self.sub_array)
+ self.sub_array.disconnect_signals()
+ self.sub_array.deleteLater()
+ self.sub_array=widget
+ self.layout().addWidget(self.sub_array)
+ self.sub_array.connect_signals()
+ self.filter_state.readback()
+ def resizeEvent(self,event):
+ super(SliderArray,self).resizeEvent(event)
+ if self.inhibit_resize==0:
+ self.inhibit_resize+=1
+ #self.add_sliders_to_fit()
+ t=QtCore.QTimer(self)
+ t.setSingleShot(True)
+ t.setInterval(0)
+ t.timeout.connect(partial(self.add_sliders_to_fit,event))
+ t.start()
+ def add_sliders_to_fit(self,event):
+ if event.oldSize().width()>0 and event.size().width()>0:
+ i=len(self.filter_state.frequencies)*int(round(float(event.size().width())/event.oldSize().width()))
+ else:
+ i=len(self.filter_state.frequencies)
+
+ t_w=self.size().width()
+ def evaluate(filter_state, target, variable):
+ base_freqs=self.filter_state.freq_proper(self.filter_state.DEFAULT_FREQUENCIES)
+ filter_state._set_frequency_values(subdivide(base_freqs,variable))
+ new_widget=SliderArraySub(filter_state)
+ w=new_widget.sizeHint().width()
+ return w-target
+ def searcher(initial,evaluator):
+ i=initial
+ def d(e): return 1 if e>=0 else -1
+ error=evaluator(i)
+ old_direction=d(error)
+ i-=old_direction
+ while True:
+ error=evaluator(i)
+ direction=d(error)
+ if direction!=old_direction:
+ k=i-1
+ #while direction<0 and error!=0:
+ # k-=1
+ # error=evaluator(i)
+ # direction=d(error)
+ return k, evaluator(k)
+ i-=direction
+ old_direction=direction
+ searcher(i,partial(evaluate,self.filter_state,t_w))
+ self.set_sub_array(SliderArraySub(self.filter_state))
+ self.inhibit_resize-=1
+
+class SliderArraySub(QtGui.QWidget):
+ def __init__(self,filter_state,parent=None):
+ super(SliderArraySub,self).__init__(parent)
+ self.filter_state=filter_state
+ self.setLayout(QtGui.QGridLayout())
+ self.slider=[None]*len(self.filter_state.frequencies)
+ self.label=[None]*len(self.slider)
+ #self.setStyleSheet('padding: 0px; border-width: 0px; margin: 0px;')
+ #self.setStyleSheet('font-size: 7pt; font-family: monospace;'+outline%('blue'))
+ qt=QtCore.Qt
+ #self.layout().setHorizontalSpacing(1)
+ def add_slider(slider,label, c):
+ self.layout().addWidget(slider,0,c,qt.AlignHCenter)
+ self.layout().addWidget(label,1,c,qt.AlignHCenter)
+ self.layout().setColumnMinimumWidth(c,max(label.sizeHint().width(),slider.sizeHint().width()))
+ def create_slider(slider_label):
+ slider=QtGui.QSlider(QtCore.Qt.Vertical,self)
+ label=SliderLabel(slider_label,filter_state,self)
+ slider.setRange(-1000,2000)
+ slider.setSingleStep(1)
+ return (slider,label)
+ self.preamp_slider,self.preamp_label=create_slider('Preamp')
+ add_slider(self.preamp_slider,self.preamp_label,0)
+ for i,hz in enumerate(self.filter_state.frequencies):
+ slider,label=create_slider(self.hz2label(hz))
+ self.slider[i]=slider
+ #slider.setStyleSheet('font-size: 7pt; font-family: monospace;'+outline%('red',))
+ self.label[i]=label
+ c=i+1
+ add_slider(slider,label,i+1)
+ def hz2label(self, hz):
+ if hz==0:
+ label_text='DC'
+ elif hz==self.filter_state.sample_rate//2:
+ label_text='Coda'
+ else:
+ label_text=hz2str(hz)
+ return label_text
+
+ def connect_signals(self):
+ def connect(writer,reader,slider,label):
+ slider.valueChanged.connect(writer)
+ self.filter_state.readFilter.connect(reader)
+ label_cb=partial(slider.setValue,0)
+ label.clicked.connect(label_cb)
+ return label_cb
+
+ self.preamp_writer_cb=self.write_preamp
+ self.preamp_reader_cb=self.sync_preamp
+ self.preamp_label_cb=connect(self.preamp_writer_cb,
+ self.preamp_reader_cb,
+ self.preamp_slider,
+ self.preamp_label)
+ self.writer_callbacks=[None]*len(self.slider)
+ self.reader_callbacks=[None]*len(self.slider)
+ self.label_callbacks=[None]*len(self.label)
+ for i in range(len(self.slider)):
+ self.writer_callbacks[i]=partial(self.write_coefficient,i)
+ self.reader_callbacks[i]=partial(self.sync_coefficient,i)
+ self.label_callbacks[i]=connect(self.writer_callbacks[i],
+ self.reader_callbacks[i],
+ self.slider[i],
+ self.label[i])
+ def disconnect_signals(self):
+ def disconnect(writer,reader,label_cb,slider,label):
+ slider.valueChanged.disconnect(writer)
+ self.filter_state.readFilter.disconnect(reader)
+ label.clicked.disconnect(label_cb)
+ disconnect(self.preamp_writer_cb, self.preamp_reader_cb,
+ self.preamp_label_cb, self.preamp_slider, self.preamp_label)
+ for i in range(len(self.slider)):
+ disconnect(self.writer_callbacks[i],
+ self.reader_callbacks[i],
+ self.label_callbacks[i],
+ self.slider[i],
+ self.label[i])
+
+ def write_preamp(self, v):
+ self.filter_state.preamp=self.slider2coef(v)
+ self.filter_state.seed()
+ def sync_preamp(self):
+ self.preamp_slider.blockSignals(True)
+ self.preamp_slider.setValue(self.coef2slider(self.filter_state.preamp))
+ self.preamp_slider.blockSignals(False)
+
+
+ def write_coefficient(self,i,v):
+ self.filter_state.coefficients[i]=self.slider2coef(v)/math.sqrt(2.0)
+ self.filter_state.seed()
+ def sync_coefficient(self,i):
+ slider=self.slider[i]
+ slider.blockSignals(True)
+ slider.setValue(self.coef2slider(math.sqrt(2.0)*self.filter_state.coefficients[i]))
+ slider.blockSignals(False)
+ @staticmethod
+ def slider2coef(x):
+ return (1.0+(x/1000.0))
+ @staticmethod
+ def coef2slider(x):
+ return int((x-1.0)*1000)
+outline='border-width: 1px; border-style: solid; border-color: %s;'
+
+class SliderLabel(QtGui.QLabel):
+ clicked=QtCore.pyqtSignal()
+ def __init__(self,label_text,filter_state,parent=None):
+ super(SliderLabel,self).__init__(parent)
+ self.setStyleSheet('font-size: 7pt; font-family: monospace;')
+ self.setText(label_text)
+ self.setMinimumSize(self.sizeHint())
+ def mouseDoubleClickEvent(self, event):
+ self.clicked.emit()
+ super(SliderLabel,self).mouseDoubleClickEvent(event)
+
+#until there are server side state savings, do it in the client but try and avoid
+#simulaneous broadcasting situations
+class FilterState(QtCore.QObject):
+ #DEFAULT_FREQUENCIES=map(float,[25,50,75,100,150,200,300,400,500,800,1e3,1.5e3,3e3,5e3,7e3,10e3,15e3,20e3])
+ DEFAULT_FREQUENCIES=[31.75,63.5,125,250,500,1e3,2e3,4e3,8e3,16e3]
+ readFilter=QtCore.pyqtSignal()
+ def __init__(self,sink):
+ super(FilterState,self).__init__()
+ self.sink_props=dbus.Interface(sink,dbus_interface=prop_iface)
+ self.sink=dbus.Interface(sink,dbus_interface=eq_iface)
+ self.sample_rate=self.get_eq_attr('SampleRate')
+ self.filter_rate=self.get_eq_attr('FilterSampleRate')
+ self.channels=self.get_eq_attr('NChannels')
+ self.channel=self.channels
+ self.set_frequency_values(self.DEFAULT_FREQUENCIES)
+ self.sync_timer=QtCore.QTimer()
+ self.sync_timer.setSingleShot(True)
+ self.sync_timer.timeout.connect(self.save_state)
+
+ def get_eq_attr(self,attr):
+ return self.sink_props.Get(eq_iface,attr)
+ def freq_proper(self,xs):
+ return [0]+xs+[self.sample_rate//2]
+ def _set_frequency_values(self,freqs):
+ self.frequencies=freqs
+ #print 'base',self.frequencies
+ self.filter_frequencies=map(lambda x: int(round(x)), \
+ self.translate_rates(self.filter_rate,self.sample_rate,
+ self.frequencies) \
+ )
+ self.coefficients=[0.0]*len(self.frequencies)
+ self.preamp=1.0
+ def set_frequency_values(self,freqs):
+ self._set_frequency_values(self.freq_proper(freqs))
+ @staticmethod
+ def translate_rates(dst,src,rates):
+ return list(map(lambda x: x*dst/src,rates))
+ def seed(self):
+ self.sink.SeedFilter(self.channel,self.filter_frequencies,self.coefficients,self.preamp)
+ self.sync_timer.start(SYNC_TIMEOUT)
+ def readback(self):
+ coefs,preamp=self.sink.FilterAtPoints(self.channel,self.filter_frequencies)
+ self.coefficients=coefs
+ self.preamp=preamp
+ self.readFilter.emit()
+ def set_filter(self,preamp,coefs):
+ self.sink.SetFilter(self.channel,dbus.Array(coefs),self.preamp)
+ self.sync_timer.start(SYNC_TIMEOUT)
+ def save_state(self):
+ print 'saving state'
+ self.sink.SaveState()
+ def load_profile(self,profile):
+ self.sink.LoadProfile(self.channel,dbus.String(profile))
+ self.sync_timer.start(SYNC_TIMEOUT)
+ def flush_state(self):
+ if self.sync_timer.isActive():
+ self.sync_timer.stop()
+ self.save_state()
+
+
+def safe_log(k,b):
+ i=0
+ while k//b!=0:
+ i+=1
+ k=k//b
+ return i
+def hz2str(hz):
+ p=safe_log(hz,10.0)
+ if p<3:
+ return '%dHz' %(hz,)
+ elif hz%1000==0:
+ return '%dKHz' %(hz/(10.0**3),)
+ else:
+ return '%.1fKHz' %(hz/(10.0**3),)
+
+def subdivide(xs, t_points):
+ while len(xs)<t_points:
+ m=[0]*(2*len(xs)-1)
+ m[0:len(m):2]=xs
+ for i in range(1,len(m),2):
+ m[i]=(m[i-1]+m[i+1])//2
+ xs=m
+ p_drop=len(xs)-t_points
+ p_drop_left=p_drop//2
+ p_drop_right=p_drop-p_drop_left
+ #print 'xs',xs
+ #print 'dropping %d, %d left, %d right' %(p_drop,p_drop_left,p_drop_right)
+ c=len(xs)//2
+ left=xs[0:p_drop_left*2:2]+xs[p_drop_left*2:c]
+ right=list(reversed(xs[c:]))
+ right=right[0:p_drop_right*2:2]+right[p_drop_right*2:]
+ right=list(reversed(right))
+ return left+right
+
+def main():
+ dbus.mainloop.qt.DBusQtMainLoop(set_as_default=True)
+ app=QtGui.QApplication(sys.argv)
+ qpaeq_main=QPaeq()
+ qpaeq_main.show()
+ sys.exit(app.exec_())
+
+if __name__=='__main__':
+ main()