OS:Linux x86_64(Fedora18)
Qt:4.8
CPU:i7-3930K 3.20GHz

I am making a recording program using QAudioInput in Qt Multimedia. When I run my program, the CPU utilization is under a few percents initially but it becomes larger and larger up to more than 50% in some hours,and then segmentaion fault occurs.

The debugger told that was happened in pcm.c:2465
return pcm->fast_ops->avail_update(pcm->fast_op_arg);
called from qaudioinput_alsa_p.cpp:466 .
int frames = snd_pcm_avail_update(handle);

This is my code to reproduce that. This code records pcm data and clear it endlessly.
(Of cause, program termination is omitted, ex. destructor, and can not be terminated normally. Just for reproduction of run out of CPU resource.)

main.cpp
Qt Code:
  1. #include <QCoreApplication>
  2. #include <QThread>
  3. #include "recorder.hpp"
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. QCoreApplication a(argc, argv);
  8. QThread rec_thread;
  9. Recorder* recorder = new Recorder(0);
  10. recorder->moveToThread(&rec_thread);
  11. rec_thread.start();
  12.  
  13. QMetaObject::invokeMethod(recorder, "startRecording");
  14. return a.exec();
  15. }
To copy to clipboard, switch view to plain text mode 


recorder.hpp
Qt Code:
  1. #include <QBuffer>
  2. #include <QObject>
  3. #include <QAudioInput>
  4.  
  5. class Recorder : public QObject
  6. {
  7. Q_OBJECT
  8. public:
  9. explicit Recorder(QObject *parent = 0);
  10.  
  11. signals:
  12. void restartRecorder();
  13. private slots:
  14. void startRecording();
  15. void stopRecording();
  16.  
  17. private:
  18. QBuffer reading_buffer_;
  19. QAudioInput* audio_input_;
  20. QAudioFormat format_;
  21. };
To copy to clipboard, switch view to plain text mode 


recorder.cpp
Qt Code:
  1. #include "recorder.hpp"
  2. #include <QDebug>
  3. #include <QTimer>
  4.  
  5. Recorder::Recorder(QObject *parent) :
  6. QObject(parent)
  7. {
  8. format_.setSampleRate(44100); format_.setChannelCount(1);
  9. format_.setSampleSize(16); format_.setSampleType(QAudioFormat::SignedInt);
  10. format_.setCodec("audio/pcm"); format_.setByteOrder(QAudioFormat::LittleEndian);
  11. audio_input_ = new QAudioInput(format_, 0);
  12. connect(this, SIGNAL(restartRecorder()), this, SLOT(startRecording()));
  13. }
  14.  
  15. void Recorder::startRecording()
  16. {
  17. reading_buffer_.open(QBuffer::WriteOnly | QBuffer::Truncate);
  18. if(!reading_buffer_.isOpen()) qFatal("buffer not opened");
  19. QTimer::singleShot(1000, this, SLOT(stopRecording()));
  20. audio_input_->start(&reading_buffer_);
  21. }
  22.  
  23. void Recorder::stopRecording()
  24. {
  25. audio_input_->stop();
  26. audio_input_->reset();
  27. reading_buffer_.close();
  28. qDebug() << "Recording succeeded";
  29. emit restartRecorder();
  30. }
To copy to clipboard, switch view to plain text mode 



What is wrong with my program?

Thanks in advance