Skip to content

Commit

Permalink
Check and report on pulseaudio errors.
Browse files Browse the repository at this point in the history
Fixes #285 - Hangs when pulseaudio is not present.
  • Loading branch information
csete committed Nov 10, 2017
1 parent 884d5d9 commit ad9b582
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/applications/gqrx/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QDesktopServices>
#include <QDir>
#include <QFile>
#include <QMessageBox>
#include <QString>
#include <QStringList>
#include <QStyleFactory>
Expand All @@ -33,6 +34,10 @@
#ifdef WITH_PORTAUDIO
#include <portaudio.h>
#endif
#ifdef WITH_PULSEAUDIO
#include <pulse/error.h>
#include <pulse/simple.h>
#endif

#include "mainwindow.h"
#include "gqrx.h"
Expand Down Expand Up @@ -67,13 +72,6 @@ int main(int argc, char *argv[])
else
qDebug() << "Failed to disable controlport";

#ifdef WITH_PORTAUDIO
PaError err = Pa_Initialize();
if (err != paNoError)
qCritical() << "Failed to initialize Portaudio backend:"
<< Pa_GetErrorText(err);
#endif

// setup the program options
po::options_description desc("Command line options");
desc.add_options()
Expand Down Expand Up @@ -120,6 +118,41 @@ int main(int argc, char *argv[])
return 0;
}

// check whether audio backend is functional
#ifdef WITH_PORTAUDIO
PaError err = Pa_Initialize();
if (err != paNoError)
{
QString message = QString("Portaudio error: %1").arg(Pa_GetErrorText(err));
qCritical() << message;
QMessageBox::critical(0, "Audio Error", message,
QMessageBox::Abort, QMessageBox::NoButton);
return 1;
}
#endif

#ifdef WITH_PULSEAUDIO
int error = 0;
pa_simple *test_sink;
pa_sample_spec ss;

ss.format = PA_SAMPLE_FLOAT32LE;
ss.rate = 48000;
ss.channels = 2;
test_sink = pa_simple_new(NULL, "Gqrx Test", PA_STREAM_PLAYBACK, NULL,
"Test stream", &ss, NULL, NULL, &error);
if (!test_sink)
{
QString message = QString("Pulseaudio error: %1").arg(pa_strerror(error));
qCritical() << message;
QMessageBox::critical(0, "Audio Error", message,
QMessageBox::Abort, QMessageBox::NoButton);
return 1;
}
pa_simple_free(test_sink);
#endif


if (!conf.empty())
{
cfg_file = QString::fromStdString(conf);
Expand Down

0 comments on commit ad9b582

Please sign in to comment.