app_echo.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. * \ingroup applications
  23. */
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <unistd.h>
  27. #include <string.h>
  28. #include "asterisk.h"
  29. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  30. #include "asterisk/lock.h"
  31. #include "asterisk/file.h"
  32. #include "asterisk/logger.h"
  33. #include "asterisk/channel.h"
  34. #include "asterisk/pbx.h"
  35. #include "asterisk/module.h"
  36. static char *tdesc = "Simple Echo Application";
  37. static char *app = "Echo";
  38. static char *synopsis = "Echo audio read back to the user";
  39. static char *descrip =
  40. " Echo(): Echo audio read from channel back to the channel. \n"
  41. "User can exit the application by either pressing the '#' key, \n"
  42. "or hanging up.\n";
  43. STANDARD_LOCAL_USER;
  44. LOCAL_USER_DECL;
  45. static int echo_exec(struct ast_channel *chan, void *data)
  46. {
  47. int res=-1;
  48. struct localuser *u;
  49. struct ast_frame *f;
  50. LOCAL_USER_ADD(u);
  51. ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
  52. ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
  53. /* Do our thing here */
  54. while(ast_waitfor(chan, -1) > -1) {
  55. f = ast_read(chan);
  56. if (!f)
  57. break;
  58. f->delivery.tv_sec = 0;
  59. f->delivery.tv_usec = 0;
  60. if (f->frametype == AST_FRAME_VOICE) {
  61. if (ast_write(chan, f))
  62. break;
  63. } else if (f->frametype == AST_FRAME_VIDEO) {
  64. if (ast_write(chan, f))
  65. break;
  66. } else if (f->frametype == AST_FRAME_DTMF) {
  67. if (f->subclass == '#') {
  68. res = 0;
  69. break;
  70. } else
  71. if (ast_write(chan, f))
  72. break;
  73. }
  74. ast_frfree(f);
  75. }
  76. LOCAL_USER_REMOVE(u);
  77. return res;
  78. }
  79. int unload_module(void)
  80. {
  81. int res;
  82. res = ast_unregister_application(app);
  83. STANDARD_HANGUP_LOCALUSERS;
  84. return res;
  85. }
  86. int load_module(void)
  87. {
  88. return ast_register_application(app, echo_exec, synopsis, descrip);
  89. }
  90. char *description(void)
  91. {
  92. return tdesc;
  93. }
  94. int usecount(void)
  95. {
  96. int res;
  97. STANDARD_USECOUNT(res);
  98. return res;
  99. }
  100. char *key()
  101. {
  102. return ASTERISK_GPL_KEY;
  103. }