Linphone c++


初始化
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_message_received(cbs, linphoneCoreCbsMessageReceivedCb);
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());
const char** video_devices = linphone_core_get_video_devices(lc);
linphone_core_set_video_device(lc, video_devices[index]);
linphone_core_set_native_video_window_id(lc, (void *)ui.graphicsView->winId());
linphone_core_set_avpf_mode(lc, LinphoneAVPFDisabled);

注册
LinphoneProxyConfig* proxy_cfg;
LinphoneAddress *from;
proxy_cfg = linphone_core_create_proxy_config(lc);
from = linphone_address_new(identity);
LinphoneAuthInfo *authinfo = linphone_auth_info_new(user .c_str(), user .c_str(), psd.c_str(), NULL, NULL, host.c_str());
linphone_core_add_auth_info(lc, authinfo);
linphone_auth_info_unref(authinfo);

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);

linphone_core_add_proxy_config(lc, proxy_cfg);
linphone_core_set_default_proxy_config(lc, proxy_cfg);

linphone_proxy_config_unref(proxy_cfg);

呼叫
LinphoneCall *curentcall = linphone_core_get_current_call(lc);
LinphoneCallParams *callpa = linphone_core_create_call_params(lc, curentcall);
linphone_call_params_enable_video(callpa, FALSE);//视频呼叫TRUE
LinphoneCall *call = linphone_core_invite_with_params(lc, url, callpa);//url:sip:ip:port
linphone_call_ref(call);

呼叫状态
LinphoneCoreCbs* cbs = linphone_core_get_current_callbacks(lc);
    switch (LinphoneCallState) {
    case LinphoneCallIncomingReceived:
            ...
        break;
    case LinphoneCallOutgoingRinging:
        ...
        break;
    case LinphoneCallOutgoingEarlyMedia:
        ...
        break;
    case LinphoneCallConnected:
        ...
        break;
    case LinphoneCallStreamsRunning:
        ...
        break;
    case LinphoneCallEnd:
        ...
        break;
    case LinphoneCallError:
        ...
        break;
    default:
        ...
    }

接听
LinphoneCall *curentcall = linphone_core_get_current_call(lc);
const LinphoneCallParams * remotecpa = linphone_call_get_remote_params(curentcall);
if (linphone_call_params_video_enabled(remotecpa)) {
    LinphoneCallParams * callpa = linphone_core_create_call_params(lc, curentcall);
    linphone_call_params_enable_video(callpa, TRUE);
    linphone_core_accept_call_with_params(lc, curentcall, callpa);
}
else {
    linphone_call_accept(curentcall);
}

挂断
LinphoneCall *curentcall = linphone_core_get_current_call(lc);
if (NULL != curentcall) {
    linphone_call_terminate(curentcall);
}

你可能感兴趣的:(Linphone c++)