[pulseaudio-discuss] [PATCH 2/4] alsa-{source, sink}: Remove old smoother code

Georg Chini georg at chini.tk
Sun Jun 5 19:48:56 UTC 2016


The old code is no longer needed.

---
 src/modules/alsa/alsa-sink.c   | 85 ------------------------------------------
 src/modules/alsa/alsa-source.c | 83 +----------------------------------------
 2 files changed, 1 insertion(+), 167 deletions(-)

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 229a3be..d497200 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -51,7 +51,6 @@
 #include <pulsecore/thread.h>
 #include <pulsecore/thread-mq.h>
 #include <pulsecore/rtpoll.h>
-#include <pulsecore/time-smoother.h>
 
 #include <modules/reserve-wrap.h>
 
@@ -77,12 +76,6 @@
 #define TSCHED_MIN_SLEEP_USEC (10*PA_USEC_PER_MSEC)                /* 10ms  -- Sleep at least 10ms on each iteration */
 #define TSCHED_MIN_WAKEUP_USEC (4*PA_USEC_PER_MSEC)                /* 4ms   -- Wakeup at least this long before the buffer runs empty*/
 
-#define SMOOTHER_WINDOW_USEC  (10*PA_USEC_PER_SEC)                 /* 10s   -- smoother windows size */
-#define SMOOTHER_ADJUST_USEC  (1*PA_USEC_PER_SEC)                  /* 1s    -- smoother adjust time */
-
-#define SMOOTHER_MIN_INTERVAL (2*PA_USEC_PER_MSEC)                 /* 2ms   -- min smoother update interval */
-#define SMOOTHER_MAX_INTERVAL (200*PA_USEC_PER_MSEC)               /* 200ms -- max smoother update interval */
-
 #define VOLUME_ACCURACY (PA_VOLUME_NORM/100)  /* don't require volume adjustments to be perfectly correct. don't necessarily extend granularity in software unless the differences get greater than this level */
 
 #define DEFAULT_REWIND_SAFEGUARD_BYTES (256U) /* 1.33ms @48kHz, we'll never rewind less than this */
