Oops. I wasn't waking up the software when the output buffer had space
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 27 May 2014 16:50:34 +0000 (16:50 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 27 May 2014 16:50:34 +0000 (16:50 +0000)
available and there were bytes to output. This made the output buffer
underrun situation worse.

git-svn-id: https://svn.code.sf.net/p/freetel/code@1598 01035d8c-6547-0410-b346-abe4f91aad63

freedv-server/source/run.cpp

index fe9b26ba54f3fc8149c109e899033516b6f4460e..78625cf885bba6976638b2e68e0e2251b3225208 100644 (file)
@@ -32,6 +32,7 @@ namespace FreeDV {
     Interfaces * const i;
     int                        poll_fd_count;
     int                        poll_fd_base;
+    int                        output_fd_base;
     PollType           poll_fds[100];
 
     FIFO               codec_fifo;
@@ -65,7 +66,7 @@ namespace FreeDV {
   };
   
   Run::Run(Interfaces * interfaces)
-  : i(interfaces), poll_fd_count(0), poll_fd_base(0),
+  : i(interfaces), poll_fd_count(0), poll_fd_base(0), output_fd_base(-1),
     codec_fifo(FIFOSize), in_fifo(FIFOSize),
     out_fifo(FIFOSize)
   {
@@ -213,6 +214,22 @@ namespace FreeDV {
       else if ( result < 0 )
        std::cerr << "Transmitter I/O error: " << strerror(errno) << std::endl;
     }
+    if ( out_fifo.get_available() > 0 ) {
+      // There are samples queued for the transmitter. Wake when there is room
+      // in its buffer.
+      if ( output_fd_base < 0 ) {
+        output_fd_base = poll_fd_count;
+        add_poll_device(i->transmitter);
+      }
+    }
+    else {
+      // There are no samples queued for the transmitter. Don't wake upon its
+      // bufffer availability.
+      if ( output_fd_base > 0 ) {
+        poll_fd_count = output_fd_base;
+        output_fd_base = -1;
+      }
+    }
 
     if ( final ) {
       if ( in_fifo.get_available() == 0
@@ -250,6 +267,22 @@ namespace FreeDV {
       else if ( result < 0 )
        std::cerr << "Transmitter I/O error: " << strerror(errno) << std::endl;
     }
+    if ( out_fifo.get_available() > 0 ) {
+      // There are samples queued for the transmitter. Wake when there is room
+      // in its buffer.
+      if ( output_fd_base < 0 ) {
+        output_fd_base = poll_fd_count;
+        add_poll_device(i->transmitter);
+      }
+    }
+    else {
+      // There are no samples queued for the transmitter. Don't wake upon its
+      // bufffer availability.
+      if ( output_fd_base > 0 ) {
+        poll_fd_count = output_fd_base;
+        output_fd_base = -1;
+      }
+    }
     return false;
   }
 
@@ -328,6 +361,23 @@ namespace FreeDV {
       else if ( result < 0 )
        std::cerr << "Loudspeaker I/O error: " << strerror(errno) << std::endl;
     }
+
+    if ( out_fifo.get_available() > 0 ) {
+      // There are samples queued for the loudspeaker. Wake when there is room
+      // in its buffer.
+      if ( output_fd_base < 0 ) {
+        output_fd_base = poll_fd_count;
+        add_poll_device(i->transmitter);
+      }
+    }
+    else {
+      // There are no samples queued for the loudspeaker. Don't wake upon its
+      // bufffer availability.
+      if ( output_fd_base > 0 ) {
+        poll_fd_count = output_fd_base;
+        output_fd_base = -1;
+      }
+    }
   }
    
   // FIX: Once everything else has been tested, make this program work with