зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1791839 - Remove OpenSLESProvider.cpp, update cubeb vendoring manifest. r=kinetik
Differential Revision: https://phabricator.services.mozilla.com/D157856
This commit is contained in:
Родитель
38cba0f692
Коммит
b7eeae5027
|
@ -1,174 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "OpenSLESProvider.h"
|
||||
#include "mozilla/IntegerPrintfMacros.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <SLES/OpenSLES_Android.h>
|
||||
#include <SLES/OpenSLES_AndroidConfiguration.h>
|
||||
|
||||
// MOZ_LOG=OpenSLESProvider:5
|
||||
#undef LOG
|
||||
#undef LOG_ENABLED
|
||||
mozilla::LazyLogModule gOpenSLESProviderLog("OpenSLESProvider");
|
||||
#define LOG(args) MOZ_LOG(gOpenSLESProviderLog, mozilla::LogLevel::Debug, args)
|
||||
#define LOG_ENABLED() \
|
||||
MOZ_LOG_TEST(gOpenSLESProviderLog, mozilla::LogLevel::Debug)
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
OpenSLESProvider::OpenSLESProvider()
|
||||
: mLock("OpenSLESProvider.mLock"),
|
||||
mSLEngine(nullptr),
|
||||
mSLEngineUsers(0),
|
||||
mIsRealized(false),
|
||||
mOpenSLESLib(nullptr) {
|
||||
LOG(("OpenSLESProvider being initialized"));
|
||||
}
|
||||
|
||||
OpenSLESProvider::~OpenSLESProvider() {
|
||||
if (mOpenSLESLib) {
|
||||
LOG(("OpenSLES Engine was not properly Destroyed"));
|
||||
(void)dlclose(mOpenSLESLib);
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
OpenSLESProvider& OpenSLESProvider::getInstance() {
|
||||
// This doesn't need a Mutex in C++11 or GCC 4.3+, see N2660 and
|
||||
// https://gcc.gnu.org/projects/cxx0x.html
|
||||
static OpenSLESProvider instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/* static */
|
||||
SLresult OpenSLESProvider::Get(SLObjectItf* aObjectm, SLuint32 aOptionCount,
|
||||
const SLEngineOption* aOptions) {
|
||||
OpenSLESProvider& provider = OpenSLESProvider::getInstance();
|
||||
return provider.GetEngine(aObjectm, aOptionCount, aOptions);
|
||||
}
|
||||
|
||||
SLresult OpenSLESProvider::GetEngine(SLObjectItf* aObjectm,
|
||||
SLuint32 aOptionCount,
|
||||
const SLEngineOption* aOptions) {
|
||||
MutexAutoLock lock(mLock);
|
||||
LOG(("Getting OpenSLES engine"));
|
||||
// Bug 1042051: Validate options are the same
|
||||
if (mSLEngine != nullptr) {
|
||||
*aObjectm = mSLEngine;
|
||||
mSLEngineUsers++;
|
||||
LOG(("Returning existing engine, %d users", mSLEngineUsers));
|
||||
return SL_RESULT_SUCCESS;
|
||||
} else {
|
||||
SLresult res = ConstructEngine(aObjectm, aOptionCount, aOptions);
|
||||
if (res == SL_RESULT_SUCCESS) {
|
||||
// Bug 1042051: Store engine options
|
||||
mSLEngine = *aObjectm;
|
||||
mSLEngineUsers++;
|
||||
LOG(("Returning new engine"));
|
||||
} else {
|
||||
LOG(("Error getting engine: %lu", static_cast<unsigned long>(res)));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
SLresult OpenSLESProvider::ConstructEngine(SLObjectItf* aObjectm,
|
||||
SLuint32 aOptionCount,
|
||||
const SLEngineOption* aOptions) {
|
||||
mLock.AssertCurrentThreadOwns();
|
||||
|
||||
if (!mOpenSLESLib) {
|
||||
mOpenSLESLib = dlopen("libOpenSLES.so", RTLD_LAZY);
|
||||
if (!mOpenSLESLib) {
|
||||
LOG(("Failed to dlopen OpenSLES library"));
|
||||
return SL_RESULT_MEMORY_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
typedef SLresult (*slCreateEngine_t)(SLObjectItf*, SLuint32,
|
||||
const SLEngineOption*, SLuint32,
|
||||
const SLInterfaceID*, const SLboolean*);
|
||||
|
||||
slCreateEngine_t f_slCreateEngine =
|
||||
(slCreateEngine_t)dlsym(mOpenSLESLib, "slCreateEngine");
|
||||
int result =
|
||||
f_slCreateEngine(aObjectm, aOptionCount, aOptions, 0, NULL, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void OpenSLESProvider::Destroy(SLObjectItf* aObjectm) {
|
||||
OpenSLESProvider& provider = OpenSLESProvider::getInstance();
|
||||
provider.DestroyEngine(aObjectm);
|
||||
}
|
||||
|
||||
void OpenSLESProvider::DestroyEngine(SLObjectItf* aObjectm) {
|
||||
MutexAutoLock lock(mLock);
|
||||
NS_ASSERTION(mOpenSLESLib, "OpenSLES destroy called but library is not open");
|
||||
|
||||
mSLEngineUsers--;
|
||||
LOG(("Freeing engine, %d users left", mSLEngineUsers));
|
||||
if (mSLEngineUsers) {
|
||||
return;
|
||||
}
|
||||
|
||||
(*(*aObjectm))->Destroy(*aObjectm);
|
||||
// This assumes SLObjectItf is a pointer, but given the previous line,
|
||||
// that's a given.
|
||||
*aObjectm = nullptr;
|
||||
|
||||
(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: %lu",
|
||||
static_cast<unsigned long>(res)));
|
||||
} else {
|
||||
LOG(("Realized OpenSLES engine"));
|
||||
mIsRealized = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
extern "C" {
|
||||
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) {
|
||||
mozilla::OpenSLESProvider::Destroy(aObjectm);
|
||||
}
|
||||
|
||||
SLresult mozilla_realize_sles_engine(SLObjectItf aObjectm) {
|
||||
return mozilla::OpenSLESProvider::Realize(aObjectm);
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef _OPENSLESPROVIDER_H_
|
||||
#define _OPENSLESPROVIDER_H_
|
||||
|
||||
#include <SLES/OpenSLES.h>
|
||||
#include <mozilla/Types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern MOZ_EXPORT 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
|
||||
|
||||
#ifdef __cplusplus
|
||||
# include "mozilla/Mutex.h"
|
||||
|
||||
extern mozilla::LazyLogModule gOpenSLESProviderLog;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class OpenSLESProvider {
|
||||
public:
|
||||
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();
|
||||
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 MOZ_UNANNOTATED;
|
||||
SLObjectItf mSLEngine;
|
||||
int mSLEngineUsers;
|
||||
bool mIsRealized;
|
||||
void* mOpenSLESLib;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
#endif // cplusplus
|
||||
|
||||
#endif /* _OPENSLESPROVIDER_H_ */
|
|
@ -56,13 +56,6 @@ if CONFIG["MOZ_WEBRTC"]:
|
|||
if CONFIG["OS_TARGET"] == "Android":
|
||||
DEFINES["WEBRTC_ANDROID"] = True
|
||||
|
||||
|
||||
if CONFIG["OS_TARGET"] == "Android":
|
||||
EXPORTS += ["OpenSLESProvider.h"]
|
||||
UNIFIED_SOURCES += [
|
||||
"OpenSLESProvider.cpp",
|
||||
]
|
||||
|
||||
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
|
||||
UNIFIED_SOURCES += ["OSXRunLoopSingleton.cpp"]
|
||||
EXPORTS += ["OSXRunLoopSingleton.h"]
|
||||
|
|
|
@ -29,7 +29,6 @@ vendoring:
|
|||
- docs
|
||||
- scan-build-install.sh
|
||||
- src/cubeb-jni-instances.h
|
||||
- src/cubeb-sles.h
|
||||
- src/cubeb_assert.h
|
||||
- src/cubeb_audiotrack.c
|
||||
- src/cubeb_kai.c
|
||||
|
@ -43,7 +42,6 @@ vendoring:
|
|||
- include/cubeb_export.h
|
||||
- include/moz.build
|
||||
- src/cubeb-jni-instances.h
|
||||
- src/cubeb-sles.h
|
||||
- src/cubeb_assert.h
|
||||
- src/cubeb_osx_run_loop.c
|
||||
- src/moz.build
|
||||
|
|
Загрузка…
Ссылка в новой задаче