h323_fs.cpp
上传用户:hnnddl
上传日期:2007-01-06
资源大小:3580k
文件大小:9k
源码类别:

IP电话/视频会议

开发平台:

WINDOWS

  1. /*
  2.  * $Revision: 1.3 $
  3.  * $Date: 1998/10/23 15:52:32 $
  4.  */
  5. ////////////////////////////////////////////////////////////////
  6. //               Copyright (c) 1996-98 Lucent Technologies    //
  7. //                       All Rights Reserved                  //
  8. //                                                            //
  9. //                       THIS IS UNPUBLISHED                  //
  10. //                       PROPRIETARY SOURCE                   //
  11. //                   CODE OF Lucent Technologies              //
  12. // AND elemedia   //
  13. //                                                            //
  14. ////////////////////////////////////////////////////////////////
  15. //
  16. ////////////////////////////////////////////////////////////////
  17. // Example programs are provided soley to demonstrate one     //
  18. // possible use of the stack libraries and are included for   //
  19. // instructional purposes only.  You are free to use, modify  //
  20. // and/or redistribute any portion of code in the example     //
  21. // programs.  However, such examples are not intended to      //
  22. // represent production quality code.                         //
  23. //                                                            //
  24. // THE COPYRIGHT HOLDERS PROVIDE THESE EXAMPLE PROGRAMS       //
  25. // "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED     //
  26. // OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     //
  27. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A            //
  28. // PARTICULAR PURPOSE.                                        //
  29. ////////////////////////////////////////////////////////////////
  30. #include "exchange.h"
  31. #include "call.h"
  32. #include <assert.h>
  33. // Caveats: expects call->rtcp_addr/call->rtp_addr to be valid.
  34. int
  35. H323Call::InitFastStartProposal(H225CSSetupUUIE *setup_uuie)
  36. {
  37. ProtReturnCode ret;
  38. H245SigOpenLogicalChannel *olc_p;
  39. H245SigForwardLCParams *fwd_lcp_p;
  40. H245SigReverseLCParams *rev_lcp_p;
  41. H245SigH225Params *h225_mux_p; 
  42. H245SigMuxNone *none_mux_p;
  43. assert(do_faststart != 0);
  44. // Lets do only G.723 for now.
  45. H245SigAudDataType g723type;
  46. H245SigNullDataType nulltype;
  47. H245SigG7231Cap g7231cap;
  48. g7231cap.SetMaxFrames(3);
  49. g7231cap.SetSilenceSupp(FALSE);
  50. g723type.Set(g7231cap);
  51. // Prepare the outgoing Logical channel proposal first.
  52. h225_mux_p = new H245SigH225Params;
  53. h225_mux_p->SetSessionID(PRI_SSID_AUDIO);
  54. h225_mux_p->SetDynamicRTPPayloadType(G7231_RTP_PAYLOAD_TYPE);
  55. h225_mux_p->SetSilenceSupp(FALSE);
  56. h225_mux_p->SetMediaCtrlChan((struct sockaddr *)&rtcp_addr);
  57. fwd_lcp_p = new H245SigForwardLCParams;
  58. fwd_lcp_p->SetDataType(g723type);
  59. fwd_lcp_p->SetPortNumber(0x1234);
  60. fwd_lcp_p->SetMuxParams(*h225_mux_p);
  61. olc_p = new H245SigOpenLogicalChannel;
  62. olc_p->SetForwardLCNumber(1);
  63. olc_p->SetForwardLCParams(*fwd_lcp_p);
  64. ret = setup_uuie->AddOLC(*olc_p);
  65. delete olc_p;
  66. delete fwd_lcp_p;
  67. delete h225_mux_p;
  68. if (!(PROT_IS_SUCCESS(ret)))
  69. {
  70. return -1;
  71. }
  72. // Prepare the incoming Logical channel proposal now.
  73. none_mux_p = new H245SigMuxNone;
  74. fwd_lcp_p = new H245SigForwardLCParams;
  75. fwd_lcp_p->SetDataType(nulltype);
  76. fwd_lcp_p->SetMuxParams(*none_mux_p);
  77. h225_mux_p = new H245SigH225Params;
  78. h225_mux_p->SetSessionID(PRI_SSID_AUDIO);
  79. h225_mux_p->SetDynamicRTPPayloadType(G7231_RTP_PAYLOAD_TYPE);
  80. h225_mux_p->SetSilenceSupp(FALSE);
  81. h225_mux_p->SetMediaChan((struct sockaddr *)&rtp_addr);
  82. h225_mux_p->SetMediaCtrlChan((struct sockaddr *)&rtcp_addr);
  83. rev_lcp_p = new H245SigReverseLCParams;
  84. rev_lcp_p->SetDataType(g723type);
  85. rev_lcp_p->SetMuxParams(*h225_mux_p);
  86. olc_p = new H245SigOpenLogicalChannel;
  87. olc_p->SetForwardLCNumber(2);
  88. olc_p->SetForwardLCParams(*fwd_lcp_p);
  89. olc_p->SetReverseLCParams(*rev_lcp_p);
  90. ret = setup_uuie->AddOLC(*olc_p);
  91. delete olc_p;
  92. delete fwd_lcp_p;
  93. delete rev_lcp_p;
  94. delete h225_mux_p;
  95. delete none_mux_p;
  96. if (!(PROT_IS_SUCCESS(ret)))
  97. {
  98. return -1;
  99. }
  100. return 0;
  101. }
  102. // Caveats: expects call->rtcp_addr/call->rtp_addr to be valid.
  103. int 
  104. H323Call::InitFastStartReply(H225CSSetupUUIE *setup_uuie)
  105. {
  106. // We wil do only G.723.
  107. ProtReturnCode ret;
  108. int num_replys = 0;
  109. int num_selected = 0;
  110. int i;
  111. setup_uuie->GetNumOLC(num_replys);
  112. if (num_replys <= 0)
  113. {
  114. return -1;
  115. }
  116. H245SigOpenLogicalChannel *olclist = 
  117. new H245SigOpenLogicalChannel[num_replys]; 
  118. ret = setup_uuie->GetOLC(olclist, num_replys);
  119. if (!PROT_IS_SUCCESS(ret))
  120. {
  121. delete [] olclist;
  122. return ret;
  123. }
  124. for(i = 0; i < num_replys && num_selected < 2; i++)
  125. {
  126. int type;
  127. H245SigForwardLCParams fwd_lcp;
  128. H245SigReverseLCParams rev_lcp;
  129. H245SigAudDataType data_type;
  130. ret = olclist[i].GetForwardLCParams(fwd_lcp);
  131. if (!(PROT_IS_SUCCESS(ret)))
  132. {
  133. delete [] olclist;
  134. return -1;
  135. }
  136. fwd_lcp.GetTypeOfDataType(type);
  137. if (type == DT_AUDIO)
  138. {
  139. int dtype, cap_type, cap_sub_type;
  140. fwd_lcp.GetDataType(data_type);
  141. data_type.GetType(dtype,cap_type,cap_sub_type);
  142. if (dtype == DT_AUDIO && cap_type == CAP_AUDIO && 
  143. cap_sub_type == AUD_G7231)
  144. {
  145. // Remote end is trying to open g7231 audio channel.
  146. // accept this. Copy the olc structure and fix the
  147. // h2250Logicalchannelparameters with our rtp/rtcp addresses.
  148. H245SigOpenLogicalChannel *olc_p;
  149. H245SigH225Params h225_mux;
  150. int dynamic_rtp_pt = 0;
  151. fs_channels[FS_CHANNEL_INCOMING] = olclist[i];
  152. olc_p = &fs_channels[FS_CHANNEL_INCOMING];
  153. // save the incoming lc number and dynamic rtp payload type.
  154. olc_p->GetForwardLCNumber(in_lc_num);
  155. fwd_lcp.GetMuxParams(h225_mux);
  156. h225_mux.GetDynamicRTPPayloadType(dynamic_rtp_pt);
  157. audio_session->SetRemotePayloadType(dynamic_rtp_pt);
  158. h225_mux.SetSessionID(PRI_SSID_AUDIO);
  159. h225_mux.SetSilenceSupp(FALSE);
  160. h225_mux.SetDynamicRTPPayloadType(G7231_RTP_PAYLOAD_TYPE);
  161. h225_mux.SetMediaChan((struct sockaddr *)&rtp_addr);
  162. h225_mux.SetMediaCtrlChan((struct sockaddr *)&rtcp_addr);
  163. fwd_lcp.SetMuxParams(h225_mux);
  164. olc_p->SetForwardLCParams(fwd_lcp);
  165. num_selected++;
  166. }
  167. }
  168. else if (type == DT_NULL)
  169. {
  170. ret = olclist[i].GetReverseLCParams(rev_lcp);
  171. rev_lcp.GetTypeOfDataType(type);
  172. if (type == DT_AUDIO)
  173. {
  174. int dtype, cap_type, cap_sub_type;
  175. rev_lcp.GetDataType(data_type);
  176. data_type.GetType(dtype,cap_type,cap_sub_type);
  177. if (dtype == DT_AUDIO && cap_type == CAP_AUDIO && 
  178. cap_sub_type == AUD_G7231)
  179. {
  180. H245SigOpenLogicalChannel *olc_p;
  181. H245SigH225Params h225_mux;
  182. struct sockaddr_in rrtp_addr;
  183. struct sockaddr_in rrtcp_addr;
  184. fs_channels[FS_CHANNEL_OUTGOING] = olclist[i];
  185. olc_p = &fs_channels[FS_CHANNEL_OUTGOING];
  186. out_lc_num = 1;
  187. olc_p->SetForwardLCNumber(out_lc_num);
  188. rev_lcp.GetMuxParams(h225_mux);
  189. // Save the remote ends rtp/rctp addresses.
  190. h225_mux.GetMediaChan((sockaddr*)&rrtp_addr);
  191. h225_mux.GetMediaCtrlChan((sockaddr*)&rrtcp_addr);
  192. assert(audio_session != NULL);
  193. audio_session->SetRemotePorts(rrtp_addr.sin_addr.s_addr,
  194. rrtp_addr.sin_port,rrtcp_addr.sin_port);
  195. // Fill our rtcp address.
  196. h225_mux.SetMediaCtrlChan((struct sockaddr *)&rtcp_addr);
  197. rev_lcp.SetMuxParams(h225_mux);
  198. olc_p->SetReverseLCParams(rev_lcp);
  199. num_selected++;
  200. }
  201. }
  202. }
  203. }
  204. if (num_selected != 2)
  205. {
  206. delete [] olclist;
  207. return -1;
  208. }
  209. delete [] olclist;
  210. return 0;
  211. }
  212. int 
  213. H323Call::InterpretFastStartReply(UUIEItemFastStartList *fs_list)
  214. {
  215. ProtReturnCode ret;
  216. int num_replys = 0;
  217. int i;
  218. assert(do_faststart != 0);
  219. assert(faststart_state == FAST_START_STATE_PENDING);
  220. fs_list->GetNumOLC(num_replys);
  221. if (num_replys <= 0)
  222. {
  223. return -1;
  224. }
  225. H245SigOpenLogicalChannel *olclist = 
  226. new H245SigOpenLogicalChannel[num_replys]; 
  227. ret = fs_list->GetOLC(olclist, num_replys);
  228. if (!PROT_IS_SUCCESS(ret))
  229. {
  230. delete [] olclist;
  231. return ret;
  232. }
  233. // Remember we advertized only two lc's in the outgoing 
  234. // side. So, we will not check to see if the remote side
  235. // chose G.723 or not, since that is our default.
  236. for(i = 0; i < num_replys ; i++)
  237. {
  238. H245SigForwardLCParams fwd_lcp;
  239. H245SigReverseLCParams rev_lcp;
  240. H245SigAudDataType data_type;
  241. ret = olclist[i].GetReverseLCParams(rev_lcp);
  242. if (!PROT_IS_SUCCESS(ret))
  243. {
  244. H245SigOpenLogicalChannel *olc_p;
  245. H245SigH225Params h225_mux;
  246. struct sockaddr_in rrtp_addr;
  247. struct sockaddr_in rrtcp_addr;
  248. // Reverse LC params not present...
  249. // This is the case where the lc is opened to the remote side.
  250. ret = olclist[i].GetForwardLCParams(fwd_lcp);
  251. if (!(PROT_IS_SUCCESS(ret)))
  252. {
  253. delete [] olclist;
  254. return -1;
  255. }
  256. fs_channels[FS_CHANNEL_OUTGOING] = olclist[i];
  257. olc_p = &fs_channels[FS_CHANNEL_OUTGOING];
  258. // Update the RTP/RTCP address of the remote side.
  259. // If more audio capabilities than just one was advertised
  260. // this would be a place to check for the datatype etc..
  261. ret = fwd_lcp.GetMuxParams(h225_mux);
  262. // Save the remote ends rtp/rctp addresses.
  263. h225_mux.GetMediaChan((sockaddr*)&rrtp_addr);
  264. h225_mux.GetMediaCtrlChan((sockaddr*)&rrtcp_addr);
  265. assert(audio_session != NULL);
  266. audio_session->SetRemotePorts(rrtp_addr.sin_addr.s_addr,
  267. rrtp_addr.sin_port,rrtcp_addr.sin_port);
  268. }
  269. else
  270. {
  271. H245SigOpenLogicalChannel *olc_p;
  272. fs_channels[FS_CHANNEL_INCOMING] = olclist[i];
  273. olc_p = &fs_channels[FS_CHANNEL_OUTGOING];
  274. olc_p->GetForwardLCNumber(in_lc_num);
  275. }
  276. }
  277. delete [] olclist;
  278. return 0;
  279. }