Bug 1364821 - Introduce AbstractThread::AutoEnter and remove main thread's AbstractThread::GetCurrent() (r=jwwang)

MozReview-Commit-ID: FSLVn7xe3sq
This commit is contained in:
Bill McCloskey 2017-07-31 14:29:07 -07:00
Родитель a38177ad5a
Коммит 2273c53b75
6 изменённых файлов: 72 добавлений и 1 удалений

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

@ -508,6 +508,8 @@ HTMLMediaElement::MediaLoadListener::OnStartRequest(nsIRequest* aRequest,
RefPtr<HTMLMediaElement> element; RefPtr<HTMLMediaElement> element;
element.swap(mElement); element.swap(mElement);
AbstractThread::AutoEnter context(element->AbstractMainThread());
if (mLoadID != element->GetCurrentLoadID()) { if (mLoadID != element->GetCurrentLoadID()) {
// The channel has been cancelled before we had a chance to create // The channel has been cancelled before we had a chance to create
// a decoder. Abort, don't dispatch an "error" event, as the new load // a decoder. Abort, don't dispatch an "error" event, as the new load
@ -2471,6 +2473,8 @@ void HTMLMediaElement::UpdatePreloadAction()
nsresult HTMLMediaElement::LoadResource() nsresult HTMLMediaElement::LoadResource()
{ {
AbstractThread::AutoEnter context(AbstractMainThread());
NS_ASSERTION(mDelayingLoadEvent, NS_ASSERTION(mDelayingLoadEvent,
"Should delay load event (if in document) during load"); "Should delay load event (if in document) during load");

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

@ -291,6 +291,7 @@ MediaDecoder::NotifyOwnerActivityChanged(bool aIsDocumentVisible,
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
SetElementVisibility(aIsDocumentVisible, aElementVisibility, aIsElementInTree); SetElementVisibility(aIsDocumentVisible, aElementVisibility, aIsElementInTree);
NotifyCompositor(); NotifyCompositor();
@ -301,6 +302,7 @@ MediaDecoder::Pause()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
if (mPlayState == PLAY_STATE_LOADING || IsEnded()) { if (mPlayState == PLAY_STATE_LOADING || IsEnded()) {
mNextState = PLAY_STATE_PAUSED; mNextState = PLAY_STATE_PAUSED;
return; return;
@ -312,6 +314,7 @@ void
MediaDecoder::SetVolume(double aVolume) MediaDecoder::SetVolume(double aVolume)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
mVolume = aVolume; mVolume = aVolume;
} }
@ -321,6 +324,7 @@ MediaDecoder::AddOutputStream(ProcessedMediaStream* aStream,
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mDecoderStateMachine, "Must be called after Load()."); MOZ_ASSERT(mDecoderStateMachine, "Must be called after Load().");
AbstractThread::AutoEnter context(AbstractMainThread());
mDecoderStateMachine->AddOutputStream(aStream, aFinishWhenEnded); mDecoderStateMachine->AddOutputStream(aStream, aFinishWhenEnded);
} }
@ -329,6 +333,7 @@ MediaDecoder::RemoveOutputStream(MediaStream* aStream)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mDecoderStateMachine, "Must be called after Load()."); MOZ_ASSERT(mDecoderStateMachine, "Must be called after Load().");
AbstractThread::AutoEnter context(AbstractMainThread());
mDecoderStateMachine->RemoveOutputStream(aStream); mDecoderStateMachine->RemoveOutputStream(aStream);
} }
@ -336,6 +341,7 @@ double
MediaDecoder::GetDuration() MediaDecoder::GetDuration()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
return mDuration; return mDuration;
} }
@ -344,6 +350,7 @@ MediaDecoder::SetInfinite(bool aInfinite)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
mInfiniteStream = aInfinite; mInfiniteStream = aInfinite;
DurationChanged(); DurationChanged();
} }
@ -352,6 +359,7 @@ bool
MediaDecoder::IsInfinite() const MediaDecoder::IsInfinite() const
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
return mInfiniteStream; return mInfiniteStream;
} }
@ -444,6 +452,7 @@ MediaDecoder::Shutdown()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
// Unwatch all watch targets to prevent further notifications. // Unwatch all watch targets to prevent further notifications.
mWatchManager.Shutdown(); mWatchManager.Shutdown();
@ -597,6 +606,7 @@ MediaDecoder::InitializeStateMachine()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
NS_ASSERTION(mDecoderStateMachine, "Cannot initialize null state machine!"); NS_ASSERTION(mDecoderStateMachine, "Cannot initialize null state machine!");
AbstractThread::AutoEnter context(AbstractMainThread());
nsresult rv = mDecoderStateMachine->Init(this); nsresult rv = mDecoderStateMachine->Init(this);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -645,6 +655,7 @@ MediaDecoder::Play()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
NS_ASSERTION(mDecoderStateMachine != nullptr, "Should have state machine."); NS_ASSERTION(mDecoderStateMachine != nullptr, "Should have state machine.");
if (mPlaybackRate == 0) { if (mPlaybackRate == 0) {
return NS_OK; return NS_OK;
@ -667,6 +678,7 @@ MediaDecoder::Seek(double aTime, SeekTarget::Type aSeekType)
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
MOZ_ASSERT(aTime >= 0.0, "Cannot seek to a negative value."); MOZ_ASSERT(aTime >= 0.0, "Cannot seek to a negative value.");
int64_t timeUsecs = TimeUnit::FromSeconds(aTime).ToMicroseconds(); int64_t timeUsecs = TimeUnit::FromSeconds(aTime).ToMicroseconds();
@ -688,6 +700,7 @@ void
MediaDecoder::DiscardOngoingSeekIfExists() MediaDecoder::DiscardOngoingSeekIfExists()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
mSeekRequest.DisconnectIfExists(); mSeekRequest.DisconnectIfExists();
GetOwner()->AsyncRejectSeekDOMPromiseIfExists(); GetOwner()->AsyncRejectSeekDOMPromiseIfExists();
} }
@ -696,6 +709,7 @@ void
MediaDecoder::CallSeek(const SeekTarget& aTarget) MediaDecoder::CallSeek(const SeekTarget& aTarget)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
DiscardOngoingSeekIfExists(); DiscardOngoingSeekIfExists();
mDecoderStateMachine->InvokeSeek(aTarget) mDecoderStateMachine->InvokeSeek(aTarget)
@ -708,6 +722,7 @@ double
MediaDecoder::GetCurrentTime() MediaDecoder::GetCurrentTime()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
return mLogicalPosition; return mLogicalPosition;
} }
@ -715,6 +730,7 @@ already_AddRefed<nsIPrincipal>
MediaDecoder::GetCurrentPrincipal() MediaDecoder::GetCurrentPrincipal()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
return mResource ? mResource->GetCurrentPrincipal() : nullptr; return mResource ? mResource->GetCurrentPrincipal() : nullptr;
} }
@ -722,6 +738,7 @@ void
MediaDecoder::OnMetadataUpdate(TimedMetadata&& aMetadata) MediaDecoder::OnMetadataUpdate(TimedMetadata&& aMetadata)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
GetOwner()->RemoveMediaTracks(); GetOwner()->RemoveMediaTracks();
MetadataLoaded(MakeUnique<MediaInfo>(*aMetadata.mInfo), MetadataLoaded(MakeUnique<MediaInfo>(*aMetadata.mInfo),
UniquePtr<MetadataTags>(aMetadata.mTags.forget()), UniquePtr<MetadataTags>(aMetadata.mTags.forget()),
@ -736,6 +753,7 @@ MediaDecoder::MetadataLoaded(UniquePtr<MediaInfo> aInfo,
MediaDecoderEventVisibility aEventVisibility) MediaDecoderEventVisibility aEventVisibility)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
LOG("MetadataLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d", LOG("MetadataLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d",
@ -773,6 +791,7 @@ void
MediaDecoder::EnsureTelemetryReported() MediaDecoder::EnsureTelemetryReported()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
if (mTelemetryReported || !mInfo) { if (mTelemetryReported || !mInfo) {
// Note: sometimes we get multiple MetadataLoaded calls (for example // Note: sometimes we get multiple MetadataLoaded calls (for example
@ -806,6 +825,7 @@ const char*
MediaDecoder::PlayStateStr() MediaDecoder::PlayStateStr()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
return ToPlayStateStr(mPlayState); return ToPlayStateStr(mPlayState);
} }
@ -815,6 +835,7 @@ MediaDecoder::FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo,
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d " LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d "
"mPlayState=%s", "mPlayState=%s",
@ -867,6 +888,7 @@ void
MediaDecoder::UpdateSameOriginStatus(bool aSameOrigin) MediaDecoder::UpdateSameOriginStatus(bool aSameOrigin)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
mSameOriginMedia = aSameOrigin; mSameOriginMedia = aSameOrigin;
} }
@ -990,6 +1012,7 @@ MediaDecoder::NotifySuspendedStatusChanged()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
if (mResource) { if (mResource) {
bool suspended = mResource->IsSuspendedByCache(); bool suspended = mResource->IsSuspendedByCache();
GetOwner()->NotifySuspendedByCache(suspended); GetOwner()->NotifySuspendedByCache(suspended);
@ -1043,6 +1066,7 @@ MediaDecoder::NotifyDownloadEnded(nsresult aStatus)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
LOG("NotifyDownloadEnded, status=%" PRIx32, static_cast<uint32_t>(aStatus)); LOG("NotifyDownloadEnded, status=%" PRIx32, static_cast<uint32_t>(aStatus));
@ -1069,6 +1093,7 @@ MediaDecoder::NotifyPrincipalChanged()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
nsCOMPtr<nsIPrincipal> newPrincipal = GetCurrentPrincipal(); nsCOMPtr<nsIPrincipal> newPrincipal = GetCurrentPrincipal();
mMediaPrincipalHandle = MakePrincipalHandle(newPrincipal); mMediaPrincipalHandle = MakePrincipalHandle(newPrincipal);
GetOwner()->NotifyDecoderPrincipalChanged(); GetOwner()->NotifyDecoderPrincipalChanged();
@ -1079,6 +1104,7 @@ MediaDecoder::NotifyBytesConsumed(int64_t aBytes, int64_t aOffset)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
if (mIgnoreProgressData) { if (mIgnoreProgressData) {
return; return;
@ -1096,6 +1122,7 @@ MediaDecoder::OnSeekResolved()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
mSeekRequest.Complete(); mSeekRequest.Complete();
{ {
@ -1134,6 +1161,7 @@ MediaDecoder::ChangeState(PlayState aState)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!IsShutdown(), "SHUTDOWN is the final state."); MOZ_ASSERT(!IsShutdown(), "SHUTDOWN is the final state.");
AbstractThread::AutoEnter context(AbstractMainThread());
if (mNextState == aState) { if (mNextState == aState) {
mNextState = PLAY_STATE_PAUSED; mNextState = PLAY_STATE_PAUSED;
@ -1178,6 +1206,7 @@ MediaDecoder::DurationChanged()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
AbstractThread::AutoEnter context(AbstractMainThread());
double oldDuration = mDuration; double oldDuration = mDuration;
if (IsInfinite()) { if (IsInfinite()) {
@ -1269,6 +1298,9 @@ MediaDecoder::SetSuspendTaint(bool aTainted)
void void
MediaDecoder::UpdateVideoDecodeMode() MediaDecoder::UpdateVideoDecodeMode()
{ {
MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(mAbstractMainThread);
// The MDSM may yet be set. // The MDSM may yet be set.
if (!mDecoderStateMachine) { if (!mDecoderStateMachine) {
LOG("UpdateVideoDecodeMode(), early return because we don't have MDSM."); LOG("UpdateVideoDecodeMode(), early return because we don't have MDSM.");
@ -1414,6 +1446,7 @@ void
MediaDecoder::SetPlaybackRate(double aPlaybackRate) MediaDecoder::SetPlaybackRate(double aPlaybackRate)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
double oldRate = mPlaybackRate; double oldRate = mPlaybackRate;
mPlaybackRate = aPlaybackRate; mPlaybackRate = aPlaybackRate;
@ -1438,6 +1471,7 @@ void
MediaDecoder::SetPreservesPitch(bool aPreservesPitch) MediaDecoder::SetPreservesPitch(bool aPreservesPitch)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
mPreservesPitch = aPreservesPitch; mPreservesPitch = aPreservesPitch;
} }
@ -1445,6 +1479,7 @@ void
MediaDecoder::SetLooping(bool aLooping) MediaDecoder::SetLooping(bool aLooping)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
mLooping = aLooping; mLooping = aLooping;
} }

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

@ -3152,6 +3152,7 @@ void MediaDecoderStateMachine::PlayStateChanged()
void MediaDecoderStateMachine::SetVideoDecodeMode(VideoDecodeMode aMode) void MediaDecoderStateMachine::SetVideoDecodeMode(VideoDecodeMode aMode)
{ {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIRunnable> r = NewRunnableMethod<VideoDecodeMode>( nsCOMPtr<nsIRunnable> r = NewRunnableMethod<VideoDecodeMode>(
"MediaDecoderStateMachine::SetVideoDecodeModeInternal", "MediaDecoderStateMachine::SetVideoDecodeModeInternal",
this, this,

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

@ -53,6 +53,7 @@ MediaSourceDecoder::Load(nsIPrincipal* aPrincipal)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!GetStateMachine()); MOZ_ASSERT(!GetStateMachine());
AbstractThread::AutoEnter context(AbstractMainThread());
mResource = new MediaSourceResource(aPrincipal); mResource = new MediaSourceResource(aPrincipal);
@ -78,6 +79,7 @@ media::TimeIntervals
MediaSourceDecoder::GetSeekable() MediaSourceDecoder::GetSeekable()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
if (!mMediaSource) { if (!mMediaSource) {
NS_WARNING("MediaSource element isn't attached"); NS_WARNING("MediaSource element isn't attached");
return media::TimeIntervals::Invalid(); return media::TimeIntervals::Invalid();
@ -119,6 +121,7 @@ media::TimeIntervals
MediaSourceDecoder::GetBuffered() MediaSourceDecoder::GetBuffered()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
if (!mMediaSource) { if (!mMediaSource) {
NS_WARNING("MediaSource element isn't attached"); NS_WARNING("MediaSource element isn't attached");
@ -164,6 +167,7 @@ void
MediaSourceDecoder::Shutdown() MediaSourceDecoder::Shutdown()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
MSE_DEBUG("Shutdown"); MSE_DEBUG("Shutdown");
// Detach first so that TrackBuffers are unused on the main thread when // Detach first so that TrackBuffers are unused on the main thread when
// shut down on the decode task queue. // shut down on the decode task queue.
@ -193,6 +197,7 @@ void
MediaSourceDecoder::Ended(bool aEnded) MediaSourceDecoder::Ended(bool aEnded)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
static_cast<MediaSourceResource*>(mResource.get())->SetEnded(aEnded); static_cast<MediaSourceResource*>(mResource.get())->SetEnded(aEnded);
if (aEnded) { if (aEnded) {
// We want the MediaSourceReader to refresh its buffered range as it may // We want the MediaSourceReader to refresh its buffered range as it may
@ -206,6 +211,7 @@ void
MediaSourceDecoder::AddSizeOfResources(ResourceSizes* aSizes) MediaSourceDecoder::AddSizeOfResources(ResourceSizes* aSizes)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
if (GetDemuxer()) { if (GetDemuxer()) {
GetDemuxer()->AddSizeOfResources(aSizes); GetDemuxer()->AddSizeOfResources(aSizes);
} }
@ -215,6 +221,7 @@ void
MediaSourceDecoder::SetInitialDuration(int64_t aDuration) MediaSourceDecoder::SetInitialDuration(int64_t aDuration)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
// Only use the decoded duration if one wasn't already // Only use the decoded duration if one wasn't already
// set. // set.
if (!mMediaSource || !IsNaN(ExplicitDuration())) { if (!mMediaSource || !IsNaN(ExplicitDuration())) {
@ -232,6 +239,7 @@ void
MediaSourceDecoder::SetMediaSourceDuration(double aDuration) MediaSourceDecoder::SetMediaSourceDuration(double aDuration)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
MOZ_ASSERT(!IsShutdown()); MOZ_ASSERT(!IsShutdown());
if (aDuration >= 0) { if (aDuration >= 0) {
int64_t checkedDuration; int64_t checkedDuration;
@ -259,6 +267,7 @@ double
MediaSourceDecoder::GetDuration() MediaSourceDecoder::GetDuration()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
return ExplicitDuration(); return ExplicitDuration();
} }
@ -266,6 +275,7 @@ MediaDecoderOwner::NextFrameStatus
MediaSourceDecoder::NextFrameBufferedStatus() MediaSourceDecoder::NextFrameBufferedStatus()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
if (!mMediaSource if (!mMediaSource
|| mMediaSource->ReadyState() == dom::MediaSourceReadyState::Closed) { || mMediaSource->ReadyState() == dom::MediaSourceReadyState::Closed) {
@ -289,6 +299,7 @@ bool
MediaSourceDecoder::CanPlayThrough() MediaSourceDecoder::CanPlayThrough()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
if (NextFrameBufferedStatus() == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE) { if (NextFrameBufferedStatus() == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE) {
return false; return false;
@ -321,6 +332,7 @@ TimeInterval
MediaSourceDecoder::ClampIntervalToEnd(const TimeInterval& aInterval) MediaSourceDecoder::ClampIntervalToEnd(const TimeInterval& aInterval)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
if (!mEnded) { if (!mEnded) {
return aInterval; return aInterval;
@ -338,6 +350,7 @@ void
MediaSourceDecoder::NotifyInitDataArrived() MediaSourceDecoder::NotifyInitDataArrived()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
if (mDemuxer) { if (mDemuxer) {
mDemuxer->NotifyInitDataArrived(); mDemuxer->NotifyInitDataArrived();

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

@ -90,6 +90,8 @@ public:
void FireTailDispatcher() void FireTailDispatcher()
{ {
AutoEnter context(this);
MOZ_DIAGNOSTIC_ASSERT(mTailDispatcher.isSome()); MOZ_DIAGNOSTIC_ASSERT(mTailDispatcher.isSome());
mTailDispatcher.ref().DrainDirectTasks(); mTailDispatcher.ref().DrainDirectTasks();
mTailDispatcher.reset(); mTailDispatcher.reset();
@ -315,7 +317,6 @@ AbstractThread::InitMainThread()
if (!sCurrentThreadTLS.init()) { if (!sCurrentThreadTLS.init()) {
MOZ_CRASH(); MOZ_CRASH();
} }
sCurrentThreadTLS.set(sMainThread);
} }
void void

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

@ -124,6 +124,23 @@ public:
MOZ_CRASH("Not support!"); MOZ_CRASH("Not support!");
} }
struct AutoEnter
{
AutoEnter(AbstractThread* aThread)
{
mLastCurrentThread = sCurrentThreadTLS.get();
sCurrentThreadTLS.set(aThread);
}
~AutoEnter()
{
sCurrentThreadTLS.set(mLastCurrentThread);
}
private:
AbstractThread* mLastCurrentThread = nullptr;
};
protected: protected:
virtual ~AbstractThread() {} virtual ~AbstractThread() {}
static MOZ_THREAD_LOCAL(AbstractThread*) sCurrentThreadTLS; static MOZ_THREAD_LOCAL(AbstractThread*) sCurrentThreadTLS;