Skip to content

Webrtc win #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DEPOT_TOOLS_DIR="$THIRD_PARTY_DIR/depot_tools"
OS=$(go env GOOS)
ARCH=$(go env GOARCH)
CONFIG="Release"
COMMIT="c279861207c5b15fc51069e96595782350e0ac12" # branch-heads/58
COMMIT="6f21dc245689c29730002da09534a8d275e6aa92" # branch-heads/62

# Values are from,
# https://github.com/golang/go/blob/master/src/go/build/syslist.go
Expand Down
32 changes: 32 additions & 0 deletions ctestenums-win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// +build windows

package webrtc

/*
#ifdef _WIN32
int CGO_IceTransportPolicyNone = 0;
int CGO_IceTransportPolicyRelay = 0;
int CGO_IceTransportPolicyNoHost = 0;
int CGO_IceTransportPolicyAll = 0;
int CGO_BundlePolicyBalanced = 0;
int CGO_BundlePolicyMaxBundle = 0;
int CGO_BundlePolicyMaxCompat = 0;
int CGO_SignalingStateStable = 0;
int CGO_SignalingStateHaveLocalOffer = 0;
int CGO_SignalingStateHaveLocalPrAnswer = 0;
int CGO_SignalingStateHaveRemoteOffer = 0;
int CGO_SignalingStateHaveRemotePrAnswer = 0;
int CGO_SignalingStateClosed = 0;
int CGO_IceConnectionStateNew = 0;
int CGO_IceConnectionStateChecking = 0;
int CGO_IceConnectionStateConnected = 0;
int CGO_IceConnectionStateCompleted = 0;
int CGO_IceConnectionStateFailed = 0;
int CGO_IceConnectionStateDisconnected = 0;
int CGO_IceConnectionStateClosed = 0;
int CGO_IceGatheringStateNew = 0;
int CGO_IceGatheringStateGathering = 0;
int CGO_IceGatheringStateComplete = 0;
#endif
*/
import "C"
2 changes: 2 additions & 0 deletions ctestenums.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !_WIN32 || WIN_WEBRTC
#include "ctestenums.h"
#include "webrtc/api/peerconnectioninterface.h"

Expand Down Expand Up @@ -64,3 +65,4 @@ const int CGO_IceGatheringStateGathering =
PeerConnectionInterface::IceGatheringState::kIceGatheringGathering;
const int CGO_IceGatheringStateComplete =
PeerConnectionInterface::IceGatheringState::kIceGatheringComplete;
#endif
6 changes: 6 additions & 0 deletions ctestenums.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#ifndef NOMINMAX
# define NOMINMAX
#endif

#ifndef _C_TEST_ENUMS_H_
#define _C_TEST_ENUMS_H_

#ifndef _WIN32
#define WEBRTC_POSIX 1
#endif

#ifdef __cplusplus
extern "C" {
Expand Down
81 changes: 81 additions & 0 deletions datachannel-win.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#ifdef _WIN32
#include <_cgo_export.h> // Allow calling certain Go functions.

#include "datachannel.h"

int CGO_DataStateConnecting = 0;
int CGO_DataStateOpen = 0;
int CGO_DataStateClosing = 0;
int CGO_DataStateClosed = 0;

void CGO_DataChannelInit() {
CGO_DataStateConnecting = dll_DataStateConnecting();
CGO_DataStateOpen = dll_DataStateOpen();
CGO_DataStateClosing = dll_DataStateClosing();
CGO_DataStateClosed = dll_DataStateClosed();
}

int CGO_Channel_BufferedAmount(CGO_Channel channel) {
return dll_Channel_BufferedAmount(channel);
}

int CGO_Channel_ID(CGO_Channel channel) {
return dll_Channel_ID(channel);
}

const char *CGO_Channel_Label(CGO_Channel channel) {
return (const char*)dll_Channel_Label(channel);
}

const char *CGO_Channel_Protocol(CGO_Channel channel) {
return (const char*)dll_Channel_Protocol(channel);
}

CGO_Channel CGO_Channel_RegisterObserver(void *o, int goChannel) {
return dll_Channel_RegisterObserver(o, goChannel);
}

int CGO_Channel_MaxRetransmitTime(CGO_Channel channel) {
return dll_Channel_MaxRetransmitTime(channel);
}

int CGO_Channel_MaxRetransmits(CGO_Channel channel) {
return dll_Channel_MaxRetransmits(channel);
}

int CGO_Channel_ReadyState(CGO_Channel channel) {
return dll_Channel_ReadyState(channel);
}

const bool CGO_Channel_Negotiated(CGO_Channel channel) {
return dll_Channel_Negotiated(channel);
}

void* CGO_getFakeDataChannel() {
return dll_getFakeDataChannel();
}

const bool CGO_Channel_Ordered(CGO_Channel channel) {
return dll_Channel_Ordered(channel);
}

void CGO_Channel_Close(CGO_Channel channel) {
return dll_Channel_Close(channel);
}

void CGO_Channel_Send(CGO_Channel channel, void *data, int size, bool binary) {
return dll_Channel_Send( channel, data, size, binary);
}

void CGO_fakeBufferAmount(CGO_Channel channel, int amount) {
return dll_fakeBufferAmount(channel, amount);
}

void CGO_fakeMessage(CGO_Channel channel, void *data, int size) {
return dll_fakeMessage(channel, data, size);
}

void CGO_fakeStateChange(CGO_Channel channel, int state) {
return dll_fakeStateChange(channel, state);
}
#endif
10 changes: 6 additions & 4 deletions datachannel.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !_WIN32 || WIN_WEBRTC
#include "datachannel.h"
#include "datachannel.hpp"

Expand Down Expand Up @@ -182,7 +183,8 @@ void CGO_fakeBufferAmount(CGO_Channel channel, int amount) {
dc->SetBufferedAmount(amount);
}

const int CGO_DataStateConnecting = DataChannelInterface::DataState::kConnecting;
const int CGO_DataStateOpen = DataChannelInterface::DataState::kOpen;
const int CGO_DataStateClosing = DataChannelInterface::DataState::kClosing;
const int CGO_DataStateClosed = DataChannelInterface::DataState::kClosed;
int CGO_DataStateConnecting = DataChannelInterface::DataState::kConnecting;
int CGO_DataStateOpen = DataChannelInterface::DataState::kOpen;
int CGO_DataStateClosing = DataChannelInterface::DataState::kClosing;
int CGO_DataStateClosed = DataChannelInterface::DataState::kClosed;
#endif
17 changes: 13 additions & 4 deletions datachannel.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#ifndef NOMINMAX
# define NOMINMAX
#endif

#ifndef _C_DATACHANNEL_H_
#define _C_DATACHANNEL_H_

#ifndef _WIN32
#define WEBRTC_POSIX 1
#endif

#include <stdbool.h>

Expand Down Expand Up @@ -30,17 +36,20 @@ extern "C" {
int CGO_Channel_ReadyState(CGO_Channel);
int CGO_Channel_BufferedAmount(CGO_Channel channel);

extern const int CGO_DataStateConnecting;
extern const int CGO_DataStateOpen;
extern const int CGO_DataStateClosing;
extern const int CGO_DataStateClosed;
extern int CGO_DataStateConnecting;
extern int CGO_DataStateOpen;
extern int CGO_DataStateClosing;
extern int CGO_DataStateClosed;

// Testing helpers:
CGO_Channel CGO_getFakeDataChannel();
void CGO_fakeMessage(CGO_Channel channel, void *data, int size);
void CGO_fakeStateChange(CGO_Channel channel, int state);
void CGO_fakeBufferAmount(CGO_Channel channel, int amount);

// Windows init
void CGO_DataChannelInit();

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 7 additions & 1 deletion datachannel.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#ifndef _DATACHANNEL_H_
#define _DATACHANNEL_H_

#include <_cgo_export.h> // Allow calling certain Go functions.

#include <assert.h>

#include "webrtc/api/peerconnectioninterface.h"
#include "webrtc/api/datachannelinterface.h"

#ifdef _WIN32
#include "externs.h"
#else
#include <_cgo_export.h> // Allow calling certain Go functions.
#endif

typedef rtc::scoped_refptr<webrtc::DataChannelInterface> DataChannel;

class CGoDataChannelObserver
Expand Down
8 changes: 4 additions & 4 deletions datachannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
func TestDataStateEnums(t *testing.T) {

Convey("Enum: DataState", t, func() {
So(DataStateConnecting, ShouldEqual, _cgoDataStateConnecting)
So(DataStateOpen, ShouldEqual, _cgoDataStateOpen)
So(DataStateClosing, ShouldEqual, _cgoDataStateClosing)
So(DataStateClosed, ShouldEqual, _cgoDataStateClosed)
So(_cgoDataStateConnecting, ShouldEqual, DataStateConnecting)
So(_cgoDataStateOpen, ShouldEqual, DataStateOpen)
So(_cgoDataStateClosing, ShouldEqual, DataStateClosing)
So(_cgoDataStateClosed, ShouldEqual, DataStateClosed)
})

Convey("DataChannel", t, func() {
Expand Down
124 changes: 124 additions & 0 deletions datachannel_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// +build windows
package webrtc

/*
#include "datachannel.h"
#include "string.h"
*/
import "C"
import (
"unsafe"
)

//export dll_Channel_BufferedAmount
func dll_Channel_BufferedAmount(channel C.CGO_Channel) C.int {
r1, _, _ := myfuncs["dll_Channel_BufferedAmount"].Call(uintptr(channel))
return C.int(r1)
}

//export dll_Channel_ID
func dll_Channel_ID(channel C.CGO_Channel) C.int {
r1, _, _ := myfuncs["dll_Channel_ID"].Call(uintptr(channel))
return C.int(r1)
}

//export dll_Channel_Label
func dll_Channel_Label(channel C.CGO_Channel) *C.char {
r1, _, _ := myfuncs["dll_Channel_Label"].Call(uintptr(channel))
// The caller is going to call free using C.free, that will invoke gcc's free which
// is NOT the same as MSVC's free
res := C.strdup((*C.char)(unsafe.Pointer(r1)))
myfuncs["dll_Free"].Call(r1)
return res
}

//export dll_Channel_Protocol
func dll_Channel_Protocol(channel C.CGO_Channel) *C.char {
r1, _, _ := myfuncs["dll_Channel_Protocol"].Call(uintptr(channel))
// The caller is going to call free using C.free, that will invoke gcc's free which
// is NOT the same as MSVC's free
res := C.strdup((*C.char)(unsafe.Pointer(r1)))
myfuncs["dll_Free"].Call(r1)
return res
}

//export dll_Channel_RegisterObserver
func dll_Channel_RegisterObserver(o unsafe.Pointer, index C.int) unsafe.Pointer {
r1, _, _ := myfuncs["dll_Channel_RegisterObserver"].Call(uintptr(o), uintptr(index))
return unsafe.Pointer(r1)
}

//export dll_Channel_MaxRetransmitTime
func dll_Channel_MaxRetransmitTime(channel C.CGO_Channel) C.int {
r1, _, _ := myfuncs["dll_Channel_MaxRetransmitTime"].Call(uintptr(channel))
return C.int(r1)
}

//export dll_Channel_MaxRetransmits
func dll_Channel_MaxRetransmits(channel C.CGO_Channel) C.int {
r1, _, _ := myfuncs["dll_Channel_MaxRetransmits"].Call(uintptr(channel))
return C.int(r1)
}

//export dll_Channel_Negotiated
func dll_Channel_Negotiated(channel C.CGO_Channel) C.bool {
r1, _, _ := myfuncs["dll_Channel_Negotiated"].Call(uintptr(channel))
res := int8(r1)
if res == 1 {
return C.bool(true)
} else {
return C.bool(false)
}
}

//export dll_getFakeDataChannel
func dll_getFakeDataChannel() unsafe.Pointer {
r1, _, _ := myfuncs["dll_getFakeDataChannel"].Call()
return unsafe.Pointer(r1)
}

//export dll_Channel_Ordered
func dll_Channel_Ordered(channel C.CGO_Channel) C.bool {
r1, _, _ := myfuncs["dll_Channel_Ordered"].Call(uintptr(channel))
res := int8(r1)
if res == 1 {
return C.bool(true)
} else {
return C.bool(false)
}
}

//export dll_Channel_ReadyState
func dll_Channel_ReadyState(channel C.CGO_Channel) C.int {
r1, _, _ := myfuncs["dll_Channel_ReadyState"].Call(uintptr(channel))
return C.int(r1)
}

//export dll_Channel_Close
func dll_Channel_Close(channel C.CGO_Channel) {
myfuncs["dll_Channel_Close"].Call(uintptr(channel))
}

//export dll_Channel_Send
func dll_Channel_Send(channel C.CGO_Channel, data unsafe.Pointer, size C.int, binary C.bool) {
var intBool = 0
if binary == C.bool(true) {
intBool = 1
}
myfuncs["dll_Channel_Send"].Call(uintptr(channel), uintptr(data), uintptr(size), uintptr(intBool))
}

//export dll_fakeBufferAmount
func dll_fakeBufferAmount(channel C.CGO_Channel, amount C.int) {
myfuncs["dll_fakeBufferAmount"].Call(uintptr(channel), uintptr(amount))
}

//export dll_fakeMessage
func dll_fakeMessage(channel C.CGO_Channel, data unsafe.Pointer, size C.int) {
myfuncs["dll_fakeMessage"].Call(uintptr(channel), uintptr(data), uintptr(size))
}

//export dll_fakeStateChange
func dll_fakeStateChange(channel C.CGO_Channel, state C.int) {
myfuncs["dll_fakeStateChange"].Call(uintptr(channel), uintptr(state))
}
8 changes: 7 additions & 1 deletion demo/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fmt"
"os"
"os/signal"
"runtime"
"strings"

"github.com/keroserene/go-webrtc"
Expand Down Expand Up @@ -274,7 +275,12 @@ func main() {

// Input loop.
for {
text, _ := reader.ReadString('\n')
text := ""
if runtime.GOOS == "windows" {
text, _ = reader.ReadString('\r')
} else {
text, _ = reader.ReadString('\n')
}
switch mode {
case ModeInit:
if strings.HasPrefix(text, "start") {
Expand Down
Loading