Skip to content
Snippets Groups Projects
Commit a4e572df authored by Tristan Matthews's avatar Tristan Matthews
Browse files

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

parent b6705da3
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "noncopyable.h" #include "noncopyable.h"
#include "dbus/configurationmanager.h" #include "dbus/configurationmanager.h"
#include <ctime> #include <ctime>
#include "cc_thread.h"
#define SFL_ALSA_PERIOD_SIZE 160 #define SFL_ALSA_PERIOD_SIZE 160
#define SFL_ALSA_NB_PERIOD 8 #define SFL_ALSA_NB_PERIOD 8
......
...@@ -32,13 +32,14 @@ ...@@ -32,13 +32,14 @@
#include "mainbuffer.h" #include "mainbuffer.h"
#include "logger.h" #include "logger.h"
#include <sstream> #include <sstream>
#include <unistd.h>
#include <cassert> #include <cassert>
#include <tr1/array> #include <tr1/array>
int AudioRecorder::count_ = 0; int AudioRecorder::count_ = 0;
AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : ost::Thread(), AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) :
recorderId_(), mbuffer_(mb), arecord_(arec), running_(true) recorderId_(), mbuffer_(mb), arecord_(arec), running_(false), thread_(0)
{ {
assert(mb); assert(mb);
...@@ -55,6 +56,26 @@ AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : ost::Thread() ...@@ -55,6 +56,26 @@ AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : ost::Thread()
recorderId_ = id.append(s); 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() * Reimplementation of run()
*/ */
...@@ -71,6 +92,6 @@ void AudioRecorder::run() ...@@ -71,6 +92,6 @@ void AudioRecorder::run()
if (availableBytes > 0) if (availableBytes > 0)
arecord_->recData(buffer.data(), availableBytes / sizeof(SFLDataFormat)); arecord_->recData(buffer.data(), availableBytes / sizeof(SFLDataFormat));
Thread::sleep(20); usleep(20000); // 20 ms
} }
} }
...@@ -32,37 +32,34 @@ ...@@ -32,37 +32,34 @@
#define AUDIORECORDER_H_ #define AUDIORECORDER_H_
#include <string> #include <string>
#include "cc_thread.h" #include <pthread.h>
#include "audiorecord.h" #include "audiorecord.h"
#include "noncopyable.h" #include "noncopyable.h"
class MainBuffer; class MainBuffer;
class AudioRecorder : public ost::Thread { class AudioRecorder {
public: public:
AudioRecorder(AudioRecord *arec, MainBuffer *mb); AudioRecorder(AudioRecord *arec, MainBuffer *mb);
~AudioRecorder();
~AudioRecorder() {
running_ = false;
terminate();
}
static int count_;
std::string getRecorderID() const { std::string getRecorderID() const {
return recorderId_; return recorderId_;
} }
virtual void run(); void start();
private: private:
NON_COPYABLE(AudioRecorder); NON_COPYABLE(AudioRecorder);
void run();
static void * runCallback(void *data);
static int count_;
std::string recorderId_; std::string recorderId_;
MainBuffer *mbuffer_; MainBuffer *mbuffer_;
AudioRecord *arecord_; AudioRecord *arecord_;
bool running_; bool running_;
pthread_t thread_;
}; };
#endif #endif
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "audio/dcblocker.h" #include "audio/dcblocker.h"
#include "logger.h" #include "logger.h"
#include "manager.h" #include "manager.h"
#include "cc_thread.h"
#include <cstdlib> #include <cstdlib>
#include <fstream> #include <fstream>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment