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

View File

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

View File

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