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:
Robert O'Callahan 2011-01-04 16:55:32 +13:00
Родитель 957f9c6e7a
Коммит de26124762
2 изменённых файлов: 23 добавлений и 8 удалений

Просмотреть файл

@ -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