bridge_native_rtp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * Joshua Colp <jcolp@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. *
  20. * \brief Native RTP bridging technology module
  21. *
  22. * \author Joshua Colp <jcolp@digium.com>
  23. *
  24. * \ingroup bridges
  25. */
  26. /*** MODULEINFO
  27. <support_level>core</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <sys/types.h>
  35. #include <sys/stat.h>
  36. #include "asterisk/module.h"
  37. #include "asterisk/channel.h"
  38. #include "asterisk/bridge.h"
  39. #include "asterisk/bridge_technology.h"
  40. #include "asterisk/frame.h"
  41. #include "asterisk/rtp_engine.h"
  42. /*! \brief Internal structure which contains information about bridged RTP channels */
  43. struct native_rtp_bridge_data {
  44. /*! \brief Framehook used to intercept certain control frames */
  45. int id;
  46. };
  47. /*! \brief Internal helper function which gets all RTP information (glue and instances) relating to the given channels */
  48. static enum ast_rtp_glue_result native_rtp_bridge_get(struct ast_channel *c0, struct ast_channel *c1, struct ast_rtp_glue **glue0,
  49. struct ast_rtp_glue **glue1, struct ast_rtp_instance **instance0, struct ast_rtp_instance **instance1,
  50. struct ast_rtp_instance **vinstance0, struct ast_rtp_instance **vinstance1)
  51. {
  52. enum ast_rtp_glue_result audio_glue0_res;
  53. enum ast_rtp_glue_result video_glue0_res;
  54. enum ast_rtp_glue_result audio_glue1_res;
  55. enum ast_rtp_glue_result video_glue1_res;
  56. if (!(*glue0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) ||
  57. !(*glue1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type))) {
  58. return AST_RTP_GLUE_RESULT_FORBID;
  59. }
  60. audio_glue0_res = (*glue0)->get_rtp_info(c0, instance0);
  61. video_glue0_res = (*glue0)->get_vrtp_info ? (*glue0)->get_vrtp_info(c0, vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
  62. audio_glue1_res = (*glue1)->get_rtp_info(c1, instance1);
  63. video_glue1_res = (*glue1)->get_vrtp_info ? (*glue1)->get_vrtp_info(c1, vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
  64. /* Apply any limitations on direct media bridging that may be present */
  65. if (audio_glue0_res == audio_glue1_res && audio_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) {
  66. if ((*glue0)->allow_rtp_remote && !((*glue0)->allow_rtp_remote(c0, *instance1))) {
  67. /* If the allow_rtp_remote indicates that remote isn't allowed, revert to local bridge */
  68. audio_glue0_res = audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
  69. } else if ((*glue1)->allow_rtp_remote && !((*glue1)->allow_rtp_remote(c1, *instance0))) {
  70. audio_glue0_res = audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
  71. }
  72. }
  73. if (video_glue0_res == video_glue1_res && video_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) {
  74. if ((*glue0)->allow_vrtp_remote && !((*glue0)->allow_vrtp_remote(c0, *instance1))) {
  75. /* if the allow_vrtp_remote indicates that remote isn't allowed, revert to local bridge */
  76. video_glue0_res = video_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
  77. } else if ((*glue1)->allow_vrtp_remote && !((*glue1)->allow_vrtp_remote(c1, *instance0))) {
  78. video_glue0_res = video_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
  79. }
  80. }
  81. /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
  82. if (video_glue0_res != AST_RTP_GLUE_RESULT_FORBID
  83. && (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE
  84. || video_glue0_res != AST_RTP_GLUE_RESULT_REMOTE)) {
  85. audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
  86. }
  87. if (video_glue1_res != AST_RTP_GLUE_RESULT_FORBID
  88. && (audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE
  89. || video_glue1_res != AST_RTP_GLUE_RESULT_REMOTE)) {
  90. audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
  91. }
  92. /* The order of preference is: forbid, local, and remote. */
  93. if (audio_glue0_res == AST_RTP_GLUE_RESULT_FORBID ||
  94. audio_glue1_res == AST_RTP_GLUE_RESULT_FORBID) {
  95. /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
  96. return AST_RTP_GLUE_RESULT_FORBID;
  97. } else if (audio_glue0_res == AST_RTP_GLUE_RESULT_LOCAL ||
  98. audio_glue1_res == AST_RTP_GLUE_RESULT_LOCAL) {
  99. return AST_RTP_GLUE_RESULT_LOCAL;
  100. } else {
  101. return AST_RTP_GLUE_RESULT_REMOTE;
  102. }
  103. }
  104. /*!
  105. * \internal
  106. * \brief Start native RTP bridging of two channels
  107. *
  108. * \param bridge The bridge that had native RTP bridging happening on it
  109. * \param target If remote RTP bridging, the channel that is unheld.
  110. *
  111. * \note Bridge must be locked when calling this function.
  112. */
  113. static void native_rtp_bridge_start(struct ast_bridge *bridge, struct ast_channel *target)
  114. {
  115. struct ast_bridge_channel *bc0 = AST_LIST_FIRST(&bridge->channels);
  116. struct ast_bridge_channel *bc1 = AST_LIST_LAST(&bridge->channels);
  117. enum ast_rtp_glue_result native_type;
  118. struct ast_rtp_glue *glue0, *glue1;
  119. RAII_VAR(struct ast_rtp_instance *, instance0, NULL, ao2_cleanup);
  120. RAII_VAR(struct ast_rtp_instance *, instance1, NULL, ao2_cleanup);
  121. RAII_VAR(struct ast_rtp_instance *, vinstance0, NULL, ao2_cleanup);
  122. RAII_VAR(struct ast_rtp_instance *, vinstance1, NULL, ao2_cleanup);
  123. RAII_VAR(struct ast_rtp_instance *, tinstance0, NULL, ao2_cleanup);
  124. RAII_VAR(struct ast_rtp_instance *, tinstance1, NULL, ao2_cleanup);
  125. RAII_VAR(struct ast_format_cap *, cap0, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup);
  126. RAII_VAR(struct ast_format_cap *, cap1, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup);
  127. if (bc0 == bc1) {
  128. return;
  129. }
  130. ast_channel_lock_both(bc0->chan, bc1->chan);
  131. native_type = native_rtp_bridge_get(bc0->chan, bc1->chan, &glue0, &glue1, &instance0, &instance1, &vinstance0, &vinstance1);
  132. switch (native_type) {
  133. case AST_RTP_GLUE_RESULT_LOCAL:
  134. if (ast_rtp_instance_get_engine(instance0)->local_bridge) {
  135. ast_rtp_instance_get_engine(instance0)->local_bridge(instance0, instance1);
  136. }
  137. if (ast_rtp_instance_get_engine(instance1)->local_bridge) {
  138. ast_rtp_instance_get_engine(instance1)->local_bridge(instance1, instance0);
  139. }
  140. ast_rtp_instance_set_bridged(instance0, instance1);
  141. ast_rtp_instance_set_bridged(instance1, instance0);
  142. ast_verb(4, "Locally RTP bridged '%s' and '%s' in stack\n",
  143. ast_channel_name(bc0->chan), ast_channel_name(bc1->chan));
  144. break;
  145. case AST_RTP_GLUE_RESULT_REMOTE:
  146. if (glue0->get_codec) {
  147. glue0->get_codec(bc0->chan, cap0);
  148. }
  149. if (glue1->get_codec) {
  150. glue1->get_codec(bc1->chan, cap1);
  151. }
  152. /* If we have a target, it's the channel that received the UNHOLD or UPDATE_RTP_PEER frame and was told to resume */
  153. if (!target) {
  154. glue0->update_peer(bc0->chan, instance1, vinstance1, tinstance1, cap1, 0);
  155. glue1->update_peer(bc1->chan, instance0, vinstance0, tinstance0, cap0, 0);
  156. ast_verb(4, "Remotely bridged '%s' and '%s' - media will flow directly between them\n",
  157. ast_channel_name(bc0->chan), ast_channel_name(bc1->chan));
  158. } else {
  159. /*
  160. * If a target was provided, it is the recipient of an unhold or an update and needs to have
  161. * its media redirected to fit the current remote bridging needs. The other channel is either
  162. * already set up to handle the new media path or will have its own set of updates independent
  163. * of this pass.
  164. */
  165. if (bc0->chan == target) {
  166. glue0->update_peer(bc0->chan, instance1, vinstance1, tinstance1, cap1, 0);
  167. } else {
  168. glue1->update_peer(bc1->chan, instance0, vinstance0, tinstance0, cap0, 0);
  169. }
  170. }
  171. break;
  172. case AST_RTP_GLUE_RESULT_FORBID:
  173. break;
  174. }
  175. ast_channel_unlock(bc0->chan);
  176. ast_channel_unlock(bc1->chan);
  177. }
  178. static void native_rtp_bridge_stop(struct ast_bridge *bridge, struct ast_channel *target)
  179. {
  180. struct ast_bridge_channel *bc0 = AST_LIST_FIRST(&bridge->channels);
  181. struct ast_bridge_channel *bc1 = AST_LIST_LAST(&bridge->channels);
  182. enum ast_rtp_glue_result native_type;
  183. struct ast_rtp_glue *glue0, *glue1 = NULL;
  184. RAII_VAR(struct ast_rtp_instance *, instance0, NULL, ao2_cleanup);
  185. RAII_VAR(struct ast_rtp_instance *, instance1, NULL, ao2_cleanup);
  186. RAII_VAR(struct ast_rtp_instance *, vinstance0, NULL, ao2_cleanup);
  187. RAII_VAR(struct ast_rtp_instance *, vinstance1, NULL, ao2_cleanup);
  188. if (bc0 == bc1) {
  189. return;
  190. }
  191. ast_channel_lock_both(bc0->chan, bc1->chan);
  192. native_type = native_rtp_bridge_get(bc0->chan, bc1->chan, &glue0, &glue1, &instance0, &instance1, &vinstance0, &vinstance1);
  193. switch (native_type) {
  194. case AST_RTP_GLUE_RESULT_LOCAL:
  195. if (ast_rtp_instance_get_engine(instance0)->local_bridge) {
  196. ast_rtp_instance_get_engine(instance0)->local_bridge(instance0, NULL);
  197. }
  198. if (instance1 && ast_rtp_instance_get_engine(instance1)->local_bridge) {
  199. ast_rtp_instance_get_engine(instance1)->local_bridge(instance1, NULL);
  200. }
  201. ast_rtp_instance_set_bridged(instance0, NULL);
  202. if (instance1) {
  203. ast_rtp_instance_set_bridged(instance1, NULL);
  204. }
  205. break;
  206. case AST_RTP_GLUE_RESULT_REMOTE:
  207. if (target) {
  208. /*
  209. * If a target was provided, it is being put on hold and should expect to
  210. * receive media from Asterisk instead of what it was previously connected to.
  211. */
  212. if (bc0->chan == target) {
  213. glue0->update_peer(bc0->chan, NULL, NULL, NULL, NULL, 0);
  214. } else {
  215. glue1->update_peer(bc1->chan, NULL, NULL, NULL, NULL, 0);
  216. }
  217. }
  218. break;
  219. case AST_RTP_GLUE_RESULT_FORBID:
  220. break;
  221. }
  222. if (!target && native_type != AST_RTP_GLUE_RESULT_FORBID) {
  223. glue0->update_peer(bc0->chan, NULL, NULL, NULL, NULL, 0);
  224. glue1->update_peer(bc1->chan, NULL, NULL, NULL, NULL, 0);
  225. }
  226. ast_debug(2, "Discontinued RTP bridging of '%s' and '%s' - media will flow through Asterisk core\n",
  227. ast_channel_name(bc0->chan), ast_channel_name(bc1->chan));
  228. ast_channel_unlock(bc0->chan);
  229. ast_channel_unlock(bc1->chan);
  230. }
  231. /*! \brief Frame hook that is called to intercept hold/unhold */
  232. static struct ast_frame *native_rtp_framehook(struct ast_channel *chan, struct ast_frame *f, enum ast_framehook_event event, void *data)
  233. {
  234. RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
  235. if (!f || (event != AST_FRAMEHOOK_EVENT_WRITE)) {
  236. return f;
  237. }
  238. bridge = ast_channel_get_bridge(chan);
  239. if (bridge) {
  240. /* native_rtp_bridge_start/stop are not being called from bridging
  241. core so we need to lock the bridge prior to calling these functions
  242. Unfortunately that means unlocking the channel, but as it
  243. should not be modified this should be okay...hopefully */
  244. ast_channel_unlock(chan);
  245. ast_bridge_lock(bridge);
  246. if (f->subclass.integer == AST_CONTROL_HOLD) {
  247. native_rtp_bridge_stop(bridge, chan);
  248. } else if ((f->subclass.integer == AST_CONTROL_UNHOLD) || (f->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER)) {
  249. native_rtp_bridge_start(bridge, chan);
  250. }
  251. ast_bridge_unlock(bridge);
  252. ast_channel_lock(chan);
  253. }
  254. return f;
  255. }
  256. /*! \brief Callback function which informs upstream if we are consuming a frame of a specific type */
  257. static int native_rtp_framehook_consume(void *data, enum ast_frame_type type)
  258. {
  259. return (type == AST_FRAME_CONTROL ? 1 : 0);
  260. }
  261. /*! \brief Internal helper function which checks whether the channels are compatible with our native bridging */
  262. static int native_rtp_bridge_capable(struct ast_channel *chan)
  263. {
  264. return !ast_channel_has_hook_requiring_audio(chan);
  265. }
  266. static int native_rtp_bridge_compatible(struct ast_bridge *bridge)
  267. {
  268. struct ast_bridge_channel *bc0 = AST_LIST_FIRST(&bridge->channels);
  269. struct ast_bridge_channel *bc1 = AST_LIST_LAST(&bridge->channels);
  270. enum ast_rtp_glue_result native_type;
  271. struct ast_rtp_glue *glue0, *glue1;
  272. RAII_VAR(struct ast_rtp_instance *, instance0, NULL, ao2_cleanup);
  273. RAII_VAR(struct ast_rtp_instance *, instance1, NULL, ao2_cleanup);
  274. RAII_VAR(struct ast_rtp_instance *, vinstance0, NULL, ao2_cleanup);
  275. RAII_VAR(struct ast_rtp_instance *, vinstance1, NULL, ao2_cleanup);
  276. RAII_VAR(struct ast_format_cap *, cap0, NULL, ao2_cleanup);
  277. RAII_VAR(struct ast_format_cap *, cap1, NULL, ao2_cleanup);
  278. int read_ptime0, read_ptime1, write_ptime0, write_ptime1;
  279. /* We require two channels before even considering native bridging */
  280. if (bridge->num_channels != 2) {
  281. ast_debug(1, "Bridge '%s' can not use native RTP bridge as two channels are required\n",
  282. bridge->uniqueid);
  283. return 0;
  284. }
  285. if (!native_rtp_bridge_capable(bc0->chan)) {
  286. ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has features which prevent it\n",
  287. bridge->uniqueid, ast_channel_name(bc0->chan));
  288. return 0;
  289. }
  290. if (!native_rtp_bridge_capable(bc1->chan)) {
  291. ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has features which prevent it\n",
  292. bridge->uniqueid, ast_channel_name(bc1->chan));
  293. return 0;
  294. }
  295. if ((native_type = native_rtp_bridge_get(bc0->chan, bc1->chan, &glue0, &glue1, &instance0, &instance1, &vinstance0, &vinstance1))
  296. == AST_RTP_GLUE_RESULT_FORBID) {
  297. ast_debug(1, "Bridge '%s' can not use native RTP bridge as it was forbidden while getting details\n",
  298. bridge->uniqueid);
  299. return 0;
  300. }
  301. if (ao2_container_count(bc0->features->dtmf_hooks) && ast_rtp_instance_dtmf_mode_get(instance0)) {
  302. ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has DTMF hooks\n",
  303. bridge->uniqueid, ast_channel_name(bc0->chan));
  304. return 0;
  305. }
  306. if (ao2_container_count(bc1->features->dtmf_hooks) && ast_rtp_instance_dtmf_mode_get(instance1)) {
  307. ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has DTMF hooks\n",
  308. bridge->uniqueid, ast_channel_name(bc1->chan));
  309. return 0;
  310. }
  311. if ((native_type == AST_RTP_GLUE_RESULT_LOCAL) && ((ast_rtp_instance_get_engine(instance0)->local_bridge !=
  312. ast_rtp_instance_get_engine(instance1)->local_bridge) ||
  313. (ast_rtp_instance_get_engine(instance0)->dtmf_compatible &&
  314. !ast_rtp_instance_get_engine(instance0)->dtmf_compatible(bc0->chan, instance0, bc1->chan, instance1)))) {
  315. ast_debug(1, "Bridge '%s' can not use local native RTP bridge as local bridge or DTMF is not compatible\n",
  316. bridge->uniqueid);
  317. return 0;
  318. }
  319. cap0 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  320. cap1 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  321. if (!cap0 || !cap1) {
  322. return 0;
  323. }
  324. /* Make sure that codecs match */
  325. if (glue0->get_codec) {
  326. glue0->get_codec(bc0->chan, cap0);
  327. }
  328. if (glue1->get_codec) {
  329. glue1->get_codec(bc1->chan, cap1);
  330. }
  331. if (ast_format_cap_count(cap0) != 0 && ast_format_cap_count(cap1) != 0 && !ast_format_cap_iscompatible(cap0, cap1)) {
  332. struct ast_str *codec_buf0 = ast_str_alloca(64);
  333. struct ast_str *codec_buf1 = ast_str_alloca(64);
  334. ast_debug(1, "Channel codec0 = %s is not codec1 = %s, cannot native bridge in RTP.\n",
  335. ast_format_cap_get_names(cap0, &codec_buf0), ast_format_cap_get_names(cap1, &codec_buf1));
  336. return 0;
  337. }
  338. read_ptime0 = ast_format_cap_get_format_framing(cap0, ast_channel_rawreadformat(bc0->chan));
  339. read_ptime1 = ast_format_cap_get_format_framing(cap1, ast_channel_rawreadformat(bc1->chan));
  340. write_ptime0 = ast_format_cap_get_format_framing(cap0, ast_channel_rawwriteformat(bc0->chan));
  341. write_ptime1 = ast_format_cap_get_format_framing(cap1, ast_channel_rawwriteformat(bc1->chan));
  342. if (read_ptime0 != write_ptime1 || read_ptime1 != write_ptime0) {
  343. ast_debug(1, "Packetization differs between RTP streams (%d != %d or %d != %d). Cannot native bridge in RTP\n",
  344. read_ptime0, write_ptime1, read_ptime1, write_ptime0);
  345. return 0;
  346. }
  347. return 1;
  348. }
  349. /*! \brief Helper function which adds frame hook to bridge channel */
  350. static int native_rtp_bridge_framehook_attach(struct ast_bridge_channel *bridge_channel)
  351. {
  352. struct native_rtp_bridge_data *data = ao2_alloc(sizeof(*data), NULL);
  353. static struct ast_framehook_interface hook = {
  354. .version = AST_FRAMEHOOK_INTERFACE_VERSION,
  355. .event_cb = native_rtp_framehook,
  356. .consume_cb = native_rtp_framehook_consume,
  357. .disable_inheritance = 1,
  358. };
  359. if (!data) {
  360. return -1;
  361. }
  362. ast_channel_lock(bridge_channel->chan);
  363. data->id = ast_framehook_attach(bridge_channel->chan, &hook);
  364. ast_channel_unlock(bridge_channel->chan);
  365. if (data->id < 0) {
  366. ao2_cleanup(data);
  367. return -1;
  368. }
  369. bridge_channel->tech_pvt = data;
  370. return 0;
  371. }
  372. /*! \brief Helper function which removes frame hook from bridge channel */
  373. static void native_rtp_bridge_framehook_detach(struct ast_bridge_channel *bridge_channel)
  374. {
  375. RAII_VAR(struct native_rtp_bridge_data *, data, bridge_channel->tech_pvt, ao2_cleanup);
  376. if (!data) {
  377. return;
  378. }
  379. ast_channel_lock(bridge_channel->chan);
  380. ast_framehook_detach(bridge_channel->chan, data->id);
  381. ast_channel_unlock(bridge_channel->chan);
  382. bridge_channel->tech_pvt = NULL;
  383. }
  384. static int native_rtp_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
  385. {
  386. native_rtp_bridge_framehook_detach(bridge_channel);
  387. if (native_rtp_bridge_framehook_attach(bridge_channel)) {
  388. return -1;
  389. }
  390. native_rtp_bridge_start(bridge, NULL);
  391. return 0;
  392. }
  393. static void native_rtp_bridge_unsuspend(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
  394. {
  395. native_rtp_bridge_join(bridge, bridge_channel);
  396. }
  397. static void native_rtp_bridge_leave(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
  398. {
  399. native_rtp_bridge_framehook_detach(bridge_channel);
  400. native_rtp_bridge_stop(bridge, NULL);
  401. }
  402. static int native_rtp_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
  403. {
  404. return ast_bridge_queue_everyone_else(bridge, bridge_channel, frame);
  405. }
  406. static struct ast_bridge_technology native_rtp_bridge = {
  407. .name = "native_rtp",
  408. .capabilities = AST_BRIDGE_CAPABILITY_NATIVE,
  409. .preference = AST_BRIDGE_PREFERENCE_BASE_NATIVE,
  410. .join = native_rtp_bridge_join,
  411. .unsuspend = native_rtp_bridge_unsuspend,
  412. .leave = native_rtp_bridge_leave,
  413. .suspend = native_rtp_bridge_leave,
  414. .write = native_rtp_bridge_write,
  415. .compatible = native_rtp_bridge_compatible,
  416. };
  417. static int unload_module(void)
  418. {
  419. ast_bridge_technology_unregister(&native_rtp_bridge);
  420. return 0;
  421. }
  422. static int load_module(void)
  423. {
  424. if (ast_bridge_technology_register(&native_rtp_bridge)) {
  425. unload_module();
  426. return AST_MODULE_LOAD_DECLINE;
  427. }
  428. return AST_MODULE_LOAD_SUCCESS;
  429. }
  430. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Native RTP bridging module");