Skip to content

Commit

Permalink
Fix issue #32 #29 #26 #16 #1
Browse files Browse the repository at this point in the history
  • Loading branch information
System Administrator authored and System Administrator committed Aug 15, 2015
1 parent 5a44e5f commit a1bda7b
Show file tree
Hide file tree
Showing 14 changed files with 897 additions and 683 deletions.
102 changes: 53 additions & 49 deletions common/_Common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ static webrtc::CriticalSectionWrapper* _fake_peer_connection_cs = webrtc::Critic
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> _fake_peer_connection(webrtc::CreatePeerConnectionFactory());
#endif

static const char kFirefoxPattern[] = "Firefox";
#if 0
static const char kFirefoxPattern[] = "Firefox";
static const char kInternetExplorerPattern[] = "MSIE";
#endif
static const char kAutoDetectPattern[] = "";
#if 1
# define kAgentHoldingProxyInfo kAutoDetectPattern
Expand All @@ -38,58 +40,60 @@ static const char kAutoDetectPattern[] = "";
# endif
#endif

// TODO(mdi): On OSX We have to include "portallocatorfactory.cc" because it seems like "portallocatorfactory.o" is missing in libjingle_peerconnection
// This could cause duplicated symbols if the bug get fixed by Google
//
// _RTCPortAllocatorFactory
//
class _RTCPortAllocatorFactory : public webrtc::PortAllocatorFactory
{
public:
public:
_RTCPortAllocatorFactory(rtc::Thread* worker_thread)
: webrtc::PortAllocatorFactory(worker_thread)
{

}
virtual ~_RTCPortAllocatorFactory()
{
}

virtual cricket::PortAllocator* CreatePortAllocator(
const std::vector<StunConfiguration>& stun,
const std::vector<TurnConfiguration>& turn)
{
cricket::PortAllocator* allocator_ = webrtc::PortAllocatorFactory::CreatePortAllocator(stun, turn);
if (allocator_) {
cricket::ProtocolType protocol;
rtc::ProxyInfo proxyInfo;
}
virtual ~_RTCPortAllocatorFactory()
{
}

virtual cricket::PortAllocator* CreatePortAllocator(
const std::vector<StunConfiguration>& stun,
const std::vector<TurnConfiguration>& turn)
{
cricket::PortAllocator* allocator_ = webrtc::PortAllocatorFactory::CreatePortAllocator(stun, turn);
if (allocator_) {
cricket::ProtocolType protocol;
rtc::ProxyInfo proxyInfo;
static const struct {
std::string scheme;
rtc::ProxyType proxy_type;
} PROXIES[] = {
{ "http", rtc::ProxyType::PROXY_HTTPS },
{ "https", rtc::ProxyType::PROXY_HTTPS },
{ "socks5", rtc::ProxyType::PROXY_SOCKS5 }
};
for (size_t i = 0; i < turn.size(); ++i) {
if (cricket::StringToProto(turn[i].transport_type.c_str(), &protocol)) {
if (protocol == cricket::ProtocolType::PROTO_TCP || protocol == cricket::ProtocolType::PROTO_SSLTCP) {
for (size_t j = 0; j < sizeof(PROXIES) / sizeof(PROXIES[0]); ++j) {
std::string url = PROXIES[j].scheme + "://" + turn[i].server.hostname();
if (rtc::GetProxySettingsForUrl(kAgentHoldingProxyInfo, url.c_str(), &proxyInfo, false)) {
if (proxyInfo.type != rtc::ProxyType::PROXY_NONE && !proxyInfo.address.IsAnyIP() && !proxyInfo.address.IsLoopbackIP() && proxyInfo.address.hostname() != "localhost") {
if (proxyInfo.type == rtc::ProxyType::PROXY_UNKNOWN) {
proxyInfo.type = PROXIES[j].proxy_type;
}
allocator_->set_proxy(kAgentHoldingProxyInfo, proxyInfo);
goto proxy_done;
}
}
}
}
}
}
}
proxy_done:
return allocator_;
};
for (size_t i = 0; i < turn.size(); ++i) {
if (cricket::StringToProto(turn[i].transport_type.c_str(), &protocol)) {
if (protocol == cricket::ProtocolType::PROTO_TCP || protocol == cricket::ProtocolType::PROTO_SSLTCP) {
for (size_t j = 0; j < sizeof(PROXIES) / sizeof(PROXIES[0]); ++j) {
std::string url = PROXIES[j].scheme + "://" + turn[i].server.hostname();
if (rtc::GetProxySettingsForUrl(kAgentHoldingProxyInfo, url.c_str(), &proxyInfo, false)) {
if (proxyInfo.type != rtc::ProxyType::PROXY_NONE && !proxyInfo.address.IsAnyIP() && !proxyInfo.address.IsLoopbackIP() && proxyInfo.address.hostname() != "localhost") {
if (proxyInfo.type == rtc::ProxyType::PROXY_UNKNOWN) {
proxyInfo.type = PROXIES[j].proxy_type;
}
allocator_->set_proxy(kAgentHoldingProxyInfo, proxyInfo);
goto proxy_done;
}
}
}
}
}
}
}
proxy_done:
return allocator_;
}
private:

