bridge_simple.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. return ast_bridge_queue_everyone_else(bridge, bridge_channel, frame);
  57. }
  58. static struct ast_bridge_technology simple_bridge = {
  59. .name = "simple_bridge",
  60. .capabilities = AST_BRIDGE_CAPABILITY_1TO1MIX,
  61. .preference = AST_BRIDGE_PREFERENCE_BASE_1TO1MIX,
  62. .join = simple_bridge_join,
  63. .write = simple_bridge_write,
  64. };
  65. static int unload_module(void)
  66. {
  67. ast_bridge_technology_unregister(&simple_bridge);
  68. return 0;
  69. }
  70. static int load_module(void)
  71. {
  72. if (ast_bridge_technology_register(&simple_bridge)) {
  73. unload_module();
  74. return AST_MODULE_LOAD_DECLINE;
  75. }
  76. return AST_MODULE_LOAD_SUCCESS;
  77. }
  78. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple two channel bridging module");