mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
minor fixes for latency interpolation
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@291 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
cd3a98a2ab
commit
c57d5deef6
6 changed files with 75 additions and 17 deletions
|
|
@ -23,6 +23,7 @@
|
|||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <asoundlib.h>
|
||||
|
||||
#include "alsa-util.h"
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -517,9 +520,9 @@ int pa_mainloop_iterate(struct pa_mainloop *m, int block, int *retval) {
|
|||
int r, t, dispatched = 0;
|
||||
assert(m && !m->running);
|
||||
|
||||
m->running = 1;
|
||||
m->running ++;
|
||||
|
||||
if(m->quit)
|
||||
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,7 +559,7 @@ int pa_mainloop_iterate(struct pa_mainloop *m, int block, int *retval) {
|
|||
}
|
||||
}
|
||||
|
||||
m->running = 0;
|
||||
m->running--;
|
||||
|
||||
/* pa_log("dispatched: %i\n", dispatched); */
|
||||
|
||||
|
|
@ -563,7 +567,7 @@ int pa_mainloop_iterate(struct pa_mainloop *m, int block, int *retval) {
|
|||
|
||||
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");
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -568,8 +576,10 @@ struct pa_operation* pa_stream_cork(struct pa_stream *s, int b, void (*cb) (stru
|
|||
|
||||
if (s->interpolate) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue