Merge most of elmarco/rtclock2

Merge commit 'e4d914c945'
This commit is contained in:
Lennart Poettering 2009-06-22 23:09:46 +02:00
commit fc33f7ee97
56 changed files with 510 additions and 335 deletions

View file

@ -64,6 +64,11 @@ AM_CFLAGS = \
-I$(top_srcdir)/src/modules/alsa \ -I$(top_srcdir)/src/modules/alsa \
-I$(top_builddir)/src/modules/alsa \ -I$(top_builddir)/src/modules/alsa \
-I$(top_srcdir)/src/modules/raop \ -I$(top_srcdir)/src/modules/raop \
-I$(top_builddir)/src/modules/raop \
-I$(top_srcdir)/src/modules/x11 \
-I$(top_builddir)/src/modules/x11 \
-I$(top_srcdir)/src/modules/jack \
-I$(top_builddir)/src/modules/jack \
$(PTHREAD_CFLAGS) -D_POSIX_PTHREAD_SEMANTICS \ $(PTHREAD_CFLAGS) -D_POSIX_PTHREAD_SEMANTICS \
$(LIBSAMPLERATE_CFLAGS) \ $(LIBSAMPLERATE_CFLAGS) \
$(LIBSNDFILE_CFLAGS) \ $(LIBSNDFILE_CFLAGS) \
@ -561,6 +566,7 @@ libpulsecommon_@PA_MAJORMINORMICRO@_la_SOURCES = \
pulsecore/authkey.c pulsecore/authkey.h \ pulsecore/authkey.c pulsecore/authkey.h \
pulsecore/conf-parser.c pulsecore/conf-parser.h \ pulsecore/conf-parser.c pulsecore/conf-parser.h \
pulsecore/core-error.c pulsecore/core-error.h \ pulsecore/core-error.c pulsecore/core-error.h \
pulsecore/core-rtclock.c pulsecore/core-rtclock.h \
pulsecore/core-util.c pulsecore/core-util.h \ pulsecore/core-util.c pulsecore/core-util.h \
pulsecore/rtkit.c pulsecore/rtkit.h \ pulsecore/rtkit.c pulsecore/rtkit.h \
pulsecore/creds.h \ pulsecore/creds.h \
@ -600,7 +606,6 @@ libpulsecommon_@PA_MAJORMINORMICRO@_la_SOURCES = \
pulsecore/queue.c pulsecore/queue.h \ pulsecore/queue.c pulsecore/queue.h \
pulsecore/random.c pulsecore/random.h \ pulsecore/random.c pulsecore/random.h \
pulsecore/refcnt.h \ pulsecore/refcnt.h \
pulsecore/rtclock.c pulsecore/rtclock.h \
pulsecore/shm.c pulsecore/shm.h \ pulsecore/shm.c pulsecore/shm.h \
pulsecore/bitset.c pulsecore/bitset.h \ pulsecore/bitset.c pulsecore/bitset.h \
pulsecore/socket-client.c pulsecore/socket-client.h \ pulsecore/socket-client.c pulsecore/socket-client.h \
@ -678,6 +683,7 @@ pulseinclude_HEADERS = \
pulse/operation.h \ pulse/operation.h \
pulse/proplist.h \ pulse/proplist.h \
pulse/pulseaudio.h \ pulse/pulseaudio.h \
pulse/rtclock.h \
pulse/sample.h \ pulse/sample.h \
pulse/scache.h \ pulse/scache.h \
pulse/simple.h \ pulse/simple.h \
@ -728,6 +734,7 @@ libpulse_la_SOURCES = \
pulse/operation.c pulse/operation.h \ pulse/operation.c pulse/operation.h \
pulse/proplist.c pulse/proplist.h \ pulse/proplist.c pulse/proplist.h \
pulse/pulseaudio.h \ pulse/pulseaudio.h \
pulse/rtclock.c pulse/rtclock.h \
pulse/sample.c pulse/sample.h \ pulse/sample.c pulse/sample.h \
pulse/scache.c pulse/scache.h \ pulse/scache.c pulse/scache.h \
pulse/stream.c pulse/stream.h \ pulse/stream.c pulse/stream.h \

View file

