Added a check in alsa sink if error has occurred due to blocking; if so, it will...
authorTom Rondeau <trondeau@vt.edu>
Sat, 30 Oct 2010 20:29:27 +0000 (16:29 -0400)
committerTom Rondeau <trondeau@vt.edu>
Sat, 30 Oct 2010 20:29:27 +0000 (16:29 -0400)
gr-audio-alsa/src/audio_alsa_sink.cc
gr-audio-alsa/src/audio_alsa_sink.h

index d6b7f84cfb8745723179874e4fc2b25b394cdfc2..c28e23fea64bfaa06e6800c752d1905e38963a9e 100644 (file)
@@ -90,7 +90,7 @@ audio_alsa_sink::audio_alsa_sink (int sampling_rate,
     d_period_size (0),
     d_buffer_size_bytes (0), d_buffer (0),
     d_worker (0), d_special_case_mono_to_stereo (false),
-    d_nunderuns (0), d_nsuspends (0)
+    d_nunderuns (0), d_nsuspends (0), d_ok_to_block(ok_to_block)
 {
   CHATTY_DEBUG = gr_prefs::singleton()->get_bool("audio_alsa", "verbose", false);
 
@@ -100,6 +100,8 @@ audio_alsa_sink::audio_alsa_sink (int sampling_rate,
   // open the device for playback
   error = snd_pcm_open(&d_pcm_handle, d_device_name.c_str (),
                       SND_PCM_STREAM_PLAYBACK, 0);
+  if (ok_to_block == false)
+    snd_pcm_nonblock(d_pcm_handle, !ok_to_block);
   if (error < 0){
     fprintf (stderr, "audio_alsa_sink[%s]: %s\n",
             d_device_name.c_str(), snd_strerror(error));
@@ -287,7 +289,6 @@ audio_alsa_sink::check_topology (int ninputs, int noutputs)
   default:
     assert (0);
   }
-
   return true;
 }
 
@@ -489,7 +490,12 @@ audio_alsa_sink::write_buffer (const void *vbuffer,
   while (nframes > 0){
     int r = snd_pcm_writei (d_pcm_handle, buffer, nframes);
     if (r == -EAGAIN)
-      continue;                        // try again
+    {
+      if (d_ok_to_block == true)
+       continue;               // try again
+      
+      break;
+    }
 
     else if (r == -EPIPE){     // underrun
       d_nunderuns++;
index d4b540382e766d8568e65bd5f812aa33abe08250..f3007f60f8a0503040873966c613776feea07d45 100644 (file)
@@ -83,6 +83,7 @@ class audio_alsa_sink : public gr_sync_block {
   // random stats
   int                  d_nunderuns;            // count of underruns
   int                  d_nsuspends;            // count of suspends
+  bool                 d_ok_to_block;      // defaults to "true", controls blocking/non-block I/O
 
   void output_error_msg (const char *msg, int err);
   void bail (const char *msg, int err) throw (std::runtime_error);