Fix audio capture reinitialization
We returned instead of continuing, so audio never worked after reinit. We also had no retry logic if no audio device was available.
This commit is contained in:
parent
86c854ce97
commit
97f18d6353
2 changed files with 27 additions and 7 deletions
|
|
@ -222,14 +222,15 @@ namespace audio {
|
|||
case platf::capture_e::timeout:
|
||||
continue;
|
||||
case platf::capture_e::reinit:
|
||||
BOOST_LOG(info) << "Reinitializing audio capture"sv;
|
||||
mic.reset();
|
||||
mic = control->microphone(stream->mapping, stream->channelCount, stream->sampleRate, frame_size);
|
||||
if (!mic) {
|
||||
BOOST_LOG(error) << "Couldn't re-initialize audio input"sv;
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
do {
|
||||
mic = control->microphone(stream->mapping, stream->channelCount, stream->sampleRate, frame_size);
|
||||
if (!mic) {
|
||||
BOOST_LOG(warning) << "Couldn't re-initialize audio input"sv;
|
||||
}
|
||||
} while (!mic && !shutdown_event->view(5s));
|
||||
continue;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,6 +100,25 @@ namespace safe {
|
|||
return _status;
|
||||
}
|
||||
|
||||
// pop and view shoud not be used interchangeably
|
||||
template <class Rep, class Period>
|
||||
status_t
|
||||
view(std::chrono::duration<Rep, Period> delay) {
|
||||
std::unique_lock ul { _lock };
|
||||
|
||||
if (!_continue) {
|
||||
return util::false_v<status_t>;
|
||||
}
|
||||
|
||||
while (!_status) {
|
||||
if (!_continue || _cv.wait_for(ul, delay) == std::cv_status::timeout) {
|
||||
return util::false_v<status_t>;
|
||||
}
|
||||
}
|
||||
|
||||
return _status;
|
||||
}
|
||||
|
||||
bool
|
||||
peek() {
|
||||
return _continue && (bool) _status;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue