From abea726d16eecbc0ecfb60c5e23958ed5275b779 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 18 Apr 2006 13:22:41 +0000 Subject: add a jack source module git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@738 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 393 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 393 insertions(+) create mode 100644 src/modules/module-jack-source.c (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c new file mode 100644 index 00000000..eef416f6 --- /dev/null +++ b/src/modules/module-jack-source.c @@ -0,0 +1,393 @@ +/* $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 +#include +#include +#include +#include +#include + +#include "module-jack-source-symdef.h" + +PA_MODULE_AUTHOR("Lennart Poettering") +PA_MODULE_DESCRIPTION("Jack Source") +PA_MODULE_VERSION(PACKAGE_VERSION) +PA_MODULE_USAGE( + "source_name= " + "server_name= " + "client_name= " + "channels= " + "connect=" +) + +#define DEFAULT_SOURCE_NAME "jack_in" + +struct userdata { + pa_core *core; + pa_module *module; + + pa_source *source; + + unsigned channels; + + jack_port_t* port[PA_CHANNELS_MAX]; + jack_client_t *client; + + pthread_mutex_t mutex; + pthread_cond_t cond; + + void * buffer[PA_CHANNELS_MAX]; + jack_nframes_t frames_posted; + int quit_requested; + + int pipe_fds[2]; + pa_io_event *io_event; + + jack_nframes_t frames_in_buffer; + jack_nframes_t timestamp; +}; + +static const char* const valid_modargs[] = { + "source_name", + "server_name", + "client_name", + "channels", + "connect", + NULL +}; + +static void stop_source(struct userdata *u) { + assert (u); + + jack_client_close(u->client); + u->client = NULL; + u->core->mainloop->io_free(u->io_event); + u->io_event = NULL; + pa_source_disconnect(u->source); + pa_source_unref(u->source); + u->source = NULL; + pa_module_unload_request(u->module); +} + +static void io_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event_flags_t flags, void *userdata) { + struct userdata *u = userdata; + char x; + + assert(m); + assert(flags == PA_IO_EVENT_INPUT); + assert(u); + assert(u->pipe_fds[0] == fd); + + read(fd, &x, 1); + + if (u->quit_requested) { + stop_source(u); + u->quit_requested = 0; + return; + } + + pthread_mutex_lock(&u->mutex); + + if (u->frames_posted > 0) { + unsigned fs; + jack_nframes_t frame_idx; + pa_memchunk chunk; + + fs = pa_frame_size(&u->source->sample_spec); + + chunk.memblock = pa_memblock_new(chunk.length = u->frames_posted * fs, u->core->memblock_stat); + chunk.index = 0; + + for (frame_idx = 0; frame_idx < u->frames_posted; frame_idx ++) { + unsigned c; + + for (c = 0; c < u->channels; c++) { + float *s = ((float*) u->buffer[c]) + frame_idx; + float *d = ((float*) ((uint8_t*) chunk.memblock->data + chunk.index)) + (frame_idx * u->channels) + c; + + *d = *s; + } + } + + pa_source_post(u->source, &chunk); + pa_memblock_unref(chunk.memblock); + + u->frames_posted = 0; + + pthread_cond_signal(&u->cond); + } + + pthread_mutex_unlock(&u->mutex); +} + +static void request_post(struct userdata *u) { + char c = 'x'; + assert(u); + + assert(u->pipe_fds[1] >= 0); + write(u->pipe_fds[1], &c, 1); +} + +static void jack_shutdown(void *arg) { + struct userdata *u = arg; + assert(u); + + u->quit_requested = 1; + request_post(u); +} + +static int jack_process(jack_nframes_t nframes, void *arg) { + struct userdata *u = arg; + assert(u); + + if (jack_transport_query(u->client, NULL) == JackTransportRolling) { + unsigned c; + + pthread_mutex_lock(&u->mutex); + + u->frames_posted = nframes; + + for (c = 0; c < u->channels; c++) { + u->buffer[c] = jack_port_get_buffer(u->port[c], nframes); + assert(u->buffer[c]); + } + + request_post(u); + + pthread_cond_wait(&u->cond, &u->mutex); + + u->frames_in_buffer = nframes; + u->timestamp = jack_get_current_transport_frame(u->client); + + pthread_mutex_unlock(&u->mutex); + } + + return 0; +} + +static pa_usec_t source_get_latency_cb(pa_source *s) { + struct userdata *u; + jack_nframes_t n, l, d; + + assert(s); + u = s->userdata; + + if (jack_transport_query(u->client, NULL) != JackTransportRolling) + return 0; + + n = jack_get_current_transport_frame(u->client); + + if (n < u->timestamp) + return 0; + + d = n - u->timestamp; + l = jack_port_get_total_latency(u->client, u->port[0]); + + return pa_bytes_to_usec((l + d) * pa_frame_size(&s->sample_spec), &s->sample_spec); +} + +static void jack_error_func(const char*t) { + pa_log_warn(__FILE__": JACK error >%s<", t); +} + +int pa__init(pa_core *c, pa_module*m) { + struct userdata *u = NULL; + pa_sample_spec ss; + pa_channel_map cm; + pa_modargs *ma = NULL; + jack_status_t status; + const char *server_name, *client_name; + uint32_t channels = 0; + int connect = 1; + unsigned i; + const char **ports = NULL, **p; + + assert(c); + assert(m); + + jack_set_error_function(jack_error_func); + + if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { + pa_log(__FILE__": failed to parse module arguments."); + goto fail; + } + + if (pa_modargs_get_value_boolean(ma, "connect", &connect) < 0) { + pa_log(__FILE__": failed to parse connect= argument."); + goto fail; + } + + server_name = pa_modargs_get_value(ma, "server_name", NULL); + client_name = pa_modargs_get_value(ma, "client_name", "polypaudio"); + + u = pa_xnew0(struct userdata, 1); + m->userdata = u; + u->core = c; + u->module = m; + u->pipe_fds[0] = u->pipe_fds[1] = -1; + + pthread_mutex_init(&u->mutex, NULL); + pthread_cond_init(&u->cond, NULL); + + if (pipe(u->pipe_fds) < 0) { + pa_log(__FILE__": pipe() failed: %s", strerror(errno)); + goto fail; + } + + pa_make_nonblock_fd(u->pipe_fds[1]); + + if (!(u->client = jack_client_open(client_name, server_name ? JackServerName : JackNullOption, &status, server_name))) { + pa_log(__FILE__": jack_client_open() failed."); + goto fail; + } + + ports = jack_get_ports(u->client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput); + + channels = 0; + for (p = ports; *p; p++) + channels++; + + if (!channels) + channels = c->default_sample_spec.channels; + + if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 || channels <= 0 || channels >= PA_CHANNELS_MAX) { + pa_log(__FILE__": failed to parse channels= argument."); + goto fail; + } + + pa_log_info(__FILE__": Successfully connected as '%s'", jack_get_client_name(u->client)); + + ss.channels = u->channels = channels; + ss.rate = jack_get_sample_rate(u->client); + ss.format = PA_SAMPLE_FLOAT32NE; + + assert(pa_sample_spec_valid(&ss)); + + pa_channel_map_init_auto(&cm, channels); + + for (i = 0; i < ss.channels; i++) { + if (!(u->port[i] = jack_port_register(u->client, pa_channel_position_to_string(cm.map[i]), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput|JackPortIsTerminal, 0))) { + pa_log(__FILE__": jack_port_register() failed."); + goto fail; + } + } + + if (!(u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &cm))) { + pa_log(__FILE__": failed to create source."); + goto fail; + } + + u->source->userdata = u; + pa_source_set_owner(u->source, m); + u->source->description = pa_sprintf_malloc("Jack source (%s)", jack_get_client_name(u->client)); + u->source->get_latency = source_get_latency_cb; + + jack_set_process_callback(u->client, jack_process, u); + jack_on_shutdown(u->client, jack_shutdown, u); + + if (jack_activate(u->client)) { + pa_log(__FILE__": jack_activate() failed"); + goto fail; + } + + if (connect) { + for (i = 0, p = ports; i < ss.channels; i++, p++) { + + if (!*p) { + pa_log(__FILE__": not enough physical output ports, leaving unconnected."); + break; + } + + pa_log_info(__FILE__": connecting %s to %s", jack_port_name(u->port[i]), *p); + + if (jack_connect(u->client, jack_port_name(u->port[i]), *p)) { + pa_log(__FILE__": failed to connect %s to %s, leaving unconnected.", jack_port_name(u->port[i]), *p); + break; + } + } + + } + + u->io_event = c->mainloop->io_new(c->mainloop, u->pipe_fds[0], PA_IO_EVENT_INPUT, io_event_cb, u); + + free(ports); + pa_modargs_free(ma); + + return 0; + +fail: + if (ma) + pa_modargs_free(ma); + + free(ports); + + pa__done(c, m); + + return -1; +} + +void pa__done(pa_core *c, pa_module*m) { + struct userdata *u; + assert(c && m); + + if (!(u = m->userdata)) + return; + + if (u->client) + jack_client_close(u->client); + + if (u->io_event) + c->mainloop->io_free(u->io_event); + + if (u->source) { + pa_source_disconnect(u->source); + pa_source_unref(u->source); + } + + if (u->pipe_fds[0] >= 0) + close(u->pipe_fds[0]); + if (u->pipe_fds[1] >= 0) + close(u->pipe_fds[1]); + + pthread_mutex_destroy(&u->mutex); + pthread_cond_destroy(&u->cond); + pa_xfree(u); +} -- cgit From a5100be08335822c9ab87310e12d0d7f1dea870b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 18 Apr 2006 17:20:05 +0000 Subject: fix connecting of jack source in jack daemon git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@748 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index eef416f6..5f0e560d 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -338,7 +338,7 @@ int pa__init(pa_core *c, pa_module*m) { pa_log_info(__FILE__": connecting %s to %s", jack_port_name(u->port[i]), *p); - if (jack_connect(u->client, jack_port_name(u->port[i]), *p)) { + if (jack_connect(u->client, *p, jack_port_name(u->port[i]))) { pa_log(__FILE__": failed to connect %s to %s, leaving unconnected.", jack_port_name(u->port[i]), *p); break; } -- cgit From 185a57cadd7b4e8e85c7fbecc866d7c279704e12 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 26 Apr 2006 15:40:14 +0000 Subject: support new channel_map argument in sink/source modules git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@803 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 5f0e560d..ad39b9dd 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -56,7 +56,7 @@ PA_MODULE_USAGE( "client_name= " "channels= " "connect=" -) + "channel_map=") #define DEFAULT_SOURCE_NAME "jack_in" @@ -91,6 +91,7 @@ static const char* const valid_modargs[] = { "client_name", "channels", "connect", + "channel_map", NULL }; @@ -231,7 +232,7 @@ static void jack_error_func(const char*t) { int pa__init(pa_core *c, pa_module*m) { struct userdata *u = NULL; pa_sample_spec ss; - pa_channel_map cm; + pa_channel_map map; pa_modargs *ma = NULL; jack_status_t status; const char *server_name, *client_name; @@ -292,6 +293,12 @@ int pa__init(pa_core *c, pa_module*m) { pa_log(__FILE__": failed to parse channels= argument."); goto fail; } + + pa_channel_map_init_auto(&map, channels); + if (pa_modargs_get_channel_map(ma, &map) < 0 || map.channels != channels) { + pa_log(__FILE__": failed to parse channel_map= argument."); + goto fail; + } pa_log_info(__FILE__": Successfully connected as '%s'", jack_get_client_name(u->client)); @@ -301,16 +308,14 @@ int pa__init(pa_core *c, pa_module*m) { assert(pa_sample_spec_valid(&ss)); - pa_channel_map_init_auto(&cm, channels); - for (i = 0; i < ss.channels; i++) { - if (!(u->port[i] = jack_port_register(u->client, pa_channel_position_to_string(cm.map[i]), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput|JackPortIsTerminal, 0))) { + if (!(u->port[i] = jack_port_register(u->client, pa_channel_position_to_string(map.map[i]), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput|JackPortIsTerminal, 0))) { pa_log(__FILE__": jack_port_register() failed."); goto fail; } } - if (!(u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &cm))) { + if (!(u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map))) { pa_log(__FILE__": failed to create source."); goto fail; } -- cgit From 4b6ab291a787ff597c938842b569a35434ab11d8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 16 May 2006 23:47:38 +0000 Subject: * modify pa_channel_map_init_auto() to take an extra argument specifying the standard to use (ALSA, AIFF, ...) * add some more validity checks to pa_source_new(),pa_sink_new(),pa_sink_input_new(),pa_source_output_new() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@888 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index ad39b9dd..94cabbea 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -294,7 +294,7 @@ int pa__init(pa_core *c, pa_module*m) { goto fail; } - pa_channel_map_init_auto(&map, channels); + pa_channel_map_init_auto(&map, channels, PA_CHANNEL_MAP_ALSA); if (pa_modargs_get_channel_map(ma, &map) < 0 || map.channels != channels) { pa_log(__FILE__": failed to parse channel_map= argument."); goto fail; -- cgit From d9cc2cfcb97c1b0449bcbfb6ab0301a58d77bd55 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 17 May 2006 16:34:18 +0000 Subject: Move xmalloc to the public side (libpolyp). git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@908 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 94cabbea..29c46d85 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -36,12 +36,13 @@ #include +#include + #include #include #include #include #include -#include #include #include -- cgit From c47e937011f00eebab7230cedb58fd59f16487b4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 May 2006 20:09:57 +0000 Subject: split polypcore/util.[ch] into polypcore/core-util.[ch] and polyp/util.[ch] git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@917 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 29c46d85..3d783145 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include #include -- cgit From 4e3dc7ce68561c16254712d713b2ccd472b8afe7 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 22 May 2006 15:20:46 +0000 Subject: Wrap strerror() in a function that makes it thread safe and converts the output to UTF-8. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@945 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 3d783145..8816fb8a 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -36,6 +36,7 @@ #include +#include #include #include @@ -270,7 +271,7 @@ int pa__init(pa_core *c, pa_module*m) { pthread_cond_init(&u->cond, NULL); if (pipe(u->pipe_fds) < 0) { - pa_log(__FILE__": pipe() failed: %s", strerror(errno)); + pa_log(__FILE__": pipe() failed: %s", pa_cstrerror(errno)); goto fail; } -- cgit From 4413b89d7a45587b545a31463ad2196767f45563 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 25 May 2006 17:16:55 +0000 Subject: * split pa_cstrerror() into its own file polypcore/core-error.[ch] * fix building of padsp * remove a warning when compiling padsp.c git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@972 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 8816fb8a..ca9560a6 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -36,9 +36,9 @@ #include -#include #include +#include #include #include #include -- 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/modules/module-jack-source.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index ca9560a6..6f31f6c3 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.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. ***/ @@ -36,16 +36,16 @@ #include -#include +#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include "module-jack-source-symdef.h" @@ -259,7 +259,7 @@ int pa__init(pa_core *c, pa_module*m) { } server_name = pa_modargs_get_value(ma, "server_name", NULL); - client_name = pa_modargs_get_value(ma, "client_name", "polypaudio"); + client_name = pa_modargs_get_value(ma, "client_name", "pulseaudio"); u = pa_xnew0(struct userdata, 1); m->userdata = u; -- cgit From 3cf16214334b4a1c51e56b0536abd8223d6813dd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 23:51:58 +0000 Subject: * more s/pulseaudio/PulseAudio/ replacements * name the per-user dir ~/.pulse (instead of .pulseaudio), just like /etc/pulse/ git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1039 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 6f31f6c3..9c7f449f 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -259,7 +259,7 @@ int pa__init(pa_core *c, pa_module*m) { } server_name = pa_modargs_get_value(ma, "server_name", NULL); - client_name = pa_modargs_get_value(ma, "client_name", "pulseaudio"); + client_name = pa_modargs_get_value(ma, "client_name", "PulseAudio"); u = pa_xnew0(struct userdata, 1); m->userdata = u; -- cgit From 860be2e70b33ff5eeb9130f80c4b1c096a2a8f27 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 14 Jul 2006 22:42:01 +0000 Subject: try to use send(,,MSG_NOSIGNAL) instead of write() wherever possible (which will allow us to drop the SIGPIPE check). Cache the results of the last write()/send() to make sure that we do not issue more than necessary system calls. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1083 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 9c7f449f..649a8f98 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -81,6 +81,7 @@ struct userdata { int quit_requested; int pipe_fds[2]; + int pipe_fd_type; pa_io_event *io_event; jack_nframes_t frames_in_buffer; @@ -119,7 +120,7 @@ static void io_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event_ assert(u); assert(u->pipe_fds[0] == fd); - read(fd, &x, 1); + pa_read(fd, &x, 1, &u->pipe_fd_type); if (u->quit_requested) { stop_source(u); @@ -166,7 +167,7 @@ static void request_post(struct userdata *u) { assert(u); assert(u->pipe_fds[1] >= 0); - write(u->pipe_fds[1], &c, 1); + pa_write(u->pipe_fds[1], &c, 1, &u->pipe_fd_type); } static void jack_shutdown(void *arg) { @@ -266,6 +267,7 @@ int pa__init(pa_core *c, pa_module*m) { u->core = c; u->module = m; u->pipe_fds[0] = u->pipe_fds[1] = -1; + u->pipe_fd_type = 0; pthread_mutex_init(&u->mutex, NULL); pthread_cond_init(&u->cond, NULL); -- cgit From a382492204ad3588c0c837e120e5bc31578df72a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Jul 2006 21:48:35 +0000 Subject: * add new function pa_check_in_group() * abstract credential APis a little bit by introducing HAVE_CREDS and a structure pa_creds * rework credential authentication * fix module-volume-restore and friends for usage in system-wide instance * remove loopback= argument from moulde-*-protocol-tcp since it is a superset of listen= and usually a bad idea anyway since the user shouldn't load the TCP module at all if he doesn't want remote access * rename a few variables in the jack modules to make sure they don't conflict with symbols defined in the system headers * add server address for system-wide daemons to the default server list for the the client libs * update todo git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1109 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 649a8f98..2a492929 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -240,7 +240,7 @@ int pa__init(pa_core *c, pa_module*m) { jack_status_t status; const char *server_name, *client_name; uint32_t channels = 0; - int connect = 1; + int do_connect = 1; unsigned i; const char **ports = NULL, **p; @@ -254,7 +254,7 @@ int pa__init(pa_core *c, pa_module*m) { goto fail; } - if (pa_modargs_get_value_boolean(ma, "connect", &connect) < 0) { + if (pa_modargs_get_value_boolean(ma, "connect", &do_connect) < 0) { pa_log(__FILE__": failed to parse connect= argument."); goto fail; } @@ -337,7 +337,7 @@ int pa__init(pa_core *c, pa_module*m) { goto fail; } - if (connect) { + if (do_connect) { for (i = 0, p = ports; i < ss.channels; i++, p++) { if (!*p) { -- cgit From bfa6604b1ddc5e2c0f1aaa15330363724856359b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 11 Aug 2006 23:58:55 +0000 Subject: don't set the sink/source descriptions manually, use the new functions pa_{sink,source}_set_description() instead git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1205 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 2a492929..583f3b8e 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -243,6 +243,7 @@ int pa__init(pa_core *c, pa_module*m) { int do_connect = 1; unsigned i; const char **ports = NULL, **p; + char *t; assert(c); assert(m); @@ -326,7 +327,8 @@ int pa__init(pa_core *c, pa_module*m) { u->source->userdata = u; pa_source_set_owner(u->source, m); - u->source->description = pa_sprintf_malloc("Jack source (%s)", jack_get_client_name(u->client)); + pa_source_set_description(u->source, t = pa_sprintf_malloc("Jack source (%s)", jack_get_client_name(u->client))); + pa_xfree(t); u->source->get_latency = source_get_latency_cb; jack_set_process_callback(u->client, jack_process, u); -- cgit From 0e436a6926af56f37a74a03bb5e143e078ca0d55 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 18 Aug 2006 19:55:18 +0000 Subject: Rework memory management to allow shared memory data transfer. The central idea is to allocate all audio memory blocks from a per-process memory pool which is available as read-only SHM segment to other local processes. Then, instead of writing the actual audio data to the socket just write references to this shared memory pool. To work optimally all memory blocks should now be of type PA_MEMBLOCK_POOL or PA_MEMBLOCK_POOL_EXTERNAL. The function pa_memblock_new() now generates memory blocks of this type by default. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1266 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 583f3b8e..8e659198 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -137,7 +137,7 @@ static void io_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event_ fs = pa_frame_size(&u->source->sample_spec); - chunk.memblock = pa_memblock_new(chunk.length = u->frames_posted * fs, u->core->memblock_stat); + chunk.memblock = pa_memblock_new(u->core->mempool, chunk.length = u->frames_posted * fs); chunk.index = 0; for (frame_idx = 0; frame_idx < u->frames_posted; frame_idx ++) { -- cgit From e385d93e5aad6a6fce754c00c804ff1d6a6746d4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 18 Aug 2006 21:38:40 +0000 Subject: remove all occurences of pa_logXXX(__FILE__": and replace them by pa_logXXX(" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1272 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 8e659198..62a99108 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -229,7 +229,7 @@ static pa_usec_t source_get_latency_cb(pa_source *s) { } static void jack_error_func(const char*t) { - pa_log_warn(__FILE__": JACK error >%s<", t); + pa_log_warn("JACK error >%s<", t); } int pa__init(pa_core *c, pa_module*m) { @@ -251,12 +251,12 @@ int pa__init(pa_core *c, pa_module*m) { jack_set_error_function(jack_error_func); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { - pa_log(__FILE__": failed to parse module arguments."); + pa_log("failed to parse module arguments."); goto fail; } if (pa_modargs_get_value_boolean(ma, "connect", &do_connect) < 0) { - pa_log(__FILE__": failed to parse connect= argument."); + pa_log("failed to parse connect= argument."); goto fail; } @@ -274,14 +274,14 @@ int pa__init(pa_core *c, pa_module*m) { pthread_cond_init(&u->cond, NULL); if (pipe(u->pipe_fds) < 0) { - pa_log(__FILE__": pipe() failed: %s", pa_cstrerror(errno)); + pa_log("pipe() failed: %s", pa_cstrerror(errno)); goto fail; } pa_make_nonblock_fd(u->pipe_fds[1]); if (!(u->client = jack_client_open(client_name, server_name ? JackServerName : JackNullOption, &status, server_name))) { - pa_log(__FILE__": jack_client_open() failed."); + pa_log("jack_client_open() failed."); goto fail; } @@ -295,17 +295,17 @@ int pa__init(pa_core *c, pa_module*m) { channels = c->default_sample_spec.channels; if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 || channels <= 0 || channels >= PA_CHANNELS_MAX) { - pa_log(__FILE__": failed to parse channels= argument."); + pa_log("failed to parse channels= argument."); goto fail; } pa_channel_map_init_auto(&map, channels, PA_CHANNEL_MAP_ALSA); if (pa_modargs_get_channel_map(ma, &map) < 0 || map.channels != channels) { - pa_log(__FILE__": failed to parse channel_map= argument."); + pa_log("failed to parse channel_map= argument."); goto fail; } - pa_log_info(__FILE__": Successfully connected as '%s'", jack_get_client_name(u->client)); + pa_log_info("Successfully connected as '%s'", jack_get_client_name(u->client)); ss.channels = u->channels = channels; ss.rate = jack_get_sample_rate(u->client); @@ -315,13 +315,13 @@ int pa__init(pa_core *c, pa_module*m) { for (i = 0; i < ss.channels; i++) { if (!(u->port[i] = jack_port_register(u->client, pa_channel_position_to_string(map.map[i]), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput|JackPortIsTerminal, 0))) { - pa_log(__FILE__": jack_port_register() failed."); + pa_log("jack_port_register() failed."); goto fail; } } if (!(u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map))) { - pa_log(__FILE__": failed to create source."); + pa_log("failed to create source."); goto fail; } @@ -335,7 +335,7 @@ int pa__init(pa_core *c, pa_module*m) { jack_on_shutdown(u->client, jack_shutdown, u); if (jack_activate(u->client)) { - pa_log(__FILE__": jack_activate() failed"); + pa_log("jack_activate() failed"); goto fail; } @@ -343,14 +343,14 @@ int pa__init(pa_core *c, pa_module*m) { for (i = 0, p = ports; i < ss.channels; i++, p++) { if (!*p) { - pa_log(__FILE__": not enough physical output ports, leaving unconnected."); + pa_log("not enough physical output ports, leaving unconnected."); break; } - pa_log_info(__FILE__": connecting %s to %s", jack_port_name(u->port[i]), *p); + pa_log_info("connecting %s to %s", jack_port_name(u->port[i]), *p); if (jack_connect(u->client, *p, jack_port_name(u->port[i]))) { - pa_log(__FILE__": failed to connect %s to %s, leaving unconnected.", jack_port_name(u->port[i]), *p); + pa_log("failed to connect %s to %s, leaving unconnected.", jack_port_name(u->port[i]), *p); break; } } -- cgit From d210ebbb09daddb2c8c8e8e77243e088b0b19c4d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 26 Sep 2006 23:50:56 +0000 Subject: rework memory block management to be thread-safe and mostly lock-free. pa_memblock is now an opaque structure. Access to its fields is now done through various accessor functions in a thread-safe manner. pa_memblock_acquire() and pa_memblock_release() are now used to access the attached audio data. Why? To allow safe manipulation of the memory pointer maintained by the memory block. Internally _acquire() and _release() maintain a reference counter. Please do not confuse this reference counter whith the one maintained by pa_memblock_ref()/_unref()! As a side effect this patch removes all direct usages of AO_t and replaces it with pa_atomic_xxx based code. This stuff needs some serious testing love. Especially if threads are actively used. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1404 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 62a99108..5270b241 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -134,23 +134,28 @@ static void io_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event_ unsigned fs; jack_nframes_t frame_idx; pa_memchunk chunk; + void *p; fs = pa_frame_size(&u->source->sample_spec); chunk.memblock = pa_memblock_new(u->core->mempool, chunk.length = u->frames_posted * fs); chunk.index = 0; + + p = pa_memblock_acquire(chunk.memblock); for (frame_idx = 0; frame_idx < u->frames_posted; frame_idx ++) { unsigned c; for (c = 0; c < u->channels; c++) { float *s = ((float*) u->buffer[c]) + frame_idx; - float *d = ((float*) ((uint8_t*) chunk.memblock->data + chunk.index)) + (frame_idx * u->channels) + c; + float *d = ((float*) ((uint8_t*) p + chunk.index)) + (frame_idx * u->channels) + c; *d = *s; } } + pa_memblock_release(chunk.memblock); + pa_source_post(u->source, &chunk); pa_memblock_unref(chunk.memblock); -- cgit From 8dc62142765249addf131b058c27f931ede1776b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 6 Nov 2006 13:06:01 +0000 Subject: Revert r1404 and keep it on a development branch until it is fully tested. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1409 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 5270b241..62a99108 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -134,28 +134,23 @@ static void io_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event_ unsigned fs; jack_nframes_t frame_idx; pa_memchunk chunk; - void *p; fs = pa_frame_size(&u->source->sample_spec); chunk.memblock = pa_memblock_new(u->core->mempool, chunk.length = u->frames_posted * fs); chunk.index = 0; - - p = pa_memblock_acquire(chunk.memblock); for (frame_idx = 0; frame_idx < u->frames_posted; frame_idx ++) { unsigned c; for (c = 0; c < u->channels; c++) { float *s = ((float*) u->buffer[c]) + frame_idx; - float *d = ((float*) ((uint8_t*) p + chunk.index)) + (frame_idx * u->channels) + c; + float *d = ((float*) ((uint8_t*) chunk.memblock->data + chunk.index)) + (frame_idx * u->channels) + c; *d = *s; } } - pa_memblock_release(chunk.memblock); - pa_source_post(u->source, &chunk); pa_memblock_unref(chunk.memblock); -- 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/modules/module-jack-source.c | 70 ++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 62a99108..8d891ce6 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.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 @@ -75,7 +75,7 @@ struct userdata { pthread_mutex_t mutex; pthread_cond_t cond; - + void * buffer[PA_CHANNELS_MAX]; jack_nframes_t frames_posted; int quit_requested; @@ -100,7 +100,7 @@ static const char* const valid_modargs[] = { static void stop_source(struct userdata *u) { assert (u); - + jack_client_close(u->client); u->client = NULL; u->core->mainloop->io_free(u->io_event); @@ -114,39 +114,39 @@ static void stop_source(struct userdata *u) { static void io_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event_flags_t flags, void *userdata) { struct userdata *u = userdata; char x; - + assert(m); assert(flags == PA_IO_EVENT_INPUT); assert(u); assert(u->pipe_fds[0] == fd); pa_read(fd, &x, 1, &u->pipe_fd_type); - + if (u->quit_requested) { stop_source(u); u->quit_requested = 0; return; } - + pthread_mutex_lock(&u->mutex); if (u->frames_posted > 0) { unsigned fs; jack_nframes_t frame_idx; pa_memchunk chunk; - + fs = pa_frame_size(&u->source->sample_spec); chunk.memblock = pa_memblock_new(u->core->mempool, chunk.length = u->frames_posted * fs); chunk.index = 0; - + for (frame_idx = 0; frame_idx < u->frames_posted; frame_idx ++) { unsigned c; - + for (c = 0; c < u->channels; c++) { float *s = ((float*) u->buffer[c]) + frame_idx; float *d = ((float*) ((uint8_t*) chunk.memblock->data + chunk.index)) + (frame_idx * u->channels) + c; - + *d = *s; } } @@ -155,7 +155,7 @@ static void io_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event_ pa_memblock_unref(chunk.memblock); u->frames_posted = 0; - + pthread_cond_signal(&u->cond); } @@ -184,36 +184,36 @@ static int jack_process(jack_nframes_t nframes, void *arg) { if (jack_transport_query(u->client, NULL) == JackTransportRolling) { unsigned c; - + pthread_mutex_lock(&u->mutex); - + u->frames_posted = nframes; - + for (c = 0; c < u->channels; c++) { u->buffer[c] = jack_port_get_buffer(u->port[c], nframes); assert(u->buffer[c]); } - + request_post(u); - + pthread_cond_wait(&u->cond, &u->mutex); u->frames_in_buffer = nframes; u->timestamp = jack_get_current_transport_frame(u->client); - + pthread_mutex_unlock(&u->mutex); } - + return 0; } static pa_usec_t source_get_latency_cb(pa_source *s) { struct userdata *u; jack_nframes_t n, l, d; - + assert(s); u = s->userdata; - + if (jack_transport_query(u->client, NULL) != JackTransportRolling) return 0; @@ -224,7 +224,7 @@ static pa_usec_t source_get_latency_cb(pa_source *s) { d = n - u->timestamp; l = jack_port_get_total_latency(u->client, u->port[0]); - + return pa_bytes_to_usec((l + d) * pa_frame_size(&s->sample_spec), &s->sample_spec); } @@ -244,12 +244,12 @@ int pa__init(pa_core *c, pa_module*m) { unsigned i; const char **ports = NULL, **p; char *t; - + assert(c); assert(m); jack_set_error_function(jack_error_func); - + if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("failed to parse module arguments."); goto fail; @@ -259,7 +259,7 @@ int pa__init(pa_core *c, pa_module*m) { pa_log("failed to parse connect= argument."); goto fail; } - + server_name = pa_modargs_get_value(ma, "server_name", NULL); client_name = pa_modargs_get_value(ma, "client_name", "PulseAudio"); @@ -272,28 +272,28 @@ int pa__init(pa_core *c, pa_module*m) { pthread_mutex_init(&u->mutex, NULL); pthread_cond_init(&u->cond, NULL); - + if (pipe(u->pipe_fds) < 0) { pa_log("pipe() failed: %s", pa_cstrerror(errno)); goto fail; } pa_make_nonblock_fd(u->pipe_fds[1]); - + if (!(u->client = jack_client_open(client_name, server_name ? JackServerName : JackNullOption, &status, server_name))) { pa_log("jack_client_open() failed."); goto fail; } ports = jack_get_ports(u->client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput); - + channels = 0; for (p = ports; *p; p++) channels++; if (!channels) channels = c->default_sample_spec.channels; - + if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 || channels <= 0 || channels >= PA_CHANNELS_MAX) { pa_log("failed to parse channels= argument."); goto fail; @@ -304,7 +304,7 @@ int pa__init(pa_core *c, pa_module*m) { pa_log("failed to parse channel_map= argument."); goto fail; } - + pa_log_info("Successfully connected as '%s'", jack_get_client_name(u->client)); ss.channels = u->channels = channels; @@ -348,7 +348,7 @@ int pa__init(pa_core *c, pa_module*m) { } pa_log_info("connecting %s to %s", jack_port_name(u->port[i]), *p); - + if (jack_connect(u->client, *p, jack_port_name(u->port[i]))) { pa_log("failed to connect %s to %s, leaving unconnected.", jack_port_name(u->port[i]), *p); break; @@ -358,10 +358,10 @@ int pa__init(pa_core *c, pa_module*m) { } u->io_event = c->mainloop->io_new(c->mainloop, u->pipe_fds[0], PA_IO_EVENT_INPUT, io_event_cb, u); - + free(ports); pa_modargs_free(ma); - + return 0; fail: @@ -369,7 +369,7 @@ fail: pa_modargs_free(ma); free(ports); - + pa__done(c, m); return -1; -- 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/modules/module-jack-source.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 8d891ce6..8ca24035 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -3,6 +3,8 @@ /*** This file is part of PulseAudio. + Copyright 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, -- 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/modules/module-jack-source.c | 315 +++++++++++++++++++++------------------ 1 file changed, 167 insertions(+), 148 deletions(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 8ca24035..b62ebe7a 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -28,31 +28,34 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include -#include #include #include #include #include #include -#include +#include +#include +#include +#include #include "module-jack-source-symdef.h" +/* See module-jack-sink for a few comments how this module basically + * works */ + PA_MODULE_AUTHOR("Lennart Poettering") -PA_MODULE_DESCRIPTION("Jack Source") +PA_MODULE_DESCRIPTION("JACK Source") PA_MODULE_VERSION(PACKAGE_VERSION) PA_MODULE_USAGE( "source_name= " @@ -67,7 +70,6 @@ PA_MODULE_USAGE( struct userdata { pa_core *core; pa_module *module; - pa_source *source; unsigned channels; @@ -75,19 +77,15 @@ struct userdata { jack_port_t* port[PA_CHANNELS_MAX]; jack_client_t *client; - pthread_mutex_t mutex; - pthread_cond_t cond; + pa_thread_mq thread_mq; + pa_asyncmsgq *jack_msgq; + pa_rtpoll *rtpoll; + pa_rtpoll_item *rtpoll_item; - void * buffer[PA_CHANNELS_MAX]; - jack_nframes_t frames_posted; - int quit_requested; + pa_thread *thread; - int pipe_fds[2]; - int pipe_fd_type; - pa_io_event *io_event; - - jack_nframes_t frames_in_buffer; - jack_nframes_t timestamp; + jack_nframes_t saved_frame_time; + pa_bool_t saved_frame_time_valid; }; static const char* const valid_modargs[] = { @@ -100,141 +98,150 @@ static const char* const valid_modargs[] = { NULL }; -static void stop_source(struct userdata *u) { - assert (u); - - jack_client_close(u->client); - u->client = NULL; - u->core->mainloop->io_free(u->io_event); - u->io_event = NULL; - pa_source_disconnect(u->source); - pa_source_unref(u->source); - u->source = NULL; - pa_module_unload_request(u->module); -} +enum { + SOURCE_MESSAGE_POST = PA_SOURCE_MESSAGE_MAX, + SOURCE_MESSAGE_ON_SHUTDOWN +}; -static void io_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event_flags_t flags, void *userdata) { - struct userdata *u = userdata; - char x; +static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) { + struct userdata *u = PA_SOURCE(o)->userdata; - assert(m); - assert(flags == PA_IO_EVENT_INPUT); - assert(u); - assert(u->pipe_fds[0] == fd); + switch (code) { - pa_read(fd, &x, 1, &u->pipe_fd_type); + case SOURCE_MESSAGE_POST: - if (u->quit_requested) { - stop_source(u); - u->quit_requested = 0; - return; - } + /* Handle the new block from the JACK thread */ + pa_assert(chunk); + pa_assert(chunk->length > 0); - pthread_mutex_lock(&u->mutex); + if (u->source->thread_info.state == PA_SOURCE_RUNNING) + pa_source_post(u->source, chunk); - if (u->frames_posted > 0) { - unsigned fs; - jack_nframes_t frame_idx; - pa_memchunk chunk; + u->saved_frame_time = offset; + u->saved_frame_time_valid = TRUE; - fs = pa_frame_size(&u->source->sample_spec); + return 0; - chunk.memblock = pa_memblock_new(u->core->mempool, chunk.length = u->frames_posted * fs); - chunk.index = 0; + case SOURCE_MESSAGE_ON_SHUTDOWN: + pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL); + return 0; - for (frame_idx = 0; frame_idx < u->frames_posted; frame_idx ++) { - unsigned c; + case PA_SOURCE_MESSAGE_GET_LATENCY: { + jack_nframes_t l, ft, d; + size_t n; - for (c = 0; c < u->channels; c++) { - float *s = ((float*) u->buffer[c]) + frame_idx; - float *d = ((float*) ((uint8_t*) chunk.memblock->data + chunk.index)) + (frame_idx * u->channels) + c; + /* This is the "worst-case" latency */ + l = jack_port_get_total_latency(u->client, u->port[0]); - *d = *s; - } - } + if (u->saved_frame_time_valid) { + /* Adjust the worst case latency by the time that + * passed since we last handed data to JACK */ - pa_source_post(u->source, &chunk); - pa_memblock_unref(chunk.memblock); + ft = jack_frame_time(u->client); + d = ft > u->saved_frame_time ? ft - u->saved_frame_time : 0; + l += d; + } - u->frames_posted = 0; + /* Convert it to usec */ + n = l * pa_frame_size(&u->source->sample_spec); + *((pa_usec_t*) data) = pa_bytes_to_usec(n, &u->source->sample_spec); - pthread_cond_signal(&u->cond); + return 0; + } } - pthread_mutex_unlock(&u->mutex); -} - -static void request_post(struct userdata *u) { - char c = 'x'; - assert(u); - - assert(u->pipe_fds[1] >= 0); - pa_write(u->pipe_fds[1], &c, 1, &u->pipe_fd_type); -} - -static void jack_shutdown(void *arg) { - struct userdata *u = arg; - assert(u); - - u->quit_requested = 1; - request_post(u); + return pa_source_process_msg(o, code, data, offset, chunk); } static int jack_process(jack_nframes_t nframes, void *arg) { + unsigned c; struct userdata *u = arg; - assert(u); - - if (jack_transport_query(u->client, NULL) == JackTransportRolling) { - unsigned c; + const void *buffer[PA_CHANNELS_MAX]; + void *p; + jack_nframes_t frame_time; + pa_memchunk chunk; - pthread_mutex_lock(&u->mutex); + pa_assert(u); - u->frames_posted = nframes; + for (c = 0; c < u->channels; c++) + pa_assert(buffer[c] = jack_port_get_buffer(u->port[c], nframes)); - for (c = 0; c < u->channels; c++) { - u->buffer[c] = jack_port_get_buffer(u->port[c], nframes); - assert(u->buffer[c]); - } + /* We interleave the data and pass it on to the other RT thread */ - request_post(u); + pa_memchunk_reset(&chunk); + chunk.length = nframes * pa_frame_size(&u->source->sample_spec); + chunk.memblock = pa_memblock_new(u->core->mempool, chunk.length); + p = pa_memblock_acquire(chunk.memblock); + pa_interleave(buffer, u->channels, p, sizeof(float), nframes); + pa_memblock_release(chunk.memblock); - pthread_cond_wait(&u->cond, &u->mutex); + frame_time = jack_frame_time(u->client); - u->frames_in_buffer = nframes; - u->timestamp = jack_get_current_transport_frame(u->client); + pa_asyncmsgq_post(u->jack_msgq, PA_MSGOBJECT(u->source), SOURCE_MESSAGE_POST, NULL, frame_time, &chunk, NULL); - pthread_mutex_unlock(&u->mutex); - } + pa_memblock_unref(chunk.memblock); return 0; } -static pa_usec_t source_get_latency_cb(pa_source *s) { - struct userdata *u; - jack_nframes_t n, l, d; +static void thread_func(void *userdata) { + struct userdata *u = userdata; + + pa_assert(u); - assert(s); - u = s->userdata; + pa_log_debug("Thread starting up"); - if (jack_transport_query(u->client, NULL) != JackTransportRolling) - return 0; + if (u->core->high_priority) + pa_make_realtime(); - n = jack_get_current_transport_frame(u->client); + pa_thread_mq_install(&u->thread_mq); + pa_rtpoll_install(u->rtpoll); - if (n < u->timestamp) - return 0; + for (;;) { + int ret; - d = n - u->timestamp; - l = jack_port_get_total_latency(u->client, u->port[0]); + if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) + goto fail; + + if (ret == 0) + goto finish; + } - return pa_bytes_to_usec((l + d) * pa_frame_size(&s->sample_spec), &s->sample_spec); +fail: + /* If this was no regular exit from the loop we have to continue + * processing messages until we received PA_MESSAGE_SHUTDOWN */ + pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL); + pa_asyncmsgq_wait_for(u->thread_mq.inq, PA_MESSAGE_SHUTDOWN); + +finish: + pa_log_debug("Thread shutting down"); } static void jack_error_func(const char*t) { - pa_log_warn("JACK error >%s<", t); + char *s; + + s = pa_xstrndup(t, strcspn(t, "\n\r")); + pa_log_warn("JACK error >%s<", s); + pa_xfree(s); +} + +static void jack_init(void *arg) { + struct userdata *u = arg; + + pa_log_info("JACK thread starting up."); + + if (u->core->high_priority) + pa_make_realtime(); } -int pa__init(pa_core *c, pa_module*m) { +static void jack_shutdown(void* arg) { + struct userdata *u = arg; + + pa_log_info("JACK thread shutting down.."); + pa_asyncmsgq_post(u->jack_msgq, PA_MSGOBJECT(u->source), SOURCE_MESSAGE_ON_SHUTDOWN, NULL, 0, NULL, NULL); +} + +int pa__init(pa_module*m) { struct userdata *u = NULL; pa_sample_spec ss; pa_channel_map map; @@ -247,40 +254,35 @@ int pa__init(pa_core *c, pa_module*m) { const char **ports = NULL, **p; char *t; - assert(c); - assert(m); + pa_assert(m); jack_set_error_function(jack_error_func); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { - pa_log("failed to parse module arguments."); + pa_log("Failed to parse module arguments."); goto fail; } if (pa_modargs_get_value_boolean(ma, "connect", &do_connect) < 0) { - pa_log("failed to parse connect= argument."); + pa_log("Failed to parse connect= argument."); goto fail; } server_name = pa_modargs_get_value(ma, "server_name", NULL); - client_name = pa_modargs_get_value(ma, "client_name", "PulseAudio"); + client_name = pa_modargs_get_value(ma, "client_name", "PulseAudio JACK Source"); u = pa_xnew0(struct userdata, 1); - m->userdata = u; - u->core = c; + u->core = m->core; u->module = m; - u->pipe_fds[0] = u->pipe_fds[1] = -1; - u->pipe_fd_type = 0; - - pthread_mutex_init(&u->mutex, NULL); - pthread_cond_init(&u->cond, NULL); + m->userdata = u; + u->saved_frame_time_valid = FALSE; - if (pipe(u->pipe_fds) < 0) { - pa_log("pipe() failed: %s", pa_cstrerror(errno)); - goto fail; - } + pa_thread_mq_init(&u->thread_mq, m->core->mainloop); + u->rtpoll = pa_rtpoll_new(); + pa_rtpoll_item_new_asyncmsgq(u->rtpoll, PA_RTPOLL_EARLY, u->thread_mq.inq); - pa_make_nonblock_fd(u->pipe_fds[1]); + u->jack_msgq = pa_asyncmsgq_new(0); + u->rtpoll_item = pa_rtpoll_item_new_asyncmsgq(u->rtpoll, PA_RTPOLL_EARLY-1, u->jack_msgq); if (!(u->client = jack_client_open(client_name, server_name ? JackServerName : JackNullOption, &status, server_name))) { pa_log("jack_client_open() failed."); @@ -294,7 +296,7 @@ int pa__init(pa_core *c, pa_module*m) { channels++; if (!channels) - channels = c->default_sample_spec.channels; + channels = m->core->default_sample_spec.channels; if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 || channels <= 0 || channels >= PA_CHANNELS_MAX) { pa_log("failed to parse channels= argument."); @@ -302,7 +304,7 @@ int pa__init(pa_core *c, pa_module*m) { } pa_channel_map_init_auto(&map, channels, PA_CHANNEL_MAP_ALSA); - if (pa_modargs_get_channel_map(ma, &map) < 0 || map.channels != channels) { + if (pa_modargs_get_channel_map(ma, NULL, &map) < 0 || map.channels != channels) { pa_log("failed to parse channel_map= argument."); goto fail; } @@ -313,7 +315,7 @@ int pa__init(pa_core *c, pa_module*m) { ss.rate = jack_get_sample_rate(u->client); ss.format = PA_SAMPLE_FLOAT32NE; - assert(pa_sample_spec_valid(&ss)); + pa_assert(pa_sample_spec_valid(&ss)); for (i = 0; i < ss.channels; i++) { if (!(u->port[i] = jack_port_register(u->client, pa_channel_position_to_string(map.map[i]), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput|JackPortIsTerminal, 0))) { @@ -322,19 +324,29 @@ int pa__init(pa_core *c, pa_module*m) { } } - if (!(u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map))) { + if (!(u->source = pa_source_new(m->core, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map))) { pa_log("failed to create source."); goto fail; } + u->source->parent.process_msg = source_process_msg; u->source->userdata = u; - pa_source_set_owner(u->source, m); + u->source->flags = PA_SOURCE_LATENCY; + + pa_source_set_module(u->source, m); + pa_source_set_asyncmsgq(u->source, u->thread_mq.inq); + pa_source_set_rtpoll(u->source, u->rtpoll); pa_source_set_description(u->source, t = pa_sprintf_malloc("Jack source (%s)", jack_get_client_name(u->client))); pa_xfree(t); - u->source->get_latency = source_get_latency_cb; jack_set_process_callback(u->client, jack_process, u); jack_on_shutdown(u->client, jack_shutdown, u); + jack_set_thread_init_callback(u->client, jack_init, u); + + if (!(u->thread = pa_thread_new(thread_func, u))) { + pa_log("Failed to create thread."); + goto fail; + } if (jack_activate(u->client)) { pa_log("jack_activate() failed"); @@ -359,7 +371,7 @@ int pa__init(pa_core *c, pa_module*m) { } - u->io_event = c->mainloop->io_new(c->mainloop, u->pipe_fds[0], PA_IO_EVENT_INPUT, io_event_cb, u); + pa_source_put(u->source); free(ports); pa_modargs_free(ma); @@ -372,14 +384,14 @@ fail: free(ports); - pa__done(c, m); + pa__done(m); return -1; } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) { struct userdata *u; - assert(c && m); + pa_assert(m); if (!(u = m->userdata)) return; @@ -387,20 +399,27 @@ void pa__done(pa_core *c, pa_module*m) { if (u->client) jack_client_close(u->client); - if (u->io_event) - c->mainloop->io_free(u->io_event); + if (u->source) + pa_source_unlink(u->source); - if (u->source) { - pa_source_disconnect(u->source); - pa_source_unref(u->source); + if (u->thread) { + pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL); + pa_thread_free(u->thread); } - if (u->pipe_fds[0] >= 0) - close(u->pipe_fds[0]); - if (u->pipe_fds[1] >= 0) - close(u->pipe_fds[1]); + pa_thread_mq_done(&u->thread_mq); + + if (u->source) + pa_source_unref(u->source); + + if (u->rtpoll_item) + pa_rtpoll_item_free(u->rtpoll_item); + + if (u->jack_msgq) + pa_asyncmsgq_unref(u->jack_msgq); + + if (u->rtpoll) + pa_rtpoll_free(u->rtpoll); - pthread_mutex_destroy(&u->mutex); - pthread_cond_destroy(&u->cond); pa_xfree(u); } -- cgit From 7bfd1b2f01613dd14b9ca478ae530c1641aa46a1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 1 Nov 2007 02:58:26 +0000 Subject: make rtprio and nice level actually configurable git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2014 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index b62ebe7a..380f87eb 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -191,8 +191,8 @@ static void thread_func(void *userdata) { pa_log_debug("Thread starting up"); - if (u->core->high_priority) - pa_make_realtime(); + if (u->core->realtime_scheduling) + pa_make_realtime(u->core->realtime_priority); pa_thread_mq_install(&u->thread_mq); pa_rtpoll_install(u->rtpoll); @@ -230,8 +230,8 @@ static void jack_init(void *arg) { pa_log_info("JACK thread starting up."); - if (u->core->high_priority) - pa_make_realtime(); + if (u->core->realtime_scheduling) + pa_make_realtime(u->core->realtime_priority+4); } static void jack_shutdown(void* arg) { -- cgit From e313fe1b3d0d9f9945c41c151d72edbe9cf1ec54 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 9 Nov 2007 18:25:40 +0000 Subject: tag modules that may only be loaded once at most especially, and enforce that in the module loader git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2043 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 380f87eb..93618020 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -54,16 +54,17 @@ /* See module-jack-sink for a few comments how this module basically * works */ -PA_MODULE_AUTHOR("Lennart Poettering") -PA_MODULE_DESCRIPTION("JACK Source") -PA_MODULE_VERSION(PACKAGE_VERSION) +PA_MODULE_AUTHOR("Lennart Poettering"); +PA_MODULE_DESCRIPTION("JACK Source"); +PA_MODULE_VERSION(PACKAGE_VERSION); +PA_MODULE_LOAD_ONCE(TRUE); PA_MODULE_USAGE( "source_name= " "server_name= " "client_name= " "channels= " "connect=" - "channel_map=") + "channel_map="); #define DEFAULT_SOURCE_NAME "jack_in" -- cgit From 9b75b9de563bb61ef4b8f2000ed973fecba1137a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 14 Nov 2007 16:09:03 +0000 Subject: add missing pa_boolization git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2056 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 93618020..f81c719a 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -250,7 +250,7 @@ int pa__init(pa_module*m) { jack_status_t status; const char *server_name, *client_name; uint32_t channels = 0; - int do_connect = 1; + pa_bool_t do_connect = TRUE; unsigned i; const char **ports = NULL, **p; char *t; -- cgit From 86b9ef8c961bed9d3a65f044741bb423c26d8005 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Feb 2008 22:13:44 +0000 Subject: deal with a possibly failing pa_channel_map_init_auto() correctly git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2105 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-jack-source.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/modules/module-jack-source.c') diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index f81c719a..4ee08bf1 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -304,6 +304,7 @@ int pa__init(pa_module*m) { goto fail; } + pa_assert_se(pa_channel_map_init_auto(&map, channels, PA_CHANNEL_MAP_AUX)); pa_channel_map_init_auto(&map, channels, PA_CHANNEL_MAP_ALSA); if (pa_modargs_get_channel_map(ma, NULL, &map) < 0 || map.channels != channels) { pa_log("failed to parse channel_map= argument."); -- cgit