app_echo.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. int fir_sent = 0;
  54. while (ast_waitfor(chan, -1) > -1) {
  55. struct ast_frame *f = ast_read(chan);
  56. if (!f) {
  57. break;
  58. }
  59. f->delivery.tv_sec = 0;
  60. f->delivery.tv_usec = 0;
  61. if (f->frametype == AST_FRAME_CONTROL
  62. && f->subclass.integer == AST_CONTROL_VIDUPDATE
  63. && !fir_sent) {
  64. if (ast_write(chan, f) < 0) {
  65. ast_frfree(f);
  66. goto end;
  67. }
  68. fir_sent = 1;
  69. }
  70. if (!fir_sent && f->frametype == AST_FRAME_VIDEO) {
  71. struct ast_frame frame = {
  72. .frametype = AST_FRAME_CONTROL,
  73. .subclass.integer = AST_CONTROL_VIDUPDATE,
  74. };
  75. ast_write(chan, &frame);
  76. fir_sent = 1;
  77. }
  78. if (f->frametype != AST_FRAME_CONTROL
  79. && f->frametype != AST_FRAME_MODEM
  80. && f->frametype != AST_FRAME_NULL
  81. && ast_write(chan, f)) {
  82. ast_frfree(f);
  83. goto end;
  84. }
  85. if ((f->frametype == AST_FRAME_DTMF) && (f->subclass.integer == '#')) {
  86. res = 0;
  87. ast_frfree(f);
  88. goto end;
  89. }
  90. ast_frfree(f);
  91. }
  92. end:
  93. return res;
  94. }
  95. static int unload_module(void)
  96. {
  97. return ast_unregister_application(app);
  98. }
  99. static int load_module(void)
  100. {
  101. return ast_register_application_xml(app, echo_exec);
  102. }
  103. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");