summaryrefslogtreecommitdiffstats
path: root/src/modules/alsa/alsa-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/alsa/alsa-util.c')
-rw-r--r--src/modules/alsa/alsa-util.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index 0e22d17e..52f12599 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -43,6 +43,7 @@
#include <pulsecore/once.h>
#include <pulsecore/thread.h>
#include <pulsecore/conf-parser.h>
+#include <pulsecore/core-rtclock.h>
#include "alsa-util.h"
#include "alsa-mixer.h"
@@ -258,6 +259,10 @@ int pa_alsa_set_hw_params(
goto finish;
}
+ /* We ignore very small sampling rate deviations */
+ if (_ss.rate >= ss->rate*.95 && _ss.rate <= ss->rate*1.05)
+ _ss.rate = ss->rate;
+
if (require_exact_channel_number) {
if ((ret = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, _ss.channels)) < 0) {
pa_log_debug("snd_pcm_hw_params_set_channels(%u) failed: %s", _ss.channels, pa_alsa_strerror(ret));
@@ -302,7 +307,7 @@ int pa_alsa_set_hw_params(
if (set_buffer_size(pcm_handle, hwparams_copy, _buffer_size) >= 0 &&
set_period_size(pcm_handle, hwparams_copy, _period_size) >= 0 &&
snd_pcm_hw_params(pcm_handle, hwparams_copy) >= 0) {
- pa_log_debug("Set buffer size first, period size second.");
+ pa_log_debug("Set buffer size first (to %lu samples), period size second (to %lu samples).", (unsigned long) _buffer_size, (unsigned long) _period_size);
goto success;
}
@@ -310,7 +315,7 @@ int pa_alsa_set_hw_params(
if (set_period_size(pcm_handle, hwparams_copy, _period_size) >= 0 &&
set_buffer_size(pcm_handle, hwparams_copy, _buffer_size) >= 0 &&
snd_pcm_hw_params(pcm_handle, hwparams_copy) >= 0) {
- pa_log_debug("Set period size first, buffer size second.");
+ pa_log_debug("Set period size first (to %lu samples), buffer size second (to %lu samples).", (unsigned long) _period_size, (unsigned long) _buffer_size);
goto success;
}
}
@@ -321,7 +326,7 @@ int pa_alsa_set_hw_params(
/* Third try: set only buffer size */
if (set_buffer_size(pcm_handle, hwparams_copy, _buffer_size) >= 0 &&
snd_pcm_hw_params(pcm_handle, hwparams_copy) >= 0) {
- pa_log_debug("Set only buffer size second.");
+ pa_log_debug("Set only buffer size (to %lu samples).", (unsigned long) _buffer_size);
goto success;
}
}
@@ -332,7 +337,7 @@ int pa_alsa_set_hw_params(
/* Fourth try: set only period size */
if (set_period_size(pcm_handle, hwparams_copy, _period_size) >= 0 &&
snd_pcm_hw_params(pcm_handle, hwparams_copy) >= 0) {
- pa_log_debug("Set only period size second.");
+ pa_log_debug("Set only period size (to %lu samples).", (unsigned long) _period_size);
goto success;
}
}
@@ -373,9 +378,7 @@ success:
goto finish;
}
- /* If the sample rate deviates too much, we need to resample */
- if (_ss.rate < ss->rate*.95 || _ss.rate > ss->rate*1.05)
- ss->rate = _ss.rate;
+ ss->rate = _ss.rate;
ss->channels = _ss.channels;
ss->format = _ss.format;
@@ -1308,3 +1311,26 @@ const char* pa_alsa_strerror(int errnum) {
return translated;
}
+
+pa_bool_t pa_alsa_may_tsched(pa_bool_t want) {
+
+ if (!want)
+ return FALSE;
+
+ if (!pa_rtclock_hrtimer()) {
+ /* We cannot depend on being woken up in time when the timers
+ are inaccurate, so let's fallback to classic IO based playback
+ then. */
+ pa_log_notice("Disabling timer-based scheduling because high-resolution timers are not available from the kernel.");
+ return FALSE; }
+
+ if (pa_running_in_vm()) {
+ /* We cannot depend on being woken up when we ask for in a VM,
+ * so let's fallback to classic IO based playback then. */
+ pa_log_notice("Disabling timer-based scheduling because running inside a VM.");
+ return FALSE;
+ }
+
+
+ return TRUE;
+}