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 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <unistd.h>
00029 #include <string.h>
00030
00031 #include "asterisk.h"
00032
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00034
00035 #include "asterisk/lock.h"
00036 #include "asterisk/file.h"
00037 #include "asterisk/logger.h"
00038 #include "asterisk/channel.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/module.h"
00041
00042 static char *tdesc = "Simple Echo Application";
00043
00044 static char *app = "Echo";
00045
00046 static char *synopsis = "Echo audio read back to the user";
00047
00048 static char *descrip =
00049 " Echo(): Echo audio read from channel back to the channel. \n"
00050 "User can exit the application by either pressing the '#' key, \n"
00051 "or hanging up.\n";
00052
00053 STANDARD_LOCAL_USER;
00054
00055 LOCAL_USER_DECL;
00056
00057 static int echo_exec(struct ast_channel *chan, void *data)
00058 {
00059 int res=-1;
00060 struct localuser *u;
00061 struct ast_frame *f;
00062 LOCAL_USER_ADD(u);
00063 ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
00064 ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
00065
00066 while(ast_waitfor(chan, -1) > -1) {
00067 f = ast_read(chan);
00068 if (!f)
00069 break;
00070 f->delivery.tv_sec = 0;
00071 f->delivery.tv_usec = 0;
00072 if (f->frametype == AST_FRAME_VOICE) {
00073 if (ast_write(chan, f))
00074 break;
00075 } else if (f->frametype == AST_FRAME_VIDEO) {
00076 if (ast_write(chan, f))
00077 break;
00078 } else if (f->frametype == AST_FRAME_DTMF) {
00079 if (f->subclass == '#') {
00080 res = 0;
00081 break;
00082 } else
00083 if (ast_write(chan, f))
00084 break;
00085 }
00086 ast_frfree(f);
00087 }
00088 LOCAL_USER_REMOVE(u);
00089 return res;
00090 }
00091
00092 int unload_module(void)
00093 {
00094 int res;
00095
00096 res = ast_unregister_application(app);
00097
00098 STANDARD_HANGUP_LOCALUSERS;
00099
00100 return res;
00101 }
00102
00103 int load_module(void)
00104 {
00105 return ast_register_application(app, echo_exec, synopsis, descrip);
00106 }
00107
00108 char *description(void)
00109 {
00110 return tdesc;
00111 }
00112
00113 int usecount(void)
00114 {
00115 int res;
00116 STANDARD_USECOUNT(res);
00117 return res;
00118 }
00119
00120 char *key()
00121 {
00122 return ASTERISK_GPL_KEY;
00123 }