зеркало из https://github.com/mozilla/gecko-dev.git
Bug 803093: Lock access to MediaEngineWebRTC singleton r=anant
This commit is contained in:
Родитель
7af2a0ac17
Коммит
bef0a4c1e2
|
@ -29,6 +29,8 @@ MediaEngineWebRTC::EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSourc
|
||||||
{
|
{
|
||||||
webrtc::ViEBase* ptrViEBase;
|
webrtc::ViEBase* ptrViEBase;
|
||||||
webrtc::ViECapture* ptrViECapture;
|
webrtc::ViECapture* ptrViECapture;
|
||||||
|
// We spawn threads to handle gUM runnables, so we must protect the member vars
|
||||||
|
MutexAutoLock lock(mMutex);
|
||||||
|
|
||||||
if (!mVideoEngine) {
|
if (!mVideoEngine) {
|
||||||
if (!(mVideoEngine = webrtc::VideoEngine::Create())) {
|
if (!(mVideoEngine = webrtc::VideoEngine::Create())) {
|
||||||
|
@ -123,6 +125,8 @@ MediaEngineWebRTC::EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSourc
|
||||||
{
|
{
|
||||||
webrtc::VoEBase* ptrVoEBase = NULL;
|
webrtc::VoEBase* ptrVoEBase = NULL;
|
||||||
webrtc::VoEHardware* ptrVoEHw = NULL;
|
webrtc::VoEHardware* ptrVoEHw = NULL;
|
||||||
|
// We spawn threads to handle gUM runnables, so we must protect the member vars
|
||||||
|
MutexAutoLock lock(mMutex);
|
||||||
|
|
||||||
if (!mVoiceEngine) {
|
if (!mVoiceEngine) {
|
||||||
mVoiceEngine = webrtc::VoiceEngine::Create();
|
mVoiceEngine = webrtc::VoiceEngine::Create();
|
||||||
|
@ -181,6 +185,9 @@ MediaEngineWebRTC::EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSourc
|
||||||
void
|
void
|
||||||
MediaEngineWebRTC::Shutdown()
|
MediaEngineWebRTC::Shutdown()
|
||||||
{
|
{
|
||||||
|
// This is likely paranoia
|
||||||
|
MutexAutoLock lock(mMutex);
|
||||||
|
|
||||||
if (mVideoEngine) {
|
if (mVideoEngine) {
|
||||||
mVideoSources.Clear();
|
mVideoSources.Clear();
|
||||||
webrtc::VideoEngine::Delete(mVideoEngine);
|
webrtc::VideoEngine::Delete(mVideoEngine);
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "nsIThread.h"
|
#include "nsIThread.h"
|
||||||
#include "nsIRunnable.h"
|
#include "nsIRunnable.h"
|
||||||
|
|
||||||
|
#include "mozilla/Mutex.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsDOMFile.h"
|
#include "nsDOMFile.h"
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
|
@ -218,10 +219,12 @@ class MediaEngineWebRTC : public MediaEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MediaEngineWebRTC()
|
MediaEngineWebRTC()
|
||||||
: mVideoEngine(NULL)
|
: mMutex("mozilla::MediaEngineWebRTC")
|
||||||
|
, mVideoEngine(NULL)
|
||||||
, mVoiceEngine(NULL)
|
, mVoiceEngine(NULL)
|
||||||
, mVideoEngineInit(false)
|
, mVideoEngineInit(false)
|
||||||
, mAudioEngineInit(false) {
|
, mAudioEngineInit(false)
|
||||||
|
{
|
||||||
mVideoSources.Init();
|
mVideoSources.Init();
|
||||||
mAudioSources.Init();
|
mAudioSources.Init();
|
||||||
}
|
}
|
||||||
|
@ -235,6 +238,9 @@ public:
|
||||||
virtual void EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSource> >*);
|
virtual void EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSource> >*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Mutex mMutex;
|
||||||
|
// protected with mMutex:
|
||||||
|
|
||||||
webrtc::VideoEngine* mVideoEngine;
|
webrtc::VideoEngine* mVideoEngine;
|
||||||
webrtc::VoiceEngine* mVoiceEngine;
|
webrtc::VoiceEngine* mVoiceEngine;
|
||||||
|
|
||||||
|
|
|
@ -812,6 +812,7 @@ MediaManager::GetUserMedia(bool aPrivileged, nsPIDOMWindow* aWindow,
|
||||||
if (!mMediaThread) {
|
if (!mMediaThread) {
|
||||||
nsresult rv = NS_NewThread(getter_AddRefs(mMediaThread));
|
nsresult rv = NS_NewThread(getter_AddRefs(mMediaThread));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
LOG(("New Media thread for gum"));
|
||||||
}
|
}
|
||||||
mMediaThread->Dispatch(gUMRunnable, NS_DISPATCH_NORMAL);
|
mMediaThread->Dispatch(gUMRunnable, NS_DISPATCH_NORMAL);
|
||||||
} else {
|
} else {
|
||||||
|
@ -952,8 +953,11 @@ MediaManager::Observe(nsISupports* aSubject, const char* aTopic,
|
||||||
|
|
||||||
// Reuse the same thread to save memory.
|
// Reuse the same thread to save memory.
|
||||||
if (!mMediaThread) {
|
if (!mMediaThread) {
|
||||||
|
LOG(("New Media thread for gum on allow"));
|
||||||
nsresult rv = NS_NewThread(getter_AddRefs(mMediaThread));
|
nsresult rv = NS_NewThread(getter_AddRefs(mMediaThread));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
} else {
|
||||||
|
LOG(("Reused Media thread for gum on allow"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aSubject) {
|
if (aSubject) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче