Skip to content

Commit a1bda7b

Browse files
System AdministratorSystem Administrator
System Administrator
authored and
System Administrator
committed
Fix issue #32 #29 #26 #16 #1
1 parent 5a44e5f commit a1bda7b

14 files changed

+897
-683
lines changed

common/_Common.cc

+53-49
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ static webrtc::CriticalSectionWrapper* _fake_peer_connection_cs = webrtc::Critic
2525
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> _fake_peer_connection(webrtc::CreatePeerConnectionFactory());
2626
#endif
2727

28-
static const char kFirefoxPattern[] = "Firefox";
28+
#if 0
29+
static const char kFirefoxPattern[] = "Firefox";
2930
static const char kInternetExplorerPattern[] = "MSIE";
31+
#endif
3032
static const char kAutoDetectPattern[] = "";
3133
#if 1
3234
# define kAgentHoldingProxyInfo kAutoDetectPattern
@@ -38,58 +40,60 @@ static const char kAutoDetectPattern[] = "";
3840
# endif
3941
#endif
4042

43+
// TODO(mdi): On OSX We have to include "portallocatorfactory.cc" because it seems like "portallocatorfactory.o" is missing in libjingle_peerconnection
44+
// This could cause duplicated symbols if the bug get fixed by Google
4145
//
4246
// _RTCPortAllocatorFactory
4347
//
4448
class _RTCPortAllocatorFactory : public webrtc::PortAllocatorFactory
4549
{
46-
public:
50+
public:
4751
_RTCPortAllocatorFactory(rtc::Thread* worker_thread)
4852
: webrtc::PortAllocatorFactory(worker_thread)
4953
{
5054

51-
}
52-
virtual ~_RTCPortAllocatorFactory()
53-
{
54-
}
55-
56-
virtual cricket::PortAllocator* CreatePortAllocator(
57-
const std::vector<StunConfiguration>& stun,
58-
const std::vector<TurnConfiguration>& turn)
59-
{
60-
cricket::PortAllocator* allocator_ = webrtc::PortAllocatorFactory::CreatePortAllocator(stun, turn);
61-
if (allocator_) {
62-
cricket::ProtocolType protocol;
63-
rtc::ProxyInfo proxyInfo;
55+
}
56+
virtual ~_RTCPortAllocatorFactory()
57+
{
58+
}
59+
60+
virtual cricket::PortAllocator* CreatePortAllocator(
61+
const std::vector<StunConfiguration>& stun,
62+
const std::vector<TurnConfiguration>& turn)
63+
{
64+
cricket::PortAllocator* allocator_ = webrtc::PortAllocatorFactory::CreatePortAllocator(stun, turn);
65+
if (allocator_) {
66+
cricket::ProtocolType protocol;
67+
rtc::ProxyInfo proxyInfo;
6468
static const struct {
6569
std::string scheme;
6670
rtc::ProxyType proxy_type;
6771
} PROXIES[] = {
6872
{ "http", rtc::ProxyType::PROXY_HTTPS },
6973
{ "https", rtc::ProxyType::PROXY_HTTPS },
7074
{ "socks5", rtc::ProxyType::PROXY_SOCKS5 }
71-
};
72-
for (size_t i = 0; i < turn.size(); ++i) {
73-
if (cricket::StringToProto(turn[i].transport_type.c_str(), &protocol)) {
74-
if (protocol == cricket::ProtocolType::PROTO_TCP || protocol == cricket::ProtocolType::PROTO_SSLTCP) {
75-
for (size_t j = 0; j < sizeof(PROXIES) / sizeof(PROXIES[0]); ++j) {
76-
std::string url = PROXIES[j].scheme + "://" + turn[i].server.hostname();
77-
if (rtc::GetProxySettingsForUrl(kAgentHoldingProxyInfo, url.c_str(), &proxyInfo, false)) {
78-
if (proxyInfo.type != rtc::ProxyType::PROXY_NONE && !proxyInfo.address.IsAnyIP() && !proxyInfo.address.IsLoopbackIP() && proxyInfo.address.hostname() != "localhost") {
79-
if (proxyInfo.type == rtc::ProxyType::PROXY_UNKNOWN) {
80-
proxyInfo.type = PROXIES[j].proxy_type;
81-
}
82-
allocator_->set_proxy(kAgentHoldingProxyInfo, proxyInfo);
83-
goto proxy_done;
84-
}
85-
}
86-
}
87-
}
88-
}
89-
}
90-
}
91-
proxy_done:
92-
return allocator_;
75+
};
76+
for (size_t i = 0; i < turn.size(); ++i) {
77+
if (cricket::StringToProto(turn[i].transport_type.c_str(), &protocol)) {
78+
if (protocol == cricket::ProtocolType::PROTO_TCP || protocol == cricket::ProtocolType::PROTO_SSLTCP) {
79+
for (size_t j = 0; j < sizeof(PROXIES) / sizeof(PROXIES[0]); ++j) {
80+
std::string url = PROXIES[j].scheme + "://" + turn[i].server.hostname();
81+
if (rtc::GetProxySettingsForUrl(kAgentHoldingProxyInfo, url.c_str(), &proxyInfo, false)) {
82+
if (proxyInfo.type != rtc::ProxyType::PROXY_NONE && !proxyInfo.address.IsAnyIP() && !proxyInfo.address.IsLoopbackIP() && proxyInfo.address.hostname() != "localhost") {
83+
if (proxyInfo.type == rtc::ProxyType::PROXY_UNKNOWN) {
84+
proxyInfo.type = PROXIES[j].proxy_type;
85+
}
86+
allocator_->set_proxy(kAgentHoldingProxyInfo, proxyInfo);
87+
goto proxy_done;
88+
}
89+
}
90+
}
91+
}
92+
}
93+
}
94+
}
95+
proxy_done:
96+
return allocator_;
9397
}
9498
private:
9599

@@ -158,7 +162,7 @@ WEBRTC_EVERYWHERE_API rtc::Thread* GetWorkerThread()
158162
WEBRTC_EVERYWHERE_API rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> GetPortAllocatorFactory()
159163
{
160164
if (!_port_allocator_factory) {
161-
_port_allocator_factory = new rtc::RefCountedObject<_RTCPortAllocatorFactory>(GetWorkerThread());
165+
_port_allocator_factory = new rtc::RefCountedObject<_RTCPortAllocatorFactory>(GetWorkerThread());
162166
}
163167
return _port_allocator_factory;
164168
}
@@ -323,26 +327,26 @@ _File::_File(const char* path, bool write /*= false*/)
323327
: m_write(write)
324328

325329
{
326-
m_file = open(path, write ? O_CREAT | O_RDWR : O_CREAT | O_RDONLY);
330+
m_file = fopen(path, write ? "w" : "r");
327331
}
328332

329333
_File::~_File()
330334
{
331335
if (IsValid()) {
332-
close(m_file);
336+
fclose(m_file);
333337
m_file = 0;
334338
}
335339
}
336340

337341
bool _File::IsValid()const
338342
{
339-
return m_file != -1;
343+
return !!m_file;
340344
}
341345

342346
bool _File::LockInterProcess(bool exclusive /*= false*/)
343347
{
344348
if (IsValid()) {
345-
if (flock(m_file, exclusive ? LOCK_EX : LOCK_SH) == 0) {
349+
if (flock(fileno(m_file), exclusive ? LOCK_EX : LOCK_SH) == 0) {
346350
return true;
347351
}
348352
}
@@ -352,7 +356,7 @@ bool _File::LockInterProcess(bool exclusive /*= false*/)
352356
bool _File::UnlockInterProcess()
353357
{
354358
if (IsValid()) {
355-
if (flock(m_file, LOCK_UN) == 0) {
359+
if (flock(fileno(m_file), LOCK_UN) == 0) {
356360
return true;
357361
}
358362
}
@@ -364,10 +368,10 @@ cpp11::shared_ptr<_Buffer> _File::Read()
364368
{
365369
if (IsValid()) {
366370
struct stat _stat;
367-
if (fstat(m_file, &_stat) == 0 && _stat.st_size) {
371+
if (fstat(fileno(m_file), &_stat) == 0 && _stat.st_size) {
368372
cpp11::shared_ptr<_Buffer> buffer(new _Buffer(NULL, (size_t)_stat.st_size));
369373
if (buffer && buffer->getPtr()) {
370-
if (read(m_file, (void*)buffer->getPtr(), buffer->getSize()) == buffer->getSize()) {
374+
if (read(fileno(m_file), (void*)buffer->getPtr(), buffer->getSize()) == buffer->getSize()) {
371375
return buffer;
372376
}
373377
}
@@ -380,15 +384,15 @@ bool _File::Write(cpp11::shared_ptr<_Buffer>& buffer, bool append /*= false*/)
380384
{
381385
if (IsValid() && buffer && buffer->getPtr() && buffer->getSize()) {
382386
if (!append) {
383-
FILE* fp = fdopen(m_file, "w"); // will be closed when close() is called
387+
FILE* fp = fdopen(fileno(m_file), "w"); // will be closed when close() is called
384388
if (!fp) {
385389
return false;
386390
}
387391
rewind(fp);
388392
}
389-
if (write(m_file, buffer->getPtr(), buffer->getSize()) == buffer->getSize()) {
393+
if (write(fileno(m_file), buffer->getPtr(), buffer->getSize()) == buffer->getSize()) {
390394
if (!append) {
391-
if (ftruncate(m_file, buffer->getSize()) != 0) {
395+
if (ftruncate(fileno(m_file), buffer->getSize()) != 0) {
392396
return false;
393397
}
394398
}
@@ -404,7 +408,7 @@ bool _File::GetModificationTime(_FTIME *time)
404408
#define LONG long
405409
if (IsValid()) {
406410
struct stat _stat;
407-
if (fstat(m_file, &_stat) == 0) {
411+
if (fstat(fileno(m_file), &_stat) == 0) {
408412
time_t tt = (time_t)_stat.st_mtimespec.tv_sec;
409413
LONGLONG ll = Int32x32To64(tt, 10000000) + 116444736000000000;
410414
time->dwLowDateTime = (unsigned long) ll;

common/_Common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ class _File {
431431
#if WE_UNDER_WINDOWS
432432
HANDLE m_file;
433433
#else
434-
int m_file;
434+
FILE* m_file;
435435
#endif
436436
bool m_write;
437437
};

common/_MediaStreamTrack.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ _MediaStreamTrackVideo:: ~_MediaStreamTrackVideo()
294294
#if WE_UNDER_APPLE
295295
#include "mac/_webrtcvideocapturer.h"
296296
#include "webrtc/modules/video_capture/include/video_capture_factory.h"
297-
class _VideoCapturerFactory : public cricket::VideoCapturerFactory {
297+
class _VideoCapturerFactory : public cricket::VideoDeviceCapturerFactory {
298298
public:
299299
_VideoCapturerFactory() {}
300300
virtual ~_VideoCapturerFactory() {}
@@ -321,7 +321,7 @@ static cricket::VideoCapturer* OpenVideoCaptureDevice(std::string id) {
321321
// ISSUE: https://groups.google.com/forum/#!topic/discuss-webrtc/RV6oKhY2qEM
322322
#if WE_UNDER_APPLE
323323
cricket::DeviceManager* device_manager = static_cast<cricket::DeviceManager*>(dev_manager.get());
324-
device_manager->set_device_video_capturer_factory(new _VideoCapturerFactory());
324+
device_manager->SetVideoDeviceCapturerFactory(new _VideoCapturerFactory());
325325
#endif /* WE_UNDER_APPLE */
326326

327327
std::vector<cricket::Device> devs;

common/_RTCDTMFSender.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool _RTCDTMFSender::canInsertDTMF()
5555

5656
void _RTCDTMFSender::insertDTMF(const char* tones, long duration /*= 100*/, long interToneGap /*= 50*/)
5757
{
58-
m_sender->InsertDtmf(std::string(tones), duration, interToneGap);
58+
m_sender->InsertDtmf(std::string(tones), (int)duration, (int)interToneGap);
5959
}
6060

6161
cpp11::shared_ptr<_MediaStreamTrack> _RTCDTMFSender::track()

common/_RTCDisplay.cc

+2
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ void _RTCDisplay::StopVideoRenderer()
428428
if (m_renderer) {
429429
m_renderer->SetHwnd(m_renderer->GetHwnd(), NULL);
430430
}
431+
#elif WE_UNDER_APPLE
432+
431433
#endif
432434

433435
m_renderer.reset();

common/_Utils.cc

+15-13
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ std::map<long, const _UniqueObject*> _Utils::s_unique_objs;
3939
_FTIME _Utils::s_time_config_modif = { 0 };
4040
cpp11::shared_ptr<_EncryptCtx> _Utils::s_encrypt_ctx = nullPtr;
4141
std::string _Utils::s_UserAgent = "Unknown";
42+
rtc::Thread* _Utils::s_InitThread = nullptr;
4243

4344

4445
_Utils::_Utils()
@@ -53,7 +54,8 @@ _Utils::~_Utils()
5354

5455
WeError _Utils::Initialize(WeError(*InitializeAdditionals) (void) /*= NULL*/)
5556
{
56-
if(!g_bInitialized) {
57+
if (!g_bInitialized) {
58+
s_InitThread = rtc::Thread::Current();
5759
#if 0
5860
StartDebug();
5961
#endif
@@ -62,15 +64,13 @@ WeError _Utils::Initialize(WeError(*InitializeAdditionals) (void) /*= NULL*/)
6264
HRESULT hr = E_FAIL; // CoInitializeEx(NULL, COINIT_MULTITHREADED);
6365
g_winCoInitialize = SUCCEEDED(hr);
6466
rtc::EnsureWinsockInit();
65-
static rtc::Win32Thread w32_thread;
67+
static rtc::Win32Thread w32_thread;
6668
rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
6769
#endif
6870

6971
#if WE_UNDER_MAC
70-
#if 0 // NOT_USING_MAC_SERVER
7172
static rtc::MacCocoaSocketServer ss;
7273
static rtc::SocketServerScope ss_scope(&ss);
73-
#endif
7474
#endif
7575

7676
rtc::InitializeSSL();
@@ -96,6 +96,7 @@ WeError _Utils::DeInitialize(void)
9696
CoUninitialize();
9797
}
9898
#endif
99+
s_InitThread = nullptr;
99100
}
100101
return WeError_Success;
101102
}
@@ -738,14 +739,14 @@ WeError _Utils::ConvertToBMP(const void* _rgb32_ptr, size_t width, size_t height
738739
#endif
739740
typedef struct WE_PACKED tagBMPINFOHEADER{
740741
uint32_t biSize;
741-
long biWidth;
742-
long biHeight;
742+
uint32_t biWidth;
743+
uint32_t biHeight;
743744
uint16_t biPlanes;
744745
uint16_t biBitCount;
745746
uint32_t biCompression;
746747
uint32_t biSizeImage;
747-
long biXPelsPerMeter;
748-
long biYPelsPerMeter;
748+
uint32_t biXPelsPerMeter;
749+
uint32_t biYPelsPerMeter;
749750
uint32_t biClrUsed;
750751
uint32_t biClrImportant;
751752
} BMPINFOHEADER;
@@ -789,19 +790,19 @@ WeError _Utils::ConvertToBMP(const void* _rgb32_ptr, size_t width, size_t height
789790
# define BI_RGB 0L
790791
#endif
791792

792-
hdr_file.bfSize = (DWORD)*bmp_size_ptr;
793+
hdr_file.bfSize = (uint32_t)*bmp_size_ptr;
793794
hdr_file.bfOffBits = sizeof(BMPFILEHEADER) + sizeof(BMPINFOHEADER);
794795

795796
hdr_info.biSize = sizeof(BMPINFOHEADER);
796797
hdr_file.bfType = 0x4D42;
797-
hdr_info.biWidth = (LONG)width;
798-
hdr_info.biHeight = (LONG)height;
798+
hdr_info.biWidth = (uint32_t)width;
799+
hdr_info.biHeight = (uint32_t)height;
799800
hdr_info.biXPelsPerMeter = 0;
800801
hdr_info.biYPelsPerMeter = 0;
801802
hdr_info.biPlanes = 1;
802803
hdr_info.biBitCount = 32;
803804
hdr_info.biCompression = BI_RGB;
804-
hdr_info.biSizeImage = (DWORD)(stride * height);
805+
hdr_info.biSizeImage = (uint32_t)(stride * height);
805806
hdr_info.biClrImportant = 0;
806807
hdr_info.biClrUsed = 0;
807808
#if WE_UNDER_WINDOWS || WE_UNDER_APPLE
@@ -823,7 +824,8 @@ WeError _Utils::ConvertToBMP(const void* _rgb32_ptr, size_t width, size_t height
823824
}
824825

825826
#if 0
826-
FILE* file = fopen("C:\\Projects\\webrtc-everywhere\\screenshot.png", "wb");
827+
//FILE* file = fopen("C:\\Projects\\webrtc-everywhere\\screenshot.png", "wb");
828+
FILE* file = fopen("/Users/mamadou/Library/Application Support/webrtc-everywhere/screenshot.png", "wb");
827829
if (file) {
828830
fwrite(*bmp_pptr, 1, *bmp_size_ptr, file);
829831
fclose(file);

common/_Utils.h

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class WEBRTC_EVERYWHERE_API _Utils
5353

5454
static void SetUserAgent(const char* userAgent);
5555
static const char* GetUserAgent();
56+
57+
static rtc::Thread* GetInitThread() { return s_InitThread; }
5658

5759
private:
5860
#if _MSC_VER
@@ -64,6 +66,7 @@ class WEBRTC_EVERYWHERE_API _Utils
6466
static _FTIME s_time_config_modif;
6567
static cpp11::shared_ptr<_EncryptCtx> s_encrypt_ctx;
6668
static std::string s_UserAgent;
69+
static rtc::Thread* s_InitThread;
6770
#if _MSC_VER
6871
#pragma warning(pop)
6972
#endif

0 commit comments

Comments
 (0)