From e205b25d65ccb380fa158711e24d55b6de5d9bc1 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 16 Feb 2006 19:19:58 +0000 Subject: Reorganised the source tree. We now have src/ with a couple of subdirs: * daemon/ - Contains the files specific to the polypaudio daemon. * modules/ - All loadable modules. * polyp/ - Files that are part of the public, application interface or are only used in libpolyp. * polypcore/ - All other shared files. * tests/ - Test programs. * utils/ - Utility programs. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@487 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 386 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 386 insertions(+) create mode 100644 src/utils/paplay.c (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c new file mode 100644 index 00000000..ddc1cbc1 --- /dev/null +++ b/src/utils/paplay.c @@ -0,0 +1,386 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio 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. + + polypaudio 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 polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#if PA_API_VERSION != 8 +#error Invalid Polypaudio 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 sf_count_t (*readf_function)(SNDFILE *_sndfile, void *ptr, sf_count_t frames); + +/* 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) { + size_t k; + sf_count_t f, n; + void *data; + assert(s && length); + + if (!sndfile) + return; + + k = pa_frame_size(&sample_spec); + + data = malloc(length); + + n = length/k; + + f = readf_function(sndfile, data, n); + + if (f > 0) + pa_stream_write(s, data, f*k, free, 0); + + if (f < n) { + 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, 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, PA_CHANNELS_MAX, volume)); + + 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...256\n", + argv0); +} + +enum { + ARG_VERSION = 256, + ARG_STREAM_NAME, + ARG_VOLUME +}; + +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}, + {NULL, 0, NULL, 0} + }; + + 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 libpolyp %s\nLinked with libpolyp %s\n", pa_get_headers_version(), pa_get_library_version()); + ret = 0; + goto quit; + + case 'd': + free(device); + device = strdup(optarg); + break; + + case 's': + free(server); + server = strdup(optarg); + break; + + case 'n': + free(client_name); + client_name = strdup(optarg); + break; + + case ARG_STREAM_NAME: + free(stream_name); + stream_name = strdup(optarg); + break; + + case 'v': + verbose = 1; + break; + + case ARG_VOLUME: { + int v = atoi(optarg); + volume = v < 0 ? 0 : v; + break; + } + + default: + goto quit; + } + } + + + filename = optind < argc ? argv[optind] : "STDIN"; + + + if (!client_name) + client_name = strdup(bn); + + if (!stream_name) + stream_name = strdup(filename); + + 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; + + switch (sfinfo.format & 0xFF) { + case SF_FORMAT_PCM_16: + case SF_FORMAT_PCM_U8: + case SF_FORMAT_ULAW: + case SF_FORMAT_ALAW: + 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_FLOAT: + default: + sample_spec.format = PA_SAMPLE_FLOAT32NE; + readf_function = (sf_count_t (*)(SNDFILE *_sndfile, void *ptr, sf_count_t frames)) sf_readf_float; + break; + } + + 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, 1, 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); + } + + free(server); + free(device); + free(client_name); + free(stream_name); + + if (sndfile) + sf_close(sndfile); + + return ret; +} -- cgit From 22c8cebb858012e4e9c551bb54456237e7597697 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Feb 2006 22:43:59 +0000 Subject: drop polyplib- prefix from client library files git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@492 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index ddc1cbc1..1b3697fa 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -35,10 +35,10 @@ #include #include -#include +#include #include #include -#include +#include #if PA_API_VERSION != 8 #error Invalid Polypaudio API version -- cgit From b4cb249d704cbb0458640526a07e1f541b899d3e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Feb 2006 23:12:10 +0000 Subject: shorten include list of utils a little git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@495 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 1b3697fa..9f73b834 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -34,11 +34,9 @@ #include -#include -#include +#include #include #include -#include #if PA_API_VERSION != 8 #error Invalid Polypaudio API version -- cgit From 304449002cbc84fdcf235b5dfaec891278dd7085 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 20 Feb 2006 04:05:16 +0000 Subject: 1) Add flexible seeking support (including absolute) for memory block queues and playback streams 2) Add support to synchronize multiple playback streams 3) add two tests for 1) and 2) 4) s/PA_ERROR/PA_ERR/ 5) s/PA_ERROR_OK/PA_OK/ 6) update simple API to deal properly with new peek/drop recording API 7) add beginnings of proper validity checking on API calls in client libs (needs to be extended) 8) report playback buffer overflows/underflows to the client 9) move client side recording mcalign stuff into the memblockq 10) create typedefs for a bunch of API callback prototypes 11) simplify handling of HUP poll() events Yes, i know, it's usually better to commit a lot of small patches instead of a single big one. In this case however, this would have contradicted the other rule: never commit broken or incomplete stuff. *** This stuff needs a lot of additional testing! *** git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@511 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 9f73b834..5f985ee9 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -113,7 +113,7 @@ static void stream_write_callback(pa_stream *s, size_t length, void *userdata) { f = readf_function(sndfile, data, n); if (f > 0) - pa_stream_write(s, data, f*k, free, 0); + pa_stream_write(s, data, f*k, free, 0, PA_SEEK_RELATIVE); if (f < n) { sf_close(sndfile); @@ -166,7 +166,7 @@ static void context_state_callback(pa_context *c, void *userdata) { 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, PA_CHANNELS_MAX, volume)); + pa_stream_connect_playback(stream, device, NULL, 0, pa_cvolume_set(&cv, sample_spec.channels, volume), NULL); break; } -- cgit From 31a027b78b5081903ecdde5cff1b42770c93b075 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 20 Feb 2006 23:29:46 +0000 Subject: change calls of pa_context_connect() to pass flags arugment correctly git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@533 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 5f985ee9..4efb4cf6 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -352,7 +352,7 @@ int main(int argc, char *argv[]) { pa_context_set_state_callback(context, context_state_callback, NULL); /* Connect the context */ - pa_context_connect(context, server, 1, NULL); + pa_context_connect(context, server, 0, NULL); /* Run the main loop */ if (pa_mainloop_run(m, &ret) < 0) { -- cgit From c27b1407f8197230136158eae2aeb75f526a12f3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 26 Apr 2006 16:28:29 +0000 Subject: allow the user to specify an alternative channel map in paplay too git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@809 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 4efb4cf6..7f665413 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -53,7 +53,9 @@ static pa_volume_t volume = PA_VOLUME_NORM; static SNDFILE* sndfile = NULL; -static pa_sample_spec sample_spec = { 0, 0, 0 }; +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); @@ -161,7 +163,7 @@ static void context_state_callback(pa_context *c, void *userdata) { if (verbose) fprintf(stderr, "Connection established.\n"); - stream = pa_stream_new(c, stream_name, &sample_spec, NULL); + 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); @@ -200,14 +202,16 @@ static void help(const char *argv0) { " -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...256\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_VOLUME, + ARG_CHANNELMAP }; int main(int argc, char *argv[]) { @@ -226,6 +230,7 @@ int main(int argc, char *argv[]) { {"help", 0, NULL, 'h'}, {"verbose", 0, NULL, 'v'}, {"volume", 1, NULL, ARG_VOLUME}, + {"channel-map", 1, NULL, ARG_CHANNELMAP}, {NULL, 0, NULL, 0} }; @@ -277,6 +282,15 @@ int main(int argc, char *argv[]) { 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; } @@ -322,6 +336,13 @@ int main(int argc, char *argv[]) { 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 (verbose) { char t[PA_SAMPLE_SPEC_SNPRINT_MAX]; pa_sample_spec_snprint(t, sizeof(t), &sample_spec); -- cgit From c2c8539201307cf8bf500ce7b77c8f09eaa655b7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 16 May 2006 18:28:03 +0000 Subject: bump version number to 0.9 git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@886 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 7f665413..ad9d4553 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -38,7 +38,7 @@ #include #include -#if PA_API_VERSION != 8 +#if PA_API_VERSION != 9 #error Invalid Polypaudio API version #endif -- cgit From 31a9d4fb301bdfed50bee2cf162cc98093bb19f6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 May 2006 14:06:12 +0000 Subject: when playing an ULAW or ALAW audio file, do not convert to S16NE unconditionally, instead use sf_read_raw() to read raw audio data git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@898 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 57 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 22 deletions(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index ad9d4553..d4af95c1 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -57,7 +57,7 @@ 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); +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) { @@ -98,26 +98,30 @@ static void stream_drain_complete(pa_stream*s, int success, void *userdata) { /* 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) { - size_t k; - sf_count_t f, n; + sf_count_t bytes; void *data; assert(s && length); if (!sndfile) return; - - k = pa_frame_size(&sample_spec); data = malloc(length); - n = length/k; - - f = readf_function(sndfile, data, n); + if (readf_function) { + size_t k = pa_frame_size(&sample_spec); - if (f > 0) - pa_stream_write(s, data, f*k, free, 0, PA_SEEK_RELATIVE); + if ((bytes = readf_function(sndfile, data, length/k)) > 0) + bytes *= k; + + } else + bytes = sf_read_raw(sndfile, data, length); - if (f < n) { + if (bytes > 0) + pa_stream_write(s, data, bytes, free, 0, PA_SEEK_RELATIVE); + else + free(data); + + if (bytes < length) { sf_close(sndfile); sndfile = NULL; pa_operation_unref(pa_stream_drain(s, stream_drain_complete, NULL)); @@ -296,16 +300,8 @@ int main(int argc, char *argv[]) { } } - filename = optind < argc ? argv[optind] : "STDIN"; - - if (!client_name) - client_name = strdup(bn); - - if (!stream_name) - stream_name = strdup(filename); - memset(&sfinfo, 0, sizeof(sfinfo)); if (optind < argc) @@ -317,18 +313,27 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Failed to open file '%s'\n", filename); goto quit; } - + sample_spec.rate = sfinfo.samplerate; sample_spec.channels = sfinfo.channels; switch (sfinfo.format & 0xFF) { case SF_FORMAT_PCM_16: case SF_FORMAT_PCM_U8: - case SF_FORMAT_ULAW: - case SF_FORMAT_ALAW: 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; + readf_function = NULL; + break; + + case SF_FORMAT_ALAW: + sample_spec.format = PA_SAMPLE_ALAW; + readf_function = NULL; + break; + case SF_FORMAT_FLOAT: default: sample_spec.format = PA_SAMPLE_FLOAT32NE; @@ -343,6 +348,14 @@ int main(int argc, char *argv[]) { goto quit; } + if (!client_name) + client_name = strdup(bn); + + if (!stream_name) { + const char *n = sf_get_string(sndfile, SF_STR_TITLE); + stream_name = strdup(n ? n : filename); + } + if (verbose) { char t[PA_SAMPLE_SPEC_SNPRINT_MAX]; pa_sample_spec_snprint(t, sizeof(t), &sample_spec); -- cgit From e6695538d721941132db2183e40f142b9e52076e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 May 2006 14:54:41 +0000 Subject: * use S16NE for SF_FORMAT_PCM_S8 formats, too git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@899 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index d4af95c1..5f203615 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -317,24 +317,26 @@ int main(int argc, char *argv[]) { 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; - readf_function = NULL; break; case SF_FORMAT_ALAW: sample_spec.format = PA_SAMPLE_ALAW; - readf_function = NULL; 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; -- cgit From fbdb06351385eb210c50ba6a1fc2b8c14575513e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 May 2006 19:26:54 +0000 Subject: replace memory allocation function calls with pa_xXXXX() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@916 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 5f203615..b66c13da 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -35,8 +35,6 @@ #include #include -#include -#include #if PA_API_VERSION != 9 #error Invalid Polypaudio API version @@ -105,7 +103,7 @@ static void stream_write_callback(pa_stream *s, size_t length, void *userdata) { if (!sndfile) return; - data = malloc(length); + data = pa_xmalloc(length); if (readf_function) { size_t k = pa_frame_size(&sample_spec); @@ -117,9 +115,9 @@ static void stream_write_callback(pa_stream *s, size_t length, void *userdata) { bytes = sf_read_raw(sndfile, data, length); if (bytes > 0) - pa_stream_write(s, data, bytes, free, 0, PA_SEEK_RELATIVE); + pa_stream_write(s, data, bytes, pa_xfree, 0, PA_SEEK_RELATIVE); else - free(data); + pa_xfree(data); if (bytes < length) { sf_close(sndfile); @@ -257,23 +255,23 @@ int main(int argc, char *argv[]) { goto quit; case 'd': - free(device); - device = strdup(optarg); + pa_xfree(device); + device = pa_xstrdup(optarg); break; case 's': - free(server); - server = strdup(optarg); + pa_xfree(server); + server = pa_xstrdup(optarg); break; case 'n': - free(client_name); - client_name = strdup(optarg); + pa_xfree(client_name); + client_name = pa_xstrdup(optarg); break; case ARG_STREAM_NAME: - free(stream_name); - stream_name = strdup(optarg); + pa_xfree(stream_name); + stream_name = pa_xstrdup(optarg); break; case 'v': @@ -351,11 +349,11 @@ int main(int argc, char *argv[]) { } if (!client_name) - client_name = strdup(bn); + client_name = pa_xstrdup(bn); if (!stream_name) { const char *n = sf_get_string(sndfile, SF_STR_TITLE); - stream_name = strdup(n ? n : filename); + stream_name = pa_xstrdup(n ? n : filename); } if (verbose) { @@ -408,10 +406,10 @@ quit: pa_mainloop_free(m); } - free(server); - free(device); - free(client_name); - free(stream_name); + pa_xfree(server); + pa_xfree(device); + pa_xfree(client_name); + pa_xfree(stream_name); if (sndfile) sf_close(sndfile); -- cgit From 83591883d8bcec475e74881b3f9cbcb84900c7ec Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 18 May 2006 08:21:41 +0000 Subject: Make paplay convert names to UTF-8 before sending to the server. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@932 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index b66c13da..effc2a11 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -236,6 +237,8 @@ int main(int argc, char *argv[]) { {NULL, 0, NULL, 0} }; + setlocale(LC_ALL, ""); + if (!(bn = strrchr(argv[0], '/'))) bn = argv[0]; else @@ -348,12 +351,23 @@ int main(int argc, char *argv[]) { goto quit; } - if (!client_name) - client_name = pa_xstrdup(bn); + 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 = sf_get_string(sndfile, SF_STR_TITLE); - stream_name = pa_xstrdup(n ? n : filename); + 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) { -- cgit From f44ba092651aa75055e109e04b4164ea92ae7fdc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 21:53:48 +0000 Subject: big s/polyp/pulse/g git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1033 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index effc2a11..4b4a1ea6 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -1,20 +1,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + 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. - polypaudio is distributed in the hope that it will be useful, but + 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 polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -35,7 +35,7 @@ #include -#include +#include #if PA_API_VERSION != 9 #error Invalid Polypaudio API version @@ -253,7 +253,7 @@ int main(int argc, char *argv[]) { goto quit; case ARG_VERSION: - printf("paplay "PACKAGE_VERSION"\nCompiled with libpolyp %s\nLinked with libpolyp %s\n", pa_get_headers_version(), pa_get_library_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; -- cgit From 10b5e997d7a8a4e955ce49cc816fdcd36225ff6e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 22:11:49 +0000 Subject: replace a few remaining uppercase "Polypaudio" occurences with "PulseAudio" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1036 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 4b4a1ea6..7b34016c 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -38,7 +38,7 @@ #include #if PA_API_VERSION != 9 -#error Invalid Polypaudio API version +#error Invalid PulseAudio API version #endif static pa_context *context = NULL; -- cgit From 7f93d08d4014cc68965611068c47834c1e5547ef Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 1 Aug 2006 21:04:43 +0000 Subject: bump API and protocol version. Return PA_ERR_NOTSUPPORTED if pa_context_move_sink_input_by_*()is called for servers that don't support it git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1179 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 7b34016c..0386c9df 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -37,7 +37,7 @@ #include -#if PA_API_VERSION != 9 +#if PA_API_VERSION < 9 #error Invalid PulseAudio API version #endif -- cgit From 521daf6f0ac4fa6a2fbfb5d523c0c743342dca2b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 4 Jan 2007 13:43:45 +0000 Subject: Huge trailing whitespace cleanup. Let's keep the tree pure from here on, mmmkay? git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1418 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 0386c9df..1617b27d 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -2,17 +2,17 @@ /*** 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 @@ -77,14 +77,14 @@ static void stream_drain_complete(pa_stream*s, int success, void *userdata) { fprintf(stderr, "Failed to drain stream: %s\n", pa_strerror(pa_context_errno(context))); quit(1); } - - if (verbose) + + 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 { @@ -111,7 +111,7 @@ static void stream_write_callback(pa_stream *s, size_t length, void *userdata) { if ((bytes = readf_function(sndfile, data, length/k)) > 0) bytes *= k; - + } else bytes = sf_read_raw(sndfile, data, length); @@ -140,7 +140,7 @@ static void stream_state_callback(pa_stream *s, void *userdata) { 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)))); @@ -157,10 +157,10 @@ static void context_state_callback(pa_context *c, void *userdata) { case PA_CONTEXT_AUTHORIZING: case PA_CONTEXT_SETTING_NAME: break; - + case PA_CONTEXT_READY: { pa_cvolume cv; - + assert(c && !stream); if (verbose) @@ -172,10 +172,10 @@ static void context_state_callback(pa_context *c, void *userdata) { 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; @@ -192,7 +192,7 @@ static void exit_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, if (verbose) fprintf(stderr, "Got SIGINT, exiting.\n"); quit(0); - + } static void help(const char *argv0) { @@ -251,7 +251,7 @@ int main(int argc, char *argv[]) { 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; @@ -302,7 +302,7 @@ int main(int argc, char *argv[]) { } filename = optind < argc ? argv[optind] : "STDIN"; - + memset(&sfinfo, 0, sizeof(sfinfo)); if (optind < argc) @@ -317,9 +317,9 @@ int main(int argc, char *argv[]) { 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: @@ -327,11 +327,11 @@ int main(int argc, char *argv[]) { 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; @@ -369,13 +369,13 @@ int main(int argc, char *argv[]) { 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"); @@ -390,7 +390,7 @@ int main(int argc, char *argv[]) { #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"); @@ -407,7 +407,7 @@ int main(int argc, char *argv[]) { fprintf(stderr, "pa_mainloop_run() failed.\n"); goto quit; } - + quit: if (stream) pa_stream_unref(stream); @@ -427,6 +427,6 @@ quit: if (sndfile) sf_close(sndfile); - + return ret; } -- cgit From 06211b7c8fd329137ae9003818543912a87d9898 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 13 Feb 2007 15:35:19 +0000 Subject: Add copyright notices to all relevant files. (based on svn log) git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1426 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 1617b27d..2c779a7a 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -3,6 +3,9 @@ /*** This file is part of PulseAudio. + Copyright 2004-2006 Lennart Poettering + Copyright 2006 Pierre Ossman 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, -- cgit From a67c21f093202f142438689d3f7cfbdf4ea82eea Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 28 Oct 2007 19:13:50 +0000 Subject: merge 'lennart' branch back into trunk. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1971 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 2c779a7a..e7076d2d 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -123,7 +123,7 @@ static void stream_write_callback(pa_stream *s, size_t length, void *userdata) { else pa_xfree(data); - if (bytes < length) { + if (bytes < (sf_count_t) length) { sf_close(sndfile); sndfile = NULL; pa_operation_unref(pa_stream_drain(s, stream_drain_complete, NULL)); -- cgit From 0eb011bda093438044338946d575ff7845e6aa3c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 5 Nov 2007 23:56:30 +0000 Subject: minor cleanups of --help texts git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2025 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/paplay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/utils/paplay.c') diff --git a/src/utils/paplay.c b/src/utils/paplay.c index e7076d2d..fddbb18c 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -203,9 +203,9 @@ 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" + " -v, --verbose Enable verbose operation\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" + " -d, --device=DEVICE The name of the sink 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" -- cgit