mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-12-16 08:56:40 -05:00
support for latency interpolation
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@256 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
da45617efc
commit
148202d432
13 changed files with 250 additions and 72 deletions
5
doc/todo
5
doc/todo
|
|
@ -1,7 +1,6 @@
|
||||||
*** $Id$ ***
|
*** $Id$ ***
|
||||||
|
|
||||||
*** 0.6 ****
|
*** 0.6 ****
|
||||||
- latency interpolation
|
|
||||||
- per-channel volume
|
- per-channel volume
|
||||||
- unix socket directories include user name
|
- unix socket directories include user name
|
||||||
- add sample directory
|
- add sample directory
|
||||||
|
|
@ -11,7 +10,9 @@
|
||||||
- filter capture data in client through alignment
|
- filter capture data in client through alignment
|
||||||
- add radio module
|
- add radio module
|
||||||
- make autoload list use idxset
|
- make autoload list use idxset
|
||||||
- enlarge mqmblockq sizes
|
- enlarge memblockq sizes
|
||||||
|
- add null-sink
|
||||||
|
- add sync API
|
||||||
|
|
||||||
** later ***
|
** later ***
|
||||||
- xmlrpc/http
|
- xmlrpc/http
|
||||||
|
|
|
||||||
|
|
@ -297,7 +297,8 @@ static void exit_signal_callback(struct pa_mainloop_api*m, struct pa_signal_even
|
||||||
|
|
||||||
/* Show the current latency */
|
/* Show the current latency */
|
||||||
static void stream_get_latency_callback(struct pa_stream *s, const struct pa_latency_info *i, void *userdata) {
|
static void stream_get_latency_callback(struct pa_stream *s, const struct pa_latency_info *i, void *userdata) {
|
||||||
double total;
|
pa_usec_t total;
|
||||||
|
int negative = 0;
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|
||||||
if (!i) {
|
if (!i) {
|
||||||
|
|
@ -306,20 +307,17 @@ static void stream_get_latency_callback(struct pa_stream *s, const struct pa_lat
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == PLAYBACK)
|
total = pa_stream_get_latency(s, i, &negative);
|
||||||
total = (double) i->sink_usec + i->buffer_usec + i->transport_usec;
|
|
||||||
else
|
|
||||||
total = (double) i->source_usec + i->buffer_usec + i->transport_usec - i->sink_usec;
|
|
||||||
|
|
||||||
fprintf(stderr, "Latency: buffer: %0.0f usec; sink: %0.0f usec; source: %0.0f usec; transport: %0.0f usec; total: %0.0f usec; synchronized clocks: %s.\n",
|
fprintf(stderr, "Latency: buffer: %0.0f usec; sink: %0.0f usec; source: %0.0f usec; transport: %0.0f usec; total: %0.0f usec; synchronized clocks: %s.\n",
|
||||||
(float) i->buffer_usec, (float) i->sink_usec, (float) i->source_usec, (float) i->transport_usec, total,
|
(float) i->buffer_usec, (float) i->sink_usec, (float) i->source_usec, (float) i->transport_usec, (float) total * (negative?-1:1),
|
||||||
i->synchronized_clocks ? "yes" : "no");
|
i->synchronized_clocks ? "yes" : "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Someone requested that the latency is shown */
|
/* Someone requested that the latency is shown */
|
||||||
static void sigusr1_signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) {
|
static void sigusr1_signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) {
|
||||||
fprintf(stderr, "Got SIGUSR1, requesting latency.\n");
|
fprintf(stderr, "Got SIGUSR1, requesting latency.\n");
|
||||||
pa_operation_unref(pa_stream_get_latency(stream, stream_get_latency_callback, NULL));
|
pa_operation_unref(pa_stream_get_latency_info(stream, stream_get_latency_callback, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,21 @@ enum pa_stream_direction {
|
||||||
/** Some special flags for stream connections. \since 0.6 */
|
/** Some special flags for stream connections. \since 0.6 */
|
||||||
enum pa_stream_flags {
|
enum pa_stream_flags {
|
||||||
PA_STREAM_START_CORKED = 1, /**< Create the stream corked, requiring an explicit pa_stream_cork() call to uncork it. */
|
PA_STREAM_START_CORKED = 1, /**< Create the stream corked, requiring an explicit pa_stream_cork() call to uncork it. */
|
||||||
|
PA_STREAM_INTERPOLATE_LATENCY = 2 /**< Interpolate the latency for
|
||||||
|
* this stream. When enabled,
|
||||||
|
* you can use
|
||||||
|
* pa_stream_interpolated_xxx()
|
||||||
|
* for synchronization. Using
|
||||||
|
* these functions instead of
|
||||||
|
* pa_stream_get_latency() has
|
||||||
|
* the advantage of not
|
||||||
|
* requiring a whole roundtrip
|
||||||
|
* for responses. Consider using
|
||||||
|
* this option when frequently
|
||||||
|
* requesting latency
|
||||||
|
* information. This is
|
||||||
|
* especially useful on long latency
|
||||||
|
* network connections. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Playback and record buffer metrics */
|
/** Playback and record buffer metrics */
|
||||||
|
|
@ -171,6 +186,7 @@ struct pa_latency_info {
|
||||||
* limited und unreliable itself. \since
|
* limited und unreliable itself. \since
|
||||||
* 0.5 */
|
* 0.5 */
|
||||||
struct timeval timestamp; /**< The time when this latency info was current */
|
struct timeval timestamp; /**< The time when this latency info was current */
|
||||||
|
uint64_t counter; /**< The byte counter current when the latency info was requested. \since 0.6 */
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A structure for the spawn api. This may be used to integrate auto
|
/** A structure for the spawn api. This may be used to integrate auto
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ struct pa_context {
|
||||||
struct pa_stream {
|
struct pa_stream {
|
||||||
int ref;
|
int ref;
|
||||||
struct pa_context *context;
|
struct pa_context *context;
|
||||||
|
struct pa_mainloop_api *mainloop;
|
||||||
PA_LLIST_FIELDS(struct pa_stream);
|
PA_LLIST_FIELDS(struct pa_stream);
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
|
|
@ -95,6 +96,13 @@ struct pa_stream {
|
||||||
pa_usec_t previous_time;
|
pa_usec_t previous_time;
|
||||||
enum pa_stream_state state;
|
enum pa_stream_state state;
|
||||||
|
|
||||||
|
int interpolate;
|
||||||
|
int corked;
|
||||||
|
|
||||||
|
uint32_t ipol_usec;
|
||||||
|
struct timeval ipol_timestamp;
|
||||||
|
struct pa_time_event *ipol_event;
|
||||||
|
|
||||||
void (*state_callback)(struct pa_stream*c, void *userdata);
|
void (*state_callback)(struct pa_stream*c, void *userdata);
|
||||||
void *state_userdata;
|
void *state_userdata;
|
||||||
|
|
||||||
|
|
@ -103,6 +111,7 @@ struct pa_stream {
|
||||||
|
|
||||||
void (*write_callback)(struct pa_stream *p, size_t length, void *userdata);
|
void (*write_callback)(struct pa_stream *p, size_t length, void *userdata);
|
||||||
void *write_userdata;
|
void *write_userdata;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pa_operation {
|
struct pa_operation {
|
||||||
|
|
@ -135,4 +144,7 @@ struct pa_operation* pa_context_send_simple_command(struct pa_context *c, uint32
|
||||||
|
|
||||||
void pa_stream_set_state(struct pa_stream *s, enum pa_stream_state st);
|
void pa_stream_set_state(struct pa_stream *s, enum pa_stream_state st);
|
||||||
|
|
||||||
|
void pa_stream_trash_ipol(struct pa_stream *s);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -341,7 +341,7 @@ pa_usec_t pa_simple_get_playback_latency(struct pa_simple *p, int *perror) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p->latency = 0;
|
p->latency = 0;
|
||||||
o = pa_stream_get_latency(p->stream, latency_complete, p);
|
o = pa_stream_get_latency_info(p->stream, latency_complete, p);
|
||||||
|
|
||||||
while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
|
while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,15 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "polyplib-internal.h"
|
#include "polyplib-internal.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
#include "pstream-util.h"
|
#include "pstream-util.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
#define LATENCY_IPOL_INTERVAL_USEC (100000L)
|
||||||
|
|
||||||
struct pa_stream *pa_stream_new(struct pa_context *c, const char *name, const struct pa_sample_spec *ss) {
|
struct pa_stream *pa_stream_new(struct pa_context *c, const char *name, const struct pa_sample_spec *ss) {
|
||||||
struct pa_stream *s;
|
struct pa_stream *s;
|
||||||
assert(c && ss);
|
assert(c && ss);
|
||||||
|
|
@ -39,6 +42,7 @@ struct pa_stream *pa_stream_new(struct pa_context *c, const char *name, const st
|
||||||
s = pa_xmalloc(sizeof(struct pa_stream));
|
s = pa_xmalloc(sizeof(struct pa_stream));
|
||||||
s->ref = 1;
|
s->ref = 1;
|
||||||
s->context = c;
|
s->context = c;
|
||||||
|
s->mainloop = c->mainloop;
|
||||||
|
|
||||||
s->read_callback = NULL;
|
s->read_callback = NULL;
|
||||||
s->read_userdata = NULL;
|
s->read_userdata = NULL;
|
||||||
|
|
@ -60,6 +64,13 @@ struct pa_stream *pa_stream_new(struct pa_context *c, const char *name, const st
|
||||||
s->counter = 0;
|
s->counter = 0;
|
||||||
s->previous_time = 0;
|
s->previous_time = 0;
|
||||||
|
|
||||||
|
s->corked = 0;
|
||||||
|
s->interpolate = 0;
|
||||||
|
|
||||||
|
s->ipol_usec = 0;
|
||||||
|
memset(&s->ipol_timestamp, 0, sizeof(s->ipol_timestamp));
|
||||||
|
s->ipol_event = NULL;
|
||||||
|
|
||||||
PA_LLIST_PREPEND(struct pa_stream, c->streams, s);
|
PA_LLIST_PREPEND(struct pa_stream, c->streams, s);
|
||||||
|
|
||||||
return pa_stream_ref(s);
|
return pa_stream_ref(s);
|
||||||
|
|
@ -67,6 +78,12 @@ struct pa_stream *pa_stream_new(struct pa_context *c, const char *name, const st
|
||||||
|
|
||||||
static void stream_free(struct pa_stream *s) {
|
static void stream_free(struct pa_stream *s) {
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|
||||||
|
if (s->ipol_event) {
|
||||||
|
assert(s->mainloop);
|
||||||
|
s->mainloop->time_free(s->ipol_event);
|
||||||
|
}
|
||||||
|
|
||||||
pa_xfree(s->name);
|
pa_xfree(s->name);
|
||||||
pa_xfree(s);
|
pa_xfree(s);
|
||||||
}
|
}
|
||||||
|
|
@ -181,6 +198,22 @@ finish:
|
||||||
pa_context_unref(c);
|
pa_context_unref(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ipol_callback(struct pa_mainloop_api *m, struct pa_time_event *e, const struct timeval *tv, void *userdata) {
|
||||||
|
struct timeval tv2;
|
||||||
|
struct pa_stream *s = userdata;
|
||||||
|
|
||||||
|
pa_stream_ref(s);
|
||||||
|
pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
|
||||||
|
|
||||||
|
gettimeofday(&tv2, NULL);
|
||||||
|
tv2.tv_usec += LATENCY_IPOL_INTERVAL_USEC;
|
||||||
|
|
||||||
|
m->time_restart(e, &tv2);
|
||||||
|
|
||||||
|
pa_stream_unref(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void pa_create_stream_callback(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
|
void pa_create_stream_callback(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
|
||||||
struct pa_stream *s = userdata;
|
struct pa_stream *s = userdata;
|
||||||
assert(pd && s && s->state == PA_STREAM_CREATING);
|
assert(pd && s && s->state == PA_STREAM_CREATING);
|
||||||
|
|
@ -207,6 +240,17 @@ void pa_create_stream_callback(struct pa_pdispatch *pd, uint32_t command, uint32
|
||||||
pa_dynarray_put((s->direction == PA_STREAM_RECORD) ? s->context->record_streams : s->context->playback_streams, s->channel, s);
|
pa_dynarray_put((s->direction == PA_STREAM_RECORD) ? s->context->record_streams : s->context->playback_streams, s->channel, s);
|
||||||
pa_stream_set_state(s, PA_STREAM_READY);
|
pa_stream_set_state(s, PA_STREAM_READY);
|
||||||
|
|
||||||
|
if (s->interpolate) {
|
||||||
|
struct timeval tv;
|
||||||
|
pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
|
||||||
|
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
tv.tv_usec += LATENCY_IPOL_INTERVAL_USEC; /* every 100 ms */
|
||||||
|
|
||||||
|
assert(!s->ipol_event);
|
||||||
|
s->ipol_event = s->mainloop->time_new(s->mainloop, &tv, &ipol_callback, s);
|
||||||
|
}
|
||||||
|
|
||||||
if (s->requested_bytes && s->ref > 1 && s->write_callback)
|
if (s->requested_bytes && s->ref > 1 && s->write_callback)
|
||||||
s->write_callback(s, s->requested_bytes, s->write_userdata);
|
s->write_callback(s, s->requested_bytes, s->write_userdata);
|
||||||
|
|
||||||
|
|
@ -221,6 +265,9 @@ static void create_stream(struct pa_stream *s, const char *dev, const struct pa_
|
||||||
|
|
||||||
pa_stream_ref(s);
|
pa_stream_ref(s);
|
||||||
|
|
||||||
|
s->interpolate = !!(flags & PA_STREAM_INTERPOLATE_LATENCY);
|
||||||
|
pa_stream_trash_ipol(s);
|
||||||
|
|
||||||
if (attr)
|
if (attr)
|
||||||
s->buffer_attr = *attr;
|
s->buffer_attr = *attr;
|
||||||
else {
|
else {
|
||||||
|
|
@ -330,7 +377,7 @@ struct pa_operation * pa_stream_drain(struct pa_stream *s, void (*cb) (struct pa
|
||||||
return pa_operation_ref(o);
|
return pa_operation_ref(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stream_get_latency_callback(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
|
static void stream_get_latency_info_callback(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
|
||||||
struct pa_operation *o = userdata;
|
struct pa_operation *o = userdata;
|
||||||
struct pa_latency_info i, *p = NULL;
|
struct pa_latency_info i, *p = NULL;
|
||||||
struct timeval local, remote, now;
|
struct timeval local, remote, now;
|
||||||
|
|
@ -347,12 +394,11 @@ static void stream_get_latency_callback(struct pa_pdispatch *pd, uint32_t comman
|
||||||
pa_tagstruct_getu32(t, &i.queue_length) < 0 ||
|
pa_tagstruct_getu32(t, &i.queue_length) < 0 ||
|
||||||
pa_tagstruct_get_timeval(t, &local) < 0 ||
|
pa_tagstruct_get_timeval(t, &local) < 0 ||
|
||||||
pa_tagstruct_get_timeval(t, &remote) < 0 ||
|
pa_tagstruct_get_timeval(t, &remote) < 0 ||
|
||||||
|
pa_tagstruct_getu64(t, &i.counter) < 0 ||
|
||||||
!pa_tagstruct_eof(t)) {
|
!pa_tagstruct_eof(t)) {
|
||||||
pa_context_fail(o->context, PA_ERROR_PROTOCOL);
|
pa_context_fail(o->context, PA_ERROR_PROTOCOL);
|
||||||
goto finish;
|
goto finish;
|
||||||
} else
|
} else {
|
||||||
p = &i;
|
|
||||||
|
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
|
|
||||||
if (pa_timeval_cmp(&local, &remote) < 0 && pa_timeval_cmp(&remote, &now)) {
|
if (pa_timeval_cmp(&local, &remote) < 0 && pa_timeval_cmp(&remote, &now)) {
|
||||||
|
|
@ -373,6 +419,14 @@ static void stream_get_latency_callback(struct pa_pdispatch *pd, uint32_t comman
|
||||||
pa_timeval_add(&i.timestamp, i.transport_usec);
|
pa_timeval_add(&i.timestamp, i.transport_usec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (o->stream->interpolate) {
|
||||||
|
o->stream->ipol_timestamp = now;
|
||||||
|
o->stream->ipol_usec = pa_stream_get_time(o->stream, &i);
|
||||||
|
}
|
||||||
|
|
||||||
|
p = &i;
|
||||||
|
}
|
||||||
|
|
||||||
if (o->callback) {
|
if (o->callback) {
|
||||||
void (*cb)(struct pa_stream *s, const struct pa_latency_info *i, void *userdata) = o->callback;
|
void (*cb)(struct pa_stream *s, const struct pa_latency_info *i, void *userdata) = o->callback;
|
||||||
cb(o->stream, p, o->userdata);
|
cb(o->stream, p, o->userdata);
|
||||||
|
|
@ -383,7 +437,7 @@ finish:
|
||||||
pa_operation_unref(o);
|
pa_operation_unref(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pa_operation* pa_stream_get_latency(struct pa_stream *s, void (*cb)(struct pa_stream *p, const struct pa_latency_info*i, void *userdata), void *userdata) {
|
struct pa_operation* pa_stream_get_latency_info(struct pa_stream *s, void (*cb)(struct pa_stream *p, const struct pa_latency_info*i, void *userdata), void *userdata) {
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
struct pa_operation *o;
|
struct pa_operation *o;
|
||||||
struct pa_tagstruct *t;
|
struct pa_tagstruct *t;
|
||||||
|
|
@ -403,9 +457,10 @@ struct pa_operation* pa_stream_get_latency(struct pa_stream *s, void (*cb)(struc
|
||||||
|
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
pa_tagstruct_put_timeval(t, &now);
|
pa_tagstruct_put_timeval(t, &now);
|
||||||
|
pa_tagstruct_putu64(t, s->counter);
|
||||||
|
|
||||||
pa_pstream_send_tagstruct(s->context->pstream, t);
|
pa_pstream_send_tagstruct(s->context->pstream, t);
|
||||||
pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, stream_get_latency_callback, o);
|
pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, stream_get_latency_info_callback, o);
|
||||||
|
|
||||||
return pa_operation_ref(o);
|
return pa_operation_ref(o);
|
||||||
}
|
}
|
||||||
|
|
@ -505,6 +560,13 @@ struct pa_operation* pa_stream_cork(struct pa_stream *s, int b, void (*cb) (stru
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
assert(s && s->ref >= 1 && s->state == PA_STREAM_READY);
|
assert(s && s->ref >= 1 && s->state == PA_STREAM_READY);
|
||||||
|
|
||||||
|
if (!s->corked && b)
|
||||||
|
s->ipol_usec = pa_stream_get_interpolated_time(s);
|
||||||
|
else if (s->corked && !b)
|
||||||
|
gettimeofday(&s->ipol_timestamp, NULL);
|
||||||
|
|
||||||
|
s->corked = b;
|
||||||
|
|
||||||
o = pa_operation_new(s->context, s);
|
o = pa_operation_new(s->context, s);
|
||||||
assert(o);
|
assert(o);
|
||||||
o->callback = cb;
|
o->callback = cb;
|
||||||
|
|
@ -519,6 +581,8 @@ struct pa_operation* pa_stream_cork(struct pa_stream *s, int b, void (*cb) (stru
|
||||||
pa_pstream_send_tagstruct(s->context->pstream, t);
|
pa_pstream_send_tagstruct(s->context->pstream, t);
|
||||||
pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_stream_simple_ack_callback, o);
|
pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_stream_simple_ack_callback, o);
|
||||||
|
|
||||||
|
pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
|
||||||
|
|
||||||
return pa_operation_ref(o);
|
return pa_operation_ref(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -543,15 +607,24 @@ struct pa_operation* pa_stream_send_simple_command(struct pa_stream *s, uint32_t
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pa_operation* pa_stream_flush(struct pa_stream *s, void (*cb)(struct pa_stream *s, int success, void *userdata), void *userdata) {
|
struct pa_operation* pa_stream_flush(struct pa_stream *s, void (*cb)(struct pa_stream *s, int success, void *userdata), void *userdata) {
|
||||||
return pa_stream_send_simple_command(s, s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_FLUSH_PLAYBACK_STREAM : PA_COMMAND_FLUSH_RECORD_STREAM, cb, userdata);
|
struct pa_operation *o;
|
||||||
|
o = pa_stream_send_simple_command(s, s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_FLUSH_PLAYBACK_STREAM : PA_COMMAND_FLUSH_RECORD_STREAM, cb, userdata);
|
||||||
|
pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
|
||||||
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pa_operation* pa_stream_prebuf(struct pa_stream *s, void (*cb)(struct pa_stream *s, int success, void *userdata), void *userdata) {
|
struct pa_operation* pa_stream_prebuf(struct pa_stream *s, void (*cb)(struct pa_stream *s, int success, void *userdata), void *userdata) {
|
||||||
return pa_stream_send_simple_command(s, PA_COMMAND_PREBUF_PLAYBACK_STREAM, cb, userdata);
|
struct pa_operation *o;
|
||||||
|
o = pa_stream_send_simple_command(s, PA_COMMAND_PREBUF_PLAYBACK_STREAM, cb, userdata);
|
||||||
|
pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
|
||||||
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pa_operation* pa_stream_trigger(struct pa_stream *s, void (*cb)(struct pa_stream *s, int success, void *userdata), void *userdata) {
|
struct pa_operation* pa_stream_trigger(struct pa_stream *s, void (*cb)(struct pa_stream *s, int success, void *userdata), void *userdata) {
|
||||||
return pa_stream_send_simple_command(s, PA_COMMAND_TRIGGER_PLAYBACK_STREAM, cb, userdata);
|
struct pa_operation *o;
|
||||||
|
o = pa_stream_send_simple_command(s, PA_COMMAND_TRIGGER_PLAYBACK_STREAM, cb, userdata);
|
||||||
|
pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
|
||||||
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pa_operation* pa_stream_set_name(struct pa_stream *s, const char *name, void(*cb)(struct pa_stream*c, int success, void *userdata), void *userdata) {
|
struct pa_operation* pa_stream_set_name(struct pa_stream *s, const char *name, void(*cb)(struct pa_stream*c, int success, void *userdata), void *userdata) {
|
||||||
|
|
@ -582,12 +655,6 @@ uint64_t pa_stream_get_counter(struct pa_stream *s) {
|
||||||
return s->counter;
|
return s->counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pa_stream_reset_counter(struct pa_stream *s) {
|
|
||||||
assert(s);
|
|
||||||
s->counter = 0;
|
|
||||||
s->previous_time = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_usec_t pa_stream_get_time(struct pa_stream *s, const struct pa_latency_info *i) {
|
pa_usec_t pa_stream_get_time(struct pa_stream *s, const struct pa_latency_info *i) {
|
||||||
pa_usec_t usec;
|
pa_usec_t usec;
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|
@ -620,27 +687,22 @@ pa_usec_t pa_stream_get_time(struct pa_stream *s, const struct pa_latency_info *
|
||||||
return usec;
|
return usec;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_usec_t pa_stream_get_total_latency(struct pa_stream *s, const struct pa_latency_info *i, int *negative) {
|
pa_usec_t pa_stream_get_latency(struct pa_stream *s, const struct pa_latency_info *i, int *negative) {
|
||||||
|
pa_usec_t t, c;
|
||||||
assert(s && i);
|
assert(s && i);
|
||||||
|
|
||||||
if (s->direction == PA_STREAM_PLAYBACK) {
|
t = pa_stream_get_time(s, i);
|
||||||
if (negative)
|
c = pa_bytes_to_usec(s->counter, &s->sample_spec);
|
||||||
*negative = 0;
|
|
||||||
|
|
||||||
return i->transport_usec + i->buffer_usec + i->sink_usec;
|
if (t <= c) {
|
||||||
} else if (s->direction == PA_STREAM_RECORD) {
|
|
||||||
pa_usec_t usec = i->source_usec + i->buffer_usec + i->transport_usec;
|
|
||||||
|
|
||||||
if (usec >= i->sink_usec) {
|
|
||||||
if (negative)
|
|
||||||
*negative = 0;
|
|
||||||
return usec - i->sink_usec;
|
|
||||||
} else {
|
|
||||||
if (negative)
|
if (negative)
|
||||||
*negative = 1;
|
*negative = 1;
|
||||||
|
|
||||||
return i->sink_usec - usec;
|
return c-t;
|
||||||
}
|
} else {
|
||||||
|
if (negative)
|
||||||
|
*negative = 0;
|
||||||
|
return t-c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -650,3 +712,52 @@ const struct pa_sample_spec* pa_stream_get_sample_spec(struct pa_stream *s) {
|
||||||
assert(s);
|
assert(s);
|
||||||
return &s->sample_spec;
|
return &s->sample_spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pa_stream_trash_ipol(struct pa_stream *s) {
|
||||||
|
assert(s);
|
||||||
|
|
||||||
|
if (!s->interpolate)
|
||||||
|
return;
|
||||||
|
|
||||||
|
memset(&s->ipol_timestamp, 0, sizeof(s->ipol_timestamp));
|
||||||
|
s->ipol_usec = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pa_usec_t pa_stream_get_interpolated_time(struct pa_stream *s) {
|
||||||
|
pa_usec_t usec;
|
||||||
|
assert(s && s->interpolate);
|
||||||
|
|
||||||
|
if (s->corked)
|
||||||
|
usec = s->ipol_usec;
|
||||||
|
else {
|
||||||
|
if (s->ipol_timestamp.tv_sec == 0)
|
||||||
|
usec = 0;
|
||||||
|
else
|
||||||
|
usec = s->ipol_usec + pa_timeval_age(&s->ipol_timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usec < s->previous_time)
|
||||||
|
usec = s->previous_time;
|
||||||
|
|
||||||
|
s->previous_time = usec;
|
||||||
|
return usec;
|
||||||
|
}
|
||||||
|
|
||||||
|
pa_usec_t pa_stream_get_interpolated_latency(struct pa_stream *s, int *negative) {
|
||||||
|
pa_usec_t t, c;
|
||||||
|
assert(s && s->interpolate);
|
||||||
|
|
||||||
|
t = pa_stream_get_interpolated_time(s);
|
||||||
|
c = pa_bytes_to_usec(s->counter, &s->sample_spec);
|
||||||
|
|
||||||
|
if (t <= c) {
|
||||||
|
if (negative)
|
||||||
|
*negative = 1;
|
||||||
|
|
||||||
|
return c-t;
|
||||||
|
} else {
|
||||||
|
if (negative)
|
||||||
|
*negative = 0;
|
||||||
|
return t-c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ size_t pa_stream_writable_size(struct pa_stream *p);
|
||||||
struct pa_operation* pa_stream_drain(struct pa_stream *s, void (*cb) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
struct pa_operation* pa_stream_drain(struct pa_stream *s, void (*cb) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||||
|
|
||||||
/** Get the playback latency of a stream */
|
/** Get the playback latency of a stream */
|
||||||
struct pa_operation* pa_stream_get_latency(struct pa_stream *p, void (*cb)(struct pa_stream *p, const struct pa_latency_info *i, void *userdata), void *userdata);
|
struct pa_operation* pa_stream_get_latency_info(struct pa_stream *p, void (*cb)(struct pa_stream *p, const struct pa_latency_info *i, void *userdata), void *userdata);
|
||||||
|
|
||||||
/** Set the callback function that is called whenever the state of the stream changes */
|
/** Set the callback function that is called whenever the state of the stream changes */
|
||||||
void pa_stream_set_state_callback(struct pa_stream *s, void (*cb)(struct pa_stream *s, void *userdata), void *userdata);
|
void pa_stream_set_state_callback(struct pa_stream *s, void (*cb)(struct pa_stream *s, void *userdata), void *userdata);
|
||||||
|
|
@ -138,9 +138,6 @@ struct pa_operation* pa_stream_set_name(struct pa_stream *s, const char *name, v
|
||||||
* this yourself using pa_stream_reset_counter(). \since 0.6 */
|
* this yourself using pa_stream_reset_counter(). \since 0.6 */
|
||||||
uint64_t pa_stream_get_counter(struct pa_stream *s);
|
uint64_t pa_stream_get_counter(struct pa_stream *s);
|
||||||
|
|
||||||
/** Reset the total byte count to 0. \since 0.6 */
|
|
||||||
void pa_stream_reset_counter(struct pa_stream *s);
|
|
||||||
|
|
||||||
/** Return the current playback/recording time. This is based on the
|
/** Return the current playback/recording time. This is based on the
|
||||||
* counter accessible with pa_stream_get_counter(). This function
|
* counter accessible with pa_stream_get_counter(). This function
|
||||||
* requires a pa_latency_info structure as argument, which should be
|
* requires a pa_latency_info structure as argument, which should be
|
||||||
|
|
@ -152,7 +149,18 @@ pa_usec_t pa_stream_get_time(struct pa_stream *s, const struct pa_latency_info *
|
||||||
* using pa_stream_get_latency(). In case the stream is a monitoring
|
* using pa_stream_get_latency(). In case the stream is a monitoring
|
||||||
* stream the result can be negative, i.e. the captured samples are
|
* stream the result can be negative, i.e. the captured samples are
|
||||||
* not yet played. In this case *negative is set to 1. \since 0.6 */
|
* not yet played. In this case *negative is set to 1. \since 0.6 */
|
||||||
pa_usec_t pa_stream_get_total_latency(struct pa_stream *s, const struct pa_latency_info *i, int *negative);
|
pa_usec_t pa_stream_get_latency(struct pa_stream *s, const struct pa_latency_info *i, int *negative);
|
||||||
|
|
||||||
|
/** Return the interpolated playback/recording time. Requires the
|
||||||
|
* PA_STREAM_INTERPOLATE_LATENCY bit set when creating the stream. In
|
||||||
|
* contrast to pa_stream_get_latency() this function doesn't require
|
||||||
|
* a whole roundtrip for response. \since 0.6 */
|
||||||
|
pa_usec_t pa_stream_get_interpolated_time(struct pa_stream *s);
|
||||||
|
|
||||||
|
/** Return the interpolated playback/recording latency. Requires the
|
||||||
|
* PA_STREAM_INTERPOLATE_LATENCY bit set when creating the
|
||||||
|
* stream. \since 0.6 */
|
||||||
|
pa_usec_t pa_stream_get_interpolated_latency(struct pa_stream *s, int *negative);
|
||||||
|
|
||||||
/** Return a pointer to the streams sample specification. \since 0.6 */
|
/** Return a pointer to the streams sample specification. \since 0.6 */
|
||||||
const struct pa_sample_spec* pa_stream_get_sample_spec(struct pa_stream *s);
|
const struct pa_sample_spec* pa_stream_get_sample_spec(struct pa_stream *s);
|
||||||
|
|
|
||||||
|
|
@ -875,11 +875,13 @@ static void command_get_playback_latency(struct pa_pdispatch *pd, uint32_t comma
|
||||||
struct pa_tagstruct *reply;
|
struct pa_tagstruct *reply;
|
||||||
struct playback_stream *s;
|
struct playback_stream *s;
|
||||||
struct timeval tv, now;
|
struct timeval tv, now;
|
||||||
|
uint64_t counter;
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
assert(c && t);
|
assert(c && t);
|
||||||
|
|
||||||
if (pa_tagstruct_getu32(t, &index) < 0 ||
|
if (pa_tagstruct_getu32(t, &index) < 0 ||
|
||||||
pa_tagstruct_get_timeval(t, &tv) < 0 ||
|
pa_tagstruct_get_timeval(t, &tv) < 0 ||
|
||||||
|
pa_tagstruct_getu64(t, &counter) < 0 ||
|
||||||
!pa_tagstruct_eof(t)) {
|
!pa_tagstruct_eof(t)) {
|
||||||
protocol_error(c);
|
protocol_error(c);
|
||||||
return;
|
return;
|
||||||
|
|
@ -907,6 +909,7 @@ static void command_get_playback_latency(struct pa_pdispatch *pd, uint32_t comma
|
||||||
pa_tagstruct_put_timeval(reply, &tv);
|
pa_tagstruct_put_timeval(reply, &tv);
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
pa_tagstruct_put_timeval(reply, &now);
|
pa_tagstruct_put_timeval(reply, &now);
|
||||||
|
pa_tagstruct_putu64(reply, counter);
|
||||||
pa_pstream_send_tagstruct(c->pstream, reply);
|
pa_pstream_send_tagstruct(c->pstream, reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -915,11 +918,13 @@ static void command_get_record_latency(struct pa_pdispatch *pd, uint32_t command
|
||||||
struct pa_tagstruct *reply;
|
struct pa_tagstruct *reply;
|
||||||
struct record_stream *s;
|
struct record_stream *s;
|
||||||
struct timeval tv, now;
|
struct timeval tv, now;
|
||||||
|
uint64_t counter;
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
assert(c && t);
|
assert(c && t);
|
||||||
|
|
||||||
if (pa_tagstruct_getu32(t, &index) < 0 ||
|
if (pa_tagstruct_getu32(t, &index) < 0 ||
|
||||||
pa_tagstruct_get_timeval(t, &tv) < 0 ||
|
pa_tagstruct_get_timeval(t, &tv) < 0 ||
|
||||||
|
pa_tagstruct_getu64(t, &counter) < 0 ||
|
||||||
!pa_tagstruct_eof(t)) {
|
!pa_tagstruct_eof(t)) {
|
||||||
protocol_error(c);
|
protocol_error(c);
|
||||||
return;
|
return;
|
||||||
|
|
@ -947,6 +952,7 @@ static void command_get_record_latency(struct pa_pdispatch *pd, uint32_t command
|
||||||
pa_tagstruct_put_timeval(reply, &tv);
|
pa_tagstruct_put_timeval(reply, &tv);
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
pa_tagstruct_put_timeval(reply, &now);
|
pa_tagstruct_put_timeval(reply, &now);
|
||||||
|
pa_tagstruct_putu64(reply, counter);
|
||||||
pa_pstream_send_tagstruct(c->pstream, reply);
|
pa_pstream_send_tagstruct(c->pstream, reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,10 +68,10 @@ struct pa_sample_spec {
|
||||||
uint8_t channels; /**< Audio channels. (1 for mono, 2 for stereo, ...) */
|
uint8_t channels; /**< Audio channels. (1 for mono, 2 for stereo, ...) */
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Type for usec specifications. May be either 32 or 64 bit, depending on the architecture */
|
/** Type for usec specifications (unsigned). May be either 32 or 64 bit, depending on the architecture */
|
||||||
typedef uint64_t pa_usec_t;
|
typedef uint64_t pa_usec_t;
|
||||||
|
|
||||||
/** Return the amount of bytes playback of a second of audio with the speicified sample type takes */
|
/** Return the amount of bytes playback of a second of audio with the specified sample type takes */
|
||||||
size_t pa_bytes_per_second(const struct pa_sample_spec *spec);
|
size_t pa_bytes_per_second(const struct pa_sample_spec *spec);
|
||||||
|
|
||||||
/** Return the size of a frame with the specific sample type */
|
/** Return the size of a frame with the specific sample type */
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,15 @@ void pa_tagstruct_put_usec(struct pa_tagstruct*t, pa_usec_t u) {
|
||||||
t->length += 9;
|
t->length += 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pa_tagstruct_putu64(struct pa_tagstruct*t, uint64_t u) {
|
||||||
|
assert(t);
|
||||||
|
extend(t, 9);
|
||||||
|
t->data[t->length] = TAG_U64;
|
||||||
|
*((uint32_t*) (t->data+t->length+1)) = htonl((uint32_t) (u >> 32));
|
||||||
|
*((uint32_t*) (t->data+t->length+5)) = htonl((uint32_t) u);
|
||||||
|
t->length += 9;
|
||||||
|
}
|
||||||
|
|
||||||
int pa_tagstruct_gets(struct pa_tagstruct*t, const char **s) {
|
int pa_tagstruct_gets(struct pa_tagstruct*t, const char **s) {
|
||||||
int error = 0;
|
int error = 0;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
@ -332,3 +341,18 @@ int pa_tagstruct_get_usec(struct pa_tagstruct*t, pa_usec_t *u) {
|
||||||
t->rindex +=9;
|
t->rindex +=9;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pa_tagstruct_getu64(struct pa_tagstruct*t, uint64_t *u) {
|
||||||
|
assert(t && u);
|
||||||
|
|
||||||
|
if (t->rindex+9 > t->length)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (t->data[t->rindex] != TAG_U64)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
*u = (uint64_t) ntohl(*((uint32_t*) (t->data+t->rindex+1))) << 32;
|
||||||
|
*u |= (uint64_t) ntohl(*((uint32_t*) (t->data+t->rindex+5)));
|
||||||
|
t->rindex +=9;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,9 @@ void pa_tagstruct_free(struct pa_tagstruct*t);
|
||||||
uint8_t* pa_tagstruct_free_data(struct pa_tagstruct*t, size_t *l);
|
uint8_t* pa_tagstruct_free_data(struct pa_tagstruct*t, size_t *l);
|
||||||
|
|
||||||
void pa_tagstruct_puts(struct pa_tagstruct*t, const char *s);
|
void pa_tagstruct_puts(struct pa_tagstruct*t, const char *s);
|
||||||
void pa_tagstruct_putu32(struct pa_tagstruct*t, uint32_t i);
|
|
||||||
void pa_tagstruct_putu8(struct pa_tagstruct*t, uint8_t c);
|
void pa_tagstruct_putu8(struct pa_tagstruct*t, uint8_t c);
|
||||||
|
void pa_tagstruct_putu32(struct pa_tagstruct*t, uint32_t i);
|
||||||
|
void pa_tagstruct_putu64(struct pa_tagstruct*t, uint64_t i);
|
||||||
void pa_tagstruct_put_sample_spec(struct pa_tagstruct *t, const struct pa_sample_spec *ss);
|
void pa_tagstruct_put_sample_spec(struct pa_tagstruct *t, const struct pa_sample_spec *ss);
|
||||||
void pa_tagstruct_put_arbitrary(struct pa_tagstruct*t, const void *p, size_t length);
|
void pa_tagstruct_put_arbitrary(struct pa_tagstruct*t, const void *p, size_t length);
|
||||||
void pa_tagstruct_put_boolean(struct pa_tagstruct*t, int b);
|
void pa_tagstruct_put_boolean(struct pa_tagstruct*t, int b);
|
||||||
|
|
@ -45,8 +46,9 @@ void pa_tagstruct_put_timeval(struct pa_tagstruct*t, const struct timeval *tv);
|
||||||
void pa_tagstruct_put_usec(struct pa_tagstruct*t, pa_usec_t u);
|
void pa_tagstruct_put_usec(struct pa_tagstruct*t, pa_usec_t u);
|
||||||
|
|
||||||
int pa_tagstruct_gets(struct pa_tagstruct*t, const char **s);
|
int pa_tagstruct_gets(struct pa_tagstruct*t, const char **s);
|
||||||
int pa_tagstruct_getu32(struct pa_tagstruct*t, uint32_t *i);
|
|
||||||
int pa_tagstruct_getu8(struct pa_tagstruct*t, uint8_t *c);
|
int pa_tagstruct_getu8(struct pa_tagstruct*t, uint8_t *c);
|
||||||
|
int pa_tagstruct_getu32(struct pa_tagstruct*t, uint32_t *i);
|
||||||
|
int pa_tagstruct_getu64(struct pa_tagstruct*t, uint64_t *i);
|
||||||
int pa_tagstruct_get_sample_spec(struct pa_tagstruct *t, struct pa_sample_spec *ss);
|
int pa_tagstruct_get_sample_spec(struct pa_tagstruct *t, struct pa_sample_spec *ss);
|
||||||
int pa_tagstruct_get_arbitrary(struct pa_tagstruct *t, const void **p, size_t length);
|
int pa_tagstruct_get_arbitrary(struct pa_tagstruct *t, const void **p, size_t length);
|
||||||
int pa_tagstruct_get_boolean(struct pa_tagstruct *t, int *b);
|
int pa_tagstruct_get_boolean(struct pa_tagstruct *t, int *b);
|
||||||
|
|
|
||||||
|
|
@ -266,7 +266,7 @@ int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_usec_t pa_age(const struct timeval *tv) {
|
pa_usec_t pa_timeval_age(const struct timeval *tv) {
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
assert(tv);
|
assert(tv);
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ char *pa_path_get_filename(const char *p);
|
||||||
|
|
||||||
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b);
|
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);
|
int pa_timeval_cmp(const struct timeval *a, const struct timeval *b);
|
||||||
pa_usec_t pa_age(const struct timeval *tv);
|
pa_usec_t pa_timeval_age(const struct timeval *tv);
|
||||||
void pa_timeval_add(struct timeval *tv, pa_usec_t v);
|
void pa_timeval_add(struct timeval *tv, pa_usec_t v);
|
||||||
|
|
||||||
void pa_raise_priority(void);
|
void pa_raise_priority(void);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue