[pulseaudio-discuss] [PATCH] alsa: disable period wakeups in tsched mode if possible

Pierre-Louis Bossart bossart.nospam at gmail.com
Mon Nov 29 09:26:30 PST 2010


alsa-lib now provides additional features to disable period
wakeups if hardware can work without it (HDAudio, oxygen and
Intel SST). This patch reflects this new capability that
Lennart was wishing for. Wish granted...

This patch is providing for testing purposes at this time.
It requires the latest alsa kernel and lib code. Once
ALSA maintainers release a new version, we can add an explicit
compilation dependency.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart at intel.com>
---
 src/modules/alsa/alsa-util.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index 5a726ff..6446352 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -204,6 +204,7 @@ int pa_alsa_set_hw_params(
     int ret = -1;
     snd_pcm_hw_params_t *hwparams, *hwparams_copy;
     int dir;
+    unsigned int no_wakeup;
     snd_pcm_uframes_t _period_size = period_size ? *period_size : 0;
     snd_pcm_uframes_t _buffer_size = buffer_size ? *buffer_size : 0;
     pa_bool_t _use_mmap = use_mmap && *use_mmap;
@@ -251,6 +252,20 @@ int pa_alsa_set_hw_params(
     if (!pa_alsa_pcm_is_hw(pcm_handle))
         _use_tsched = FALSE;
 
+    if (_use_tsched) {
+
+        /* try to disable period wakeups if hardware can do so */
+        if (snd_pcm_hw_params_can_disable_period_wakeup(hwparams)) {
+
+            if (snd_pcm_hw_params_set_period_wakeup(pcm_handle, hwparams, FALSE) < 0)
+                /* don't bail, keep going with default mode with period wakeups */
+                pa_log_debug("snd_pcm_hw_params_set_period_wakeup() failed: %s", pa_alsa_strerror(ret));
+            else
+                pa_log_info("Trying to disable ALSA period wakeups, using timers only");
+        } else
+            pa_log_info("cannot disable ALSA period wakeups");
+    }
+
     if ((ret = set_format(pcm_handle, hwparams, &_ss.format)) < 0)
         goto finish;
 
@@ -378,6 +393,13 @@ success:
         goto finish;
     }
 
+    /* see if period wakeups were disabled */
+    snd_pcm_hw_params_get_period_wakeup(pcm_handle, hwparams, &no_wakeup);
+    if (no_wakeup == 0)
+        pa_log_info("ALSA period wakeups disabled");
+    else
+        pa_log_info("ALSA period wakeups were not disabled");
+
     ss->rate = _ss.rate;
     ss->channels = _ss.channels;
     ss->format = _ss.format;
-- 
1.7.2.3




More information about the pulseaudio-discuss mailing list