Replace RWLockWrapper --> Mutex in DeviceInfoImpl
Reader-writer locks helps performance only when there are many concurrent readers, and I would expect that isn't the case for this class. Using a plain mutex reduces complexity. Bug: webrtc:12102 Change-Id: I07c315bcbfc38f1d8befe5395c9ece54c673aeb7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/190722 Reviewed-by: Magnus Flodman <mflodman@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32547}
This commit is contained in:
@ -25,34 +25,25 @@ namespace webrtc {
|
||||
namespace videocapturemodule {
|
||||
|
||||
DeviceInfoImpl::DeviceInfoImpl()
|
||||
: _apiLock(*RWLockWrapper::CreateRWLock()),
|
||||
_lastUsedDeviceName(NULL),
|
||||
_lastUsedDeviceNameLength(0) {}
|
||||
: _lastUsedDeviceName(NULL), _lastUsedDeviceNameLength(0) {}
|
||||
|
||||
DeviceInfoImpl::~DeviceInfoImpl(void) {
|
||||
_apiLock.AcquireLockExclusive();
|
||||
MutexLock lock(&_apiLock);
|
||||
free(_lastUsedDeviceName);
|
||||
_apiLock.ReleaseLockExclusive();
|
||||
|
||||
delete &_apiLock;
|
||||
}
|
||||
|
||||
int32_t DeviceInfoImpl::NumberOfCapabilities(const char* deviceUniqueIdUTF8) {
|
||||
if (!deviceUniqueIdUTF8)
|
||||
return -1;
|
||||
|
||||
_apiLock.AcquireLockShared();
|
||||
MutexLock lock(&_apiLock);
|
||||
|
||||
// Is it the same device that is asked for again.
|
||||
if (absl::EqualsIgnoreCase(
|
||||
deviceUniqueIdUTF8,
|
||||
absl::string_view(_lastUsedDeviceName, _lastUsedDeviceNameLength))) {
|
||||
_apiLock.ReleaseLockShared();
|
||||
return static_cast<int32_t>(_captureCapabilities.size());
|
||||
}
|
||||
// Need to get exclusive rights to create the new capability map.
|
||||
_apiLock.ReleaseLockShared();
|
||||
WriteLockScoped cs2(_apiLock);
|
||||
|
||||
int32_t ret = CreateCapabilityMap(deviceUniqueIdUTF8);
|
||||
return ret;
|
||||
@ -63,20 +54,14 @@ int32_t DeviceInfoImpl::GetCapability(const char* deviceUniqueIdUTF8,
|
||||
VideoCaptureCapability& capability) {
|
||||
assert(deviceUniqueIdUTF8 != NULL);
|
||||
|
||||
ReadLockScoped cs(_apiLock);
|
||||
MutexLock lock(&_apiLock);
|
||||
|
||||
if (!absl::EqualsIgnoreCase(
|
||||
deviceUniqueIdUTF8,
|
||||
absl::string_view(_lastUsedDeviceName, _lastUsedDeviceNameLength))) {
|
||||
_apiLock.ReleaseLockShared();
|
||||
_apiLock.AcquireLockExclusive();
|
||||
if (-1 == CreateCapabilityMap(deviceUniqueIdUTF8)) {
|
||||
_apiLock.ReleaseLockExclusive();
|
||||
_apiLock.AcquireLockShared();
|
||||
return -1;
|
||||
}
|
||||
_apiLock.ReleaseLockExclusive();
|
||||
_apiLock.AcquireLockShared();
|
||||
}
|
||||
|
||||
// Make sure the number is valid
|
||||
@ -98,17 +83,13 @@ int32_t DeviceInfoImpl::GetBestMatchedCapability(
|
||||
if (!deviceUniqueIdUTF8)
|
||||
return -1;
|
||||
|
||||
ReadLockScoped cs(_apiLock);
|
||||
MutexLock lock(&_apiLock);
|
||||
if (!absl::EqualsIgnoreCase(
|
||||
deviceUniqueIdUTF8,
|
||||
absl::string_view(_lastUsedDeviceName, _lastUsedDeviceNameLength))) {
|
||||
_apiLock.ReleaseLockShared();
|
||||
_apiLock.AcquireLockExclusive();
|
||||
if (-1 == CreateCapabilityMap(deviceUniqueIdUTF8)) {
|
||||
return -1;
|
||||
}
|
||||
_apiLock.ReleaseLockExclusive();
|
||||
_apiLock.AcquireLockShared();
|
||||
}
|
||||
|
||||
int32_t bestformatIndex = -1;
|
||||
|
||||
@ -18,7 +18,8 @@
|
||||
#include "api/video/video_rotation.h"
|
||||
#include "modules/video_capture/video_capture.h"
|
||||
#include "modules/video_capture/video_capture_defines.h"
|
||||
#include "rtc_base/synchronization/rw_lock_wrapper.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace videocapturemodule {
|
||||
@ -45,15 +46,16 @@ class DeviceInfoImpl : public VideoCaptureModule::DeviceInfo {
|
||||
* Fills the member variable _captureCapabilities with capabilities for the
|
||||
* given device name.
|
||||
*/
|
||||
virtual int32_t CreateCapabilityMap(const char* deviceUniqueIdUTF8) = 0;
|
||||
virtual int32_t CreateCapabilityMap(const char* deviceUniqueIdUTF8)
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(_apiLock) = 0;
|
||||
|
||||
protected:
|
||||
// Data members
|
||||
typedef std::vector<VideoCaptureCapability> VideoCaptureCapabilities;
|
||||
VideoCaptureCapabilities _captureCapabilities;
|
||||
RWLockWrapper& _apiLock;
|
||||
char* _lastUsedDeviceName;
|
||||
uint32_t _lastUsedDeviceNameLength;
|
||||
VideoCaptureCapabilities _captureCapabilities RTC_GUARDED_BY(_apiLock);
|
||||
Mutex _apiLock;
|
||||
char* _lastUsedDeviceName RTC_GUARDED_BY(_apiLock);
|
||||
uint32_t _lastUsedDeviceNameLength RTC_GUARDED_BY(_apiLock);
|
||||
};
|
||||
} // namespace videocapturemodule
|
||||
} // namespace webrtc
|
||||
|
||||
@ -33,13 +33,14 @@ class DeviceInfoLinux : public DeviceInfoImpl {
|
||||
* Fills the membervariable _captureCapabilities with capabilites for the
|
||||
* given device name.
|
||||
*/
|
||||
int32_t CreateCapabilityMap(const char* deviceUniqueIdUTF8) override;
|
||||
int32_t CreateCapabilityMap(const char* deviceUniqueIdUTF8) override
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(_apiLock);
|
||||
int32_t DisplayCaptureSettingsDialogBox(const char* /*deviceUniqueIdUTF8*/,
|
||||
const char* /*dialogTitleUTF8*/,
|
||||
void* /*parentWindow*/,
|
||||
uint32_t /*positionX*/,
|
||||
uint32_t /*positionY*/) override;
|
||||
int32_t FillCapabilities(int fd);
|
||||
int32_t FillCapabilities(int fd) RTC_EXCLUSIVE_LOCKS_REQUIRED(_apiLock);
|
||||
int32_t Init() override;
|
||||
|
||||
private:
|
||||
|
||||
@ -99,7 +99,7 @@ int32_t DeviceInfoDS::Init() {
|
||||
return 0;
|
||||
}
|
||||
uint32_t DeviceInfoDS::NumberOfDevices() {
|
||||
ReadLockScoped cs(_apiLock);
|
||||
MutexLock lock(&_apiLock);
|
||||
return GetDeviceInfo(0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ int32_t DeviceInfoDS::GetDeviceName(uint32_t deviceNumber,
|
||||
uint32_t deviceUniqueIdUTF8Length,
|
||||
char* productUniqueIdUTF8,
|
||||
uint32_t productUniqueIdUTF8Length) {
|
||||
ReadLockScoped cs(_apiLock);
|
||||
MutexLock lock(&_apiLock);
|
||||
const int32_t result = GetDeviceInfo(
|
||||
deviceNumber, deviceNameUTF8, deviceNameLength, deviceUniqueIdUTF8,
|
||||
deviceUniqueIdUTF8Length, productUniqueIdUTF8, productUniqueIdUTF8Length);
|
||||
@ -287,7 +287,7 @@ IBaseFilter* DeviceInfoDS::GetDeviceFilter(const char* deviceUniqueIdUTF8,
|
||||
int32_t DeviceInfoDS::GetWindowsCapability(
|
||||
const int32_t capabilityIndex,
|
||||
VideoCaptureCapabilityWindows& windowsCapability) {
|
||||
ReadLockScoped cs(_apiLock);
|
||||
MutexLock lock(&_apiLock);
|
||||
|
||||
if (capabilityIndex < 0 || static_cast<size_t>(capabilityIndex) >=
|
||||
_captureCapabilitiesWindows.size()) {
|
||||
@ -584,7 +584,7 @@ int32_t DeviceInfoDS::DisplayCaptureSettingsDialogBox(
|
||||
void* parentWindow,
|
||||
uint32_t positionX,
|
||||
uint32_t positionY) {
|
||||
ReadLockScoped cs(_apiLock);
|
||||
MutexLock lock(&_apiLock);
|
||||
HWND window = (HWND)parentWindow;
|
||||
|
||||
IBaseFilter* filter = GetDeviceFilter(deviceUniqueIdUTF8, NULL, 0);
|
||||
|
||||
@ -85,7 +85,8 @@ class DeviceInfoDS : public DeviceInfoImpl {
|
||||
char* productUniqueIdUTF8,
|
||||
uint32_t productUniqueIdUTF8Length);
|
||||
|
||||
int32_t CreateCapabilityMap(const char* deviceUniqueIdUTF8) override;
|
||||
int32_t CreateCapabilityMap(const char* deviceUniqueIdUTF8) override
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(_apiLock);
|
||||
|
||||
private:
|
||||
ICreateDevEnum* _dsDevEnum;
|
||||
|
||||
Reference in New Issue
Block a user