conf_chan_record.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013 Digium, Inc.
  5. *
  6. * Richard Mudgett <rmudgett@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. /*!
  19. * \file
  20. * \brief ConfBridge recorder channel driver
  21. *
  22. * \author Richard Mudgett <rmudgett@digium.com>
  23. *
  24. * See Also:
  25. * \arg \ref AstCREDITS
  26. */
  27. #include "asterisk.h"
  28. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/channel.h"
  30. #include "asterisk/bridge.h"
  31. #include "asterisk/format_cache.h"
  32. #include "include/confbridge.h"
  33. /* ------------------------------------------------------------------- */
  34. static unsigned int name_sequence = 0;
  35. static int rec_call(struct ast_channel *chan, const char *addr, int timeout)
  36. {
  37. /* Make sure anyone calling ast_call() for this channel driver is going to fail. */
  38. return -1;
  39. }
  40. static struct ast_frame *rec_read(struct ast_channel *ast)
  41. {
  42. return &ast_null_frame;
  43. }
  44. static int rec_write(struct ast_channel *ast, struct ast_frame *f)
  45. {
  46. return 0;
  47. }
  48. static struct ast_channel *rec_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
  49. {
  50. struct ast_channel *chan;
  51. const char *conf_name = data;
  52. RAII_VAR(struct ast_format_cap *, capabilities, NULL, ao2_cleanup);
  53. int generated_seqno = ast_atomic_fetchadd_int((int *) &name_sequence, +1);
  54. capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  55. if (!capabilities) {
  56. return NULL;
  57. }
  58. ast_format_cap_append_by_type(capabilities, AST_MEDIA_TYPE_UNKNOWN);
  59. chan = ast_channel_alloc(1, AST_STATE_UP, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0,
  60. "CBRec/conf-%s-uid-%08x",
  61. conf_name, (unsigned) generated_seqno);
  62. if (!chan) {
  63. return NULL;
  64. }
  65. if (ast_channel_add_bridge_role(chan, "recorder")) {
  66. ast_channel_unlock(chan);
  67. ast_channel_release(chan);
  68. return NULL;
  69. }
  70. ast_channel_tech_set(chan, conf_record_get_tech());
  71. ast_channel_nativeformats_set(chan, capabilities);
  72. ast_channel_set_writeformat(chan, ast_format_slin);
  73. ast_channel_set_rawwriteformat(chan, ast_format_slin);
  74. ast_channel_set_readformat(chan, ast_format_slin);
  75. ast_channel_set_rawreadformat(chan, ast_format_slin);
  76. ast_channel_unlock(chan);
  77. return chan;
  78. }
  79. static struct ast_channel_tech record_tech = {
  80. .type = "CBRec",
  81. .description = "Conference Bridge Recording Channel",
  82. .requester = rec_request,
  83. .call = rec_call,
  84. .read = rec_read,
  85. .write = rec_write,
  86. .properties = AST_CHAN_TP_INTERNAL,
  87. };
  88. struct ast_channel_tech *conf_record_get_tech(void)
  89. {
  90. return &record_tech;
  91. }