Skip to content

Commit 51ec044

Browse files
Fix inaccessible audio device crash
Throw an exception form pa_sink::pa_sink Better exceptions handling in receiver::set_output_device Set conf_ok to false in MainWindow::loadConfig if rx->set_output_device fails.
1 parent f0ff2e1 commit 51ec044

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/applications/gqrx/mainwindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ bool MainWindow::loadConfig(const QString& cfgfile, bool check_crash,
549549
"Please select another device.")
550550
.arg(x.what()),
551551
QMessageBox::Ok);
552+
conf_ok = false;
552553
}
553554

554555
int_val = m_settings->value("input/sample_rate", 0).toInt(&conv_ok);

src/applications/gqrx/receiver.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,16 @@ void receiver::set_output_device(const std::string device)
273273
tb->disconnect(audio_gain0, 0, audio_snk, 0);
274274
tb->disconnect(audio_gain1, 0, audio_snk, 1);
275275
}
276-
audio_snk.reset();
277276

278277
try {
279278
#ifdef WITH_PULSEAUDIO
280-
audio_snk = make_pa_sink(device, d_audio_rate, "GQRX", "Audio output");
279+
auto new_audio_snk = make_pa_sink(device, d_audio_rate, "GQRX", "Audio output");
281280
#elif WITH_PORTAUDIO
282-
audio_snk = make_portaudio_sink(device, d_audio_rate, "GQRX", "Audio output");
281+
auto new_audio_snk = make_portaudio_sink(device, d_audio_rate, "GQRX", "Audio output");
283282
#else
284-
audio_snk = gr::audio::sink::make(d_audio_rate, device, true);
283+
auto new_audio_snk = gr::audio::sink::make(d_audio_rate, device, true);
285284
#endif
286-
285+
audio_snk = new_audio_snk;
287286
if (d_demod != RX_DEMOD_OFF)
288287
{
289288
tb->connect(audio_gain0, 0, audio_snk, 0);
@@ -293,6 +292,12 @@ void receiver::set_output_device(const std::string device)
293292
tb->unlock();
294293

295294
} catch (std::exception &x) {
295+
if (d_demod != RX_DEMOD_OFF)
296+
{
297+
tb->connect(audio_gain0, 0, audio_snk, 0);
298+
tb->connect(audio_gain1, 0, audio_snk, 1);
299+
}
300+
296301
tb->unlock();
297302
// handle problems on non-freeing devices
298303
throw x;

src/pulseaudio/pa_sink.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ pa_sink::pa_sink(const string device_name, int audio_rate,
6969
&error);
7070

7171
if (!d_pasink) {
72-
/** FIXME: Throw an exception **/
7372
fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
73+
throw std::runtime_error("Failed to open pulseaudio device '" + device_name + "'");
7474
}
7575

7676
}
@@ -114,8 +114,8 @@ void pa_sink::select_device(string device_name)
114114
&error);
115115

116116
if (!d_pasink) {
117-
/** FIXME: Throw an exception **/
118117
fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
118+
throw std::runtime_error("Failed to select pulseaudio device '" + device_name + "'");
119119
}
120120
}
121121

0 commit comments

Comments
 (0)