Fixed #2086: Add C# binding using SWIG, and support for Xamarin
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@5735 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
parent
c7d20d5111
commit
08ff24ac94
|
@ -700,6 +700,7 @@ ac_external_speex
|
|||
ac_shared_libraries
|
||||
ac_linux_poll
|
||||
ac_os_objs
|
||||
ac_target_arch
|
||||
EGREP
|
||||
GREP
|
||||
CPP
|
||||
|
@ -5060,10 +5061,12 @@ else
|
|||
CFLAGS="$CFLAGS -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1"
|
||||
fi
|
||||
|
||||
|
||||
case $target in
|
||||
*android*)
|
||||
$as_echo "#define PJ_ANDROID 1" >>confdefs.h
|
||||
|
||||
ac_target_arch=$TARGET_ABI
|
||||
;;
|
||||
*mingw* | *cygw* | *win32* | *w32* )
|
||||
$as_echo "#define PJ_WIN32 1" >>confdefs.h
|
||||
|
@ -5076,6 +5079,7 @@ case $target in
|
|||
*darwin*)
|
||||
$as_echo "#define PJ_DARWINOS 1" >>confdefs.h
|
||||
|
||||
ac_target_arch=$ARCH_VAL
|
||||
;;
|
||||
*linux*)
|
||||
$as_echo "#define PJ_LINUX 1" >>confdefs.h
|
||||
|
|
|
@ -146,9 +146,11 @@ fi
|
|||
dnl
|
||||
dnl Legacy macros
|
||||
dnl
|
||||
AC_SUBST(ac_target_arch)
|
||||
case $target in
|
||||
*android*)
|
||||
AC_DEFINE(PJ_ANDROID,1)
|
||||
ac_target_arch=$TARGET_ABI
|
||||
;;
|
||||
*mingw* | *cygw* | *win32* | *w32* )
|
||||
AC_DEFINE(PJ_WIN32,1)
|
||||
|
@ -157,6 +159,7 @@ case $target in
|
|||
;;
|
||||
*darwin*)
|
||||
AC_DEFINE(PJ_DARWINOS,1)
|
||||
ac_target_arch=$ARCH_VAL
|
||||
;;
|
||||
*linux*)
|
||||
AC_DEFINE(PJ_LINUX,1)
|
||||
|
|
|
@ -7,6 +7,7 @@ export MACHINE_NAME := auto
|
|||
export OS_NAME := auto
|
||||
export HOST_NAME := unix
|
||||
export CC_NAME := gcc
|
||||
export TARGET_ARCH := @ac_target_arch@
|
||||
export TARGET_NAME := @target@
|
||||
export CROSS_COMPILE := @ac_cross_compile@
|
||||
export LINUX_POLL := @ac_linux_poll@
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
include ../../../build.mak
|
||||
|
||||
ifneq ($(findstring android,$(TARGET_NAME)),)
|
||||
# no python for android
|
||||
DIRS = java
|
||||
# no python for android
|
||||
DIRS = java csharp
|
||||
else
|
||||
DIRS = python java
|
||||
ifneq ($(findstring ios,$(TARGET_NAME)),)
|
||||
DIRS = csharp
|
||||
else
|
||||
DIRS = python java
|
||||
endif
|
||||
endif
|
||||
|
||||
export SWIG_FLAGS=-I../../../../pjlib/include \
|
||||
|
@ -28,6 +32,9 @@ all clean dep depend distclean print realclean install uninstall:
|
|||
fi; \
|
||||
done
|
||||
|
||||
csharp:
|
||||
$(MAKE) $(MAKE_FLAGS) -C csharp $@
|
||||
|
||||
symbols.i: symbols.lst
|
||||
@echo ** Warning **: file symbols.i is out of date. Run 'make symbol'.
|
||||
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
include ../../../../build.mak
|
||||
include ../../../../build/common.mak
|
||||
|
||||
ifneq ($(findstring android,$(TARGET_NAME)),)
|
||||
OS=android
|
||||
else
|
||||
ifneq ($(findstring ios,$(TARGET_NAME)),)
|
||||
OS=ios
|
||||
endif
|
||||
endif
|
||||
|
||||
SWIG_FLAGS += -w312
|
||||
|
||||
PROJ_NAME=pjsua2xamarin
|
||||
OUT_DIR=$(PROJ_NAME)/$(PROJ_NAME)/pjsua2
|
||||
NAMESPACE=$(PROJ_NAME).pjsua2
|
||||
|
||||
ARCH=$(TARGET_ARCH)
|
||||
|
||||
ifeq ($(OS),android)
|
||||
LIBPJSUA2_DIR=$(PROJ_NAME)/Droid/lib/$(ARCH)
|
||||
LIBPJSUA2=$(LIBPJSUA2_DIR)/libpjsua2.so
|
||||
endif
|
||||
ifeq ($(OS),ios)
|
||||
LIBPJSUA2_DIR=$(PROJ_NAME)/iOS/lib/$(ARCH)
|
||||
LIBPJSUA2=$(LIBPJSUA2_DIR)/libpjsua2.a
|
||||
endif
|
||||
|
||||
# Build settings
|
||||
MY_CFLAGS := $(PJ_CXXFLAGS) $(CFLAGS)
|
||||
MY_LDFLAGS := $(PJ_LDXXFLAGS) $(PJ_LDXXLIBS) $(LDFLAGS)
|
||||
|
||||
.PHONY: all install uninstall
|
||||
|
||||
all: $(LIBPJSUA2) sample
|
||||
|
||||
$(LIBPJSUA2): $(OUT_DIR)/pjsua2_wrap.o
|
||||
mkdir -p $(LIBPJSUA2_DIR)
|
||||
ifeq ($(OS),android)
|
||||
$(PJ_CXX) -shared -o $(LIBPJSUA2) $(OUT_DIR)/pjsua2_wrap.o \
|
||||
$(MY_CFLAGS) $(MY_LDFLAGS)
|
||||
endif
|
||||
ifeq ($(OS),ios)
|
||||
$(AR) $(LIBPJSUA2) $(AR_FLAGS) $(OUT_DIR)/pjsua2_wrap.o $(PJ_LIBXX_FILES)
|
||||
endif
|
||||
|
||||
$(OUT_DIR)/pjsua2_wrap.o: $(OUT_DIR)/pjsua2_wrap.cpp
|
||||
$(PJ_CXX) -c $(OUT_DIR)/pjsua2_wrap.cpp -o $(OUT_DIR)/pjsua2_wrap.o \
|
||||
$(MY_CFLAGS)
|
||||
|
||||
$(OUT_DIR)/pjsua2_wrap.cpp: ../pjsua2.i ../symbols.i Makefile $(SRCS)
|
||||
mkdir -p $(OUT_DIR)
|
||||
swig $(SWIG_FLAGS) -namespace $(NAMESPACE) -csharp -o $(OUT_DIR)/pjsua2_wrap.cpp ../pjsua2.i
|
||||
|
||||
sample: sample.cs
|
||||
@echo "Copying sample code..."
|
||||
cp sample.cs $(PROJ_NAME)/$(PROJ_NAME)
|
||||
|
||||
clean distclean realclean:
|
||||
rm -rf $(OUT_DIR)/*
|
||||
rm -rf $(LIBPJSUA2_DIR)/*
|
||||
|
||||
install:
|
||||
|
||||
uninstall:
|
|
@ -0,0 +1,89 @@
|
|||
/* $Id $ */
|
||||
/*
|
||||
* Copyright (C) 2018-2018 Teluu Inc. (http://www.teluu.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using pjsua2xamarin.pjsua2;
|
||||
|
||||
namespace pjsua2xamarin
|
||||
{
|
||||
public class MyAccount : Account
|
||||
{
|
||||
override public void onRegState(OnRegStateParam prm)
|
||||
{
|
||||
AccountInfo ai = getInfo();
|
||||
Console.WriteLine("***" + (ai.regIsActive? "": "Un") +
|
||||
"Register: code=" + prm.code);
|
||||
}
|
||||
}
|
||||
|
||||
public class MyLogWriter : LogWriter
|
||||
{
|
||||
override public void write(LogEntry entry)
|
||||
{
|
||||
Console.WriteLine(entry.msg);
|
||||
}
|
||||
}
|
||||
|
||||
public class sample
|
||||
{
|
||||
public static Endpoint ep = new Endpoint();
|
||||
public static MyLogWriter writer = new MyLogWriter();
|
||||
|
||||
public sample()
|
||||
{
|
||||
}
|
||||
|
||||
public void test1()
|
||||
{
|
||||
try {
|
||||
ep.libCreate();
|
||||
|
||||
// Init library
|
||||
EpConfig epConfig = new EpConfig();
|
||||
epConfig.logConfig.writer = writer;
|
||||
ep.libInit(epConfig);
|
||||
|
||||
// Create transport
|
||||
TransportConfig tcfg = new TransportConfig();
|
||||
tcfg.port = 5080;
|
||||
ep.transportCreate(pjsip_transport_type_e.PJSIP_TRANSPORT_UDP,
|
||||
tcfg);
|
||||
ep.transportCreate(pjsip_transport_type_e.PJSIP_TRANSPORT_TCP,
|
||||
tcfg);
|
||||
|
||||
// Start library
|
||||
ep.libStart();
|
||||
Console.WriteLine("*** PJSUA2 STARTED ***");
|
||||
|
||||
// Add account
|
||||
AccountConfig accCfg = new AccountConfig();
|
||||
accCfg.idUri = "sip:test1@pjsip.org";
|
||||
accCfg.regConfig.registrarUri = "sip:sip.pjsip.org";
|
||||
accCfg.sipConfig.authCreds.Add(
|
||||
new AuthCredInfo("digest", "*", "test1", 0, "test1") );
|
||||
MyAccount acc = new MyAccount();
|
||||
acc.create(accCfg);
|
||||
|
||||
ep.libDestroy();
|
||||
} catch (Exception err) {
|
||||
Console.WriteLine("Exception: " + err.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -175,7 +175,7 @@ typedef enum pjsua_call_flag {PJSUA_CALL_UNHOLD = 1, PJSUA_CALL_UPDATE_CONTACT =
|
|||
|
||||
typedef enum pjsua_create_media_transport_flag {PJSUA_MED_TP_CLOSE_MEMBER = 1} pjsua_create_media_transport_flag;
|
||||
|
||||
typedef enum pjsua_snd_dev_id {PJSUA_SND_DEFAULT_CAPTURE_DEV = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV, PJSUA_SND_DEFAULT_PLAYBACK_DEV = PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV, PJSUA_SND_NO_DEV = PJMEDIA_AUD_INVALID_DEV, PJSUA_SND_NULL_DEV = -99} pjsua_snd_dev_id;
|
||||
typedef enum pjsua_snd_dev_id {PJSUA_SND_DEFAULT_CAPTURE_DEV = -1, PJSUA_SND_DEFAULT_PLAYBACK_DEV = -2, PJSUA_SND_NO_DEV = -3, PJSUA_SND_NULL_DEV = -99} pjsua_snd_dev_id;
|
||||
|
||||
typedef enum pjsua_snd_dev_mode {PJSUA_SND_DEV_SPEAKER_ONLY = 1, PJSUA_SND_DEV_NO_IMMEDIATE_OPEN = 2} pjsua_snd_dev_mode;
|
||||
|
||||
|
|
Loading…
Reference in New Issue