app_echo.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@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 Echo application -- play back what you hear to evaluate latency
  21. *
  22. * \author Mark Spencer <markster@digium.com>
  23. *
  24. * \ingroup applications
  25. */
  26. #include "asterisk.h"
  27. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  28. #include "asterisk/file.h"
  29. #include "asterisk/module.h"
  30. #include "asterisk/channel.h"
  31. static char *app = "Echo";
  32. static char *synopsis = "Echo audio, video, or DTMF back to the calling party";
  33. static char *descrip =
  34. " Echo(): This application will echo any audio, video, or DTMF frames read from\n"
  35. "the calling channel back to itself. If the DTMF digit '#' is received, the\n"
  36. "application will exit.\n";
  37. static int echo_exec(struct ast_channel *chan, void *data)
  38. {
  39. int res = -1;
  40. int format;
  41. format = ast_best_codec(chan->nativeformats);
  42. ast_set_write_format(chan, format);
  43. ast_set_read_format(chan, format);
  44. while (ast_waitfor(chan, -1) > -1) {
  45. struct ast_frame *f = ast_read(chan);
  46. if (!f) {
  47. break;
  48. }
  49. f->delivery.tv_sec = 0;
  50. f->delivery.tv_usec = 0;
  51. if (ast_write(chan, f)) {
  52. ast_frfree(f);
  53. goto end;
  54. }
  55. if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '#')) {
  56. res = 0;
  57. ast_frfree(f);
  58. goto end;
  59. }
  60. ast_frfree(f);
  61. }
  62. end:
  63. return res;
  64. }
  65. static int unload_module(void)
  66. {
  67. return ast_unregister_application(app);
  68. }
  69. static int load_module(void)
  70. {
  71. return ast_register_application(app, echo_exec, synopsis, descrip);
  72. }
  73. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");