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