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/modules/module-null-sink.c | 150 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/modules/module-null-sink.c (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c new file mode 100644 index 00000000..5731a403 --- /dev/null +++ b/src/modules/module-null-sink.c @@ -0,0 +1,150 @@ +/* $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 "module-null-sink-symdef.h" + +PA_MODULE_AUTHOR("Lennart Poettering") +PA_MODULE_DESCRIPTION("Clocked NULL sink") +PA_MODULE_VERSION(PACKAGE_VERSION) +PA_MODULE_USAGE("format= channels= rate= sink_name=") + +#define DEFAULT_SINK_NAME "null" + +struct userdata { + pa_core *core; + pa_module *module; + pa_sink *sink; + pa_time_event *time_event; + size_t block_size; +}; + +static const char* const valid_modargs[] = { + "rate", + "format", + "channels", + "sink_name", + NULL +}; + +static void time_callback(pa_mainloop_api *m, pa_time_event*e, const struct timeval *tv, void *userdata) { + struct userdata *u = userdata; + pa_memchunk chunk; + struct timeval ntv = *tv; + size_t l; + + assert(u); + + if (pa_sink_render(u->sink, u->block_size, &chunk) >= 0) { + l = chunk.length; + pa_memblock_unref(chunk.memblock); + } else + l = u->block_size; + + pa_timeval_add(&ntv, pa_bytes_to_usec(l, &u->sink->sample_spec)); + m->time_restart(e, &ntv); +} + +int pa__init(pa_core *c, pa_module*m) { + struct userdata *u = NULL; + pa_sample_spec ss; + pa_modargs *ma = NULL; + struct timeval tv; + assert(c && m); + + if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { + pa_log(__FILE__": failed to parse module arguments.\n"); + goto fail; + } + + ss = c->default_sample_spec; + if (pa_modargs_get_sample_spec(ma, &ss) < 0) { + pa_log(__FILE__": invalid sample format specification.\n"); + goto fail; + } + + u = pa_xmalloc0(sizeof(struct userdata)); + u->core = c; + u->module = m; + m->userdata = u; + + if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, NULL))) { + pa_log(__FILE__": failed to create sink.\n"); + goto fail; + } + + u->sink->userdata = u; + pa_sink_set_owner(u->sink, m); + u->sink->description = pa_sprintf_malloc("NULL sink"); + + pa_gettimeofday(&tv); + u->time_event = c->mainloop->time_new(c->mainloop, &tv, time_callback, u); + + u->block_size = pa_bytes_per_second(&ss) / 10; + + pa_modargs_free(ma); + + return 0; + +fail: + if (ma) + pa_modargs_free(ma); + + 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; + + pa_sink_disconnect(u->sink); + pa_sink_unref(u->sink); + + u->core->mainloop->time_free(u->time_event); + + pa_xfree(u); +} -- cgit From 4a64b0d1167e980d81b798d813f35209895f0674 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 23 Feb 2006 02:27:19 +0000 Subject: change pa_log() and friends to not require a trailing \n on all logged strings git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@574 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-null-sink.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 5731a403..61178239 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -92,13 +92,13 @@ int pa__init(pa_core *c, pa_module*m) { assert(c && m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { - pa_log(__FILE__": failed to parse module arguments.\n"); + pa_log(__FILE__": failed to parse module arguments."); goto fail; } ss = c->default_sample_spec; if (pa_modargs_get_sample_spec(ma, &ss) < 0) { - pa_log(__FILE__": invalid sample format specification.\n"); + pa_log(__FILE__": invalid sample format specification."); goto fail; } @@ -108,7 +108,7 @@ int pa__init(pa_core *c, pa_module*m) { m->userdata = u; if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, NULL))) { - pa_log(__FILE__": failed to create sink.\n"); + pa_log(__FILE__": failed to create sink."); goto fail; } -- 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-null-sink.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 61178239..9c564429 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -46,7 +46,12 @@ PA_MODULE_AUTHOR("Lennart Poettering") PA_MODULE_DESCRIPTION("Clocked NULL sink") PA_MODULE_VERSION(PACKAGE_VERSION) -PA_MODULE_USAGE("format= channels= rate= sink_name=") +PA_MODULE_USAGE( + "format= " + "channels= " + "rate= " + "sink_name=" + "channel_map=") #define DEFAULT_SINK_NAME "null" @@ -63,6 +68,7 @@ static const char* const valid_modargs[] = { "format", "channels", "sink_name", + "channel_map", NULL }; @@ -87,6 +93,7 @@ static void time_callback(pa_mainloop_api *m, pa_time_event*e, const struct time int pa__init(pa_core *c, pa_module*m) { struct userdata *u = NULL; pa_sample_spec ss; + pa_channel_map map; pa_modargs *ma = NULL; struct timeval tv; assert(c && m); @@ -97,8 +104,8 @@ int pa__init(pa_core *c, pa_module*m) { } ss = c->default_sample_spec; - if (pa_modargs_get_sample_spec(ma, &ss) < 0) { - pa_log(__FILE__": invalid sample format specification."); + if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map) < 0) { + pa_log(__FILE__": invalid sample format specification or channel map."); goto fail; } @@ -107,7 +114,7 @@ int pa__init(pa_core *c, pa_module*m) { u->module = m; m->userdata = u; - if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, NULL))) { + if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) { pa_log(__FILE__": failed to create sink."); 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-null-sink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 9c564429..5cdfeab8 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -104,7 +104,7 @@ int pa__init(pa_core *c, pa_module*m) { } ss = c->default_sample_spec; - if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map) < 0) { + if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) { pa_log(__FILE__": invalid sample format specification or channel map."); 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-null-sink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 5cdfeab8..2cc49063 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -33,12 +33,13 @@ #include #include +#include + #include #include #include #include #include -#include #include #include "module-null-sink-symdef.h" -- 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-null-sink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 2cc49063..78850011 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include -- cgit From 0796ead0db250f6a46a7531c9db471592ed6e129 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 18 May 2006 06:45:43 +0000 Subject: Move timeval calculation functions into their own file. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@926 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-null-sink.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 78850011..a1555e67 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -33,6 +33,7 @@ #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-null-sink.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index a1555e67..8cfce8fe 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.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. ***/ @@ -33,15 +33,15 @@ #include #include -#include -#include +#include +#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "module-null-sink-symdef.h" -- cgit From 55a8db8efe50a85abe690224c13c8501dd56be47 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 14 Jul 2006 23:59:42 +0000 Subject: improve latency calculation of NULL sink git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1088 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-null-sink.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 8cfce8fe..470be6bc 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -63,6 +63,9 @@ struct userdata { pa_sink *sink; pa_time_event *time_event; size_t block_size; + + uint64_t n_bytes; + struct timeval start_time; }; static const char* const valid_modargs[] = { @@ -90,6 +93,19 @@ static void time_callback(pa_mainloop_api *m, pa_time_event*e, const struct time pa_timeval_add(&ntv, pa_bytes_to_usec(l, &u->sink->sample_spec)); m->time_restart(e, &ntv); + + u->n_bytes += l; +} + +static pa_usec_t get_latency(pa_sink *s) { + struct userdata *u = s->userdata; + pa_usec_t a, b; + struct timeval now; + + a = pa_timeval_diff(pa_gettimeofday(&now), &u->start_time); + b = pa_bytes_to_usec(u->n_bytes, &s->sample_spec); + + return b > a ? b - a : 0; } int pa__init(pa_core *c, pa_module*m) { @@ -97,8 +113,9 @@ int pa__init(pa_core *c, pa_module*m) { pa_sample_spec ss; pa_channel_map map; pa_modargs *ma = NULL; - struct timeval tv; - assert(c && m); + + assert(c); + assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log(__FILE__": failed to parse module arguments."); @@ -111,7 +128,7 @@ int pa__init(pa_core *c, pa_module*m) { goto fail; } - u = pa_xmalloc0(sizeof(struct userdata)); + u = pa_xnew0(struct userdata, 1); u->core = c; u->module = m; m->userdata = u; @@ -120,13 +137,16 @@ int pa__init(pa_core *c, pa_module*m) { pa_log(__FILE__": failed to create sink."); goto fail; } - + + u->sink->get_latency = get_latency; u->sink->userdata = u; pa_sink_set_owner(u->sink, m); - u->sink->description = pa_sprintf_malloc("NULL sink"); + u->sink->description = pa_xstrdup("NULL sink"); - pa_gettimeofday(&tv); - u->time_event = c->mainloop->time_new(c->mainloop, &tv, time_callback, u); + u->n_bytes = 0; + pa_gettimeofday(&u->start_time); + + u->time_event = c->mainloop->time_new(c->mainloop, &u->start_time, time_callback, u); u->block_size = pa_bytes_per_second(&ss) / 10; -- 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-null-sink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 470be6bc..73cacc72 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -141,7 +141,7 @@ int pa__init(pa_core *c, pa_module*m) { u->sink->get_latency = get_latency; u->sink->userdata = u; pa_sink_set_owner(u->sink, m); - u->sink->description = pa_xstrdup("NULL sink"); + pa_sink_set_description(u->sink, "NULL sink"); u->n_bytes = 0; pa_gettimeofday(&u->start_time); -- cgit From 8da9b94af667b066b6ab2bb86553bedae330e27b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 12 Aug 2006 00:25:52 +0000 Subject: allow setting the null sink description by a module parameter git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1206 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-null-sink.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 73cacc72..4d5ebb08 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -53,7 +53,8 @@ PA_MODULE_USAGE( "channels= " "rate= " "sink_name=" - "channel_map=") + "channel_map=" + "description=") #define DEFAULT_SINK_NAME "null" @@ -73,7 +74,8 @@ static const char* const valid_modargs[] = { "format", "channels", "sink_name", - "channel_map", + "channel_map", + "description", NULL }; @@ -141,7 +143,7 @@ int pa__init(pa_core *c, pa_module*m) { u->sink->get_latency = get_latency; u->sink->userdata = u; pa_sink_set_owner(u->sink, m); - pa_sink_set_description(u->sink, "NULL sink"); + pa_sink_set_description(u->sink, pa_modargs_get_value(ma, "description", "NULL sink")); u->n_bytes = 0; pa_gettimeofday(&u->start_time); -- 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-null-sink.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 4d5ebb08..50e58853 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -120,13 +120,13 @@ int pa__init(pa_core *c, pa_module*m) { assert(m); 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; } ss = c->default_sample_spec; if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) { - pa_log(__FILE__": invalid sample format specification or channel map."); + pa_log("invalid sample format specification or channel map."); goto fail; } @@ -136,7 +136,7 @@ int pa__init(pa_core *c, pa_module*m) { m->userdata = u; if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) { - pa_log(__FILE__": failed to create sink."); + pa_log("failed to create sink."); goto fail; } -- 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-null-sink.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 50e58853..fc9107a3 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.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 @@ -115,10 +115,10 @@ int pa__init(pa_core *c, pa_module*m) { pa_sample_spec ss; pa_channel_map map; pa_modargs *ma = NULL; - + assert(c); assert(m); - + if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("failed to parse module arguments."); goto fail; @@ -129,12 +129,12 @@ int pa__init(pa_core *c, pa_module*m) { pa_log("invalid sample format specification or channel map."); goto fail; } - + u = pa_xnew0(struct userdata, 1); u->core = c; u->module = m; m->userdata = u; - + if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) { pa_log("failed to create sink."); goto fail; @@ -147,19 +147,19 @@ int pa__init(pa_core *c, pa_module*m) { u->n_bytes = 0; pa_gettimeofday(&u->start_time); - + u->time_event = c->mainloop->time_new(c->mainloop, &u->start_time, time_callback, u); u->block_size = pa_bytes_per_second(&ss) / 10; - + pa_modargs_free(ma); - + return 0; fail: if (ma) pa_modargs_free(ma); - + pa__done(c, m); return -1; @@ -171,7 +171,7 @@ void pa__done(pa_core *c, pa_module*m) { if (!(u = m->userdata)) return; - + pa_sink_disconnect(u->sink); pa_sink_unref(u->sink); -- 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-null-sink.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index fc9107a3..54a8e890 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -3,6 +3,8 @@ /*** This file is part of PulseAudio. + Copyright 2004-2006 Lennart Poettering + PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, -- 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-null-sink.c | 167 +++++++++++++++++++++++++++++------------ 1 file changed, 120 insertions(+), 47 deletions(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 54a8e890..3a4edec7 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -38,12 +37,17 @@ #include #include -#include +#include #include #include #include +#include #include #include +#include +#include +#include +#include #include "module-null-sink-symdef.h" @@ -64,11 +68,14 @@ struct userdata { pa_core *core; pa_module *module; pa_sink *sink; - pa_time_event *time_event; + + pa_thread *thread; + pa_thread_mq thread_mq; + pa_rtpoll *rtpoll; + size_t block_size; - uint64_t n_bytes; - struct timeval start_time; + struct timeval timestamp; }; static const char* const valid_modargs[] = { @@ -81,78 +88,132 @@ static const char* const valid_modargs[] = { NULL }; -static void time_callback(pa_mainloop_api *m, pa_time_event*e, const struct timeval *tv, void *userdata) { - struct userdata *u = userdata; - pa_memchunk chunk; - struct timeval ntv = *tv; - size_t l; +static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) { + struct userdata *u = PA_SINK(o)->userdata; + + switch (code) { + case PA_SINK_MESSAGE_SET_STATE: - assert(u); + if (PA_PTR_TO_UINT(data) == PA_SINK_RUNNING) + pa_rtclock_get(&u->timestamp); - if (pa_sink_render(u->sink, u->block_size, &chunk) >= 0) { - l = chunk.length; - pa_memblock_unref(chunk.memblock); - } else - l = u->block_size; + break; - pa_timeval_add(&ntv, pa_bytes_to_usec(l, &u->sink->sample_spec)); - m->time_restart(e, &ntv); + case PA_SINK_MESSAGE_GET_LATENCY: { + struct timeval now; - u->n_bytes += l; + pa_rtclock_get(&now); + + if (pa_timeval_cmp(&u->timestamp, &now) > 0) + *((pa_usec_t*) data) = 0; + else + *((pa_usec_t*) data) = pa_timeval_diff(&u->timestamp, &now); + break; + } + } + + return pa_sink_process_msg(o, code, data, offset, chunk); } -static pa_usec_t get_latency(pa_sink *s) { - struct userdata *u = s->userdata; - pa_usec_t a, b; - struct timeval now; +static void thread_func(void *userdata) { + struct userdata *u = userdata; + + pa_assert(u); + + pa_log_debug("Thread starting up"); + + pa_thread_mq_install(&u->thread_mq); + pa_rtpoll_install(u->rtpoll); + + pa_rtclock_get(&u->timestamp); + + for (;;) { + int ret; + + /* Render some data and drop it immediately */ + if (u->sink->thread_info.state == PA_SINK_RUNNING) { + struct timeval now; + + pa_rtclock_get(&now); - a = pa_timeval_diff(pa_gettimeofday(&now), &u->start_time); - b = pa_bytes_to_usec(u->n_bytes, &s->sample_spec); + if (pa_timeval_cmp(&u->timestamp, &now) <= 0) { + pa_sink_skip(u->sink, u->block_size); + pa_timeval_add(&u->timestamp, pa_bytes_to_usec(u->block_size, &u->sink->sample_spec)); + } - return b > a ? b - a : 0; + pa_rtpoll_set_timer_absolute(u->rtpoll, &u->timestamp); + } else + pa_rtpoll_set_timer_disabled(u->rtpoll); + + /* Hmm, nothing to do. Let's sleep */ + if ((ret = pa_rtpoll_run(u->rtpoll, 1)) < 0) + goto fail; + + if (ret == 0) + goto finish; + } + +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"); } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) { struct userdata *u = NULL; pa_sample_spec ss; pa_channel_map map; pa_modargs *ma = NULL; - assert(c); - assert(m); + pa_assert(m); 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; } - ss = c->default_sample_spec; + ss = m->core->default_sample_spec; if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) { - pa_log("invalid sample format specification or channel map."); + pa_log("Invalid sample format specification or channel map"); goto fail; } u = pa_xnew0(struct userdata, 1); - u->core = c; + u->core = m->core; u->module = m; m->userdata = u; + 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); - if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) { - pa_log("failed to create sink."); + if (!(u->sink = pa_sink_new(m->core, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) { + pa_log("Failed to create sink."); goto fail; } - u->sink->get_latency = get_latency; + u->sink->parent.process_msg = sink_process_msg; u->sink->userdata = u; - pa_sink_set_owner(u->sink, m); + u->sink->flags = PA_SINK_LATENCY; + + pa_sink_set_module(u->sink, m); + pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq); + pa_sink_set_rtpoll(u->sink, u->rtpoll); pa_sink_set_description(u->sink, pa_modargs_get_value(ma, "description", "NULL sink")); - u->n_bytes = 0; - pa_gettimeofday(&u->start_time); + u->block_size = pa_bytes_per_second(&ss) / 20; /* 50 ms */ + if (u->block_size <= 0) + u->block_size = pa_frame_size(&ss); - u->time_event = c->mainloop->time_new(c->mainloop, &u->start_time, time_callback, u); + if (!(u->thread = pa_thread_new(thread_func, u))) { + pa_log("Failed to create thread."); + goto fail; + } - u->block_size = pa_bytes_per_second(&ss) / 10; + pa_sink_put(u->sink); pa_modargs_free(ma); @@ -162,22 +223,34 @@ fail: if (ma) pa_modargs_free(ma); - 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; - pa_sink_disconnect(u->sink); - pa_sink_unref(u->sink); + if (u->sink) + pa_sink_unlink(u->sink); + + if (u->thread) { + pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL); + pa_thread_free(u->thread); + } + + pa_thread_mq_done(&u->thread_mq); + + if (u->sink) + pa_sink_unref(u->sink); - u->core->mainloop->time_free(u->time_event); + if (u->rtpoll) + pa_rtpoll_free(u->rtpoll); pa_xfree(u); } -- 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-null-sink.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/modules/module-null-sink.c') diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 3a4edec7..de35fff9 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -51,16 +51,17 @@ #include "module-null-sink-symdef.h" -PA_MODULE_AUTHOR("Lennart Poettering") -PA_MODULE_DESCRIPTION("Clocked NULL sink") -PA_MODULE_VERSION(PACKAGE_VERSION) +PA_MODULE_AUTHOR("Lennart Poettering"); +PA_MODULE_DESCRIPTION("Clocked NULL sink"); +PA_MODULE_VERSION(PACKAGE_VERSION); +PA_MODULE_LOAD_ONCE(FALSE); PA_MODULE_USAGE( "format= " "channels= " "rate= " "sink_name=" "channel_map=" - "description=") + "description="); #define DEFAULT_SINK_NAME "null" -- cgit