ooh323cDriver.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * Copyright (C) 2004-2005 by Objective Systems, Inc.
  3. *
  4. * This software is furnished under an open source license and may be
  5. * used and copied only in accordance with the terms of this license.
  6. * The text of the license may generally be found in the root
  7. * directory of this installation in the COPYING file. It
  8. * can also be viewed online at the following URL:
  9. *
  10. * http://www.obj-sys.com/open/license.html
  11. *
  12. * Any redistributions of this file including modified versions must
  13. * maintain this copyright notice.
  14. *
  15. *****************************************************************************/
  16. #include "ooh323cDriver.h"
  17. #include "asterisk.h"
  18. #include "asterisk/lock.h"
  19. #include "asterisk/pbx.h"
  20. #include "asterisk/logger.h"
  21. #undef AST_BACKGROUND_STACKSIZE
  22. #define AST_BACKGROUND_STACKSIZE 768 * 1024
  23. #define SEC_TO_HOLD_THREAD 24
  24. extern struct ast_module *myself;
  25. extern OOBOOL gH323Debug;
  26. extern OOH323EndPoint gH323ep;
  27. /* ooh323c stack thread. */
  28. static pthread_t ooh323c_thread = AST_PTHREADT_NULL;
  29. static pthread_t ooh323cmd_thread = AST_PTHREADT_NULL;
  30. static int grxframes = 240;
  31. static int gtxframes = 20;
  32. static struct callthread {
  33. ast_mutex_t lock;
  34. int thePipe[2];
  35. OOBOOL inUse;
  36. ooCallData* call;
  37. struct callthread *next, *prev;
  38. } *callThreads = NULL;
  39. AST_MUTEX_DEFINE_STATIC(callThreadsLock);
  40. int ooh323c_start_receive_channel(ooCallData *call, ooLogicalChannel *pChannel);
  41. int ooh323c_start_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel);
  42. int ooh323c_stop_receive_channel(ooCallData *call, ooLogicalChannel *pChannel);
  43. int ooh323c_stop_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel);
  44. int ooh323c_start_receive_datachannel(ooCallData *call, ooLogicalChannel *pChannel);
  45. int ooh323c_start_transmit_datachannel(ooCallData *call, ooLogicalChannel *pChannel);
  46. int ooh323c_stop_receive_datachannel(ooCallData *call, ooLogicalChannel *pChannel);
  47. int ooh323c_stop_transmit_datachannel(ooCallData *call, ooLogicalChannel *pChannel);
  48. void* ooh323c_stack_thread(void* dummy);
  49. void* ooh323c_cmd_thread(void* dummy);
  50. void* ooh323c_call_thread(void* dummy);
  51. int ooh323c_set_aliases(ooAliases * aliases);
  52. void* ooh323c_stack_thread(void* dummy)
  53. {
  54. ooMonitorChannels();
  55. return dummy;
  56. }
  57. void* ooh323c_cmd_thread(void* dummy)
  58. {
  59. ooMonitorCmdChannels();
  60. return dummy;
  61. }
  62. void* ooh323c_call_thread(void* dummy)
  63. {
  64. struct callthread* mycthread = (struct callthread *)dummy;
  65. struct pollfd pfds[1];
  66. char c;
  67. int res;
  68. do {
  69. ooMonitorCallChannels((ooCallData*)mycthread->call);
  70. mycthread->call = NULL;
  71. mycthread->prev = NULL;
  72. mycthread->inUse = FALSE;
  73. ast_mutex_lock(&callThreadsLock);
  74. mycthread->next = callThreads;
  75. callThreads = mycthread;
  76. if (mycthread->next) mycthread->next->prev = mycthread;
  77. ast_mutex_unlock(&callThreadsLock);
  78. pfds[0].fd = mycthread->thePipe[0];
  79. pfds[0].events = POLLIN;
  80. ooSocketPoll(pfds, 1, SEC_TO_HOLD_THREAD * 1000);
  81. if (ooPDRead(pfds, 1, mycthread->thePipe[0]))
  82. res = read(mycthread->thePipe[0], &c, 1);
  83. ast_mutex_lock(&callThreadsLock);
  84. ast_mutex_lock(&mycthread->lock);
  85. if (mycthread->prev)
  86. mycthread->prev->next = mycthread->next;
  87. else
  88. callThreads = mycthread->next;
  89. if (mycthread->next)
  90. mycthread->next->prev = mycthread->prev;
  91. ast_mutex_unlock(&mycthread->lock);
  92. ast_mutex_unlock(&callThreadsLock);
  93. } while (mycthread->call != NULL);
  94. ast_mutex_destroy(&mycthread->lock);
  95. close(mycthread->thePipe[0]);
  96. close(mycthread->thePipe[1]);
  97. free(mycthread);
  98. ast_module_unref(myself);
  99. ast_update_use_count();
  100. return dummy;
  101. }
  102. int ooh323c_start_call_thread(ooCallData *call) {
  103. char c = 'c';
  104. int res;
  105. struct callthread *cur = callThreads;
  106. ast_mutex_lock(&callThreadsLock);
  107. while (cur != NULL && (cur->inUse || ast_mutex_trylock(&cur->lock))) {
  108. cur = cur->next;
  109. }
  110. ast_mutex_unlock(&callThreadsLock);
  111. if (cur != NULL && cur->inUse) {
  112. ast_mutex_unlock(&cur->lock);
  113. cur = NULL;
  114. }
  115. /* make new thread */
  116. if (cur == NULL) {
  117. if (!(cur = ast_malloc(sizeof(struct callthread)))) {
  118. ast_log(LOG_ERROR, "Unable to allocate thread structure for call %s\n",
  119. call->callToken);
  120. return -1;
  121. }
  122. ast_module_ref(myself);
  123. memset(cur, 0, sizeof(cur));
  124. if ((socketpair(PF_LOCAL, SOCK_STREAM, 0, cur->thePipe)) == -1) {
  125. ast_log(LOG_ERROR, "Can't create thread pipe for call %s\n", call->callToken);
  126. free(cur);
  127. return -1;
  128. }
  129. cur->inUse = TRUE;
  130. cur->call = call;
  131. ast_mutex_init(&cur->lock);
  132. if (gH323Debug)
  133. ast_debug(1,"new call thread created for call %s\n", call->callToken);
  134. if(ast_pthread_create_detached_background(&call->callThread, NULL, ooh323c_call_thread, cur) < 0)
  135. {
  136. ast_log(LOG_ERROR, "Unable to start ooh323c call thread for call %s\n",
  137. call->callToken);
  138. ast_mutex_destroy(&cur->lock);
  139. close(cur->thePipe[0]);
  140. close(cur->thePipe[1]);
  141. free(cur);
  142. return -1;
  143. }
  144. } else {
  145. if (gH323Debug)
  146. ast_debug(1,"using existing call thread for call %s\n", call->callToken);
  147. cur->inUse = TRUE;
  148. cur->call = call;
  149. res = write(cur->thePipe[1], &c, 1);
  150. ast_mutex_unlock(&cur->lock);
  151. }
  152. return 0;
  153. }
  154. int ooh323c_stop_call_thread(ooCallData *call) {
  155. if (call->callThread != AST_PTHREADT_NULL) {
  156. ooStopMonitorCallChannels(call);
  157. }
  158. return 0;
  159. }
  160. int ooh323c_start_stack_thread()
  161. {
  162. if(ast_pthread_create_background(&ooh323c_thread, NULL, ooh323c_stack_thread, NULL) < 0)
  163. {
  164. ast_log(LOG_ERROR, "Unable to start ooh323c thread.\n");
  165. return -1;
  166. }
  167. if(ast_pthread_create_background(&ooh323cmd_thread, NULL, ooh323c_cmd_thread, NULL) < 0)
  168. {
  169. ast_log(LOG_ERROR, "Unable to start ooh323cmd thread.\n");
  170. return -1;
  171. }
  172. return 0;
  173. }
  174. int ooh323c_stop_stack_thread(void)
  175. {
  176. if(ooh323c_thread != AST_PTHREADT_NULL)
  177. {
  178. ooStopMonitor();
  179. pthread_join(ooh323c_thread, NULL);
  180. ooh323c_thread = AST_PTHREADT_NULL;
  181. pthread_join(ooh323cmd_thread, NULL);
  182. ooh323cmd_thread = AST_PTHREADT_NULL;
  183. }
  184. return 0;
  185. }
  186. int ooh323c_set_capability
  187. (struct ast_codec_pref *prefs, int capability, int dtmf, int dtmfcodec)
  188. {
  189. int ret = 0, x, format=0;
  190. if(gH323Debug)
  191. ast_verbose("\tAdding capabilities to H323 endpoint\n");
  192. for(x=0; 0 != (format=ast_codec_pref_index(prefs, x)); x++)
  193. {
  194. if(format & AST_FORMAT_ULAW)
  195. {
  196. if(gH323Debug)
  197. ast_verbose("\tAdding g711 ulaw capability to H323 endpoint\n");
  198. ret= ooH323EpAddG711Capability(OO_G711ULAW64K, gtxframes, grxframes,
  199. OORXANDTX, &ooh323c_start_receive_channel,
  200. &ooh323c_start_transmit_channel,
  201. &ooh323c_stop_receive_channel,
  202. &ooh323c_stop_transmit_channel);
  203. }
  204. if(format & AST_FORMAT_ALAW)
  205. {
  206. if(gH323Debug)
  207. ast_verbose("\tAdding g711 alaw capability to H323 endpoint\n");
  208. ret= ooH323EpAddG711Capability(OO_G711ALAW64K, gtxframes, grxframes,
  209. OORXANDTX, &ooh323c_start_receive_channel,
  210. &ooh323c_start_transmit_channel,
  211. &ooh323c_stop_receive_channel,
  212. &ooh323c_stop_transmit_channel);
  213. }
  214. if(format & AST_FORMAT_G729A)
  215. {
  216. if(gH323Debug)
  217. ast_verbose("\tAdding g729A capability to H323 endpoint\n");
  218. ret = ooH323EpAddG729Capability(OO_G729A, 2, 24,
  219. OORXANDTX, &ooh323c_start_receive_channel,
  220. &ooh323c_start_transmit_channel,
  221. &ooh323c_stop_receive_channel,
  222. &ooh323c_stop_transmit_channel);
  223. if(gH323Debug)
  224. ast_verbose("\tAdding g729 capability to H323 endpoint\n");
  225. ret |= ooH323EpAddG729Capability(OO_G729, 2, 24,
  226. OORXANDTX, &ooh323c_start_receive_channel,
  227. &ooh323c_start_transmit_channel,
  228. &ooh323c_stop_receive_channel,
  229. &ooh323c_stop_transmit_channel);
  230. if(gH323Debug)
  231. ast_verbose("\tAdding g729b capability to H323 endpoint\n");
  232. ret |= ooH323EpAddG729Capability(OO_G729B, 2, 24,
  233. OORXANDTX, &ooh323c_start_receive_channel,
  234. &ooh323c_start_transmit_channel,
  235. &ooh323c_stop_receive_channel,
  236. &ooh323c_stop_transmit_channel);
  237. }
  238. if(format & AST_FORMAT_G723_1)
  239. {
  240. if(gH323Debug)
  241. ast_verbose("\tAdding g7231 capability to H323 endpoint\n");
  242. ret = ooH323EpAddG7231Capability(OO_G7231, 1, 1, FALSE,
  243. OORXANDTX, &ooh323c_start_receive_channel,
  244. &ooh323c_start_transmit_channel,
  245. &ooh323c_stop_receive_channel,
  246. &ooh323c_stop_transmit_channel);
  247. }
  248. if(format & AST_FORMAT_G726)
  249. {
  250. if(gH323Debug)
  251. ast_verbose("\tAdding g726 capability to H323 endpoint\n");
  252. ret = ooH323EpAddG726Capability(OO_G726, gtxframes, grxframes, FALSE,
  253. OORXANDTX, &ooh323c_start_receive_channel,
  254. &ooh323c_start_transmit_channel,
  255. &ooh323c_stop_receive_channel,
  256. &ooh323c_stop_transmit_channel);
  257. }
  258. if(format & AST_FORMAT_G726_AAL2)
  259. {
  260. if(gH323Debug)
  261. ast_verbose("\tAdding g726aal2 capability to H323 endpoint\n");
  262. ret = ooH323EpAddG726Capability(OO_G726AAL2, gtxframes, grxframes, FALSE,
  263. OORXANDTX, &ooh323c_start_receive_channel,
  264. &ooh323c_start_transmit_channel,
  265. &ooh323c_stop_receive_channel,
  266. &ooh323c_stop_transmit_channel);
  267. }
  268. if(format & AST_FORMAT_H263)
  269. {
  270. if(gH323Debug)
  271. ast_verbose("\tAdding h263 capability to H323 endpoint\n");
  272. ret = ooH323EpAddH263VideoCapability(OO_H263VIDEO, 1, 0, 0, 0, 0, 320*1024,
  273. OORXANDTX, &ooh323c_start_receive_channel,
  274. &ooh323c_start_transmit_channel,
  275. &ooh323c_stop_receive_channel,
  276. &ooh323c_stop_transmit_channel);
  277. }
  278. if(format & AST_FORMAT_GSM)
  279. {
  280. if(gH323Debug)
  281. ast_verbose("\tAdding gsm capability to H323 endpoint\n");
  282. ret = ooH323EpAddGSMCapability(OO_GSMFULLRATE, 4, FALSE, FALSE,
  283. OORXANDTX, &ooh323c_start_receive_channel,
  284. &ooh323c_start_transmit_channel,
  285. &ooh323c_stop_receive_channel,
  286. &ooh323c_stop_transmit_channel);
  287. }
  288. #ifdef AST_FORMAT_AMRNB
  289. if(format & AST_FORMAT_AMRNB)
  290. {
  291. if(gH323Debug)
  292. ast_verbose("\tAdding amr nb capability to H323 endpoint\n");
  293. ret = ooH323EpAddAMRNBCapability(OO_AMRNB, 4, 4, FALSE,
  294. OORXANDTX, &ooh323c_start_receive_channel,
  295. &ooh323c_start_transmit_channel,
  296. &ooh323c_stop_receive_channel,
  297. &ooh323c_stop_transmit_channel);
  298. }
  299. #endif
  300. #ifdef AST_FORMAT_SPEEX
  301. if(format & AST_FORMAT_SPEEX)
  302. {
  303. if(gH323Debug)
  304. ast_verbose("\tAdding speex capability to H323 endpoint\n");
  305. ret = ooH323EpAddSpeexCapability(OO_SPEEX, 4, 4, FALSE,
  306. OORXANDTX, &ooh323c_start_receive_channel,
  307. &ooh323c_start_transmit_channel,
  308. &ooh323c_stop_receive_channel,
  309. &ooh323c_stop_transmit_channel);
  310. }
  311. #endif
  312. }
  313. if(dtmf & H323_DTMF_CISCO)
  314. ret |= ooH323EpEnableDTMFCISCO(0);
  315. if(dtmf & H323_DTMF_RFC2833)
  316. ret |= ooH323EpEnableDTMFRFC2833(0);
  317. else if(dtmf & H323_DTMF_H245ALPHANUMERIC)
  318. ret |= ooH323EpEnableDTMFH245Alphanumeric();
  319. else if(dtmf & H323_DTMF_H245SIGNAL)
  320. ret |= ooH323EpEnableDTMFH245Signal();
  321. return ret;
  322. }
  323. int ooh323c_set_capability_for_call
  324. (ooCallData *call, struct ast_codec_pref *prefs, int capability, int dtmf, int dtmfcodec,
  325. int t38support, int g729onlyA)
  326. {
  327. int ret = 0, x, txframes;
  328. int format=0;
  329. if(gH323Debug)
  330. ast_verbose("\tAdding capabilities to call(%s, %s)\n", call->callType,
  331. call->callToken);
  332. if(dtmf & H323_DTMF_CISCO || 1)
  333. ret |= ooCallEnableDTMFCISCO(call,dtmfcodec);
  334. if(dtmf & H323_DTMF_RFC2833 || 1)
  335. ret |= ooCallEnableDTMFRFC2833(call,dtmfcodec);
  336. if(dtmf & H323_DTMF_H245ALPHANUMERIC || 1)
  337. ret |= ooCallEnableDTMFH245Alphanumeric(call);
  338. if(dtmf & H323_DTMF_H245SIGNAL || 1)
  339. ret |= ooCallEnableDTMFH245Signal(call);
  340. if (t38support)
  341. ooCapabilityAddT38Capability(call, OO_T38, OORXANDTX,
  342. &ooh323c_start_receive_datachannel,
  343. &ooh323c_start_transmit_datachannel,
  344. &ooh323c_stop_receive_datachannel,
  345. &ooh323c_stop_transmit_datachannel,
  346. 0);
  347. for(x=0; 0 !=(format=ast_codec_pref_index(prefs, x)); x++)
  348. {
  349. if(format & AST_FORMAT_ULAW)
  350. {
  351. if(gH323Debug)
  352. ast_verbose("\tAdding g711 ulaw capability to call(%s, %s)\n",
  353. call->callType, call->callToken);
  354. txframes = prefs->framing[x];
  355. ret= ooCallAddG711Capability(call, OO_G711ULAW64K, txframes,
  356. txframes, OORXANDTX,
  357. &ooh323c_start_receive_channel,
  358. &ooh323c_start_transmit_channel,
  359. &ooh323c_stop_receive_channel,
  360. &ooh323c_stop_transmit_channel);
  361. }
  362. if(format & AST_FORMAT_ALAW)
  363. {
  364. if(gH323Debug)
  365. ast_verbose("\tAdding g711 alaw capability to call(%s, %s)\n",
  366. call->callType, call->callToken);
  367. txframes = prefs->framing[x];
  368. ret= ooCallAddG711Capability(call, OO_G711ALAW64K, txframes,
  369. txframes, OORXANDTX,
  370. &ooh323c_start_receive_channel,
  371. &ooh323c_start_transmit_channel,
  372. &ooh323c_stop_receive_channel,
  373. &ooh323c_stop_transmit_channel);
  374. }
  375. if(format & AST_FORMAT_G726)
  376. {
  377. if(gH323Debug)
  378. ast_verbose("\tAdding g726 capability to call (%s, %s)\n",
  379. call->callType, call->callToken);
  380. txframes = prefs->framing[x];
  381. ret = ooCallAddG726Capability(call, OO_G726, txframes, grxframes, FALSE,
  382. OORXANDTX, &ooh323c_start_receive_channel,
  383. &ooh323c_start_transmit_channel,
  384. &ooh323c_stop_receive_channel,
  385. &ooh323c_stop_transmit_channel);
  386. }
  387. if(format & AST_FORMAT_G726_AAL2)
  388. {
  389. if(gH323Debug)
  390. ast_verbose("\tAdding g726aal2 capability to call (%s, %s)\n",
  391. call->callType, call->callToken);
  392. txframes = prefs->framing[x];
  393. ret = ooCallAddG726Capability(call, OO_G726AAL2, txframes, grxframes, FALSE,
  394. OORXANDTX, &ooh323c_start_receive_channel,
  395. &ooh323c_start_transmit_channel,
  396. &ooh323c_stop_receive_channel,
  397. &ooh323c_stop_transmit_channel);
  398. }
  399. if(format & AST_FORMAT_G729A)
  400. {
  401. txframes = (prefs->framing[x])/10;
  402. if(gH323Debug)
  403. ast_verbose("\tAdding g729A capability to call(%s, %s)\n",
  404. call->callType, call->callToken);
  405. ret= ooCallAddG729Capability(call, OO_G729A, txframes, txframes,
  406. OORXANDTX, &ooh323c_start_receive_channel,
  407. &ooh323c_start_transmit_channel,
  408. &ooh323c_stop_receive_channel,
  409. &ooh323c_stop_transmit_channel);
  410. if (g729onlyA)
  411. continue;
  412. if(gH323Debug)
  413. ast_verbose("\tAdding g729 capability to call(%s, %s)\n",
  414. call->callType, call->callToken);
  415. ret|= ooCallAddG729Capability(call, OO_G729, txframes, txframes,
  416. OORXANDTX, &ooh323c_start_receive_channel,
  417. &ooh323c_start_transmit_channel,
  418. &ooh323c_stop_receive_channel,
  419. &ooh323c_stop_transmit_channel);
  420. if(gH323Debug)
  421. ast_verbose("\tAdding g729B capability to call(%s, %s)\n",
  422. call->callType, call->callToken);
  423. ret|= ooCallAddG729Capability(call, OO_G729B, txframes, txframes,
  424. OORXANDTX, &ooh323c_start_receive_channel,
  425. &ooh323c_start_transmit_channel,
  426. &ooh323c_stop_receive_channel,
  427. &ooh323c_stop_transmit_channel);
  428. }
  429. if(format & AST_FORMAT_G723_1)
  430. {
  431. if(gH323Debug)
  432. ast_verbose("\tAdding g7231 capability to call (%s, %s)\n",
  433. call->callType, call->callToken);
  434. ret = ooCallAddG7231Capability(call, OO_G7231, 1, 1, FALSE,
  435. OORXANDTX, &ooh323c_start_receive_channel,
  436. &ooh323c_start_transmit_channel,
  437. &ooh323c_stop_receive_channel,
  438. &ooh323c_stop_transmit_channel);
  439. }
  440. if(format & AST_FORMAT_H263)
  441. {
  442. if(gH323Debug)
  443. ast_verbose("\tAdding h263 capability to call (%s, %s)\n",
  444. call->callType, call->callToken);
  445. ret = ooCallAddH263VideoCapability(call, OO_H263VIDEO, 1, 0, 0, 0, 0, 320*1024,
  446. OORXANDTX, &ooh323c_start_receive_channel,
  447. &ooh323c_start_transmit_channel,
  448. &ooh323c_stop_receive_channel,
  449. &ooh323c_stop_transmit_channel);
  450. }
  451. if(format & AST_FORMAT_GSM)
  452. {
  453. if(gH323Debug)
  454. ast_verbose("\tAdding gsm capability to call(%s, %s)\n",
  455. call->callType, call->callToken);
  456. ret = ooCallAddGSMCapability(call, OO_GSMFULLRATE, 4, FALSE, FALSE,
  457. OORXANDTX, &ooh323c_start_receive_channel,
  458. &ooh323c_start_transmit_channel,
  459. &ooh323c_stop_receive_channel,
  460. &ooh323c_stop_transmit_channel);
  461. }
  462. #ifdef AST_FORMAT_AMRNB
  463. if(format & AST_FORMAT_AMRNB)
  464. {
  465. if(gH323Debug)
  466. ast_verbose("\tAdding AMR capability to call(%s, %s)\n",
  467. call->callType, call->callToken);
  468. ret = ooCallAddAMRNBCapability(call, OO_AMRNB, 4, 4, FALSE,
  469. OORXANDTX, &ooh323c_start_receive_channel,
  470. &ooh323c_start_transmit_channel,
  471. &ooh323c_stop_receive_channel,
  472. &ooh323c_stop_transmit_channel);
  473. }
  474. #endif
  475. #ifdef AST_FORMAT_SPEEX
  476. if(format & AST_FORMAT_SPEEX)
  477. {
  478. if(gH323Debug)
  479. ast_verbose("\tAdding Speex capability to call(%s, %s)\n",
  480. call->callType, call->callToken);
  481. ret = ooCallAddSpeexCapability(call, OO_SPEEX, 4, 4, FALSE,
  482. OORXANDTX, &ooh323c_start_receive_channel,
  483. &ooh323c_start_transmit_channel,
  484. &ooh323c_stop_receive_channel,
  485. &ooh323c_stop_transmit_channel);
  486. }
  487. #endif
  488. }
  489. return ret;
  490. }
  491. int ooh323c_set_aliases(ooAliases * aliases)
  492. {
  493. ooAliases *cur = aliases;
  494. while(cur)
  495. {
  496. switch(cur->type)
  497. {
  498. case T_H225AliasAddress_dialedDigits:
  499. ooH323EpAddAliasDialedDigits(cur->value);
  500. break;
  501. case T_H225AliasAddress_h323_ID:
  502. ooH323EpAddAliasH323ID(cur->value);
  503. break;
  504. case T_H225AliasAddress_url_ID:
  505. ooH323EpAddAliasURLID(cur->value);
  506. break;
  507. case T_H225AliasAddress_email_ID:
  508. ooH323EpAddAliasEmailID(cur->value);
  509. break;
  510. default:
  511. ast_debug(1, "Ignoring unknown alias type\n");
  512. }
  513. cur = cur->next;
  514. }
  515. return 1;
  516. }
  517. int ooh323c_start_receive_channel(ooCallData *call, ooLogicalChannel *pChannel)
  518. {
  519. format_t fmt=-1;
  520. fmt = convertH323CapToAsteriskCap(pChannel->chanCap->cap);
  521. if(fmt>0) {
  522. /* ooh323_set_read_format(call, fmt); */
  523. }else{
  524. ast_log(LOG_ERROR, "Invalid capability type for receive channel %s\n",
  525. call->callToken);
  526. return -1;
  527. }
  528. return 1;
  529. }
  530. int ooh323c_start_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel)
  531. {
  532. format_t fmt;
  533. fmt = convertH323CapToAsteriskCap(pChannel->chanCap->cap);
  534. if(fmt>0) {
  535. switch (fmt) {
  536. case AST_FORMAT_ALAW:
  537. case AST_FORMAT_ULAW:
  538. ooh323_set_write_format(call, fmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes);
  539. break;
  540. case AST_FORMAT_G729A:
  541. ooh323_set_write_format(call, fmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes*10);
  542. break;
  543. default:
  544. ooh323_set_write_format(call, fmt, 0);
  545. }
  546. }else{
  547. ast_log(LOG_ERROR, "Invalid capability type for receive channel %s\n",
  548. call->callToken);
  549. return -1;
  550. }
  551. setup_rtp_connection(call, pChannel->remoteIP, pChannel->remoteMediaPort);
  552. return 1;
  553. }
  554. int ooh323c_stop_receive_channel(ooCallData *call, ooLogicalChannel *pChannel)
  555. {
  556. return 1;
  557. }
  558. int ooh323c_stop_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel)
  559. {
  560. close_rtp_connection(call);
  561. return 1;
  562. }
  563. int ooh323c_start_receive_datachannel(ooCallData *call, ooLogicalChannel *pChannel)
  564. {
  565. return 1;
  566. }
  567. int ooh323c_start_transmit_datachannel(ooCallData *call, ooLogicalChannel *pChannel)
  568. {
  569. setup_udptl_connection(call, pChannel->remoteIP, pChannel->remoteMediaPort);
  570. return 1;
  571. }
  572. int ooh323c_stop_receive_datachannel(ooCallData *call, ooLogicalChannel *pChannel)
  573. {
  574. return 1;
  575. }
  576. int ooh323c_stop_transmit_datachannel(ooCallData *call, ooLogicalChannel *pChannel)
  577. {
  578. close_udptl_connection(call);
  579. return 1;
  580. }
  581. format_t convertH323CapToAsteriskCap(int cap)
  582. {
  583. switch(cap)
  584. {
  585. case OO_G711ULAW64K:
  586. return AST_FORMAT_ULAW;
  587. case OO_G711ALAW64K:
  588. return AST_FORMAT_ALAW;
  589. case OO_GSMFULLRATE:
  590. return AST_FORMAT_GSM;
  591. #ifdef AST_FORMAT_AMRNB
  592. case OO_AMRNB:
  593. return AST_FORMAT_AMRNB;
  594. #endif
  595. #ifdef AST_FORMAT_SPEEX
  596. case OO_SPEEX:
  597. return AST_FORMAT_SPEEX;
  598. #endif
  599. case OO_G729:
  600. return AST_FORMAT_G729A;
  601. case OO_G729A:
  602. return AST_FORMAT_G729A;
  603. case OO_G729B:
  604. return AST_FORMAT_G729A;
  605. case OO_G7231:
  606. return AST_FORMAT_G723_1;
  607. case OO_G726:
  608. return AST_FORMAT_G726;
  609. case OO_G726AAL2:
  610. return AST_FORMAT_G726_AAL2;
  611. case OO_H263VIDEO:
  612. return AST_FORMAT_H263;
  613. default:
  614. ast_debug(1, "Cap %d is not supported by driver yet\n", cap);
  615. return -1;
  616. }
  617. return -1;
  618. }