Expand Down Expand Up @@ -158,7 +162,7 @@ WEBRTC_EVERYWHERE_API rtc::Thread* GetWorkerThread()
WEBRTC_EVERYWHERE_API rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> GetPortAllocatorFactory()
{
if (!_port_allocator_factory) {
_port_allocator_factory = new rtc::RefCountedObject<_RTCPortAllocatorFactory>(GetWorkerThread());
_port_allocator_factory = new rtc::RefCountedObject<_RTCPortAllocatorFactory>(GetWorkerThread());
}
return _port_allocator_factory;
}
Expand Down Expand Up @@ -323,26 +327,26 @@ _File::_File(const char* path, bool write /*= false*/)
: m_write(write)

{
m_file = open(path, write ? O_CREAT | O_RDWR : O_CREAT | O_RDONLY);
m_file = fopen(path, write ? "w" : "r");
}

_File::~_File()
{
if (IsValid()) {
close(m_file);
fclose(m_file);
m_file = 0;
}
}

bool _File::IsValid()const
{
return m_file != -1;
return !!m_file;
}

bool _File::LockInterProcess(bool exclusive /*= false*/)
{
if (IsValid()) {
if (flock(m_file, exclusive ? LOCK_EX : LOCK_SH) == 0) {
if (flock(fileno(m_file), exclusive ? LOCK_EX : LOCK_SH) == 0) {
return true;
}
}
Expand All @@ -352,7 +356,7 @@ bool _File::LockInterProcess(bool exclusive /*= false*/)
bool _File::UnlockInterProcess()
{
if (IsValid()) {
if (flock(m_file, LOCK_UN) == 0) {
if (flock(fileno(m_file), LOCK_UN) == 0) {
return true;
}
}
Expand All @@ -364,10 +368,10 @@ cpp11::shared_ptr<_Buffer> _File::Read()
{
if (IsValid()) {
struct stat _stat;
if (fstat(m_file, &_stat) == 0 && _stat.st_size) {
if (fstat(fileno(m_file), &_stat) == 0 && _stat.st_size) {
cpp11::shared_ptr<_Buffer> buffer(new _Buffer(NULL, (size_t)_stat.st_size));
if (buffer && buffer->getPtr()) {
if (read(m_file, (void*)buffer->getPtr(), buffer->getSize()) == buffer->getSize()) {
if (read(fileno(m_file), (void*)buffer->getPtr(), buffer->getSize()) == buffer->getSize()) {
return buffer;
}
}
Expand All @@ -380,15 +384,15 @@ bool _File::Write(cpp11::shared_ptr<_Buffer>& buffer, bool append /*= false*/)
{
if (IsValid() && buffer && buffer->getPtr() && buffer->getSize()) {
if (!append) {
FILE* fp = fdopen(m_file, "w"); // will be closed when close() is called
FILE* fp = fdopen(fileno(m_file), "w"); // will be closed when close() is called
if (!fp) {
return false;
}
rewind(fp);
}
if (write(m_file, buffer->getPtr(), buffer->getSize()) == buffer->getSize()) {
if (write(fileno(m_file), buffer->getPtr(), buffer->getSize()) == buffer->getSize()) {
if (!append) {
if (ftruncate(m_file, buffer->getSize()) != 0) {
if (ftruncate(fileno(m_file), buffer->getSize()) != 0) {
return false;
}
}
Expand All @@ -404,7 +408,7 @@ bool _File::GetModificationTime(_FTIME *time)
#define LONG long
if (IsValid()) {
struct stat _stat;
if (fstat(m_file, &_stat) == 0) {
if (fstat(fileno(m_file), &_stat) == 0) {
time_t tt = (time_t)_stat.st_mtimespec.tv_sec;
LONGLONG ll = Int32x32To64(tt, 10000000) + 116444736000000000;
time->dwLowDateTime = (unsigned long) ll;
Expand Down
2 changes: 1 addition & 1 deletion common/_Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ class _File {
#if WE_UNDER_WINDOWS
HANDLE m_file;
#else
int m_file;
FILE* m_file;
#endif
bool m_write;
};
Expand Down
4 changes: 2 additions & 2 deletions common/_MediaStreamTrack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ _MediaStreamTrackVideo:: ~_MediaStreamTrackVideo()
#if WE_UNDER_APPLE
#include "mac/_webrtcvideocapturer.h"
#include "webrtc/modules/video_capture/include/video_capture_factory.h"
class _VideoCapturerFactory : public cricket::VideoCapturerFactory {
class _VideoCapturerFactory : public cricket::VideoDeviceCapturerFactory {
public:
_VideoCapturerFactory() {}
virtual ~_VideoCapturerFactory() {}
Expand All @@ -321,7 +321,7 @@ static cricket::VideoCapturer* OpenVideoCaptureDevice(std::string id) {
// ISSUE: https://groups.google.com/forum/#!topic/discuss-webrtc/RV6oKhY2qEM
#if WE_UNDER_APPLE
cricket::DeviceManager* device_manager = static_cast<cricket::DeviceManager*>(dev_manager.get());
device_manager->set_device_video_capturer_factory(new _VideoCapturerFactory());
device_manager->SetVideoDeviceCapturerFactory(new _VideoCapturerFactory());
#endif /* WE_UNDER_APPLE */

std::vector<cricket::Device> devs;
Expand Down
2 changes: 1 addition & 1 deletion common/_RTCDTMFSender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool _RTCDTMFSender::canInsertDTMF()

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

cpp11::shared_ptr<_MediaStreamTrack> _RTCDTMFSender::track()
Expand Down
2 changes: 2 additions & 0 deletions common/_RTCDisplay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ void _RTCDisplay::StopVideoRenderer()
if (m_renderer) {
m_renderer->SetHwnd(m_renderer->GetHwnd(), NULL);
}
#elif WE_UNDER_APPLE

#endif

m_renderer.reset();
Expand Down
28 changes: 15 additions & 13 deletions common/_Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ std::map<long, const _UniqueObject*> _Utils::s_unique_objs;
_FTIME _Utils::s_time_config_modif = { 0 };
cpp11::shared_ptr<_EncryptCtx> _Utils::s_encrypt_ctx = nullPtr;
std::string _Utils::s_UserAgent = "Unknown";
rtc::Thread* _Utils::s_InitThread = nullptr;


_Utils::_Utils()
Expand All @@ -53,7 +54,8 @@ _Utils::~_Utils()

WeError _Utils::Initialize(WeError(*InitializeAdditionals) (void) /*= NULL*/)
{
if(!g_bInitialized) {
if (!g_bInitialized) {
s_InitThread = rtc::Thread::Current();
#if 0
StartDebug();
#endif
Expand All @@ -62,15 +64,13 @@ WeError _Utils::Initialize(WeError(*InitializeAdditionals) (void) /*= NULL*/)
HRESULT hr = E_FAIL; // CoInitializeEx(NULL, COINIT_MULTITHREADED);
g_winCoInitialize = SUCCEEDED(hr);
rtc::EnsureWinsockInit();
static rtc::Win32Thread w32_thread;
static rtc::Win32Thread w32_thread;
rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
#endif

#if WE_UNDER_MAC
#if 0 // NOT_USING_MAC_SERVER
static rtc::MacCocoaSocketServer ss;
static rtc::SocketServerScope ss_scope(&ss);
#endif
#endif

rtc::InitializeSSL();
Expand All @@ -96,6 +96,7 @@ WeError _Utils::DeInitialize(void)
CoUninitialize();
}
#endif
s_InitThread = nullptr;
}
return WeError_Success;
}
Expand Down Expand Up @@ -738,14 +739,14 @@ WeError _Utils::ConvertToBMP(const void* _rgb32_ptr, size_t width, size_t height
#endif
typedef struct WE_PACKED tagBMPINFOHEADER{
uint32_t biSize;
long biWidth;
long biHeight;
uint32_t biWidth;
uint32_t biHeight;
uint16_t biPlanes;
uint16_t biBitCount;
uint32_t biCompression;
uint32_t biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
uint32_t biXPelsPerMeter;
uint32_t biYPelsPerMeter;
uint32_t biClrUsed;
uint32_t biClrImportant;
} BMPINFOHEADER;
Expand Down Expand Up @@ -789,19 +790,19 @@ WeError _Utils::ConvertToBMP(const void* _rgb32_ptr, size_t width, size_t height
# define BI_RGB 0L
#endif

hdr_file.bfSize = (DWORD)*bmp_size_ptr;
hdr_file.bfSize = (uint32_t)*bmp_size_ptr;
hdr_file.bfOffBits = sizeof(BMPFILEHEADER) + sizeof(BMPINFOHEADER);

hdr_info.biSize = sizeof(BMPINFOHEADER);
hdr_file.bfType = 0x4D42;
hdr_info.biWidth = (LONG)width;
hdr_info.biHeight = (LONG)height;
hdr_info.biWidth = (uint32_t)width;
hdr_info.biHeight = (uint32_t)height;
hdr_info.biXPelsPerMeter = 0;
hdr_info.biYPelsPerMeter = 0;
hdr_info.biPlanes = 1;
hdr_info.biBitCount = 32;
hdr_info.biCompression = BI_RGB;
hdr_info.biSizeImage = (DWORD)(stride * height);
hdr_info.biSizeImage = (uint32_t)(stride * height);
hdr_info.biClrImportant = 0;
hdr_info.biClrUsed = 0;
#if WE_UNDER_WINDOWS || WE_UNDER_APPLE
Expand All @@ -823,7 +824,8 @@ WeError _Utils::ConvertToBMP(const void* _rgb32_ptr, size_t width, size_t height
}

#if 0
FILE* file = fopen("C:\\Projects\\webrtc-everywhere\\screenshot.png", "wb");
//FILE* file = fopen("C:\\Projects\\webrtc-everywhere\\screenshot.png", "wb");
FILE* file = fopen("/Users/mamadou/Library/Application Support/webrtc-everywhere/screenshot.png", "wb");
if (file) {
fwrite(*bmp_pptr, 1, *bmp_size_ptr, file);
fclose(file);
Expand Down
3 changes: 3 additions & 0 deletions common/_Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class WEBRTC_EVERYWHERE_API _Utils

static void SetUserAgent(const char* userAgent);
static const char* GetUserAgent();

static rtc::Thread* GetInitThread() { return s_InitThread; }

private:
#if _MSC_VER
Expand All @@ -64,6 +66,7 @@ class WEBRTC_EVERYWHERE_API _Utils
static _FTIME s_time_config_modif;
static cpp11::shared_ptr<_EncryptCtx> s_encrypt_ctx;
static std::string s_UserAgent;
static rtc::Thread* s_InitThread;
#if _MSC_VER
#pragma warning(pop)
#endif
Expand Down
Loading

0 comments on commit a1bda7b

Please sign in to comment.