From 5cd6f2703a7fb8c74e151c831038dd4977df7d1a Mon Sep 17 00:00:00 2001 From: darkeye Date: Tue, 20 Nov 2007 13:59:03 +0000 Subject: [PATCH] applied patch sent by Pierre Souchay , closes #30 --- darkice/trunk/ChangeLog | 2 + darkice/trunk/src/JackDspSource.cpp | 59 +++++++++++++++++++---------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/darkice/trunk/ChangeLog b/darkice/trunk/ChangeLog index 52ffcfd..7f3c0b8 100644 --- a/darkice/trunk/ChangeLog +++ b/darkice/trunk/ChangeLog @@ -2,6 +2,8 @@ Darkice 0.19 to be released o added mount point option for Darwin Streaming Server thanks to Pierre Souchay + o fix for some reliablity issues when using a Jack source + thanks to Pierre Souchay 26-04-2007 DarkIce 0.18.1 released diff --git a/darkice/trunk/src/JackDspSource.cpp b/darkice/trunk/src/JackDspSource.cpp index 77757bd..1a26262 100644 --- a/darkice/trunk/src/JackDspSource.cpp +++ b/darkice/trunk/src/JackDspSource.cpp @@ -277,26 +277,39 @@ bool JackDspSource :: canRead ( unsigned int sec, unsigned int usec ) throw ( Exception ) { - size_t available=0; - + const unsigned int max_wait_time = sec * 1000000; + const unsigned int wait_increment = 10000; + unsigned int cur_wait = 0; + if ( !isOpen() ) { return false; } - - // How many bytes available in ring buffer ? - available = jack_ringbuffer_read_space( rb[0] ); - if (available) return true; - - // Sleep and check again - // FIXME: should we really sleep the full duration ? - usleep( (sec*1000000) + usec ); - - available = jack_ringbuffer_read_space( rb[0] ); - if (available) { - return true; - } else { - return false; + + while (max_wait_time > cur_wait) { + bool canRead = true; + + for (unsigned int c = 0 ; c < getChannel() ; c++) { + if (jack_ringbuffer_read_space(rb[c]) <= 0) { + canRead = false; + } + } + + if (canRead) { + return true; + } + + cur_wait += wait_increment; + usleep ( wait_increment ); } + + usleep( usec ); + for (unsigned int c = 0 ; c < getChannel() ; c++) { + if (jack_ringbuffer_read_space(rb[c]) <= 0) { + return false; + } + } + + return true; } @@ -324,14 +337,22 @@ JackDspSource :: read ( void * buf, throw Exception( __FILE__, __LINE__, "realloc on tmp_buffer failed"); } + // We must be sure to fetch as many data on both channels + int minBytesAvailable = samples * sizeof( jack_default_audio_sample_t ); - for (c=0; c