mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
Abstract the gettimeofday call into a utility function to ease porting.
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/ossman@366 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
70710e14d8
commit
687e2d7da5
17 changed files with 38 additions and 29 deletions
|
|
@ -144,7 +144,7 @@ void pa_core_check_quit(struct pa_core *c) {
|
|||
|
||||
if (!c->quit_event && c->exit_idle_time >= 0 && pa_idxset_ncontents(c->clients) == 0) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
pa_gettimeofday(&tv);
|
||||
tv.tv_sec+= c->exit_idle_time;
|
||||
c->quit_event = c->mainloop->time_new(c->mainloop, &tv, quit_callback, c);
|
||||
} else if (c->quit_event && pa_idxset_ncontents(c->clients) > 0) {
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ static void glib_time_restart(struct pa_time_event*e, const struct timeval *tv)
|
|||
struct timeval now;
|
||||
assert(e && e->mainloop && !e->dead);
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
pa_gettimeofday(&now);
|
||||
if (e->source) {
|
||||
g_source_destroy(e->source);
|
||||
g_source_unref(e->source);
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ static void glib_time_restart(struct pa_time_event*e, const struct timeval *tv)
|
|||
struct timeval now;
|
||||
assert(e && e->mainloop && !e->dead);
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
pa_gettimeofday(&now);
|
||||
if (e->source != (guint) -1)
|
||||
g_source_remove(e->source);
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ int main(int argc, char *argv[]) {
|
|||
de = a->defer_new(a, dcb, NULL);
|
||||
assert(de);
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
pa_gettimeofday(&tv);
|
||||
tv.tv_sec += 10;
|
||||
te = a->time_new(a, &tv, tcb, NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -457,7 +457,7 @@ static int calc_next_timeout(struct pa_mainloop *m) {
|
|||
|
||||
/* Let's save a system call */
|
||||
if (!got_time) {
|
||||
gettimeofday(&now, NULL);
|
||||
pa_gettimeofday(&now);
|
||||
got_time = 1;
|
||||
}
|
||||
|
||||
|
|
@ -498,7 +498,7 @@ static int dispatch_timeout(struct pa_mainloop *m) {
|
|||
|
||||
/* Let's save a system call */
|
||||
if (!got_time) {
|
||||
gettimeofday(&now, NULL);
|
||||
pa_gettimeofday(&now);
|
||||
got_time = 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ static void time_callback(struct pa_mainloop_api*a, struct pa_time_event* e, con
|
|||
|
||||
adjust_rates(u);
|
||||
|
||||
gettimeofday(&n, NULL);
|
||||
pa_gettimeofday(&n);
|
||||
n.tv_sec += u->adjust_time;
|
||||
u->sink->core->mainloop->time_restart(e, &n);
|
||||
}
|
||||
|
|
@ -363,7 +363,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
|
|||
pa_log_warn(__FILE__": WARNING: no slave sinks specified.\n");
|
||||
|
||||
if (u->adjust_time > 0) {
|
||||
gettimeofday(&tv, NULL);
|
||||
pa_gettimeofday(&tv);
|
||||
tv.tv_sec += u->adjust_time;
|
||||
u->time_event = c->mainloop->time_new(c->mainloop, &tv, time_callback, u);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
|
|||
pa_sink_set_owner(u->sink, m);
|
||||
u->sink->description = pa_sprintf_malloc("NULL sink");
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
pa_gettimeofday(&tv);
|
||||
u->time_event = c->mainloop->time_new(c->mainloop, &tv, time_callback, u);
|
||||
|
||||
u->block_size = pa_bytes_per_second(&ss) / 10;
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@ static void stream_get_latency_callback(struct pa_pdispatch *pd, uint32_t comman
|
|||
return;
|
||||
}
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
pa_gettimeofday(&now);
|
||||
|
||||
if (pa_timeval_cmp(&local, &remote) < 0 && pa_timeval_cmp(&remote, &now)) {
|
||||
/* local and remote seem to have synchronized clocks */
|
||||
|
|
@ -324,7 +324,7 @@ static void request_latency(struct userdata *u) {
|
|||
pa_tagstruct_putu32(t, tag = u->ctag++);
|
||||
pa_tagstruct_putu32(t, u->channel);
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
pa_gettimeofday(&now);
|
||||
pa_tagstruct_put_timeval(t, &now);
|
||||
pa_tagstruct_putu64(t, 0);
|
||||
|
||||
|
|
@ -536,7 +536,7 @@ static void timeout_callback(struct pa_mainloop_api *m, struct pa_time_event*e,
|
|||
|
||||
request_latency(u);
|
||||
|
||||
gettimeofday(&ntv, NULL);
|
||||
pa_gettimeofday(&ntv);
|
||||
ntv.tv_sec += LATENCY_INTERVAL;
|
||||
m->time_restart(e, &ntv);
|
||||
}
|
||||
|
|
@ -650,7 +650,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
|
|||
pa_source_set_owner(u->source, m);
|
||||
#endif
|
||||
|
||||
gettimeofday(&ntv, NULL);
|
||||
pa_gettimeofday(&ntv);
|
||||
ntv.tv_sec += LATENCY_INTERVAL;
|
||||
u->time_event = c->mainloop->time_new(c->mainloop, &ntv, timeout_callback, u);
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ static void timeout_callback(struct pa_mainloop_api *m, struct pa_time_event*e,
|
|||
|
||||
pa_module_unload_unused(c);
|
||||
|
||||
gettimeofday(&ntv, NULL);
|
||||
pa_gettimeofday(&ntv);
|
||||
ntv.tv_sec += UNLOAD_POLL_TIME;
|
||||
m->time_restart(e, &ntv);
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ struct pa_module* pa_module_load(struct pa_core *c, const char *name, const char
|
|||
|
||||
if (!c->module_auto_unload_event) {
|
||||
struct timeval ntv;
|
||||
gettimeofday(&ntv, NULL);
|
||||
pa_gettimeofday(&ntv);
|
||||
ntv.tv_sec += UNLOAD_POLL_TIME;
|
||||
c->module_auto_unload_event = c->mainloop->time_new(c->mainloop, &ntv, timeout_callback, c);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ void pa_pdispatch_register_reply(struct pa_pdispatch *pd, uint32_t tag, int time
|
|||
r->userdata = userdata;
|
||||
r->tag = tag;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
pa_gettimeofday(&tv);
|
||||
tv.tv_sec += timeout;
|
||||
|
||||
r->time_event = pd->mainloop->time_new(pd->mainloop, &tv, timeout_callback, r);
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ static void ipol_callback(struct pa_mainloop_api *m, struct pa_time_event *e, co
|
|||
s->ipol_requested = 1;
|
||||
}
|
||||
|
||||
gettimeofday(&tv2, NULL);
|
||||
pa_gettimeofday(&tv2);
|
||||
pa_timeval_add(&tv2, LATENCY_IPOL_INTERVAL_USEC);
|
||||
|
||||
m->time_restart(e, &tv2);
|
||||
|
|
@ -256,7 +256,7 @@ void pa_create_stream_callback(struct pa_pdispatch *pd, uint32_t command, uint32
|
|||
struct timeval tv;
|
||||
pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
pa_gettimeofday(&tv);
|
||||
tv.tv_usec += LATENCY_IPOL_INTERVAL_USEC; /* every 100 ms */
|
||||
|
||||
assert(!s->ipol_event);
|
||||
|
|
@ -412,7 +412,7 @@ static void stream_get_latency_info_callback(struct pa_pdispatch *pd, uint32_t c
|
|||
pa_context_fail(o->context, PA_ERROR_PROTOCOL);
|
||||
goto finish;
|
||||
} else {
|
||||
gettimeofday(&now, NULL);
|
||||
pa_gettimeofday(&now);
|
||||
|
||||
if (pa_timeval_cmp(&local, &remote) < 0 && pa_timeval_cmp(&remote, &now)) {
|
||||
/* local and remote seem to have synchronized clocks */
|
||||
|
|
@ -470,7 +470,7 @@ struct pa_operation* pa_stream_get_latency_info(struct pa_stream *s, void (*cb)(
|
|||
pa_tagstruct_putu32(t, tag = s->context->ctag++);
|
||||
pa_tagstruct_putu32(t, s->channel);
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
pa_gettimeofday(&now);
|
||||
pa_tagstruct_put_timeval(t, &now);
|
||||
pa_tagstruct_putu64(t, s->counter);
|
||||
|
||||
|
|
@ -581,7 +581,7 @@ struct pa_operation* pa_stream_cork(struct pa_stream *s, int b, void (*cb) (stru
|
|||
s->ipol_usec = pa_stream_get_interpolated_time(s);
|
||||
else if (s->corked && !b)
|
||||
/* Unpausing */
|
||||
gettimeofday(&s->ipol_timestamp, NULL);
|
||||
pa_gettimeofday(&s->ipol_timestamp);
|
||||
}
|
||||
|
||||
s->corked = b;
|
||||
|
|
|
|||
|
|
@ -1099,7 +1099,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
|
|||
|
||||
if (!c->authorized) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
pa_gettimeofday(&tv);
|
||||
tv.tv_sec += AUTH_TIMEOUT;
|
||||
c->auth_timeout_event = p->core->mainloop->time_new(p->core->mainloop, &tv, auth_timeout, c);
|
||||
} else
|
||||
|
|
|
|||
|
|
@ -928,7 +928,7 @@ static void command_get_playback_latency(struct pa_pdispatch *pd, uint32_t comma
|
|||
pa_tagstruct_put_boolean(reply, pa_memblockq_is_readable(s->memblockq));
|
||||
pa_tagstruct_putu32(reply, pa_memblockq_get_length(s->memblockq));
|
||||
pa_tagstruct_put_timeval(reply, &tv);
|
||||
gettimeofday(&now, NULL);
|
||||
pa_gettimeofday(&now);
|
||||
pa_tagstruct_put_timeval(reply, &now);
|
||||
pa_tagstruct_putu64(reply, counter);
|
||||
pa_pstream_send_tagstruct(c->pstream, reply);
|
||||
|
|
@ -971,7 +971,7 @@ static void command_get_record_latency(struct pa_pdispatch *pd, uint32_t command
|
|||
pa_tagstruct_put_boolean(reply, 0);
|
||||
pa_tagstruct_putu32(reply, pa_memblockq_get_length(s->memblockq));
|
||||
pa_tagstruct_put_timeval(reply, &tv);
|
||||
gettimeofday(&now, NULL);
|
||||
pa_gettimeofday(&now);
|
||||
pa_tagstruct_put_timeval(reply, &now);
|
||||
pa_tagstruct_putu64(reply, counter);
|
||||
pa_pstream_send_tagstruct(c->pstream, reply);
|
||||
|
|
@ -2024,7 +2024,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
|
|||
|
||||
if (!c->authorized) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
pa_gettimeofday(&tv);
|
||||
tv.tv_sec += AUTH_TIMEOUT;
|
||||
c->auth_timeout_event = p->core->mainloop->time_new(p->core->mainloop, &tv, auth_timeout, c);
|
||||
} else
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ static void timeout_callback(struct pa_mainloop_api *m, struct pa_time_event*e,
|
|||
|
||||
pa_scache_unload_unused(c);
|
||||
|
||||
gettimeofday(&ntv, NULL);
|
||||
pa_gettimeofday(&ntv);
|
||||
ntv.tv_sec += UNLOAD_POLL_TIME;
|
||||
m->time_restart(e, &ntv);
|
||||
}
|
||||
|
|
@ -165,7 +165,7 @@ int pa_scache_add_file_lazy(struct pa_core *c, const char *name, const char *fil
|
|||
|
||||
if (!c->scache_auto_unload_event) {
|
||||
struct timeval ntv;
|
||||
gettimeofday(&ntv, NULL);
|
||||
pa_gettimeofday(&ntv);
|
||||
ntv.tv_sec += UNLOAD_POLL_TIME;
|
||||
c->scache_auto_unload_event = c->mainloop->time_new(c->mainloop, &ntv, timeout_callback, c);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -377,7 +377,7 @@ static void start_timeout(struct pa_socket_client *c) {
|
|||
assert(c);
|
||||
assert(!c->timeout_event);
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
pa_gettimeofday(&tv);
|
||||
pa_timeval_add(&tv, CONNECT_TIMEOUT * 1000000);
|
||||
c->timeout_event = c->mainloop->time_new(c->mainloop, &tv, timeout_cb, c);
|
||||
}
|
||||
|
|
|
|||
10
polyp/util.c
10
polyp/util.c
|
|
@ -302,6 +302,14 @@ char *pa_strlcpy(char *b, const char *s, size_t l) {
|
|||
return b;
|
||||
}
|
||||
|
||||
int pa_gettimeofday(struct timeval *tv) {
|
||||
#ifdef HAVE_GETTIMEOFDAY
|
||||
return gettimeofday(tv, NULL);
|
||||
#else
|
||||
#error "Platform lacks gettimeofday() or equivalent function."
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Calculate the difference between the two specfified timeval
|
||||
* timestamsps. */
|
||||
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
|
||||
|
|
@ -351,7 +359,7 @@ int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) {
|
|||
pa_usec_t pa_timeval_age(const struct timeval *tv) {
|
||||
struct timeval now;
|
||||
assert(tv);
|
||||
gettimeofday(&now, NULL);
|
||||
pa_gettimeofday(&now);
|
||||
return pa_timeval_diff(&now, tv);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ char *pa_get_home_dir(char *s, size_t l);
|
|||
|
||||
char *pa_path_get_filename(const char *p);
|
||||
|
||||
int pa_gettimeofday(struct timeval *tv);
|
||||
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b);
|
||||
int pa_timeval_cmp(const struct timeval *a, const struct timeval *b);
|
||||
pa_usec_t pa_timeval_age(const struct timeval *tv);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue