diff --git a/dom/media/systemservices/video_engine/desktop_capture_impl.cc b/dom/media/systemservices/video_engine/desktop_capture_impl.cc index 6797c0eda2ef..6ea0cb2c373d 100644 --- a/dom/media/systemservices/video_engine/desktop_capture_impl.cc +++ b/dom/media/systemservices/video_engine/desktop_capture_impl.cc @@ -526,7 +526,7 @@ bool DesktopCaptureImpl::SetApplyRotation(bool aEnable) { return true; } int32_t DesktopCaptureImpl::StartCapture( const VideoCaptureCapability& aCapability) { - MOZ_DIAGNOSTIC_ASSERT(mControlThread->IsOnCurrentThread()); + RTC_DCHECK_RUN_ON(&mControlThreadChecker); if (mRequestedCapability) { // Already initialized @@ -558,7 +558,7 @@ int32_t DesktopCaptureImpl::StartCapture( } bool DesktopCaptureImpl::FocusOnSelectedSource() { - MOZ_DIAGNOSTIC_ASSERT(mControlThread->IsOnCurrentThread()); + RTC_DCHECK_RUN_ON(&mControlThreadChecker); if (!mCaptureThread) { MOZ_ASSERT_UNREACHABLE( "FocusOnSelectedSource must be called after StartCapture"); @@ -568,6 +568,7 @@ bool DesktopCaptureImpl::FocusOnSelectedSource() { bool success = false; MOZ_ALWAYS_SUCCEEDS(mozilla::SyncRunnable::DispatchToThread( mCaptureThread, NS_NewRunnableFunction(__func__, [&] { + RTC_DCHECK_RUN_ON(&mCaptureThreadChecker); MOZ_ASSERT(mCapturer); success = mCapturer && mCapturer->FocusOnSelectedSource(); }))); @@ -575,7 +576,7 @@ bool DesktopCaptureImpl::FocusOnSelectedSource() { } int32_t DesktopCaptureImpl::StopCapture() { - MOZ_DIAGNOSTIC_ASSERT(mControlThread->IsOnCurrentThread()); + RTC_DCHECK_RUN_ON(&mControlThreadChecker); if (mRequestedCapability) { // Sync-cancel the capture timer so no CaptureFrame calls will come in after // we return. @@ -608,7 +609,7 @@ int32_t DesktopCaptureImpl::CaptureSettings(VideoCaptureCapability& aSettings) { void DesktopCaptureImpl::OnCaptureResult(DesktopCapturer::Result aResult, std::unique_ptr aFrame) { - MOZ_ASSERT(mCaptureThreadChecker.IsCurrent()); + RTC_DCHECK_RUN_ON(&mCaptureThreadChecker); if (!aFrame) { return; } @@ -693,7 +694,7 @@ void DesktopCaptureImpl::OnCaptureResult(DesktopCapturer::Result aResult, } void DesktopCaptureImpl::NotifyOnFrame(const VideoFrame& aFrame) { - MOZ_ASSERT(mCaptureThreadChecker.IsCurrent()); + RTC_DCHECK_RUN_ON(&mCaptureThreadChecker); MOZ_ASSERT(Timestamp::Millis(aFrame.render_time_ms()) > mNextFrameMinimumTime); // Set the next frame's minimum time to ensure two consecutive frames don't @@ -708,7 +709,7 @@ void DesktopCaptureImpl::NotifyOnFrame(const VideoFrame& aFrame) { void DesktopCaptureImpl::InitOnThread( std::unique_ptr aCapturer, int aFramerate) { - MOZ_DIAGNOSTIC_ASSERT(mCaptureThreadChecker.IsCurrent()); + RTC_DCHECK_RUN_ON(&mCaptureThreadChecker); mCapturer = std::move(aCapturer); @@ -723,7 +724,7 @@ void DesktopCaptureImpl::InitOnThread( } void DesktopCaptureImpl::ShutdownOnThread() { - MOZ_DIAGNOSTIC_ASSERT(mCaptureThreadChecker.IsCurrent()); + RTC_DCHECK_RUN_ON(&mCaptureThreadChecker); if (mCaptureTimer) { mCaptureTimer->Cancel(); mCaptureTimer = nullptr; @@ -737,7 +738,7 @@ void DesktopCaptureImpl::ShutdownOnThread() { } void DesktopCaptureImpl::CaptureFrameOnThread() { - MOZ_DIAGNOSTIC_ASSERT(mCaptureThreadChecker.IsCurrent()); + RTC_DCHECK_RUN_ON(&mCaptureThreadChecker); #if defined(WEBRTC_MAC) // Give cycles to the RunLoop so frame callbacks can happen diff --git a/dom/media/systemservices/video_engine/desktop_capture_impl.h b/dom/media/systemservices/video_engine/desktop_capture_impl.h index 5773bf1ac398..64eadb140131 100644 --- a/dom/media/systemservices/video_engine/desktop_capture_impl.h +++ b/dom/media/systemservices/video_engine/desktop_capture_impl.h @@ -215,23 +215,27 @@ class DesktopCaptureImpl : public DesktopCapturer::Callback, // Control thread on which the public API is called. const nsCOMPtr mControlThread; // Set in StartCapture. - mozilla::Maybe mRequestedCapability; + mozilla::Maybe mRequestedCapability + RTC_GUARDED_BY(mControlThreadChecker); // The DesktopCapturer is created on mControlThread but assigned and accessed // only on mCaptureThread. - std::unique_ptr mCapturer; - // Dedicated thread that does the capturing. Only used on mControlThread. - nsCOMPtr mCaptureThread; + std::unique_ptr mCapturer + RTC_GUARDED_BY(mCaptureThreadChecker); + // Dedicated thread that does the capturing. + nsCOMPtr mCaptureThread RTC_GUARDED_BY(mControlThreadChecker); + // Checks that API methods are called on mControlThread. + webrtc::SequenceChecker mControlThreadChecker; // Checks that frame delivery only happens on mCaptureThread. webrtc::SequenceChecker mCaptureThreadChecker; // Timer that triggers frame captures. Only used on mCaptureThread. // TODO(Bug 1806646): Drive capture with vsync instead. - nsCOMPtr mCaptureTimer; + nsCOMPtr mCaptureTimer RTC_GUARDED_BY(mCaptureThreadChecker); // Interval between captured frames, based on the framerate in // mRequestedCapability. mCaptureThread only. - mozilla::Maybe mRequestedCaptureInterval; + mozilla::Maybe mRequestedCaptureInterval + RTC_GUARDED_BY(mCaptureThreadChecker); // Used to make sure incoming timestamp is increasing for every frame. - // mCaptureThread only. - webrtc::Timestamp mNextFrameMinimumTime; + webrtc::Timestamp mNextFrameMinimumTime RTC_GUARDED_BY(mCaptureThreadChecker); // Callbacks for captured frames. Mutated on mControlThread, callbacks happen // on mCaptureThread. mozilla::DataMutex*>> mCallbacks;