您的位置:首页 > 理论基础 > 计算机网络

linphone初始化研究(图片源自网络)

2016-06-08 11:38 381 查看
linphone初始化研究(图片源自网络)



int _tmain(int argc, _TCHAR* wargv[]) {
char **argv=convert_args_to_ascii(argc,wargv);
trace_level=6;

#else
int
main (int argc, char *argv[]) {
#endif
linphonec_vtable.call_state_changed=linphonec_call_state_changed;
******
linphonec_vtable.call_encryption_changed=linphonec_call_encryption_changed;

if (! linphonec_init(argc, argv) ) exit(EXIT_FAILURE);

linphonec_main_loop (linphonec);
linphonec_finish(EXIT_SUCCESS);

exit(EXIT_SUCCESS); /* should never reach here */
}

#ifdef _MSC_VER
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
return main(__argc, __argv);
}
#endif


/*
* Initialize linphone core
*/
linphonec=linphone_core_new (&linphonec_vtable, configfile_name, factory_configfile_name, NULL);

LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
const char *config_path, const char *factory_config_path, void * userdata)
{
LinphoneCore *lc;
LpConfig *config = lp_config_new_with_factory(config_path, factory_config_path);
lc=linphone_core_new_with_config(vtable, config, userdata);
lp_config_unref(config);
return lc;
}

LinphoneCore *linphone_core_new_with_config(const LinphoneCoreVTable *vtable, struct _LpConfig *config, void *userdata)
{
LinphoneCore *core = ms_new0(LinphoneCore, 1);
linphone_core_init(core, vtable, config, userdata);
return core;
}


*  Initialize the oRTP library. You should call this function first before using
*  oRTP API.
**/
void ortp_init()
{
if (ortp_initialized++) return;

#ifdef _WIN32
win32_init_sockets();
#endif

av_profile_init(&av_profile);
ortp_global_stats_reset();
init_random_number_generator();

ortp_message("oRTP-" ORTP_VERSION " initialized.");
}




static void linphone_core_init(LinphoneCore * lc, const LinphoneCoreVTable *vtable, LpConfig *config, void * userdata){
const char *remote_provisioning_uri = NULL;
LinphoneCoreVTable* local_vtable= linphone_core_v_table_new();//用于初始化屏幕相关,以及输出相关
ms_message("Initializing LinphoneCore %s", linphone_core_get_version());

lc->config=lp_config_ref(config);
lc->data=userdata;
lc->ringstream_autorelease=TRUE;

memcpy(local_vtable,vtable,sizeof(LinphoneCoreVTable));
_linphone_core_add_listener(lc, local_vtable, TRUE);

linphone_core_set_state(lc,LinphoneGlobalStartup,"Starting up");
ortp_init();//初始华ortp,并加载默认的PayloadType
linphone_core_activate_log_serialization_if_needed();

ms_init();

linphone_core_register_default_codecs(lc);
/* Get the mediastreamer2 event queue */
/* This allows to run event's callback in linphone_core_iterate() */
lc->msevq=ms_factory_get_event_queue(ms_factory_get_fallback());

lc->sal=sal_init();

sal_set_user_pointer(lc->sal,lc);
sal_set_callbacks(lc->sal,&linphone_sal_callbacks);

#ifdef TUNNEL_ENABLED
lc->tunnel=linphone_core_tunnel_new(lc);
#endif

lc->network_last_check = 0;
lc->network_last_status = FALSE;
lc->register_last_check = 0;
lc->http_provider = belle_sip_stack_create_http_provider(sal_get_belle_sip_stack(lc->sal), "0.0.0.0");
lc->http_verify_policy = belle_tls_verify_policy_new();
belle_http_provider_set_tls_verify_policy(lc->http_provider,lc->http_verify_policy);

certificates_config_read(lc);

remote_provisioning_uri = linphone_core_get_provisioning_uri(lc);
if (remote_provisioning_uri == NULL) {
linphone_configuring_terminated(lc, LinphoneConfiguringSkipped, NULL);
} // else linphone_core_start will be called after the remote provisioning (see linphone_core_iterate)
}


linphone_core_set_sip_port 用于打开sip 端口,等待并接收sip 信息

linphonec_parse_command_line(linphonec, iptr);

分析命令行参数,如果没有命令行参数

/***************************************************************************
*
*  Global variables
*
***************************************************************************/

