Reland "Migrate modules/desktop_capture and modules/video_capture to webrtc::Mutex."

This is a reland of 44dd3d743517fe85212ba4f68bda1e78c2e6d7ec

Original change's description:
> Migrate modules/desktop_capture and modules/video_capture to webrtc::Mutex.
> 
> Bug: webrtc:11567
> Change-Id: I7bfca17f91bf44151148f863480ce77804d53a04
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178805
> Commit-Queue: Markus Handell <handellm@webrtc.org>
> Reviewed-by: Tommi <tommi@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#31681}

Bug: webrtc:11567
Change-Id: I03a32cb7194cffb9e678355c4af4d370b39384b3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/179093
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31716}
This commit is contained in:
Markus Handell 2020-07-13 13:09:15 +02:00 committed by Commit Bot
parent 30c8eaa1dc
commit 4379a7db1f
10 changed files with 33 additions and 29 deletions

View File

@ -480,6 +480,7 @@ rtc_library("desktop_capture_generic") {
"../../api:scoped_refptr",
"../../rtc_base", # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
"../../rtc_base:checks",
"../../rtc_base/synchronization:mutex",
"../../rtc_base/synchronization:rw_lock_wrapper",
"../../rtc_base/system:arch",
"../../rtc_base/system:rtc_export",

View File

@ -21,7 +21,7 @@ DesktopConfigurationMonitor::DesktopConfigurationMonitor() {
DesktopConfigurationMonitor::DisplaysReconfiguredCallback, this);
if (err != kCGErrorSuccess)
RTC_LOG(LS_ERROR) << "CGDisplayRegisterReconfigurationCallback " << err;
rtc::CritScope cs(&desktop_configuration_lock_);
MutexLock lock(&desktop_configuration_lock_);
desktop_configuration_ = MacDesktopConfiguration::GetCurrent(
MacDesktopConfiguration::TopLeftOrigin);
}
@ -34,7 +34,7 @@ DesktopConfigurationMonitor::~DesktopConfigurationMonitor() {
}
MacDesktopConfiguration DesktopConfigurationMonitor::desktop_configuration() {
rtc::CritScope crit(&desktop_configuration_lock_);
MutexLock lock(&desktop_configuration_lock_);
return desktop_configuration_;
}
@ -64,7 +64,7 @@ void DesktopConfigurationMonitor::DisplaysReconfigured(
reconfiguring_displays_.erase(display);
if (reconfiguring_displays_.empty()) {
rtc::CritScope cs(&desktop_configuration_lock_);
MutexLock lock(&desktop_configuration_lock_);
desktop_configuration_ = MacDesktopConfiguration::GetCurrent(
MacDesktopConfiguration::TopLeftOrigin);
}

View File

@ -19,7 +19,7 @@
#include "api/ref_counted_base.h"
#include "modules/desktop_capture/mac/desktop_configuration.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
@ -41,7 +41,7 @@ class DesktopConfigurationMonitor : public rtc::RefCountedBase {
void DisplaysReconfigured(CGDirectDisplayID display,
CGDisplayChangeSummaryFlags flags);
rtc::CriticalSection desktop_configuration_lock_;
Mutex desktop_configuration_lock_;
MacDesktopConfiguration desktop_configuration_
RTC_GUARDED_BY(&desktop_configuration_lock_);
std::set<CGDirectDisplayID> reconfiguring_displays_;

View File

@ -36,6 +36,7 @@ rtc_library("video_capture_module") {
"../../media:rtc_media_base",
"../../rtc_base:rtc_base_approved",
"../../rtc_base:stringutils",
"../../rtc_base/synchronization:mutex",
"../../rtc_base/synchronization:rw_lock_wrapper",
"../../system_wrappers",
"//third_party/libyuv",
@ -51,6 +52,7 @@ if (!build_with_chromium) {
"../../api:scoped_refptr",
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
"../../rtc_base/synchronization:mutex",
"../../system_wrappers",
]
@ -129,6 +131,7 @@ if (!build_with_chromium) {
"../../api/video:video_rtp_headers",
"../../common_video",
"../../rtc_base:rtc_base_approved",
"../../rtc_base/synchronization:mutex",
"../../system_wrappers",
"../../test:frame_utils",
"../../test:test_main",

View File

@ -115,7 +115,7 @@ int32_t VideoCaptureModuleV4L2::StartCapture(
}
}
rtc::CritScope cs(&_captureCritSect);
MutexLock lock(&capture_lock_);
// first open /dev/video device
char device[20];
sprintf(device, "/dev/video%d", (int)_deviceId);
@ -264,7 +264,7 @@ int32_t VideoCaptureModuleV4L2::StartCapture(
int32_t VideoCaptureModuleV4L2::StopCapture() {
if (_captureThread) {
{
rtc::CritScope cs(&_captureCritSect);
MutexLock lock(&capture_lock_);
quit_ = true;
}
// Make sure the capture thread stop stop using the critsect.
@ -272,7 +272,7 @@ int32_t VideoCaptureModuleV4L2::StopCapture() {
_captureThread.reset();
}
rtc::CritScope cs(&_captureCritSect);
MutexLock lock(&capture_lock_);
if (_captureStarted) {
_captureStarted = false;
@ -387,7 +387,7 @@ bool VideoCaptureModuleV4L2::CaptureProcess() {
}
{
rtc::CritScope cs(&_captureCritSect);
MutexLock lock(&capture_lock_);
if (quit_) {
return false;

View File

@ -18,8 +18,8 @@
#include "modules/video_capture/video_capture_defines.h"
#include "modules/video_capture/video_capture_impl.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
namespace videocapturemodule {
@ -43,8 +43,8 @@ class VideoCaptureModuleV4L2 : public VideoCaptureImpl {
// TODO(pbos): Stop using unique_ptr and resetting the thread.
std::unique_ptr<rtc::PlatformThread> _captureThread;
rtc::CriticalSection _captureCritSect;
bool quit_ RTC_GUARDED_BY(_captureCritSect);
Mutex capture_lock_;
bool quit_ RTC_GUARDED_BY(capture_lock_);
int32_t _deviceId;
int32_t _deviceFd;

View File

@ -23,7 +23,7 @@
#include "common_video/libyuv/include/webrtc_libyuv.h"
#include "modules/utility/include/process_thread.h"
#include "modules/video_capture/video_capture_factory.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/time_utils.h"
#include "system_wrappers/include/sleep.h"
#include "test/frame_utils.h"
@ -74,7 +74,7 @@ class TestVideoCaptureCallback
}
void OnFrame(const webrtc::VideoFrame& videoFrame) override {
rtc::CritScope cs(&capture_cs_);
webrtc::MutexLock lock(&capture_lock_);
int height = videoFrame.height();
int width = videoFrame.width();
#if defined(WEBRTC_ANDROID) && WEBRTC_ANDROID
@ -106,38 +106,38 @@ class TestVideoCaptureCallback
}
void SetExpectedCapability(VideoCaptureCapability capability) {
rtc::CritScope cs(&capture_cs_);
webrtc::MutexLock lock(&capture_lock_);
capability_ = capability;
incoming_frames_ = 0;
last_render_time_ms_ = 0;
}
int incoming_frames() {
rtc::CritScope cs(&capture_cs_);
webrtc::MutexLock lock(&capture_lock_);
return incoming_frames_;
}
int timing_warnings() {
rtc::CritScope cs(&capture_cs_);
webrtc::MutexLock lock(&capture_lock_);
return timing_warnings_;
}
VideoCaptureCapability capability() {
rtc::CritScope cs(&capture_cs_);
webrtc::MutexLock lock(&capture_lock_);
return capability_;
}
bool CompareLastFrame(const webrtc::VideoFrame& frame) {
rtc::CritScope cs(&capture_cs_);
webrtc::MutexLock lock(&capture_lock_);
return webrtc::test::FrameBufsEqual(last_frame_,
frame.video_frame_buffer());
}
void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) {
rtc::CritScope cs(&capture_cs_);
webrtc::MutexLock lock(&capture_lock_);
rotate_frame_ = rotation;
}
private:
rtc::CriticalSection capture_cs_;
webrtc::Mutex capture_lock_;
VideoCaptureCapability capability_;
int64_t last_render_time_ms_;
int incoming_frames_;

View File

@ -96,12 +96,12 @@ VideoCaptureImpl::~VideoCaptureImpl() {
void VideoCaptureImpl::RegisterCaptureDataCallback(
rtc::VideoSinkInterface<VideoFrame>* dataCallBack) {
rtc::CritScope cs(&_apiCs);
MutexLock lock(&api_lock_);
_dataCallBack = dataCallBack;
}
void VideoCaptureImpl::DeRegisterCaptureDataCallback() {
rtc::CritScope cs(&_apiCs);
MutexLock lock(&api_lock_);
_dataCallBack = NULL;
}
int32_t VideoCaptureImpl::DeliverCapturedFrame(VideoFrame& captureFrame) {
@ -118,7 +118,7 @@ int32_t VideoCaptureImpl::IncomingFrame(uint8_t* videoFrame,
size_t videoFrameLength,
const VideoCaptureCapability& frameInfo,
int64_t captureTime /*=0*/) {
rtc::CritScope cs(&_apiCs);
MutexLock lock(&api_lock_);
const int32_t width = frameInfo.width;
const int32_t height = frameInfo.height;
@ -223,7 +223,7 @@ int32_t VideoCaptureImpl::CaptureSettings(
}
int32_t VideoCaptureImpl::SetCaptureRotation(VideoRotation rotation) {
rtc::CritScope cs(&_apiCs);
MutexLock lock(&api_lock_);
_rotateFrame = rotation;
return 0;
}

View File

@ -25,7 +25,7 @@
#include "modules/video_capture/video_capture.h"
#include "modules/video_capture/video_capture_config.h"
#include "modules/video_capture/video_capture_defines.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
@ -78,7 +78,7 @@ class VideoCaptureImpl : public VideoCaptureModule {
~VideoCaptureImpl() override;
char* _deviceUniqueId; // current Device unique name;
rtc::CriticalSection _apiCs;
Mutex api_lock_;
VideoCaptureCapability _requestedCapability; // Should be set by platform
// dependent code in
// StartCapture.

View File

@ -130,7 +130,7 @@ int32_t VideoCaptureDS::Init(const char* deviceUniqueIdUTF8) {
}
int32_t VideoCaptureDS::StartCapture(const VideoCaptureCapability& capability) {
rtc::CritScope cs(&_apiCs);
MutexLock lock(&api_lock_);
if (capability != _requestedCapability) {
DisconnectGraph();
@ -148,7 +148,7 @@ int32_t VideoCaptureDS::StartCapture(const VideoCaptureCapability& capability) {
}
int32_t VideoCaptureDS::StopCapture() {
rtc::CritScope cs(&_apiCs);
MutexLock lock(&api_lock_);
HRESULT hr = _mediaControl->Pause();
if (FAILED(hr)) {