audiomanager: fix crash and return error text if applicable

This commit is contained in:
itsmattkc
2022-05-05 11:47:53 -07:00
parent fd692e6910
commit 591d02bdd6
4 changed files with 15 additions and 7 deletions
+10 -3
View File
@@ -189,7 +189,7 @@ void AudioManager::HardReset()
Pa_Initialize();
}
bool AudioManager::StartRecording(const EncodingParams &params)
bool AudioManager::StartRecording(const EncodingParams &params, QString *error_str)
{
if (input_device_ == paNoDevice) {
return false;
@@ -203,12 +203,19 @@ bool AudioManager::StartRecording(const EncodingParams &params)
PaStreamParameters p = GetPortAudioParams(params.audio_params(), input_device_);
if (Pa_OpenStream(&input_stream_, &p, nullptr, params.audio_params().sample_rate(), paFramesPerBufferUnspecified, paNoFlag, InputCallback, input_encoder_) == paNoError) {
if (Pa_StartStream(input_stream_) == paNoError) {
PaError r = Pa_OpenStream(&input_stream_, &p, nullptr, params.audio_params().sample_rate(), paFramesPerBufferUnspecified, paNoFlag, InputCallback, input_encoder_);
if (r == paNoError) {
//const PaStreamInfo* info = Pa_GetStreamInfo(input_stream_);
r = Pa_StartStream(input_stream_);
if (r == paNoError) {
return true;
}
}
if (error_str) {
*error_str = Pa_GetErrorText(r);
}
StopRecording();
return false;
}