/*
* Commands table.
*/
static LPC_COMMAND commands[] = {
{ "help", lpc_cmd_help, "Print commands help.",
"'help <command>'\t: displays specific help for command.\n"
"'help advanced'\t: shows advanced commands.\n"
},
{ "answer", lpc_cmd_answer, "Answer a call",
"'answer' : Answer the current incoming call\n"
"'answer <call id>' : Answer the call with given id\n"
},
{ "autoanswer", lpc_cmd_autoanswer, "Show/set auto-answer mode",
"'autoanswer'       \t: show current autoanswer mode\n"
"'autoanswer enable'\t: enable autoanswer mode\n"
"'autoanswer disable'\t: disable autoanswer mode\n"
},
{ "call", lpc_cmd_call, "Call a SIP uri or number",
#ifdef VIDEO_ENABLED
"'call <sip-url or number>  [options]' \t: initiate a call to the specified destination.\n"
"Options can be:\n"
"--audio-only : initiate the call without video.\n"
"--early-media : sends audio and video stream immediately when remote proposes early media.\n"
#else
"'call <sip-url or number>' \t: initiate a call to the specified destination.\n"
#endif
},
{ "calls", lpc_cmd_calls, "Show all the current calls with their id and status.",
NULL
},
{ "call-logs", lpc_cmd_call_logs, "Calls history", NULL
},
#ifdef VIDEO_ENABLED
{ "camera", lpc_cmd_camera, "Send camera output for current call.",
"'camera on'\t: allow sending of local camera video to remote end.\n"
"'camera off'\t: disable sending of local camera's video to remote end.\n"
},
#endif
{ "chat", lpc_cmd_chat, "Chat with a SIP uri",
"'chat <sip-url> \"message\"' "
": send a chat message \"message\" to the specified destination."
},
{ "conference", lpc_cmd_conference, "Create and manage an audio conference.",
"'conference add <call id> : join the call with id 'call id' into the audio conference."
"'conference rm <call id> : remove the call with id 'call id' from the audio conference."
},
{ "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL
},
{ "firewall", lpc_cmd_firewall, "Set firewall policy",
"'firewall'        : show current firewall policy.\n"
"'firewall none'   : use direct connection.\n"
"'firewall nat'    : use nat address given with the 'nat' command.\n"
"'firewall stun'   : use stun server given with the 'stun' command.\n"
"'firewall ice'    : use ice.\n"
"'firewall upnp'   : use uPnP IGD.\n"
},
{ "friend", lpc_cmd_friend, "Manage friends",
"'friend list [<pattern>]'    : list friends.\n"
"'friend call <index>'        : call a friend.\n"
"'friend add <name> <addr>'   : add friend, <name> must be quoted to include\n"
"                               spaces, <addr> has \"sip:\" added if it isn't\n"
"                               there.  Don't use '<' '>' around <addr>.\n"
"'friend delete <index>'      : remove friend, 'all' removes all\n"
},
{ "ipv6", lpc_cmd_ipv6, "Use IPV6",
"'ipv6 status' : show ipv6 usage status.\n"
"'ipv6 enable' : enable the use of the ipv6 network.\n"
"'ipv6 disable' : do not use ipv6 network."
},
{ "mute", lpc_cmd_mute_mic,
"Mute microphone and suspend voice transmission."
},
{ "nat", lpc_cmd_nat, "Set nat address",
"'nat'        : show nat settings.\n"
"'nat <addr>' : set nat address.\n"
},
{ "pause", lpc_cmd_pause, "pause a call",
"'pause' : pause the current call\n"
},
{ "play", lpc_cmd_play, "play a wav file",
"This command has two roles:\n"
"Plays a file instead of capturing from soundcard - only available in file mode (see 'help soundcard')\n"
"Specifies a wav file to be played to play music to far end when putting it on hold (pause)\n"
"'play <wav file>'    : play a wav file."
},
{ "playbackgain", lpc_cmd_playback_gain,
"Adjust playback gain."
},
{ "proxy", lpc_cmd_proxy, "Manage proxies",
"'proxy list' : list all proxy setups.\n"
"'proxy add' : add a new proxy setup.\n"
"'proxy remove <index>' : remove proxy setup with number index.\n"
"'proxy use <index>' : use proxy with number index as default proxy.\n"
"'proxy unuse' : don't use a default proxy.\n"
"'proxy show <index>' : show configuration and status of the proxy numbered by index.\n"
"'proxy show default' : show configuration and status of the default proxy.\n"
},
{ "record", lpc_cmd_record, "record to a wav file",
"This feature is available only in file mode (see 'help soundcard')\n"
"'record <wav file>'    : record into wav file."
},
{ "resume", lpc_cmd_resume, "resume a call",
"'resume' : resume the unique call\n"
"'resume <call id>' : hold off the call with given id\n"
},
{ "soundcard", lpc_cmd_soundcard, "Manage soundcards",
"'soundcard list' : list all sound devices.\n"
"'soundcard show' : show current sound devices configuration.\n"
"'soundcard use <index>' : select a sound device.\n"
"'soundcard use files' : use .wav files instead of soundcard\n"
},
{ "stun", lpc_cmd_stun, "Set stun server address",
"'stun'        : show stun settings.\n"
"'stun <addr>' : set stun server address.\n"
},
{ "terminate", lpc_cmd_terminate, "Terminate a call",
"'terminate' : Terminate the current call\n"
"'terminate <call id>' : Terminate the call with supplied id\n"
"'terminate <all>' : Terminate all the current calls\n"
},
{ "transfer", lpc_cmd_transfer,
"Transfer a call to a specified destination.",
"'transfer <sip-uri>' : transfers the current active call to the destination sip-uri\n"
"'transfer <call id> <sip-uri>': transfers the call with 'id' to the destination sip-uri\n"
"'transfer <call id1> --to-call <call id2>': transfers the call with 'id1' to the destination of call 'id2' (attended transfer)\n"
},
{ "unmute", lpc_cmd_unmute_mic,
"Unmute microphone and resume voice transmission."
},
{ "webcam", lpc_cmd_webcam, "Manage webcams",
"'webcam list' : list all known devices.\n"
"'webcam use <index>' : select a video device.\n"
},
{ "quit", lpc_cmd_quit, "Exit linphonec", NULL
},
{ (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL
}
};


typedef struct {

char name; / User printable name of the function. */

lpc_cmd_handler func; /* Function to call to do the job. */

char help; / Short help for this function. */

char doc; / Long description. */

} LPC_COMMAND;





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: