mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 791269 - dlopen opensl library, r=kinetik
This commit is contained in:
parent
21e917a1e7
commit
74b74d66d7
@ -7,10 +7,15 @@
|
||||
#undef NDEBUG
|
||||
#include "cubeb/cubeb.h"
|
||||
#include <assert.h>
|
||||
#include <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include <SLES/OpenSLES.h>
|
||||
|
||||
struct cubeb {
|
||||
void * lib;
|
||||
SLInterfaceID SL_IID_OUTPUTMIX;
|
||||
SLInterfaceID SL_IID_BUFFERQUEUE;
|
||||
SLInterfaceID SL_IID_PLAY;
|
||||
SLObjectItf engObj;
|
||||
SLEngineItf eng;
|
||||
};
|
||||
@ -82,18 +87,46 @@ cubeb_init(cubeb ** context, char const * context_name)
|
||||
ctx = calloc(1, sizeof(*ctx));
|
||||
assert(ctx);
|
||||
|
||||
ctx->lib = dlopen("libOpenSLES.so", RTLD_LAZY);
|
||||
if (!ctx->lib) {
|
||||
free(ctx);
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
typedef SLresult (*slCreateEngine_t)(SLObjectItf *,
|
||||
SLuint32,
|
||||
const SLEngineOption *,
|
||||
SLuint32,
|
||||
const SLInterfaceID *,
|
||||
const SLboolean *);
|
||||
slCreateEngine_t f_slCreateEngine =
|
||||
(slCreateEngine_t)dlsym(ctx->lib, "slCreateEngine");
|
||||
SLInterfaceID SL_IID_ENGINE = *(SLInterfaceID *)dlsym(ctx->lib, "SL_IID_ENGINE");
|
||||
ctx->SL_IID_OUTPUTMIX = *(SLInterfaceID *)dlsym(ctx->lib, "SL_IID_OUTPUTMIX");
|
||||
ctx->SL_IID_BUFFERQUEUE = *(SLInterfaceID *)dlsym(ctx->lib, "SL_IID_BUFFERQUEUE");
|
||||
ctx->SL_IID_PLAY = *(SLInterfaceID *)dlsym(ctx->lib, "SL_IID_PLAY");
|
||||
if (!f_slCreateEngine ||
|
||||
!SL_IID_ENGINE ||
|
||||
!ctx->SL_IID_OUTPUTMIX ||
|
||||
!ctx->SL_IID_BUFFERQUEUE ||
|
||||
!ctx->SL_IID_PLAY) {
|
||||
cubeb_destroy(ctx);
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
|
||||
const SLEngineOption opt[] = {{SL_ENGINEOPTION_THREADSAFE, SL_BOOLEAN_TRUE}};
|
||||
|
||||
SLresult res;
|
||||
res = slCreateEngine(&ctx->engObj, 1, opt, 0, NULL, NULL);
|
||||
res = f_slCreateEngine(&ctx->engObj, 1, opt, 0, NULL, NULL);
|
||||
if (res != SL_RESULT_SUCCESS) {
|
||||
free(ctx);
|
||||
cubeb_destroy(ctx);
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
res = (*ctx->engObj)->Realize(ctx->engObj, SL_BOOLEAN_FALSE);
|
||||
if (res != SL_RESULT_SUCCESS) {
|
||||
free(ctx);
|
||||
cubeb_destroy(ctx);
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
@ -117,7 +150,9 @@ cubeb_get_backend_id(cubeb * ctx)
|
||||
void
|
||||
cubeb_destroy(cubeb * ctx)
|
||||
{
|
||||
(*ctx->engObj)->Destroy(ctx->engObj);
|
||||
dlclose(ctx->lib);
|
||||
if (ctx->engObj)
|
||||
(*ctx->engObj)->Destroy(ctx->engObj);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
@ -188,7 +223,7 @@ cubeb_stream_init(cubeb * ctx, cubeb_stream ** stream, char const * stream_name,
|
||||
source.pFormat = &format;
|
||||
|
||||
SLresult res;
|
||||
const SLInterfaceID idsom[] = {SL_IID_OUTPUTMIX};
|
||||
const SLInterfaceID idsom[] = {ctx->SL_IID_OUTPUTMIX};
|
||||
const SLboolean reqom[] = {SL_BOOLEAN_TRUE};
|
||||
res = (*ctx->eng)->CreateOutputMix(ctx->eng, &stm->outmixObj, 1, idsom, reqom);
|
||||
if (res != SL_RESULT_SUCCESS) {
|
||||
@ -209,7 +244,7 @@ cubeb_stream_init(cubeb * ctx, cubeb_stream ** stream, char const * stream_name,
|
||||
sink.pLocator = &loc_outmix;
|
||||
sink.pFormat = NULL;
|
||||
|
||||
const SLInterfaceID ids[] = {SL_IID_BUFFERQUEUE};
|
||||
const SLInterfaceID ids[] = {ctx->SL_IID_BUFFERQUEUE};
|
||||
const SLboolean req[] = {SL_BOOLEAN_TRUE};
|
||||
res = (*ctx->eng)->CreateAudioPlayer(ctx->eng, &stm->playerObj,
|
||||
&source, &sink, 1, ids, req);
|
||||
@ -224,13 +259,13 @@ cubeb_stream_init(cubeb * ctx, cubeb_stream ** stream, char const * stream_name,
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
res = (*stm->playerObj)->GetInterface(stm->playerObj, SL_IID_PLAY, &stm->play);
|
||||
res = (*stm->playerObj)->GetInterface(stm->playerObj, ctx->SL_IID_PLAY, &stm->play);
|
||||
if (res != SL_RESULT_SUCCESS) {
|
||||
cubeb_stream_destroy(stm);
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
res = (*stm->playerObj)->GetInterface(stm->playerObj, SL_IID_BUFFERQUEUE,
|
||||
res = (*stm->playerObj)->GetInterface(stm->playerObj, ctx->SL_IID_BUFFERQUEUE,
|
||||
&stm->bufq);
|
||||
if (res != SL_RESULT_SUCCESS) {
|
||||
cubeb_stream_destroy(stm);
|
||||
|
@ -410,12 +410,6 @@ OS_LIBS += \
|
||||
-lsensorservice \
|
||||
-ldbus \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_CUBEB
|
||||
OS_LIBS += \
|
||||
-lOpenSLES \
|
||||
$(NULL)
|
||||
endif
|
||||
endif
|
||||
|
||||
EXTRA_DEPS += \
|
||||
|
Loading…
Reference in New Issue
Block a user