环境:
本文用qt5、 LIBLINPHONE-SDK-4.1.1-WIN32.ZIP (下载地址http://www.linphone.org/technical-corner/liblinphone)
自己去编译个也行 下载地址 https://gitlab.linphone.org/BC/public/linphone-sdk
git clone https://gitlab.linphone.org/BC/public/linphone-sdk.git --recursive
创建一个vs qt 项目在项目种导入头文件和lib dll考到exe 运行目录下
(你要觉得麻烦或难解决错误可到https://item.taobao.com/item.htm?id=592349919838获取源码。源码功能性更好、更完善。群q群:261074724)
在sdk文件夹share下有文档 文档很重要
另外的参考https://www.linphone.org/snapshots/docs/liblinphone/multilang/index.html 写
1.初始化的时候:
//linphone
LinphoneFactory *factory = linphone_factory_get();
LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(factory);
linphone_core_cbs_set_call_state_changed(cbs, call_state_changed);
linphone_core_cbs_set_registration_state_changed(cbs, registration_state_changed);
linphone_core_cbs_set_user_data(cbs, &ui );
LinphoneConfig*config = linphone_config_new_with_factory("linphonerc", "linphonerc-factory");
lc = linphone_factory_create_core_with_config(factory, cbs, config);
linphone_core_cbs_ref(cbs);
linphone_core_reload_ms_plugins(lc, NULL);
linphone_core_set_user_agent(lc, "mylinphone", linphone_core_get_version());
上面的两个文件可以到源码种去找
2.
LinphoneProxyConfig* proxy_cfg;
LinphoneAddress *from;
const char* identity = "sip:1010@ip";/* takes sip uri identity from the command line arguments */
const char* password = "h12345";
//
//remove all
proxy_cfg = linphone_core_create_proxy_config(lc);
from = linphone_address_new(identity);
LinphoneAuthInfo *authinfo = linphone_auth_info_new("1010", "1010", password, NULL, NULL, "ip");
linphone_core_add_auth_info(lc, authinfo);
linphone_auth_info_unref(authinfo); //sifang
linphone_proxy_config_set_identity_address(proxy_cfg, from);
linphone_proxy_config_set_server_addr(proxy_cfg, identity);
linphone_proxy_config_edit(proxy_cfg);
linphone_proxy_config_enable_publish(proxy_cfg, TRUE);
linphone_proxy_config_enable_register(proxy_cfg, TRUE);
linphone_proxy_config_done(proxy_cfg);
linphone_address_unref(from); //sifang
linphone_core_add_proxy_config(lc, proxy_cfg);
linphone_core_set_default_proxy_config(lc, proxy_cfg);
linphone_proxy_config_unref(proxy_cfg); //sifang
3.创建一个线程一直while运行 注册成功后回有信息返回
linphone_core_iterate(lc);
ms_usleep(50000);//
4.呼叫
num = "sip:" +num+"@ip";
const char* url = str.c_str();
LinphoneCall *curentcall = linphone_core_get_current_call(lc);
if (NULL == curentcall) {
LinphoneCall *call=linphone_core_invite(lc, url);
linphone_call_ref(call);
}
5。接听
LinphoneCall *curentcall = linphone_core_get_current_call(lc);
if (NULL != curentcall) {
linphone_call_accept(curentcall);
}
c# 使用参考https://blog.csdn.net/Java_lilin/article/details/106311843
交流群:261074724