app_echo.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * Echo application -- play back what you hear to evaluate latency
  5. *
  6. * Copyright (C) 1999, Mark Spencer
  7. *
  8. * Mark Spencer <markster@linux-support.net>
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License
  12. */
  13. #include <asterisk/lock.h>
  14. #include <asterisk/file.h>
  15. #include <asterisk/logger.h>
  16. #include <asterisk/channel.h>
  17. #include <asterisk/pbx.h>
  18. #include <asterisk/module.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <pthread.h>
  24. static char *tdesc = "Simple Echo Application";
  25. static char *app = "Echo";
  26. static char *synopsis = "Echo audio read back to the user";
  27. static char *descrip =
  28. " Echo(): Echo audio read from channel back to the channel. Returns 0\n"
  29. "if the user exits with the '#' key, or -1 if the user hangs up.\n";
  30. STANDARD_LOCAL_USER;
  31. LOCAL_USER_DECL;
  32. static int echo_exec(struct ast_channel *chan, void *data)
  33. {
  34. int res=-1;
  35. struct localuser *u;
  36. struct ast_frame *f;
  37. LOCAL_USER_ADD(u);
  38. ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
  39. ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
  40. /* Do our thing here */
  41. while(ast_waitfor(chan, -1) > -1) {
  42. f = ast_read(chan);
  43. if (!f)
  44. break;
  45. if (f->frametype == AST_FRAME_VOICE) {
  46. if (ast_write(chan, f))
  47. break;
  48. } else if (f->frametype == AST_FRAME_VIDEO) {
  49. if (ast_write(chan, f))
  50. break;
  51. } else if (f->frametype == AST_FRAME_DTMF) {
  52. if (f->subclass == '#') {
  53. res = 0;
  54. break;
  55. } else
  56. if (ast_write(chan, f))
  57. break;
  58. }
  59. ast_frfree(f);
  60. }
  61. LOCAL_USER_REMOVE(u);
  62. return res;
  63. }
  64. int unload_module(void)
  65. {
  66. STANDARD_HANGUP_LOCALUSERS;
  67. return ast_unregister_application(app);
  68. }
  69. int load_module(void)
  70. {
  71. return ast_register_application(app, echo_exec, synopsis, descrip);
  72. }
  73. char *description(void)
  74. {
  75. return tdesc;
  76. }
  77. int usecount(void)
  78. {
  79. int res;
  80. STANDARD_USECOUNT(res);
  81. return res;
  82. }
  83. char *key()
  84. {
  85. return ASTERISK_GPL_KEY;
  86. }