Skip to content

Commit

Permalink
Fix issue #11(Add support for p2p data api (DataChannel)), #10(Adds s…
Browse files Browse the repository at this point in the history
…upport for p2p DTMF) and #3(Implement secure prompt in getUserMedia)
  • Loading branch information
sarandogou committed Aug 6, 2014
1 parent 2dfa049 commit 1faea2c
Show file tree
Hide file tree
Showing 205 changed files with 39,426 additions and 1,106 deletions.
8 changes: 6 additions & 2 deletions WebRTC.htm
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
if (!element.pluginObj && stream) {
// FIXME
var _pluginObj = document.createElement('object');
_pluginObj.innerHTML = '<param name=\"windowless\" value=\"false\">';
var _isIE = (Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(window, "ActiveXObject")) || ("ActiveXObject" in window);
if (_isIE) {
_pluginObj.setAttribute('classid', 'CLSID:7FD49E23-C8D7-4C4F-93A1-F7EACFA1EC53');
Expand Down Expand Up @@ -290,12 +291,13 @@
var completeStyle = window.getComputedStyle(myvideo_local, null);
// IE11: "window.ActiveXObject" not defined -> http://msdn.microsoft.com/en-us/library/ie/dn423948%28v=vs.85%29.aspx
var pluginObj = document.createElement('object');
pluginObj.innerHTML = '<param name=\"windowless\" value=\"false\">';
pluginObj.setAttribute('id', 'WebrtcEverywhere');
if ((Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(window, "ActiveXObject")) || ("ActiveXObject" in window)) {
pluginObj.setAttribute('classid', 'CLSID:7FD49E23-C8D7-4C4F-93A1-F7EACFA1EC53');
} else {
pluginObj.setAttribute('type', 'application/webrtc-everywhere');
}
pluginObj.setAttribute('id', 'WebrtcEverywhere');
document.body.appendChild(pluginObj);
pluginObj.setAttribute('width', '0');
pluginObj.setAttribute('height', '0');
Expand Down Expand Up @@ -323,6 +325,8 @@
<canvas id="mycanvas" width="250px" height="250px" style="margin-top: 72px; border:1px solid #000; z-index: 10"></canvas>


<!--object id="video_local" width="50px" height="50px" type="application/webrtc-everywhere" style="background-color: #000000;"></object-->
<!--object id="video_local" width="50px" height="50px" classid="clsid:7fd49e23-c8d7-4c4f-93a1-f7eacfa1ec53" style="background-color: #000000;">
<param name="windowless" value=true>
</object-->
</body>
</HTML>
32 changes: 16 additions & 16 deletions common/_Buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
#include "_Buffer.h"
#include "_Debug.h"

_Buffer::_Buffer()
: m_pPtr(NULL)
, m_nSize(0)
_Buffer::_Buffer(const void* ptr, size_t size)
: m_pPtr(NULL)
, m_nSize(0)
{
m_pPtr = malloc(size + 1);
if (!m_pPtr) {
WE_DEBUG_ERROR("Failed to allocate buffer with size=%lu", size);
return;
}
((char*)m_pPtr)[size] = '\0';
if (size && ptr) {
memcpy(m_pPtr, ptr, size);
}
m_nSize = size;
}

_Buffer::~_Buffer()
Expand All @@ -19,21 +29,11 @@ WeError _Buffer::New(const void* ptr, size_t size, _Buffer** ppObj)
WE_DEBUG_ERROR("Invalid argument");
return WeError_InvalidArgument;
}
(*ppObj) = new _Buffer();
if (!(*ppObj)) {
(*ppObj) = new _Buffer(ptr, size);
if (!(*ppObj) || (*ppObj)->getSize() != size) {
SafeFree(ppObj);
WE_DEBUG_ERROR("Failed to create new buffer");
return WeError_OutOfMemory;
}
(*ppObj)->m_pPtr = malloc(size + 1);
if (!(*ppObj)) {
WE_DEBUG_ERROR("Failed to allocate buffer with size=%lu", size);
SafeFree(ppObj);
return WeError_OutOfMemory;
}
((char*)(*ppObj)->m_pPtr)[size] = '\0';
if (ptr) {
memcpy((*ppObj)->m_pPtr, ptr, size);
}
(*ppObj)->m_nSize = size;
return WeError_Success;
}
2 changes: 1 addition & 1 deletion common/_Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class WEBRTC_EVERYWHERE_API _Buffer
{
public:
_Buffer(const void* ptr, size_t size);
virtual ~_Buffer();
WE_INLINE const void* getPtr()const {
return m_pPtr;
Expand All @@ -18,7 +19,6 @@ class WEBRTC_EVERYWHERE_API _Buffer
static WeError New(const void* ptr, size_t size, _Buffer** ppObj);

private:
_Buffer();
void* m_pPtr;
size_t m_nSize;
};
Expand Down
120 changes: 119 additions & 1 deletion common/_Common.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* Copyright(C) 2014 Sarandogou <https://github.com/sarandogou/webrtc-everywhere> */
#include "_Common.h"
#include "_Utils.h"
#include "_Buffer.h"
#include "_MediaStream.h"

#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"

#include <sys/stat.h>

#if !defined(PEERCONN_MODE)
#define PEERCONN_MODE 1
#endif
Expand Down Expand Up @@ -61,7 +64,7 @@ WEBRTC_EVERYWHERE_API void ReleaseFakePeerConnectionFactory()
#endif
}

talk_base::scoped_refptr<_RTCMediaConstraints> BuildConstraints(const _MediaConstraintsObj* _constraints /*= NULL*/)
talk_base::scoped_refptr<_RTCMediaConstraints> BuildConstraints(const _MediaConstraintsObj* _constraints)
{
talk_base::scoped_refptr<_RTCMediaConstraints> contraints = new talk_base::RefCountedObject<_RTCMediaConstraints>();

Expand Down Expand Up @@ -104,3 +107,118 @@ _UniqueObject::~_UniqueObject()



#if WE_UNDER_WINDOWS

_File::_File(const TCHAR* path, bool write /*= false*/)
: m_write(write)

{
if ((m_file = CreateFile(path,
GENERIC_READ | (write ? GENERIC_WRITE : 0),
FILE_SHARE_READ | (write ? FILE_SHARE_WRITE : 0),
NULL,
(write ? OPEN_ALWAYS : OPEN_EXISTING),
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS /*| FILE_FLAG_NO_BUFFERING*/,
NULL)) == INVALID_HANDLE_VALUE) {
m_file = NULL;
}
}

_File::~_File()
{
if (IsValid()) {
CloseHandle(m_file);
m_file = NULL;
}
}

bool _File::IsValid()const
{
return (m_file && m_file != INVALID_HANDLE_VALUE);
}

bool _File::LockInterProcess(bool exclusive /*= false*/)
{
if (IsValid()) {
DWORD flags = exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0;
static const DWORD len = 0xffffffff;
OVERLAPPED offset;
ZeroMemory(&offset, sizeof(offset));
if (LockFileEx(m_file, flags, 0, len, len, &offset)) {
return true;
}
}
return false;
}

bool _File::UnlockInterProcess()
{
if (IsValid()) {
static const DWORD len = 0xffffffff;
OVERLAPPED offset;
ZeroMemory(&offset, sizeof(offset));
if (UnlockFileEx(m_file, 0, len, len, &offset)) {
return true;
}
}
return false;
}

// No safe: up to the caller to lock the file
cpp11::shared_ptr<_Buffer> _File::Read()
{
if (IsValid()) {
DWORD nNumberOfBytesToRead = GetFileSize(m_file, NULL);
if (nNumberOfBytesToRead != INVALID_FILE_SIZE && nNumberOfBytesToRead) {
cpp11::shared_ptr<_Buffer> buffer(new _Buffer(NULL, nNumberOfBytesToRead));
if (buffer && buffer->getPtr()) {
DWORD nNumberOfBytesRead;
OVERLAPPED offset;
ZeroMemory(&offset, sizeof(offset));
if (ReadFile(m_file, (LPVOID)buffer->getPtr(), nNumberOfBytesToRead, &nNumberOfBytesRead, &offset)) {
if (buffer->getSize() == nNumberOfBytesRead) {
return buffer;
}
}
}
}
}
return nullPtr;
}

bool _File::Write(cpp11::shared_ptr<_Buffer>& buffer, bool append /*= false*/)
{
if (IsValid() && buffer && buffer->getPtr() && buffer->getSize()) {
DWORD dwBytesWritten = 0;
OVERLAPPED offset;
ZeroMemory(&offset, sizeof(offset));
if (!append) {
static LARGE_INTEGER li_zero = { 0 };
if (!SetFilePointerEx(m_file, li_zero, NULL, FILE_BEGIN)) {
return false;
}
}
if (WriteFile(m_file, buffer->getPtr(), buffer->getSize(), &dwBytesWritten, &offset)) {
if (dwBytesWritten == buffer->getSize()) {
return (SetEndOfFile(m_file) == TRUE);
}
}
}
return false;
}

bool _File::GetModificationTime(_FTIME *time)
{
if (IsValid()) {
if (GetFileTime(m_file, NULL, NULL, time)) {
return true;
}
}
return false;
}

#else // !WE_UNDER_WINDOWS
#error "Not implemented"
#endif


Loading

0 comments on commit 1faea2c

Please sign in to comment.