diff --git a/media/libcubeb/src/cubeb_opensl.c b/media/libcubeb/src/cubeb_opensl.c index 494bc6295cfa..106f4a80dba0 100644 --- a/media/libcubeb/src/cubeb_opensl.c +++ b/media/libcubeb/src/cubeb_opensl.c @@ -13,11 +13,11 @@ struct cubeb { void * lib; - SLInterfaceID SL_IID_OUTPUTMIX; SLInterfaceID SL_IID_BUFFERQUEUE; SLInterfaceID SL_IID_PLAY; SLObjectItf engObj; SLEngineItf eng; + SLObjectItf outmixObj; }; #define NBUFS 4 @@ -27,7 +27,6 @@ struct cubeb_stream { SLObjectItf playerObj; SLPlayItf play; SLBufferQueueItf bufq; - SLObjectItf outmixObj; void *queuebuf[NBUFS]; int queuebuf_idx; long queuebuf_len; @@ -102,12 +101,12 @@ cubeb_init(cubeb ** context, char const * context_name) 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"); + SLInterfaceID 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 || + !SL_IID_OUTPUTMIX || !ctx->SL_IID_BUFFERQUEUE || !ctx->SL_IID_PLAY) { cubeb_destroy(ctx); @@ -136,6 +135,20 @@ cubeb_init(cubeb ** context, char const * context_name) return CUBEB_ERROR; } + const SLInterfaceID idsom[] = {SL_IID_OUTPUTMIX}; + const SLboolean reqom[] = {SL_BOOLEAN_TRUE}; + res = (*ctx->eng)->CreateOutputMix(ctx->eng, &ctx->outmixObj, 1, idsom, reqom); + if (res != SL_RESULT_SUCCESS) { + cubeb_destroy(ctx); + return CUBEB_ERROR; + } + + res = (*ctx->outmixObj)->Realize(ctx->outmixObj, SL_BOOLEAN_FALSE); + if (res != SL_RESULT_SUCCESS) { + cubeb_destroy(ctx); + return CUBEB_ERROR; + } + *context = ctx; return CUBEB_OK; @@ -151,6 +164,8 @@ void cubeb_destroy(cubeb * ctx) { dlclose(ctx->lib); + if (ctx->outmixObj) + (*ctx->outmixObj)->Destroy(ctx->outmixObj); if (ctx->engObj) (*ctx->engObj)->Destroy(ctx->engObj); free(ctx); @@ -222,32 +237,17 @@ cubeb_stream_init(cubeb * ctx, cubeb_stream ** stream, char const * stream_name, source.pLocator = &loc_bufq; source.pFormat = &format; - SLresult res; - 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) { - cubeb_stream_destroy(stm); - return CUBEB_ERROR; - } - - res = (*stm->outmixObj)->Realize(stm->outmixObj, SL_BOOLEAN_FALSE); - if (res != SL_RESULT_SUCCESS) { - cubeb_stream_destroy(stm); - return CUBEB_ERROR; - } - SLDataLocator_OutputMix loc_outmix; loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - loc_outmix.outputMix = stm->outmixObj; + loc_outmix.outputMix = ctx->outmixObj; SLDataSink sink; sink.pLocator = &loc_outmix; sink.pFormat = NULL; 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); + SLresult res = (*ctx->eng)->CreateAudioPlayer(ctx->eng, &stm->playerObj, + &source, &sink, 1, ids, req); if (res != SL_RESULT_SUCCESS) { cubeb_stream_destroy(stm); return CUBEB_ERROR; @@ -288,8 +288,6 @@ cubeb_stream_destroy(cubeb_stream * stm) { if (stm->playerObj) (*stm->playerObj)->Destroy(stm->playerObj); - if (stm->outmixObj) - (*stm->outmixObj)->Destroy(stm->outmixObj); free(stm); }