Commit 8efcb3e1 authored by Leander Schulten's avatar Leander Schulten

Fix #71. Register a error callback, so that no exceptions are thrown.

parent 3001660b
Pipeline #204683 passed with stage
in 5 minutes
......@@ -114,6 +114,12 @@ void AudioCaptureManager::dataCallback(float* data, unsigned int frames, bool*do
}
}
void AudioCaptureManager::rtAudioErrorCallback(RtAudioError::Type /*type*/, const std::string &errorText) {
get().currentCaptureDevice = -1;
emit get().currentCaptureDeviceChanged();
ErrorNotifier::showError("Error while capturing from capture device. Capturing stopped.\nError: " + QString::fromStdString(errorText) + "\nPlease select a new audio capture device the settings tab.");
}
bool AudioCaptureManager::startCapturingFromInput(unsigned input) {
if (input >= rtAudio.getDeviceCount()) {
return false;
......@@ -140,7 +146,7 @@ bool AudioCaptureManager::startCapturingFromInput(unsigned input) {
isp.firstChannel = 0;
unsigned samplesPerFrame = static_cast<unsigned>(this->samplesPerFrame);
try {
rtAudio.openStream(nullptr, &isp, RTAUDIO_FLOAT32, static_cast<unsigned>(this->samplesPerSecond), &samplesPerFrame, rtAudioCallback, nullptr, nullptr, nullptr);
rtAudio.openStream(nullptr, &isp, RTAUDIO_FLOAT32, static_cast<unsigned>(this->samplesPerSecond), &samplesPerFrame, rtAudioCallback, nullptr, nullptr, rtAudioErrorCallback);
if (static_cast<int>(samplesPerFrame) != this->samplesPerFrame) {
rtAudio.closeStream();
return false;
......
......@@ -58,6 +58,7 @@ class AudioCaptureManager : public QObject
private:
AudioCaptureManager();
private:
static void rtAudioErrorCallback(RtAudioError::Type type, const std::string &errorText);
static int rtAudioCallback(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData);
void initCallback(int channels, int samplesPerSecond);
void dataCallback(float *data, unsigned int frames, bool *done);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment