app_echo.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /*** MODULEINFO
  27. <support_level>core</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  31. #include "asterisk/file.h"
  32. #include "asterisk/module.h"
  33. #include "asterisk/channel.h"
  34. /*** DOCUMENTATION
  35. <application name="Echo" language="en_US">
  36. <synopsis>
  37. Echo media, DTMF back to the calling party
  38. </synopsis>
  39. <syntax />
  40. <description>
  41. <para>Echos back any media or DTMF frames read from the calling
  42. channel back to itself. This will not echo CONTROL, MODEM, or NULL
  43. frames. Note: If '#' detected application exits.</para>
  44. <para>This application does not automatically answer and should be
  45. preceeded by an application such as Answer() or Progress().</para>
  46. </description>
  47. </application>
  48. ***/
  49. static const char app[] = "Echo";
  50. static int echo_exec(struct ast_channel *chan, const char *data)
  51. {
  52. int res = -1;
  53. while (ast_waitfor(chan, -1) > -1) {
  54. struct ast_frame *f = ast_read(chan);
  55. if (!f) {
  56. break;
  57. }
  58. f->delivery.tv_sec = 0;
  59. f->delivery.tv_usec = 0;
  60. if (f->frametype != AST_FRAME_CONTROL
  61. && f->frametype != AST_FRAME_MODEM
  62. && f->frametype != AST_FRAME_NULL
  63. && ast_write(chan, f)) {
  64. ast_frfree(f);
  65. goto end;
  66. }
  67. if ((f->frametype == AST_FRAME_DTMF) && (f->subclass.integer == '#')) {
  68. res = 0;
  69. ast_frfree(f);
  70. goto end;
  71. }
  72. ast_frfree(f);
  73. }
  74. end:
  75. return res;
  76. }
  77. static int unload_module(void)
  78. {
  79. return ast_unregister_application(app);
  80. }
  81. static int load_module(void)
  82. {
  83. return ast_register_application_xml(app, echo_exec);
  84. }
  85. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");