@@ -142,11 +135,8 @@ struct userdata {
 
     pa_rtpoll_item *alsa_rtpoll_item;
 
-    pa_smoother *smoother;
     uint64_t write_count;
     uint64_t since_start;
-    pa_usec_t smoother_interval;
-    pa_usec_t last_smoother_update;
 
     pa_usec_t start_time;
     pa_usec_t first_start_time;
@@ -963,63 +953,12 @@ static void update_time_estimate(struct userdata *u) {
     u->last_time = time_stamp;
 }
 
-static void update_smoother(struct userdata *u) {
-    snd_pcm_sframes_t delay = 0;
-    int64_t position;
-    int err;
-    pa_usec_t now1 = 0, now2;
-    snd_pcm_status_t *status;
-    snd_htimestamp_t htstamp = { 0, 0 };
-
-    snd_pcm_status_alloca(&status);
-
-    pa_assert(u);
-    pa_assert(u->pcm_handle);
-
-    /* Let's update the time smoother */
-
-    if (PA_UNLIKELY((err = pa_alsa_safe_delay(u->pcm_handle, status, &delay, u->hwbuf_size, &u->sink->sample_spec, false)) < 0)) {
-        pa_log_warn("Failed to query DSP status data: %s", pa_alsa_strerror(err));
-        return;
-    }
-
-    snd_pcm_status_get_htstamp(status, &htstamp);
-    now1 = pa_timespec_load(&htstamp);
-
-    /* Hmm, if the timestamp is 0, then it wasn't set and we take the current time */
-    if (now1 <= 0)
-        now1 = pa_rtclock_now();
-
-    /* check if the time since the last update is bigger than the interval */
-    if (u->last_smoother_update > 0)
-        if (u->last_smoother_update + u->smoother_interval > now1)
-            return;
-
-    position = (int64_t) u->write_count - ((int64_t) delay * (int64_t) u->frame_size);
-
-    if (PA_UNLIKELY(position < 0))
-        position = 0;
-
-    now2 = pa_bytes_to_usec((uint64_t) position, &u->sink->sample_spec);
-
-    pa_smoother_put(u->smoother, now1, now2);
-
-    u->last_smoother_update = now1;
-    /* exponentially increase the update interval up to the MAX limit */
-    u->smoother_interval = PA_MIN (u->smoother_interval * 2, SMOOTHER_MAX_INTERVAL);
-}
-
 static pa_usec_t sink_get_latency(struct userdata *u, bool raw) {
     int64_t delay;
     int64_t now2;
 
     pa_assert(u);
 
-/*    now1 = pa_rtclock_now();
-    now2 = pa_smoother_get(u->smoother, now1);
-
-    delay = (int64_t) pa_bytes_to_usec(u->write_count, &u->sink->sample_spec) - (int64_t) now2; */
-
     /* Convert system time difference to soundcard time difference */
     now2 = (pa_rtclock_now() - u->start_time) * u->time_factor;
 
@@ -1053,8 +992,6 @@ static int suspend(struct userdata *u) {
     pa_assert(u);
     pa_assert(u->pcm_handle);
 
-    pa_smoother_pause(u->smoother, pa_rtclock_now());
-
     /* Let's suspend -- we don't call snd_pcm_drain() here since that might
      * take awfully long with our long buffer sizes today. */
     snd_pcm_close(u->pcm_handle);
@@ -1239,10 +1176,6 @@ static int unsuspend(struct userdata *u) {
         goto fail;
 
     u->write_count = 0;
-    pa_smoother_reset(u->smoother, pa_rtclock_now(), true);
-    u->smoother_interval = SMOOTHER_MIN_INTERVAL;
-    u->last_smoother_update = 0;
-
     u->first = true;
     u->since_start = 0;
 
@@ -1864,12 +1797,8 @@ static void thread_func(void *userdata) {
                     pa_log_info("Starting playback.");
                     snd_pcm_start(u->pcm_handle);
 
-                    pa_smoother_resume(u->smoother, pa_rtclock_now(), true);
-
                     u->first = false;
                 }
-
-                update_smoother(u);
             }
 
             if (u->use_tsched) {
@@ -1898,7 +1827,6 @@ static void thread_func(void *userdata) {
 
                 /* Convert from the sound card time domain to the
                  * system time domain */
-/*                cusec = pa_smoother_translate(u->smoother, pa_rtclock_now(), sleep_usec); */
                 cusec = sleep_usec  * u->time_factor;
 
 #ifdef DEBUG_TIMING
@@ -2254,16 +2182,6 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     u->rtpoll = pa_rtpoll_new();
     pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
 
-    u->smoother = pa_smoother_new(
-            SMOOTHER_ADJUST_USEC,
-            SMOOTHER_WINDOW_USEC,
-            true,
-            true,
-            5,
-            pa_rtclock_now(),
-            true);
-    u->smoother_interval = SMOOTHER_MIN_INTERVAL;
-
     /* use ucm */
     if (mapping && mapping->ucm_context.ucm)
         u->ucm_context = &mapping->ucm_context;
@@ -2622,9 +2540,6 @@ static void userdata_free(struct userdata *u) {
     if (u->mixer_handle)
         snd_mixer_close(u->mixer_handle);
 
-    if (u->smoother)
-        pa_smoother_free(u->smoother);
-
     if (u->formats)
         pa_idxset_free(u->formats, (pa_free_cb_t) pa_format_info_free);
 
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index 55fb30f..c3dd75d 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -46,7 +46,6 @@
 #include <pulsecore/thread.h>
 #include <pulsecore/thread-mq.h>
 #include <pulsecore/rtpoll.h>
-#include <pulsecore/time-smoother.h>
 
 #include <modules/reserve-wrap.h>
 
@@ -70,12 +69,6 @@
 #define TSCHED_MIN_SLEEP_USEC (10*PA_USEC_PER_MSEC)                /* 10ms */
 #define TSCHED_MIN_WAKEUP_USEC (4*PA_USEC_PER_MSEC)                /* 4ms */
 
-#define SMOOTHER_WINDOW_USEC  (10*PA_USEC_PER_SEC)                 /* 10s */
-#define SMOOTHER_ADJUST_USEC  (1*PA_USEC_PER_SEC)                  /* 1s */
-
-#define SMOOTHER_MIN_INTERVAL (2*PA_USEC_PER_MSEC)                 /* 2ms */
-#define SMOOTHER_MAX_INTERVAL (200*PA_USEC_PER_MSEC)               /* 200ms */
-
 #define VOLUME_ACCURACY (PA_VOLUME_NORM/100)
 
 struct userdata {
@@ -129,10 +122,7 @@ struct userdata {
 
     pa_rtpoll_item *alsa_rtpoll_item;
 
-    pa_smoother *smoother;
     uint64_t read_count;
-    pa_usec_t smoother_interval;
-    pa_usec_t last_smoother_update;
 
     pa_usec_t start_time;
     pa_usec_t first_start_time;
@@ -871,59 +861,12 @@ static void update_time_estimate(struct userdata *u) {
     u->last_time = time_stamp;
 }
 
-static void update_smoother(struct userdata *u) {
-    snd_pcm_sframes_t delay = 0;
-    uint64_t position;
-    int err;
-    pa_usec_t now1 = 0, now2;
-    snd_pcm_status_t *status;
-    snd_htimestamp_t htstamp = { 0, 0 };
-
-    snd_pcm_status_alloca(&status);
-
-    pa_assert(u);
-    pa_assert(u->pcm_handle);
-
-    /* Let's update the time smoother */
-
-    if (PA_UNLIKELY((err = pa_alsa_safe_delay(u->pcm_handle, status, &delay, u->hwbuf_size, &u->source->sample_spec, true)) < 0)) {
-        pa_log_warn("Failed to get delay: %s", pa_alsa_strerror(err));
-        return;
-    }
-
-    snd_pcm_status_get_htstamp(status, &htstamp);
-    now1 = pa_timespec_load(&htstamp);
-
-    /* Hmm, if the timestamp is 0, then it wasn't set and we take the current time */
-    if (now1 <= 0)
-        now1 = pa_rtclock_now();
-
-    /* check if the time since the last update is bigger than the interval */
-    if (u->last_smoother_update > 0)
-        if (u->last_smoother_update + u->smoother_interval > now1)
-            return;
-
-    position = u->read_count + ((uint64_t) delay * (uint64_t) u->frame_size);
-    now2 = pa_bytes_to_usec(position, &u->source->sample_spec);
-
-    pa_smoother_put(u->smoother, now1, now2);
-
-    u->last_smoother_update = now1;
-    /* exponentially increase the update interval up to the MAX limit */
-    u->smoother_interval = PA_MIN (u->smoother_interval * 2, SMOOTHER_MAX_INTERVAL);
-}
-
 static pa_usec_t source_get_latency(struct userdata *u, bool raw) {
     int64_t delay;
     int64_t now2;
 
     pa_assert(u);
 
-/*    now1 = pa_rtclock_now();
-    now2 = pa_smoother_get(u->smoother, now1);
-
-    delay = (int64_t) now2 - (int64_t) pa_bytes_to_usec(u->read_count, &u->source->sample_spec); */
-
     /* Convert system time difference to soundcard time difference */
     now2 = (pa_rtclock_now() - u->start_time) * u->time_factor;
 
@@ -954,8 +897,6 @@ static int suspend(struct userdata *u) {
     pa_assert(u);
     pa_assert(u->pcm_handle);
 
-    pa_smoother_pause(u->smoother, pa_rtclock_now());
-
     /* Let's suspend */
     snd_pcm_close(u->pcm_handle);
     u->pcm_handle = NULL;
@@ -1115,10 +1056,6 @@ static int unsuspend(struct userdata *u) {
     /* FIXME: We need to reload the volume somehow */
 
     u->read_count = 0;
-    pa_smoother_reset(u->smoother, pa_rtclock_now(), true);
-    u->smoother_interval = SMOOTHER_MIN_INTERVAL;
-    u->last_smoother_update = 0;
-
     u->first = true;
 
     /* reset the watermark to the value defined when source was created */
@@ -1583,8 +1520,6 @@ static void thread_func(void *userdata) {
                 init_time_estimate(u);
                 snd_pcm_start(u->pcm_handle);
 
-                pa_smoother_resume(u->smoother, pa_rtclock_now(), true);
-
                 u->first = false;
             }
 
@@ -1598,10 +1533,8 @@ static void thread_func(void *userdata) {
 
 /*             pa_log_debug("work_done = %i", work_done); */
 
-            if (work_done) {
-                update_smoother(u);
+            if (work_done)
                 update_time_estimate(u);
-            }
 
             if (u->use_tsched) {
                 pa_usec_t cusec;
@@ -1613,7 +1546,6 @@ static void thread_func(void *userdata) {
 
                 /* Convert from the sound card time domain to the
                  * system time domain */
-/*                cusec = pa_smoother_translate(u->smoother, pa_rtclock_now(), sleep_usec); */
                 cusec = sleep_usec * u->time_factor;
 
 /*                 pa_log_debug("Waking up in %0.2fms (system clock).", (double) cusec / PA_USEC_PER_MSEC); */
@@ -1955,16 +1887,6 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     u->rtpoll = pa_rtpoll_new();
     pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
 
-    u->smoother = pa_smoother_new(
-            SMOOTHER_ADJUST_USEC,
-            SMOOTHER_WINDOW_USEC,
-            true,
-            true,
-            5,
-            pa_rtclock_now(),
-            true);
-    u->smoother_interval = SMOOTHER_MIN_INTERVAL;
-
     /* use ucm */
     if (mapping && mapping->ucm_context.ucm)
         u->ucm_context = &mapping->ucm_context;
@@ -2287,9 +2209,6 @@ static void userdata_free(struct userdata *u) {
     if (u->mixer_handle)
         snd_mixer_close(u->mixer_handle);
 
-    if (u->smoother)
-        pa_smoother_free(u->smoother);
-
     if (u->rates)
         pa_xfree(u->rates);
 
-- 
2.8.1



More information about the pulseaudio-discuss mailing list