Skip to content

Commit

Permalink
Fixes to build WebRTC for Fuchsia
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Tommi <[email protected]>
Reviewed-by: Stefan Holmer <[email protected]>
Reviewed-by: Niels Moller <[email protected]>
Cr-Commit-Position: refs/heads/master@{#21233}
  • Loading branch information
SergeyUlanov authored and Commit Bot committed Dec 12, 2017
1 parent 3fe1b15 commit 6acefdb
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 48 deletions.
3 changes: 3 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 1 addition & 7 deletions modules/rtp_rtcp/source/rtp_utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
Expand Down
38 changes: 11 additions & 27 deletions modules/video_capture/device_info_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
#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)
#endif

namespace webrtc {
namespace videocapturemodule {

DeviceInfoImpl::DeviceInfoImpl()
: _apiLock(*RWLockWrapper::CreateRWLock()),
_lastUsedDeviceName(NULL),
Expand All @@ -33,22 +35,17 @@ DeviceInfoImpl::~DeviceInfoImpl(void) {

delete &_apiLock;
}

int32_t DeviceInfoImpl::NumberOfCapabilities(const char* deviceUniqueIdUTF8) {
if (!deviceUniqueIdUTF8)
return -1;

_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<int32_t>(_captureCapabilities.size());
Expand All @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
8 changes: 7 additions & 1 deletion rtc_base/platform_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <sys/syscall.h>
#endif

#if defined(WEBRTC_FUCHSIA)
#include <zircon/process.h>
#endif

namespace rtc {

PlatformThreadId CurrentThreadId() {
Expand All @@ -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<pid_t>(pthread_self());
Expand Down
5 changes: 5 additions & 0 deletions rtc_base/platform_thread_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#if defined(WEBRTC_WIN)
#include <winsock2.h>
#include <windows.h>
#elif defined(WEBRTC_FUCHSIA)
#include <zircon/types.h>
#elif defined(WEBRTC_POSIX)
#include <pthread.h>
#include <unistd.h>
Expand All @@ -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;
Expand Down
27 changes: 14 additions & 13 deletions system_wrappers/source/clock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <MMSystem.h>

#elif ((defined WEBRTC_LINUX) || (defined WEBRTC_MAC))
#elif defined(WEBRTC_POSIX)

#include <sys/time.h>
#include <time.h>

#endif
#endif // defined(WEBRTC_POSIX)

#include "rtc_base/criticalsection.h"
#include "rtc_base/timeutils.h"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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() {}
Expand All @@ -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"
Expand All @@ -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)
Expand Down

0 comments on commit 6acefdb

Please sign in to comment.