This source file includes following definitions.
- IntializeLibraryHandle
- LibraryHandle
- slCreateEngine
#define const
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
#undef const
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/native_library.h"
SLInterfaceID SL_IID_ENGINE = NULL;
SLInterfaceID SL_IID_ANDROIDSIMPLEBUFFERQUEUE = NULL;
SLInterfaceID SL_IID_ANDROIDCONFIGURATION = NULL;
SLInterfaceID SL_IID_RECORD = NULL;
SLInterfaceID SL_IID_BUFFERQUEUE = NULL;
SLInterfaceID SL_IID_VOLUME = NULL;
SLInterfaceID SL_IID_PLAY = NULL;
namespace {
const char kOpenSLLibraryName[] = "libOpenSLES.so";
base::NativeLibrary IntializeLibraryHandle() {
base::NativeLibrary handle =
base::LoadNativeLibrary(base::FilePath(kOpenSLLibraryName), NULL);
DCHECK(handle) << "Unable to load " << kOpenSLLibraryName;
struct SymbolDefinition {
const char* name;
SLInterfaceID* sl_iid;
};
const SymbolDefinition kSymbols[] = {
{"SL_IID_ENGINE", &SL_IID_ENGINE},
{"SL_IID_ANDROIDSIMPLEBUFFERQUEUE", &SL_IID_ANDROIDSIMPLEBUFFERQUEUE},
{"SL_IID_ANDROIDCONFIGURATION", &SL_IID_ANDROIDCONFIGURATION},
{"SL_IID_RECORD", &SL_IID_RECORD},
{"SL_IID_BUFFERQUEUE", &SL_IID_BUFFERQUEUE},
{"SL_IID_VOLUME", &SL_IID_VOLUME},
{"SL_IID_PLAY", &SL_IID_PLAY}
};
for (size_t i = 0; i < sizeof(kSymbols) / sizeof(kSymbols[0]); ++i) {
memcpy(kSymbols[i].sl_iid,
base::GetFunctionPointerFromNativeLibrary(handle, kSymbols[i].name),
sizeof(SLInterfaceID));
DCHECK(*kSymbols[i].sl_iid) << "Unable to find symbol for "
<< kSymbols[i].name;
}
return handle;
}
base::NativeLibrary LibraryHandle() {
static base::NativeLibrary g_opensles_LibraryHandle =
IntializeLibraryHandle();
return g_opensles_LibraryHandle;
}
}
SLresult slCreateEngine(SLObjectItf* engine,
SLuint32 num_options,
SLEngineOption* engine_options,
SLuint32 num_interfaces,
SLInterfaceID* interface_ids,
SLboolean* interfaces_required) {
typedef SLresult (*SlCreateEngineSignature)(SLObjectItf*,
SLuint32,
SLEngineOption*,
SLuint32,
SLInterfaceID*,
SLboolean*);
static SlCreateEngineSignature g_sl_create_engine_handle =
reinterpret_cast<SlCreateEngineSignature>(
base::GetFunctionPointerFromNativeLibrary(LibraryHandle(),
"slCreateEngine"));
DCHECK(g_sl_create_engine_handle)
<< "Unable to find symbol for slCreateEngine";
return g_sl_create_engine_handle(engine,
num_options,
engine_options,
num_interfaces,
interface_ids,
interfaces_required);
}