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.
explicit MediaEngineSource(MediaEngineState aState)
: mState(aState)
#ifdef DEBUG
, mOwningThread(PR_GetCurrentThread())
#endif
, mHasFakeTracks(false)
{}
void AssertIsOnOwningThread()
{
MOZ_ASSERT(PR_GetCurrentThread() == mOwningThread);
}
MediaEngineState mState;
#ifdef DEBUG
PRThread* mOwningThread;
#endif
bool mHasFakeTracks;
};

View File

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

View File

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