Commit 7caa8eab authored by Alexandre Savard's avatar Alexandre Savard

#10220: Fix recording thread does not exit when hanging up while recording

parent 1c642ecd
......@@ -30,6 +30,7 @@
#include "audiorecorder.h"
#include "mainbuffer.h"
#include "logger.h"
#include <sstream>
#include <cassert>
#include <tr1/array>
......@@ -37,7 +38,7 @@
int AudioRecorder::count_ = 0;
AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : ost::Thread(),
recorderId_(), mbuffer_(mb), arecord_(arec)
recorderId_(), mbuffer_(mb), arecord_(arec), running_(true)
{
assert(mb);
......@@ -63,13 +64,13 @@ void AudioRecorder::run()
std::tr1::array<SFLDataFormat, BUFFER_LENGTH> buffer;
buffer.assign(0);
while (isRunning()) {
while (running_) {
size_t availBytes = mbuffer_->availForGet(recorderId_);
mbuffer_->getData(buffer.data(), std::min(availBytes, buffer.size()), recorderId_);
if (availBytes > 0)
arecord_->recData(buffer.data(), availBytes / sizeof(SFLDataFormat));
sleep(20);
Thread::sleep(20);
}
}
......@@ -44,6 +44,7 @@ class AudioRecorder : public ost::Thread {
AudioRecorder(AudioRecord *arec, MainBuffer *mb);
~AudioRecorder() {
running_ = false;
terminate();
}
......@@ -61,6 +62,7 @@ class AudioRecorder : public ost::Thread {
std::string recorderId_;
MainBuffer *mbuffer_;
AudioRecord *arecord_;
bool running_;
};
#endif
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