ooh323cDriver.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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_calloc(1, 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, struct ast_format_cap *cap, int dtmf, int dtmfcodec)
  188. {
  189. int ret = 0, x;
  190. struct ast_format tmpfmt;
  191. if(gH323Debug)
  192. ast_verbose("\tAdding capabilities to H323 endpoint\n");
  193. for(x=0; ast_codec_pref_index(prefs, x, &tmpfmt); x++)
  194. {
  195. if(tmpfmt.id == AST_FORMAT_ULAW)
  196. {
  197. if(gH323Debug)
  198. ast_verbose("\tAdding g711 ulaw capability to H323 endpoint\n");
  199. ret= ooH323EpAddG711Capability(OO_G711ULAW64K, gtxframes, grxframes,
  200. OORXANDTX, &ooh323c_start_receive_channel,
  201. &ooh323c_start_transmit_channel,
  202. &ooh323c_stop_receive_channel,
  203. &ooh323c_stop_transmit_channel);
  204. }
  205. if(tmpfmt.id == AST_FORMAT_ALAW)
  206. {
  207. if(gH323Debug)
  208. ast_verbose("\tAdding g711 alaw capability to H323 endpoint\n");
  209. ret= ooH323EpAddG711Capability(OO_G711ALAW64K, gtxframes, grxframes,
  210. OORXANDTX, &ooh323c_start_receive_channel,
  211. &ooh323c_start_transmit_channel,
  212. &ooh323c_stop_receive_channel,
  213. &ooh323c_stop_transmit_channel);
  214. }
  215. if(tmpfmt.id == AST_FORMAT_G729A)
  216. {
  217. if(gH323Debug)
  218. ast_verbose("\tAdding g729A capability to H323 endpoint\n");
  219. ret = ooH323EpAddG729Capability(OO_G729A, 2, 24,
  220. OORXANDTX, &ooh323c_start_receive_channel,
  221. &ooh323c_start_transmit_channel,
  222. &ooh323c_stop_receive_channel,
  223. &ooh323c_stop_transmit_channel);
  224. if(gH323Debug)
  225. ast_verbose("\tAdding g729 capability to H323 endpoint\n");
  226. ret |= ooH323EpAddG729Capability(OO_G729, 2, 24,
  227. OORXANDTX, &ooh323c_start_receive_channel,
  228. &ooh323c_start_transmit_channel,
  229. &ooh323c_stop_receive_channel,
  230. &ooh323c_stop_transmit_channel);
  231. if(gH323Debug)
  232. ast_verbose("\tAdding g729b capability to H323 endpoint\n");
  233. ret |= ooH323EpAddG729Capability(OO_G729B, 2, 24,
  234. OORXANDTX, &ooh323c_start_receive_channel,
  235. &ooh323c_start_transmit_channel,
  236. &ooh323c_stop_receive_channel,
  237. &ooh323c_stop_transmit_channel);
  238. }
  239. if(tmpfmt.id == AST_FORMAT_G723_1)
  240. {
  241. if(gH323Debug)
  242. ast_verbose("\tAdding g7231 capability to H323 endpoint\n");
  243. ret = ooH323EpAddG7231Capability(OO_G7231, 1, 1, FALSE,
  244. OORXANDTX, &ooh323c_start_receive_channel,
  245. &ooh323c_start_transmit_channel,
  246. &ooh323c_stop_receive_channel,
  247. &ooh323c_stop_transmit_channel);
  248. }
  249. if(tmpfmt.id == AST_FORMAT_G726)
  250. {
  251. if(gH323Debug)
  252. ast_verbose("\tAdding g726 capability to H323 endpoint\n");
  253. ret = ooH323EpAddG726Capability(OO_G726, gtxframes, grxframes, FALSE,
  254. OORXANDTX, &ooh323c_start_receive_channel,
  255. &ooh323c_start_transmit_channel,
  256. &ooh323c_stop_receive_channel,
  257. &ooh323c_stop_transmit_channel);
  258. }
  259. if(tmpfmt.id == AST_FORMAT_G726_AAL2)
  260. {
  261. if(gH323Debug)
  262. ast_verbose("\tAdding g726aal2 capability to H323 endpoint\n");
  263. ret = ooH323EpAddG726Capability(OO_G726AAL2, gtxframes, grxframes, FALSE,
  264. OORXANDTX, &ooh323c_start_receive_channel,
  265. &ooh323c_start_transmit_channel,
  266. &ooh323c_stop_receive_channel,
  267. &ooh323c_stop_transmit_channel);
  268. }
  269. if(tmpfmt.id == AST_FORMAT_H263)
  270. {
  271. if(gH323Debug)
  272. ast_verbose("\tAdding h263 capability to H323 endpoint\n");
  273. ret = ooH323EpAddH263VideoCapability(OO_H263VIDEO, 1, 0, 0, 0, 0, 320*1024,
  274. OORXANDTX, &ooh323c_start_receive_channel,
  275. &ooh323c_start_transmit_channel,
  276. &ooh323c_stop_receive_channel,
  277. &ooh323c_stop_transmit_channel);
  278. }
  279. if(tmpfmt.id == AST_FORMAT_GSM)
  280. {
  281. if(gH323Debug)
  282. ast_verbose("\tAdding gsm capability to H323 endpoint\n");
  283. ret = ooH323EpAddGSMCapability(OO_GSMFULLRATE, 4, FALSE, FALSE,
  284. OORXANDTX, &ooh323c_start_receive_channel,
  285. &ooh323c_start_transmit_channel,
  286. &ooh323c_stop_receive_channel,
  287. &ooh323c_stop_transmit_channel);
  288. }
  289. #ifdef AST_FORMAT_AMRNB
  290. if(tmpfmt.id == AST_FORMAT_AMRNB)
  291. {
  292. if(gH323Debug)
  293. ast_verbose("\tAdding amr nb capability to H323 endpoint\n");
  294. ret = ooH323EpAddAMRNBCapability(OO_AMRNB, 4, 4, FALSE,
  295. OORXANDTX, &ooh323c_start_receive_channel,
  296. &ooh323c_start_transmit_channel,
  297. &ooh323c_stop_receive_channel,
  298. &ooh323c_stop_transmit_channel);
  299. }
  300. #endif
  301. #ifdef AST_FORMAT_SPEEX
  302. if(tmpfmt.id == AST_FORMAT_SPEEX)
  303. {
  304. if(gH323Debug)
  305. ast_verbose("\tAdding speex capability to H323 endpoint\n");
  306. ret = ooH323EpAddSpeexCapability(OO_SPEEX, 4, 4, FALSE,
  307. OORXANDTX, &ooh323c_start_receive_channel,
  308. &ooh323c_start_transmit_channel,
  309. &ooh323c_stop_receive_channel,
  310. &ooh323c_stop_transmit_channel);
  311. }
  312. #endif
  313. }
  314. if(dtmf & H323_DTMF_CISCO)
  315. ret |= ooH323EpEnableDTMFCISCO(0);
  316. if(dtmf & H323_DTMF_RFC2833)
  317. ret |= ooH323EpEnableDTMFRFC2833(0);
  318. else if(dtmf & H323_DTMF_H245ALPHANUMERIC)
  319. ret |= ooH323EpEnableDTMFH245Alphanumeric();
  320. else if(dtmf & H323_DTMF_H245SIGNAL)
  321. ret |= ooH323EpEnableDTMFH245Signal();
  322. return ret;
  323. }
  324. int ooh323c_set_capability_for_call
  325. (ooCallData *call, struct ast_codec_pref *prefs, struct ast_format_cap *cap, int dtmf, int dtmfcodec,
  326. int t38support, int g729onlyA)
  327. {
  328. int ret = 0, x, txframes;
  329. struct ast_format tmpfmt;
  330. if(gH323Debug)
  331. ast_verbose("\tAdding capabilities to call(%s, %s)\n", call->callType,
  332. call->callToken);
  333. if(dtmf & H323_DTMF_CISCO || 1)
  334. ret |= ooCallEnableDTMFCISCO(call,dtmfcodec);
  335. if(dtmf & H323_DTMF_RFC2833 || 1)
  336. ret |= ooCallEnableDTMFRFC2833(call,dtmfcodec);
  337. if(dtmf & H323_DTMF_H245ALPHANUMERIC || 1)
  338. ret |= ooCallEnableDTMFH245Alphanumeric(call);
  339. if(dtmf & H323_DTMF_H245SIGNAL || 1)
  340. ret |= ooCallEnableDTMFH245Signal(call);
  341. if (t38support)
  342. ooCapabilityAddT38Capability(call, OO_T38, OORXANDTX,
  343. &ooh323c_start_receive_datachannel,
  344. &ooh323c_start_transmit_datachannel,
  345. &ooh323c_stop_receive_datachannel,
  346. &ooh323c_stop_transmit_datachannel,
  347. 0);
  348. for(x=0; ast_codec_pref_index(prefs, x, &tmpfmt); x++)
  349. {
  350. if(tmpfmt.id == AST_FORMAT_ULAW)
  351. {
  352. if(gH323Debug)
  353. ast_verbose("\tAdding g711 ulaw capability to call(%s, %s)\n",
  354. call->callType, call->callToken);
  355. txframes = prefs->framing[x];
  356. ret= ooCallAddG711Capability(call, OO_G711ULAW64K, txframes,
  357. txframes, OORXANDTX,
  358. &ooh323c_start_receive_channel,
  359. &ooh323c_start_transmit_channel,
  360. &ooh323c_stop_receive_channel,
  361. &ooh323c_stop_transmit_channel);
  362. }
  363. if(tmpfmt.id == AST_FORMAT_ALAW)
  364. {
  365. if(gH323Debug)
  366. ast_verbose("\tAdding g711 alaw capability to call(%s, %s)\n",
  367. call->callType, call->callToken);
  368. txframes = prefs->framing[x];
  369. ret= ooCallAddG711Capability(call, OO_G711ALAW64K, txframes,
  370. txframes, OORXANDTX,
  371. &ooh323c_start_receive_channel,
  372. &ooh323c_start_transmit_channel,
  373. &ooh323c_stop_receive_channel,
  374. &ooh323c_stop_transmit_channel);
  375. }
  376. if(tmpfmt.id == AST_FORMAT_G726)
  377. {
  378. if(gH323Debug)
  379. ast_verbose("\tAdding g726 capability to call (%s, %s)\n",
  380. call->callType, call->callToken);
  381. txframes = prefs->framing[x];
  382. ret = ooCallAddG726Capability(call, OO_G726, txframes, grxframes, FALSE,
  383. OORXANDTX, &ooh323c_start_receive_channel,
  384. &ooh323c_start_transmit_channel,
  385. &ooh323c_stop_receive_channel,
  386. &ooh323c_stop_transmit_channel);
  387. }
  388. if(tmpfmt.id == AST_FORMAT_G726_AAL2)
  389. {
  390. if(gH323Debug)
  391. ast_verbose("\tAdding g726aal2 capability to call (%s, %s)\n",
  392. call->callType, call->callToken);
  393. txframes = prefs->framing[x];
  394. ret = ooCallAddG726Capability(call, OO_G726AAL2, txframes, grxframes, FALSE,
  395. OORXANDTX, &ooh323c_start_receive_channel,
  396. &ooh323c_start_transmit_channel,
  397. &ooh323c_stop_receive_channel,
  398. &ooh323c_stop_transmit_channel);
  399. }
  400. if(tmpfmt.id == AST_FORMAT_G729A)
  401. {
  402. txframes = (prefs->framing[x])/10;
  403. if(gH323Debug)
  404. ast_verbose("\tAdding g729A capability to call(%s, %s)\n",
  405. call->callType, call->callToken);
  406. ret= ooCallAddG729Capability(call, OO_G729A, txframes, txframes,
  407. OORXANDTX, &ooh323c_start_receive_channel,
  408. &ooh323c_start_transmit_channel,
  409. &ooh323c_stop_receive_channel,
  410. &ooh323c_stop_transmit_channel);
  411. if (g729onlyA)
  412. continue;
  413. if(gH323Debug)
  414. ast_verbose("\tAdding g729 capability to call(%s, %s)\n",
  415. call->callType, call->callToken);
  416. ret|= ooCallAddG729Capability(call, OO_G729, txframes, txframes,
  417. OORXANDTX, &ooh323c_start_receive_channel,
  418. &ooh323c_start_transmit_channel,
  419. &ooh323c_stop_receive_channel,
  420. &ooh323c_stop_transmit_channel);
  421. if(gH323Debug)
  422. ast_verbose("\tAdding g729B capability to call(%s, %s)\n",
  423. call->callType, call->callToken);
  424. ret|= ooCallAddG729Capability(call, OO_G729B, txframes, txframes,
  425. OORXANDTX, &ooh323c_start_receive_channel,
  426. &ooh323c_start_transmit_channel,
  427. &ooh323c_stop_receive_channel,
  428. &ooh323c_stop_transmit_channel);
  429. }
  430. if(tmpfmt.id == AST_FORMAT_G723_1)
  431. {
  432. if(gH323Debug)
  433. ast_verbose("\tAdding g7231 capability to call (%s, %s)\n",
  434. call->callType, call->callToken);
  435. ret = ooCallAddG7231Capability(call, OO_G7231, 1, 1, FALSE,
  436. OORXANDTX, &ooh323c_start_receive_channel,
  437. &ooh323c_start_transmit_channel,
  438. &ooh323c_stop_receive_channel,
  439. &ooh323c_stop_transmit_channel);
  440. }
  441. if(tmpfmt.id == AST_FORMAT_H263)
  442. {
  443. if(gH323Debug)
  444. ast_verbose("\tAdding h263 capability to call (%s, %s)\n",
  445. call->callType, call->callToken);
  446. ret = ooCallAddH263VideoCapability(call, OO_H263VIDEO, 1, 0, 0, 0, 0, 320*1024,
  447. OORXANDTX, &ooh323c_start_receive_channel,
  448. &ooh323c_start_transmit_channel,
  449. &ooh323c_stop_receive_channel,
  450. &ooh323c_stop_transmit_channel);
  451. }
  452. if(tmpfmt.id == AST_FORMAT_GSM)
  453. {
  454. if(gH323Debug)
  455. ast_verbose("\tAdding gsm capability to call(%s, %s)\n",
  456. call->callType, call->callToken);
  457. ret = ooCallAddGSMCapability(call, OO_GSMFULLRATE, 4, FALSE, FALSE,
  458. OORXANDTX, &ooh323c_start_receive_channel,
  459. &ooh323c_start_transmit_channel,
  460. &ooh323c_stop_receive_channel,
  461. &ooh323c_stop_transmit_channel);
  462. }
  463. #ifdef AST_FORMAT_AMRNB
  464. if(tmpfmt.id == AST_FORMAT_AMRNB)
  465. {
  466. if(gH323Debug)
  467. ast_verbose("\tAdding AMR capability to call(%s, %s)\n",
  468. call->callType, call->callToken);
  469. ret = ooCallAddAMRNBCapability(call, OO_AMRNB, 4, 4, FALSE,
  470. OORXANDTX, &ooh323c_start_receive_channel,
  471. &ooh323c_start_transmit_channel,
  472. &ooh323c_stop_receive_channel,
  473. &ooh323c_stop_transmit_channel);
  474. }
  475. #endif
  476. #ifdef AST_FORMAT_SPEEX
  477. if(tmpfmt.id == AST_FORMAT_SPEEX)
  478. {
  479. if(gH323Debug)
  480. ast_verbose("\tAdding Speex capability to call(%s, %s)\n",
  481. call->callType, call->callToken);
  482. ret = ooCallAddSpeexCapability(call, OO_SPEEX, 4, 4, FALSE,
  483. OORXANDTX, &ooh323c_start_receive_channel,
  484. &ooh323c_start_transmit_channel,
  485. &ooh323c_stop_receive_channel,
  486. &ooh323c_stop_transmit_channel);
  487. }
  488. #endif
  489. }
  490. return ret;
  491. }
  492. int ooh323c_set_aliases(ooAliases * aliases)
  493. {
  494. ooAliases *cur = aliases;
  495. while(cur)
  496. {
  497. switch(cur->type)
  498. {
  499. case T_H225AliasAddress_dialedDigits:
  500. ooH323EpAddAliasDialedDigits(cur->value);
  501. break;
  502. case T_H225AliasAddress_h323_ID:
  503. ooH323EpAddAliasH323ID(cur->value);
  504. break;
  505. case T_H225AliasAddress_url_ID:
  506. ooH323EpAddAliasURLID(cur->value);
  507. break;
  508. case T_H225AliasAddress_email_ID:
  509. ooH323EpAddAliasEmailID(cur->value);
  510. break;
  511. default:
  512. ast_debug(1, "Ignoring unknown alias type\n");
  513. }
  514. cur = cur->next;
  515. }
  516. return 1;
  517. }
  518. int ooh323c_start_receive_channel(ooCallData *call, ooLogicalChannel *pChannel)
  519. {
  520. struct ast_format tmpfmt;
  521. convertH323CapToAsteriskCap(pChannel->chanCap->cap, &tmpfmt);
  522. if(tmpfmt.id) {
  523. /* ooh323_set_read_format(call, fmt); */
  524. }else{
  525. ast_log(LOG_ERROR, "Invalid capability type for receive channel %s\n",
  526. call->callToken);
  527. return -1;
  528. }
  529. return 1;
  530. }
  531. int ooh323c_start_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel)
  532. {
  533. struct ast_format tmpfmt;
  534. convertH323CapToAsteriskCap(pChannel->chanCap->cap, &tmpfmt);
  535. if(tmpfmt.id) {
  536. switch (tmpfmt.id) {
  537. case AST_FORMAT_ALAW:
  538. case AST_FORMAT_ULAW:
  539. ooh323_set_write_format(call, &tmpfmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes);
  540. break;
  541. case AST_FORMAT_G729A:
  542. ooh323_set_write_format(call, &tmpfmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes*10);
  543. break;
  544. default:
  545. ooh323_set_write_format(call, &tmpfmt, 0);
  546. }
  547. }else{
  548. ast_log(LOG_ERROR, "Invalid capability type for receive channel %s\n",
  549. call->callToken);
  550. return -1;
  551. }
  552. setup_rtp_connection(call, pChannel->remoteIP, pChannel->remoteMediaPort);
  553. return 1;
  554. }
  555. int ooh323c_stop_receive_channel(ooCallData *call, ooLogicalChannel *pChannel)
  556. {
  557. return 1;
  558. }
  559. int ooh323c_stop_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel)
  560. {
  561. close_rtp_connection(call);
  562. return 1;
  563. }
  564. int ooh323c_start_receive_datachannel(ooCallData *call, ooLogicalChannel *pChannel)
  565. {
  566. return 1;
  567. }
  568. int ooh323c_start_transmit_datachannel(ooCallData *call, ooLogicalChannel *pChannel)
  569. {
  570. setup_udptl_connection(call, pChannel->remoteIP, pChannel->remoteMediaPort);
  571. return 1;
  572. }
  573. int ooh323c_stop_receive_datachannel(ooCallData *call, ooLogicalChannel *pChannel)
  574. {
  575. return 1;
  576. }
  577. int ooh323c_stop_transmit_datachannel(ooCallData *call, ooLogicalChannel *pChannel)
  578. {
  579. close_udptl_connection(call);
  580. return 1;
  581. }
  582. struct ast_format *convertH323CapToAsteriskCap(int cap, struct ast_format *result)
  583. {
  584. ast_format_clear(result);
  585. switch(cap)
  586. {
  587. case OO_G711ULAW64K:
  588. return ast_format_set(result, AST_FORMAT_ULAW, 0);
  589. case OO_G711ALAW64K:
  590. return ast_format_set(result, AST_FORMAT_ALAW, 0);
  591. case OO_GSMFULLRATE:
  592. return ast_format_set(result, AST_FORMAT_GSM, 0);
  593. #ifdef AST_FORMAT_AMRNB
  594. case OO_AMRNB:
  595. return ast_format_set(result, AST_FORMAT_AMRNB, 0);
  596. #endif
  597. #ifdef AST_FORMAT_SPEEX
  598. case OO_SPEEX:
  599. return ast_format_set(result, AST_FORMAT_SPEEX, 0);
  600. #endif
  601. case OO_G729:
  602. return ast_format_set(result, AST_FORMAT_G729A, 0);
  603. case OO_G729A:
  604. return ast_format_set(result, AST_FORMAT_G729A, 0);
  605. case OO_G729B:
  606. return ast_format_set(result, AST_FORMAT_G729A, 0);
  607. case OO_G7231:
  608. return ast_format_set(result, AST_FORMAT_G723_1, 0);
  609. case OO_G726:
  610. return ast_format_set(result, AST_FORMAT_G726, 0);
  611. case OO_G726AAL2:
  612. return ast_format_set(result, AST_FORMAT_G726_AAL2, 0);
  613. case OO_H263VIDEO:
  614. return ast_format_set(result, AST_FORMAT_H263, 0);
  615. default:
  616. ast_debug(1, "Cap %d is not supported by driver yet\n", cap);
  617. return NULL;
  618. }
  619. return NULL;
  620. }