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: 249946 $")
00031
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <unistd.h>
00035 #include <string.h>
00036
00037 #include "asterisk/lock.h"
00038 #include "asterisk/file.h"
00039 #include "asterisk/logger.h"
00040 #include "asterisk/channel.h"
00041 #include "asterisk/pbx.h"
00042 #include "asterisk/module.h"
00043
00044 static char *app = "Echo";
00045
00046 static char *synopsis = "Echo audio, video, or DTMF back to the calling party";
00047
00048 static char *descrip =
00049 " Echo(): This application will echo any audio, video, or DTMF frames read from\n"
00050 "the calling channel back to itself. If the DTMF digit '#' is received, the\n"
00051 "application will exit.\n";
00052
00053
00054 static int echo_exec(struct ast_channel *chan, void *data)
00055 {
00056 int res = -1;
00057 int format;
00058 struct ast_module_user *u;
00059
00060 u = ast_module_user_add(chan);
00061
00062 format = ast_best_codec(chan->nativeformats);
00063 ast_set_write_format(chan, format);
00064 ast_set_read_format(chan, format);
00065
00066 while (ast_waitfor(chan, -1) > -1) {
00067 struct ast_frame *f = ast_read(chan);
00068 if (!f) {
00069 break;
00070 }
00071 f->delivery.tv_sec = 0;
00072 f->delivery.tv_usec = 0;
00073 if (ast_write(chan, f)) {
00074 ast_frfree(f);
00075 goto end;
00076 }
00077 if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '#')) {
00078 res = 0;
00079 ast_frfree(f);
00080 goto end;
00081 }
00082 ast_frfree(f);
00083 }
00084 end:
00085 ast_module_user_remove(u);
00086 return res;
00087 }
00088
00089 static int unload_module(void)
00090 {
00091 int res;
00092
00093 res = ast_unregister_application(app);
00094
00095 ast_module_user_hangup_all();
00096
00097 return res;
00098 }
00099
00100 static int load_module(void)
00101 {
00102 return ast_register_application(app, echo_exec, synopsis, descrip);
00103 }
00104
00105 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");