зеркало из https://github.com/mozilla/gecko-dev.git
Bug 621430. Lazily create stream writer thread so we don't create one when using local audio. Also, shut down the stream writer thread when the audio stream dies. r=dougt,a=blocker
This commit is contained in:
Родитель
957f9c6e7a
Коммит
de26124762
|
@ -301,10 +301,12 @@ void nsAudioStream::ShutdownLibrary()
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
nsIThread *
|
||||
nsAudioStream::GetThread()
|
||||
{
|
||||
if (!mAudioPlaybackThread) {
|
||||
NS_NewThread(getter_AddRefs(mAudioPlaybackThread));
|
||||
}
|
||||
return mAudioPlaybackThread;
|
||||
}
|
||||
|
||||
|
@ -318,6 +320,23 @@ nsAudioStream* nsAudioStream::AllocateStream()
|
|||
return new nsAudioStreamLocal();
|
||||
}
|
||||
|
||||
class AsyncShutdownPlaybackThread : public nsRunnable
|
||||
{
|
||||
public:
|
||||
AsyncShutdownPlaybackThread(nsIThread* aThread) : mThread(aThread) {}
|
||||
NS_IMETHODIMP Run() { return mThread->Shutdown(); }
|
||||
private:
|
||||
nsCOMPtr<nsIThread> mThread;
|
||||
};
|
||||
|
||||
nsAudioStream::~nsAudioStream()
|
||||
{
|
||||
if (mAudioPlaybackThread) {
|
||||
nsCOMPtr<nsIRunnable> event = new AsyncShutdownPlaybackThread(mAudioPlaybackThread);
|
||||
NS_DispatchToMainThread(event);
|
||||
}
|
||||
}
|
||||
|
||||
nsAudioStreamLocal::nsAudioStreamLocal() :
|
||||
mVolume(1.0),
|
||||
mAudioHandle(0),
|
||||
|
@ -327,12 +346,6 @@ nsAudioStreamLocal::nsAudioStreamLocal() :
|
|||
mPaused(PR_FALSE),
|
||||
mInError(PR_FALSE)
|
||||
{
|
||||
#ifdef MOZ_IPC
|
||||
// We only need this thread in the main process.
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||
NS_NewThread(getter_AddRefs(mAudioPlaybackThread));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
nsAudioStreamLocal::~nsAudioStreamLocal()
|
||||
|
|
|
@ -54,6 +54,8 @@ public:
|
|||
FORMAT_FLOAT32
|
||||
};
|
||||
|
||||
virtual ~nsAudioStream();
|
||||
|
||||
// Initialize Audio Library. Some Audio backends require initializing the
|
||||
// library before using it.
|
||||
static void InitLibrary();
|
||||
|
@ -64,7 +66,7 @@ public:
|
|||
|
||||
// Thread, usually for MOZ_IPC handling, that is shared between audio streams.
|
||||
// This may return null in the child process
|
||||
virtual nsIThread *GetThread();
|
||||
nsIThread *GetThread();
|
||||
|
||||
// AllocateStream will return either a local stream or a remoted stream
|
||||
// depending on where you call it from. If MOZ_IPC is enabled, and you
|
||||
|
|
Загрузка…
Ссылка в новой задаче