X-Git-Url: https://code.delx.au/pulseaudio/blobdiff_plain/c0fb91db545774ec45f208a6f771c22a0b153637..5cf0c1e544a5fce97d514c793256b2e301277136:/src/pulse/context.c diff --git a/src/pulse/context.c b/src/pulse/context.c index 8686e0de..894ab2e0 100644 --- a/src/pulse/context.c +++ b/src/pulse/context.c @@ -6,7 +6,7 @@ PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published - by the Free Software Foundation; either version 2 of the License, + by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. PulseAudio is distributed in the hope that it will be useful, but @@ -54,6 +54,8 @@ #include #include #include +#include +#include #include #include @@ -64,6 +66,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +77,7 @@ #include "internal.h" #include "client-conf.h" +#include "fork-detect.h" #ifdef HAVE_X11 #include "client-conf-x11.h" @@ -98,10 +102,16 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = { [PA_COMMAND_EXTENSION] = pa_command_extension, [PA_COMMAND_PLAYBACK_STREAM_EVENT] = pa_command_stream_event, [PA_COMMAND_RECORD_STREAM_EVENT] = pa_command_stream_event, - [PA_COMMAND_CLIENT_EVENT] = pa_command_client_event + [PA_COMMAND_CLIENT_EVENT] = pa_command_client_event, + [PA_COMMAND_PLAYBACK_BUFFER_ATTR_CHANGED] = pa_command_stream_buffer_attr, + [PA_COMMAND_RECORD_BUFFER_ATTR_CHANGED] = pa_command_stream_buffer_attr }; static void context_free(pa_context *c); +#ifdef HAVE_DBUS +static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, void *userdata); +#endif + pa_context *pa_context_new(pa_mainloop_api *mainloop, const char *name) { return pa_context_new_with_proplist(mainloop, name, NULL); } @@ -127,6 +137,9 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char * pa_assert(mainloop); + if (pa_detect_fork()) + return NULL; + pa_init_i18n(); c = pa_xnew(pa_context, 1); @@ -137,6 +150,9 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char * if (name) pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name); +#ifdef HAVE_DBUS + c->system_bus = c->session_bus = NULL; +#endif c->mainloop = mainloop; c->client = NULL; c->pstream = NULL; @@ -144,6 +160,7 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char * c->playback_streams = pa_dynarray_new(); c->record_streams = pa_dynarray_new(); c->client_index = PA_INVALID_INDEX; + c->use_rtclock = pa_mainloop_is_our_api(mainloop); PA_LLIST_HEAD_INIT(pa_stream, c->streams); PA_LLIST_HEAD_INIT(pa_operation, c->operations); @@ -161,6 +178,8 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char * c->do_shm = FALSE; + c->server_specified = FALSE; + c->no_fail = FALSE; c->do_autospawn = FALSE; memset(&c->spawn_api, 0, sizeof(c->spawn_api)); @@ -171,10 +190,10 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char * #endif c->conf = pa_client_conf_new(); + pa_client_conf_load(c->conf, NULL); #ifdef HAVE_X11 pa_client_conf_from_x11(c->conf, NULL); #endif - pa_client_conf_load(c->conf, NULL); pa_client_conf_env(c->conf); if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm, c->conf->shm_size))) { @@ -231,6 +250,18 @@ static void context_free(pa_context *c) { context_unlink(c); +#ifdef HAVE_DBUS + if (c->system_bus) { + dbus_connection_remove_filter(pa_dbus_wrap_connection_get(c->system_bus), filter_cb, c); + pa_dbus_wrap_connection_free(c->system_bus); + } + + if (c->session_bus) { + dbus_connection_remove_filter(pa_dbus_wrap_connection_get(c->session_bus), filter_cb, c); + pa_dbus_wrap_connection_free(c->session_bus); + } +#endif + if (c->record_streams) pa_dynarray_free(c->record_streams, NULL, NULL); if (c->playback_streams) @@ -335,8 +366,7 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o pa_assert(p); pa_assert(chunk); - pa_assert(chunk->memblock); - pa_assert(chunk->length); + pa_assert(chunk->length > 0); pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); @@ -344,11 +374,11 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o if ((s = pa_dynarray_get(c->record_streams, channel))) { - pa_assert(seek == PA_SEEK_RELATIVE); - pa_assert(offset == 0); - - pa_memblockq_seek(s->record_memblockq, offset, seek); - pa_memblockq_push_align(s->record_memblockq, chunk); + if (chunk->memblock) { + pa_memblockq_seek(s->record_memblockq, offset, seek, TRUE); + pa_memblockq_push_align(s->record_memblockq, chunk); + } else + pa_memblockq_seek(s->record_memblockq, offset+chunk->length, seek, TRUE); if (s->read_callback) { size_t l; @@ -514,7 +544,7 @@ static void setup_context(pa_context *c, pa_iochannel *io) { pa_pstream_set_recieve_memblock_callback(c->pstream, pstream_memblock_callback, c); pa_assert(!c->pdispatch); - c->pdispatch = pa_pdispatch_new(c->mainloop, command_table, PA_COMMAND_MAX); + c->pdispatch = pa_pdispatch_new(c->mainloop, c->use_rtclock, command_table, PA_COMMAND_MAX); if (!c->conf->cookie_valid) pa_log_info(_("No cookie loaded. Attempting to connect without.")); @@ -555,6 +585,7 @@ static void setup_context(pa_context *c, pa_iochannel *io) { pa_context_unref(c); } +#ifdef ENABLE_LEGACY_RUNTIME_DIR static char *get_old_legacy_runtime_dir(void) { char *p, u[128]; struct stat st; @@ -598,10 +629,12 @@ static char *get_very_old_legacy_runtime_dir(void) { return p; } - +#endif static pa_strlist *prepend_per_user(pa_strlist *l) { char *ufn; + +#ifdef ENABLE_LEGACY_RUNTIME_DIR static char *legacy_dir; /* The very old per-user instance path (< 0.9.11). This is supported only to ease upgrades */ @@ -619,6 +652,7 @@ static pa_strlist *prepend_per_user(pa_strlist *l) { pa_xfree(p); pa_xfree(legacy_dir); } +#endif /* The per-user instance */ if ((ufn = pa_runtime_path(PA_NATIVE_DEFAULT_UNIX_SOCKET))) { @@ -634,11 +668,24 @@ static pa_strlist *prepend_per_user(pa_strlist *l) { static int context_autospawn(pa_context *c) { pid_t pid; int status, r; - - pa_log_debug("Trying to autospawn..."); + struct sigaction sa; pa_context_ref(c); + if (sigaction(SIGCHLD, NULL, &sa) < 0) { + pa_log_debug("sigaction() failed: %s", pa_cstrerror(errno)); + pa_context_fail(c, PA_ERR_INTERNAL); + goto fail; + } + + if ((sa.sa_flags & SA_NOCLDWAIT) || sa.sa_handler == SIG_IGN) { + pa_log_debug("Process disabled waitpid(), cannot autospawn."); + pa_context_fail(c, PA_ERR_CONNECTIONREFUSED); + goto fail; + } + + pa_log_debug("Trying to autospawn..."); + if (c->spawn_api.prefork) c->spawn_api.prefork(); @@ -654,23 +701,23 @@ static int context_autospawn(pa_context *c) { /* Child */ const char *state = NULL; -#define MAX_ARGS 64 - const char * argv[MAX_ARGS+1]; - int n; + const char * argv[32]; + unsigned n = 0; if (c->spawn_api.atfork) c->spawn_api.atfork(); + /* We leave most of the cleaning up of the process environment + * to the executable. We only clean up the file descriptors to + * make sure the executable can actually be loaded + * correctly. */ pa_close_all(-1); /* Setup argv */ - - n = 0; - argv[n++] = c->conf->daemon_binary; argv[n++] = "--start"; - while (n < MAX_ARGS) { + while (n < PA_ELEMENTSOF(argv)-1) { char *a; if (!(a = pa_split_spaces(c->conf->extra_arguments, &state))) @@ -680,10 +727,10 @@ static int context_autospawn(pa_context *c) { } argv[n++] = NULL; + pa_assert(n <= PA_ELEMENTSOF(argv)); execv(argv[0], (char * const *) argv); _exit(1); -#undef MAX_ARGS } /* Parent */ @@ -696,9 +743,16 @@ static int context_autospawn(pa_context *c) { } while (r < 0 && errno == EINTR); if (r < 0) { - pa_log(_("waitpid(): %s"), pa_cstrerror(errno)); - pa_context_fail(c, PA_ERR_INTERNAL); - goto fail; + + if (errno != ESRCH) { + pa_log(_("waitpid(): %s"), pa_cstrerror(errno)); + pa_context_fail(c, PA_ERR_INTERNAL); + goto fail; + } + + /* hmm, something already reaped our child, so we assume + * startup worked, even if we cannot know */ + } else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { pa_context_fail(c, PA_ERR_CONNECTIONREFUSED); goto fail; @@ -719,6 +773,45 @@ fail: static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userdata); +#ifdef HAVE_DBUS +static void track_pulseaudio_on_dbus(pa_context *c, DBusBusType type, pa_dbus_wrap_connection **conn) { + DBusError error; + + pa_assert(c); + pa_assert(conn); + + dbus_error_init(&error); + + if (!(*conn = pa_dbus_wrap_connection_new(c->mainloop, c->use_rtclock, type, &error)) || dbus_error_is_set(&error)) { + pa_log_warn("Unable to contact DBUS: %s: %s", error.name, error.message); + goto fail; + } + + if (!dbus_connection_add_filter(pa_dbus_wrap_connection_get(*conn), filter_cb, c, NULL)) { + pa_log_warn("Failed to add filter function"); + goto fail; + } + + if (pa_dbus_add_matches( + pa_dbus_wrap_connection_get(*conn), &error, + "type='signal',sender='" DBUS_SERVICE_DBUS "',interface='" DBUS_INTERFACE_DBUS "',member='NameOwnerChanged',arg0='org.pulseaudio.Server',arg1=''", NULL) < 0) { + + pa_log_warn("Unable to track org.pulseaudio.Server: %s: %s", error.name, error.message); + goto fail; + } + + return; + +fail: + if (*conn) { + pa_dbus_wrap_connection_free(*conn); + *conn = NULL; + } + + dbus_error_free(&error); +} +#endif + static int try_next_connection(pa_context *c) { char *u = NULL; int r = -1; @@ -751,7 +844,16 @@ static int try_next_connection(pa_context *c) { } #endif - pa_context_fail(c, PA_ERR_CONNECTIONREFUSED); +#ifdef HAVE_DBUS + if (c->no_fail && !c->server_specified) { + if (!c->session_bus) + track_pulseaudio_on_dbus(c, DBUS_BUS_SESSION, &c->session_bus); + if (!c->system_bus) + track_pulseaudio_on_dbus(c, DBUS_BUS_SYSTEM, &c->system_bus); + } else +#endif + pa_context_fail(c, PA_ERR_CONNECTIONREFUSED); + goto finish; } @@ -760,7 +862,7 @@ static int try_next_connection(pa_context *c) { pa_xfree(c->server); c->server = pa_xstrdup(u); - if (!(c->client = pa_socket_client_new_string(c->mainloop, u, PA_NATIVE_DEFAULT_PORT))) + if (!(c->client = pa_socket_client_new_string(c->mainloop, c->use_rtclock, u, PA_NATIVE_DEFAULT_PORT))) continue; c->is_local = !!pa_socket_client_is_local(c->client); @@ -790,7 +892,7 @@ static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userd c->client = NULL; if (!io) { - /* Try the item in the list */ + /* Try the next item in the list */ if (saved_errno == ECONNREFUSED || saved_errno == ETIMEDOUT || saved_errno == EHOSTUNREACH) { @@ -808,6 +910,41 @@ finish: pa_context_unref(c); } +#ifdef HAVE_DBUS +static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, void *userdata) { + pa_context *c = userdata; + pa_bool_t is_session; + + pa_assert(bus); + pa_assert(message); + pa_assert(c); + + if (c->state != PA_CONTEXT_CONNECTING) + goto finish; + + if (!c->no_fail) + goto finish; + + /* FIXME: We probably should check if this is actually the NameOwnerChanged we were looking for */ + + is_session = c->session_bus && bus == pa_dbus_wrap_connection_get(c->session_bus); + pa_log_debug("Rock!! PulseAudio might be back on %s bus", is_session ? "session" : "system"); + + if (is_session) + /* The user instance via PF_LOCAL */ + c->server_list = prepend_per_user(c->server_list); + else + /* The system wide instance via PF_LOCAL */ + c->server_list = pa_strlist_prepend(c->server_list, PA_SYSTEM_RUNTIME_PATH PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET); + + if (!c->client) + try_next_connection(c); + +finish: + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} +#endif + int pa_context_connect( pa_context *c, const char *server, @@ -819,15 +956,20 @@ int pa_context_connect( pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + PA_CHECK_VALIDITY(c, !pa_detect_fork(), PA_ERR_FORKED); PA_CHECK_VALIDITY(c, c->state == PA_CONTEXT_UNCONNECTED, PA_ERR_BADSTATE); - PA_CHECK_VALIDITY(c, !(flags & ~PA_CONTEXT_NOAUTOSPAWN), PA_ERR_INVALID); + PA_CHECK_VALIDITY(c, !(flags & ~(PA_CONTEXT_NOAUTOSPAWN|PA_CONTEXT_NOFAIL)), PA_ERR_INVALID); PA_CHECK_VALIDITY(c, !server || *server, PA_ERR_INVALID); - if (!server) + if (server) + c->conf->autospawn = FALSE; + else server = c->conf->default_server; pa_context_ref(c); + c->no_fail = !!(flags & PA_CONTEXT_NOFAIL); + c->server_specified = !!server; pa_assert(!c->server_list); if (server) { @@ -843,10 +985,7 @@ int pa_context_connect( /* Follow the X display */ if ((d = getenv("DISPLAY"))) { - char *e; - d = pa_xstrdup(d); - if ((e = strchr(d, ':'))) - *e = 0; + d = pa_xstrndup(d, strcspn(d, ":")); if (*d) c->server_list = pa_strlist_prepend(c->server_list, d); @@ -863,18 +1002,18 @@ int pa_context_connect( /* The user instance via PF_LOCAL */ c->server_list = prepend_per_user(c->server_list); + } - /* Set up autospawning */ - if (!(flags & PA_CONTEXT_NOAUTOSPAWN) && c->conf->autospawn) { + /* Set up autospawning */ + if (!(flags & PA_CONTEXT_NOAUTOSPAWN) && c->conf->autospawn) { - if (getuid() == 0) - pa_log_debug("Not doing autospawn since we are root."); - else { - c->do_autospawn = TRUE; + if (getuid() == 0) + pa_log_debug("Not doing autospawn since we are root."); + else { + c->do_autospawn = TRUE; - if (api) - c->spawn_api = *api; - } + if (api) + c->spawn_api = *api; } } @@ -891,6 +1030,9 @@ void pa_context_disconnect(pa_context *c) { pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + if (pa_detect_fork()) + return; + if (PA_CONTEXT_IS_GOOD(c->state)) pa_context_set_state(c, PA_CONTEXT_TERMINATED); } @@ -913,6 +1055,9 @@ void pa_context_set_state_callback(pa_context *c, pa_context_notify_cb_t cb, voi pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + if (pa_detect_fork()) + return; + if (c->state == PA_CONTEXT_TERMINATED || c->state == PA_CONTEXT_FAILED) return; @@ -924,6 +1069,9 @@ void pa_context_set_event_callback(pa_context *c, pa_context_event_cb_t cb, void pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + if (pa_detect_fork()) + return; + if (c->state == PA_CONTEXT_TERMINATED || c->state == PA_CONTEXT_FAILED) return; @@ -935,6 +1083,7 @@ int pa_context_is_pending(pa_context *c) { pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + PA_CHECK_VALIDITY(c, !pa_detect_fork(), PA_ERR_FORKED); PA_CHECK_VALIDITY(c, PA_CONTEXT_IS_GOOD(c->state), PA_ERR_BADSTATE); return (c->pstream && pa_pstream_is_pending(c->pstream)) || @@ -991,6 +1140,7 @@ pa_operation* pa_context_drain(pa_context *c, pa_context_notify_cb_t cb, void *u pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED); PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE); PA_CHECK_VALIDITY_RETURN_NULL(c, pa_context_is_pending(c), PA_ERR_BADSTATE); @@ -1039,6 +1189,7 @@ pa_operation* pa_context_send_simple_command(pa_context *c, uint32_t command, pa pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED); PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE); o = pa_operation_new(c, NULL, cb, userdata); @@ -1065,6 +1216,7 @@ pa_operation* pa_context_set_default_sink(pa_context *c, const char *name, pa_co pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED); PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE); o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata); @@ -1084,6 +1236,7 @@ pa_operation* pa_context_set_default_source(pa_context *c, const char *name, pa_ pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED); PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE); o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata); @@ -1099,6 +1252,7 @@ int pa_context_is_local(pa_context *c) { pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + PA_CHECK_VALIDITY_RETURN_ANY(c, !pa_detect_fork(), PA_ERR_FORKED, -1); PA_CHECK_VALIDITY_RETURN_ANY(c, PA_CONTEXT_IS_GOOD(c->state), PA_ERR_BADSTATE, -1); return !!c->is_local; @@ -1111,6 +1265,7 @@ pa_operation* pa_context_set_name(pa_context *c, const char *name, pa_context_su pa_assert(PA_REFCNT_VALUE(c) >= 1); pa_assert(name); + PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED); PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE); if (c->version >= 13) { @@ -1141,8 +1296,8 @@ const char* pa_context_get_server(pa_context *c) { pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); - if (!c->server) - return NULL; + PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED); + PA_CHECK_VALIDITY_RETURN_NULL(c, c->server, PA_ERR_NOENTITY); if (*c->server == '{') { char *e = strchr(c->server+1, '}'); @@ -1160,6 +1315,7 @@ uint32_t pa_context_get_server_protocol_version(pa_context *c) { pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + PA_CHECK_VALIDITY_RETURN_ANY(c, !pa_detect_fork(), PA_ERR_FORKED, PA_INVALID_INDEX); PA_CHECK_VALIDITY_RETURN_ANY(c, PA_CONTEXT_IS_GOOD(c->state), PA_ERR_BADSTATE, PA_INVALID_INDEX); return c->version; @@ -1182,6 +1338,7 @@ uint32_t pa_context_get_index(pa_context *c) { pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + PA_CHECK_VALIDITY_RETURN_ANY(c, !pa_detect_fork(), PA_ERR_FORKED, PA_INVALID_INDEX); PA_CHECK_VALIDITY_RETURN_ANY(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE, PA_INVALID_INDEX); PA_CHECK_VALIDITY_RETURN_ANY(c, c->version >= 13, PA_ERR_NOTSUPPORTED, PA_INVALID_INDEX); @@ -1196,6 +1353,7 @@ pa_operation *pa_context_proplist_update(pa_context *c, pa_update_mode_t mode, p pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED); PA_CHECK_VALIDITY_RETURN_NULL(c, mode == PA_UPDATE_SET || mode == PA_UPDATE_MERGE || mode == PA_UPDATE_REPLACE, PA_ERR_INVALID); PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE); PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 13, PA_ERR_NOTSUPPORTED); @@ -1224,6 +1382,7 @@ pa_operation *pa_context_proplist_remove(pa_context *c, const char *const keys[] pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); + PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED); PA_CHECK_VALIDITY_RETURN_NULL(c, keys && keys[0], PA_ERR_INVALID); PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE); PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 13, PA_ERR_NOTSUPPORTED); @@ -1316,3 +1475,31 @@ finish: if (pl) pa_proplist_free(pl); } + +pa_time_event* pa_context_rttime_new(pa_context *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata) { + struct timeval tv; + + pa_assert(c); + pa_assert(c->mainloop); + + if (usec == PA_USEC_INVALID) + return c->mainloop->time_new(c->mainloop, NULL, cb, userdata); + + pa_timeval_rtstore(&tv, usec, c->use_rtclock); + + return c->mainloop->time_new(c->mainloop, &tv, cb, userdata); +} + +void pa_context_rttime_restart(pa_context *c, pa_time_event *e, pa_usec_t usec) { + struct timeval tv; + + pa_assert(c); + pa_assert(c->mainloop); + + if (usec == PA_USEC_INVALID) + c->mainloop->time_restart(e, NULL); + else { + pa_timeval_rtstore(&tv, usec, c->use_rtclock); + c->mainloop->time_restart(e, &tv); + } +}