bridge_simple.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2007, 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 Simple two channel bridging 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. static int simple_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
  42. {
  43. struct ast_channel *c0 = AST_LIST_FIRST(&bridge->channels)->chan;
  44. struct ast_channel *c1 = AST_LIST_LAST(&bridge->channels)->chan;
  45. /*
  46. * If this is the first channel we can't make it compatible...
  47. * unless we make it compatible with itself. O.o
  48. */
  49. if (c0 == c1) {
  50. return 0;
  51. }
  52. return ast_channel_make_compatible(c0, c1);
  53. }
  54. static int simple_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
  55. {
  56. const struct ast_control_t38_parameters *t38_parameters;
  57. int defer = 0;
  58. if (!ast_bridge_queue_everyone_else(bridge, bridge_channel, frame)) {
  59. /* This frame was successfully queued so no need to defer */
  60. return 0;
  61. }
  62. /* Depending on the frame defer it so when the next channel joins it receives it */
  63. switch (frame->frametype) {
  64. case AST_FRAME_CONTROL:
  65. switch (frame->subclass.integer) {
  66. case AST_CONTROL_T38_PARAMETERS:
  67. t38_parameters = frame->data.ptr;
  68. switch (t38_parameters->request_response) {
  69. case AST_T38_REQUEST_NEGOTIATE:
  70. defer = -1;
  71. break;
  72. default:
  73. break;
  74. }
  75. break;
  76. default:
  77. break;
  78. }
  79. break;
  80. default:
  81. break;
  82. }
  83. return defer;
  84. }
  85. static struct ast_bridge_technology simple_bridge = {
  86. .name = "simple_bridge",
  87. .capabilities = AST_BRIDGE_CAPABILITY_1TO1MIX,
  88. .preference = AST_BRIDGE_PREFERENCE_BASE_1TO1MIX,
  89. .join = simple_bridge_join,
  90. .write = simple_bridge_write,
  91. };
  92. static int unload_module(void)
  93. {
  94. ast_bridge_technology_unregister(&simple_bridge);
  95. return 0;
  96. }
  97. static int load_module(void)
  98. {
  99. if (ast_bridge_technology_register(&simple_bridge)) {
  100. unload_module();
  101. return AST_MODULE_LOAD_DECLINE;
  102. }
  103. return AST_MODULE_LOAD_SUCCESS;
  104. }
  105. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple two channel bridging module");