[pulseaudio-discuss] [PATCH] alsa-sink/source: Fix "Scheduling delay of..." message
David Henningsson
david.henningsson at canonical.com
Wed Jun 12 04:49:05 PDT 2013
The tsched_watermark is in bytes, not in usecs. Fix this by introducing
a new variable, and also use that variable in some places for optimisation.
Signed-off-by: David Henningsson <david.henningsson at canonical.com>
---
src/modules/alsa/alsa-sink.c | 21 ++++++++++++---------
src/modules/alsa/alsa-source.c | 22 +++++++++++++---------
2 files changed, 25 insertions(+), 18 deletions(-)
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 97fddbf..68d2c45 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -129,6 +129,7 @@ struct userdata {
pa_usec_t watermark_dec_not_before;
pa_usec_t min_latency_ref;
+ pa_usec_t tsched_watermark_usec;
pa_memchunk memchunk;
@@ -318,6 +319,8 @@ static void fix_tsched_watermark(struct userdata *u) {
if (u->tsched_watermark < u->min_wakeup)
u->tsched_watermark = u->min_wakeup;
+
+ u->tsched_watermark_usec = pa_bytes_to_usec(u->tsched_watermark, &u->sink->sample_spec);
}
static void increase_watermark(struct userdata *u) {
@@ -334,7 +337,7 @@ static void increase_watermark(struct userdata *u) {
if (old_watermark != u->tsched_watermark) {
pa_log_info("Increasing wakeup watermark to %0.2f ms",
- (double) pa_bytes_to_usec(u->tsched_watermark, &u->sink->sample_spec) / PA_USEC_PER_MSEC);
+ (double) u->tsched_watermark_usec / PA_USEC_PER_MSEC);
return;
}
@@ -384,7 +387,7 @@ static void decrease_watermark(struct userdata *u) {
if (old_watermark != u->tsched_watermark)
pa_log_info("Decreasing wakeup watermark to %0.2f ms",
- (double) pa_bytes_to_usec(u->tsched_watermark, &u->sink->sample_spec) / PA_USEC_PER_MSEC);
+ (double) u->tsched_watermark_usec / PA_USEC_PER_MSEC);
/* We don't change the latency range*/
@@ -406,7 +409,7 @@ static void hw_sleep_time(struct userdata *u, pa_usec_t *sleep_usec, pa_usec_t*p
if (usec == (pa_usec_t) -1)
usec = pa_bytes_to_usec(u->hwbuf_size, &u->sink->sample_spec);
- wm = pa_bytes_to_usec(u->tsched_watermark, &u->sink->sample_spec);
+ wm = u->tsched_watermark_usec;
if (wm > usec)
wm = usec/2;
@@ -677,7 +680,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
pa_usec_t underrun_sleep = pa_bytes_to_usec_round_up(input_underrun, &u->sink->sample_spec);
*sleep_usec = pa_bytes_to_usec(left_to_play, &u->sink->sample_spec);
- process_usec = pa_bytes_to_usec(u->tsched_watermark, &u->sink->sample_spec);
+ process_usec = u->tsched_watermark_usec;
if (*sleep_usec > process_usec)
*sleep_usec -= process_usec;
@@ -832,7 +835,7 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
pa_usec_t underrun_sleep = pa_bytes_to_usec_round_up(input_underrun, &u->sink->sample_spec);
*sleep_usec = pa_bytes_to_usec(left_to_play, &u->sink->sample_spec);
- process_usec = pa_bytes_to_usec(u->tsched_watermark, &u->sink->sample_spec);
+ process_usec = u->tsched_watermark_usec;
if (*sleep_usec > process_usec)
*sleep_usec -= process_usec;
@@ -1049,7 +1052,7 @@ static void reset_watermark(struct userdata *u, size_t tsched_watermark, pa_samp
}
pa_log_info("Time scheduling watermark is %0.2fms",
- (double) pa_bytes_to_usec(u->tsched_watermark, ss) / PA_USEC_PER_MSEC);
+ (double) u->tsched_watermark_usec / PA_USEC_PER_MSEC);
}
/* Called from IO context */
@@ -1823,10 +1826,10 @@ static void thread_func(void *userdata) {
(double) rtpoll_sleep / PA_USEC_PER_MSEC, (double) real_sleep / PA_USEC_PER_MSEC,
(double) ((int64_t) real_sleep - (int64_t) rtpoll_sleep) / PA_USEC_PER_MSEC);
#endif
- if (u->use_tsched && real_sleep > rtpoll_sleep + u->tsched_watermark)
- pa_log_info("Scheduling delay of %0.2fms > %0.2fms, you might want to investigate this to improve latency...",
+ if (u->use_tsched && real_sleep > rtpoll_sleep + u->tsched_watermark_usec)
+ pa_log_info("Scheduling delay of %0.2f ms > %0.2f ms, you might want to investigate this to improve latency...",
(double) (real_sleep - rtpoll_sleep) / PA_USEC_PER_MSEC,
- (double) (u->tsched_watermark) / PA_USEC_PER_MSEC);
+ (double) (u->tsched_watermark_usec) / PA_USEC_PER_MSEC);
}
if (u->sink->flags & PA_SINK_DEFERRED_VOLUME)
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index dedb673..15b6aeb 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -118,6 +118,7 @@ struct userdata {
pa_usec_t watermark_dec_not_before;
pa_usec_t min_latency_ref;
+ pa_usec_t tsched_watermark_usec;
char *device_name; /* name of the PCM device */
char *control_device; /* name of the control device */
@@ -293,6 +294,8 @@ static void fix_tsched_watermark(struct userdata *u) {
if (u->tsched_watermark < u->min_wakeup)
u->tsched_watermark = u->min_wakeup;
+
+ u->tsched_watermark_usec = pa_bytes_to_usec(u->tsched_watermark, &u->source->sample_spec);
}
static void increase_watermark(struct userdata *u) {
@@ -309,7 +312,7 @@ static void increase_watermark(struct userdata *u) {
if (old_watermark != u->tsched_watermark) {
pa_log_info("Increasing wakeup watermark to %0.2f ms",
- (double) pa_bytes_to_usec(u->tsched_watermark, &u->source->sample_spec) / PA_USEC_PER_MSEC);
+ (double) u->tsched_watermark_usec / PA_USEC_PER_MSEC);
return;
}
@@ -359,7 +362,7 @@ static void decrease_watermark(struct userdata *u) {
if (old_watermark != u->tsched_watermark)
pa_log_info("Decreasing wakeup watermark to %0.2f ms",
- (double) pa_bytes_to_usec(u->tsched_watermark, &u->source->sample_spec) / PA_USEC_PER_MSEC);
+ (double) u->tsched_watermark_usec / PA_USEC_PER_MSEC);
/* We don't change the latency range*/
@@ -381,7 +384,7 @@ static void hw_sleep_time(struct userdata *u, pa_usec_t *sleep_usec, pa_usec_t*p
if (usec == (pa_usec_t) -1)
usec = pa_bytes_to_usec(u->hwbuf_size, &u->source->sample_spec);
- wm = pa_bytes_to_usec(u->tsched_watermark, &u->source->sample_spec);
+ wm = u->tsched_watermark_usec;
if (wm > usec)
wm = usec/2;
@@ -625,7 +628,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
if (u->use_tsched) {
*sleep_usec = pa_bytes_to_usec(left_to_record, &u->source->sample_spec);
- process_usec = pa_bytes_to_usec(u->tsched_watermark, &u->source->sample_spec);
+ process_usec = u->tsched_watermark_usec;
if (*sleep_usec > process_usec)
*sleep_usec -= process_usec;
@@ -755,7 +758,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
if (u->use_tsched) {
*sleep_usec = pa_bytes_to_usec(left_to_record, &u->source->sample_spec);
- process_usec = pa_bytes_to_usec(u->tsched_watermark, &u->source->sample_spec);
+ process_usec = u->tsched_watermark_usec;
if (*sleep_usec > process_usec)
*sleep_usec -= process_usec;
@@ -941,7 +944,7 @@ static void reset_watermark(struct userdata *u, size_t tsched_watermark, pa_samp
}
pa_log_info("Time scheduling watermark is %0.2fms",
- (double) pa_bytes_to_usec(u->tsched_watermark, ss) / PA_USEC_PER_MSEC);
+ (double) u->tsched_watermark_usec / PA_USEC_PER_MSEC);
}
/* Called from IO context */
@@ -1534,9 +1537,10 @@ static void thread_func(void *userdata) {
(double) rtpoll_sleep / PA_USEC_PER_MSEC, (double) real_sleep / PA_USEC_PER_MSEC,
(double) ((int64_t) real_sleep - (int64_t) rtpoll_sleep) / PA_USEC_PER_MSEC);
#endif
- if (u->use_tsched && real_sleep > rtpoll_sleep + u->tsched_watermark)
- pa_log_info("Scheduling delay of %0.2fms, you might want to investigate this to improve latency...",
- (double) (real_sleep - rtpoll_sleep) / PA_USEC_PER_MSEC);
+ if (u->use_tsched && real_sleep > rtpoll_sleep + u->tsched_watermark_usec)
+ pa_log_info("Scheduling delay of %0.2f ms > %0.2f ms, you might want to investigate this to improve latency...",
+ (double) (real_sleep - rtpoll_sleep) / PA_USEC_PER_MSEC,
+ (double) (u->tsched_watermark_usec) / PA_USEC_PER_MSEC);
}
if (u->source->flags & PA_SOURCE_DEFERRED_VOLUME)
--
1.7.9.5
More information about the pulseaudio-discuss
mailing list