- // frame_length is in TIMEBASE units.
- void add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned num_samples, bmusb::AudioFormat audio_format, int64_t frame_length);
- void add_silence(DeviceSpec device_spec, unsigned samples_per_frame, unsigned num_frames, int64_t frame_length);
+ // Add audio (or silence) to the given device's queue. Can return false if
+ // the lock wasn't successfully taken; if so, you should simply try again.
+ // (This is to avoid a deadlock where a card hangs on the mutex in add_audio()
+ // while we are trying to shut it down from another thread that also holds
+ // the mutex.) frame_length is in TIMEBASE units.
+ bool add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned num_samples, bmusb::AudioFormat audio_format, int64_t frame_length);
+ bool add_silence(DeviceSpec device_spec, unsigned samples_per_frame, unsigned num_frames, int64_t frame_length);
+