diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/alsa/alsa-sink.c | 5 | ||||
-rw-r--r-- | src/modules/alsa/alsa-source.c | 5 | ||||
-rw-r--r-- | src/modules/alsa/alsa-util.c | 15 | ||||
-rw-r--r-- | src/modules/alsa/alsa-util.h | 2 | ||||
-rw-r--r-- | src/modules/bluetooth/bluetooth-util.c | 2 | ||||
-rw-r--r-- | src/modules/bluetooth/module-bluetooth-device.c | 3 | ||||
-rw-r--r-- | src/modules/bluetooth/module-bluetooth-discover.c | 2 | ||||
-rw-r--r-- | src/modules/bluetooth/module-bluetooth-proximity.c | 2 | ||||
-rw-r--r-- | src/modules/dbus-util.c | 437 | ||||
-rw-r--r-- | src/modules/dbus-util.h | 68 | ||||
-rw-r--r-- | src/modules/hal-util.c | 2 | ||||
-rw-r--r-- | src/modules/module-console-kit.c | 2 | ||||
-rw-r--r-- | src/modules/module-hal-detect.c | 2 | ||||
-rw-r--r-- | src/modules/module-raop-sink.c | 11 | ||||
-rw-r--r-- | src/modules/module-tunnel.c | 187 | ||||
-rw-r--r-- | src/modules/reserve-wrap.c | 3 |
16 files changed, 173 insertions, 575 deletions
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c index 7c09553e..0296f64e 100644 --- a/src/modules/alsa/alsa-sink.c +++ b/src/modules/alsa/alsa-sink.c @@ -1630,6 +1630,11 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca u->use_tsched = use_tsched = FALSE; } + if (use_tsched && !pa_alsa_pcm_is_hw(u->pcm_handle)) { + pa_log_info("Device is not a hardware device, disabling timer-based scheduling."); + u->use_tsched = use_tsched = FALSE; + } + if (u->use_mmap) pa_log_info("Successfully enabled mmap() mode."); diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c index dfd18702..ef365a21 100644 --- a/src/modules/alsa/alsa-source.c +++ b/src/modules/alsa/alsa-source.c @@ -1482,6 +1482,11 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p u->use_tsched = use_tsched = FALSE; } + if (use_tsched && !pa_alsa_pcm_is_hw(u->pcm_handle)) { + pa_log_info("Device is not a hardware device, disabling timer-based scheduling."); + u->use_tsched = use_tsched = FALSE; + } + if (u->use_mmap) pa_log_info("Successfully enabled mmap() mode."); diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c index 3f26aebe..2d0ca107 100644 --- a/src/modules/alsa/alsa-util.c +++ b/src/modules/alsa/alsa-util.c @@ -1716,10 +1716,11 @@ char *pa_alsa_get_driver_name(int card) { char *pa_alsa_get_driver_name_by_pcm(snd_pcm_t *pcm) { int card; - snd_pcm_info_t* info; snd_pcm_info_alloca(&info); + pa_assert(pcm); + if (snd_pcm_info(pcm, info) < 0) return NULL; @@ -1749,3 +1750,15 @@ char *pa_alsa_get_reserve_name(const char *device) { return pa_sprintf_malloc("Audio%i", i); } + +pa_bool_t pa_alsa_pcm_is_hw(snd_pcm_t *pcm) { + snd_pcm_info_t* info; + snd_pcm_info_alloca(&info); + + pa_assert(pcm); + + if (snd_pcm_info(pcm, info) < 0) + return FALSE; + + return snd_pcm_info_get_card(info) >= 0; +} diff --git a/src/modules/alsa/alsa-util.h b/src/modules/alsa/alsa-util.h index fe0f71e0..68496d51 100644 --- a/src/modules/alsa/alsa-util.h +++ b/src/modules/alsa/alsa-util.h @@ -139,4 +139,6 @@ char *pa_alsa_get_driver_name_by_pcm(snd_pcm_t *pcm); char *pa_alsa_get_reserve_name(const char *device); +pa_bool_t pa_alsa_pcm_is_hw(snd_pcm_t *pcm); + #endif diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index 771afff5..94c1d315 100644 --- a/src/modules/bluetooth/bluetooth-util.c +++ b/src/modules/bluetooth/bluetooth-util.c @@ -25,7 +25,7 @@ #include <pulsecore/core-util.h> #include <pulsecore/shared.h> -#include <modules/dbus-util.h> +#include <pulsecore/dbus-shared.h> #include "bluetooth-util.h" diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index 9fc1531e..f9800ac0 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -46,8 +46,7 @@ #include <pulsecore/time-smoother.h> #include <pulsecore/rtclock.h> #include <pulsecore/namereg.h> - -#include <modules/dbus-util.h> +#include <pulsecore/dbus-shared.h> #include "module-bluetooth-device-symdef.h" #include "ipc.h" diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c index 6f3dba12..788fee00 100644 --- a/src/modules/bluetooth/module-bluetooth-discover.c +++ b/src/modules/bluetooth/module-bluetooth-discover.c @@ -34,7 +34,7 @@ #include <pulsecore/macro.h> #include <pulsecore/llist.h> #include <pulsecore/core-util.h> -#include <modules/dbus-util.h> +#include <pulsecore/dbus-shared.h> #include "module-bluetooth-discover-symdef.h" #include "bluetooth-util.h" diff --git a/src/modules/bluetooth/module-bluetooth-proximity.c b/src/modules/bluetooth/module-bluetooth-proximity.c index c8d7b4d9..9993c8dc 100644 --- a/src/modules/bluetooth/module-bluetooth-proximity.c +++ b/src/modules/bluetooth/module-bluetooth-proximity.c @@ -42,8 +42,8 @@ #include <pulsecore/core-util.h> #include <pulsecore/core-error.h> #include <pulsecore/start-child.h> +#include <pulsecore/dbus-shared.h> -#include "../dbus-util.h" #include "module-bluetooth-proximity-symdef.h" PA_MODULE_AUTHOR("Lennart Poettering"); diff --git a/src/modules/dbus-util.c b/src/modules/dbus-util.c deleted file mode 100644 index e2d45803..00000000 --- a/src/modules/dbus-util.c +++ /dev/null @@ -1,437 +0,0 @@ -/*** - This file is part of PulseAudio. - - Copyright 2006 Lennart Poettering - Copyright 2006 Shams E. King - - PulseAudio is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published - by the Free Software Foundation; either version 2.1 of the License, - or (at your option) any later version. - - PulseAudio is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with PulseAudio; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - USA. -***/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdarg.h> - -#include <pulse/xmalloc.h> -#include <pulse/timeval.h> -#include <pulsecore/log.h> -#include <pulsecore/shared.h> - -#include "dbus-util.h" - -struct pa_dbus_connection { - PA_REFCNT_DECLARE; - - pa_core *core; - DBusConnection *connection; - const char *property_name; - pa_defer_event* dispatch_event; -}; - -static void dispatch_cb(pa_mainloop_api *ea, pa_defer_event *ev, void *userdata) { - DBusConnection *conn = userdata; - - if (dbus_connection_dispatch(conn) == DBUS_DISPATCH_COMPLETE) { - /* no more data to process, disable the deferred */ - ea->defer_enable(ev, 0); - } -} - -/* DBusDispatchStatusFunction callback for the pa mainloop */ -static void dispatch_status(DBusConnection *conn, DBusDispatchStatus status, void *userdata) { - pa_dbus_connection *c = userdata; - - pa_assert(c); - - switch(status) { - - case DBUS_DISPATCH_COMPLETE: - c->core->mainloop->defer_enable(c->dispatch_event, 0); - break; - - case DBUS_DISPATCH_DATA_REMAINS: - case DBUS_DISPATCH_NEED_MEMORY: - default: - c->core->mainloop->defer_enable(c->dispatch_event, 1); - break; - } -} - -static pa_io_event_flags_t get_watch_flags(DBusWatch *watch) { - unsigned int flags; - pa_io_event_flags_t events = 0; - - pa_assert(watch); - - flags = dbus_watch_get_flags(watch); - - /* no watch flags for disabled watches */ - if (!dbus_watch_get_enabled(watch)) - return PA_IO_EVENT_NULL; - - if (flags & DBUS_WATCH_READABLE) - events |= PA_IO_EVENT_INPUT; - if (flags & DBUS_WATCH_WRITABLE) - events |= PA_IO_EVENT_OUTPUT; - - return events | PA_IO_EVENT_HANGUP | PA_IO_EVENT_ERROR; -} - -/* pa_io_event_cb_t IO event handler */ -static void handle_io_event(pa_mainloop_api *ea, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) { - unsigned int flags = 0; - DBusWatch *watch = userdata; - -#if HAVE_DBUS_WATCH_GET_UNIX_FD - pa_assert(fd == dbus_watch_get_unix_fd(watch)); -#else - pa_assert(fd == dbus_watch_get_fd(watch)); -#endif - - if (!dbus_watch_get_enabled(watch)) { - pa_log_warn("Asked to handle disabled watch: %p %i", (void*) watch, fd); - return; - } - - if (events & PA_IO_EVENT_INPUT) - flags |= DBUS_WATCH_READABLE; - if (events & PA_IO_EVENT_OUTPUT) - flags |= DBUS_WATCH_WRITABLE; - if (events & PA_IO_EVENT_HANGUP) - flags |= DBUS_WATCH_HANGUP; - if (events & PA_IO_EVENT_ERROR) - flags |= DBUS_WATCH_ERROR; - - dbus_watch_handle(watch, flags); -} - -/* pa_time_event_cb_t timer event handler */ -static void handle_time_event(pa_mainloop_api *ea, pa_time_event* e, const struct timeval *tv, void *userdata) { - DBusTimeout *timeout = userdata; - - if (dbus_timeout_get_enabled(timeout)) { - struct timeval next = *tv; - dbus_timeout_handle(timeout); - - /* restart it for the next scheduled time */ - pa_timeval_add(&next, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000); - ea->time_restart(e, &next); - } -} - -/* DBusAddWatchFunction callback for pa mainloop */ -static dbus_bool_t add_watch(DBusWatch *watch, void *data) { - pa_core *c = PA_CORE(data); - pa_io_event *ev; - - pa_assert(watch); - pa_assert(c); - - ev = c->mainloop->io_new( - c->mainloop, -#if HAVE_DBUS_WATCH_GET_UNIX_FD - dbus_watch_get_unix_fd(watch), -#else - dbus_watch_get_fd(watch), -#endif - get_watch_flags(watch), handle_io_event, watch); - - dbus_watch_set_data(watch, ev, NULL); - - return TRUE; -} - -/* DBusRemoveWatchFunction callback for pa mainloop */ -static void remove_watch(DBusWatch *watch, void *data) { - pa_core *c = PA_CORE(data); - pa_io_event *ev; - - pa_assert(watch); - pa_assert(c); - - if ((ev = dbus_watch_get_data(watch))) - c->mainloop->io_free(ev); -} - -/* DBusWatchToggledFunction callback for pa mainloop */ -static void toggle_watch(DBusWatch *watch, void *data) { - pa_core *c = PA_CORE(data); - pa_io_event *ev; - - pa_assert(watch); - pa_core_assert_ref(c); - - pa_assert_se(ev = dbus_watch_get_data(watch)); - - /* get_watch_flags() checks if the watch is enabled */ - c->mainloop->io_enable(ev, get_watch_flags(watch)); -} - -/* DBusAddTimeoutFunction callback for pa mainloop */ -static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) { - pa_core *c = PA_CORE(data); - pa_time_event *ev; - struct timeval tv; - - pa_assert(timeout); - pa_assert(c); - - if (!dbus_timeout_get_enabled(timeout)) - return FALSE; - - pa_gettimeofday(&tv); - pa_timeval_add(&tv, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000); - - ev = c->mainloop->time_new(c->mainloop, &tv, handle_time_event, timeout); - - dbus_timeout_set_data(timeout, ev, NULL); - - return TRUE; -} - -/* DBusRemoveTimeoutFunction callback for pa mainloop */ -static void remove_timeout(DBusTimeout *timeout, void *data) { - pa_core *c = PA_CORE(data); - pa_time_event *ev; - - pa_assert(timeout); - pa_assert(c); - - if ((ev = dbus_timeout_get_data(timeout))) - c->mainloop->time_free(ev); -} - -/* DBusTimeoutToggledFunction callback for pa mainloop */ -static void toggle_timeout(DBusTimeout *timeout, void *data) { - pa_core *c = PA_CORE(data); - pa_time_event *ev; - - pa_assert(timeout); - pa_assert(c); - - pa_assert_se(ev = dbus_timeout_get_data(timeout)); - - if (dbus_timeout_get_enabled(timeout)) { - struct timeval tv; - - pa_gettimeofday(&tv); - pa_timeval_add(&tv, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000); - - c->mainloop->time_restart(ev, &tv); - } else - c->mainloop->time_restart(ev, NULL); -} - -static void wakeup_main(void *userdata) { - pa_dbus_connection *c = userdata; - - pa_assert(c); - - /* this will wakeup the mainloop and dispatch events, although - * it may not be the cleanest way of accomplishing it */ - c->core->mainloop->defer_enable(c->dispatch_event, 1); -} - -static pa_dbus_connection* pa_dbus_connection_new(pa_core* c, DBusConnection *conn, const char* name) { - pa_dbus_connection *pconn; - - pconn = pa_xnew(pa_dbus_connection, 1); - PA_REFCNT_INIT(pconn); - pconn->core = c; - pconn->property_name = name; - pconn->connection = conn; - pconn->dispatch_event = c->mainloop->defer_new(c->mainloop, dispatch_cb, conn); - - pa_shared_set(c, name, pconn); - - return pconn; -} - -DBusConnection* pa_dbus_connection_get(pa_dbus_connection *c){ - pa_assert(c); - pa_assert(PA_REFCNT_VALUE(c) > 0); - pa_assert(c->connection); - - return c->connection; -} - -void pa_dbus_connection_unref(pa_dbus_connection *c) { - pa_assert(c); - pa_assert(PA_REFCNT_VALUE(c) > 0); - - if (PA_REFCNT_DEC(c) > 0) - return; - - if (dbus_connection_get_is_connected(c->connection)) { - dbus_connection_close(c->connection); - /* must process remaining messages, bit of a kludge to handle - * both unload and shutdown */ - while (dbus_connection_read_write_dispatch(c->connection, -1)); - } - - /* already disconnected, just free */ - pa_shared_remove(c->core, c->property_name); - c->core->mainloop->defer_free(c->dispatch_event); - dbus_connection_unref(c->connection); - pa_xfree(c); -} - -pa_dbus_connection* pa_dbus_connection_ref(pa_dbus_connection *c) { - pa_assert(c); - pa_assert(PA_REFCNT_VALUE(c) > 0); - - PA_REFCNT_INC(c); - - return c; -} - -pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *error) { - - static const char *const prop_name[] = { - [DBUS_BUS_SESSION] = "dbus-connection-session", - [DBUS_BUS_SYSTEM] = "dbus-connection-system", - [DBUS_BUS_STARTER] = "dbus-connection-starter" - }; - DBusConnection *conn; - pa_dbus_connection *pconn; - - pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER); - - if ((pconn = pa_shared_get(c, prop_name[type]))) - return pa_dbus_connection_ref(pconn); - - if (!(conn = dbus_bus_get_private(type, error))) - return NULL; - - pconn = pa_dbus_connection_new(c, conn, prop_name[type]); - - dbus_connection_set_exit_on_disconnect(conn, FALSE); - dbus_connection_set_dispatch_status_function(conn, dispatch_status, pconn, NULL); - dbus_connection_set_watch_functions(conn, add_watch, remove_watch, toggle_watch, c, NULL); - dbus_connection_set_timeout_functions(conn, add_timeout, remove_timeout, toggle_timeout, c, NULL); - dbus_connection_set_wakeup_main_function(conn, wakeup_main, pconn, NULL); - - return pconn; -} - -int pa_dbus_add_matches(DBusConnection *c, DBusError *error, ...) { - const char *t; - va_list ap; - unsigned k = 0; - - pa_assert(c); - pa_assert(error); - - va_start(ap, error); - while ((t = va_arg(ap, const char*))) { - dbus_bus_add_match(c, t, error); - - if (dbus_error_is_set(error)) - goto fail; - - k++; - } - va_end(ap); - return 0; - -fail: - - va_end(ap); - va_start(ap, error); - for (; k > 0; k--) { - DBusError e; - - pa_assert_se(t = va_arg(ap, const char*)); - - dbus_error_init(&e); - dbus_bus_remove_match(c, t, &e); - dbus_error_free(&e); - } - va_end(ap); - - return -1; -} - -void pa_dbus_remove_matches(DBusConnection *c, ...) { - const char *t; - va_list ap; - DBusError error; - - pa_assert(c); - - dbus_error_init(&error); - - va_start(ap, c); - while ((t = va_arg(ap, const char*))) { - dbus_bus_remove_match(c, t, &error); - dbus_error_free(&error); - } - va_end(ap); -} - -pa_dbus_pending *pa_dbus_pending_new( - DBusConnection *c, - DBusMessage *m, - DBusPendingCall *pending, - void *context_data, - void *call_data) { - - pa_dbus_pending *p; - - pa_assert(pending); - - p = pa_xnew(pa_dbus_pending, 1); - p->connection = c; - p->message = m; - p->pending = pending; - p->context_data = context_data; - p->call_data = call_data; - - PA_LLIST_INIT(pa_dbus_pending, p); - - return p; -} - -void pa_dbus_pending_free(pa_dbus_pending *p) { - pa_assert(p); - - if (p->pending) - dbus_pending_call_cancel(p->pending); /* p->pending is freed by cancel() */ - - if (p->message) - dbus_message_unref(p->message); - - pa_xfree(p); -} - -void pa_dbus_sync_pending_list(pa_dbus_pending **p) { - pa_assert(p); - - while (*p && dbus_connection_read_write_dispatch((*p)->connection, -1)) - ; -} - -void pa_dbus_free_pending_list(pa_dbus_pending **p) { - pa_dbus_pending *i; - - pa_assert(p); - - while ((i = *p)) { - PA_LLIST_REMOVE(pa_dbus_pending, *p, i); - pa_dbus_pending_free(i); - } -} diff --git a/src/modules/dbus-util.h b/src/modules/dbus-util.h deleted file mode 100644 index 554f41a4..00000000 --- a/src/modules/dbus-util.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef foodbusutilhfoo -#define foodbusutilhfoo - -/*** - This file is part of PulseAudio. - - Copyright 2006 Shams E. King - - PulseAudio is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published - by the Free Software Foundation; either version 2.1 of the License, - or (at your option) any later version. - - PulseAudio is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with PulseAudio; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - USA. -***/ - -#include <dbus/dbus.h> - -#include <pulsecore/core.h> -#include <pulsecore/llist.h> - -typedef struct pa_dbus_connection pa_dbus_connection; - -/* return the DBusConnection of the specified type for the given core, - * like dbus_bus_get(), but integrates the connection with the pa_core */ -pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *error); - -DBusConnection* pa_dbus_connection_get(pa_dbus_connection *conn); - -pa_dbus_connection* pa_dbus_connection_ref(pa_dbus_connection *conn); -void pa_dbus_connection_unref(pa_dbus_connection *conn); - -int pa_dbus_add_matches(DBusConnection *c, DBusError *error, ...) PA_GCC_SENTINEL; -void pa_dbus_remove_matches(DBusConnection *c, ...) PA_GCC_SENTINEL; - -typedef struct pa_dbus_pending pa_dbus_pending; - -struct userdata; /* We leave the actual definition to the caller */ - -struct pa_dbus_pending { - DBusConnection *connection; - DBusMessage *message; - DBusPendingCall *pending; - - void *context_data; - void *call_data; - - PA_LLIST_FIELDS(pa_dbus_pending); -}; - -pa_dbus_pending *pa_dbus_pending_new(DBusConnection *c, DBusMessage *m, DBusPendingCall *pending, void *context_data, void *call_data); -void pa_dbus_pending_free(pa_dbus_pending *p); - -/* Sync up a list of pa_dbus_pending_call objects */ -void pa_dbus_sync_pending_list(pa_dbus_pending **p); - -/* Free up a list of pa_dbus_pending_call objects */ -void pa_dbus_free_pending_list(pa_dbus_pending **p); - -#endif diff --git a/src/modules/hal-util.c b/src/modules/hal-util.c index 422ae4ec..e2a2d8d7 100644 --- a/src/modules/hal-util.c +++ b/src/modules/hal-util.c @@ -24,10 +24,10 @@ #endif #include <pulsecore/log.h> +#include <pulsecore/dbus-shared.h> #include <hal/libhal.h> -#include "dbus-util.h" #include "hal-util.h" int pa_hal_get_info(pa_core *core, pa_proplist *p, int card) { diff --git a/src/modules/module-console-kit.c b/src/modules/module-console-kit.c index 3fba7ef6..a666073c 100644 --- a/src/modules/module-console-kit.c +++ b/src/modules/module-console-kit.c @@ -44,8 +44,8 @@ #include <pulsecore/namereg.h> #include <pulsecore/core-scache.h> #include <pulsecore/modargs.h> +#include <pulsecore/dbus-shared.h> -#include "dbus-util.h" #include "module-console-kit-symdef.h" PA_MODULE_AUTHOR("Lennart Poettering"); diff --git a/src/modules/module-hal-detect.c b/src/modules/module-hal-detect.c index 9b0d71c9..0dd22cbd 100644 --- a/src/modules/module-hal-detect.c +++ b/src/modules/module-hal-detect.c @@ -45,10 +45,10 @@ #include <pulsecore/namereg.h> #include <pulsecore/core-scache.h> #include <pulsecore/modargs.h> +#include <pulsecore/dbus-shared.h> #include <hal/libhal.h> -#include "dbus-util.h" #include "module-hal-detect-symdef.h" PA_MODULE_AUTHOR("Shahms King"); diff --git a/src/modules/module-raop-sink.c b/src/modules/module-raop-sink.c index 00f0c63c..d8ddf184 100644 --- a/src/modules/module-raop-sink.c +++ b/src/modules/module-raop-sink.c @@ -135,13 +135,22 @@ enum { /* Forward declaration */ static void sink_set_volume_cb(pa_sink *); -static void on_connection(PA_GCC_UNUSED int fd, void*userdata) { +static void on_connection(int fd, void*userdata) { + int so_sndbuf = 0; + socklen_t sl = sizeof(int); struct userdata *u = userdata; pa_assert(u); pa_assert(u->fd < 0); u->fd = fd; + if (getsockopt(u->fd, SOL_SOCKET, SO_SNDBUF, &so_sndbuf, &sl) < 0) + pa_log_warn("getsockopt(SO_SNDBUF) failed: %s", pa_cstrerror(errno)); + else { + pa_log_debug("SO_SNDBUF is %zu.", (size_t) so_sndbuf); + pa_sink_set_max_request(u->sink, PA_MAX((size_t) so_sndbuf, u->block_size)); + } + /* Set the initial volume */ sink_set_volume_cb(u->sink); diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c index c1488841..7f303f1f 100644 --- a/src/modules/module-tunnel.c +++ b/src/modules/module-tunnel.c @@ -145,6 +145,7 @@ static void command_stream_killed(pa_pdispatch *pd, uint32_t command, uint32_t t static void command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static void command_suspended(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static void command_moved(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); +static void command_stream_or_client_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = { #ifdef TUNNEL_SINK @@ -159,7 +160,10 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = { [PA_COMMAND_PLAYBACK_STREAM_SUSPENDED] = command_suspended, [PA_COMMAND_RECORD_STREAM_SUSPENDED] = command_suspended, [PA_COMMAND_PLAYBACK_STREAM_MOVED] = command_moved, - [PA_COMMAND_RECORD_STREAM_MOVED] = command_moved + [PA_COMMAND_RECORD_STREAM_MOVED] = command_moved, + [PA_COMMAND_PLAYBACK_STREAM_EVENT] = command_stream_or_client_event, + [PA_COMMAND_RECORD_STREAM_EVENT] = command_stream_or_client_event, + [PA_COMMAND_CLIENT_EVENT] = command_stream_or_client_event }; struct userdata { @@ -196,8 +200,8 @@ struct userdata { pa_bool_t remote_corked:1; pa_bool_t remote_suspended:1; - pa_usec_t transport_usec; - pa_bool_t transport_usec_valid; + pa_usec_t transport_usec; /* maintained in the main thread */ + pa_usec_t thread_transport_usec; /* maintained in the IO thread */ uint32_t ignore_latency_before; @@ -222,6 +226,11 @@ struct userdata { static void request_latency(struct userdata *u); /* Called from main context */ +static void command_stream_or_client_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { + pa_log_debug("Got stream or client event."); +} + +/* Called from main context */ static void command_stream_killed(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { struct userdata *u = userdata; @@ -261,11 +270,14 @@ static void command_suspended(pa_pdispatch *pd, uint32_t command, uint32_t tag if (pa_tagstruct_getu32(t, &channel) < 0 || pa_tagstruct_get_boolean(t, &suspended) < 0 || !pa_tagstruct_eof(t)) { - pa_log("Invalid packet"); + + pa_log("Invalid packet."); pa_module_unload_request(u->module, TRUE); return; } + pa_log_debug("Server reports device suspend."); + #ifdef TUNNEL_SINK pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_REMOTE_SUSPEND, PA_UINT32_TO_PTR(!!suspended), 0, NULL); #else @@ -278,13 +290,33 @@ static void command_suspended(pa_pdispatch *pd, uint32_t command, uint32_t tag /* Called from main context */ static void command_moved(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { struct userdata *u = userdata; + uint32_t channel, di; + const char *dn; + pa_bool_t suspended; pa_assert(pd); pa_assert(t); pa_assert(u); pa_assert(u->pdispatch == pd); + if (pa_tagstruct_getu32(t, &channel) < 0 || + pa_tagstruct_getu32(t, &di) < 0 || + pa_tagstruct_gets(t, &dn) < 0 || + pa_tagstruct_get_boolean(t, &suspended) < 0) { + + pa_log_error("Invalid packet."); + pa_module_unload_request(u->module, TRUE); + return; + } + pa_log_debug("Server reports a stream move."); + +#ifdef TUNNEL_SINK + pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_REMOTE_SUSPEND, PA_UINT32_TO_PTR(!!suspended), 0, NULL); +#else + pa_asyncmsgq_send(u->source->asyncmsgq, PA_MSGOBJECT(u->source), SOURCE_MESSAGE_REMOTE_SUSPEND, PA_UINT32_TO_PTR(!!suspended), 0, NULL); +#endif + request_latency(u); } @@ -306,21 +338,21 @@ static void command_started(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa #endif /* Called from IO thread context */ -static void stream_cork_within_thread(struct userdata *u, pa_bool_t cork) { +static void check_smoother_status(struct userdata *u, pa_bool_t past) { pa_usec_t x; - pa_assert(u); - if (u->remote_corked == cork) - return; + pa_assert(u); - u->remote_corked = cork; x = pa_rtclock_usec(); - /* Correct by the time this needs to travel to the other side. - * This is a valid thread-safe access, because the main thread is - * waiting for us */ - if (u->transport_usec_valid) - x += u->transport_usec; + /* Correct by the time the requested issued needs to travel to the + * other side. This is a valid thread-safe access, because the + * main thread is waiting for us */ + + if (past) + x -= u->thread_transport_usec; + else + x += u->thread_transport_usec; if (u->remote_suspended || u->remote_corked) pa_smoother_pause(u->smoother, x); @@ -328,6 +360,17 @@ static void stream_cork_within_thread(struct userdata *u, pa_bool_t cork) { pa_smoother_resume(u->smoother, x); } +/* Called from IO thread context */ +static void stream_cork_within_thread(struct userdata *u, pa_bool_t cork) { + pa_assert(u); + + if (u->remote_corked == cork) + return; + + u->remote_corked = cork; + check_smoother_status(u, FALSE); +} + /* Called from main context */ static void stream_cork(struct userdata *u, pa_bool_t cork) { pa_tagstruct *t; @@ -352,26 +395,13 @@ static void stream_cork(struct userdata *u, pa_bool_t cork) { /* Called from IO thread context */ static void stream_suspend_within_thread(struct userdata *u, pa_bool_t suspend) { - pa_usec_t x; pa_assert(u); if (u->remote_suspended == suspend) return; u->remote_suspended = suspend; - - x = pa_rtclock_usec(); - - /* Correct by the time this needed to travel from the other side. - * This is a valid thread-safe access, because the main thread is - * waiting for us */ - if (u->transport_usec_valid) - x -= u->transport_usec; - - if (u->remote_suspended || u->remote_corked) - pa_smoother_pause(u->smoother, x); - else - pa_smoother_resume(u->smoother, x); + check_smoother_status(u, TRUE); } #ifdef TUNNEL_SINK @@ -446,13 +476,16 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse y = pa_bytes_to_usec((uint64_t) u->counter, &u->sink->sample_spec); - if (y > (pa_usec_t) offset || offset < 0) + if (y > (pa_usec_t) offset) y -= (pa_usec_t) offset; else y = 0; pa_smoother_put(u->smoother, pa_rtclock_usec(), y); + /* We can access this freely here, since the main thread is waiting for us */ + u->thread_transport_usec = u->transport_usec; + return 0; } @@ -546,14 +579,13 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off pa_usec_t y; y = pa_bytes_to_usec((uint64_t) u->counter, &u->source->sample_spec); - - if (offset >= 0 || y > (pa_usec_t) -offset) - y += (pa_usec_t) offset; - else - y = 0; + y += (pa_usec_t) offset; pa_smoother_put(u->smoother, pa_rtclock_usec(), y); + /* We can access this freely here, since the main thread is waiting for us */ + u->thread_transport_usec = u->transport_usec; + return 0; } } @@ -606,7 +638,7 @@ static void thread_func(void *userdata) { #ifdef TUNNEL_SINK if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) - if (u->sink->thread_info.rewind_requested) + if (PA_UNLIKELY(u->sink->thread_info.rewind_requested)) pa_sink_process_rewind(u->sink, 0); #endif @@ -662,7 +694,7 @@ fail: /* Called from main context */ static void stream_get_latency_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { struct userdata *u = userdata; - pa_usec_t sink_usec, source_usec, transport_usec = 0; + pa_usec_t sink_usec, source_usec; pa_bool_t playing; int64_t write_index, read_index; struct timeval local, remote, now; @@ -709,7 +741,6 @@ static void stream_get_latency_callback(pa_pdispatch *pd, uint32_t command, uint } if (tag < u->ignore_latency_before) { - request_latency(u); return; } @@ -725,7 +756,6 @@ static void stream_get_latency_callback(pa_pdispatch *pd, uint32_t command, uint #endif } else u->transport_usec = pa_timeval_diff(&now, &local)/2; - u->transport_usec_valid = TRUE; /* First, take the device's delay */ #ifdef TUNNEL_SINK @@ -745,9 +775,9 @@ static void stream_get_latency_callback(pa_pdispatch *pd, uint32_t command, uint /* Our measurements are already out of date, hence correct by the * * transport latency */ #ifdef TUNNEL_SINK - delay -= (int64_t) transport_usec; + delay -= (int64_t) u->transport_usec; #else - delay += (int64_t) transport_usec; + delay += (int64_t) u->transport_usec; #endif /* Now correct by what we have have read/written since we requested the update */ @@ -786,8 +816,7 @@ static void request_latency(struct userdata *u) { pa_tagstruct_putu32(t, tag = u->ctag++); pa_tagstruct_putu32(t, u->channel); - pa_gettimeofday(&now); - pa_tagstruct_put_timeval(t, &now); + pa_tagstruct_put_timeval(t, pa_gettimeofday(&now)); pa_pstream_send_tagstruct(u->pstream, t); pa_pdispatch_register_reply(u->pdispatch, tag, DEFAULT_TIMEOUT, stream_get_latency_callback, u, NULL); @@ -861,6 +890,7 @@ static void update_description(struct userdata *u) { static void server_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { struct userdata *u = userdata; pa_sample_spec ss; + pa_channel_map cm; const char *server_name, *server_version, *user_name, *host_name, *default_sink_name, *default_source_name; uint32_t cookie; @@ -882,7 +912,9 @@ static void server_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa pa_tagstruct_get_sample_spec(t, &ss) < 0 || pa_tagstruct_gets(t, &default_sink_name) < 0 || pa_tagstruct_gets(t, &default_source_name) < 0 || - pa_tagstruct_getu32(t, &cookie) < 0) { + pa_tagstruct_getu32(t, &cookie) < 0 || + (u->version >= 15 && + pa_tagstruct_get_channel_map(t, &cm) < 0)) { pa_log("Parse failure"); goto fail; @@ -963,6 +995,20 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_t } } + if (u->version >= 15) { + pa_volume_t base_volume; + uint32_t state, n_volume_steps, card; + + if (pa_tagstruct_get_volume(t, &base_volume) < 0 || + pa_tagstruct_getu32(t, &state) < 0 || + pa_tagstruct_getu32(t, &n_volume_steps) < 0 || + pa_tagstruct_getu32(t, &card) < 0) { + + pa_log("Parse failure"); + goto fail; + } + } + if (!pa_tagstruct_eof(t)) { pa_log("Packet too long"); goto fail; @@ -1059,12 +1105,11 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag pa_cvolume_equal(&volume, &u->sink->virtual_volume)) return; - memcpy(&u->sink->virtual_volume, &volume, sizeof(pa_cvolume)); + pa_sink_volume_changed(u->sink, &volume); if (u->version >= 11) - u->sink->muted = !!mute; + pa_sink_mute_changed(u->sink, mute); - pa_subscription_post(u->sink->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, u->sink->index); return; fail: @@ -1126,6 +1171,20 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa } } + if (u->version >= 15) { + pa_volume_t base_volume; + uint32_t state, n_volume_steps, card; + + if (pa_tagstruct_get_volume(t, &base_volume) < 0 || + pa_tagstruct_getu32(t, &state) < 0 || + pa_tagstruct_getu32(t, &n_volume_steps) < 0 || + pa_tagstruct_getu32(t, &card) < 0) { + + pa_log("Parse failure"); + goto fail; + } + } + if (!pa_tagstruct_eof(t)) { pa_log("Packet too long"); goto fail; @@ -1314,11 +1373,11 @@ static void create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t if (pa_tagstruct_get_usec(t, &usec) < 0) goto parse_error; -#ifdef TUNNEL_SINK - pa_sink_set_latency_range(u->sink, usec + MIN_NETWORK_LATENCY_USEC, 0); -#else - pa_source_set_latency_range(u->source, usec + MIN_NETWORK_LATENCY_USEC, 0); -#endif +/* #ifdef TUNNEL_SINK */ +/* pa_sink_set_latency_range(u->sink, usec + MIN_NETWORK_LATENCY_USEC, 0); */ +/* #else */ +/* pa_source_set_latency_range(u->source, usec + MIN_NETWORK_LATENCY_USEC, 0); */ +/* #endif */ } if (!pa_tagstruct_eof(t)) @@ -1391,11 +1450,17 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t pa_log_debug("Protocol version: remote %u, local %u", u->version, PA_PROTOCOL_VERSION); #ifdef TUNNEL_SINK + pa_proplist_setf(u->sink->proplist, "tunnel.remote_version", "%u", u->version); + pa_sink_update_proplist(u->sink, 0, NULL); + pa_snprintf(name, sizeof(name), "%s for %s@%s", u->sink_name, pa_get_user_name(un, sizeof(un)), pa_get_host_name(hn, sizeof(hn))); #else + pa_proplist_setf(u->source->proplist, "tunnel.remote_version", "%u", u->version); + pa_source_update_proplist(u->source, 0, NULL); + pa_snprintf(name, sizeof(name), "%s for %s@%s", u->source_name, pa_get_user_name(un, sizeof(un)), @@ -1409,9 +1474,9 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t if (u->version >= 13) { pa_proplist *pl; pl = pa_proplist_new(); - pa_init_proplist(pl); pa_proplist_sets(pl, PA_PROP_APPLICATION_ID, "org.PulseAudio.PulseAudio"); pa_proplist_sets(pl, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION); + pa_init_proplist(pl); pa_tagstruct_put_proplist(reply, pl); pa_proplist_free(pl); } else @@ -1503,6 +1568,14 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t pa_tagstruct_put_boolean(reply, TRUE); /* early rquests */ } + if (u->version >= 15) { +#ifdef TUNNEL_SINK + pa_tagstruct_put_boolean(reply, FALSE); /* muted_set */ +#endif + pa_tagstruct_put_boolean(reply, FALSE); /* don't inhibit auto suspend */ + pa_tagstruct_put_boolean(reply, FALSE); /* fail on suspend */ + } + pa_pstream_send_tagstruct(u->pstream, reply); pa_pdispatch_register_reply(u->pdispatch, tag, DEFAULT_TIMEOUT, create_stream_callback, u, NULL); @@ -1559,7 +1632,6 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o u->counter_delta += (int64_t) chunk->length; } - #endif /* Called from main context */ @@ -1700,8 +1772,7 @@ int pa__init(pa_module*m) { u->device_index = u->channel = PA_INVALID_INDEX; u->time_event = NULL; u->ignore_latency_before = 0; - u->transport_usec = 0; - u->transport_usec_valid = FALSE; + u->transport_usec = u->thread_transport_usec = 0; u->remote_suspended = u->remote_corked = FALSE; u->counter = u->counter_delta = 0; @@ -1747,7 +1818,7 @@ int pa__init(pa_module*m) { if (u->sink_name) pa_proplist_sets(data.proplist, "tunnel.remote.sink", u->sink_name); - u->sink = pa_sink_new(m->core, &data, PA_SINK_NETWORK|PA_SINK_LATENCY|PA_SINK_HW_VOLUME_CTRL); + u->sink = pa_sink_new(m->core, &data, PA_SINK_NETWORK|PA_SINK_LATENCY|PA_SINK_HW_VOLUME_CTRL|PA_SINK_HW_MUTE_CTRL); pa_sink_new_data_done(&data); if (!u->sink) { @@ -1763,7 +1834,7 @@ int pa__init(pa_module*m) { u->sink->refresh_volume = u->sink->refresh_muted = FALSE; - pa_sink_set_latency_range(u->sink, MIN_NETWORK_LATENCY_USEC, 0); +/* pa_sink_set_latency_range(u->sink, MIN_NETWORK_LATENCY_USEC, 0); */ pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq); pa_sink_set_rtpoll(u->sink, u->rtpoll); @@ -1797,7 +1868,7 @@ int pa__init(pa_module*m) { u->source->set_state = source_set_state; u->source->userdata = u; - pa_source_set_latency_range(u->source, MIN_NETWORK_LATENCY_USEC, 0); +/* pa_source_set_latency_range(u->source, MIN_NETWORK_LATENCY_USEC, 0); */ pa_source_set_asyncmsgq(u->source, u->thread_mq.inq); pa_source_set_rtpoll(u->source, u->rtpoll); diff --git a/src/modules/reserve-wrap.c b/src/modules/reserve-wrap.c index c956673b..1927342b 100644 --- a/src/modules/reserve-wrap.c +++ b/src/modules/reserve-wrap.c @@ -29,8 +29,7 @@ #include <pulsecore/core-error.h> #include <pulsecore/core-util.h> #include <pulsecore/shared.h> - -#include <modules/dbus-util.h> +#include <pulsecore/dbus-shared.h> #include "reserve.h" #include "reserve-wrap.h" |