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