Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT6 doesn't record audio, only header in WAV file and QWaitCondition::wakeAll(): mutex lock failure

QT6 doesn't record audio, only header in WAV file and QWaitCondition::wakeAll(): mutex lock failure

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt6.5multimediaaudio recordingrecord
2 Posts 1 Posters 327 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deKewer
    wrote on 14 Aug 2023, 08:09 last edited by deKewer
    #1

    QT6 doesn't record audio, only header in WAV file and QWaitCondition::wakeAll(): mutex lock failure

    I'm writing a simple application to record audio, unfortunately it doesn't work properly. I have simplified everything as much as possible to make it easier to find errors and still have no success. Unfortunately, I couldn't find any information on the web to help solve the problem.

    I compiled the program under Debian 12 (bookworm) and under Windows 10. In both cases I use the official QT environment (6.5.2) downloaded from the QT website.

    The program only saves the header of the WAV file, which looks correct.

    While running a program on Debian, I get the following message and the program quits unexpectedly:

    !started recording from button!
    !record status changed:!
    QMediaRecorder::RecordingState
    !recording stoped!
    QUrl("file:///tmp/test")
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex lock failure (Bad argument)
    QWaitCondition::wakeAll(): mutex unlock failure (Bad argument)
    

    When launched on Windows, the program gives the following messages but does not close:

    !started recording from button!
    !record status changed:!
    QMediaRecorder::RecordingState
    !recording stoped!
    QUrl("file://test")
    

    Below is the program code. I will be very grateful for help in solving the problem.

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        // Creating audioInput
        audioInput = new QAudioInput(this);
        audioInput->setDevice(QMediaDevices::defaultAudioInput());
    
        // Creating format for simplest WAVE file
        formatAudio = new QMediaFormat;
        formatAudio->resolveForEncoding(QMediaFormat::NoFlags);
        formatAudio->setAudioCodec(QMediaFormat::AudioCodec::Wave);
        formatAudio->setFileFormat(QMediaFormat::Wave);
    
        // Creating recorder
        recorder = new QMediaRecorder(this);
        recorder->setAudioChannelCount(2);
        recorder->setAudioSampleRate(48000);
        recorder->setMediaFormat(*formatAudio);
        // anyone can write to /tmp
        // user running this program is in group pulse (for access to soundcard)
        recorder->setOutputLocation(QUrl::fromLocalFile("/tmp/test"));
    
        // Creating session
        session = new QMediaCaptureSession(this);
        session->setAudioInput(audioInput);
        session->setRecorder(recorder);
    
        connect(recorder, SIGNAL(recorderStateChanged(QMediaRecorder::RecorderState)), this, SLOT(recStatCh(QMediaRecorder::RecorderState)));
        connect(recorder, SIGNAL(errorOccurred(QMediaRecorder::Error,QString)), this, SLOT(recErrOc(QMediaRecorder::Error,QString)));
        connect(recorder, SIGNAL(errorChanged()), this, SLOT(recErrCh()));
        connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(startRecording()));
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::stopRecording()
    {
        recorder->stop();
        qInfo() << "Recording stoped";
        qInfo() << recorder->outputLocation();
    }
    
    void MainWindow::startRecording()
    {
        qInfo() << "Started recording from button";
        recorder->record();
        QTimer::singleShot(5000, this, SLOT(stopRecording()));
    }
    
    void MainWindow::recErrCh()
    {
        qInfo() << "recorder: errorChanged()";
    }
    
    void MainWindow::recStatCh(QMediaRecorder::RecorderState state)
    {
        qInfo() << "!record status changed:!";
        qInfo() << state;
    }
    
    void MainWindow::recErrOc(QMediaRecorder::Error error, const QString &errorString)
    {
        qInfo() << "!record error occured:!";
        qInfo() << error;
        qInfo() << errorString;
    }
    
    1 Reply Last reply
    0
    • D Offline
      D Offline
      deKewer
      wrote on 15 Aug 2023, 12:37 last edited by
      #2

      OK, I found the cause of the problem. Well, the problem is the right combination of codec, format and QMediaRecorder configuration. In the case of my systems, it turned out that they do not support WAV. Using AAC and a bitrate of 256kbit solved the problem. Previously I tried with AAC and 320kbit but the codec does not work with such a high bitrate and there was no error message.

      1 Reply Last reply
      0

      2/2

      15 Aug 2023, 12:37

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved