C# Pjsip (Pjsua2 api ) 2.10 windows sip语音呼叫教程

1、安装swigwin-4.0.1 下载地址http://www.swig.org/download.html 注意是swigwin
Windows users should download swigwin-4.0.1 which includes a prebuilt executable. 
配置目录到win path 

2、下载pjsip2.10.zip 编译lib 

具体参考pjsip windows demo编译运行 (pjsip 2.9 qt环境)_pjsip中windows编译-CSDN博客 编译后

注意是选择x64 和 将项目属性c/c++-代码生成-运行库改成多线程 DLL(/MDd)

产生在根目录lib 下有个 libpjproject-x86_64-x64-vc14-Debug.lib

3、在pjsip-apps/src/swig/csharp目录下创建一个x.bat

swig -I../../../../pjlib/include -I../../../../pjlib-util/include -I../../../../pjmedia/include -I../../../../pjsip/include -I../../../../pjnath/include -w312 -c++ -csharp -o pjsua2_wrap.cpp ../pjsua2.i

成功产生多个xx.cs 、 pjsua2_wrap.h 、pjsua2_wrap.cpp

4. 创建c  dll工程 导入pjsua2_wrap.h 、pjsua2_wrap.cpp、test.i 生成PJSUA2.dll

项目配置

Once this is created, add references to "libpjproject" and "pjsua2_lib". Then open "pjsip-apps/src/swig/csharp" and copy and paste into the project the following files:

  • pjsua2_wrap.h
  • pjsua2_wrap.cpp
  • pjsua2.i

Next you want to amend the project properties in several places. So first, open the Property Pages for your project and ensure the following values are set:

General

  • Target Name = PJSUA2
  • Target Extension = .dll
  • Configuration Type = Dynamic Library (.dll)
  • Common Language Runtime Support = Common Language Runtime Support (/clr)

C/C++ - General

  • Additional Include Directories = ../pjsip/include;../pjlib/include;../pjlib-util/include;../pjmedia/include;../pjnath/include;%(AdditionalIncludeDirectories);

Linker - Input (or in All Options)

  • Additional Dependencies = Iphlpapi.lib;dsound.lib;dxguid.lib;netapi32.lib;mswsock.lib;ws2_32.lib;odbc32.lib;odbccp32.lib;ole32.lib;user32.lib;gdi32.lib;advapi32.lib;%(AdditionalDependencies)
  • Ignore Specific Default Libraries = msvcrt.lib;%(IgnoreSpecificDefaultLibraries)

Once again, the paths may need adjusting for your solution so if you get a file-not-found type of error, the include directories paths may need to be adjusted.

Now open the Project Properties and select the Project Dependencies. You can select pretty much all of the projects in the solution but the key ones are those referenced in the include paths above:

  • libpjproject
  • pjlib
  • pjlib_util
  • pjmedia
  • pjnath
  • pjsua2_lib

This is because these projects already reference others that they need.

来源PJSIP-PJSUA2-CSharp/build-it-yourself.md at master · AaronReynoldsUK/PJSIP-PJSUA2-CSharp · GitHub

4.创建c# Console 程序或者其他c#  创建一个文件夹导入2的多个xx.cs 和在项目引用上添加PJSUA2.dll

5.测试代码参考pjsip-apps/src/swig/csharp默认的sample.cs或者https://www.pjsip.org/docs/book-latest/html/intro_pjsua2.html#id1


using System;
using pjsua2xamarin.pjsua2;

namespace pjsua2xamarin
{
    public class MyAccount : Account
    {
        ~MyAccount()
        {
            Console.WriteLine("*** Account is being deleted");
        }

        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";//需要改成自己的ip
            accCfg.regConfig.registrarUri = "sip:sip.pjsip.org";//需要改成自己的ip
            accCfg.sipConfig.authCreds.Add(
                new AuthCredInfo("digest", "*", "test1", 0, "test1") );
                MyAccount acc = new MyAccount();
                acc.create(accCfg);

                Console.WriteLine("*** DESTROYING PJSUA2 ***");
                // Explicitly delete account when unused

              Console.ReadLine();

                acc.Dispose();
                ep.libDestroy();
            } catch (Exception err) {
                Console.WriteLine("Exception: " + err.Message);
            }
        }
    }
}

最后运行看到cmd输出pjsip的加载信息为成功

如果你觉得麻烦可以去 https://item.taobao.com/item.htm?id=618486196283

sip服务器搭建可参考:https://blog.csdn.net/Java_lilin/article/details/103063930

pjsip qt win32参考:https://blog.csdn.net/Java_lilin/article/details/103511795

java pjsip  Java Pjsip (Pjsua2 api ) 2.10 windows sip语音呼叫教程_org.pjsip.pjsua2-CSDN博客 

更多写法可以参考安卓pjsua2代码:https://blog.csdn.net/Java_lilin/article/details/89212406

测试交流群:261074724 
 

 视频教程yuexiajiayan的个人空间-yuexiajiayan个人主页-哔哩哔哩视频

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值