app_echo.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 149589 $")
00031
00032 #include "asterisk/file.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/channel.h"
00035
00036 static char *app = "Echo";
00037
00038 static char *synopsis = "Echo audio, video, or DTMF back to the calling party";
00039
00040 static char *descrip =
00041 " Echo(): This application will echo any audio, video, or DTMF frames read from\n"
00042 "the calling channel back to itself. If the DTMF digit '#' is received, the\n"
00043 "application will exit.\n";
00044
00045
00046 static int echo_exec(struct ast_channel *chan, void *data)
00047 {
00048 int res = -1;
00049 int format;
00050
00051 format = ast_best_codec(chan->nativeformats);
00052 ast_set_write_format(chan, format);
00053 ast_set_read_format(chan, format);
00054
00055 while (ast_waitfor(chan, -1) > -1) {
00056 struct ast_frame *f = ast_read(chan);
00057 if (!f) {
00058 break;
00059 }
00060 f->delivery.tv_sec = 0;
00061 f->delivery.tv_usec = 0;
00062 if (ast_write(chan, f)) {
00063 ast_frfree(f);
00064 goto end;
00065 }
00066 if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '#')) {
00067 res = 0;
00068 ast_frfree(f);
00069 goto end;
00070 }
00071 ast_frfree(f);
00072 }
00073 end:
00074 return res;
00075 }
00076
00077 static int unload_module(void)
00078 {
00079 return ast_unregister_application(app);
00080 }
00081
00082 static int load_module(void)
00083 {
00084 return ast_register_application(app, echo_exec, synopsis, descrip);
00085 }
00086
00087 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");