diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-11-08 21:48:25 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-11-08 21:48:25 +0100 |
| commit | 4ea1bc85ee824156cc0fee3c3bfa35dd52fe95cd (patch) | |
| tree | 40e3057e35fa3dff947c3385b2e9937af6f115ab | |
| parent | e91ab84201d0ccb1ec7aff3c410a8ced9e62f62f (diff) | |
Handle all errors from RtAudio getDeviceInfo() calls more calmly.
| -rw-r--r-- | src/wx/config_dialog.cc | 31 | ||||
| -rw-r--r-- | src/wx/film_viewer.cc | 19 |
2 files changed, 34 insertions, 16 deletions
diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index f6fb3c948..154211316 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -177,9 +177,13 @@ GeneralPage::add_play_sound_controls (wxGridBagSizer* table, int& r) RtAudio audio (DCPOMATIC_RTAUDIO_API); for (unsigned int i = 0; i < audio.getDeviceCount(); ++i) { - RtAudio::DeviceInfo dev = audio.getDeviceInfo (i); - if (dev.probed && dev.outputChannels > 0) { - _sound_output->Append (std_to_wx (dev.name)); + try { + RtAudio::DeviceInfo dev = audio.getDeviceInfo (i); + if (dev.probed && dev.outputChannels > 0) { + _sound_output->Append (std_to_wx (dev.name)); + } + } catch (RtAudioError&) { + /* Something went wrong, so let's just ignore that device */ } } @@ -248,7 +252,7 @@ GeneralPage::config_changed () RtAudio audio (DCPOMATIC_RTAUDIO_API); try { configured_so = audio.getDeviceInfo(audio.getDefaultOutputDevice()).name; - } catch (RtAudioError& e) { + } catch (RtAudioError&) { /* Probably no audio devices at all */ } } @@ -281,9 +285,13 @@ GeneralPage::config_changed () int channels = 0; if (configured_so) { for (unsigned int i = 0; i < audio.getDeviceCount(); ++i) { - RtAudio::DeviceInfo info = audio.getDeviceInfo(i); - if (info.name == *configured_so && info.outputChannels > 0) { - channels = info.outputChannels; + try { + RtAudio::DeviceInfo info = audio.getDeviceInfo(i); + if (info.name == *configured_so && info.outputChannels > 0) { + channels = info.outputChannels; + } + } catch (RtAudioError&) { + /* Never mind */ } } } @@ -360,7 +368,14 @@ GeneralPage::sound_output_changed () { RtAudio audio (DCPOMATIC_RTAUDIO_API); optional<string> const so = get_sound_output(); - if (!so || *so == audio.getDeviceInfo(audio.getDefaultOutputDevice()).name) { + string default_device; + try { + default_device = audio.getDeviceInfo(audio.getDefaultOutputDevice()).name; + } catch (RtAudioError&) { + /* Never mind */ + } + + if (!so || *so == default_device) { Config::instance()->unset_sound_output (); } else { Config::instance()->set_sound_output (*so); diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index c05e76f83..726d5c918 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -664,8 +664,12 @@ FilmViewer::config_changed (Config::Property p) unsigned int st = 0; if (Config::instance()->sound_output()) { while (st < _audio.getDeviceCount()) { - if (_audio.getDeviceInfo(st).name == Config::instance()->sound_output().get()) { - break; + try { + if (_audio.getDeviceInfo(st).name == Config::instance()->sound_output().get()) { + break; + } + } catch (RtAudioError&) { + /* Something went wrong with the device so we don't want to use it anyway */ } ++st; } @@ -676,13 +680,12 @@ FilmViewer::config_changed (Config::Property p) st = _audio.getDefaultOutputDevice(); } - _audio_channels = _audio.getDeviceInfo(st).outputChannels; - - RtAudio::StreamParameters sp; - sp.deviceId = st; - sp.nChannels = _audio_channels; - sp.firstChannel = 0; try { + _audio_channels = _audio.getDeviceInfo(st).outputChannels; + RtAudio::StreamParameters sp; + sp.deviceId = st; + sp.nChannels = _audio_channels; + sp.firstChannel = 0; _audio.openStream (&sp, 0, RTAUDIO_FLOAT32, 48000, &_audio_block_size, &rtaudio_callback, this); } catch (RtAudioError& e) { error_dialog ( |
