Bug 1070216 - Assert main MediaEngine APIs are called on the owning thread. r=jib

--HG--
extra : commitid : J9Hj3Lffpg
extra : rebase_source : da1183be4a7d8c4a750b3c9ea65c3d10390c938a
This commit is contained in:
Andreas Pehrson 2015-10-15 01:08:34 +08:00
parent 21f95c0d4a
commit 26afff5658
3 changed files with 24 additions and 0 deletions

View File

@ -188,9 +188,21 @@ protected:
// Only class' own members can be initialized in constructor initializer list. // Only class' own members can be initialized in constructor initializer list.
explicit MediaEngineSource(MediaEngineState aState) explicit MediaEngineSource(MediaEngineState aState)
: mState(aState) : mState(aState)
#ifdef DEBUG
, mOwningThread(PR_GetCurrentThread())
#endif
, mHasFakeTracks(false) , mHasFakeTracks(false)
{} {}
void AssertIsOnOwningThread()
{
MOZ_ASSERT(PR_GetCurrentThread() == mOwningThread);
}
MediaEngineState mState; MediaEngineState mState;
#ifdef DEBUG
PRThread* mOwningThread;
#endif
bool mHasFakeTracks; bool mHasFakeTracks;
}; };

View File

@ -96,6 +96,7 @@ MediaEngineRemoteVideoSource::Allocate(const dom::MediaTrackConstraints& aConstr
const nsString& aDeviceId) const nsString& aDeviceId)
{ {
LOG((__PRETTY_FUNCTION__)); LOG((__PRETTY_FUNCTION__));
AssertIsOnOwningThread();
if (!mInitDone) { if (!mInitDone) {
LOG(("Init not done")); LOG(("Init not done"));
@ -135,6 +136,7 @@ nsresult
MediaEngineRemoteVideoSource::Deallocate() MediaEngineRemoteVideoSource::Deallocate()
{ {
LOG((__PRETTY_FUNCTION__)); LOG((__PRETTY_FUNCTION__));
AssertIsOnOwningThread();
--mNrAllocations; --mNrAllocations;
MOZ_ASSERT(mNrAllocations >= 0, "Double-deallocations are prohibited"); MOZ_ASSERT(mNrAllocations >= 0, "Double-deallocations are prohibited");
@ -156,6 +158,7 @@ nsresult
MediaEngineRemoteVideoSource::Start(SourceMediaStream* aStream, TrackID aID) MediaEngineRemoteVideoSource::Start(SourceMediaStream* aStream, TrackID aID)
{ {
LOG((__PRETTY_FUNCTION__)); LOG((__PRETTY_FUNCTION__));
AssertIsOnOwningThread();
if (!mInitDone || !aStream) { if (!mInitDone || !aStream) {
LOG(("No stream or init not done")); LOG(("No stream or init not done"));
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -190,6 +193,7 @@ MediaEngineRemoteVideoSource::Stop(mozilla::SourceMediaStream* aSource,
mozilla::TrackID aID) mozilla::TrackID aID)
{ {
LOG((__PRETTY_FUNCTION__)); LOG((__PRETTY_FUNCTION__));
AssertIsOnOwningThread();
{ {
MonitorAutoLock lock(mMonitor); MonitorAutoLock lock(mMonitor);
@ -223,6 +227,7 @@ MediaEngineRemoteVideoSource::Restart(const dom::MediaTrackConstraints& aConstra
const MediaEnginePrefs& aPrefs, const MediaEnginePrefs& aPrefs,
const nsString& aDeviceId) const nsString& aDeviceId)
{ {
AssertIsOnOwningThread();
if (!mInitDone) { if (!mInitDone) {
LOG(("Init not done")); LOG(("Init not done"));
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -398,6 +403,7 @@ MediaEngineRemoteVideoSource::ChooseCapability(const MediaTrackConstraints &aCon
const MediaEnginePrefs &aPrefs, const MediaEnginePrefs &aPrefs,
const nsString& aDeviceId) const nsString& aDeviceId)
{ {
AssertIsOnOwningThread();
switch(mMediaSource) { switch(mMediaSource) {
case dom::MediaSourceEnum::Screen: case dom::MediaSourceEnum::Screen:

View File

@ -285,6 +285,7 @@ MediaEngineWebRTCMicrophoneSource::Allocate(const dom::MediaTrackConstraints &aC
const MediaEnginePrefs &aPrefs, const MediaEnginePrefs &aPrefs,
const nsString& aDeviceId) const nsString& aDeviceId)
{ {
AssertIsOnOwningThread();
if (mState == kReleased) { if (mState == kReleased) {
if (mInitDone) { if (mInitDone) {
ScopedCustomReleasePtr<webrtc::VoEHardware> ptrVoEHw(webrtc::VoEHardware::GetInterface(mVoiceEngine)); ScopedCustomReleasePtr<webrtc::VoEHardware> ptrVoEHw(webrtc::VoEHardware::GetInterface(mVoiceEngine));
@ -312,6 +313,7 @@ MediaEngineWebRTCMicrophoneSource::Allocate(const dom::MediaTrackConstraints &aC
nsresult nsresult
MediaEngineWebRTCMicrophoneSource::Deallocate() MediaEngineWebRTCMicrophoneSource::Deallocate()
{ {
AssertIsOnOwningThread();
--mNrAllocations; --mNrAllocations;
MOZ_ASSERT(mNrAllocations >= 0, "Double-deallocations are prohibited"); MOZ_ASSERT(mNrAllocations >= 0, "Double-deallocations are prohibited");
if (mNrAllocations == 0) { if (mNrAllocations == 0) {
@ -332,6 +334,7 @@ nsresult
MediaEngineWebRTCMicrophoneSource::Start(SourceMediaStream *aStream, MediaEngineWebRTCMicrophoneSource::Start(SourceMediaStream *aStream,
TrackID aID) TrackID aID)
{ {
AssertIsOnOwningThread();
if (!mInitDone || !aStream) { if (!mInitDone || !aStream) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -385,6 +388,7 @@ MediaEngineWebRTCMicrophoneSource::Start(SourceMediaStream *aStream,
nsresult nsresult
MediaEngineWebRTCMicrophoneSource::Stop(SourceMediaStream *aSource, TrackID aID) MediaEngineWebRTCMicrophoneSource::Stop(SourceMediaStream *aSource, TrackID aID)
{ {
AssertIsOnOwningThread();
{ {
MonitorAutoLock lock(mMonitor); MonitorAutoLock lock(mMonitor);
@ -661,6 +665,7 @@ nsresult
MediaEngineWebRTCAudioCaptureSource::Start(SourceMediaStream *aMediaStream, MediaEngineWebRTCAudioCaptureSource::Start(SourceMediaStream *aMediaStream,
TrackID aId) TrackID aId)
{ {
AssertIsOnOwningThread();
aMediaStream->AddTrack(aId, 0, new AudioSegment()); aMediaStream->AddTrack(aId, 0, new AudioSegment());
return NS_OK; return NS_OK;
} }
@ -669,6 +674,7 @@ nsresult
MediaEngineWebRTCAudioCaptureSource::Stop(SourceMediaStream *aMediaStream, MediaEngineWebRTCAudioCaptureSource::Stop(SourceMediaStream *aMediaStream,
TrackID aId) TrackID aId)
{ {
AssertIsOnOwningThread();
aMediaStream->EndAllTrackAndFinish(); aMediaStream->EndAllTrackAndFinish();
return NS_OK; return NS_OK;
} }