Hello all@list,

MPD's ALSA input plugin works since
791efc171a35848bb062aad0aee41220cd1f62ba in SND_PCM_NONBLOCK mode.
According to ALSA documentation
http://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.html#ga4c2c7bd26cf221268d59dc3bbeb9c048
snd_pcm_readi does not wait in non-blocking mode. This causes a loop,
resulting in a high cpu load.

Patch adds wait with 500ms timeout. Thanks to kuikka for clarification.


diff --git a/src/input/plugins/AlsaInputPlugin.cxx
b/src/input/plugins/AlsaInputPlugin.cxx
index 9607398e0..04dbf24ee 100644
--- a/src/input/plugins/AlsaInputPlugin.cxx
+++ b/src/input/plugins/AlsaInputPlugin.cxx
@@ -199,8 +199,12 @@ AlsaInputStream::DispatchSockets()
        snd_pcm_sframes_t n_frames;
        while ((n_frames = snd_pcm_readi(capture_handle,
                                         w.data, w_frames)) < 0) {
-               if (n_frames == -EAGAIN)
-                       return;
+
+               if (n_frames == -EAGAIN) {
+                       if (Recover(snd_pcm_wait(capture_handle, 500)) <
0) {
+                               return;
+                       }
+               }

                if (Recover(n_frames) < 0) {
                        postponed_exception =
std::make_exception_ptr(std::runtime_error("PCM error - stream aborted"));



Best regards,
jr.
_______________________________________________
mpd-devel mailing list
mpd-devel@musicpd.org
http://mailman.blarg.de/listinfo/mpd-devel

Reply via email to