[DEV] try use std thread on android

This commit is contained in:
Edouard DUPIN 2015-07-10 23:47:48 +02:00
parent ca312d1dac
commit cd9f9e76e3
3 changed files with 26 additions and 50 deletions

View File

@ -15,20 +15,13 @@
#include <audio/ess/decOgg.h> #include <audio/ess/decOgg.h>
#include <unistd.h> #include <unistd.h>
#if defined(__TARGET_OS__Android) void audio::ess::LoadedFile::threadCallback() {
static void* threadCallback2(void* _userData) { //etk::thread::setName("audio-ess decoder");
#else //decode();
static void threadCallback2(void* _userData) { }
#endif static void threadCallback222() {
etk::thread::setName("ewolSA decoder"); //etk::thread::setName("audio-ess decoder");
audio::ess::LoadedFile* decodeFile = static_cast<audio::ess::LoadedFile*>(_userData); //decode();
if (decodeFile != nullptr) {
decodeFile->decode();
}
#if defined(__TARGET_OS__Android)
return nullptr;
#endif
} }
void audio::ess::LoadedFile::decode() { void audio::ess::LoadedFile::decode() {
@ -39,9 +32,7 @@ void audio::ess::LoadedFile::decode() {
} }
audio::ess::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanRequested) : audio::ess::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanRequested) :
#if !defined(__TARGET_OS__Android) m_thread(nullptr),
m_thread(nullptr),
#endif
m_file(_fileName), m_file(_fileName),
m_nbSamples(0), m_nbSamples(0),
m_nbChanRequested(_nbChanRequested), m_nbChanRequested(_nbChanRequested),
@ -53,15 +44,15 @@ audio::ess::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanR
m_nbSamples = m_data.size(); m_nbSamples = m_data.size();
} else if (etk::end_with(tmpName, ".ogg") == true) { } else if (etk::end_with(tmpName, ".ogg") == true) {
#if 1 #if 1
EWOLSA_DEBUG("create thread"); EWOLSA_INFO("create thread");
#if defined(__TARGET_OS__Android)
pthread_create(&m_thread, nullptr, &threadCallback2, this); //m_thread = std::make_shared<std::thread>(&audio::ess::LoadedFile::threadCallback, this);
#else //m_thread = std::make_shared<std::thread>(&threadCallback222);
m_thread = new std::thread(&threadCallback2, this); static std::thread plop(&threadCallback222);
#endif plop.detach();
EWOLSA_DEBUG("done 1"); EWOLSA_INFO("done 1");
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(10000));
EWOLSA_DEBUG("done 2"); EWOLSA_INFO("done 2");
#else #else
EWOLSA_DEBUG("done 1"); EWOLSA_DEBUG("done 1");
decode(); decode();
@ -71,23 +62,13 @@ audio::ess::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanR
EWOLSA_ERROR("Extention not managed '" << m_file << "' Sopported extention : .wav / .ogg"); EWOLSA_ERROR("Extention not managed '" << m_file << "' Sopported extention : .wav / .ogg");
return; return;
} }
/*
if (m_data == nullptr) {
// write an error ...
EWOLSA_ERROR("Can not open file : " << _fileName);
}
*/
} }
audio::ess::LoadedFile::~LoadedFile() { audio::ess::LoadedFile::~LoadedFile() {
#if defined(__TARGET_OS__Android) if (m_thread != nullptr) {
// TODO : ... //m_thread->join();
#else }
if (m_thread != nullptr) { //m_thread.reset();
delete m_thread;
}
#endif
} }

View File

@ -11,11 +11,7 @@
#define __EWOLSA_LOADED_FILE_H__ #define __EWOLSA_LOADED_FILE_H__
#include <etk/types.h> #include <etk/types.h>
#if defined(__TARGET_OS__Android) #include <thread>
#include <pthread.h>
#else
#include <thread>
#endif
namespace audio { namespace audio {
namespace ess { namespace ess {
@ -27,11 +23,7 @@ namespace audio {
return m_uid; return m_uid;
} }
private: private:
#if defined(__TARGET_OS__Android) std::shared_ptr<std::thread> m_thread;
pthread_t m_thread;
#else
std::thread* m_thread;
#endif
public: public:
LoadedFile(const std::string& _fileName, int8_t _nbChanRequested=1); LoadedFile(const std::string& _fileName, int8_t _nbChanRequested=1);
~LoadedFile(); ~LoadedFile();
@ -45,6 +37,8 @@ namespace audio {
return m_file; return m_file;
}; };
void decode(); void decode();
private:
void threadCallback();
}; };
} }
} }

View File

@ -68,6 +68,7 @@ void audio::ess::Music::onDataNeeded(void* _data,
if (_format != audio::format_int16) { if (_format != audio::format_int16) {
EWOLSA_ERROR("call wrong type ... (need int16_t)"); EWOLSA_ERROR("call wrong type ... (need int16_t)");
} }
return;
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
if (m_current != m_next) { if (m_current != m_next) {
EWOLSA_INFO("change track " << (m_current==nullptr?-1:m_current->getUId()) << " ==> " << (m_next==nullptr?-1:m_next->getUId())); EWOLSA_INFO("change track " << (m_current==nullptr?-1:m_current->getUId()) << " ==> " << (m_next==nullptr?-1:m_next->getUId()));