PDA

View Full Version : Assertion 's' failed at pulse/stream.c while restarting QAudioOutput and QAudioInput?



the_naive
11th May 2016, 14:19
My application uses QAudioOutput and QAudioInput for audio communication between different audio devices. So, a user can speak through a microphone and that can be heard through a speaker using this app. It has a push-to-talk feature where the user can push a button on the app or a key on the keyboard to activate speaking through a microphone for the very moment when the button or the key is pressed.

The problem is that when push-to-talk option is used in quick succession, like when the user presses and releases the button in very quick succession for several times, like 5-6 times, sometimes the application crashes with an error message that says:



Assertion 's' failed at pulse/stream.c:1662, function pa_stream_writable_size(). Aborting.
Aborted


My OS is Ubuntu 14.04 LTS.

The methods for starting and stopping the microphone and the speaker are as below:


void AudioSettings::pushToTalk_pressed()
{
if(output->state() != QAudio::ActiveState && input->state() != QAudio::ActiveState)
{
output->start(input->start());
}
}

void AudioSettings::pushToTalk_released()
{
if(output->state() == QAudio::ActiveState && input->state() == QAudio::ActiveState)
{
output->stop();
input->stop();
}
}


Here input and output are respectively pointers to object of QAudioInput and QAudioOutput. They are initialized in the following way:


QAudioFormat audioFormat;
audioFormat.setChannelCount(2);
audioFormat.setCodec("audio/pcm");
audioFormat.setSampleRate(22050);
audioFormat.setSampleSize(16);
audioFormat.setByteOrder(QAudioFormat::LittleEndia n);
audioFormat.setSampleType(QAudioFormat::SignedInt) ;

QAudioDeviceInfo outputDevinfo = ui->output2Box->itemData(ui->output2Box->currentIndex()).value<QAudioDeviceInfo>();

if (!outputDevinfo.isFormatSupported(audioFormat))
{
//Default format not supported - trying to use nearest
audioFormat = outputDevinfo.nearestFormat(audioFormat);
}

//Initializing output device
output = new QAudioOutput(outputDevinfo, audioFormat, this);

QAudioDeviceInfo inputDevinfo = ui->input2Box->itemData(ui->input2Box->currentIndex()).value<QAudioDeviceInfo>();


if (!inputDevinfo.isFormatSupported(audioFormat))
{
//Default format not supported - trying to use nearest
audioFormat = inputDevinfo.nearestFormat(audioFormat);
}

//Initializing input device
input = new QAudioInput(inputDevinfo, audioFormat, this);


I tried to use GDB for finding out why this crash happens, but I only get the result in call stack of QtCreator as shown in the image.
11937
Could anyone please tell me how to prevent the aforementioned crash?

Thanks.

yeye_olive
11th May 2016, 14:42
Could you add qDebug() statements to track exactly when lines 5, 13, and 14 of your first snippet are executed? Maybe at some point line 5 is executed twice, without lines 13 and 14 having been executed in-between; then the second call to input->start() potentially invalidates the first QIODevice while output is still reading from it.

the_naive
11th May 2016, 14:59
Thanks yeye_olive for responding. I understand your point, I thought about it as well, which is why I used the "if" statement to prevent it from starting the devices when they are already in active mode. Shouldn't that "if" statement prevent the devices from getting started while they are not inactive?

Added after 12 minutes:

11938

So, according to your suggestion I did so. Apparently the "if" statements are doing they are job as I couldn't any single instant where the devices are getting stopped or started twice in a row without the other happening in the middel. I added an image of the qdebug output. As you can see for some reason QAudioOutput complains about having an buffer underflow and QAudioInput compains about not being able to set input volume.