dahdi_echocan_jpah.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * ECHO_CAN_JPAH
  3. *
  4. * by Jason Parker
  5. *
  6. * Based upon mg2ec.h - sort of.
  7. * This "echo can" will completely hose your audio.
  8. * Don't use it unless you're absolutely sure you know what you're doing.
  9. *
  10. * Copyright (C) 2007-2012, Digium, Inc.
  11. *
  12. * All rights reserved.
  13. *
  14. */
  15. /*
  16. * See http://www.asterisk.org for more information about
  17. * the Asterisk project. Please do not directly contact
  18. * any of the maintainers of this project for assistance;
  19. * the project provides a web site, mailing lists and IRC
  20. * channels for your use.
  21. *
  22. * This program is free software, distributed under the terms of
  23. * the GNU General Public License Version 2 as published by the
  24. * Free Software Foundation. See the LICENSE file included with
  25. * this program for more details.
  26. */
  27. #include <linux/kernel.h>
  28. #include <linux/slab.h>
  29. #include <linux/errno.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/ctype.h>
  33. #include <linux/moduleparam.h>
  34. #include <dahdi/kernel.h>
  35. static int debug;
  36. static int echo_can_create(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp,
  37. struct dahdi_echocanparam *p, struct dahdi_echocan_state **ec);
  38. static void echo_can_free(struct dahdi_chan *chan, struct dahdi_echocan_state *ec);
  39. static void echo_can_process(struct dahdi_echocan_state *ec, short *isig, const short *iref, u32 size);
  40. static int echo_can_traintap(struct dahdi_echocan_state *ec, int pos, short val);
  41. static const char *name = "JPAH";
  42. static const char *ec_name(const struct dahdi_chan *chan) { return name; }
  43. static const struct dahdi_echocan_factory my_factory = {
  44. .get_name = ec_name,
  45. .owner = THIS_MODULE,
  46. .echocan_create = echo_can_create,
  47. };
  48. static const struct dahdi_echocan_ops my_ops = {
  49. .echocan_free = echo_can_free,
  50. .echocan_process = echo_can_process,
  51. .echocan_traintap = echo_can_traintap,
  52. };
  53. struct ec_pvt {
  54. struct dahdi_echocan_state dahdi;
  55. int blah;
  56. };
  57. #define dahdi_to_pvt(a) container_of(a, struct ec_pvt, dahdi)
  58. static int echo_can_create(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp,
  59. struct dahdi_echocanparam *p, struct dahdi_echocan_state **ec)
  60. {
  61. struct ec_pvt *pvt;
  62. if (ecp->param_count > 0) {
  63. printk(KERN_WARNING "JPAH does not support parameters; failing request\n");
  64. return -EINVAL;
  65. }
  66. pvt = kzalloc(sizeof(*pvt), GFP_KERNEL);
  67. if (!pvt)
  68. return -ENOMEM;
  69. pvt->dahdi.ops = &my_ops;
  70. *ec = &pvt->dahdi;
  71. return 0;
  72. }
  73. static void echo_can_free(struct dahdi_chan *chan, struct dahdi_echocan_state *ec)
  74. {
  75. struct ec_pvt *pvt = dahdi_to_pvt(ec);
  76. kfree(pvt);
  77. }
  78. static void echo_can_process(struct dahdi_echocan_state *ec, short *isig, const short *iref, u32 size)
  79. {
  80. struct ec_pvt *pvt = dahdi_to_pvt(ec);
  81. u32 x;
  82. for (x = 0; x < size; x++) {
  83. if (pvt->blah < 2) {
  84. pvt->blah++;
  85. *isig++ = 0;
  86. } else {
  87. pvt->blah = 0;
  88. isig++;
  89. }
  90. }
  91. }
  92. static int echo_can_traintap(struct dahdi_echocan_state *ec, int pos, short val)
  93. {
  94. return 0;
  95. }
  96. static int __init mod_init(void)
  97. {
  98. if (dahdi_register_echocan_factory(&my_factory)) {
  99. module_printk(KERN_ERR, "could not register with DAHDI core\n");
  100. return -EPERM;
  101. }
  102. module_printk(KERN_NOTICE, "Registered echo canceler '%s'\n",
  103. my_factory.get_name(NULL));
  104. return 0;
  105. }
  106. static void __exit mod_exit(void)
  107. {
  108. dahdi_unregister_echocan_factory(&my_factory);
  109. }
  110. module_param(debug, int, S_IRUGO | S_IWUSR);
  111. MODULE_DESCRIPTION("DAHDI Jason Parker Audio Hoser");
  112. MODULE_AUTHOR("Jason Parker <jparker@digium.com>");
  113. MODULE_LICENSE("GPL v2");
  114. module_init(mod_init);
  115. module_exit(mod_exit);