зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1809672 - Use webrtc::SequenceChecker and RTC_GUARDED_BY for static analysis of threads in DesktopCaptureImpl. r=karlt
Differential Revision: https://phabricator.services.mozilla.com/D176296
This commit is contained in:
Родитель
4c44977f03
Коммит
cd60329357
|
@ -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<DesktopFrame> 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<DesktopCapturer> 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
|
||||
|
|
|
@ -215,23 +215,27 @@ class DesktopCaptureImpl : public DesktopCapturer::Callback,
|
|||
// Control thread on which the public API is called.
|
||||
const nsCOMPtr<nsISerialEventTarget> mControlThread;
|
||||
// Set in StartCapture.
|
||||
mozilla::Maybe<VideoCaptureCapability> mRequestedCapability;
|
||||
mozilla::Maybe<VideoCaptureCapability> mRequestedCapability
|
||||
RTC_GUARDED_BY(mControlThreadChecker);
|
||||
// The DesktopCapturer is created on mControlThread but assigned and accessed
|
||||
// only on mCaptureThread.
|
||||
std::unique_ptr<DesktopCapturer> mCapturer;
|
||||
// Dedicated thread that does the capturing. Only used on mControlThread.
|
||||
nsCOMPtr<nsIThread> mCaptureThread;
|
||||
std::unique_ptr<DesktopCapturer> mCapturer
|
||||
RTC_GUARDED_BY(mCaptureThreadChecker);
|
||||
// Dedicated thread that does the capturing.
|
||||
nsCOMPtr<nsIThread> 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<nsITimer> mCaptureTimer;
|
||||
nsCOMPtr<nsITimer> mCaptureTimer RTC_GUARDED_BY(mCaptureThreadChecker);
|
||||
// Interval between captured frames, based on the framerate in
|
||||
// mRequestedCapability. mCaptureThread only.
|
||||
mozilla::Maybe<mozilla::TimeDuration> mRequestedCaptureInterval;
|
||||
mozilla::Maybe<mozilla::TimeDuration> 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<std::set<rtc::VideoSinkInterface<VideoFrame>*>> mCallbacks;
|
||||
|
|
Загрузка…
Ссылка в новой задаче