Commit a4e572df authored by Tristan Matthews's avatar Tristan Matthews

* #18668: audiorecorder: use pthread instead of ost::Thread

parent b6705da3
......@@ -39,6 +39,7 @@
#include "noncopyable.h"
#include "dbus/configurationmanager.h"
#include <ctime>
#include "cc_thread.h"
#define SFL_ALSA_PERIOD_SIZE 160
#define SFL_ALSA_NB_PERIOD 8
......
......@@ -32,13 +32,14 @@
#include "mainbuffer.h"
#include "logger.h"
#include <sstream>
#include <unistd.h>
#include <cassert>
#include <tr1/array>
int AudioRecorder::count_ = 0;
AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : ost::Thread(),
recorderId_(), mbuffer_(mb), arecord_(arec), running_(true)
AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) :
recorderId_(), mbuffer_(mb), arecord_(arec), running_(false), thread_(0)
{
assert(mb);
......@@ -55,6 +56,26 @@ AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : ost::Thread()
recorderId_ = id.append(s);
}
AudioRecorder::~AudioRecorder() {
running_ = false;
if (thread_)
pthread_join(thread_, NULL);
}
void AudioRecorder::start()
{
running_ = true;
pthread_create(&thread_, NULL, &runCallback, this);
}
void *
AudioRecorder::runCallback(void *data)
{
AudioRecorder *context = static_cast<AudioRecorder*>(data);
context->run();
return NULL;
}
/**
* Reimplementation of run()
*/
......@@ -71,6 +92,6 @@ void AudioRecorder::run()
if (availableBytes > 0)
arecord_->recData(buffer.data(), availableBytes / sizeof(SFLDataFormat));
Thread::sleep(20);
usleep(20000); // 20 ms
}
}
......@@ -32,37 +32,34 @@
#define AUDIORECORDER_H_
#include <string>
#include "cc_thread.h"
#include <pthread.h>
#include "audiorecord.h"
#include "noncopyable.h"
class MainBuffer;
class AudioRecorder : public ost::Thread {
class AudioRecorder {
public:
AudioRecorder(AudioRecord *arec, MainBuffer *mb);
~AudioRecorder() {
running_ = false;
terminate();
}
static int count_;
~AudioRecorder();
std::string getRecorderID() const {
return recorderId_;
}
virtual void run();
void start();
private:
NON_COPYABLE(AudioRecorder);
void run();
static void * runCallback(void *data);
static int count_;
std::string recorderId_;
MainBuffer *mbuffer_;
AudioRecord *arecord_;
bool running_;
pthread_t thread_;
};
#endif
......@@ -38,6 +38,7 @@
#include "audio/dcblocker.h"
#include "logger.h"
#include "manager.h"
#include "cc_thread.h"
#include <cstdlib>
#include <fstream>
......
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