summaryrefslogtreecommitdiff
path: root/src/pulsecore/source.c
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2010-08-24 13:30:41 +0200
committerWim Taymans <wim.taymans@collabora.co.uk>2010-09-29 18:22:32 +0200
commita38460fefc2d41858b730428e06e8c7a43c78f7c (patch)
tree262b161d9ed217fe4d31888beb8a07a93efaea9d /src/pulsecore/source.c
parentbb19b67ee1ad1cf689b6729d32a848d03d010ec1 (diff)
timings: improve timings by returning latency/time pair
When we ask for the latency, also return the time when the latency calculation was made so that we can use both values to have more accurate timing results.
Diffstat (limited to 'src/pulsecore/source.c')
-rw-r--r--src/pulsecore/source.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 415c54bc3..1a960d791 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -32,6 +32,7 @@
#include <pulse/xmalloc.h>
#include <pulse/timeval.h>
#include <pulse/util.h>
+#include <pulse/rtclock.h>
#include <pulsecore/core-util.h>
#include <pulsecore/source-output.h>
@@ -709,7 +710,7 @@ void pa_source_post_direct(pa_source*s, pa_source_output *o, const pa_memchunk *
/* Called from main thread */
pa_usec_t pa_source_get_latency(pa_source *s) {
- pa_usec_t usec;
+ pa_usec_t usec[2] = { 0, 0 };
pa_source_assert_ref(s);
pa_assert_ctl_context();
@@ -721,36 +722,52 @@ pa_usec_t pa_source_get_latency(pa_source *s) {
if (!(s->flags & PA_SOURCE_LATENCY))
return 0;
- pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) == 0);
+ pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_LATENCY, usec, 0, NULL) == 0);
- return usec;
+ return usec[0];
}
/* Called from IO thread */
-pa_usec_t pa_source_get_latency_within_thread(pa_source *s) {
- pa_usec_t usec = 0;
+void pa_source_get_latency_values_within_thread(pa_source *s, pa_usec_t *latency, pa_usec_t *now) {
+ pa_usec_t usec[2] = { 0, 0 };
pa_msgobject *o;
pa_source_assert_ref(s);
pa_source_assert_io_context(s);
pa_assert(PA_SOURCE_IS_LINKED(s->thread_info.state));
+ *latency = 0;
+ *now = 0;
+
/* The returned value is supposed to be in the time domain of the sound card! */
if (s->thread_info.state == PA_SOURCE_SUSPENDED)
- return 0;
+ return;
if (!(s->flags & PA_SOURCE_LATENCY))
- return 0;
+ return;
o = PA_MSGOBJECT(s);
/* We probably should make this a proper vtable callback instead of going through process_msg() */
- if (o->process_msg(o, PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0)
- return -1;
+ if (o->process_msg(o, PA_SOURCE_MESSAGE_GET_LATENCY, usec, 0, NULL) < 0)
+ return;
+
+ *latency = usec[0];
+ if (usec[1] == 0)
+ *now = pa_rtclock_now();
+ else
+ *now = usec[1];
+}
- return usec;
+/* Called from IO thread */
+pa_usec_t pa_source_get_latency_within_thread(pa_source *s) {
+ pa_usec_t latency, now;
+
+ pa_source_get_latency_values_within_thread(s, &latency, &now);
+
+ return latency;
}
/* Called from main thread */