spu: don't block on audio
authornotaz <notasas@gmail.com>
Mon, 5 Jan 2015 21:50:33 +0000 (23:50 +0200)
committernotaz <notasas@gmail.com>
Fri, 9 Jan 2015 23:57:56 +0000 (01:57 +0200)
plugins/dfsound/alsa.c
plugins/dfsound/oss.c

index b5655a9..6b9f83e 100644 (file)
@@ -195,8 +195,21 @@ static void alsa_feed(void *pSound, int lBytes)
    snd_pcm_prepare(handle);
    snd_pcm_writei(handle, sbuf, sizeof(sbuf) / 4);
    snd_pcm_writei(handle, sbuf, sizeof(sbuf) / 4);
    snd_pcm_prepare(handle);
    snd_pcm_writei(handle, sbuf, sizeof(sbuf) / 4);
    snd_pcm_writei(handle, sbuf, sizeof(sbuf) / 4);
+   snd_pcm_writei(handle, sbuf, sizeof(sbuf) / 4);
+  }
+ else
+  {
+   int l = snd_pcm_avail(handle);
+   if (l < lBytes / 4)
+    {
+     if (l == 0)
+      return;
+
+     lBytes = l * 4;
+    }
   }
   }
- snd_pcm_writei(handle,pSound, lBytes / 4);
+
+ snd_pcm_writei(handle, pSound, lBytes / 4);
 }
 
 void out_register_alsa(struct out_driver *drv)
 }
 
 void out_register_alsa(struct out_driver *drv)
index 8093ae4..6b1cb4a 100644 (file)
@@ -34,6 +34,9 @@
 
 #define OSS_SPEED_44100     44100
 
 
 #define OSS_SPEED_44100     44100
 
+#define FRAGMENT_SHIFT 12
+#define FRAGMENT_SIZE  (1 << FRAGMENT_SHIFT)
+
 static int oss_audio_fd = -1;
 extern int errno;
 
 static int oss_audio_fd = -1;
 extern int errno;
 
@@ -46,7 +49,6 @@ static int oss_init(void)
  int pspeed=44100;
  int pstereo;
  int format;
  int pspeed=44100;
  int pstereo;
  int format;
- int fragsize = 0;
  int myfrag;
  int oss_speed, oss_stereo;
 
  int myfrag;
  int oss_speed, oss_stereo;
 
@@ -69,8 +71,7 @@ static int oss_init(void)
  // we use 64 fragments with 1024 bytes each
  // rearmed: now using 10*4096 for better latency
 
  // we use 64 fragments with 1024 bytes each
  // rearmed: now using 10*4096 for better latency
 
- fragsize=12;
- myfrag=(10<<16)|fragsize;
+ myfrag = (10<<16) | FRAGMENT_SHIFT;
 
  if(ioctl(oss_audio_fd,SNDCTL_DSP_SETFRAGMENT,&myfrag)==-1)
   {
 
  if(ioctl(oss_audio_fd,SNDCTL_DSP_SETFRAGMENT,&myfrag)==-1)
   {
@@ -160,11 +161,18 @@ static void oss_feed(void *buf, int bytes)
  if(oss_audio_fd == -1) return;
  if(ioctl(oss_audio_fd,SNDCTL_DSP_GETOSPACE,&info)==0)
   {
  if(oss_audio_fd == -1) return;
  if(ioctl(oss_audio_fd,SNDCTL_DSP_GETOSPACE,&info)==0)
   {
+   // for fast forward
+   if(bytes > info.fragments * FRAGMENT_SIZE)
+    bytes = info.fragments * FRAGMENT_SIZE;
+   if(bytes == 0)
+    return;
+
    if(info.fragments==info.fragstotal)
     {
      memset(sbuf, 0, sizeof(sbuf));
      write(oss_audio_fd, sbuf, sizeof(sbuf));
      write(oss_audio_fd, sbuf, sizeof(sbuf));
    if(info.fragments==info.fragstotal)
     {
      memset(sbuf, 0, sizeof(sbuf));
      write(oss_audio_fd, sbuf, sizeof(sbuf));
      write(oss_audio_fd, sbuf, sizeof(sbuf));
+     write(oss_audio_fd, sbuf, sizeof(sbuf));
     }
   }
 
     }
   }