@ -24,13 +24,14 @@
#endif #endif
#include <pulse/error.h> #include <pulse/error.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/rtclock.h>
#include "cpulimit.h" #include "cpulimit.h"
@ -125,7 +126,7 @@ static void signal_handler(int sig) {
char t[256]; char t[256];
#endif #endif
now = pa_rtclock_usec(); now = pa_rtclock_now();
elapsed = now - last_time; elapsed = now - last_time;
#ifdef PRINT_CPU_LOAD #ifdef PRINT_CPU_LOAD
@ -184,7 +185,7 @@ int pa_cpu_limit_init(pa_mainloop_api *m) {
pa_assert(the_pipe[1] == -1); pa_assert(the_pipe[1] == -1);
pa_assert(!installed); pa_assert(!installed);
last_time = pa_rtclock_usec(); last_time = pa_rtclock_now();
/* Prepare the main loop pipe */ /* Prepare the main loop pipe */
if (pipe(the_pipe) < 0) { if (pipe(the_pipe) < 0) {

View file

@ -73,6 +73,7 @@
#include <pulsecore/lock-autospawn.h> #include <pulsecore/lock-autospawn.h>
#include <pulsecore/winsock.h> #include <pulsecore/winsock.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core.h> #include <pulsecore/core.h>
#include <pulsecore/memblock.h> #include <pulsecore/memblock.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
@ -131,7 +132,7 @@ static void message_cb(pa_mainloop_api*a, pa_time_event*e, const struct timeval
} }
pa_timeval_add(pa_gettimeofday(&tvnext), 100000); pa_timeval_add(pa_gettimeofday(&tvnext), 100000);
a->time_restart(e, &tvnext); a->rtclock_time_restart(e, &tvnext);
} }
#endif #endif
@ -845,7 +846,7 @@ int main(int argc, char *argv[]) {
#endif #endif
#ifdef OS_IS_WIN32 #ifdef OS_IS_WIN32
win32_timer = pa_mainloop_get_api(mainloop)->time_new(pa_mainloop_get_api(mainloop), pa_gettimeofday(&win32_tv), message_cb, NULL); win32_timer = pa_mainloop_get_api(mainloop)->rtclock_time_new(pa_mainloop_get_api(mainloop), pa_gettimeofday(&win32_tv), message_cb, NULL);
#endif #endif
oil_init(); oil_init();

View file

@ -86,6 +86,8 @@ pa_context_ref;
pa_context_remove_autoload_by_index; pa_context_remove_autoload_by_index;
pa_context_remove_autoload_by_name; pa_context_remove_autoload_by_name;
pa_context_remove_sample; pa_context_remove_sample;
pa_context_rttime_new;
pa_context_rttime_restart;
pa_context_set_card_profile_by_index; pa_context_set_card_profile_by_index;
pa_context_set_card_profile_by_name; pa_context_set_card_profile_by_name;
pa_context_set_default_sink; pa_context_set_default_sink;
@ -195,6 +197,7 @@ pa_proplist_to_string_sep;
pa_proplist_unset; pa_proplist_unset;
pa_proplist_unset_many; pa_proplist_unset_many;
pa_proplist_update; pa_proplist_update;
pa_rtclock_now;
pa_sample_format_is_be; pa_sample_format_is_be;
pa_sample_format_is_le; pa_sample_format_is_le;
pa_sample_format_to_string; pa_sample_format_to_string;

View file

@ -32,16 +32,18 @@
#include <valgrind/memcheck.h> #include <valgrind/memcheck.h>
#endif #endif
#include <pulse/xmalloc.h>
#include <pulse/util.h>
#include <pulse/timeval.h>
#include <pulse/i18n.h> #include <pulse/i18n.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h>
#include <pulse/util.h>
#include <pulse/xmalloc.h>
#include <pulsecore/core.h> #include <pulsecore/core.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
#include <pulsecore/memchunk.h> #include <pulsecore/memchunk.h>
#include <pulsecore/sink.h> #include <pulsecore/sink.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/sample-util.h> #include <pulsecore/sample-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
@ -50,7 +52,6 @@
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/rtpoll.h> #include <pulsecore/rtpoll.h>
#include <pulsecore/rtclock.h>
#include <pulsecore/time-smoother.h> #include <pulsecore/time-smoother.h>
#include <modules/reserve-wrap.h> #include <modules/reserve-wrap.h>
@ -707,7 +708,7 @@ static void update_smoother(struct userdata *u) {
/* Hmm, if the timestamp is 0, then it wasn't set and we take the current time */ /* Hmm, if the timestamp is 0, then it wasn't set and we take the current time */
if (now1 <= 0) if (now1 <= 0)
now1 = pa_rtclock_usec(); now1 = pa_rtclock_now();
now2 = pa_bytes_to_usec((uint64_t) position, &u->sink->sample_spec); now2 = pa_bytes_to_usec((uint64_t) position, &u->sink->sample_spec);
@ -721,7 +722,7 @@ static pa_usec_t sink_get_latency(struct userdata *u) {
pa_assert(u); pa_assert(u);
now1 = pa_rtclock_usec(); now1 = pa_rtclock_now();
now2 = pa_smoother_get(u->smoother, now1); now2 = pa_smoother_get(u->smoother, now1);
delay = (int64_t) pa_bytes_to_usec(u->write_count, &u->sink->sample_spec) - (int64_t) now2; delay = (int64_t) pa_bytes_to_usec(u->write_count, &u->sink->sample_spec) - (int64_t) now2;
@ -752,7 +753,7 @@ static int suspend(struct userdata *u) {
pa_assert(u); pa_assert(u);
pa_assert(u->pcm_handle); pa_assert(u->pcm_handle);
pa_smoother_pause(u->smoother, pa_rtclock_usec()); pa_smoother_pause(u->smoother, pa_rtclock_now());
/* Let's suspend -- we don't call snd_pcm_drain() here since that might /* Let's suspend -- we don't call snd_pcm_drain() here since that might
* take awfully long with our long buffer sizes today. */ * take awfully long with our long buffer sizes today. */
@ -1245,7 +1246,7 @@ static void thread_func(void *userdata) {
pa_log_info("Starting playback."); pa_log_info("Starting playback.");
snd_pcm_start(u->pcm_handle); snd_pcm_start(u->pcm_handle);
pa_smoother_resume(u->smoother, pa_rtclock_usec(), TRUE); pa_smoother_resume(u->smoother, pa_rtclock_now(), TRUE);
} }
update_smoother(u); update_smoother(u);
@ -1274,7 +1275,7 @@ static void thread_func(void *userdata) {
/* Convert from the sound card time domain to the /* Convert from the sound card time domain to the
* system time domain */ * system time domain */
cusec = pa_smoother_translate(u->smoother, pa_rtclock_usec(), sleep_usec); cusec = pa_smoother_translate(u->smoother, pa_rtclock_now(), sleep_usec);
/* pa_log_debug("Waking up in %0.2fms (system clock).", (double) cusec / PA_USEC_PER_MSEC); */ /* pa_log_debug("Waking up in %0.2fms (system clock).", (double) cusec / PA_USEC_PER_MSEC); */
@ -1580,7 +1581,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
TRUE, TRUE,
TRUE, TRUE,
5, 5,
pa_rtclock_usec(), pa_rtclock_now(),
TRUE); TRUE);
dev_id = pa_modargs_get_value( dev_id = pa_modargs_get_value(

View file

@ -28,10 +28,11 @@
#include <asoundlib.h> #include <asoundlib.h>
#include <pulse/xmalloc.h>
#include <pulse/util.h>
#include <pulse/timeval.h>
#include <pulse/i18n.h> #include <pulse/i18n.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h>
#include <pulse/util.h>
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/core.h> #include <pulsecore/core.h>
@ -39,6 +40,7 @@
#include <pulsecore/memchunk.h> #include <pulsecore/memchunk.h>
#include <pulsecore/sink.h> #include <pulsecore/sink.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/sample-util.h> #include <pulsecore/sample-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
@ -48,7 +50,6 @@
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/rtpoll.h> #include <pulsecore/rtpoll.h>
#include <pulsecore/time-smoother.h> #include <pulsecore/time-smoother.h>
#include <pulsecore/rtclock.h>
#include <modules/reserve-wrap.h> #include <modules/reserve-wrap.h>
@ -669,7 +670,7 @@ static void update_smoother(struct userdata *u) {
/* Hmm, if the timestamp is 0, then it wasn't set and we take the current time */ /* Hmm, if the timestamp is 0, then it wasn't set and we take the current time */
if (now1 <= 0) if (now1 <= 0)
now1 = pa_rtclock_usec(); now1 = pa_rtclock_now();
now2 = pa_bytes_to_usec(position, &u->source->sample_spec); now2 = pa_bytes_to_usec(position, &u->source->sample_spec);
@ -682,7 +683,7 @@ static pa_usec_t source_get_latency(struct userdata *u) {
pa_assert(u); pa_assert(u);
now1 = pa_rtclock_usec(); now1 = pa_rtclock_now();
now2 = pa_smoother_get(u->smoother, now1); now2 = pa_smoother_get(u->smoother, now1);
delay = (int64_t) now2 - (int64_t) pa_bytes_to_usec(u->read_count, &u->source->sample_spec); delay = (int64_t) now2 - (int64_t) pa_bytes_to_usec(u->read_count, &u->source->sample_spec);
@ -707,7 +708,7 @@ static int suspend(struct userdata *u) {
pa_assert(u); pa_assert(u);
pa_assert(u->pcm_handle); pa_assert(u->pcm_handle);
pa_smoother_pause(u->smoother, pa_rtclock_usec()); pa_smoother_pause(u->smoother, pa_rtclock_now());
/* Let's suspend */ /* Let's suspend */
snd_pcm_close(u->pcm_handle); snd_pcm_close(u->pcm_handle);
@ -833,7 +834,7 @@ static int unsuspend(struct userdata *u) {
/* FIXME: We need to reload the volume somehow */ /* FIXME: We need to reload the volume somehow */
snd_pcm_start(u->pcm_handle); snd_pcm_start(u->pcm_handle);
pa_smoother_resume(u->smoother, pa_rtclock_usec(), TRUE); pa_smoother_resume(u->smoother, pa_rtclock_now(), TRUE);
pa_log_info("Resumed successfully..."); pa_log_info("Resumed successfully...");
@ -1130,7 +1131,7 @@ static void thread_func(void *userdata) {
/* Convert from the sound card time domain to the /* Convert from the sound card time domain to the
* system time domain */ * system time domain */
cusec = pa_smoother_translate(u->smoother, pa_rtclock_usec(), sleep_usec); cusec = pa_smoother_translate(u->smoother, pa_rtclock_now(), sleep_usec);
/* pa_log_debug("Waking up in %0.2fms (system clock).", (double) cusec / PA_USEC_PER_MSEC); */ /* pa_log_debug("Waking up in %0.2fms (system clock).", (double) cusec / PA_USEC_PER_MSEC); */
@ -1430,7 +1431,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
TRUE, TRUE,
TRUE, TRUE,
5, 5,
pa_rtclock_usec(), pa_rtclock_now(),
FALSE); FALSE);
dev_id = pa_modargs_get_value( dev_id = pa_modargs_get_value(

View file

@ -37,6 +37,7 @@
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core.h> #include <pulsecore/core.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
#include <pulsecore/memchunk.h> #include <pulsecore/memchunk.h>
@ -51,7 +52,6 @@
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/rtpoll.h> #include <pulsecore/rtpoll.h>
#include <pulsecore/time-smoother.h> #include <pulsecore/time-smoother.h>
#include <pulsecore/rtclock.h>
#include "alsa-util.h" #include "alsa-util.h"
#include "alsa-source.h" #include "alsa-source.h"

View file

@ -30,13 +30,15 @@
#include <linux/sockios.h> #include <linux/sockios.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <pulse/xmalloc.h>
#include <pulse/timeval.h>
#include <pulse/sample.h>
#include <pulse/i18n.h> #include <pulse/i18n.h>
#include <pulse/rtclock.h>
#include <pulse/sample.h>
#include <pulse/timeval.h>
#include <pulse/xmalloc.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/socket-util.h> #include <pulsecore/socket-util.h>
@ -44,7 +46,6 @@
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/rtpoll.h> #include <pulsecore/rtpoll.h>
#include <pulsecore/time-smoother.h> #include <pulsecore/time-smoother.h>
#include <pulsecore/rtclock.h>
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
#include <pulsecore/dbus-shared.h> #include <pulsecore/dbus-shared.h>
@ -773,7 +774,7 @@ static int start_stream_fd(struct userdata *u) {
TRUE, TRUE,
TRUE, TRUE,
10, 10,
pa_rtclock_usec(), pa_rtclock_now(),
TRUE); TRUE);
return 0; return 0;
@ -867,14 +868,14 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
if (u->read_smoother) { if (u->read_smoother) {
pa_usec_t wi, ri; pa_usec_t wi, ri;
ri = pa_smoother_get(u->read_smoother, pa_rtclock_usec()); ri = pa_smoother_get(u->read_smoother, pa_rtclock_now());
wi = pa_bytes_to_usec(u->write_index + u->block_size, &u->sample_spec); wi = pa_bytes_to_usec(u->write_index + u->block_size, &u->sample_spec);
*((pa_usec_t*) data) = wi > ri ? wi - ri : 0; *((pa_usec_t*) data) = wi > ri ? wi - ri : 0;
} else { } else {
pa_usec_t ri, wi; pa_usec_t ri, wi;
ri = pa_rtclock_usec() - u->started_at; ri = pa_rtclock_now() - u->started_at;
wi = pa_bytes_to_usec(u->write_index, &u->sample_spec); wi = pa_bytes_to_usec(u->write_index, &u->sample_spec);
*((pa_usec_t*) data) = wi > ri ? wi - ri : 0; *((pa_usec_t*) data) = wi > ri ? wi - ri : 0;
@ -912,7 +913,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
stop_stream_fd(u); stop_stream_fd(u);
if (u->read_smoother) if (u->read_smoother)
pa_smoother_pause(u->read_smoother, pa_rtclock_usec()); pa_smoother_pause(u->read_smoother, pa_rtclock_now());
break; break;
case PA_SOURCE_IDLE: case PA_SOURCE_IDLE:
@ -939,7 +940,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
case PA_SOURCE_MESSAGE_GET_LATENCY: { case PA_SOURCE_MESSAGE_GET_LATENCY: {
pa_usec_t wi, ri; pa_usec_t wi, ri;
wi = pa_smoother_get(u->read_smoother, pa_rtclock_usec()); wi = pa_smoother_get(u->read_smoother, pa_rtclock_now());
ri = pa_bytes_to_usec(u->read_index, &u->sample_spec); ri = pa_bytes_to_usec(u->read_index, &u->sample_spec);
*((pa_usec_t*) data) = (wi > ri ? wi - ri : 0) + u->source->fixed_latency; *((pa_usec_t*) data) = (wi > ri ? wi - ri : 0) + u->source->fixed_latency;
@ -1086,7 +1087,7 @@ static int hsp_process_push(struct userdata *u) {
if (!found_tstamp) { if (!found_tstamp) {
pa_log_warn("Couldn't find SO_TIMESTAMP data in auxiliary recvmsg() data!"); pa_log_warn("Couldn't find SO_TIMESTAMP data in auxiliary recvmsg() data!");
tstamp = pa_rtclock_usec(); tstamp = pa_rtclock_now();
} }
pa_smoother_put(u->read_smoother, tstamp, pa_bytes_to_usec(u->read_index, &u->sample_spec)); pa_smoother_put(u->read_smoother, tstamp, pa_bytes_to_usec(u->read_index, &u->sample_spec));
@ -1308,7 +1309,7 @@ static void thread_func(void *userdata) {
/* Hmm, there is no input stream we could synchronize /* Hmm, there is no input stream we could synchronize
* to. So let's do things by time */ * to. So let's do things by time */
time_passed = pa_rtclock_usec() - u->started_at; time_passed = pa_rtclock_now() - u->started_at;
audio_sent = pa_bytes_to_usec(u->write_index, &u->sample_spec); audio_sent = pa_bytes_to_usec(u->write_index, &u->sample_spec);
if (audio_sent <= time_passed) { if (audio_sent <= time_passed) {
@ -1340,7 +1341,7 @@ static void thread_func(void *userdata) {
int n_written; int n_written;
if (u->write_index <= 0) if (u->write_index <= 0)
u->started_at = pa_rtclock_usec(); u->started_at = pa_rtclock_now();
if (u->profile == PROFILE_A2DP) { if (u->profile == PROFILE_A2DP) {
if ((n_written = a2dp_process_render(u)) < 0) if ((n_written = a2dp_process_render(u)) < 0)
@ -1360,7 +1361,7 @@ static void thread_func(void *userdata) {
/* Hmm, there is no input stream we could synchronize /* Hmm, there is no input stream we could synchronize
* to. So let's estimate when we need to wake up the latest */ * to. So let's estimate when we need to wake up the latest */
time_passed = pa_rtclock_usec() - u->started_at; time_passed = pa_rtclock_now() - u->started_at;
next_write_at = pa_bytes_to_usec(u->write_index, &u->sample_spec); next_write_at = pa_bytes_to_usec(u->write_index, &u->sample_spec);
sleep_for = time_passed < next_write_at ? next_write_at - time_passed : 0; sleep_for = time_passed < next_write_at ? next_write_at - time_passed : 0;

View file

@ -35,6 +35,7 @@
#include <pulse/volume.h> #include <pulse/volume.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/util.h> #include <pulse/util.h>
#include <pulse/rtclock.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
@ -53,7 +54,7 @@ PA_MODULE_DESCRIPTION("Automatically restore profile of cards");
PA_MODULE_VERSION(PACKAGE_VERSION); PA_MODULE_VERSION(PACKAGE_VERSION);
PA_MODULE_LOAD_ONCE(TRUE); PA_MODULE_LOAD_ONCE(TRUE);
#define SAVE_INTERVAL 10 #define SAVE_INTERVAL (10 * PA_USEC_PER_SEC)
static const char* const valid_modargs[] = { static const char* const valid_modargs[] = {
NULL NULL
@ -75,12 +76,11 @@ struct entry {
char profile[PA_NAME_MAX]; char profile[PA_NAME_MAX];
} PA_GCC_PACKED ; } PA_GCC_PACKED ;
static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) { static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *t, void *userdata) {
struct userdata *u = userdata; struct userdata *u = userdata;
pa_assert(a); pa_assert(a);
pa_assert(e); pa_assert(e);
pa_assert(tv);
pa_assert(u); pa_assert(u);
pa_assert(e == u->save_time_event); pa_assert(e == u->save_time_event);
@ -132,14 +132,10 @@ fail:
} }
static void trigger_save(struct userdata *u) { static void trigger_save(struct userdata *u) {
struct timeval tv;
if (u->save_time_event) if (u->save_time_event)
return; return;
pa_gettimeofday(&tv); u->save_time_event = pa_core_rttime_new(u->core, pa_rtclock_now() + SAVE_INTERVAL, save_time_callback, u);
tv.tv_sec += SAVE_INTERVAL;
u->save_time_event = u->core->mainloop->time_new(u->core->mainloop, &tv, save_time_callback, u);
} }
static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) { static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {

View file

@ -26,6 +26,7 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
@ -36,6 +37,7 @@
#include <pulsecore/sink-input.h> #include <pulsecore/sink-input.h>
#include <pulsecore/memblockq.h> #include <pulsecore/memblockq.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
@ -43,7 +45,6 @@
#include <pulsecore/thread.h> #include <pulsecore/thread.h>
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/rtpoll.h> #include <pulsecore/rtpoll.h>
#include <pulsecore/rtclock.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/time-smoother.h> #include <pulsecore/time-smoother.h>
@ -224,9 +225,8 @@ static void adjust_rates(struct userdata *u) {
pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_UPDATE_LATENCY, NULL, (int64_t) avg_total_latency, NULL); pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_UPDATE_LATENCY, NULL, (int64_t) avg_total_latency, NULL);
} }
static void time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) { static void time_callback(pa_mainloop_api *a, pa_time_event *e, const struct timeval *t, void *userdata) {
struct userdata *u = userdata; struct userdata *u = userdata;
struct timeval n;
pa_assert(u); pa_assert(u);
pa_assert(a); pa_assert(a);
@ -234,9 +234,7 @@ static void time_callback(pa_mainloop_api*a, pa_time_event* e, const struct time
adjust_rates(u); adjust_rates(u);
pa_gettimeofday(&n); pa_core_rttime_restart(u->core, e, pa_rtclock_now() + u->adjust_time * PA_USEC_PER_SEC);
n.tv_sec += (time_t) u->adjust_time;
u->sink->core->mainloop->time_restart(e, &n);
} }
static void process_render_null(struct userdata *u, pa_usec_t now) { static void process_render_null(struct userdata *u, pa_usec_t now) {
@ -281,7 +279,7 @@ static void thread_func(void *userdata) {
pa_thread_mq_install(&u->thread_mq); pa_thread_mq_install(&u->thread_mq);
u->thread_info.timestamp = pa_rtclock_usec(); u->thread_info.timestamp = pa_rtclock_now();
u->thread_info.in_null_mode = FALSE; u->thread_info.in_null_mode = FALSE;
for (;;) { for (;;) {
@ -295,7 +293,7 @@ static void thread_func(void *userdata) {
if (PA_SINK_IS_OPENED(u->sink->thread_info.state) && !u->thread_info.active_outputs) { if (PA_SINK_IS_OPENED(u->sink->thread_info.state) && !u->thread_info.active_outputs) {
pa_usec_t now; pa_usec_t now;
now = pa_rtclock_usec(); now = pa_rtclock_now();
if (!u->thread_info.in_null_mode || u->thread_info.timestamp <= now) if (!u->thread_info.in_null_mode || u->thread_info.timestamp <= now)
process_render_null(u, now); process_render_null(u, now);
@ -663,16 +661,16 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
pa_atomic_store(&u->thread_info.running, PA_PTR_TO_UINT(data) == PA_SINK_RUNNING); pa_atomic_store(&u->thread_info.running, PA_PTR_TO_UINT(data) == PA_SINK_RUNNING);
if (PA_PTR_TO_UINT(data) == PA_SINK_SUSPENDED) if (PA_PTR_TO_UINT(data) == PA_SINK_SUSPENDED)
pa_smoother_pause(u->thread_info.smoother, pa_rtclock_usec()); pa_smoother_pause(u->thread_info.smoother, pa_rtclock_now());
else else
pa_smoother_resume(u->thread_info.smoother, pa_rtclock_usec(), TRUE); pa_smoother_resume(u->thread_info.smoother, pa_rtclock_now(), TRUE);
break; break;
case PA_SINK_MESSAGE_GET_LATENCY: { case PA_SINK_MESSAGE_GET_LATENCY: {
pa_usec_t x, y, c, *delay = data; pa_usec_t x, y, c, *delay = data;
x = pa_rtclock_usec(); x = pa_rtclock_now();
y = pa_smoother_get(u->thread_info.smoother, x); y = pa_smoother_get(u->thread_info.smoother, x);
c = pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec); c = pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec);
@ -729,7 +727,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
case SINK_MESSAGE_UPDATE_LATENCY: { case SINK_MESSAGE_UPDATE_LATENCY: {
pa_usec_t x, y, latency = (pa_usec_t) offset; pa_usec_t x, y, latency = (pa_usec_t) offset;
x = pa_rtclock_usec(); x = pa_rtclock_now();
y = pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec); y = pa_bytes_to_usec(u->thread_info.counter, &u->sink->sample_spec);
if (y > latency) if (y > latency)
@ -1169,12 +1167,8 @@ int pa__init(pa_module*m) {
if (o->sink_input) if (o->sink_input)
pa_sink_input_put(o->sink_input); pa_sink_input_put(o->sink_input);
if (u->adjust_time > 0) { if (u->adjust_time > 0)
struct timeval tv; u->time_event = pa_core_rttime_new(m->core, pa_rtclock_now() + u->adjust_time * PA_USEC_PER_SEC, time_callback, u);
pa_gettimeofday(&tv);
tv.tv_sec += (time_t) u->adjust_time;
u->time_event = m->core->mainloop->time_new(m->core->mainloop, &tv, time_callback, u);
}
pa_modargs_free(ma); pa_modargs_free(ma);

View file

@ -26,6 +26,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/util.h> #include <pulse/util.h>
@ -42,7 +43,7 @@ PA_MODULE_DESCRIPTION("Automatically restore the default sink and source");
PA_MODULE_VERSION(PACKAGE_VERSION); PA_MODULE_VERSION(PACKAGE_VERSION);
PA_MODULE_LOAD_ONCE(TRUE); PA_MODULE_LOAD_ONCE(TRUE);
#define DEFAULT_SAVE_INTERVAL 5 #define SAVE_INTERVAL (5 * PA_USEC_PER_SEC)
struct userdata { struct userdata {
pa_core *core; pa_core *core;
@ -127,7 +128,7 @@ static void save(struct userdata *u) {
u->modified = FALSE; u->modified = FALSE;
} }
static void time_cb(pa_mainloop_api *a, pa_time_event *e, const struct timeval *tv, void *userdata) { static void time_cb(pa_mainloop_api *a, pa_time_event *e, const struct timeval *t, void *userdata) {
struct userdata *u = userdata; struct userdata *u = userdata;
pa_assert(u); pa_assert(u);
@ -146,12 +147,8 @@ static void subscribe_cb(pa_core *c, pa_subscription_event_type_t t, uint32_t id
u->modified = TRUE; u->modified = TRUE;
if (!u->time_event) { if (!u->time_event)
struct timeval tv; u->time_event = pa_core_rttime_new(u->core, pa_rtclock_now() + SAVE_INTERVAL, time_cb, u);
pa_gettimeofday(&tv);
pa_timeval_add(&tv, DEFAULT_SAVE_INTERVAL*PA_USEC_PER_SEC);
u->time_event = u->core->mainloop->time_new(u->core->mainloop, &tv, time_cb, u);
}
} }
int pa__init(pa_module *m) { int pa__init(pa_module *m) {

View file

@ -35,6 +35,7 @@
#include <pulse/volume.h> #include <pulse/volume.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/util.h> #include <pulse/util.h>
#include <pulse/rtclock.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
@ -58,7 +59,7 @@ PA_MODULE_USAGE(
"restore_volume=<Save/restore volumes?> " "restore_volume=<Save/restore volumes?> "
"restore_muted=<Save/restore muted states?>"); "restore_muted=<Save/restore muted states?>");
#define SAVE_INTERVAL 10 #define SAVE_INTERVAL (10 * PA_USEC_PER_SEC)
static const char* const valid_modargs[] = { static const char* const valid_modargs[] = {
"restore_volume", "restore_volume",
@ -95,12 +96,11 @@ struct entry {
char port[PA_NAME_MAX]; char port[PA_NAME_MAX];
} PA_GCC_PACKED; } PA_GCC_PACKED;
static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) { static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *t, void *userdata) {
struct userdata *u = userdata; struct userdata *u = userdata;
pa_assert(a); pa_assert(a);
pa_assert(e); pa_assert(e);
pa_assert(tv);
pa_assert(u); pa_assert(u);
pa_assert(e == u->save_time_event); pa_assert(e == u->save_time_event);
@ -162,14 +162,10 @@ fail:
} }
static void trigger_save(struct userdata *u) { static void trigger_save(struct userdata *u) {
struct timeval tv;
if (u->save_time_event) if (u->save_time_event)
return; return;
pa_gettimeofday(&tv); u->save_time_event = pa_core_rttime_new(u->core, pa_rtclock_now() + SAVE_INTERVAL, save_time_callback, u);
tv.tv_sec += SAVE_INTERVAL;
u->save_time_event = u->core->mainloop->time_new(u->core->mainloop, &tv, save_time_callback, u);
} }
static pa_bool_t entries_equal(const struct entry *a, const struct entry *b) { static pa_bool_t entries_equal(const struct entry *a, const struct entry *b) {

View file

@ -41,13 +41,15 @@
#include <linux/sockios.h> #include <linux/sockios.h>
#endif #endif
#include <pulse/xmalloc.h> #include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/iochannel.h> #include <pulsecore/iochannel.h>
#include <pulsecore/sink.h> #include <pulsecore/sink.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
@ -57,7 +59,6 @@
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/thread.h> #include <pulsecore/thread.h>
#include <pulsecore/time-smoother.h> #include <pulsecore/time-smoother.h>
#include <pulsecore/rtclock.h>
#include <pulsecore/socket-util.h> #include <pulsecore/socket-util.h>
#include "module-esound-sink-symdef.h" #include "module-esound-sink-symdef.h"
@ -145,14 +146,14 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
case PA_SINK_SUSPENDED: case PA_SINK_SUSPENDED:
pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state)); pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state));
pa_smoother_pause(u->smoother, pa_rtclock_usec()); pa_smoother_pause(u->smoother, pa_rtclock_now());
break; break;
case PA_SINK_IDLE: case PA_SINK_IDLE:
case PA_SINK_RUNNING: case PA_SINK_RUNNING:
if (u->sink->thread_info.state == PA_SINK_SUSPENDED) if (u->sink->thread_info.state == PA_SINK_SUSPENDED)
pa_smoother_resume(u->smoother, pa_rtclock_usec(), TRUE); pa_smoother_resume(u->smoother, pa_rtclock_now(), TRUE);
break; break;
@ -167,7 +168,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
case PA_SINK_MESSAGE_GET_LATENCY: { case PA_SINK_MESSAGE_GET_LATENCY: {
pa_usec_t w, r; pa_usec_t w, r;
r = pa_smoother_get(u->smoother, pa_rtclock_usec()); r = pa_smoother_get(u->smoother, pa_rtclock_now());
w = pa_bytes_to_usec((uint64_t) u->offset + u->memchunk.length, &u->sink->sample_spec); w = pa_bytes_to_usec((uint64_t) u->offset + u->memchunk.length, &u->sink->sample_spec);
*((pa_usec_t*) data) = w > r ? w - r : 0; *((pa_usec_t*) data) = w > r ? w - r : 0;
@ -201,7 +202,7 @@ static void thread_func(void *userdata) {
pa_thread_mq_install(&u->thread_mq); pa_thread_mq_install(&u->thread_mq);
pa_smoother_set_time_offset(u->smoother, pa_rtclock_usec()); pa_smoother_set_time_offset(u->smoother, pa_rtclock_now());
for (;;) { for (;;) {
int ret; int ret;
@ -294,7 +295,7 @@ static void thread_func(void *userdata) {
else else
usec = 0; usec = 0;
pa_smoother_put(u->smoother, pa_rtclock_usec(), usec); pa_smoother_put(u->smoother, pa_rtclock_now(), usec);
} }
/* Hmm, nothing to do. Let's sleep */ /* Hmm, nothing to do. Let's sleep */
@ -607,7 +608,7 @@ int pa__init(pa_module*m) {
pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq); pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
pa_sink_set_rtpoll(u->sink, u->rtpoll); pa_sink_set_rtpoll(u->sink, u->rtpoll);
if (!(u->client = pa_socket_client_new_string(u->core->mainloop, espeaker, ESD_DEFAULT_PORT))) { if (!(u->client = pa_socket_client_new_string(u->core->mainloop, TRUE, espeaker, ESD_DEFAULT_PORT))) {
pa_log("Failed to connect to server."); pa_log("Failed to connect to server.");
goto fail; goto fail;
} }

View file

@ -32,12 +32,14 @@
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/sink.h> #include <pulsecore/sink.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
@ -45,7 +47,6 @@
#include <pulsecore/thread.h> #include <pulsecore/thread.h>
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/rtpoll.h> #include <pulsecore/rtpoll.h>
#include <pulsecore/rtclock.h>
#include "module-null-sink-symdef.h" #include "module-null-sink-symdef.h"
@ -101,14 +102,14 @@ static int sink_process_msg(
case PA_SINK_MESSAGE_SET_STATE: case PA_SINK_MESSAGE_SET_STATE:
if (PA_PTR_TO_UINT(data) == PA_SINK_RUNNING) if (PA_PTR_TO_UINT(data) == PA_SINK_RUNNING)
u->timestamp = pa_rtclock_usec(); u->timestamp = pa_rtclock_now();
break; break;
case PA_SINK_MESSAGE_GET_LATENCY: { case PA_SINK_MESSAGE_GET_LATENCY: {
pa_usec_t now; pa_usec_t now;
now = pa_rtclock_usec(); now = pa_rtclock_now();
*((pa_usec_t*) data) = u->timestamp > now ? u->timestamp - now : 0ULL; *((pa_usec_t*) data) = u->timestamp > now ? u->timestamp - now : 0ULL;
return 0; return 0;
@ -209,7 +210,7 @@ static void thread_func(void *userdata) {
pa_thread_mq_install(&u->thread_mq); pa_thread_mq_install(&u->thread_mq);
u->timestamp = pa_rtclock_usec(); u->timestamp = pa_rtclock_now();
for (;;) { for (;;) {
int ret; int ret;
@ -218,7 +219,7 @@ static void thread_func(void *userdata) {
if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) { if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
pa_usec_t now; pa_usec_t now;
now = pa_rtclock_usec(); now = pa_rtclock_now();
if (u->sink->thread_info.rewind_requested) { if (u->sink->thread_info.rewind_requested) {
if (u->sink->thread_info.rewind_nbytes > 0) if (u->sink->thread_info.rewind_nbytes > 0)

View file

@ -34,19 +34,20 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/poll.h> #include <sys/poll.h>
#include <pulse/xmalloc.h> #include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/source.h> #include <pulsecore/source.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/thread.h> #include <pulsecore/thread.h>
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/rtpoll.h> #include <pulsecore/rtpoll.h>
#include <pulsecore/rtclock.h>
#include "module-sine-source-symdef.h" #include "module-sine-source-symdef.h"
@ -101,14 +102,14 @@ static int source_process_msg(
case PA_SOURCE_MESSAGE_SET_STATE: case PA_SOURCE_MESSAGE_SET_STATE:
if (PA_PTR_TO_UINT(data) == PA_SOURCE_RUNNING) if (PA_PTR_TO_UINT(data) == PA_SOURCE_RUNNING)
u->timestamp = pa_rtclock_usec(); u->timestamp = pa_rtclock_now();
break; break;
case PA_SOURCE_MESSAGE_GET_LATENCY: { case PA_SOURCE_MESSAGE_GET_LATENCY: {
pa_usec_t now, left_to_fill; pa_usec_t now, left_to_fill;
now = pa_rtclock_usec(); now = pa_rtclock_now();
left_to_fill = u->timestamp > now ? u->timestamp - now : 0ULL; left_to_fill = u->timestamp > now ? u->timestamp - now : 0ULL;
*((pa_usec_t*) data) = u->block_usec > left_to_fill ? u->block_usec - left_to_fill : 0ULL; *((pa_usec_t*) data) = u->block_usec > left_to_fill ? u->block_usec - left_to_fill : 0ULL;
@ -167,7 +168,7 @@ static void thread_func(void *userdata) {
pa_thread_mq_install(&u->thread_mq); pa_thread_mq_install(&u->thread_mq);
u->timestamp = pa_rtclock_usec(); u->timestamp = pa_rtclock_now();
for (;;) { for (;;) {
int ret; int ret;
@ -175,7 +176,7 @@ static void thread_func(void *userdata) {
if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) { if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
pa_usec_t now; pa_usec_t now;
now = pa_rtclock_usec(); now = pa_rtclock_now();
if (u->timestamp <= now) if (u->timestamp <= now)
process_render(u, now); process_render(u, now);

View file

@ -641,7 +641,7 @@ static void thread_func(void *userdata) {
* Since we cannot modify the size of the output buffer we fake it * Since we cannot modify the size of the output buffer we fake it
* by not filling it more than u->buffer_size. * by not filling it more than u->buffer_size.
*/ */
xtime0 = pa_rtclock_usec(); xtime0 = pa_rtclock_now();
buffered_bytes = get_playback_buffered_bytes(u); buffered_bytes = get_playback_buffered_bytes(u);
if (buffered_bytes >= (uint64_t)u->buffer_size) if (buffered_bytes >= (uint64_t)u->buffer_size)
break; break;

View file

@ -35,6 +35,7 @@
#include <pulse/volume.h> #include <pulse/volume.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/util.h> #include <pulse/util.h>
#include <pulse/rtclock.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
@ -63,7 +64,7 @@ PA_MODULE_USAGE(
"on_hotplug=<When new device becomes available, recheck streams?> " "on_hotplug=<When new device becomes available, recheck streams?> "
"on_rescue=<When device becomes unavailable, recheck streams?>"); "on_rescue=<When device becomes unavailable, recheck streams?>");
#define SAVE_INTERVAL 10 #define SAVE_INTERVAL (10 * PA_USEC_PER_SEC)
#define IDENTIFICATION_PROPERTY "module-stream-restore.id" #define IDENTIFICATION_PROPERTY "module-stream-restore.id"
static const char* const valid_modargs[] = { static const char* const valid_modargs[] = {
@ -121,12 +122,11 @@ enum {
SUBCOMMAND_EVENT SUBCOMMAND_EVENT
}; };
static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) { static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *t, void *userdata) {
struct userdata *u = userdata; struct userdata *u = userdata;
pa_assert(a); pa_assert(a);
pa_assert(e); pa_assert(e);
pa_assert(tv);
pa_assert(u); pa_assert(u);
pa_assert(e == u->save_time_event); pa_assert(e == u->save_time_event);
@ -220,7 +220,6 @@ fail:
} }
static void trigger_save(struct userdata *u) { static void trigger_save(struct userdata *u) {
struct timeval tv;
pa_native_connection *c; pa_native_connection *c;
uint32_t idx; uint32_t idx;
@ -240,9 +239,7 @@ static void trigger_save(struct userdata *u) {
if (u->save_time_event) if (u->save_time_event)
return; return;
pa_gettimeofday(&tv); u->save_time_event = pa_core_rttime_new(u->core, pa_rtclock_now() + SAVE_INTERVAL, save_time_callback, u);
tv.tv_sec += SAVE_INTERVAL;
u->save_time_event = u->core->mainloop->time_new(u->core->mainloop, &tv, save_time_callback, u);
} }
static pa_bool_t entries_equal(const struct entry *a, const struct entry *b) { static pa_bool_t entries_equal(const struct entry *a, const struct entry *b) {

View file

@ -25,6 +25,7 @@
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/rtclock.h>
#include <pulsecore/core.h> #include <pulsecore/core.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
@ -75,11 +76,11 @@ struct device_info {
struct userdata *userdata; struct userdata *userdata;
pa_sink *sink; pa_sink *sink;
pa_source *source; pa_source *source;
struct timeval last_use; pa_usec_t last_use;
pa_time_event *time_event; pa_time_event *time_event;
}; };
static void timeout_cb(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) { static void timeout_cb(pa_mainloop_api*a, pa_time_event* e, const struct timeval *t, void *userdata) {
struct device_info *d = userdata; struct device_info *d = userdata;
pa_assert(d); pa_assert(d);
@ -98,22 +99,20 @@ static void timeout_cb(pa_mainloop_api*a, pa_time_event* e, const struct timeval
} }
static void restart(struct device_info *d) { static void restart(struct device_info *d) {
struct timeval tv; pa_usec_t now;
const char *s; const char *s;
uint32_t timeout; uint32_t timeout;
pa_assert(d); pa_assert(d);
pa_assert(d->sink || d->source); pa_assert(d->sink || d->source);
pa_gettimeofday(&tv); d->last_use = now = pa_rtclock_now();
d->last_use = tv;
s = pa_proplist_gets(d->sink ? d->sink->proplist : d->source->proplist, "module-suspend-on-idle.timeout"); s = pa_proplist_gets(d->sink ? d->sink->proplist : d->source->proplist, "module-suspend-on-idle.timeout");
if (!s || pa_atou(s, &timeout) < 0) if (!s || pa_atou(s, &timeout) < 0)
timeout = d->userdata->timeout; timeout = d->userdata->timeout;
pa_timeval_add(&tv, timeout * PA_USEC_PER_SEC); pa_core_rttime_restart(d->userdata->core, d->time_event, now + timeout * PA_USEC_PER_SEC);
d->userdata->core->mainloop->time_restart(d->time_event, &tv);
if (d->sink) if (d->sink)
pa_log_debug("Sink %s becomes idle, timeout in %u seconds.", d->sink->name, timeout); pa_log_debug("Sink %s becomes idle, timeout in %u seconds.", d->sink->name, timeout);
@ -338,7 +337,7 @@ static pa_hook_result_t device_new_hook_cb(pa_core *c, pa_object *o, struct user
d->userdata = u; d->userdata = u;
d->source = source ? pa_source_ref(source) : NULL; d->source = source ? pa_source_ref(source) : NULL;
d->sink = sink ? pa_sink_ref(sink) : NULL; d->sink = sink ? pa_sink_ref(sink) : NULL;
d->time_event = c->mainloop->time_new(c->mainloop, NULL, timeout_cb, d); d->time_event = pa_core_rttime_new(c, PA_USEC_INVALID, timeout_cb, d);
pa_hashmap_put(u->device_infos, o, d); pa_hashmap_put(u->device_infos, o, d);
if ((d->sink && pa_sink_check_suspend(d->sink) <= 0) || if ((d->sink && pa_sink_check_suspend(d->sink) <= 0) ||

View file

@ -31,6 +31,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/util.h> #include <pulse/util.h>
#include <pulse/version.h> #include <pulse/version.h>
@ -50,7 +51,7 @@
#include <pulsecore/time-smoother.h> #include <pulsecore/time-smoother.h>
#include <pulsecore/thread.h> #include <pulsecore/thread.h>
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/rtclock.h> #include <pulsecore/core-rtclock.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/proplist-util.h> #include <pulsecore/proplist-util.h>
#include <pulsecore/auth-cookie.h> #include <pulsecore/auth-cookie.h>
@ -112,7 +113,7 @@ static const char* const valid_modargs[] = {
#define DEFAULT_TIMEOUT 5 #define DEFAULT_TIMEOUT 5
#define LATENCY_INTERVAL 10 #define LATENCY_INTERVAL (10*PA_USEC_PER_SEC)
#define MIN_NETWORK_LATENCY_USEC (8*PA_USEC_PER_MSEC) #define MIN_NETWORK_LATENCY_USEC (8*PA_USEC_PER_MSEC)
@ -395,7 +396,7 @@ static void check_smoother_status(struct userdata *u, pa_bool_t past) {
pa_assert(u); pa_assert(u);
x = pa_rtclock_usec(); x = pa_rtclock_now();
/* Correct by the time the requested issued needs to travel to the /* Correct by the time the requested issued needs to travel to the
* other side. This is a valid thread-safe access, because the * other side. This is a valid thread-safe access, because the
@ -500,7 +501,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
pa_usec_t yl, yr, *usec = data; pa_usec_t yl, yr, *usec = data;
yl = pa_bytes_to_usec((uint64_t) u->counter, &u->sink->sample_spec); yl = pa_bytes_to_usec((uint64_t) u->counter, &u->sink->sample_spec);
yr = pa_smoother_get(u->smoother, pa_rtclock_usec()); yr = pa_smoother_get(u->smoother, pa_rtclock_now());
*usec = yl > yr ? yl - yr : 0; *usec = yl > yr ? yl - yr : 0;
return 0; return 0;
@ -533,7 +534,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
else else
y = 0; y = 0;
pa_smoother_put(u->smoother, pa_rtclock_usec(), y); pa_smoother_put(u->smoother, pa_rtclock_now(), y);
/* We can access this freely here, since the main thread is waiting for us */ /* We can access this freely here, since the main thread is waiting for us */
u->thread_transport_usec = u->transport_usec; u->thread_transport_usec = u->transport_usec;
@ -607,7 +608,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
pa_usec_t yr, yl, *usec = data; pa_usec_t yr, yl, *usec = data;
yl = pa_bytes_to_usec((uint64_t) u->counter, &PA_SOURCE(o)->sample_spec); yl = pa_bytes_to_usec((uint64_t) u->counter, &PA_SOURCE(o)->sample_spec);
yr = pa_smoother_get(u->smoother, pa_rtclock_usec()); yr = pa_smoother_get(u->smoother, pa_rtclock_now());
*usec = yr > yl ? yr - yl : 0; *usec = yr > yl ? yr - yl : 0;
return 0; return 0;
@ -633,7 +634,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
y = pa_bytes_to_usec((uint64_t) u->counter, &u->source->sample_spec); y = pa_bytes_to_usec((uint64_t) u->counter, &u->source->sample_spec);
y += (pa_usec_t) offset; y += (pa_usec_t) offset;
pa_smoother_put(u->smoother, pa_rtclock_usec(), y); pa_smoother_put(u->smoother, pa_rtclock_now(), y);
/* We can access this freely here, since the main thread is waiting for us */ /* We can access this freely here, since the main thread is waiting for us */
u->thread_transport_usec = u->transport_usec; u->thread_transport_usec = u->transport_usec;
@ -877,9 +878,8 @@ static void request_latency(struct userdata *u) {
} }
/* Called from main context */ /* Called from main context */
static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, const struct timeval *tv, void *userdata) { static void timeout_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
struct userdata *u = userdata; struct userdata *u = userdata;
struct timeval ntv;
pa_assert(m); pa_assert(m);
pa_assert(e); pa_assert(e);
@ -887,9 +887,7 @@ static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, const struct
request_latency(u); request_latency(u);
pa_gettimeofday(&ntv); pa_core_rttime_restart(u->core, e, pa_rtclock_now() + LATENCY_INTERVAL);
ntv.tv_sec += LATENCY_INTERVAL;
m->time_restart(e, &ntv);
} }
/* Called from main context */ /* Called from main context */
@ -1356,7 +1354,6 @@ static void start_subscribe(struct userdata *u) {
/* Called from main context */ /* Called from main context */
static void create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { static void create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
struct userdata *u = userdata; struct userdata *u = userdata;
struct timeval ntv;
#ifdef TUNNEL_SINK #ifdef TUNNEL_SINK
uint32_t bytes; uint32_t bytes;
#endif #endif
@ -1438,9 +1435,7 @@ static void create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t
request_info(u); request_info(u);
pa_assert(!u->time_event); pa_assert(!u->time_event);
pa_gettimeofday(&ntv); u->time_event = pa_core_rttime_new(u->core, pa_rtclock_now() + LATENCY_INTERVAL, timeout_callback, u);
ntv.tv_sec += LATENCY_INTERVAL;
u->time_event = u->core->mainloop->time_new(u->core->mainloop, &ntv, timeout_callback, u);
request_latency(u); request_latency(u);
@ -1705,7 +1700,7 @@ static void on_connection(pa_socket_client *sc, pa_iochannel *io, void *userdata
} }
u->pstream = pa_pstream_new(u->core->mainloop, io, u->core->mempool); u->pstream = pa_pstream_new(u->core->mainloop, io, u->core->mempool);
u->pdispatch = pa_pdispatch_new(u->core->mainloop, command_table, PA_COMMAND_MAX); u->pdispatch = pa_pdispatch_new(u->core->mainloop, TRUE, command_table, PA_COMMAND_MAX);
pa_pstream_set_die_callback(u->pstream, pstream_die_callback, u); pa_pstream_set_die_callback(u->pstream, pstream_die_callback, u);
pa_pstream_set_recieve_packet_callback(u->pstream, pstream_packet_callback, u); pa_pstream_set_recieve_packet_callback(u->pstream, pstream_packet_callback, u);
@ -1824,7 +1819,7 @@ int pa__init(pa_module*m) {
TRUE, TRUE,
TRUE, TRUE,
10, 10,
pa_rtclock_usec(), pa_rtclock_now(),
FALSE); FALSE);
u->ctag = 1; u->ctag = 1;
u->device_index = u->channel = PA_INVALID_INDEX; u->device_index = u->channel = PA_INVALID_INDEX;
@ -1852,7 +1847,7 @@ int pa__init(pa_module*m) {
goto fail; goto fail;
} }
if (!(u->client = pa_socket_client_new_string(m->core->mainloop, u->server_name, PA_NATIVE_DEFAULT_PORT))) { if (!(u->client = pa_socket_client_new_string(m->core->mainloop, TRUE, u->server_name, PA_NATIVE_DEFAULT_PORT))) {
pa_log("Failed to connect to server '%s'", u->server_name); pa_log("Failed to connect to server '%s'", u->server_name);
goto fail; goto fail;
} }

View file

@ -256,7 +256,7 @@ static void poll_cb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *t
pa_gettimeofday(&ntv); pa_gettimeofday(&ntv);
pa_timeval_add(&ntv, u->poll_timeout); pa_timeval_add(&ntv, u->poll_timeout);
a->time_restart(e, &ntv); a->rtclock_time_restart(e, &ntv);
} }
static void defer_cb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) { static void defer_cb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) {
@ -549,7 +549,7 @@ int pa__init(pa_core *c, pa_module*m) {
pa_gettimeofday(&tv); pa_gettimeofday(&tv);
pa_timeval_add(&tv, u->poll_timeout); pa_timeval_add(&tv, u->poll_timeout);
u->event = c->mainloop->time_new(c->mainloop, &tv, poll_cb, u); u->event = c->mainloop->rtclock_time_new(c->mainloop, &tv, poll_cb, u);
assert(u->event); assert(u->event);
u->defer = c->mainloop->defer_new(c->mainloop, defer_cb, u); u->defer = c->mainloop->defer_new(c->mainloop, defer_cb, u);

View file

@ -42,13 +42,15 @@
#include <linux/sockios.h> #include <linux/sockios.h>
#endif #endif
#include <pulse/xmalloc.h> #include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/iochannel.h> #include <pulsecore/iochannel.h>
#include <pulsecore/sink.h> #include <pulsecore/sink.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
@ -57,7 +59,6 @@
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/thread.h> #include <pulsecore/thread.h>
#include <pulsecore/time-smoother.h> #include <pulsecore/time-smoother.h>
#include <pulsecore/rtclock.h>
#include <pulsecore/socket-util.h> #include <pulsecore/socket-util.h>
#include "module-raop-sink-symdef.h" #include "module-raop-sink-symdef.h"
@ -181,7 +182,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
case PA_SINK_SUSPENDED: case PA_SINK_SUSPENDED:
pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state)); pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state));
pa_smoother_pause(u->smoother, pa_rtclock_usec()); pa_smoother_pause(u->smoother, pa_rtclock_now());
/* Issue a FLUSH if we are connected */ /* Issue a FLUSH if we are connected */
if (u->fd >= 0) { if (u->fd >= 0) {
@ -193,7 +194,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
case PA_SINK_RUNNING: case PA_SINK_RUNNING:
if (u->sink->thread_info.state == PA_SINK_SUSPENDED) { if (u->sink->thread_info.state == PA_SINK_SUSPENDED) {
pa_smoother_resume(u->smoother, pa_rtclock_usec(), TRUE); pa_smoother_resume(u->smoother, pa_rtclock_now(), TRUE);
/* The connection can be closed when idle, so check to /* The connection can be closed when idle, so check to
see if we need to reestablish it */ see if we need to reestablish it */
@ -216,7 +217,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
case PA_SINK_MESSAGE_GET_LATENCY: { case PA_SINK_MESSAGE_GET_LATENCY: {
pa_usec_t w, r; pa_usec_t w, r;
r = pa_smoother_get(u->smoother, pa_rtclock_usec()); r = pa_smoother_get(u->smoother, pa_rtclock_now());
w = pa_bytes_to_usec((u->offset - u->encoding_overhead + (u->encoded_memchunk.length / u->encoding_ratio)), &u->sink->sample_spec); w = pa_bytes_to_usec((u->offset - u->encoding_overhead + (u->encoded_memchunk.length / u->encoding_ratio)), &u->sink->sample_spec);
*((pa_usec_t*) data) = w > r ? w - r : 0; *((pa_usec_t*) data) = w > r ? w - r : 0;
@ -324,7 +325,7 @@ static void thread_func(void *userdata) {
pa_thread_mq_install(&u->thread_mq); pa_thread_mq_install(&u->thread_mq);
pa_smoother_set_time_offset(u->smoother, pa_rtclock_usec()); pa_smoother_set_time_offset(u->smoother, pa_rtclock_now());
/* Create a chunk of memory that is our encoded silence sample. */ /* Create a chunk of memory that is our encoded silence sample. */
pa_memchunk_reset(&silence); pa_memchunk_reset(&silence);
@ -464,7 +465,7 @@ static void thread_func(void *userdata) {
else else
usec = 0; usec = 0;
pa_smoother_put(u->smoother, pa_rtclock_usec(), usec); pa_smoother_put(u->smoother, pa_rtclock_now(), usec);
} }
/* Hmm, nothing to do. Let's sleep */ /* Hmm, nothing to do. Let's sleep */

View file

@ -331,7 +331,7 @@ static void rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist* he
uint32_t port = pa_rtsp_serverport(c->rtsp); uint32_t port = pa_rtsp_serverport(c->rtsp);
pa_log_debug("RAOP: RECORDED"); pa_log_debug("RAOP: RECORDED");
if (!(c->sc = pa_socket_client_new_string(c->core->mainloop, c->host, port))) { if (!(c->sc = pa_socket_client_new_string(c->core->mainloop, TRUE, c->host, port))) {
pa_log("failed to connect to server '%s:%d'", c->host, port); pa_log("failed to connect to server '%s:%d'", c->host, port);
return; return;
} }

View file

@ -33,6 +33,7 @@
#include <unistd.h> #include <unistd.h>
#include <poll.h> #include <poll.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
@ -43,13 +44,13 @@
#include <pulsecore/sink-input.h> #include <pulsecore/sink-input.h>
#include <pulsecore/memblockq.h> #include <pulsecore/memblockq.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
#include <pulsecore/sample-util.h> #include <pulsecore/sample-util.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/atomic.h> #include <pulsecore/atomic.h>
#include <pulsecore/rtclock.h>
#include <pulsecore/atomic.h> #include <pulsecore/atomic.h>
#include <pulsecore/time-smoother.h> #include <pulsecore/time-smoother.h>
#include <pulsecore/socket-util.h> #include <pulsecore/socket-util.h>
@ -112,6 +113,7 @@ struct session {
struct userdata { struct userdata {
pa_module *module; pa_module *module;
pa_core *core;
pa_sap_context sap_context; pa_sap_context sap_context;
pa_io_event* sap_event; pa_io_event* sap_event;
@ -193,7 +195,7 @@ static void sink_input_suspend_within_thread(pa_sink_input* i, pa_bool_t b) {
pa_assert_se(s = i->userdata); pa_assert_se(s = i->userdata);
if (b) { if (b) {
pa_smoother_pause(s->smoother, pa_rtclock_usec()); pa_smoother_pause(s->smoother, pa_rtclock_now());
pa_memblockq_flush_read(s->memblockq); pa_memblockq_flush_read(s->memblockq);
} else } else
s->first_packet = FALSE; s->first_packet = FALSE;
@ -621,15 +623,13 @@ static void sap_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event
} }
} }
static void check_death_event_cb(pa_mainloop_api *m, pa_time_event *t, const struct timeval *ptv, void *userdata) { static void check_death_event_cb(pa_mainloop_api *m, pa_time_event *t, const struct timeval *tv, void *userdata) {
struct session *s, *n; struct session *s, *n;
struct userdata *u = userdata; struct userdata *u = userdata;
struct timeval now; struct timeval now;
struct timeval tv;
pa_assert(m); pa_assert(m);
pa_assert(t); pa_assert(t);
pa_assert(ptv);
pa_assert(u); pa_assert(u);
pa_rtclock_get(&now); pa_rtclock_get(&now);
@ -647,9 +647,7 @@ static void check_death_event_cb(pa_mainloop_api *m, pa_time_event *t, const str
} }
/* Restart timer */ /* Restart timer */
pa_gettimeofday(&tv); pa_core_rttime_restart(u->module->core, t, pa_rtclock_now() + DEATH_TIMEOUT * PA_USEC_PER_SEC);
pa_timeval_add(&tv, DEATH_TIMEOUT*PA_USEC_PER_SEC);
m->time_restart(t, &tv);
} }
int pa__init(pa_module*m) { int pa__init(pa_module*m) {
@ -663,7 +661,6 @@ int pa__init(pa_module*m) {
socklen_t salen; socklen_t salen;
const char *sap_address; const char *sap_address;
int fd = -1; int fd = -1;
struct timeval tv;
pa_assert(m); pa_assert(m);
@ -696,6 +693,7 @@ int pa__init(pa_module*m) {
m->userdata = u = pa_xnew(struct userdata, 1); m->userdata = u = pa_xnew(struct userdata, 1);
u->module = m; u->module = m;
u->core = m->core;
u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL)); u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
u->sap_event = m->core->mainloop->io_new(m->core->mainloop, fd, PA_IO_EVENT_INPUT, sap_event_cb, u); u->sap_event = m->core->mainloop->io_new(m->core->mainloop, fd, PA_IO_EVENT_INPUT, sap_event_cb, u);
@ -705,9 +703,7 @@ int pa__init(pa_module*m) {
u->n_sessions = 0; u->n_sessions = 0;
u->by_origin = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); u->by_origin = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
pa_gettimeofday(&tv); u->check_death_event = pa_core_rttime_new(m->core, pa_rtclock_now() + DEATH_TIMEOUT * PA_USEC_PER_SEC, check_death_event_cb, u);
pa_timeval_add(&tv, DEATH_TIMEOUT * PA_USEC_PER_SEC);
u->check_death_event = m->core->mainloop->time_new(m->core->mainloop, &tv, check_death_event_cb, u);
pa_modargs_free(ma); pa_modargs_free(ma);

View file

@ -31,6 +31,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/util.h> #include <pulse/util.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
@ -77,7 +78,7 @@ PA_MODULE_USAGE(
#define DEFAULT_DESTINATION "224.0.0.56" #define DEFAULT_DESTINATION "224.0.0.56"
#define MEMBLOCKQ_MAXLENGTH (1024*170) #define MEMBLOCKQ_MAXLENGTH (1024*170)
#define DEFAULT_MTU 1280 #define DEFAULT_MTU 1280
#define SAP_INTERVAL 5 #define SAP_INTERVAL (5*PA_USEC_PER_SEC)
static const char* const valid_modargs[] = { static const char* const valid_modargs[] = {
"source", "source",
@ -151,18 +152,14 @@ static void source_output_kill(pa_source_output* o) {
static void sap_event_cb(pa_mainloop_api *m, pa_time_event *t, const struct timeval *tv, void *userdata) { static void sap_event_cb(pa_mainloop_api *m, pa_time_event *t, const struct timeval *tv, void *userdata) {
struct userdata *u = userdata; struct userdata *u = userdata;
struct timeval next;
pa_assert(m); pa_assert(m);
pa_assert(t); pa_assert(t);
pa_assert(tv);
pa_assert(u); pa_assert(u);
pa_sap_send(&u->sap_context, 0); pa_sap_send(&u->sap_context, 0);
pa_gettimeofday(&next); pa_core_rttime_restart(u->module->core, t, pa_rtclock_now() + SAP_INTERVAL);
pa_timeval_add(&next, SAP_INTERVAL * PA_USEC_PER_SEC);
m->time_restart(t, &next);
} }
int pa__init(pa_module*m) { int pa__init(pa_module*m) {
@ -186,7 +183,6 @@ int pa__init(pa_module*m) {
char *p; char *p;
int r, j; int r, j;
socklen_t k; socklen_t k;
struct timeval tv;
char hn[128], *n; char hn[128], *n;
pa_bool_t loop = FALSE; pa_bool_t loop = FALSE;
pa_source_output_new_data data; pa_source_output_new_data data;
@ -395,9 +391,7 @@ int pa__init(pa_module*m) {
pa_sap_send(&u->sap_context, 0); pa_sap_send(&u->sap_context, 0);
pa_gettimeofday(&tv); u->sap_event = pa_core_rttime_new(m->core, pa_rtclock_now() + SAP_INTERVAL, sap_event_cb, u);
pa_timeval_add(&tv, SAP_INTERVAL * PA_USEC_PER_SEC);
u->sap_event = m->core->mainloop->time_new(m->core->mainloop, &tv, sap_event_cb, u);
pa_source_output_put(u->source_output); pa_source_output_put(u->source_output);

View file

@ -333,7 +333,7 @@ int pa_rtsp_connect(pa_rtsp_client *c) {
pa_xfree(c->session); pa_xfree(c->session);
c->session = NULL; c->session = NULL;
if (!(c->sc = pa_socket_client_new_string(c->mainloop, c->hostname, c->port))) { if (!(c->sc = pa_socket_client_new_string(c->mainloop, TRUE, c->hostname, c->port))) {
pa_log("failed to connect to server '%s:%d'", c->hostname, c->port); pa_log("failed to connect to server '%s:%d'", c->hostname, c->port);
return -1; return -1;
} }

View file

@ -54,6 +54,8 @@
#include <pulse/utf8.h> #include <pulse/utf8.h>
#include <pulse/util.h> #include <pulse/util.h>
#include <pulse/i18n.h> #include <pulse/i18n.h>
#include <pulse/mainloop.h>
#include <pulse/timeval.h>
#include <pulsecore/winsock.h> #include <pulsecore/winsock.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
@ -64,6 +66,7 @@
#include <pulsecore/dynarray.h> #include <pulsecore/dynarray.h>
#include <pulsecore/socket-client.h> #include <pulsecore/socket-client.h>
#include <pulsecore/pstream-util.h> #include <pulsecore/pstream-util.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/socket-util.h> #include <pulsecore/socket-util.h>
@ -540,7 +543,7 @@ static void setup_context(pa_context *c, pa_iochannel *io) {
pa_pstream_set_recieve_memblock_callback(c->pstream, pstream_memblock_callback, c); pa_pstream_set_recieve_memblock_callback(c->pstream, pstream_memblock_callback, c);
pa_assert(!c->pdispatch); 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) if (!c->conf->cookie_valid)
pa_log_info(_("No cookie loaded. Attempting to connect without.")); pa_log_info(_("No cookie loaded. Attempting to connect without."));
@ -757,7 +760,7 @@ static void track_pulseaudio_on_dbus(pa_context *c, DBusBusType type, pa_dbus_wr
pa_assert(conn); pa_assert(conn);
dbus_error_init(&error); dbus_error_init(&error);
if (!(*conn = pa_dbus_wrap_connection_new(c->mainloop, type, &error)) || dbus_error_is_set(&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); pa_log_warn("Unable to contact DBUS: %s: %s", error.name, error.message);
goto finish; goto finish;
} }
@ -827,7 +830,7 @@ static int try_next_connection(pa_context *c) {
pa_xfree(c->server); pa_xfree(c->server);
c->server = pa_xstrdup(u); 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; continue;
c->is_local = !!pa_socket_client_is_local(c->client); c->is_local = !!pa_socket_client_is_local(c->client);
@ -1443,3 +1446,31 @@ finish:
if (pl) if (pl)
pa_proplist_free(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);
}
}

View file

@ -260,6 +260,14 @@ pa_operation *pa_context_proplist_remove(pa_context *c, const char *const keys[]
* introspection functions, such as pa_context_get_client_info(). \since 0.9.11 */ * introspection functions, such as pa_context_get_client_info(). \since 0.9.11 */
uint32_t pa_context_get_index(pa_context *s); uint32_t pa_context_get_index(pa_context *s);
/** Create a new timer event source for the specified time (wrapper
for mainloop->time_new). \since 0.9.16 */
pa_time_event* pa_context_rttime_new(pa_context *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata);
/** Restart a running or expired timer event source (wrapper
for mainloop->time_restart). \since 0.9.16 */
void pa_context_rttime_restart(pa_context *c, pa_time_event *e, pa_usec_t usec);
PA_C_DECL_END PA_C_DECL_END
#endif #endif

View file

@ -89,6 +89,7 @@ struct pa_context {
pa_bool_t server_specified:1; pa_bool_t server_specified:1;
pa_bool_t no_fail:1; pa_bool_t no_fail:1;
pa_bool_t do_autospawn:1; pa_bool_t do_autospawn:1;
pa_bool_t use_rtclock:1;
pa_spawn_api spawn_api; pa_spawn_api spawn_api;
pa_strlist *server_list; pa_strlist *server_list;

View file

@ -27,6 +27,7 @@
#include <time.h> #include <time.h>
#include <pulse/cdecl.h> #include <pulse/cdecl.h>
#include <pulse/sample.h>
#include <pulse/version.h> #include <pulse/version.h>
/** \file /** \file

View file

@ -42,10 +42,12 @@
#include <pulsecore/pipe.h> #include <pulsecore/pipe.h>
#endif #endif
#include <pulse/i18n.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulse/i18n.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/llist.h> #include <pulsecore/llist.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
@ -75,7 +77,7 @@ struct pa_time_event {
pa_bool_t dead:1; pa_bool_t dead:1;
pa_bool_t enabled:1; pa_bool_t enabled:1;
struct timeval timeval; pa_usec_t time;
pa_time_event_cb_t callback; pa_time_event_cb_t callback;
void *userdata; void *userdata;
@ -317,6 +319,23 @@ static void mainloop_defer_set_destroy(pa_defer_event *e, pa_defer_event_destroy
} }
/* Time events */ /* Time events */
static pa_usec_t timeval_load(const struct timeval *tv) {
pa_bool_t is_rtclock;
struct timeval ttv;
if (!tv)
return PA_USEC_INVALID;
ttv = *tv;
is_rtclock = !!(ttv.tv_usec & PA_TIMEVAL_RTCLOCK);
ttv.tv_usec &= ~PA_TIMEVAL_RTCLOCK;
if (!is_rtclock)
pa_rtclock_from_wallclock(&ttv);
return pa_timeval_load(&ttv);
}
static pa_time_event* mainloop_time_new( static pa_time_event* mainloop_time_new(
pa_mainloop_api*a, pa_mainloop_api*a,
const struct timeval *tv, const struct timeval *tv,
@ -325,11 +344,14 @@ static pa_time_event* mainloop_time_new(
pa_mainloop *m; pa_mainloop *m;
pa_time_event *e; pa_time_event *e;
pa_usec_t t;
pa_assert(a); pa_assert(a);
pa_assert(a->userdata); pa_assert(a->userdata);
pa_assert(callback); pa_assert(callback);
t = timeval_load(tv);
m = a->userdata; m = a->userdata;
pa_assert(a == &m->api); pa_assert(a == &m->api);
@ -337,15 +359,15 @@ static pa_time_event* mainloop_time_new(
e->mainloop = m; e->mainloop = m;
e->dead = FALSE; e->dead = FALSE;
if ((e->enabled = !!tv)) { if ((e->enabled = (t != PA_USEC_INVALID))) {
e->timeval = *tv; e->time = t;
m->n_enabled_time_events++; m->n_enabled_time_events++;
if (m->cached_next_time_event) { if (m->cached_next_time_event) {
pa_assert(m->cached_next_time_event->enabled); pa_assert(m->cached_next_time_event->enabled);
if (pa_timeval_cmp(tv, &m->cached_next_time_event->timeval) < 0) if (t < m->cached_next_time_event->time)
m->cached_next_time_event = e; m->cached_next_time_event = e;
} }
} }
@ -363,24 +385,30 @@ static pa_time_event* mainloop_time_new(
} }
static void mainloop_time_restart(pa_time_event *e, const struct timeval *tv) { static void mainloop_time_restart(pa_time_event *e, const struct timeval *tv) {
pa_bool_t valid;
pa_usec_t t;
pa_assert(e); pa_assert(e);
pa_assert(!e->dead); pa_assert(!e->dead);
if (e->enabled && !tv) { t = timeval_load(tv);
valid = (t != PA_USEC_INVALID);
if (e->enabled && !valid) {
pa_assert(e->mainloop->n_enabled_time_events > 0); pa_assert(e->mainloop->n_enabled_time_events > 0);
e->mainloop->n_enabled_time_events--; e->mainloop->n_enabled_time_events--;
} else if (!e->enabled && tv) } else if (!e->enabled && valid)
e->mainloop->n_enabled_time_events++; e->mainloop->n_enabled_time_events++;
if ((e->enabled = !!tv)) { if ((e->enabled = valid)) {
e->timeval = *tv; e->time = t;
pa_mainloop_wakeup(e->mainloop); pa_mainloop_wakeup(e->mainloop);
} }
if (e->mainloop->cached_next_time_event && e->enabled) { if (e->mainloop->cached_next_time_event && e->enabled) {
pa_assert(e->mainloop->cached_next_time_event->enabled); pa_assert(e->mainloop->cached_next_time_event->enabled);
if (pa_timeval_cmp(tv, &e->mainloop->cached_next_time_event->timeval) < 0) if (t < e->mainloop->cached_next_time_event->time)
e->mainloop->cached_next_time_event = e; e->mainloop->cached_next_time_event = e;
} else if (e->mainloop->cached_next_time_event == e) } else if (e->mainloop->cached_next_time_event == e)
e->mainloop->cached_next_time_event = NULL; e->mainloop->cached_next_time_event = NULL;
@ -721,11 +749,11 @@ static pa_time_event* find_next_time_event(pa_mainloop *m) {
if (t->dead || !t->enabled) if (t->dead || !t->enabled)
continue; continue;
if (!n || pa_timeval_cmp(&t->timeval, &n->timeval) < 0) { if (!n || t->time < n->time) {
n = t; n = t;
/* Shortcut for tv = { 0, 0 } */ /* Shortcut for time == 0 */
if (n->timeval.tv_sec <= 0) if (n->time == 0)
break; break;
} }
} }
@ -736,7 +764,6 @@ static pa_time_event* find_next_time_event(pa_mainloop *m) {
static int calc_next_timeout(pa_mainloop *m) { static int calc_next_timeout(pa_mainloop *m) {
pa_time_event *t; pa_time_event *t;
struct timeval now;
pa_usec_t usec; pa_usec_t usec;
if (!m->n_enabled_time_events) if (!m->n_enabled_time_events)
@ -745,41 +772,41 @@ static int calc_next_timeout(pa_mainloop *m) {
t = find_next_time_event(m); t = find_next_time_event(m);
pa_assert(t); pa_assert(t);
if (t->timeval.tv_sec <= 0) if (t->time == 0)
return 0; return 0;
pa_gettimeofday(&now); usec = t->time - pa_rtclock_now();
if (pa_timeval_cmp(&t->timeval, &now) <= 0) if (usec <= 0)
return 0; return 0;
usec = pa_timeval_diff(&t->timeval, &now); return (int) (usec / 1000); /* in milliseconds */
return (int) (usec / 1000);
} }
static int dispatch_timeout(pa_mainloop *m) { static int dispatch_timeout(pa_mainloop *m) {
pa_time_event *e; pa_time_event *e;
struct timeval now; pa_usec_t now;
int r = 0; int r = 0;
pa_assert(m); pa_assert(m);
if (m->n_enabled_time_events <= 0) if (m->n_enabled_time_events <= 0)
return 0; return 0;
pa_gettimeofday(&now); now = pa_rtclock_now();
for (e = m->time_events; e && !m->quit; e = e->next) { for (e = m->time_events; e && !m->quit; e = e->next) {
if (e->dead || !e->enabled) if (e->dead || !e->enabled)
continue; continue;
if (pa_timeval_cmp(&e->timeval, &now) <= 0) { if (e->time <= now) {
struct timeval tv;
pa_assert(e->callback); pa_assert(e->callback);
/* Disable time event */ /* Disable time event */
mainloop_time_restart(e, NULL); mainloop_time_restart(e, NULL);
e->callback(&m->api, e, &e->timeval, e->userdata); e->callback(&m->api, e, pa_timeval_rtstore(&tv, e->time, TRUE), e->userdata);
r++; r++;
} }

35
src/pulse/rtclock.c Normal file
View file

@ -0,0 +1,35 @@
/***
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.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
Lesser 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 <pulsecore/core-rtclock.h>
#include "rtclock.h"
#include "timeval.h"
pa_usec_t pa_rtclock_now(void) {
struct timeval tv;
return pa_timeval_load(pa_rtclock_get(&tv));
}

39
src/pulse/rtclock.h Normal file
View file

@ -0,0 +1,39 @@
#ifndef foortclockfoo
#define foortclockfoo
/***
This file is part of PulseAudio.
Copyright 2004-2009 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.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
Lesser 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 <pulse/cdecl.h>
#include <pulse/def.h>
#include <pulse/gccmacro.h>
/** \file
* Monotonic clock utility. */
PA_C_DECL_BEGIN
/** Return the current CLOCK_MONOTONIC time in usec. \since 0.9.16 */
pa_usec_t pa_rtclock_now(void);
PA_C_DECL_END
#endif

View file

@ -30,13 +30,14 @@
#include <pulse/def.h> #include <pulse/def.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/rtclock.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/pstream-util.h> #include <pulsecore/pstream-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/hashmap.h> #include <pulsecore/hashmap.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/rtclock.h> #include <pulsecore/core-rtclock.h>
#include "fork-detect.h" #include "fork-detect.h"
#include "internal.h" #include "internal.h"
@ -319,14 +320,10 @@ static void request_auto_timing_update(pa_stream *s, pa_bool_t force) {
} }
if (s->auto_timing_update_event) { if (s->auto_timing_update_event) {
struct timeval next;
if (force) if (force)
s->auto_timing_interval_usec = AUTO_TIMING_INTERVAL_START_USEC; s->auto_timing_interval_usec = AUTO_TIMING_INTERVAL_START_USEC;
pa_gettimeofday(&next); pa_context_rttime_restart(s->context, s->auto_timing_update_event, pa_rtclock_now() + s->auto_timing_interval_usec);
pa_timeval_add(&next, s->auto_timing_interval_usec);
s->mainloop->time_restart(s->auto_timing_update_event, &next);
s->auto_timing_interval_usec = PA_MIN(AUTO_TIMING_INTERVAL_END_USEC, s->auto_timing_interval_usec*2); s->auto_timing_interval_usec = PA_MIN(AUTO_TIMING_INTERVAL_END_USEC, s->auto_timing_interval_usec*2);
} }
@ -373,7 +370,7 @@ static void check_smoother_status(pa_stream *s, pa_bool_t aposteriori, pa_bool_t
if (!s->smoother) if (!s->smoother)
return; return;
x = pa_rtclock_usec(); x = pa_rtclock_now();
if (s->timing_info_valid) { if (s->timing_info_valid) {
if (aposteriori) if (aposteriori)
@ -800,7 +797,7 @@ static void invalidate_indexes(pa_stream *s, pa_bool_t r, pa_bool_t w) {
request_auto_timing_update(s, TRUE); request_auto_timing_update(s, TRUE);
} }
static void auto_timing_update_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *tv, void *userdata) { static void auto_timing_update_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
pa_stream *s = userdata; pa_stream *s = userdata;
pa_assert(s); pa_assert(s);
@ -822,12 +819,9 @@ static void create_stream_complete(pa_stream *s) {
s->write_callback(s, (size_t) s->requested_bytes, s->write_userdata); s->write_callback(s, (size_t) s->requested_bytes, s->write_userdata);
if (s->flags & PA_STREAM_AUTO_TIMING_UPDATE) { if (s->flags & PA_STREAM_AUTO_TIMING_UPDATE) {
struct timeval tv;
pa_gettimeofday(&tv);
s->auto_timing_interval_usec = AUTO_TIMING_INTERVAL_START_USEC; s->auto_timing_interval_usec = AUTO_TIMING_INTERVAL_START_USEC;
pa_timeval_add(&tv, s->auto_timing_interval_usec);
pa_assert(!s->auto_timing_update_event); pa_assert(!s->auto_timing_update_event);
s->auto_timing_update_event = s->mainloop->time_new(s->mainloop, &tv, &auto_timing_update_callback, s); s->auto_timing_update_event = pa_context_rttime_new(s->context, pa_rtclock_now() + s->auto_timing_interval_usec, &auto_timing_update_callback, s);
request_auto_timing_update(s, TRUE); request_auto_timing_update(s, TRUE);
} }
@ -1057,7 +1051,7 @@ static int create_stream(
if (flags & PA_STREAM_INTERPOLATE_TIMING) { if (flags & PA_STREAM_INTERPOLATE_TIMING) {
pa_usec_t x; pa_usec_t x;
x = pa_rtclock_usec(); x = pa_rtclock_now();
pa_assert(!s->smoother); pa_assert(!s->smoother);
s->smoother = pa_smoother_new( s->smoother = pa_smoother_new(
@ -1594,7 +1588,7 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command,
if (o->stream->smoother) { if (o->stream->smoother) {
pa_usec_t u, x; pa_usec_t u, x;
u = x = pa_rtclock_usec() - i->transport_usec; u = x = pa_rtclock_now() - i->transport_usec;
if (o->stream->direction == PA_STREAM_PLAYBACK && o->context->version >= 13) { if (o->stream->direction == PA_STREAM_PLAYBACK && o->context->version >= 13) {
pa_usec_t su; pa_usec_t su;
@ -2103,7 +2097,7 @@ int pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec) {
PA_CHECK_VALIDITY(s->context, s->direction != PA_STREAM_RECORD || !s->timing_info.write_index_corrupt, PA_ERR_NODATA); PA_CHECK_VALIDITY(s->context, s->direction != PA_STREAM_RECORD || !s->timing_info.write_index_corrupt, PA_ERR_NODATA);
if (s->smoother) if (s->smoother)
usec = pa_smoother_get(s->smoother, pa_rtclock_usec()); usec = pa_smoother_get(s->smoother, pa_rtclock_now());
else else
usec = calc_time(s, FALSE); usec = calc_time(s, FALSE);

View file

@ -51,6 +51,9 @@ PA_C_DECL_BEGIN
/** The number of nanoseconds in a microsecond */ /** The number of nanoseconds in a microsecond */
#define PA_NSEC_PER_USEC ((pa_usec_t) 1000ULL) #define PA_NSEC_PER_USEC ((pa_usec_t) 1000ULL)
/** Invalid time in usec */
#define PA_USEC_INVALID ((pa_usec_t) -1)
struct timeval; struct timeval;
/** Return the current timestamp, just like UNIX gettimeofday() */ /** Return the current timestamp, just like UNIX gettimeofday() */

View file

@ -23,6 +23,7 @@
#include <config.h> #include <config.h>
#endif #endif
#include <pulse/timeval.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
@ -116,14 +117,13 @@ struct AvahiTimeout {
void *userdata; void *userdata;
}; };
static void timeout_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) { static void timeout_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *t, void *userdata) {
AvahiTimeout *t = userdata; AvahiTimeout *to = userdata;
pa_assert(a); pa_assert(a);
pa_assert(e); pa_assert(e);
pa_assert(t);
t->callback(t, t->userdata); to->callback(to, to->userdata);
} }
static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata) { static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata) {
@ -145,6 +145,7 @@ static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv,
} }
static void timeout_update(AvahiTimeout *t, const struct timeval *tv) { static void timeout_update(AvahiTimeout *t, const struct timeval *tv) {
pa_assert(t); pa_assert(t);
if (t->time_event && tv) if (t->time_event && tv)

View file

@ -37,7 +37,7 @@
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include "rtclock.h" #include "core-rtclock.h"
pa_usec_t pa_rtclock_age(const struct timeval *tv) { pa_usec_t pa_rtclock_age(const struct timeval *tv) {
struct timeval now; struct timeval now;
@ -122,12 +122,6 @@ void pa_rtclock_hrtimer_enable(void) {
#endif #endif
} }
pa_usec_t pa_rtclock_usec(void) {
struct timeval tv;
return pa_timeval_load(pa_rtclock_get(&tv));
}
struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) { struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) {
#ifdef HAVE_CLOCK_GETTIME #ifdef HAVE_CLOCK_GETTIME
@ -156,3 +150,41 @@ pa_usec_t pa_timespec_load(const struct timespec *ts) {
(pa_usec_t) ts->tv_sec * PA_USEC_PER_SEC + (pa_usec_t) ts->tv_sec * PA_USEC_PER_SEC +
(pa_usec_t) ts->tv_nsec / PA_NSEC_PER_USEC; (pa_usec_t) ts->tv_nsec / PA_NSEC_PER_USEC;
} }
static struct timeval* wallclock_from_rtclock(struct timeval *tv) {
#ifdef HAVE_CLOCK_GETTIME
struct timeval wc_now, rt_now;
pa_gettimeofday(&wc_now);
pa_rtclock_get(&rt_now);
pa_assert(tv);
if (pa_timeval_cmp(&rt_now, tv) < 0)
pa_timeval_add(&wc_now, pa_timeval_diff(tv, &rt_now));
else
pa_timeval_sub(&wc_now, pa_timeval_diff(&rt_now, tv));
*tv = wc_now;
#endif
return tv;
}
struct timeval* pa_timeval_rtstore(struct timeval *tv, pa_usec_t v, pa_bool_t rtclock) {
pa_assert(tv);
if (v == PA_USEC_INVALID)
return NULL;
pa_timeval_store(tv, v);
if (rtclock)
tv->tv_usec |= PA_TIMEVAL_RTCLOCK;
else
wallclock_from_rtclock(tv);
return tv;
}

View file

@ -31,8 +31,6 @@ struct timeval;
struct timeval *pa_rtclock_get(struct timeval *ts); struct timeval *pa_rtclock_get(struct timeval *ts);
pa_usec_t pa_rtclock_usec(void);
pa_usec_t pa_rtclock_age(const struct timeval *tv); pa_usec_t pa_rtclock_age(const struct timeval *tv);
pa_bool_t pa_rtclock_hrtimer(void); pa_bool_t pa_rtclock_hrtimer(void);
void pa_rtclock_hrtimer_enable(void); void pa_rtclock_hrtimer_enable(void);
@ -40,8 +38,13 @@ void pa_rtclock_hrtimer_enable(void);
/* timer with a resolution better than this are considered high-resolution */ /* timer with a resolution better than this are considered high-resolution */
#define PA_HRTIMER_THRESHOLD_USEC 10 #define PA_HRTIMER_THRESHOLD_USEC 10
/* bit to set in tv.tv_usec to mark that the timeval is in monotonic time */
#define PA_TIMEVAL_RTCLOCK (1 << 30)
struct timeval* pa_rtclock_from_wallclock(struct timeval *tv); struct timeval* pa_rtclock_from_wallclock(struct timeval *tv);
pa_usec_t pa_timespec_load(const struct timespec *ts); pa_usec_t pa_timespec_load(const struct timespec *ts);
struct timeval* pa_timeval_rtstore(struct timeval *tv, pa_usec_t v, pa_bool_t rtclock);
#endif #endif

View file

@ -47,6 +47,7 @@
#include <pulse/util.h> #include <pulse/util.h>
#include <pulse/volume.h> #include <pulse/volume.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulse/rtclock.h>
#include <pulsecore/sink-input.h> #include <pulsecore/sink-input.h>
#include <pulsecore/sample-util.h> #include <pulsecore/sample-util.h>
@ -54,6 +55,7 @@
#include <pulsecore/core-subscribe.h> #include <pulsecore/core-subscribe.h>
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
#include <pulsecore/sound-file.h> #include <pulsecore/sound-file.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
@ -61,11 +63,10 @@
#include "core-scache.h" #include "core-scache.h"
#define UNLOAD_POLL_TIME 60 #define UNLOAD_POLL_TIME (60 * PA_USEC_PER_SEC)
static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, const struct timeval *tv, void *userdata) { static void timeout_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
pa_core *c = userdata; pa_core *c = userdata;
struct timeval ntv;
pa_assert(c); pa_assert(c);
pa_assert(c->mainloop == m); pa_assert(c->mainloop == m);
@ -73,9 +74,7 @@ static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, const struct t
pa_scache_unload_unused(c); pa_scache_unload_unused(c);
pa_gettimeofday(&ntv); pa_core_rttime_restart(c, e, pa_rtclock_now() + UNLOAD_POLL_TIME);
ntv.tv_sec += UNLOAD_POLL_TIME;
m->time_restart(e, &ntv);
} }
static void free_entry(pa_scache_entry *e) { static void free_entry(pa_scache_entry *e) {
@ -256,12 +255,8 @@ int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename,
pa_proplist_sets(e->proplist, PA_PROP_MEDIA_FILENAME, filename); pa_proplist_sets(e->proplist, PA_PROP_MEDIA_FILENAME, filename);
if (!c->scache_auto_unload_event) { if (!c->scache_auto_unload_event)
struct timeval ntv; c->scache_auto_unload_event = pa_core_rttime_new(c, pa_rtclock_now() + UNLOAD_POLL_TIME, timeout_callback, c);
pa_gettimeofday(&ntv);
ntv.tv_sec += UNLOAD_POLL_TIME;
c->scache_auto_unload_event = c->mainloop->time_new(c->mainloop, &ntv, timeout_callback, c);
}
if (idx) if (idx)
*idx = e->index; *idx = e->index;

View file

@ -28,6 +28,7 @@
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
@ -35,6 +36,7 @@
#include <pulsecore/sink.h> #include <pulsecore/sink.h>
#include <pulsecore/source.h> #include <pulsecore/source.h>
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/core-scache.h> #include <pulsecore/core-scache.h>
#include <pulsecore/core-subscribe.h> #include <pulsecore/core-subscribe.h>
@ -214,7 +216,7 @@ static void core_free(pa_object *o) {
pa_xfree(c); pa_xfree(c);
} }
static void exit_callback(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) { static void exit_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
pa_core *c = userdata; pa_core *c = userdata;
pa_assert(c->exit_event == e); pa_assert(c->exit_event == e);
@ -229,11 +231,7 @@ void pa_core_check_idle(pa_core *c) {
c->exit_idle_time >= 0 && c->exit_idle_time >= 0 &&
pa_idxset_size(c->clients) == 0) { pa_idxset_size(c->clients) == 0) {
struct timeval tv; c->exit_event = pa_core_rttime_new(c, pa_rtclock_now() + c->exit_idle_time * PA_USEC_PER_SEC, exit_callback, c);
pa_gettimeofday(&tv);
tv.tv_sec+= c->exit_idle_time;
c->exit_event = c->mainloop->time_new(c->mainloop, &tv, exit_callback, c);
} else if (c->exit_event && pa_idxset_size(c->clients) > 0) { } else if (c->exit_event && pa_idxset_size(c->clients) > 0) {
c->mainloop->time_free(c->exit_event); c->mainloop->time_free(c->exit_event);
@ -261,3 +259,21 @@ void pa_core_maybe_vacuum(pa_core *c) {
pa_log_debug("Hmm, no streams around, trying to vacuum."); pa_log_debug("Hmm, no streams around, trying to vacuum.");
pa_mempool_vacuum(c->mempool); pa_mempool_vacuum(c->mempool);
} }
pa_time_event* pa_core_rttime_new(pa_core *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata) {
struct timeval tv;
pa_assert(c);
pa_assert(c->mainloop);
return c->mainloop->time_new(c->mainloop, pa_timeval_rtstore(&tv, usec, TRUE), cb, userdata);
}
void pa_core_rttime_restart(pa_core *c, pa_time_event *e, pa_usec_t usec) {
struct timeval tv;
pa_assert(c);
pa_assert(c->mainloop);
c->mainloop->time_restart(e, pa_timeval_rtstore(&tv, usec, TRUE));
}

View file

@ -183,4 +183,8 @@ int pa_core_exit(pa_core *c, pa_bool_t force, int retval);
void pa_core_maybe_vacuum(pa_core *c); void pa_core_maybe_vacuum(pa_core *c);
/* wrapper for c->mainloop->time_*() RT time events */
pa_time_event* pa_core_rttime_new(pa_core *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata);
void pa_core_rttime_restart(pa_core *c, pa_time_event *e, pa_usec_t usec);
#endif #endif

View file

@ -70,7 +70,7 @@ pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *err
if ((pconn = pa_shared_get(c, prop_name[type]))) if ((pconn = pa_shared_get(c, prop_name[type])))
return pa_dbus_connection_ref(pconn); return pa_dbus_connection_ref(pconn);
if (!(conn = pa_dbus_wrap_connection_new(c->mainloop, type, error))) if (!(conn = pa_dbus_wrap_connection_new(c->mainloop, TRUE, type, error)))
return NULL; return NULL;
return dbus_connection_new(c, conn, prop_name[type]); return dbus_connection_new(c, conn, prop_name[type]);

View file

@ -26,9 +26,11 @@
#include <stdarg.h> #include <stdarg.h>
#include <pulse/xmalloc.h> #include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
@ -38,6 +40,12 @@ struct pa_dbus_wrap_connection {
pa_mainloop_api *mainloop; pa_mainloop_api *mainloop;
DBusConnection *connection; DBusConnection *connection;
pa_defer_event* dispatch_event; pa_defer_event* dispatch_event;
pa_bool_t use_rtclock:1;
};
struct timeout_data {
pa_dbus_wrap_connection *c;
DBusTimeout *timeout;
}; };
static void dispatch_cb(pa_mainloop_api *ea, pa_defer_event *ev, void *userdata) { static void dispatch_cb(pa_mainloop_api *ea, pa_defer_event *ev, void *userdata) {
@ -118,16 +126,18 @@ static void handle_io_event(pa_mainloop_api *ea, pa_io_event *e, int fd, pa_io_e
} }
/* pa_time_event_cb_t timer event handler */ /* 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) { static void handle_time_event(pa_mainloop_api *ea, pa_time_event* e, const struct timeval *t, void *userdata) {
DBusTimeout *timeout = userdata; struct timeval tv;
struct timeout_data *d = userdata;
if (dbus_timeout_get_enabled(timeout)) { pa_assert(d);
struct timeval next = *tv; pa_assert(d->c);
dbus_timeout_handle(timeout);
if (dbus_timeout_get_enabled(d->timeout)) {
dbus_timeout_handle(d->timeout);
/* restart it for the next scheduled time */ /* restart it for the next scheduled time */
pa_timeval_add(&next, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000); ea->time_restart(e, pa_timeval_rtstore(&tv, pa_timeval_load(t) + dbus_timeout_get_interval(d->timeout) * PA_USEC_PER_MSEC, d->c->use_rtclock));
ea->time_restart(e, &next);
} }
} }
@ -179,11 +189,16 @@ static void toggle_watch(DBusWatch *watch, void *data) {
c->mainloop->io_enable(ev, get_watch_flags(watch)); c->mainloop->io_enable(ev, get_watch_flags(watch));
} }
static void time_event_destroy_cb(pa_mainloop_api *a, pa_time_event *e, void *userdata) {
pa_xfree(userdata);
}
/* DBusAddTimeoutFunction callback for pa mainloop */ /* DBusAddTimeoutFunction callback for pa mainloop */
static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) { static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) {
pa_dbus_wrap_connection *c = data; pa_dbus_wrap_connection *c = data;
pa_time_event *ev; pa_time_event *ev;
struct timeval tv; struct timeval tv;
struct timeout_data *d;
pa_assert(timeout); pa_assert(timeout);
pa_assert(c); pa_assert(c);
@ -191,10 +206,11 @@ static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) {
if (!dbus_timeout_get_enabled(timeout)) if (!dbus_timeout_get_enabled(timeout))
return FALSE; return FALSE;
pa_gettimeofday(&tv); d = pa_xnew(struct timeout_data, 1);
pa_timeval_add(&tv, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000); d->c = c;
d->timeout = timeout;
ev = c->mainloop->time_new(c->mainloop, &tv, handle_time_event, timeout); ev = c->mainloop->time_new(c->mainloop, pa_timeval_rtstore(&tv, pa_rtclock_now() + dbus_timeout_get_interval(timeout) * PA_USEC_PER_MSEC, c->use_rtclock), handle_time_event, d);
c->mainloop->time_set_destroy(ev, time_event_destroy_cb);
dbus_timeout_set_data(timeout, ev, NULL); dbus_timeout_set_data(timeout, ev, NULL);
@ -215,23 +231,20 @@ static void remove_timeout(DBusTimeout *timeout, void *data) {
/* DBusTimeoutToggledFunction callback for pa mainloop */ /* DBusTimeoutToggledFunction callback for pa mainloop */
static void toggle_timeout(DBusTimeout *timeout, void *data) { static void toggle_timeout(DBusTimeout *timeout, void *data) {
pa_dbus_wrap_connection *c = data; struct timeout_data *d = data;
pa_time_event *ev; pa_time_event *ev;
struct timeval tv;
pa_assert(d);
pa_assert(d->c);
pa_assert(timeout); pa_assert(timeout);
pa_assert(c);
pa_assert_se(ev = dbus_timeout_get_data(timeout)); pa_assert_se(ev = dbus_timeout_get_data(timeout));
if (dbus_timeout_get_enabled(timeout)) { if (dbus_timeout_get_enabled(timeout)) {
struct timeval tv; d->c->mainloop->time_restart(ev, pa_timeval_rtstore(&tv, pa_rtclock_now() + dbus_timeout_get_interval(timeout) * PA_USEC_PER_MSEC, d->c->use_rtclock));
pa_gettimeofday(&tv);
pa_timeval_add(&tv, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000);
c->mainloop->time_restart(ev, &tv);
} else } else
c->mainloop->time_restart(ev, NULL); d->c->mainloop->time_restart(ev, pa_timeval_rtstore(&tv, PA_USEC_INVALID, d->c->use_rtclock));
} }
static void wakeup_main(void *userdata) { static void wakeup_main(void *userdata) {
@ -244,7 +257,7 @@ static void wakeup_main(void *userdata) {
c->mainloop->defer_enable(c->dispatch_event, 1); c->mainloop->defer_enable(c->dispatch_event, 1);
} }
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *m, DBusBusType type, DBusError *error) { pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *m, pa_bool_t use_rtclock, DBusBusType type, DBusError *error) {
DBusConnection *conn; DBusConnection *conn;
pa_dbus_wrap_connection *pconn; pa_dbus_wrap_connection *pconn;
char *id; char *id;
@ -257,6 +270,7 @@ pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *m, DBusBus
pconn = pa_xnew(pa_dbus_wrap_connection, 1); pconn = pa_xnew(pa_dbus_wrap_connection, 1);
pconn->mainloop = m; pconn->mainloop = m;
pconn->connection = conn; pconn->connection = conn;
pconn->use_rtclock = use_rtclock;
dbus_connection_set_exit_on_disconnect(conn, FALSE); dbus_connection_set_exit_on_disconnect(conn, FALSE);
dbus_connection_set_dispatch_status_function(conn, dispatch_status, pconn, NULL); dbus_connection_set_dispatch_status_function(conn, dispatch_status, pconn, NULL);

View file

@ -30,7 +30,7 @@
/* A wrap connection is not shared or refcounted, it is available in client side */ /* A wrap connection is not shared or refcounted, it is available in client side */
typedef struct pa_dbus_wrap_connection pa_dbus_wrap_connection; typedef struct pa_dbus_wrap_connection pa_dbus_wrap_connection;
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *mainloop, DBusBusType type, DBusError *error); pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *mainloop, pa_bool_t use_rtclock, DBusBusType type, DBusError *error);
void pa_dbus_wrap_connection_free(pa_dbus_wrap_connection* conn); void pa_dbus_wrap_connection_free(pa_dbus_wrap_connection* conn);
DBusConnection* pa_dbus_wrap_connection_get(pa_dbus_wrap_connection *conn); DBusConnection* pa_dbus_wrap_connection_get(pa_dbus_wrap_connection *conn);

View file

@ -38,6 +38,7 @@
#include <syslog.h> #include <syslog.h>
#endif #endif
#include <pulse/rtclock.h>
#include <pulse/utf8.h> #include <pulse/utf8.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulse/util.h> #include <pulse/util.h>
@ -45,7 +46,7 @@
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/rtclock.h> #include <pulsecore/core-rtclock.h>
#include <pulsecore/once.h> #include <pulsecore/once.h>
#include <pulsecore/ratelimit.h> #include <pulsecore/ratelimit.h>
@ -294,7 +295,7 @@ void pa_log_levelv_meta(
static pa_usec_t start, last; static pa_usec_t start, last;
pa_usec_t u, a, r; pa_usec_t u, a, r;
u = pa_rtclock_usec(); u = pa_rtclock_now();
PA_ONCE_BEGIN { PA_ONCE_BEGIN {
start = u; start = u;

View file

@ -27,6 +27,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
@ -37,6 +38,7 @@
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/refcnt.h> #include <pulsecore/refcnt.h>
#include <pulsecore/flist.h> #include <pulsecore/flist.h>
#include <pulsecore/core-rtclock.h>
#include "pdispatch.h" #include "pdispatch.h"
@ -204,6 +206,7 @@ struct pa_pdispatch {
pa_pdispatch_drain_callback drain_callback; pa_pdispatch_drain_callback drain_callback;
void *drain_userdata; void *drain_userdata;
const pa_creds *creds; const pa_creds *creds;
pa_bool_t use_rtclock:1;
}; };
static void reply_info_free(struct reply_info *r) { static void reply_info_free(struct reply_info *r) {
@ -220,7 +223,7 @@ static void reply_info_free(struct reply_info *r) {
pa_xfree(r); pa_xfree(r);
} }
pa_pdispatch* pa_pdispatch_new(pa_mainloop_api *mainloop, const pa_pdispatch_cb_t*table, unsigned entries) { pa_pdispatch* pa_pdispatch_new(pa_mainloop_api *mainloop, pa_bool_t use_rtclock, const pa_pdispatch_cb_t *table, unsigned entries) {
pa_pdispatch *pd; pa_pdispatch *pd;
pa_assert(mainloop); pa_assert(mainloop);
@ -235,6 +238,7 @@ pa_pdispatch* pa_pdispatch_new(pa_mainloop_api *mainloop, const pa_pdispatch_cb_
pd->drain_callback = NULL; pd->drain_callback = NULL;
pd->drain_userdata = NULL; pd->drain_userdata = NULL;
pd->creds = NULL; pd->creds = NULL;
pd->use_rtclock = use_rtclock;
return pd; return pd;
} }
@ -342,7 +346,7 @@ finish:
return ret; return ret;
} }
static void timeout_callback(pa_mainloop_api*m, pa_time_event*e, const struct timeval *tv, void *userdata) { static void timeout_callback(pa_mainloop_api*m, pa_time_event*e, const struct timeval *t, void *userdata) {
struct reply_info*r = userdata; struct reply_info*r = userdata;
pa_assert(r); pa_assert(r);
@ -371,10 +375,7 @@ void pa_pdispatch_register_reply(pa_pdispatch *pd, uint32_t tag, int timeout, pa
r->free_cb = free_cb; r->free_cb = free_cb;
r->tag = tag; r->tag = tag;
pa_gettimeofday(&tv); pa_assert_se(r->time_event = pd->mainloop->time_new(pd->mainloop, pa_timeval_rtstore(&tv, pa_rtclock_now() + timeout * PA_USEC_PER_SEC, pd->use_rtclock), timeout_callback, r));
tv.tv_sec += timeout;
pa_assert_se(r->time_event = pd->mainloop->time_new(pd->mainloop, &tv, timeout_callback, r));
PA_LLIST_PREPEND(struct reply_info, pd->replies, r); PA_LLIST_PREPEND(struct reply_info, pd->replies, r);
} }

View file

@ -37,7 +37,7 @@ typedef struct pa_pdispatch pa_pdispatch;
typedef void (*pa_pdispatch_cb_t)(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); typedef void (*pa_pdispatch_cb_t)(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
typedef void (*pa_pdispatch_drain_callback)(pa_pdispatch *pd, void *userdata); typedef void (*pa_pdispatch_drain_callback)(pa_pdispatch *pd, void *userdata);
pa_pdispatch* pa_pdispatch_new(pa_mainloop_api *m, const pa_pdispatch_cb_t*table, unsigned entries); pa_pdispatch* pa_pdispatch_new(pa_mainloop_api *m, pa_bool_t use_rtclock, const pa_pdispatch_cb_t*table, unsigned entries);
void pa_pdispatch_unref(pa_pdispatch *pd); void pa_pdispatch_unref(pa_pdispatch *pd);
pa_pdispatch* pa_pdispatch_ref(pa_pdispatch *pd); pa_pdispatch* pa_pdispatch_ref(pa_pdispatch *pd);

View file

@ -30,6 +30,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#include <pulse/rtclock.h>
#include <pulse/sample.h> #include <pulse/sample.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/utf8.h> #include <pulse/utf8.h>
@ -63,7 +64,7 @@
#define MAX_CONNECTIONS 64 #define MAX_CONNECTIONS 64
/* Kick a client if it doesn't authenticate within this time */ /* Kick a client if it doesn't authenticate within this time */
#define AUTH_TIMEOUT 5 #define AUTH_TIMEOUT (5*PA_USEC_PER_SEC)
#define DEFAULT_COOKIE_FILE ".esd_auth" #define DEFAULT_COOKIE_FILE ".esd_auth"
@ -1459,11 +1460,10 @@ static pa_usec_t source_output_get_latency_cb(pa_source_output *o) {
/*** entry points ***/ /*** entry points ***/
static void auth_timeout(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) { static void auth_timeout(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
connection *c = CONNECTION(userdata); connection *c = CONNECTION(userdata);
pa_assert(m); pa_assert(m);
pa_assert(tv);
connection_assert_ref(c); connection_assert_ref(c);
pa_assert(c->auth_timeout_event == e); pa_assert(c->auth_timeout_event == e);
@ -1553,12 +1553,9 @@ void pa_esound_protocol_connect(pa_esound_protocol *p, pa_iochannel *io, pa_esou
c->authorized = TRUE; c->authorized = TRUE;
} }
if (!c->authorized) { if (!c->authorized)
struct timeval tv; c->auth_timeout_event = pa_core_rttime_new(p->core, pa_rtclock_now() + AUTH_TIMEOUT, auth_timeout, c);
pa_gettimeofday(&tv); else
tv.tv_sec += AUTH_TIMEOUT;
c->auth_timeout_event = p->core->mainloop->time_new(p->core->mainloop, &tv, auth_timeout, c);
} else
c->auth_timeout_event = NULL; c->auth_timeout_event = NULL;
c->defer_event = p->core->mainloop->defer_new(p->core->mainloop, defer_callback, c); c->defer_event = p->core->mainloop->defer_new(p->core->mainloop, defer_callback, c);

View file

@ -29,6 +29,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/version.h> #include <pulse/version.h>
#include <pulse/utf8.h> #include <pulse/utf8.h>
@ -61,7 +62,7 @@
#include "protocol-native.h" #include "protocol-native.h"
/* Kick a client if it doesn't authenticate within this time */ /* Kick a client if it doesn't authenticate within this time */
#define AUTH_TIMEOUT 60 #define AUTH_TIMEOUT (60 * PA_USEC_PER_SEC)
/* Don't accept more connection than this */ /* Don't accept more connection than this */
#define MAX_CONNECTIONS 64 #define MAX_CONNECTIONS 64
@ -4479,11 +4480,10 @@ static void client_send_event_cb(pa_client *client, const char*event, pa_proplis
/*** module entry points ***/ /*** module entry points ***/
static void auth_timeout(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) { static void auth_timeout(pa_mainloop_api*m, pa_time_event *e, const struct timeval *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata); pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
pa_assert(m); pa_assert(m);
pa_assert(tv);
pa_native_connection_assert_ref(c); pa_native_connection_assert_ref(c);
pa_assert(c->auth_timeout_event == e); pa_assert(c->auth_timeout_event == e);
@ -4541,12 +4541,9 @@ void pa_native_protocol_connect(pa_native_protocol *p, pa_iochannel *io, pa_nati
c->authorized = TRUE; c->authorized = TRUE;
} }
if (!c->authorized) { if (!c->authorized)
struct timeval tv; c->auth_timeout_event = pa_core_rttime_new(p->core, pa_rtclock_now() + AUTH_TIMEOUT, auth_timeout, c);
pa_gettimeofday(&tv); else
tv.tv_sec += AUTH_TIMEOUT;
c->auth_timeout_event = p->core->mainloop->time_new(p->core->mainloop, &tv, auth_timeout, c);
} else
c->auth_timeout_event = NULL; c->auth_timeout_event = NULL;
c->is_local = pa_iochannel_socket_is_local(io); c->is_local = pa_iochannel_socket_is_local(io);
@ -4565,7 +4562,7 @@ void pa_native_protocol_connect(pa_native_protocol *p, pa_iochannel *io, pa_nati
pa_pstream_set_revoke_callback(c->pstream, pstream_revoke_callback, c); pa_pstream_set_revoke_callback(c->pstream, pstream_revoke_callback, c);
pa_pstream_set_release_callback(c->pstream, pstream_release_callback, c); pa_pstream_set_release_callback(c->pstream, pstream_release_callback, c);
c->pdispatch = pa_pdispatch_new(p->core->mainloop, command_table, PA_COMMAND_MAX); c->pdispatch = pa_pdispatch_new(p->core->mainloop, TRUE, command_table, PA_COMMAND_MAX);
c->record_streams = pa_idxset_new(NULL, NULL); c->record_streams = pa_idxset_new(NULL, NULL);
c->output_streams = pa_idxset_new(NULL, NULL); c->output_streams = pa_idxset_new(NULL, NULL);

View file

@ -23,7 +23,8 @@
#include <config.h> #include <config.h>
#endif #endif
#include <pulsecore/rtclock.h> #include <pulse/rtclock.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/mutex.h> #include <pulsecore/mutex.h>
@ -38,7 +39,7 @@ pa_bool_t pa_ratelimit_test(pa_ratelimit *r) {
pa_usec_t now; pa_usec_t now;
pa_mutex *m; pa_mutex *m;
now = pa_rtclock_usec(); now = pa_rtclock_now();
m = pa_static_mutex_get(&mutex, FALSE, FALSE); m = pa_static_mutex_get(&mutex, FALSE, FALSE);
pa_mutex_lock(m); pa_mutex_lock(m);

View file

@ -40,7 +40,7 @@
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/rtclock.h> #include <pulsecore/core-rtclock.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/llist.h> #include <pulsecore/llist.h>
#include <pulsecore/flist.h> #include <pulsecore/flist.h>
@ -112,7 +112,7 @@ pa_rtpoll *pa_rtpoll_new(void) {
PA_LLIST_HEAD_INIT(pa_rtpoll_item, p->items); PA_LLIST_HEAD_INIT(pa_rtpoll_item, p->items);
#ifdef DEBUG_TIMING #ifdef DEBUG_TIMING
p->timestamp = pa_rtclock_usec(); p->timestamp = pa_rtclock_now();
p->slept = p->awake = 0; p->slept = p->awake = 0;
#endif #endif
@ -299,7 +299,7 @@ int pa_rtpoll_run(pa_rtpoll *p, pa_bool_t wait) {
#ifdef DEBUG_TIMING #ifdef DEBUG_TIMING
{ {
pa_usec_t now = pa_rtclock_usec(); pa_usec_t now = pa_rtclock_now();
p->awake = now - p->timestamp; p->awake = now - p->timestamp;
p->timestamp = now; p->timestamp = now;
} }
@ -319,7 +319,7 @@ int pa_rtpoll_run(pa_rtpoll *p, pa_bool_t wait) {
#ifdef DEBUG_TIMING #ifdef DEBUG_TIMING
{ {
pa_usec_t now = pa_rtclock_usec(); pa_usec_t now = pa_rtclock_now();
p->slept = now - p->timestamp; p->slept = now - p->timestamp;
p->timestamp = now; p->timestamp = now;

View file

@ -52,12 +52,14 @@
#include <asyncns.h> #include <asyncns.h>
#endif #endif
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/winsock.h> #include <pulsecore/winsock.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/socket-util.h> #include <pulsecore/socket-util.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/socket-util.h> #include <pulsecore/socket-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
@ -420,12 +422,11 @@ fail:
#endif #endif
static void timeout_cb(pa_mainloop_api *m, pa_time_event *e, const struct timeval *tv, void *userdata) { static void timeout_cb(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
pa_socket_client *c = userdata; pa_socket_client *c = userdata;
pa_assert(m); pa_assert(m);
pa_assert(e); pa_assert(e);
pa_assert(tv);
pa_assert(c); pa_assert(c);
if (c->fd >= 0) { if (c->fd >= 0) {
@ -437,17 +438,16 @@ static void timeout_cb(pa_mainloop_api *m, pa_time_event *e, const struct timeva
do_call(c); do_call(c);
} }
static void start_timeout(pa_socket_client *c) { static void start_timeout(pa_socket_client *c, pa_bool_t use_rtclock) {
struct timeval tv; struct timeval tv;
pa_assert(c); pa_assert(c);
pa_assert(!c->timeout_event); pa_assert(!c->timeout_event);
pa_gettimeofday(&tv); c->timeout_event = c->mainloop->time_new(c->mainloop, pa_timeval_rtstore(&tv, pa_rtclock_now() + CONNECT_TIMEOUT * PA_USEC_PER_SEC, use_rtclock), timeout_cb, c);
pa_timeval_add(&tv, CONNECT_TIMEOUT * PA_USEC_PER_SEC);
c->timeout_event = c->mainloop->time_new(c->mainloop, &tv, timeout_cb, c);
} }
pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*name, uint16_t default_port) { pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, pa_bool_t use_rtclock, const char*name, uint16_t default_port) {
pa_socket_client *c = NULL; pa_socket_client *c = NULL;
pa_parsed_address a; pa_parsed_address a;
@ -463,7 +463,7 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
switch (a.type) { switch (a.type) {
case PA_PARSED_ADDRESS_UNIX: case PA_PARSED_ADDRESS_UNIX:
if ((c = pa_socket_client_new_unix(m, a.path_or_host))) if ((c = pa_socket_client_new_unix(m, a.path_or_host)))
start_timeout(c); start_timeout(c, use_rtclock);
break; break;
case PA_PARSED_ADDRESS_TCP4: /* Fallthrough */ case PA_PARSED_ADDRESS_TCP4: /* Fallthrough */
@ -499,7 +499,7 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
c->asyncns_io_event = m->io_new(m, asyncns_fd(c->asyncns), PA_IO_EVENT_INPUT, asyncns_cb, c); c->asyncns_io_event = m->io_new(m, asyncns_fd(c->asyncns), PA_IO_EVENT_INPUT, asyncns_cb, c);
c->asyncns_query = asyncns_getaddrinfo(c->asyncns, a.path_or_host, port, &hints); c->asyncns_query = asyncns_getaddrinfo(c->asyncns, a.path_or_host, port, &hints);
pa_assert(c->asyncns_query); pa_assert(c->asyncns_query);
start_timeout(c); start_timeout(c, use_rtclock);
} }
#elif defined(HAVE_GETADDRINFO) #elif defined(HAVE_GETADDRINFO)
{ {
@ -513,7 +513,7 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
if (res->ai_addr) { if (res->ai_addr) {
if ((c = pa_socket_client_new_sockaddr(m, res->ai_addr, res->ai_addrlen))) if ((c = pa_socket_client_new_sockaddr(m, res->ai_addr, res->ai_addrlen)))
start_timeout(c); start_timeout(c, use_rtclock);
} }
freeaddrinfo(res); freeaddrinfo(res);
@ -546,7 +546,7 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
s.sin_port = htons(a.port); s.sin_port = htons(a.port);
if ((c = pa_socket_client_new_sockaddr(m, (struct sockaddr*)&s, sizeof(s)))) if ((c = pa_socket_client_new_sockaddr(m, (struct sockaddr*)&s, sizeof(s))))
start_timeout(c); start_timeout(c, use_rtclock);
} }
#endif /* HAVE_LIBASYNCNS */ #endif /* HAVE_LIBASYNCNS */
} }

View file

@ -40,7 +40,7 @@ pa_socket_client* pa_socket_client_new_ipv6(pa_mainloop_api *m, uint8_t address[
#endif #endif
pa_socket_client* pa_socket_client_new_unix(pa_mainloop_api *m, const char *filename); pa_socket_client* pa_socket_client_new_unix(pa_mainloop_api *m, const char *filename);
pa_socket_client* pa_socket_client_new_sockaddr(pa_mainloop_api *m, const struct sockaddr *sa, size_t salen); pa_socket_client* pa_socket_client_new_sockaddr(pa_mainloop_api *m, const struct sockaddr *sa, size_t salen);
pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char *a, uint16_t default_port); pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, pa_bool_t use_rtclock, const char *a, uint16_t default_port);
pa_socket_client* pa_socket_client_ref(pa_socket_client *c); pa_socket_client* pa_socket_client_ref(pa_socket_client *c);
void pa_socket_client_unref(pa_socket_client *c); void pa_socket_client_unref(pa_socket_client *c);

View file

@ -26,10 +26,12 @@
#include <sys/time.h> #include <sys/time.h>
#include <assert.h> #include <assert.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/gccmacro.h> #include <pulse/gccmacro.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/core-rtclock.h>
#ifdef GLIB_MAIN_LOOP #ifdef GLIB_MAIN_LOOP
@ -99,9 +101,7 @@ int main(int argc, char *argv[]) {
de = a->defer_new(a, dcb, NULL); de = a->defer_new(a, dcb, NULL);
assert(de); assert(de);
pa_gettimeofday(&tv); te = a->time_new(a, pa_timeval_rtstore(&tv, pa_rtclock_now() + 2 * PA_USEC_PER_SEC, TRUE), tcb, NULL);
tv.tv_sec += 10;
te = a->time_new(a, &tv, tcb, NULL);
#if defined(GLIB_MAIN_LOOP) #if defined(GLIB_MAIN_LOOP)
g_main_loop_run(glib_main_loop); g_main_loop_run(glib_main_loop);

View file

@ -25,6 +25,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/util.h> #include <pulse/util.h>
#include <pulse/thread-mainloop.h> #include <pulse/thread-mainloop.h>
@ -53,9 +54,7 @@ int main(int argc, char *argv[]) {
pa_assert_se(!pa_threaded_mainloop_in_thread(m)); pa_assert_se(!pa_threaded_mainloop_in_thread(m));
pa_gettimeofday(&tv); a->time_new(a, pa_timeval_rtstore(&tv, pa_rtclock_now() + 5 * PA_USEC_PER_SEC, TRUE), tcb, m);
tv.tv_sec += 5;
a->time_new(a, &tv, tcb, m);
fprintf(stderr, "waiting 5s (signal)\n"); fprintf(stderr, "waiting 5s (signal)\n");
pa_threaded_mainloop_wait(m); pa_threaded_mainloop_wait(m);

View file

@ -27,8 +27,9 @@
#include <assert.h> #include <assert.h>
#include <signal.h> #include <signal.h>
#include <pulse/pulseaudio.h>
#include <pulse/browser.h> #include <pulse/browser.h>
#include <pulse/pulseaudio.h>
#include <pulse/rtclock.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>

View file

@ -39,6 +39,7 @@
#include <pulse/i18n.h> #include <pulse/i18n.h>
#include <pulse/pulseaudio.h> #include <pulse/pulseaudio.h>
#include <pulse/rtclock.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
@ -583,9 +584,7 @@ static void sigusr1_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int s
pa_operation_unref(pa_stream_update_timing_info(stream, stream_update_timing_callback, NULL)); pa_operation_unref(pa_stream_update_timing_info(stream, stream_update_timing_callback, NULL));
} }
static void time_event_callback(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) { static void time_event_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
struct timeval next;
if (stream && pa_stream_get_state(stream) == PA_STREAM_READY) { if (stream && pa_stream_get_state(stream) == PA_STREAM_READY) {
pa_operation *o; pa_operation *o;
if (!(o = pa_stream_update_timing_info(stream, stream_update_timing_callback, NULL))) if (!(o = pa_stream_update_timing_info(stream, stream_update_timing_callback, NULL)))
@ -594,10 +593,7 @@ static void time_event_callback(pa_mainloop_api*m, pa_time_event *e, const struc
pa_operation_unref(o); pa_operation_unref(o);
} }
pa_gettimeofday(&next); pa_context_rttime_restart(context, e, pa_rtclock_now() + TIME_EVENT_USEC);
pa_timeval_add(&next, TIME_EVENT_USEC);
m->time_restart(e, &next);
} }
static void help(const char *argv0) { static void help(const char *argv0) {
@ -1068,13 +1064,8 @@ int main(int argc, char *argv[]) {
} }
if (verbose) { if (verbose) {
struct timeval tv; if (!(time_event = pa_context_rttime_new(context, pa_rtclock_now() + TIME_EVENT_USEC, time_event_callback, NULL))) {
pa_log(_("pa_context_rttime_new() failed.\n"));
pa_gettimeofday(&tv);
pa_timeval_add(&tv, TIME_EVENT_USEC);
if (!(time_event = mainloop_api->time_new(mainloop_api, &tv, time_event_callback, NULL))) {
pa_log(_("time_new() failed.\n"));
goto quit; goto quit;
} }
} }