зеркало из https://github.com/mozilla/pjs.git
Bug 723793 - Lazily initialize libcubeb on first use. r=roc
This commit is contained in:
Родитель
676d09c1c9
Коммит
81d8ec4e29
|
@ -83,10 +83,6 @@ using mozilla::TimeStamp;
|
|||
PRLogModuleInfo* gAudioStreamLog = nsnull;
|
||||
#endif
|
||||
|
||||
#if defined(MOZ_CUBEB)
|
||||
static cubeb* gCubebContext;
|
||||
#endif
|
||||
|
||||
static const PRUint32 FAKE_BUFFER_SIZE = 176400;
|
||||
|
||||
// Number of milliseconds per second.
|
||||
|
@ -363,6 +359,19 @@ static bool GetUseCubeb()
|
|||
mozilla::MutexAutoLock lock(*gAudioPrefsLock);
|
||||
return gUseCubeb;
|
||||
}
|
||||
|
||||
static cubeb* gCubebContext;
|
||||
|
||||
static cubeb* GetCubebContext()
|
||||
{
|
||||
mozilla::MutexAutoLock lock(*gAudioPrefsLock);
|
||||
if (gCubebContext ||
|
||||
cubeb_init(&gCubebContext, "nsAudioStream") == CUBEB_OK) {
|
||||
return gCubebContext;
|
||||
}
|
||||
NS_WARNING("cubeb_init failed");
|
||||
return nsnull;
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsAudioStream::InitLibrary()
|
||||
|
@ -376,9 +385,6 @@ void nsAudioStream::InitLibrary()
|
|||
#if defined(MOZ_CUBEB)
|
||||
PrefChanged(PREF_USE_CUBEB, nsnull);
|
||||
Preferences::RegisterCallback(PrefChanged, PREF_USE_CUBEB);
|
||||
if (cubeb_init(&gCubebContext, "nsAudioStream") != 0) {
|
||||
NS_WARNING("cubeb_init failed");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -932,7 +938,9 @@ NS_IMPL_THREADSAFE_ISUPPORTS0(nsBufferedAudioStream)
|
|||
nsresult
|
||||
nsBufferedAudioStream::Init(PRInt32 aNumChannels, PRInt32 aRate, SampleFormat aFormat)
|
||||
{
|
||||
if (!gCubebContext || aNumChannels < 0 || aRate < 0) {
|
||||
cubeb* cubebContext = GetCubebContext();
|
||||
|
||||
if (!cubebContext || aNumChannels < 0 || aRate < 0) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -958,7 +966,7 @@ nsBufferedAudioStream::Init(PRInt32 aNumChannels, PRInt32 aRate, SampleFormat aF
|
|||
|
||||
{
|
||||
cubeb_stream* stream;
|
||||
if (cubeb_stream_init(gCubebContext, &stream, "nsBufferedAudioStream", params,
|
||||
if (cubeb_stream_init(cubebContext, &stream, "nsBufferedAudioStream", params,
|
||||
DEFAULT_LATENCY_MS, DataCallback_S, StateCallback_S, this) == CUBEB_OK) {
|
||||
mCubebStream.own(stream);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче