Skip to content

Commit

Permalink
fix(anni-playback): add timeout on writing audio (#41)
Browse files Browse the repository at this point in the history
* fix(anni-playback): add timeout on writing audio

* chore(anni-playback): add a todo
  • Loading branch information
snylonue authored Mar 30, 2024
1 parent 1033414 commit dd518b8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions anni-playback/src/utils/blocking_rb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
// You should have received a copy of the GNU Lesser General Public License along with this program.
// If not, see <https://www.gnu.org/licenses/>.

use std::sync::{atomic::AtomicUsize, Arc, Condvar, Mutex};
use std::{
sync::{atomic::AtomicUsize, Arc, Condvar, Mutex},
time::Duration,
};

/// Provides the producer methods of the ring buffer.
#[derive(Clone)]
Expand Down Expand Up @@ -102,8 +105,15 @@ impl<T: Copy + Clone + Default + Sync + Send> BlockingRb<T, Producer> {
// Wait for the event to tell us that there free space
// available or that the operation should be cancelled.
let (mutex, cvar) = &*self.producer_events;
let mut event = mutex.lock().unwrap();
event = cvar.wait(event).unwrap();
let event = mutex.lock().unwrap();
// todo: solve remaining problems in https://github.com/ProjectAnni/anni/pull/41
let (event, timeout) = cvar
.wait_timeout(event, Duration::from_millis(500))
.unwrap();

if timeout.timed_out() {
return None;
}

match *event {
Event::CancelWrite => return None,
Expand Down

0 comments on commit dd518b8

Please sign in to comment.