[Bug 70802] artsd fails at using a modern alsa setup: pcm.default not used

Allan Sandfeld kde at carewolf.com
Wed Mar 31 22:28:34 BST 2004


------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
      
http://bugs.kde.org/show_bug.cgi?id=70802      




------- Additional Comments From kde carewolf com  2004-03-31 23:28 -------
CVS commit by carewolf: 

Avoid infinite loops when playing through DMix.

CCMAIL: 70802 bugs kde org


  M +45 -25    audioioalsa9.cc   1.7


--- arts/flow/audioioalsa9.cc  #1.6:1.7
 @ -72,5 +72,7  @ protected:
         int m_period_size, m_periods;
         bool inProgress;
+        bool restartIOHandling;
 
+        void startIO();
         int poll2iomanager(int pollTypes);
         int setPcmParams(snd_pcm_t *pcm);
 @ -118,4 +120,6  @ AudioIOALSA::AudioIOALSA()
         m_pcm_capture = NULL;
         inProgress = false;
+        restartIOHandling = false;
+        audio_read_fd = audio_write_fd = -1;
 }
 
 @ -196,14 +200,6  @ bool AudioIOALSA::open()
                   (float)(2.0 * _samplingRate * _channels)*1000.0);
 
-        /* watch PCM file descriptor(s) */
-        Dispatcher::the()->ioManager()->remove(this, IOType::all);
-        audio_read_fd = audio_write_fd = -1;
-        if (_direction & directionWrite) {
-                audio_write_fd = watchDescriptor(m_pcm_playback);
-        }
-        if (_direction & directionRead) {
-                audio_read_fd = watchDescriptor(m_pcm_capture);
-        }
 
+        startIO();
         /* restore the format value */
         switch (m_format) {
 @ -311,4 +307,16  @ int AudioIOALSA::getParam(AudioParam p)
 }
 
+void AudioIOALSA::startIO()
+{
+        /* watch PCM file descriptor(s) */
+        if (m_pcm_playback) {
+                audio_write_fd = watchDescriptor(m_pcm_playback);
+        }
+        if (m_pcm_capture) {
+                audio_read_fd = watchDescriptor(m_pcm_capture);
+        }
+
+}
+
 int AudioIOALSA::poll2iomanager(int pollTypes)
 {
 @ -352,5 +360,4  @ int AudioIOALSA::xrun(snd_pcm_t *pcm)
         if ((err = snd_pcm_prepare(pcm)) < 0)
                 return err;
-        if (pcm == m_pcm_capture)
                 snd_pcm_start(pcm); // ignore error here..
         return 0;
 @ -367,5 +374,4  @ int AudioIOALSA::resume(snd_pcm_t *pcm)
                 if ((err = snd_pcm_prepare(pcm)) < 0)
                         return err;
-                if (pcm == m_pcm_capture)
                         snd_pcm_start(pcm); // ignore error here..
         }
 @ -395,4 +401,8  @ int AudioIOALSA::read(void *buffer, int 
 int AudioIOALSA::write(void *buffer, int size)
 {
+        // DMix has an annoying habit of returning instantantly on the returned
+        // poll-descriptor. So we block here to avoid an infinity loop.
+        while(snd_pcm_wait(m_pcm_playback, 1) == 0);
+
         int frames = snd_pcm_bytes_to_frames(m_pcm_playback, size);
         int length;
 @ -416,5 +426,13  @ void AudioIOALSA::notifyIO(int fd, int t
     int todo = 0;
 
-    if (inProgress) return;
+        if(inProgress)
+        {
+                if(!restartIOHandling)
+                {
+                        Dispatcher::the()->ioManager()->remove(this,IOType::all);
+                        restartIOHandling = true;
+                }
+                return;
+        }
 
     // We can't trust the type as ALSA might have read-type events,
 @ -425,8 +443,10  @ void AudioIOALSA::notifyIO(int fd, int t
     if (type & IOType::except) todo |= AudioSubSystem::ioExcept;
 
+        restartIOHandling = false;
     inProgress = true;
     AudioSubSystem::the()->handleIO(todo);
     inProgress = false;
 
+        if (restartIOHandling) startIO();
 }



More information about the kde-multimedia mailing list