Bug 1015932 - Make WebRTC and libcubeb use the OpenSLES engine broker. r=padenot

This commit is contained in:
Gian-Carlo Pascutto 2014-07-28 08:09:48 +02:00
parent d9656ba4f4
commit cc77fa9637
4 changed files with 42 additions and 2 deletions

View File

@ -0,0 +1,20 @@
#ifndef _CUBEB_SLES_H_
#define _CUBEB_SLES_H_
#include <OpenSLESProvider.h>
#include <SLES/OpenSLES.h>
static SLresult cubeb_get_sles_engine(
SLObjectItf *pEngine,
SLuint32 numOptions,
const SLEngineOption *pEngineOptions,
SLuint32 numInterfaces,
const SLInterfaceID *pInterfaceIds,
const SLboolean * pInterfaceRequired) {
return mozilla_get_sles_engine(pEngine, numOptions, pEngineOptions);
}
static void cubeb_destroy_sles_engine(SLObjectItf *self) {
mozilla_destroy_sles_engine(self);
}
#endif

View File

@ -21,6 +21,7 @@
#include "cubeb/cubeb.h"
#include "cubeb-internal.h"
#include "cubeb_resampler.h"
#include "cubeb-sles.h"
static struct cubeb_ops const opensl_ops;
@ -263,7 +264,8 @@ opensl_init(cubeb ** context, char const * context_name)
const SLEngineOption opt[] = {{SL_ENGINEOPTION_THREADSAFE, SL_BOOLEAN_TRUE}};
SLresult res;
res = f_slCreateEngine(&ctx->engObj, 1, opt, 0, NULL, NULL);
res = cubeb_get_sles_engine(&ctx->engObj, 1, opt, 0, NULL, NULL);
if (res != SL_RESULT_SUCCESS) {
opensl_destroy(ctx);
return CUBEB_ERROR;
@ -442,7 +444,7 @@ opensl_destroy(cubeb * ctx)
if (ctx->outmixObj)
(*ctx->outmixObj)->Destroy(ctx->outmixObj);
if (ctx->engObj)
(*ctx->engObj)->Destroy(ctx->engObj);
cubeb_destroy_sles_engine(&ctx->engObj);
dlclose(ctx->lib);
dlclose(ctx->libmedia);
free(ctx);

View File

@ -13,6 +13,7 @@
#include <assert.h>
#include <dlfcn.h>
#include "OpenSLESProvider.h"
#include "webrtc/modules/audio_device/android/audio_common.h"
#include "webrtc/modules/audio_device/android/opensles_common.h"
#include "webrtc/modules/audio_device/android/single_rw_fifo.h"
@ -116,9 +117,13 @@ int32_t OpenSlesInput::Init() {
}
// Set up OpenSL engine.
#ifndef MOZILLA_INTERNAL_API
OPENSL_RETURN_ON_FAILURE(f_slCreateEngine(&sles_engine_, 1, kOption, 0,
NULL, NULL),
-1);
#else
OPENSL_RETURN_ON_FAILURE(mozilla_get_sles_engine(&sles_engine_, 1, kOption), -1);
#endif
OPENSL_RETURN_ON_FAILURE((*sles_engine_)->Realize(sles_engine_,
SL_BOOLEAN_FALSE),
-1);
@ -138,7 +143,11 @@ int32_t OpenSlesInput::Init() {
int32_t OpenSlesInput::Terminate() {
// It is assumed that the caller has stopped recording before terminating.
assert(!recording_);
#ifndef MOZILLA_INTERNAL_API
(*sles_engine_)->Destroy(sles_engine_);
#else
mozilla_destroy_sles_engine(&sles_engine_);
#endif
initialized_ = false;
mic_initialized_ = false;
rec_initialized_ = false;

View File

@ -15,6 +15,7 @@
#include <assert.h>
#include <dlfcn.h>
#include "OpenSLESProvider.h"
#include "webrtc/modules/audio_device/android/opensles_common.h"
#include "webrtc/modules/audio_device/android/fine_audio_buffer.h"
#include "webrtc/modules/audio_device/android/single_rw_fifo.h"
@ -116,9 +117,13 @@ int32_t OpenSlesOutput::Init() {
}
// Set up OpenSl engine.
#ifndef MOZILLA_INTERNAL_API
OPENSL_RETURN_ON_FAILURE(f_slCreateEngine(&sles_engine_, 1, kOption, 0,
NULL, NULL),
-1);
#else
OPENSL_RETURN_ON_FAILURE(mozilla_get_sles_engine(&sles_engine_, 1, kOption), -1);
#endif
OPENSL_RETURN_ON_FAILURE((*sles_engine_)->Realize(sles_engine_,
SL_BOOLEAN_FALSE),
-1);
@ -151,7 +156,11 @@ int32_t OpenSlesOutput::Terminate() {
// It is assumed that the caller has stopped recording before terminating.
assert(!playing_);
(*sles_output_mixer_)->Destroy(sles_output_mixer_);
#ifndef MOZILLA_INTERNAL_API
(*sles_engine_)->Destroy(sles_engine_);
#else
mozilla_destroy_sles_engine(&sles_engine_);
#endif
initialized_ = false;
speaker_initialized_ = false;
play_initialized_ = false;