liblinphone实现电话拨打及接听

余年寄山水
897次浏览
2021年02月20日 07:04
最佳经验
本文由作者推荐

-

2021年2月20日发(作者:秦始皇墓穴)


liblinphone


实现电话拨


打及接听< /p>








voip


2012-03-12 14:48 831



阅读



评论


(0)


收藏



举报



示范了通


过调



liblinphone




电话< /p>




程,原程序



/nongnu/linphone/docs/liblinphone/group __basic__call__t





中增加了接听部分



[cpp]



view plaincopyprint?



1.



/*


2.



* linphone- call.c


3.



* liblinphone



打示例



4.



* */


5.



#include


6.



#include


7.




8.



static bool_t running=TRUE;


9.



static void stop(int signum){


10.



running=FALSE;


11.



}


12.




13.



/*


14.



*






函数,用于






电话过


程状



通知



15.



*/


16.



static void call_state_changed(LinphoneCore *lc, LinphoneCall *call, Linp


honeCallState cstate, const char *msg){


17.



printf(


18.



switch(cstate){


19.



case LinphoneCallIncomingReceived:


20.



printf(


21.



char s = getchar();


22.



if(s == 'y')


23.



{


24.



printf(


25.



linphone_core_accept_call(lc, call); //


接听





26.



}


27.



else {


28.



printf(


29.



linphone_core_terminate_call(lc, call);


30.



}


31.



break;


32.



default:


33.



printf(


34.



}


35.



}


36.




37.



/*


38.



*


主函数



39.



*/


40.



int main(int argc, char *argv[]){


41.



LinphoneCoreVTable vtable={0};


42.



LinphoneCore *lc;


43.



LinphoneCall *call=NULL;


44.



const char *dest=NULL;


45.




46.



/*


命令行参数目的地址,如


sip:name@192.168.1.1*/


47.



if (argc>1){


48.



dest=argv[1];


49.



}


50.




51.



signal(SIGINT,stop); //

< p>



Ctrl-C


信号, 以



束程序



52.




53.



/* 1.


用回



函数表


LinphoneCoreVTable



< br>例化一个


LinphoneCore


< br>像。



54.



* LinphoneCoreVTable


中所有



都是可


< br>的,




仅仅设


置了


call_state_changed


,用于< /p>







的状



通知。



55.



*/


56.



_state_changed=call_state_changed;


57.




58.



lc=linphone_core_new(&vtable,NULL,NULL,NULL);


59.




60.




61.



/*


62.



* 2.




电话



63.



* */


64.



if (dest){


65.




66.



call=linphone_core_invite(lc,dest);


67.



if (call==NULL){


68.



printf(


69.



goto end;


70.



}else printf(


71.



//linphone_call_ref(call); //


增加

< p>
call


的引用



数,< /p>



72.



}


73.



/*


74.



* 3.


接收通知的主循



,




linphone_core_itera te


函数完成后台




工作



75.



*/


76.



while(running){


77.



linphone_core_iterate(lc);

-


-


-


-


-


-


-


-