2012-07-07 20:58:27 +00:00
|
|
|
#include <dlfcn.h>
|
2012-07-07 22:17:59 +00:00
|
|
|
#include <errno.h>
|
2012-07-07 20:58:27 +00:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "android/native_audio.h"
|
|
|
|
#include "android/native-audio-so.h"
|
|
|
|
|
|
|
|
static void *so;
|
2012-07-08 11:23:30 +00:00
|
|
|
static AndroidAudioCallback s_cb;
|
2012-07-07 20:58:27 +00:00
|
|
|
static OpenSLWrap_Init_T init_func;
|
|
|
|
static OpenSLWrap_Shutdown_T shutdown_func;
|
2012-07-08 11:23:30 +00:00
|
|
|
static bool playing;
|
2012-07-07 20:58:27 +00:00
|
|
|
|
2012-07-07 22:17:59 +00:00
|
|
|
bool AndroidAudio_Init(AndroidAudioCallback cb, std::string libraryDir) {
|
2012-07-08 11:23:30 +00:00
|
|
|
s_cb = cb;
|
|
|
|
playing = false;
|
2012-07-07 20:58:27 +00:00
|
|
|
ILOG("Loading native audio library...");
|
2012-07-07 22:17:59 +00:00
|
|
|
std::string so_filename = libraryDir + "/libnative_audio.so";
|
|
|
|
so = dlopen(so_filename.c_str(), RTLD_LAZY);
|
2012-07-07 20:58:27 +00:00
|
|
|
if (!so) {
|
2012-07-07 22:17:59 +00:00
|
|
|
ELOG("Failed to find native audio library: %i: %s ", errno, dlerror());
|
2012-07-07 20:58:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
init_func = (OpenSLWrap_Init_T)dlsym(so, "OpenSLWrap_Init");
|
|
|
|
shutdown_func = (OpenSLWrap_Shutdown_T)dlsym(so, "OpenSLWrap_Shutdown");
|
2012-07-08 11:23:30 +00:00
|
|
|
return AndroidAudio_Resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AndroidAudio_Resume() {
|
|
|
|
if (!playing) {
|
|
|
|
ILOG("Calling OpenSLWrap_Init_T...");
|
|
|
|
bool init_retval = init_func(s_cb);
|
|
|
|
ILOG("Returned from OpenSLWrap_Init_T");
|
|
|
|
playing = true;
|
|
|
|
return init_retval;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-07 20:58:27 +00:00
|
|
|
|
2012-07-08 11:23:30 +00:00
|
|
|
bool AndroidAudio_Pause() {
|
|
|
|
if (playing) {
|
|
|
|
ILOG("Calling OpenSLWrap_Shutdown_T...");
|
|
|
|
shutdown_func();
|
|
|
|
playing = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-07-07 20:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidAudio_Shutdown() {
|
2012-07-08 11:23:30 +00:00
|
|
|
AndroidAudio_Pause();
|
2012-07-07 20:58:27 +00:00
|
|
|
ILOG("Returned from OpenSLWrap_Shutdown_T");
|
|
|
|
dlclose(so);
|
|
|
|
so = 0;
|
2012-07-08 11:23:30 +00:00
|
|
|
ILOG("OpenSLWrap completely unloaded.");
|
2012-07-07 20:58:27 +00:00
|
|
|
}
|