Hopefully fix hang on exit when trying to close audio thread.

merge-requests/5/head
Phil Taylor 2021-06-03 12:05:28 +01:00
rodzic 2aefbe5dcd
commit 9de6d64dab
2 zmienionych plików z 12 dodań i 7 usunięć

Wyświetl plik

@ -25,8 +25,8 @@ audioHandler::~audioHandler()
speex_resampler_destroy(resampler); speex_resampler_destroy(resampler);
} }
if (isInitialized) {
if (audio != Q_NULLPTR) {
try { try {
audio->abortStream(); audio->abortStream();
audio->closeStream(); audio->closeStream();
@ -34,6 +34,9 @@ audioHandler::~audioHandler()
catch (RtAudioError& e) { catch (RtAudioError& e) {
qInfo(logAudio()) << "Error closing stream:" << aParams.deviceId << ":" << QString::fromStdString(e.getMessage()); qInfo(logAudio()) << "Error closing stream:" << aParams.deviceId << ":" << QString::fromStdString(e.getMessage());
} }
}
if (audio != Q_NULLPTR) {
delete audio; delete audio;
} }
@ -85,7 +88,7 @@ bool audioHandler::init(const quint8 bits, const quint8 radioChan, const quint16
} }
catch (RtAudioError& e) { catch (RtAudioError& e) {
qInfo(logAudio()) << "Device error:" << aParams.deviceId << ":" << QString::fromStdString(e.getMessage()); qInfo(logAudio()) << "Device error:" << aParams.deviceId << ":" << QString::fromStdString(e.getMessage());
return false; return isInitialized;
} }
if (info.probed) if (info.probed)
@ -150,6 +153,7 @@ bool audioHandler::init(const quint8 bits, const quint8 radioChan, const quint16
try { try {
audio->openStream(NULL, &aParams, RTAUDIO_SINT16, nativeSampleRate, &this->chunkSize, &staticWrite, this, &options); audio->openStream(NULL, &aParams, RTAUDIO_SINT16, nativeSampleRate, &this->chunkSize, &staticWrite, this, &options);
audio->startStream(); audio->startStream();
isInitialized = true;
} }
catch (RtAudioError& e) { catch (RtAudioError& e) {
qInfo(logAudio()) << "Error opening:" << QString::fromStdString(e.getMessage()); qInfo(logAudio()) << "Error opening:" << QString::fromStdString(e.getMessage());
@ -162,6 +166,7 @@ bool audioHandler::init(const quint8 bits, const quint8 radioChan, const quint16
try { try {
audio->openStream(&aParams, NULL, RTAUDIO_SINT16, this->nativeSampleRate, &this->chunkSize, &staticRead, this, &options); audio->openStream(&aParams, NULL, RTAUDIO_SINT16, this->nativeSampleRate, &this->chunkSize, &staticRead, this, &options);
audio->startStream(); audio->startStream();
isInitialized = true;
} }
catch (RtAudioError& e) { catch (RtAudioError& e) {
qInfo(logAudio()) << "Error opening:" << QString::fromStdString(e.getMessage()); qInfo(logAudio()) << "Error opening:" << QString::fromStdString(e.getMessage());
@ -320,7 +325,7 @@ void audioHandler::incomingAudio(audioPacket inPacket)
// Regardless of the radio stream format, the buffered audio will ALWAYS be // Regardless of the radio stream format, the buffered audio will ALWAYS be
// 16bit sample interleaved stereo 48K (or whatever the native sample rate is) // 16bit sample interleaved stereo 48K (or whatever the native sample rate is)
if (!audio->isStreamRunning()) if (!isInitialized || !audio->isStreamRunning())
{ {
qDebug(logAudio()) << "Packet received before stream was started"; qDebug(logAudio()) << "Packet received before stream was started";
return; return;
@ -424,7 +429,7 @@ void audioHandler::getNextAudioChunk(QByteArray& ret)
audioPacket packet; audioPacket packet;
packet.sent = 0; packet.sent = 0;
if (ringBuf != Q_NULLPTR && ringBuf->try_read(packet)) if (isInitialized && ringBuf != Q_NULLPTR && ringBuf->try_read(packet))
{ {
//qDebug(logAudio) << "Chunksize" << this->chunkSize << "Packet size" << packet.data.length(); //qDebug(logAudio) << "Chunksize" << this->chunkSize << "Packet size" << packet.data.length();

Wyświetl plik

@ -78,7 +78,7 @@ private:
void reinit(); void reinit();
bool isInitialized; bool isInitialized=false;
RtAudio* audio = Q_NULLPTR; RtAudio* audio = Q_NULLPTR;
int audioDevice = 0; int audioDevice = 0;
RtAudio::StreamParameters aParams; RtAudio::StreamParameters aParams;