Oops, I broke drain_ssb().
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 28 May 2014 21:19:28 +0000 (21:19 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 28 May 2014 21:19:28 +0000 (21:19 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1605 01035d8c-6547-0410-b346-abe4f91aad63

freedv-server/source/platform/linux/audio_out_alsa.cpp
freedv-server/source/run.cpp

index e14daa27b6547f6dd366fc0f4f965bd3bab4c994..d20d983c74e2e3a7c43ae0bfd4424d3f0640d56f 100644 (file)
@@ -161,15 +161,10 @@ namespace FreeDV {
     }
 
     if ( error >= 0 )
-      return error;
+      return error; // This is the normal output.
     else if ( error == -EPIPE ) {
       // This is an unlikely condition, but should not be allowed to abort
       // the program.
-      // About the only reason this might happen would be a failure of
-      // real-time schduling, for example a system management interrupt
-      // outside of the control of the operating system, or a problem with
-      // the sound hardware or driver. Punt and hope it gets better the next
-      // time.
       std::cerr << "ALSA output \"" << parameters
        << "\": double write underrun." << std::endl;
       return 0;
index 52231027a6f3c814c1509c4617c9ba40e107b5ac..bba6642b9174c33eb09089b5ab1c1603a9422111 100644 (file)
@@ -143,7 +143,7 @@ namespace FreeDV {
     if ( final ) {
       const std::size_t samples_per_frame = i->codec->samples_per_frame();
       if ( samples_to_encode < samples_per_frame && samples_to_encode > 0 ) {
-        const std::size_t fill = samples_per_frame - samples_to_encode;
+        const std::size_t fill = min(in_fifo.put_space() / 2, (samples_per_frame - samples_to_encode));
         const std::size_t bytes = fill * 2;
         memset(in_fifo.put(bytes), 0, bytes);
         in_fifo.put_done(bytes);
@@ -175,7 +175,7 @@ namespace FreeDV {
     if ( final && in_fifo.get_available() == 0 ) {
       const std::size_t bytes_per_frame = i->modem->bytes_per_frame();
       if ( bytes_to_modulate < bytes_per_frame && bytes_to_modulate > 0 ) {
-        const std::size_t fill = bytes_per_frame - bytes_to_modulate;
+        const std::size_t fill = min(codec_fifo.put_space(), (bytes_per_frame - bytes_to_modulate));
         memset(codec_fifo.put(fill), 0, fill);
         codec_fifo.put_done(fill);
         bytes_to_modulate += fill;
@@ -283,6 +283,12 @@ namespace FreeDV {
         output_fd_base = -1;
       }
     }
+
+    if ( final ) {
+      if ( in_fifo.get_available() == 0
+       &&  out_fifo.get_available() == 0 )
+        return true;
+    }
     return false;
   }