From c57d5deef6ee33ab892398c7fd27400cd4ce4542 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 Nov 2004 23:11:34 +0000 Subject: minor fixes for latency interpolation git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@291 fefdeb5f-60dc-0310-8127-8f9354f1896f --- polyp/alsa-util.c | 1 + polyp/mainloop.c | 59 +++++++++++++++++++++++++++++++++++++++++------ polyp/polyplib-context.c | 4 +++- polyp/polyplib-def.h | 2 +- polyp/polyplib-internal.h | 1 + polyp/polyplib-stream.c | 25 +++++++++++++------- 6 files changed, 75 insertions(+), 17 deletions(-) (limited to 'polyp') diff --git a/polyp/alsa-util.c b/polyp/alsa-util.c index 408bc561..188ba077 100644 --- a/polyp/alsa-util.c +++ b/polyp/alsa-util.c @@ -23,6 +23,7 @@ #include #endif +#include #include #include "alsa-util.h" diff --git a/polyp/mainloop.c b/polyp/mainloop.c index eb2eddc2..e13e7b11 100644 --- a/polyp/mainloop.c +++ b/polyp/mainloop.c @@ -425,6 +425,9 @@ static int dispatch_defer(struct pa_mainloop *m) { struct pa_defer_event *e; int r = 0; + if (!m->deferred_pending) + return 0; + for (e = pa_idxset_first(m->defer_events, &index); e && !m->quit; e = pa_idxset_next(m->defer_events, &index)) { if (e->dead || !e->enabled) continue; @@ -516,10 +519,10 @@ static int dispatch_timeout(struct pa_mainloop *m) { int pa_mainloop_iterate(struct pa_mainloop *m, int block, int *retval) { int r, t, dispatched = 0; assert(m && !m->running); - - m->running = 1; - if(m->quit) + m->running ++; + + if (m->quit) goto quit; scan_dead(m); @@ -534,6 +537,7 @@ int pa_mainloop_iterate(struct pa_mainloop *m, int block, int *retval) { } t = block ? calc_next_timeout(m) : 0; + r = poll(m->pollfds, m->n_pollfds, t); if (r < 0) { @@ -555,15 +559,15 @@ int pa_mainloop_iterate(struct pa_mainloop *m, int block, int *retval) { } } - m->running = 0; - + m->running--; + /* pa_log("dispatched: %i\n", dispatched); */ return r < 0 ? -1 : dispatched; quit: - - m->running = 0; + + m->running--; if (retval) *retval = m->retval; @@ -597,3 +601,44 @@ int pa_mainloop_deferred_pending(struct pa_mainloop *m) { assert(m); return m->deferred_pending > 0; } + + +void pa_mainloop_dump(struct pa_mainloop *m) { + assert(m); + + pa_log(__FILE__": Dumping mainloop sources START\n"); + + { + uint32_t index = PA_IDXSET_INVALID; + struct pa_io_event *e; + for (e = pa_idxset_first(m->io_events, &index); e; e = pa_idxset_next(m->io_events, &index)) { + if (e->dead) + continue; + + pa_log(__FILE__": kind=io fd=%i events=%i callback=%p userdata=%p\n", e->fd, (int) e->events, e->callback, e->userdata); + } + } + { + uint32_t index = PA_IDXSET_INVALID; + struct pa_defer_event *e; + for (e = pa_idxset_first(m->defer_events, &index); e; e = pa_idxset_next(m->defer_events, &index)) { + if (e->dead) + continue; + + pa_log(__FILE__": kind=defer enabled=%i callback=%p userdata=%p\n", e->enabled, e->callback, e->userdata); + } + } + { + uint32_t index = PA_IDXSET_INVALID; + struct pa_time_event *e; + for (e = pa_idxset_first(m->time_events, &index); e; e = pa_idxset_next(m->time_events, &index)) { + if (e->dead) + continue; + + pa_log(__FILE__": kind=time enabled=%i time=%u.%u callback=%p userdata=%p\n", e->enabled, e->timeval.tv_sec, e->timeval.tv_usec, e->callback, e->userdata); + } + } + + pa_log(__FILE__": Dumping mainloop sources STOP\n"); + +} diff --git a/polyp/polyplib-context.c b/polyp/polyplib-context.c index 15ef60b9..70429583 100644 --- a/polyp/polyplib-context.c +++ b/polyp/polyplib-context.c @@ -635,7 +635,9 @@ int pa_context_is_pending(struct pa_context *c) { /* pa_log("pstream: %i\n", pa_pstream_is_pending(c->pstream)); */ /* pa_log("pdispatch: %i\n", pa_pdispatch_is_pending(c->pdispatch)); */ - return (c->pstream && pa_pstream_is_pending(c->pstream)) || (c->pdispatch && pa_pdispatch_is_pending(c->pdispatch)) || c->client; + return (c->pstream && pa_pstream_is_pending(c->pstream)) || + (c->pdispatch && pa_pdispatch_is_pending(c->pdispatch)) || + c->client; } static void set_dispatch_callbacks(struct pa_operation *o); diff --git a/polyp/polyplib-def.h b/polyp/polyplib-def.h index e2fbaea5..44c2034b 100644 --- a/polyp/polyplib-def.h +++ b/polyp/polyplib-def.h @@ -176,7 +176,7 @@ struct pa_latency_info { pa_usec_t source_usec; /**< Time in usecs a sample takes from being recorded to being delivered to the application. Only for record streams. \since 0.5*/ pa_usec_t transport_usec; /**< Estimated time in usecs a sample takes to be transferred to/from the daemon. For both playback and record streams. \since 0.5 */ int playing; /**< Non-zero when the stream is currently playing. Only for playback streams. */ - uint32_t queue_length; /**< Queue size in bytes. For both playback and recrd streams. */ + uint32_t queue_length; /**< Queue size in bytes. For both playback and record streams. */ int synchronized_clocks; /**< Non-zero if the local and the * remote machine have synchronized * clocks. If synchronized clocks are diff --git a/polyp/polyplib-internal.h b/polyp/polyplib-internal.h index 68ba76a9..4289b3c8 100644 --- a/polyp/polyplib-internal.h +++ b/polyp/polyplib-internal.h @@ -108,6 +108,7 @@ struct pa_stream { uint32_t ipol_usec; struct timeval ipol_timestamp; struct pa_time_event *ipol_event; + int ipol_requested; void (*state_callback)(struct pa_stream*c, void *userdata); void *state_userdata; diff --git a/polyp/polyplib-stream.c b/polyp/polyplib-stream.c index 7d3d3a76..b3f1f8cd 100644 --- a/polyp/polyplib-stream.c +++ b/polyp/polyplib-stream.c @@ -32,8 +32,9 @@ #include "xmalloc.h" #include "pstream-util.h" #include "util.h" +#include "log.h" -#define LATENCY_IPOL_INTERVAL_USEC (100000L) +#define LATENCY_IPOL_INTERVAL_USEC (10000L) struct pa_stream *pa_stream_new(struct pa_context *c, const char *name, const struct pa_sample_spec *ss) { struct pa_stream *s; @@ -72,6 +73,7 @@ struct pa_stream *pa_stream_new(struct pa_context *c, const char *name, const st s->ipol_usec = 0; memset(&s->ipol_timestamp, 0, sizeof(s->ipol_timestamp)); s->ipol_event = NULL; + s->ipol_requested = 0; PA_LLIST_PREPEND(struct pa_stream, c->streams, s); @@ -208,11 +210,15 @@ static void ipol_callback(struct pa_mainloop_api *m, struct pa_time_event *e, co pa_stream_ref(s); - if (s->state == PA_STREAM_READY) +/* pa_log("requesting new ipol data\n"); */ + + if (s->state == PA_STREAM_READY && !s->ipol_requested) { pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL)); + s->ipol_requested = 1; + } gettimeofday(&tv2, NULL); - tv2.tv_usec += LATENCY_IPOL_INTERVAL_USEC; + pa_timeval_add(&tv2, LATENCY_IPOL_INTERVAL_USEC); m->time_restart(e, &tv2); @@ -426,8 +432,10 @@ static void stream_get_latency_info_callback(struct pa_pdispatch *pd, uint32_t c } if (o->stream->interpolate) { +/* pa_log("new interpol data\n"); */ o->stream->ipol_timestamp = i.timestamp; o->stream->ipol_usec = pa_stream_get_time(o->stream, &i); + o->stream->ipol_requested = 0; } p = &i; @@ -567,10 +575,12 @@ struct pa_operation* pa_stream_cork(struct pa_stream *s, int b, void (*cb) (stru assert(s && s->ref >= 1 && s->state == PA_STREAM_READY); if (s->interpolate) { - if (!s->corked && b) - s->ipol_usec = pa_stream_get_interpolated_time(s); - else if (s->corked && !b) - gettimeofday(&s->ipol_timestamp, NULL); + if (!s->corked && b) + /* Pausing */ + s->ipol_usec = pa_stream_get_interpolated_time(s); + else if (s->corked && !b) + /* Unpausing */ + gettimeofday(&s->ipol_timestamp, NULL); } s->corked = b; @@ -764,6 +774,5 @@ pa_usec_t pa_stream_get_interpolated_latency(struct pa_stream *s, int *negative) t = pa_stream_get_interpolated_time(s); c = pa_bytes_to_usec(s->counter, &s->sample_spec); - return time_counter_diff(s, t, c, negative); } -- cgit