app_echo.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. static char *tdesc = "Simple Echo Application";
  24. static char *app = "Echo";
  25. static char *synopsis = "Echo audio read back to the user";
  26. static char *descrip =
  27. " Echo(): Echo audio read from channel back to the channel. Returns 0\n"
  28. "if the user exits with the '#' key, or -1 if the user hangs up.\n";
  29. STANDARD_LOCAL_USER;
  30. LOCAL_USER_DECL;
  31. static int echo_exec(struct ast_channel *chan, void *data)
  32. {
  33. int res=-1;
  34. struct localuser *u;
  35. struct ast_frame *f;
  36. LOCAL_USER_ADD(u);
  37. ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
  38. ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
  39. /* Do our thing here */
  40. while(ast_waitfor(chan, -1) > -1) {
  41. f = ast_read(chan);
  42. if (!f)
  43. break;
  44. f->delivery.tv_sec = 0;
  45. f->delivery.tv_usec = 0;
  46. if (f->frametype == AST_FRAME_VOICE) {
  47. if (ast_write(chan, f))
  48. break;
  49. } else if (f->frametype == AST_FRAME_VIDEO) {
  50. if (ast_write(chan, f))
  51. break;
  52. } else if (f->frametype == AST_FRAME_DTMF) {
  53. if (f->subclass == '#') {
  54. res = 0;
  55. break;
  56. } else
  57. if (ast_write(chan, f))
  58. break;
  59. }
  60. ast_frfree(f);
  61. }
  62. LOCAL_USER_REMOVE(u);
  63. return res;
  64. }
  65. int unload_module(void)
  66. {
  67. STANDARD_HANGUP_LOCALUSERS;
  68. return ast_unregister_application(app);
  69. }
  70. int load_module(void)
  71. {
  72. return ast_register_application(app, echo_exec, synopsis, descrip);
  73. }
  74. char *description(void)
  75. {
  76. return tdesc;
  77. }
  78. int usecount(void)
  79. {
  80. int res;
  81. STANDARD_USECOUNT(res);
  82. return res;
  83. }
  84. char *key()
  85. {
  86. return ASTERISK_GPL_KEY;
  87. }