From 6acefdb70a0b6d86b4f5682f1a28257466efef9c Mon Sep 17 00:00:00 2001 From: Sergey Ulanov Date: Mon, 11 Dec 2017 17:38:13 -0800 Subject: [PATCH] Fixes to build WebRTC for Fuchsia 1. Added WEBRTC_FUCHSIA define. 2. Added PlatformThreadId typedef for Fuchsia. 3. Updated ifdefs for _strnicmp()/strncasecmd(), so _strnicmp() is used on all platforms 3. Updated ifdefs in clock.cc to avoid invalid assumption that POSIX = LINUX || MAC . Bug: chromium:750940 Change-Id: Id7aa98e017f467bcebb78a0b298ba91655502072 Reviewed-on: https://webrtc-review.googlesource.com/31641 Commit-Queue: Sergey Ulanov Reviewed-by: Tommi Reviewed-by: Stefan Holmer Reviewed-by: Niels Moller Cr-Commit-Position: refs/heads/master@{#21233} --- BUILD.gn | 3 ++ modules/rtp_rtcp/source/rtp_utility.cc | 8 +---- modules/video_capture/device_info_impl.cc | 38 +++++++---------------- rtc_base/platform_thread.cc | 8 ++++- rtc_base/platform_thread_types.h | 5 +++ system_wrappers/source/clock.cc | 27 ++++++++-------- 6 files changed, 41 insertions(+), 48 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index cfa24a1e00..6153e4fd92 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -134,6 +134,9 @@ config("common_inherited_config") { if (is_mac) { defines += [ "WEBRTC_MAC" ] } + if (is_fuchsia) { + defines += [ "WEBRTC_FUCHSIA" ] + } if (is_win) { defines += [ "WEBRTC_WIN", diff --git a/modules/rtp_rtcp/source/rtp_utility.cc b/modules/rtp_rtcp/source/rtp_utility.cc index 104265e730..c814716b44 100644 --- a/modules/rtp_rtcp/source/rtp_utility.cc +++ b/modules/rtp_rtcp/source/rtp_utility.cc @@ -14,6 +14,7 @@ #include "modules/rtp_rtcp/source/byte_io.h" #include "modules/rtp_rtcp/source/rtp_header_extensions.h" #include "rtc_base/logging.h" +#include "rtc_base/stringutils.h" namespace webrtc { @@ -37,17 +38,10 @@ enum { * Misc utility routines */ -#if defined(_WIN32) bool StringCompare(const char* str1, const char* str2, const uint32_t length) { return _strnicmp(str1, str2, length) == 0; } -#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) -bool StringCompare(const char* str1, const char* str2, - const uint32_t length) { - return strncasecmp(str1, str2, length) == 0; -} -#endif size_t Word32Align(size_t size) { uint32_t remainder = size % 4; diff --git a/modules/video_capture/device_info_impl.cc b/modules/video_capture/device_info_impl.cc index 0f8198c971..2f0a39f296 100644 --- a/modules/video_capture/device_info_impl.cc +++ b/modules/video_capture/device_info_impl.cc @@ -14,6 +14,7 @@ #include "modules/video_capture/device_info_impl.h" #include "modules/video_capture/video_capture_config.h" #include "rtc_base/logging.h" +#include "rtc_base/stringutils.h" #ifndef abs #define abs(a) (a >= 0 ? a : -a) @@ -21,6 +22,7 @@ namespace webrtc { namespace videocapturemodule { + DeviceInfoImpl::DeviceInfoImpl() : _apiLock(*RWLockWrapper::CreateRWLock()), _lastUsedDeviceName(NULL), @@ -33,6 +35,7 @@ DeviceInfoImpl::~DeviceInfoImpl(void) { delete &_apiLock; } + int32_t DeviceInfoImpl::NumberOfCapabilities(const char* deviceUniqueIdUTF8) { if (!deviceUniqueIdUTF8) return -1; @@ -40,15 +43,9 @@ int32_t DeviceInfoImpl::NumberOfCapabilities(const char* deviceUniqueIdUTF8) { _apiLock.AcquireLockShared(); if (_lastUsedDeviceNameLength == strlen((char*)deviceUniqueIdUTF8)) { -// Is it the same device that is asked for again. -#if defined(WEBRTC_MAC) || defined(WEBRTC_LINUX) - if (strncasecmp((char*)_lastUsedDeviceName, (char*)deviceUniqueIdUTF8, - _lastUsedDeviceNameLength) == 0) -#else + // Is it the same device that is asked for again. if (_strnicmp((char*)_lastUsedDeviceName, (char*)deviceUniqueIdUTF8, - _lastUsedDeviceNameLength) == 0) -#endif - { + _lastUsedDeviceNameLength) == 0) { // yes _apiLock.ReleaseLockShared(); return static_cast(_captureCapabilities.size()); @@ -69,16 +66,9 @@ int32_t DeviceInfoImpl::GetCapability(const char* deviceUniqueIdUTF8, ReadLockScoped cs(_apiLock); - if ((_lastUsedDeviceNameLength != strlen((char*)deviceUniqueIdUTF8)) -#if defined(WEBRTC_MAC) || defined(WEBRTC_LINUX) - || (strncasecmp((char*)_lastUsedDeviceName, (char*)deviceUniqueIdUTF8, - _lastUsedDeviceNameLength) != 0)) -#else - || (_strnicmp((char*)_lastUsedDeviceName, (char*)deviceUniqueIdUTF8, - _lastUsedDeviceNameLength) != 0)) -#endif - - { + if ((_lastUsedDeviceNameLength != strlen((char*)deviceUniqueIdUTF8)) || + (_strnicmp((char*)_lastUsedDeviceName, (char*)deviceUniqueIdUTF8, + _lastUsedDeviceNameLength) != 0)) { _apiLock.ReleaseLockShared(); _apiLock.AcquireLockExclusive(); if (-1 == CreateCapabilityMap(deviceUniqueIdUTF8)) { @@ -110,15 +100,9 @@ int32_t DeviceInfoImpl::GetBestMatchedCapability( return -1; ReadLockScoped cs(_apiLock); - if ((_lastUsedDeviceNameLength != strlen((char*)deviceUniqueIdUTF8)) -#if defined(WEBRTC_MAC) || defined(WEBRTC_LINUX) - || (strncasecmp((char*)_lastUsedDeviceName, (char*)deviceUniqueIdUTF8, - _lastUsedDeviceNameLength) != 0)) -#else - || (_strnicmp((char*)_lastUsedDeviceName, (char*)deviceUniqueIdUTF8, - _lastUsedDeviceNameLength) != 0)) -#endif - { + if ((_lastUsedDeviceNameLength != strlen((char*)deviceUniqueIdUTF8)) || + (_strnicmp((char*)_lastUsedDeviceName, (char*)deviceUniqueIdUTF8, + _lastUsedDeviceNameLength) != 0)) { _apiLock.ReleaseLockShared(); _apiLock.AcquireLockExclusive(); if (-1 == CreateCapabilityMap(deviceUniqueIdUTF8)) { diff --git a/rtc_base/platform_thread.cc b/rtc_base/platform_thread.cc index 58beed379d..06aee4ed5e 100644 --- a/rtc_base/platform_thread.cc +++ b/rtc_base/platform_thread.cc @@ -20,6 +20,10 @@ #include #endif +#if defined(WEBRTC_FUCHSIA) +#include +#endif + namespace rtc { PlatformThreadId CurrentThreadId() { @@ -31,8 +35,10 @@ PlatformThreadId CurrentThreadId() { ret = pthread_mach_thread_np(pthread_self()); #elif defined(WEBRTC_ANDROID) ret = gettid(); +#elif defined(WEBRTC_FUCHSIA) + ret = zx_thread_self(); #elif defined(WEBRTC_LINUX) - ret = syscall(__NR_gettid); + ret = syscall(__NR_gettid); #else // Default implementation for nacl and solaris. ret = reinterpret_cast(pthread_self()); diff --git a/rtc_base/platform_thread_types.h b/rtc_base/platform_thread_types.h index 66850c8c61..10c5de8397 100644 --- a/rtc_base/platform_thread_types.h +++ b/rtc_base/platform_thread_types.h @@ -14,6 +14,8 @@ #if defined(WEBRTC_WIN) #include #include +#elif defined(WEBRTC_FUCHSIA) +#include #elif defined(WEBRTC_POSIX) #include #include @@ -23,6 +25,9 @@ namespace rtc { #if defined(WEBRTC_WIN) typedef DWORD PlatformThreadId; typedef DWORD PlatformThreadRef; +#elif defined(WEBRTC_FUCHSIA) +typedef zx_handle_t PlatformThreadId; +typedef pthread_t PlatformThreadRef; #elif defined(WEBRTC_POSIX) typedef pid_t PlatformThreadId; typedef pthread_t PlatformThreadRef; diff --git a/system_wrappers/source/clock.cc b/system_wrappers/source/clock.cc index fc863552de..631974d9bc 100644 --- a/system_wrappers/source/clock.cc +++ b/system_wrappers/source/clock.cc @@ -10,19 +10,19 @@ #include "system_wrappers/include/clock.h" -#if defined(_WIN32) +#if defined(WEBRTC_WIN) // Windows needs to be included before mmsystem.h #include "rtc_base/win32.h" #include -#elif ((defined WEBRTC_LINUX) || (defined WEBRTC_MAC)) +#elif defined(WEBRTC_POSIX) #include #include -#endif +#endif // defined(WEBRTC_POSIX) #include "rtc_base/criticalsection.h" #include "rtc_base/timeutils.h" @@ -79,7 +79,7 @@ class RealTimeClock : public Clock { } }; -#if defined(_WIN32) +#if defined(WEBRTC_WIN) // TODO(pbos): Consider modifying the implementation to synchronize itself // against system time (update ref_point_, make it non-const) periodically to // prevent clock drift. @@ -181,7 +181,7 @@ class WindowsRealTimeClock : public RealTimeClock { const ReferencePoint ref_point_; }; -#elif ((defined WEBRTC_LINUX) || (defined WEBRTC_MAC)) +#elif defined(WEBRTC_POSIX) class UnixRealTimeClock : public RealTimeClock { public: UnixRealTimeClock() {} @@ -198,13 +198,14 @@ class UnixRealTimeClock : public RealTimeClock { return tv; } }; -#endif +#endif // defined(WEBRTC_POSIX) -#if defined(_WIN32) +#if defined(WEBRTC_WIN) static WindowsRealTimeClock* volatile g_shared_clock = nullptr; -#endif +#endif // defined(WEBRTC_WIN) + Clock* Clock::GetRealTimeClock() { -#if defined(_WIN32) +#if defined(WEBRTC_WIN) // This read relies on volatile read being atomic-load-acquire. This is // true in MSVC since at least 2005: // "A read of a volatile object (volatile read) has Acquire semantics" @@ -219,12 +220,12 @@ Clock* Clock::GetRealTimeClock() { delete clock; } return g_shared_clock; -#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) +#elif defined(WEBRTC_POSIX) static UnixRealTimeClock clock; return &clock; -#else - return NULL; -#endif +#else // defined(WEBRTC_POSIX) + return nullptr; +#endif // !defined(WEBRTC_WIN) || defined(WEBRTC_POSIX) } SimulatedClock::SimulatedClock(int64_t initial_time_us)