endpoint.cpp 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  1. #include "SpBase.h"
  2. #ifdef RVC_OS_WIN
  3. #include "stdafx.h"
  4. #include <ObjBase.h>
  5. #else
  6. #endif
  7. #include "endpoint.h"
  8. #include <sofia-sip/su.h>
  9. #include <sofia-sip/su_tag_class.h>
  10. #include <sofia-sip/nua.h>
  11. #include <sofia-sip/sip_status.h>
  12. #include <sofia-sip/sdp.h>
  13. #include <sofia-sip/sip_header.h>
  14. #include <sofia-sip/su_log.h>
  15. #include <sofia-sip/su_tagarg.h>
  16. #include <sofia-sip/su_tag_io.h>
  17. #include <sofia-sip/soa_tag.h>
  18. #include <sofia-sip/su_wait.h>
  19. #include <sofia-sip/nua_tag.h>
  20. #include "refcnt.h"
  21. #include "list.h"
  22. #include "sockutil.h"
  23. #include "hash.h"
  24. #include "video_session.h"
  25. #include "audio_session.h"
  26. #include "rvc_media_common.h"
  27. #include "Event.h"
  28. bool g_IsExternalTerminalted = false;
  29. // default: ptime = 20ms
  30. #define CONDITION_PARAMS \
  31. int status, \
  32. char const *phrase, \
  33. nua_t *nua, \
  34. struct endpoint_t *ep, \
  35. nua_handle_t *nh, \
  36. struct endpoint_call_t *call, \
  37. sip_t const *sip, \
  38. tagi_t tags[]
  39. // the same with rtp payload type, the same as huawei open-eye
  40. enum e_audio_rtp_pt
  41. {
  42. PCMU = 0, // 64kbps, 4.17
  43. PCMA = 8, // 64kbps, 4.11
  44. G729 = 18, // 8kbps, 3.9
  45. };
  46. enum e_video_rtp_pt
  47. {
  48. H263 = 34, // h263
  49. };
  50. enum e_media_dir
  51. {
  52. DIR_NONE = 0,
  53. DIR_TX = 1,
  54. DIR_RX = 2,
  55. DIR_BOTH = 3,
  56. };
  57. typedef struct sdpvideo_desc_t
  58. {
  59. unsigned long local_rtp_ip;
  60. int local_rtp_port;
  61. unsigned long remote_rtp_ip;
  62. int remote_rtp_port;
  63. int local_pt;
  64. int remote_pt;
  65. };
  66. typedef struct media_desc_t
  67. {
  68. unsigned long remote_ip;
  69. int remote_port;
  70. unsigned long local_ip;
  71. int local_port;
  72. int media_dir;
  73. int local_pt;
  74. int local_ptime;
  75. int remote_pt;
  76. int remote_ptime;
  77. int local_telephone_event_pt;
  78. int remote_telephone_event_pt;
  79. int param[16];
  80. }media_desc_t;
  81. // 1. how to exit
  82. struct endpoint_call_t {
  83. struct list_head entry;
  84. endpoint_call_callback_t cb;
  85. endpoint_t *ep;
  86. audio_session_t *audio;
  87. video_session_t *video;
  88. int id;
  89. su_home_t *home;
  90. nua_handle_t *nh;
  91. char *to_uri;
  92. char *from_uri;
  93. char *call_id;
  94. sdp_session_t *last_sdp;
  95. int connected;
  96. int local_media_port;
  97. int local_video_port;
  98. unsigned int last_media_desc_hash;
  99. char local_ip[RVC_MAX_IP_LEN];
  100. DeviceTypeEnum eDeviceType;
  101. CallingTypeEnum nCallType;
  102. sdpvideo_desc_t sdpvieo_desc;
  103. DECLARE_REF_COUNT_MEMBER(ref_cnt);
  104. };
  105. DECLARE_REF_COUNT_STATIC(endpoint_call, endpoint_call_t)
  106. struct endpoint_t {
  107. su_home_t home[1];
  108. su_root_t *root;
  109. nua_t *nua;
  110. endpoint_call_t *active_call;
  111. #ifdef RVC_OS_WIN
  112. HANDLE event_thread;
  113. #else
  114. pthread_t ievent_threadid;
  115. #endif
  116. int call_seq;
  117. int media_port_seq;
  118. CEntityBase *entity;
  119. struct list_head call_list;
  120. endpoint_conf_t conf;
  121. int curr_audio_dev_type; // handfree or pickup
  122. };
  123. static const char *state_desc[] = {
  124. "STATE::INIT",
  125. "STATE::CALLING",
  126. "STATE::PROCEEDING",
  127. "STATE::COMPLETING",
  128. "STATE::READY",
  129. "STATE::TERMINATING",
  130. "STATE::TERMINATED",
  131. };
  132. #ifndef VIDEOPLAYER_FLAG_DOUBLESIZE
  133. #define VIDEOPLAYER_FLAG_DOUBLESIZE 0x01
  134. #endif
  135. #ifndef VIDEOPLAYER_FLAG_NOTIMER
  136. #define VIDEOPLAYER_FLAG_NOTIMER 0x02
  137. #endif
  138. #ifndef VIDEOPLAYER_FLAG_PUSH
  139. #define VIDEOPLAYER_FLAG_PUSH 0x04
  140. #endif
  141. #ifndef VIDEOPLAYER_FLAG_PULL
  142. #define VIDEOPLAYER_FLAG_PULL 0x08
  143. #endif
  144. #ifndef VIDEOPLAYER_FLAG_CHECKTOP
  145. #define VIDEOPLAYER_FLAG_CHECKTOP 0x10
  146. #endif
  147. #ifndef VIDEOPLAYER_FLAG_ZOOMOUTSIZE
  148. #define VIDEOPLAYER_FLAG_ZOOMOUTSIZE 0x100
  149. #endif
  150. static void endpoint_media_change_audio_dev(endpoint_call_t *call, e_dev_type current_dev_type)
  151. {
  152. if (call->audio) {
  153. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_AUDIO_DEVICE_SWITCH, CSimpleStringA::Format("change audio device to %s mode.", DEV_PICKUP == current_dev_type ? "pickup" : "hand free").GetData());
  154. audio_session_change_dev(call->audio, current_dev_type);
  155. }
  156. }
  157. static __inline struct in_addr __lton(unsigned long ip)
  158. {
  159. struct in_addr addr;
  160. addr.s_addr = ip;
  161. return addr;
  162. }
  163. #ifdef RVC_OS_WIN
  164. static void endpoint_media_update_video(endpoint_call_t *call, media_desc_t *video_desc, video_session_callback_t* cb)
  165. {
  166. if (video_desc->media_dir == DIR_NONE) {
  167. if (call->video) {
  168. video_session_stop(call->video);
  169. video_session_destroy(call->video);
  170. call->video = NULL;
  171. }
  172. else{
  173. if (DOUBLERECORD_CALLTYPE == call->nCallType){
  174. double_record_broadcast_video_session_stop();
  175. }
  176. }
  177. }
  178. else
  179. {
  180. int rc;
  181. endpoint_conf_t *ep_conf = &call->ep->conf;
  182. if (!call->audio){
  183. audio_session_conf_t conf = {0};
  184. strcpy(&conf.in_dev[DEV_PICKUP][0], ep_conf->audio_pickup_in_dev);
  185. strcpy(&conf.in_dev[DEV_HANDFREE][0], ep_conf->audio_handfree_in_dev);
  186. strcpy(&conf.out_dev[DEV_PICKUP][0], ep_conf->audio_pickup_out_dev);
  187. strcpy(&conf.out_dev[DEV_HANDFREE][0], ep_conf->audio_handfree_out_dev);
  188. conf.agc_in[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_in_agc;
  189. conf.agc_in[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_in_agc;
  190. conf.agc_out[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_out_agc;
  191. conf.agc_out[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_out_agc;
  192. conf.ns_in[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_in_ns;
  193. conf.ns_in[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_in_ns;
  194. conf.ns_out[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_out_ns;
  195. conf.ns_out[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_out_ns;
  196. conf.aec[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_aec;
  197. conf.aec[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_aec;
  198. rc = audio_session_create(&conf, &call->audio);
  199. if (rc != 0) {
  200. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create audio session failed! rc = %d", rc);
  201. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402301A4").setResultCode("RTA3109")("视频连线创建音频通道失败");
  202. return;
  203. }
  204. else {
  205. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402301A4")("视频连线创建音频通道成功");
  206. }
  207. }
  208. if (call->video) {
  209. video_session_destroy(call->video);
  210. call->video = NULL;
  211. }
  212. int i = 0;
  213. int local_view_x = video_desc->param[i++];
  214. int local_view_y = video_desc->param[i++];
  215. int local_view_cx = video_desc->param[i++];
  216. int local_view_cy = video_desc->param[i++];
  217. int remote_view_x = video_desc->param[i++];
  218. int remote_view_y = video_desc->param[i++];
  219. int remote_view_cx = video_desc->param[i++];
  220. int remote_view_cy = video_desc->param[i++];
  221. int remote_width = video_desc->param[i++];
  222. int remote_height = video_desc->param[i++];
  223. int local_hwd_move = video_desc->param[i++];
  224. int remote_hwd_move = video_desc->param[i++];
  225. video_session_conf_t video_conf = {0};
  226. video_conf.bit_rate = 256 * 1024;
  227. video_conf.local_rtp_ip = video_desc->local_ip;
  228. video_conf.local_rtp_port = video_desc->local_port;
  229. video_conf.local_video_view_x = local_view_x;
  230. video_conf.local_video_view_y = local_view_y;
  231. video_conf.local_video_view_cx = local_view_cx;
  232. video_conf.local_video_view_cy = local_view_cy;
  233. video_conf.mtu = ep_conf->mtu;
  234. video_conf.video_quant = ep_conf->quant;
  235. video_conf.remote_rtp_ip = video_desc->remote_ip;
  236. video_conf.remote_rtp_port = video_desc->remote_port;
  237. video_conf.remote_video_view_x = remote_view_x;
  238. video_conf.remote_video_view_y = remote_view_y;
  239. video_conf.remote_video_view_cx = remote_view_cx;
  240. video_conf.remote_video_view_cy = remote_view_cy;
  241. video_conf.remote_video_width = remote_width;
  242. video_conf.remote_video_height = remote_height;
  243. video_conf.ref_active_camera = call->ep->conf.ref_active_camera;
  244. video_conf.ref_camera_switch = call->ep->conf.ref_camera_switch;
  245. video_conf.ref_camera_state = call->ep->conf.ref_camera_state;
  246. video_conf.ref_window_state = call->ep->conf.ref_window_state;
  247. video_conf.ref_Is_showPersonArea = call->ep->conf.ref_Is_showPersonArea;
  248. video_conf.ref_active_img = NULL;
  249. video_conf.ref_Is_ActiveInspect = NULL;
  250. video_conf.camera_count = call->ep->conf.camera_count;
  251. video_conf.screen_count = call->ep->conf.screen_count;
  252. video_conf.ref_Up_Fps = call->ep->conf.ref_Up_Fps;
  253. video_conf.eDeviceType = call->eDeviceType;
  254. video_conf.nCallType = call->nCallType;
  255. video_conf.local_move = local_hwd_move;
  256. video_conf.remote_move = remote_hwd_move;
  257. video_conf.video_echo_cb = cb;
  258. video_conf.ilocal_wind_flags = VIDEOPLAYER_FLAG_PULL|VIDEOPLAYER_FLAG_CHECKTOP;
  259. video_conf.iremote_wind_flags = VIDEOPLAYER_FLAG_PUSH|VIDEOPLAYER_FLAG_CHECKTOP;
  260. video_conf.eType = (eVideoRenderType)call->ep->conf.irendertype;
  261. video_conf.local_pt = REC_COMMON_VIDEO_H264_PT;
  262. video_conf.remote_pt = REC_COMMON_VIDEO_H264_PT;
  263. rc = video_session_create(&video_conf, &call->video);
  264. if (rc != 0) {
  265. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create video session failed! rc = %d", rc);
  266. return;
  267. }
  268. rc = video_session_start(call->video);
  269. if (rc != 0) {
  270. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start video session failed! rc = %d", rc);
  271. video_session_destroy(call->video);
  272. call->video = NULL;
  273. return;
  274. }
  275. }
  276. }
  277. #else
  278. static void endpoint_media_update_video(endpoint_call_t *call, media_desc_t *video_desc, rvc_video_render_callback_t* cb)
  279. {
  280. if (video_desc->media_dir == DIR_NONE) {
  281. if (call->video) {
  282. video_session_stop(call->video);
  283. video_session_destroy(call->video);
  284. call->video = NULL;
  285. }
  286. }
  287. else
  288. {
  289. int rc;
  290. endpoint_conf_t *ep_conf = &call->ep->conf;
  291. if (!call->audio){
  292. audio_session_conf_t conf = {0};
  293. strcpy(&conf.in_dev[DEV_PICKUP][0], ep_conf->audio_pickup_in_dev);
  294. strcpy(&conf.in_dev[DEV_HANDFREE][0], ep_conf->audio_handfree_in_dev);
  295. strcpy(&conf.out_dev[DEV_PICKUP][0], ep_conf->audio_pickup_out_dev);
  296. strcpy(&conf.out_dev[DEV_HANDFREE][0], ep_conf->audio_handfree_out_dev);
  297. conf.agc_in[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_in_agc;
  298. conf.agc_in[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_in_agc;
  299. conf.agc_out[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_out_agc;
  300. conf.agc_out[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_out_agc;
  301. conf.ns_in[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_in_ns;
  302. conf.ns_in[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_in_ns;
  303. conf.ns_out[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_out_ns;
  304. conf.ns_out[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_out_ns;
  305. conf.aec[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_aec;
  306. conf.aec[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_aec;
  307. rc = audio_session_create(&conf, &call->audio);
  308. if (rc != 0) {
  309. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create audio session failed! rc = %d", rc);
  310. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402301A4").setResultCode("RTA3109")("视频连线创建音频通道失败");
  311. return;
  312. }
  313. else {
  314. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402301A4")("视频连线创建音频通道成功");
  315. }
  316. }
  317. if (call->video) {
  318. video_session_destroy(call->video);
  319. call->video = NULL;
  320. }
  321. int i = 0;
  322. int remote_width = video_desc->param[i++];
  323. int remote_height = video_desc->param[i++];
  324. video_session_conf_t video_conf = {0};
  325. video_conf.bit_rate = 256 * 1024;
  326. video_conf.local_rtp_ip = video_desc->local_ip;
  327. video_conf.local_rtp_port = video_desc->local_port;
  328. video_conf.mtu = ep_conf->mtu;
  329. video_conf.video_quant = ep_conf->quant;
  330. video_conf.remote_rtp_ip = video_desc->remote_ip;
  331. video_conf.remote_rtp_port = video_desc->remote_port;
  332. video_conf.remote_video_width = remote_width;
  333. video_conf.remote_video_height = remote_height;
  334. video_conf.ref_active_camera = call->ep->conf.ref_active_camera;
  335. video_conf.ref_camera_switch = call->ep->conf.ref_camera_switch;
  336. video_conf.ref_camera_state = call->ep->conf.ref_camera_state;
  337. video_conf.ref_window_state = call->ep->conf.ref_window_state;
  338. video_conf.ref_Is_showPersonArea = call->ep->conf.ref_Is_showPersonArea;
  339. video_conf.ref_active_img = NULL;
  340. video_conf.ref_Is_ActiveInspect = NULL;
  341. video_conf.camera_count = call->ep->conf.camera_count;
  342. video_conf.screen_count = call->ep->conf.screen_count;
  343. video_conf.ref_Up_Fps = call->ep->conf.ref_Up_Fps;
  344. video_conf.eDeviceType = call->eDeviceType;
  345. video_conf.nCallType = call->nCallType;
  346. memcpy(&video_conf.video_render_cb, cb, sizeof(rvc_video_render_callback_t));
  347. video_conf.ilocal_wind_flags = VIDEOPLAYER_FLAG_PULL|VIDEOPLAYER_FLAG_CHECKTOP;
  348. video_conf.iremote_wind_flags = VIDEOPLAYER_FLAG_PUSH|VIDEOPLAYER_FLAG_CHECKTOP;
  349. video_conf.local_pt = REC_COMMON_VIDEO_H264_PT;
  350. video_conf.remote_pt = REC_COMMON_VIDEO_H264_PT;
  351. rc = video_session_create(&video_conf, &call->video);
  352. if (rc != 0) {
  353. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create video session failed! rc = %d", rc);
  354. return;
  355. }
  356. rc = video_session_start(call->video);
  357. if (rc != 0) {
  358. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start video session failed! rc = %d", rc);
  359. video_session_destroy(call->video);
  360. call->video = NULL;
  361. return;
  362. }
  363. }
  364. }
  365. #endif
  366. static void endpoint_media_update_audio(endpoint_call_t *call, media_desc_t *audio_desc, int dev_type)
  367. {
  368. if (audio_desc->media_dir == DIR_NONE) {
  369. if (call->audio) {
  370. audio_session_stop(call->audio);
  371. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402301A6")("停止音频通道成功");
  372. audio_session_destroy(call->audio);
  373. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402301A7")("释放音频通道成功");
  374. call->audio = NULL;
  375. }
  376. else{
  377. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("call->audio is null.");
  378. }
  379. if (call->video) { // close video also
  380. video_session_stop(call->video);
  381. video_session_destroy(call->video);
  382. call->video = NULL;
  383. }
  384. else{
  385. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("call->video is null.");
  386. #ifdef RVC_OS_WIN
  387. if (DOUBLERECORD_CALLTYPE == call->nCallType){
  388. double_record_broadcast_video_session_stop();
  389. }
  390. #endif
  391. }
  392. }
  393. else {
  394. int rc;
  395. if (call->audio) {
  396. audio_session_stop(call->audio);
  397. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402301A6")("停止音频通道成功");
  398. audio_session_destroy(call->audio);
  399. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402301A7")("释放音频通道成功");
  400. call->audio = NULL;
  401. }
  402. if (!call->audio) {
  403. endpoint_conf_t *ep_conf = &call->ep->conf;
  404. audio_session_conf_t conf = {0};
  405. strcpy(&conf.in_dev[DEV_PICKUP][0], ep_conf->audio_pickup_in_dev);
  406. strcpy(&conf.in_dev[DEV_HANDFREE][0], ep_conf->audio_handfree_in_dev);
  407. strcpy(&conf.out_dev[DEV_PICKUP][0], ep_conf->audio_pickup_out_dev);
  408. strcpy(&conf.out_dev[DEV_HANDFREE][0], ep_conf->audio_handfree_out_dev);
  409. conf.agc_in[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_in_agc;
  410. conf.agc_in[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_in_agc;
  411. conf.agc_out[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_out_agc;
  412. conf.agc_out[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_out_agc;
  413. conf.ns_in[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_in_ns;
  414. conf.ns_in[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_in_ns;
  415. conf.ns_out[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_out_ns;
  416. conf.ns_out[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_out_ns;
  417. conf.aec[DEV_PICKUP] = !!ep_conf->audio_dsp.audio_pickup_aec;
  418. conf.aec[DEV_HANDFREE] = !!ep_conf->audio_dsp.audio_handfree_aec;
  419. rc = audio_session_create(&conf, &call->audio);
  420. if (rc != 0) {
  421. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("create audio session failed! rc = %d", rc);
  422. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402301A4").setResultCode("RTA3109")("视频连线创建音频通道失败");
  423. return;
  424. }
  425. else {
  426. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402301A4")("视频连线创建音频通道成功");
  427. }
  428. }
  429. audio_session_phonemedia_conf_t phone_conf = {0};
  430. phone_conf.dir = audio_desc->media_dir;
  431. phone_conf.dev_type = (e_dev_type)dev_type;
  432. phone_conf.local_dtmf_pt = audio_desc->local_telephone_event_pt;
  433. phone_conf.local_pt = audio_desc->local_pt;
  434. phone_conf.local_ptime = audio_desc->local_ptime;
  435. phone_conf.local_rtp_ip = audio_desc->local_ip;
  436. phone_conf.local_rtp_port = audio_desc->local_port;
  437. phone_conf.remote_dtmf_pt = audio_desc->remote_telephone_event_pt;
  438. phone_conf.remote_pt = audio_desc->remote_pt;
  439. phone_conf.remote_ptime = audio_desc->remote_ptime;
  440. phone_conf.remote_rtp_ip = audio_desc->remote_ip;
  441. phone_conf.remote_rtp_port = audio_desc->remote_port;
  442. if (NULL != call){
  443. phone_conf.eCalltype = call->nCallType;
  444. phone_conf.eDeviceType = call->eDeviceType;
  445. }
  446. rc = audio_session_start_phonemedia(call->audio, &phone_conf);
  447. if (rc != 0) {
  448. LogWarn(Severity_Middle, Error_Debug, ERROR_MOD_SIP_AUDIO_INITFAIL, CSimpleStringA::Format("start audio session failed! rc = %d.", rc).GetData());
  449. audio_session_destroy(call->audio);
  450. call->audio = NULL;
  451. return;
  452. }
  453. else {
  454. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402301A5")("视频连线启动音频通道成功");
  455. }
  456. }
  457. }
  458. static unsigned int __hash_media_desc(media_desc_t *media_desc, unsigned int hash_code)
  459. {
  460. if (media_desc) {
  461. hash_code += (unsigned int)media_desc->local_ip * 33;
  462. hash_code += (unsigned int)media_desc->remote_ip * 33;
  463. hash_code += (unsigned int)media_desc->local_port * 33;
  464. hash_code += (unsigned int)media_desc->remote_port * 33;
  465. hash_code += (unsigned int)media_desc->media_dir * 33;
  466. hash_code += (unsigned int)media_desc->local_pt * 33;
  467. hash_code += (unsigned int)media_desc->local_ptime * 33;
  468. hash_code += (unsigned int)media_desc->remote_pt * 33;
  469. hash_code += (unsigned int)media_desc->remote_ptime * 33;
  470. hash_code += (unsigned int)media_desc->local_telephone_event_pt * 33;
  471. hash_code += (unsigned int)media_desc->remote_telephone_event_pt * 33;
  472. }
  473. return hash_code;
  474. }
  475. static unsigned int hash_media_desc(media_desc_t *audio)
  476. {
  477. unsigned int hash_code = 0;
  478. hash_code = __hash_media_desc(audio, hash_code);
  479. return hash_code;
  480. }
  481. #define USE_ALAW 1
  482. static const char *call_make_offer(endpoint_call_t *call, char *buf, int size)
  483. {
  484. int local_audio_rtp_port = call->local_media_port;
  485. int local_video_rtp_port = call->local_video_port;
  486. int local_video_pt = REC_COMMON_VIDEO_PT;
  487. int need;
  488. const char *fmt;
  489. {
  490. fmt =
  491. "c=IN IP4 %s\r\n"
  492. #ifdef USE_ALAW
  493. "m=audio %d RTP/AVP 8\r\n"
  494. "a=rtpmap:8 PCMA/8000\r\n"
  495. "a=ptime:30\r\n"
  496. #elif defined(USE_G729)
  497. "m=audio %d RTP/AVP 18\r\n"
  498. "a=rtpmap:18 G729/8000\r\n"
  499. "a=fmtp:18 annexb=no\r\n"
  500. "a=ptime:30\r\n"
  501. #endif
  502. //"a=rtpmap:97 telephone-event/8000\r\n"
  503. //"a=fmtp:97 0-15\r\n"
  504. #ifdef USE_H263_VIDEO
  505. "m=video %d RTP/AVP 34\r\n"
  506. "a=rtpmap:34 H263/90000\r\n"
  507. "a=fmtp:34 QCIF=2 MaxBR=5040\r\n"
  508. #endif
  509. //"a=inactive\r\n" //for debug only
  510. ;
  511. }
  512. need = _scprintf(fmt, call->local_ip, local_audio_rtp_port);
  513. if (size < 0 || size > need) {
  514. sprintf(buf, fmt, call->local_ip, local_audio_rtp_port);
  515. return buf;
  516. } else {
  517. return NULL;
  518. }
  519. }
  520. static int new_call_id(endpoint_t *ep)
  521. {
  522. return ++ep->call_seq;
  523. }
  524. int new_media_port(endpoint_t *ep)
  525. {
  526. ep->media_port_seq += 2;
  527. if (ep->media_port_seq >= ep->conf.media_stop_port) {
  528. ep->media_port_seq = ep->conf.media_start_port;
  529. }
  530. return ep->media_port_seq;
  531. }
  532. static void handle_invite(CONDITION_PARAMS)
  533. {
  534. // we are client only, not accept in-comming call
  535. nua_respond(nh, SIP_403_FORBIDDEN, TAG_END());
  536. }
  537. static void handle_reinvite(CONDITION_PARAMS)
  538. {
  539. char sdp[512] = {0};
  540. sip_content_type_t const *ct = NULL;
  541. tl_gets(tags,
  542. SIPTAG_CONTENT_TYPE_REF(ct),
  543. TAG_END());
  544. if (ct) {
  545. call_make_offer(call, sdp, sizeof(sdp));
  546. }
  547. nua_respond(nh,
  548. SIP_200_OK,
  549. TAG_IF(ct, SOATAG_USER_SDP_STR(sdp)),
  550. TAG_IF(ct, SOATAG_AUDIO_AUX("telephone-event")),
  551. TAG_END());
  552. }
  553. static void handle_r_invite(CONDITION_PARAMS)
  554. {
  555. // nothing to do
  556. }
  557. static int dir_from_attr(const sdp_media_t *m)
  558. {
  559. int dir = DIR_NONE;
  560. if (m) {
  561. if (m->m_attributes) {
  562. static const char *ds[] = {
  563. "inactive", "sendonly", "recvonly", "sendrecv"
  564. };
  565. int i;
  566. int n = array_size(ds);
  567. for (i = 0; i < n; ++i) {
  568. sdp_attribute_t *attr = sdp_attribute_find(m->m_attributes, ds[i]);
  569. if (attr) {
  570. dir = i;
  571. break;
  572. }
  573. }
  574. if (i >= n)
  575. dir = DIR_BOTH;
  576. } else {
  577. dir = DIR_BOTH;
  578. }
  579. }
  580. return dir;
  581. }
  582. static int ptime_from_attr(const sdp_media_t *m)
  583. {
  584. int ptime = 0; // zero for default
  585. if (m) {
  586. if (m->m_attributes) {
  587. sdp_attribute_t *attr = sdp_attribute_find(m->m_attributes, "ptime");
  588. if (attr && attr->a_value) {
  589. ptime = atoi(attr->a_value);
  590. if (ptime < 0)
  591. ptime = 0;
  592. }
  593. }
  594. }
  595. return ptime;
  596. }
  597. static const sdp_rtpmap_t *find_codec(const sdp_rtpmap_t *list, const char *codec)
  598. {
  599. if (!codec)
  600. return NULL;
  601. for (;list; list=list->rm_next) {
  602. if (!_stricmp(list->rm_encoding, codec)) {
  603. break;
  604. }
  605. }
  606. return list;
  607. }
  608. static int get_telephone_event_pt(const sdp_rtpmap_t *list)
  609. {
  610. int pt = -1;
  611. const sdp_rtpmap_t *rm = find_codec(list, "telephone-event");
  612. if (rm) {
  613. pt = rm->rm_pt;
  614. }
  615. return pt;
  616. }
  617. static int get_media_direction(const sdp_media_t *lm, const sdp_media_t *rm)
  618. {
  619. int media_dir = DIR_NONE;
  620. if (rm->m_port == 0 || lm->m_port == 0) {
  621. media_dir = DIR_NONE;
  622. } else {
  623. int ldir = dir_from_attr(lm);
  624. int rdir = dir_from_attr(rm);
  625. if (ldir == DIR_NONE || rdir == DIR_NONE) {
  626. media_dir = DIR_NONE;
  627. } else if (ldir == DIR_TX || rdir == DIR_RX) {
  628. media_dir = DIR_TX;
  629. } else if (ldir == DIR_RX || rdir == DIR_TX) {
  630. media_dir = DIR_RX;
  631. } else {
  632. media_dir = DIR_BOTH;
  633. }
  634. }
  635. return media_dir;
  636. }
  637. static int negotiate_audio(endpoint_call_t *call, media_desc_t *audio_desc, const sdp_media_t *lm, const sdp_media_t *rm)
  638. {
  639. memset(audio_desc, 0, sizeof(media_desc_t));
  640. const char *local_ip;
  641. const char *remote_ip;
  642. local_ip = lm->m_connections ? lm->m_connections->c_address : lm->m_session->sdp_connection->c_address;
  643. remote_ip = rm->m_connections ? rm->m_connections->c_address : rm->m_session->sdp_connection->c_address;
  644. audio_desc->local_ip = strlen(call->local_ip) ? inet_addr(call->local_ip) : 0;
  645. audio_desc->local_port = call->local_media_port;
  646. audio_desc->remote_ip = remote_ip ? inet_addr(remote_ip) : 0;
  647. audio_desc->remote_port = rm->m_port;
  648. audio_desc->local_telephone_event_pt = 97;
  649. audio_desc->remote_telephone_event_pt = get_telephone_event_pt(rm->m_rtpmaps);
  650. audio_desc->local_ptime = ptime_from_attr(lm);
  651. audio_desc->remote_ptime = ptime_from_attr(rm);
  652. int pt = -1;
  653. for (sdp_rtpmap_t *t = lm->m_rtpmaps; t; t = t->rm_next) {
  654. sdp_rtpmap_t *tt = sdp_rtpmap_find_matching(rm->m_rtpmaps, t);
  655. if (tt && tt->rm_pt < 96) {
  656. pt = tt->rm_pt;
  657. break;
  658. }
  659. }
  660. audio_desc->local_pt = audio_desc->remote_pt = pt;
  661. audio_desc->media_dir = get_media_direction(lm, rm);
  662. return 0;
  663. }
  664. static int negotiate_video(endpoint_call_t *call, media_desc_t *video_desc, const sdp_media_t *lm, const sdp_media_t *rm)
  665. {
  666. memset(video_desc, 0, sizeof(media_desc_t));
  667. const char *local_ip;
  668. const char *remote_ip;
  669. local_ip = lm->m_connections ? lm->m_connections->c_address : lm->m_session->sdp_connection->c_address;
  670. remote_ip = rm->m_connections ? rm->m_connections->c_address : rm->m_session->sdp_connection->c_address;
  671. video_desc->local_ip = strlen(call->local_ip) ? inet_addr(call->local_ip) : 0;
  672. video_desc->local_port = call->local_video_port;
  673. video_desc->remote_ip = remote_ip ? inet_addr(remote_ip) : 0;
  674. video_desc->remote_port = rm->m_port;
  675. video_desc->local_telephone_event_pt = 97;
  676. video_desc->remote_telephone_event_pt = get_telephone_event_pt(rm->m_rtpmaps);
  677. video_desc->local_ptime = ptime_from_attr(lm);
  678. video_desc->remote_ptime = ptime_from_attr(rm);
  679. int pt = -1;
  680. for (sdp_rtpmap_t *t = lm->m_rtpmaps; t; t = t->rm_next) {
  681. sdp_rtpmap_t *tt = sdp_rtpmap_find_matching(rm->m_rtpmaps, t);
  682. if (tt) {
  683. pt = tt->rm_pt;
  684. break;
  685. }
  686. }
  687. video_desc->local_pt = video_desc->remote_pt = pt;
  688. video_desc->media_dir = get_media_direction(lm, rm);
  689. return 0;
  690. }
  691. static void negotiate_sdp(endpoint_call_t *call, const sdp_session_t *local_sdp, const sdp_session_t* remote_sdp)
  692. {
  693. const sdp_media_t *lm = local_sdp->sdp_media;
  694. const sdp_media_t *rm = remote_sdp->sdp_media;
  695. media_desc_t audio_desc = {0}, video_desc = {0};
  696. int rc = -1, rv = -1;
  697. for(; lm; lm = lm->m_next)
  698. {
  699. if (0 == lm->m_port)
  700. {
  701. continue;
  702. }
  703. const sdp_media_t *rm = remote_sdp->sdp_media;
  704. for (; rm; rm = rm->m_next)
  705. {
  706. if (rm->m_type == lm->m_type)
  707. {
  708. if (sdp_media_audio == rm->m_type)
  709. {
  710. rc = negotiate_audio(call, &audio_desc, lm, rm);
  711. }
  712. if (call->nCallType != NORMAL_CALLTYPE && call->nCallType != DOUBLERECORD_CALLTYPE)
  713. {
  714. if (sdp_media_video == rm->m_type)
  715. {
  716. rv = negotiate_video(call, &video_desc, lm, rm);
  717. }
  718. }
  719. }
  720. }
  721. }
  722. if (rc == 0)
  723. {
  724. unsigned int hash_code = hash_media_desc(&audio_desc);
  725. if (hash_code != call->last_media_desc_hash)
  726. {
  727. endpoint_media_update_audio(call, &audio_desc, call->ep->curr_audio_dev_type);
  728. call->last_media_desc_hash = hash_code;
  729. //char strmsg[MAX_PATH] = {0};
  730. //snprintf(strmsg, MAX_PATH, "negotiate audio success!local audio ip=%s port=%d pt=%d,remote audio ip=%s port=%d,pt=%d",str_local,audio_desc.local_port,audio_desc.local_pt,str_remote,audio_desc.remote_port,audio_desc.remote_pt);
  731. //LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_CALL_AUDIO_NEGOTIATE, strmsg);
  732. }
  733. }
  734. if (rv == 0)
  735. {
  736. unsigned int hash_code = hash_media_desc(&video_desc);
  737. if (hash_code != call->last_media_desc_hash)
  738. {
  739. call->sdpvieo_desc.local_pt = video_desc.local_pt;
  740. call->sdpvieo_desc.local_rtp_ip = video_desc.local_ip;
  741. call->sdpvieo_desc.local_rtp_port = video_desc.local_port;
  742. call->sdpvieo_desc.remote_pt = video_desc.remote_pt;
  743. call->sdpvieo_desc.remote_rtp_ip = video_desc.remote_ip;
  744. call->sdpvieo_desc.remote_rtp_port = video_desc.remote_port;
  745. call->last_media_desc_hash = hash_code;
  746. //char strmsg[MAX_PATH] = {0};
  747. //_snprintf(strmsg, MAX_PATH, "negotiate video success!local video ip=%s port=%d pt=%d,remote video ip=%s port=%d pt=%d",str_local,video_desc.local_port,video_desc.local_pt,str_remote,video_desc.remote_port,video_desc.remote_pt);
  748. //LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_CALL_VIDEO_NEGOTIATE, strmsg);
  749. }
  750. }
  751. else
  752. {
  753. if (call->nCallType != NORMAL_CALLTYPE && call->nCallType != DOUBLERECORD_CALLTYPE)
  754. {
  755. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("negotiate video Fail!!!");
  756. }
  757. }
  758. }
  759. static void on_state(CONDITION_PARAMS)
  760. {
  761. int offer_recv = 0, answer_recv = 0, offer_sent = 0, answer_sent = 0;
  762. int state = nua_callstate_init;
  763. const char *replaces_str = NULL;
  764. const sdp_session_t *remote_sdp = NULL;
  765. const char *remote_sdp_str = NULL;
  766. const sdp_session_t *local_sdp = NULL;
  767. const char *local_sdp_str = NULL;
  768. int st;
  769. if (!call) {
  770. nua_handle_destroy(nh);
  771. return;
  772. }
  773. if (g_IsExternalTerminalted)
  774. {
  775. return;
  776. }
  777. tl_gets(tags,
  778. NUTAG_CALLSTATE_REF(state),
  779. NUTAG_OFFER_RECV_REF(offer_recv),
  780. NUTAG_ANSWER_RECV_REF(answer_recv),
  781. NUTAG_OFFER_SENT_REF(offer_sent),
  782. NUTAG_ANSWER_SENT_REF(answer_sent),
  783. SIPTAG_REPLACES_STR_REF(replaces_str),
  784. SOATAG_REMOTE_SDP_STR_REF(remote_sdp_str),
  785. SOATAG_LOCAL_SDP_STR_REF(local_sdp_str),
  786. TAG_END());
  787. switch (state)
  788. {
  789. case nua_callstate_calling:
  790. {
  791. if (local_sdp_str) {
  792. sdp_parser_t* parser = sdp_parse(call->home, local_sdp_str, strlen(local_sdp_str), -1);
  793. assert(call->last_sdp == NULL);
  794. call->last_sdp = sdp_session_dup(call->home, sdp_session(parser));
  795. sdp_parser_free(parser);
  796. }
  797. st = CALLING;
  798. call->cb.on_call_state(st, state_desc[st], phrase, call->cb.user_data);
  799. }
  800. break;
  801. case nua_callstate_proceeding:
  802. {
  803. st = PROCEEDING;
  804. call->cb.on_call_state(st, state_desc[st], phrase, call->cb.user_data);
  805. if (remote_sdp_str) {
  806. sdp_parser_t* parser = sdp_parse(call->home, remote_sdp_str, strlen(remote_sdp_str), -1);
  807. remote_sdp = sdp_session(parser);
  808. if (call->last_sdp) {
  809. negotiate_sdp(call, call->last_sdp, remote_sdp);
  810. su_free(call->home, call->last_sdp);
  811. call->last_sdp = NULL;
  812. }
  813. sdp_parser_free(parser);
  814. }
  815. }
  816. break;
  817. case nua_callstate_completing:
  818. {
  819. st = COMPLETING;
  820. call->cb.on_call_state(st, state_desc[st], phrase, call->cb.user_data);
  821. if (remote_sdp_str) {
  822. sdp_parser_t* parser = sdp_parse(call->home, remote_sdp_str, strlen(remote_sdp_str), -1);
  823. remote_sdp = sdp_session(parser);
  824. if (call->last_sdp) {
  825. negotiate_sdp(call, call->last_sdp, remote_sdp);
  826. su_free(call->home, call->last_sdp);
  827. call->last_sdp = NULL;
  828. }
  829. sdp_parser_free(parser);
  830. }
  831. }
  832. break;
  833. case nua_callstate_completed:
  834. {
  835. if (remote_sdp_str) {
  836. if (!call->last_sdp) {
  837. sdp_parser_t* parser = sdp_parse(call->home, remote_sdp_str, strlen(remote_sdp_str), -1);
  838. call->last_sdp = sdp_session_dup(call->home, sdp_session(parser));
  839. sdp_parser_free(parser);
  840. }
  841. }
  842. if (local_sdp_str) {
  843. if (call->last_sdp) {
  844. sdp_parser_t* parser = sdp_parse(call->home, local_sdp_str, strlen(local_sdp_str), -1);
  845. local_sdp = sdp_session(parser);
  846. negotiate_sdp(call, local_sdp, call->last_sdp);
  847. su_free(call->home, call->last_sdp);
  848. call->last_sdp = NULL;
  849. sdp_parser_free(parser);
  850. }
  851. }
  852. }
  853. break;
  854. case nua_callstate_ready:
  855. {
  856. call->connected = true;
  857. st = READY;
  858. call->cb.on_call_state(st, state_desc[st], phrase, call->cb.user_data);
  859. if (remote_sdp_str) {
  860. sdp_parser_t* parser = sdp_parse(call->home, remote_sdp_str, strlen(remote_sdp_str), -1);
  861. remote_sdp = sdp_session(parser);
  862. if (call->last_sdp) {
  863. negotiate_sdp(call, call->last_sdp, remote_sdp);
  864. su_free(call->home, call->last_sdp);
  865. call->last_sdp = NULL;
  866. }
  867. sdp_parser_free(parser);
  868. }
  869. #if 0
  870. if (remote_sdp_str) {
  871. sdp_parser_t* parser = sdp_parse(call->home, remote_sdp_str, strlen(remote_sdp_str), -1);
  872. remote_sdp = sdp_session(parser);
  873. negotiate_sdp(call, call->last_sdp, remote_sdp);
  874. sdp_parser_free(parser);
  875. }
  876. else if (local_sdp_str) {
  877. sdp_parser_t* parser = sdp_parse(call->home, local_sdp_str, strlen(local_sdp_str), -1);
  878. local_sdp = sdp_session(parser);
  879. negotiate_sdp(call, local_sdp, call->last_sdp);
  880. sdp_parser_free(parser);
  881. }
  882. #endif
  883. }
  884. break;
  885. case nua_callstate_terminated:
  886. {
  887. st = TERMINATED;
  888. {
  889. media_desc_t audio_desc = { 0 };
  890. audio_desc.media_dir = DIR_NONE;
  891. endpoint_media_update_audio(call, &audio_desc, call->ep->curr_audio_dev_type);
  892. }
  893. call->cb.on_call_state(st, state_desc[st], phrase, call->cb.user_data);
  894. nua_handle_bind(nh, NULL);
  895. nua_handle_destroy(nh);
  896. call->nh = NULL;
  897. }
  898. break;
  899. default:
  900. break;
  901. }
  902. }
  903. void terminatedcall(endpoint_call_t *call)
  904. {
  905. int st = TERMINATED;
  906. g_IsExternalTerminalted = true;
  907. {
  908. media_desc_t audio_desc = {0};
  909. audio_desc.media_dir = DIR_NONE;
  910. endpoint_media_update_audio(call, &audio_desc, call->ep->curr_audio_dev_type);
  911. }
  912. }
  913. static void endpoint_callback(nua_event_t event,
  914. int status,
  915. char const *phrase,
  916. nua_t *nua,
  917. nua_magic_t *magic,
  918. nua_handle_t *nh,
  919. nua_hmagic_t *hmagic,
  920. sip_t const *sip,
  921. tagi_t tags[])
  922. {
  923. switch (event)
  924. {
  925. if (!g_IsExternalTerminalted)
  926. {
  927. case nua_i_invite:
  928. if (hmagic == NULL) {
  929. handle_invite(status, phrase, nua, (endpoint_t*)magic, nh, (endpoint_call_t*)hmagic, sip, tags);
  930. } else {
  931. handle_reinvite(status, phrase, nua, (endpoint_t*)magic, nh, (endpoint_call_t*)hmagic, sip, tags);
  932. }
  933. break;
  934. case nua_r_invite:
  935. handle_r_invite(status, phrase, nua, (endpoint_t*)magic, nh, (endpoint_call_t*)hmagic, sip, tags);
  936. break;
  937. case nua_i_bye:
  938. //.....
  939. break;
  940. case nua_i_info:
  941. break;
  942. case nua_i_state:
  943. on_state(status, phrase, nua, (endpoint_t*)magic, nh, (endpoint_call_t*)hmagic, sip, tags);
  944. break;
  945. case nua_i_active:
  946. break;
  947. case nua_i_options:
  948. //nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), SOATAG_USER_SDP_STR(NULL), TAG_END());
  949. nua_respond(nh, SIP_200_OK, TAG_END());
  950. break;
  951. case nua_r_cancel:
  952. if (status > 300) {
  953. nua_bye(nh, TAG_END());
  954. }
  955. break;
  956. case nua_i_prack:
  957. case nua_r_prack:
  958. break;
  959. case nua_r_bye:
  960. //LOG_TRACE("nua_r_bye");
  961. if (status > 300) {
  962. nua_bye(nh, TAG_END());
  963. }
  964. break;
  965. /* and so on ... */
  966. default:
  967. if (status > 100) { /* unknown event -> print out error message */
  968. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unknown event %d: %03d %s.",
  969. event,
  970. status,
  971. phrase);
  972. } else {
  973. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unknown event %d.", event);
  974. }
  975. break;
  976. }
  977. }
  978. if (!hmagic)
  979. {
  980. nua_handle_destroy(nh);
  981. return;
  982. }
  983. }
  984. #ifdef RVC_OS_WIN
  985. static unsigned int __stdcall __event_thread(void* arg)
  986. #else
  987. void* __event_thread(void* arg)
  988. #endif
  989. {
  990. endpoint_t *ep = (endpoint_t *)arg;
  991. ep->entity->GetFunction()->InitLogCurrentThread();
  992. #ifdef RVC_OS_WIN
  993. CoInitialize(NULL);
  994. #else
  995. #endif // RVC_OS_WIN
  996. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("enter event_thread.");
  997. ep->root = su_root_create(ep);
  998. ep->nua = nua_create(ep->root,
  999. &endpoint_callback,
  1000. ep,
  1001. NUTAG_URL(ep->conf.uri),
  1002. TAG_END());
  1003. nua_set_params(ep->nua,
  1004. SIPTAG_ALLOW_STR("INVITE,CANCEL,BYE,ACK,INFO,OPTIONS"),
  1005. NUTAG_AUTOALERT(1),
  1006. NUTAG_ALLOW("PRACK"),
  1007. NUTAG_EARLY_MEDIA(1),
  1008. NUTAG_SESSION_TIMER(1),
  1009. NUTAG_AUTOANSWER(0),
  1010. NUTAG_AUTOACK(1),
  1011. NTATAG_SIP_T1X64(8000),
  1012. TAG_NULL());
  1013. su_root_run(ep->root);
  1014. nua_shutdown(ep->nua);
  1015. ep->nua = NULL;
  1016. su_root_destroy(ep->root);
  1017. ep->root = NULL;
  1018. #ifdef RVC_OS_WIN
  1019. CoUninitialize();
  1020. #else
  1021. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("leave event_thread.");
  1022. #endif // RVC_OS_WIN
  1023. return 0;
  1024. }
  1025. static int __endpoint_break(void *arg)
  1026. {
  1027. endpoint_t *ep = (endpoint_t *)arg;
  1028. //.....nua_shutdown
  1029. su_root_break(ep->root);
  1030. return 0;
  1031. }
  1032. static endpoint_t *__endpoint_create(CEntityBase *pEntity, const endpoint_conf_t *conf,int nDev)
  1033. {
  1034. endpoint_t *ep;
  1035. ep = ZALLOC_T(endpoint_t);
  1036. su_home_init(ep->home);
  1037. memcpy(&ep->conf, conf, sizeof(endpoint_conf_t));
  1038. ep->media_port_seq = (conf->media_start_port + (SP::Module::Comm::RVCGetTickCount() % (conf->media_stop_port - conf->media_start_port))) & 0xfffc;
  1039. ep->entity = pEntity;
  1040. ep->call_seq = SP::Module::Comm::RVCGetTickCount();
  1041. ep->curr_audio_dev_type = nDev;
  1042. INIT_LIST_HEAD(&ep->call_list);
  1043. return ep;
  1044. }
  1045. static void __endpoint_destroy(endpoint_t *ep)
  1046. {
  1047. su_root_destroy(ep->root);
  1048. su_home_deinit(ep->home);
  1049. free(ep);
  1050. }
  1051. static int __endpoint_start(endpoint_t *ep)
  1052. {
  1053. #ifdef RVC_OS_WIN
  1054. ep->event_thread = (HANDLE)_beginthreadex(NULL, 0, &__event_thread, ep, 0, NULL);
  1055. if (ep->event_thread)
  1056. {
  1057. while (!ep->root)
  1058. {
  1059. DWORD dwRet = WaitForSingleObject(ep->event_thread, 1);
  1060. if (dwRet == WAIT_OBJECT_0)
  1061. {
  1062. CloseHandle(ep->event_thread);
  1063. ep->event_thread = NULL;
  1064. break;
  1065. }
  1066. }
  1067. }
  1068. return ep->event_thread ? 0 : -1;
  1069. #else
  1070. //pthread_attr_t attr;
  1071. //pthread_attr_init(&attr);
  1072. //pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  1073. int err = pthread_create(&ep->ievent_threadid, NULL, __event_thread, ep);
  1074. //pthread_attr_destroy(&attr);
  1075. if (0 == err) {
  1076. while (!ep->root) {
  1077. struct timespec ts;
  1078. clock_gettime(CLOCK_REALTIME, &ts);
  1079. long unsec = ts.tv_nsec + (1000 * 1000);
  1080. ts.tv_sec += (unsec / 1000000000);
  1081. ts.tv_nsec = (unsec % 1000000000);
  1082. if (0 == pthread_timedjoin_np(ep->ievent_threadid, NULL, &ts)) {
  1083. ep->ievent_threadid = 0;
  1084. break;
  1085. }
  1086. }
  1087. }
  1088. else {
  1089. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create event thread failed.");
  1090. }
  1091. return ep->ievent_threadid > 0 ? 0 : -1;
  1092. #endif
  1093. }
  1094. static void __endpoint_stop(endpoint_t *ep)
  1095. {
  1096. #ifdef RVC_OS_WIN
  1097. if (ep->event_thread)
  1098. {
  1099. int rc;
  1100. su_task_execute(su_root_task(ep->root), &__endpoint_break, ep, &rc);
  1101. WaitForSingleObject(ep->event_thread, INFINITE);
  1102. CloseHandle(ep->event_thread);
  1103. ep->event_thread = NULL;
  1104. }
  1105. #else
  1106. if (ep->ievent_threadid > 0)
  1107. {
  1108. int rc;
  1109. su_task_execute(su_root_task(ep->root), &__endpoint_break, ep, &rc);
  1110. if (0 == pthread_join(ep->ievent_threadid, NULL)) {
  1111. ep->ievent_threadid = 0;
  1112. }
  1113. else {
  1114. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pthread join error for %s", strerror(errno));
  1115. }
  1116. }
  1117. #endif
  1118. }
  1119. static void rvc_sofia_logger(void* stream, char const* fmt, va_list ap) {
  1120. if (!fmt)
  1121. return;
  1122. char line[255];
  1123. vsnprintf(line, sizeof(line), fmt, ap);
  1124. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("rvc_sofia_logger : %s", line);
  1125. }
  1126. int endpoint_init_lib()
  1127. {
  1128. int result = su_init();
  1129. //su_log_set_level(NULL, 9);
  1130. //su_log_redirect(NULL, rvc_sofia_logger, NULL);
  1131. return result;
  1132. }
  1133. void endpoint_deinit_lib()
  1134. {
  1135. su_deinit();
  1136. }
  1137. endpoint_t *endpoint_create(CEntityBase *pEntity, const endpoint_conf_t *conf,int nDev)
  1138. {
  1139. endpoint_t *endpt;
  1140. endpt = __endpoint_create(pEntity, conf,nDev);
  1141. if (endpt) {
  1142. int rc = __endpoint_start(endpt);
  1143. if (rc != 0)
  1144. {
  1145. __endpoint_destroy(endpt);
  1146. endpt = NULL;
  1147. }
  1148. }
  1149. return endpt;
  1150. }
  1151. void endpoint_destroy(endpoint_t *ep)
  1152. {
  1153. if (ep)
  1154. {
  1155. __endpoint_stop(ep);
  1156. __endpoint_destroy(ep);
  1157. }
  1158. }
  1159. int endpoint_invoke(endpoint_t *ep, int (*func)(void*), void *user_data, int *result)
  1160. {
  1161. if (ep){
  1162. return su_task_execute(su_root_task(ep->root), func, user_data, result);
  1163. }
  1164. else
  1165. {
  1166. *result = Error_Param;
  1167. return -1;
  1168. }
  1169. }
  1170. void endpoint_change_audio_dev(endpoint_t *ep, int dev_type)
  1171. {
  1172. if (ep){
  1173. if (ep->curr_audio_dev_type != dev_type) {
  1174. ep->curr_audio_dev_type = dev_type;
  1175. if (ep->active_call) {
  1176. endpoint_media_change_audio_dev(ep->active_call, (e_dev_type)dev_type);
  1177. } else {
  1178. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("active call is null!");
  1179. }
  1180. }
  1181. }
  1182. }
  1183. endpoint_call_t *endpoint_call_create(endpoint_t *ep, const endpoint_call_params_t* pcallparam, const endpoint_call_callback_t *cb)
  1184. {
  1185. endpoint_call_t *call = NULL;
  1186. su_home_t *home = NULL;
  1187. if (!pcallparam || !pcallparam->to_uri){
  1188. return NULL;
  1189. }
  1190. home = su_home_create();
  1191. if (!home){
  1192. goto on_error;
  1193. }
  1194. call = (endpoint_call_t*)su_home_new(sizeof(endpoint_call_t));
  1195. if (!call){
  1196. goto on_error;
  1197. }
  1198. memset(call, 0, sizeof(endpoint_call_t));
  1199. call->connected = 0;
  1200. call->ep = ep;
  1201. call->home = home;
  1202. call->last_media_desc_hash = 0;
  1203. call->to_uri = su_strdup(home, pcallparam->to_uri);
  1204. if (pcallparam->from_uri != NULL){
  1205. call->from_uri = su_strdup(home, pcallparam->from_uri);
  1206. }
  1207. if (pcallparam->call_id != NULL){
  1208. call->call_id = su_strdup(home, pcallparam->call_id);
  1209. }
  1210. if (NULL != pcallparam->local_ip){
  1211. _snprintf(call->local_ip, RVC_MAX_IP_LEN, "%s", pcallparam->local_ip);
  1212. }
  1213. call->eDeviceType = pcallparam->nDeviceType;
  1214. call->nCallType = pcallparam->nCallType;
  1215. memcpy(&call->cb, cb, sizeof(endpoint_call_callback_t));
  1216. call->id = new_call_id(ep);
  1217. call->local_media_port = pcallparam->ilocal_audio_port;
  1218. call->local_video_port = pcallparam->ilocal_video_port;
  1219. REF_COUNT_INIT(&call->ref_cnt);
  1220. list_add_tail(&call->entry, &ep->call_list);
  1221. ep->active_call = call;
  1222. return call;
  1223. on_error:
  1224. if (home)
  1225. su_home_unref(home);
  1226. return call;
  1227. }
  1228. void endpoint_call_destroy(endpoint_call_t *call)
  1229. {
  1230. endpoint_call_dec_ref(call);
  1231. }
  1232. int endpoint_call_start(endpoint_call_t *call)
  1233. {
  1234. char sdp[512] = {0};
  1235. if (call->nh)
  1236. return -1;
  1237. if (call->from_uri != NULL && call->call_id != NULL){
  1238. call->nh = nua_handle(call->ep->nua,
  1239. call,
  1240. SIPTAG_CALL_ID_STR(call->call_id),
  1241. SIPTAG_FROM_STR(call->from_uri),
  1242. SIPTAG_TO_STR(call->to_uri),
  1243. TAG_END());
  1244. } else if (call->from_uri != NULL){
  1245. call->nh = nua_handle(call->ep->nua,
  1246. call,
  1247. SIPTAG_FROM_STR(call->from_uri),
  1248. SIPTAG_TO_STR(call->to_uri),
  1249. TAG_END());
  1250. }else if (call->call_id != NULL){
  1251. call->nh = nua_handle(call->ep->nua,
  1252. call,
  1253. SIPTAG_FROM_STR(call->ep->conf.uri),
  1254. SIPTAG_CALL_ID_STR(call->call_id),
  1255. SIPTAG_TO_STR(call->to_uri),
  1256. TAG_END());
  1257. }else{
  1258. call->nh = nua_handle(call->ep->nua,
  1259. call,
  1260. SIPTAG_FROM_STR(call->ep->conf.uri),
  1261. SIPTAG_TO_STR(call->to_uri),
  1262. TAG_END());
  1263. }
  1264. call_make_offer(call, sdp, -1);
  1265. if (0 == strlen(sdp)){
  1266. LogWarn(Severity_Middle, Error_Debug, EVENT_MOD_SIP_INVALID_SDP, "invalid sdp.");
  1267. }
  1268. nua_invite(call->nh,
  1269. //NUTAG_URL(call->remote_uri),
  1270. SOATAG_USER_SDP_STR(sdp),
  1271. NUTAG_SESSION_TIMER(20000),
  1272. //SOATAG_AUDIO_AUX("telephone-event"),
  1273. TAG_END());
  1274. return 0;
  1275. }
  1276. int endpoint_call_hangup(endpoint_call_t *call)
  1277. {
  1278. if (call->nh) {
  1279. if (call->connected) {
  1280. nua_bye(call->nh, NUTAG_SESSION_TIMER(8000),TAG_END());
  1281. } else {
  1282. nua_cancel(call->nh, NUTAG_SESSION_TIMER(8000),TAG_END());
  1283. }
  1284. }
  1285. return 0;
  1286. }
  1287. #ifdef RVC_OS_WIN
  1288. int endpoint_call_start_video(endpoint_call_t *call, unsigned long remote_ip, int remote_video_rtp,
  1289. unsigned long local_ip, int local_video_rtp,
  1290. int remote_width, int remote_height,
  1291. int local_view_x, int local_view_y, int local_view_cx, int local_view_cy,
  1292. int remote_view_x, int remote_view_y, int remote_view_cx, int remote_view_cy,
  1293. int local_move, int remote_move, video_session_callback_t* cb)
  1294. {
  1295. if (call)
  1296. {
  1297. int i = 0;
  1298. media_desc_t video_desc = {0};
  1299. video_desc.media_dir = DIR_BOTH;
  1300. if (call->nCallType == NORMAL_CALLTYPE || call->nCallType == DOUBLERECORD_CALLTYPE)//如果是可视柜台模式,使用协助通道的协商结果
  1301. {
  1302. video_desc.local_ip = local_ip;
  1303. video_desc.local_port = local_video_rtp;
  1304. video_desc.remote_port = remote_video_rtp;
  1305. video_desc.remote_ip = remote_ip;
  1306. }
  1307. else //如果是非可视柜台模式,使用SDP协商的参数
  1308. {
  1309. video_desc.local_ip = call->sdpvieo_desc.local_rtp_ip;
  1310. video_desc.local_port = call->sdpvieo_desc.local_rtp_port;
  1311. video_desc.local_pt = call->sdpvieo_desc.local_pt;
  1312. video_desc.remote_ip = call->sdpvieo_desc.remote_rtp_ip;
  1313. video_desc.remote_port = call->sdpvieo_desc.remote_rtp_port;
  1314. video_desc.remote_pt = call->sdpvieo_desc.remote_pt;
  1315. }
  1316. video_desc.param[i++] = local_view_x;
  1317. video_desc.param[i++] = local_view_y;
  1318. video_desc.param[i++] = local_view_cx;
  1319. video_desc.param[i++] = local_view_cy;
  1320. video_desc.param[i++] = remote_view_x;
  1321. video_desc.param[i++] = remote_view_y;
  1322. video_desc.param[i++] = remote_view_cx;
  1323. video_desc.param[i++] = remote_view_cy;
  1324. video_desc.param[i++] = remote_width;
  1325. video_desc.param[i++] = remote_height;
  1326. video_desc.param[i++] = local_move;
  1327. video_desc.param[i++] = remote_move;
  1328. endpoint_media_update_video(call, &video_desc, cb);
  1329. return 0;
  1330. }
  1331. else
  1332. {
  1333. return Error_Param;
  1334. }
  1335. }
  1336. #else
  1337. int endpoint_call_start_video(endpoint_call_t* call, endpoint_call_param_t* pcallparam, rvc_video_render_callback_t* render_cb)
  1338. {
  1339. if (call)
  1340. {
  1341. int i = 0;
  1342. media_desc_t video_desc = {0};
  1343. video_desc.media_dir = DIR_BOTH;
  1344. if (call->nCallType == NORMAL_CALLTYPE || call->nCallType == DOUBLERECORD_CALLTYPE)//如果是可视柜台模式,使用协助通道的协商结果
  1345. {
  1346. video_desc.local_ip = pcallparam->local_ip;
  1347. video_desc.local_port = pcallparam->local_port;
  1348. video_desc.remote_port = pcallparam->remote_port;
  1349. video_desc.remote_ip = pcallparam->remote_ip;
  1350. }
  1351. else //如果是非可视柜台模式,使用SDP协商的参数
  1352. {
  1353. video_desc.local_ip = call->sdpvieo_desc.local_rtp_ip;
  1354. video_desc.local_port = call->sdpvieo_desc.local_rtp_port;
  1355. video_desc.local_pt = call->sdpvieo_desc.local_pt;
  1356. video_desc.remote_ip = call->sdpvieo_desc.remote_rtp_ip;
  1357. video_desc.remote_port = call->sdpvieo_desc.remote_rtp_port;
  1358. video_desc.remote_pt = call->sdpvieo_desc.remote_pt;
  1359. }
  1360. video_desc.param[i++] = pcallparam->remote_width;
  1361. video_desc.param[i++] = pcallparam->remote_height;
  1362. endpoint_media_update_video(call, &video_desc, render_cb);
  1363. return 0;
  1364. }
  1365. else
  1366. {
  1367. return Error_Param;
  1368. }
  1369. }
  1370. #endif
  1371. int endpoint_call_stop_video(endpoint_call_t *call)
  1372. {
  1373. if (call) {
  1374. media_desc_t video_desc = {0};
  1375. video_desc.media_dir = DIR_NONE;
  1376. endpoint_media_update_video(call, &video_desc,NULL);
  1377. return 0;
  1378. } else {
  1379. return Error_Param;
  1380. }
  1381. }
  1382. #ifdef RVC_OS_WIN
  1383. int endpoint_call_stop_double_record_broadcast_video()
  1384. {
  1385. double_record_broadcast_video_session_stop();
  1386. return Error_Succeed;
  1387. }
  1388. int local_remote_show_video(endpoint_call_t *call,int local_view_x, int local_view_y, int local_view_cx, int local_view_cy,int remote_view_x, int remote_view_y, int remote_view_cx, int remote_view_cy, int local_move, int remote_move, video_session_callback_t* cb)
  1389. {
  1390. int rc;
  1391. endpoint_conf_t *ep_conf = &call->ep->conf;
  1392. if (call->video)
  1393. {
  1394. video_session_destroy(call->video);
  1395. call->video = NULL;
  1396. }
  1397. int remote_video_width = REC_COMMON_VIDEO_SSM_AGENT_WIDTH;
  1398. int remote_video_height = REC_COMMON_VIDEO_SSM_AGENT_HEIGHT;
  1399. if (eStand2sType == call->eDeviceType){
  1400. remote_video_width = REC_COMMON_VIDEO_DSM_AGENT_WIDTH;
  1401. remote_video_height = REC_COMMON_VIDEO_DSM_AGENT_HEIGHT;
  1402. }
  1403. video_session_conf_t video_conf = {0};
  1404. video_conf.bit_rate = 256 * 1024;
  1405. video_conf.local_rtp_ip = 0;
  1406. video_conf.local_rtp_port = 0;
  1407. video_conf.local_video_view_x = local_view_x;
  1408. video_conf.local_video_view_y = local_view_y;
  1409. video_conf.local_video_view_cx = local_view_cx;
  1410. video_conf.local_video_view_cy = local_view_cy;
  1411. video_conf.local_move = local_move;
  1412. video_conf.mtu = ep_conf->mtu;
  1413. video_conf.video_quant = ep_conf->quant;
  1414. video_conf.remote_rtp_ip = 0;
  1415. video_conf.remote_rtp_port = 0;
  1416. video_conf.remote_video_view_x = remote_view_x;
  1417. video_conf.remote_video_view_y = remote_view_y;
  1418. video_conf.remote_video_view_cx = remote_view_cx;
  1419. video_conf.remote_video_view_cy = remote_view_cy;
  1420. video_conf.remote_move = remote_move;
  1421. video_conf.remote_video_width = remote_video_width;
  1422. video_conf.remote_video_height = remote_video_height;
  1423. video_conf.ref_active_camera = call->ep->conf.ref_active_camera;
  1424. video_conf.ref_camera_switch = call->ep->conf.ref_camera_switch;
  1425. video_conf.ref_camera_state = call->ep->conf.ref_camera_state;
  1426. video_conf.ref_window_state = call->ep->conf.ref_window_state;
  1427. video_conf.ref_active_img = call->ep->conf.ref_active_img;
  1428. video_conf.ref_Is_ActiveInspect = call->ep->conf.ref_Is_ActiveInspect;
  1429. video_conf.ref_Is_showPersonArea = call->ep->conf.ref_Is_showPersonArea;
  1430. video_conf.camera_count = call->ep->conf.camera_count;
  1431. video_conf.screen_count = call->ep->conf.screen_count;
  1432. video_conf.eDeviceType = call->eDeviceType;
  1433. video_conf.video_echo_cb = cb;
  1434. video_conf.ilocal_wind_flags = VIDEOPLAYER_FLAG_PULL|VIDEOPLAYER_FLAG_CHECKTOP;
  1435. video_conf.iremote_wind_flags = VIDEOPLAYER_FLAG_PUSH|VIDEOPLAYER_FLAG_CHECKTOP;
  1436. video_conf.eType = (eVideoRenderType)call->ep->conf.irendertype;
  1437. rc = local_video_session_create(&video_conf, &call->video, true);
  1438. if (rc != 0){
  1439. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create video session failed! rc = %d", rc);
  1440. return -1;
  1441. }
  1442. rc = video_session_start(call->video);
  1443. if (rc != 0){
  1444. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start video session failed! rc = %d", rc);
  1445. video_session_destroy(call->video);
  1446. call->video = NULL;
  1447. return -1;
  1448. }
  1449. return 0;
  1450. }
  1451. int local_play_stop_video(endpoint_call_t *call)
  1452. {
  1453. if (call) {
  1454. media_desc_t video_desc = {0};
  1455. video_desc.media_dir = DIR_NONE;
  1456. endpoint_media_update_video(call, &video_desc,NULL);
  1457. return 0;
  1458. } else
  1459. {
  1460. return Error_Param;
  1461. }
  1462. }
  1463. #endif
  1464. static void __endpoint_call_destroy(endpoint_call_t *call)
  1465. {
  1466. list_del(&call->entry);
  1467. if (call->ep && call->ep->active_call == call) {
  1468. call->ep->active_call = NULL;
  1469. }
  1470. su_home_unref(call->home);
  1471. }
  1472. IMPLEMENT_REF_COUNT_MT_STATIC(endpoint_call, endpoint_call_t, ref_cnt, __endpoint_call_destroy)