Bug 1015932 - Move OpenSLES Realize into the engine broker. r=padenot

This commit is contained in:
Gian-Carlo Pascutto 2014-07-28 08:10:21 +02:00
parent cc77fa9637
commit a847503bc3
6 changed files with 81 additions and 25 deletions

View File

@ -30,6 +30,7 @@ OpenSLESProvider::OpenSLESProvider()
: mLock("OpenSLESProvider.mLock"),
mSLEngine(nullptr),
mSLEngineUsers(0),
mIsRealized(false),
mOpenSLESLib(nullptr)
{
#if defined(PR_LOGGING)
@ -57,17 +58,17 @@ OpenSLESProvider& OpenSLESProvider::getInstance()
}
/* static */
int OpenSLESProvider::Get(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions)
SLresult OpenSLESProvider::Get(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions)
{
OpenSLESProvider& provider = OpenSLESProvider::getInstance();
return provider.GetEngine(aObjectm, aOptionCount, aOptions);
}
int OpenSLESProvider::GetEngine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions)
SLresult OpenSLESProvider::GetEngine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions)
{
MutexAutoLock lock(mLock);
LOG(("Getting OpenSLES engine"));
@ -91,9 +92,9 @@ int OpenSLESProvider::GetEngine(SLObjectItf * aObjectm,
}
}
int OpenSLESProvider::ConstructEngine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions)
SLresult OpenSLESProvider::ConstructEngine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions)
{
mLock.AssertCurrentThreadOwns();
@ -143,21 +144,56 @@ void OpenSLESProvider::DestroyEngine(SLObjectItf * aObjectm)
(void)dlclose(mOpenSLESLib);
mOpenSLESLib = nullptr;
mIsRealized = false;
}
/* static */
SLresult OpenSLESProvider::Realize(SLObjectItf aObjectm)
{
OpenSLESProvider& provider = OpenSLESProvider::getInstance();
return provider.RealizeEngine(aObjectm);
}
SLresult OpenSLESProvider::RealizeEngine(SLObjectItf aObjectm)
{
MutexAutoLock lock(mLock);
NS_ASSERTION(mOpenSLESLib, "OpenSLES realize called but library is not open");
NS_ASSERTION(aObjectm != nullptr, "OpenSLES realize engine with empty ObjectItf");
if (mIsRealized) {
LOG(("Not realizing already realized engine"));
return SL_RESULT_SUCCESS;
} else {
SLresult res = (*aObjectm)->Realize(aObjectm, SL_BOOLEAN_FALSE);
if (res != SL_RESULT_SUCCESS) {
LOG(("Error realizing OpenSLES engine: %d", res));
} else {
LOG(("Realized OpenSLES engine"));
mIsRealized = true;
}
return res;
}
}
} // namespace mozilla
extern "C" {
int mozilla_get_sles_engine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions)
SLresult mozilla_get_sles_engine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions)
{
return mozilla::OpenSLESProvider::Get(aObjectm, aOptionCount, aOptions);
}
void mozilla_destroy_sles_engine(SLObjectItf * aObjectm)
{
return mozilla::OpenSLESProvider::Destroy(aObjectm);
mozilla::OpenSLESProvider::Destroy(aObjectm);
}
SLresult mozilla_realize_sles_engine(SLObjectItf aObjectm)
{
return mozilla::OpenSLESProvider::Realize(aObjectm);
}
}

View File

@ -13,11 +13,14 @@
extern "C" {
#endif
extern MOZ_EXPORT
int mozilla_get_sles_engine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions);
SLresult mozilla_get_sles_engine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions);
extern MOZ_EXPORT
void mozilla_destroy_sles_engine(SLObjectItf * aObjectm);
/* Realize is always in synchronous mode. */
extern MOZ_EXPORT
SLresult mozilla_realize_sles_engine(SLObjectItf aObjectm);
#ifdef __cplusplus
}
#endif
@ -31,28 +34,31 @@ namespace mozilla {
class OpenSLESProvider {
public:
static int Get(SLObjectItf * aObjectm,
static SLresult Get(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions);
static void Destroy(SLObjectItf * aObjectm);
static SLresult Realize(SLObjectItf aObjectm);
private:
OpenSLESProvider();
~OpenSLESProvider();
OpenSLESProvider(OpenSLESProvider const&); // NO IMPLEMENTATION
void operator=(OpenSLESProvider const&); // NO IMPLEMENTATION
static OpenSLESProvider& getInstance();
int GetEngine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions);
int ConstructEngine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions);
SLresult GetEngine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions);
SLresult ConstructEngine(SLObjectItf * aObjectm,
SLuint32 aOptionCount,
const SLEngineOption *aOptions);
SLresult RealizeEngine(SLObjectItf aObjectm);
void DestroyEngine(SLObjectItf * aObjectm);
// Protect all our internal variables
mozilla::Mutex mLock;
SLObjectItf mSLEngine;
int mSLEngineUsers;
bool mIsRealized;
void *mOpenSLESLib;
};

View File

@ -14,7 +14,13 @@ static SLresult cubeb_get_sles_engine(
}
static void cubeb_destroy_sles_engine(SLObjectItf *self) {
mozilla_destroy_sles_engine(self);
mozilla_destroy_sles_engine(self);
}
/* Only synchronous operation is supported, as if the second
parameter was FALSE. */
static SLresult cubeb_realize_sles_engine(SLObjectItf self) {
return mozilla_realize_sles_engine(self);
}
#endif

View File

@ -271,7 +271,7 @@ opensl_init(cubeb ** context, char const * context_name)
return CUBEB_ERROR;
}
res = (*ctx->engObj)->Realize(ctx->engObj, SL_BOOLEAN_FALSE);
res = cubeb_realize_sles_engine(ctx->engObj);
if (res != SL_RESULT_SUCCESS) {
opensl_destroy(ctx);
return CUBEB_ERROR;

View File

@ -124,9 +124,13 @@ int32_t OpenSlesInput::Init() {
#else
OPENSL_RETURN_ON_FAILURE(mozilla_get_sles_engine(&sles_engine_, 1, kOption), -1);
#endif
#ifndef MOZILLA_INTERNAL_API
OPENSL_RETURN_ON_FAILURE((*sles_engine_)->Realize(sles_engine_,
SL_BOOLEAN_FALSE),
-1);
#else
OPENSL_RETURN_ON_FAILURE(mozilla_realize_sles_engine(sles_engine_), -1);
#endif
OPENSL_RETURN_ON_FAILURE((*sles_engine_)->GetInterface(sles_engine_,
SL_IID_ENGINE_,
&sles_engine_itf_),

View File

@ -124,9 +124,13 @@ int32_t OpenSlesOutput::Init() {
#else
OPENSL_RETURN_ON_FAILURE(mozilla_get_sles_engine(&sles_engine_, 1, kOption), -1);
#endif
#ifndef MOZILLA_INTERNAL_API
OPENSL_RETURN_ON_FAILURE((*sles_engine_)->Realize(sles_engine_,
SL_BOOLEAN_FALSE),
-1);
#else
OPENSL_RETURN_ON_FAILURE(mozilla_realize_sles_engine(sles_engine_), -1);
#endif
OPENSL_RETURN_ON_FAILURE((*sles_engine_)->GetInterface(sles_engine_,
SL_IID_ENGINE_,
&sles_engine_itf_),