Mon Mar 19 11:30:20 2012

Asterisk developer's documentation


app_echo.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief Echo application -- play back what you hear to evaluate latency
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  *
00025  * \ingroup applications
00026  */
00027 
00028 /*** MODULEINFO
00029    <support_level>core</support_level>
00030  ***/
00031 
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 336716 $")
00035 
00036 #include "asterisk/file.h"
00037 #include "asterisk/module.h"
00038 #include "asterisk/channel.h"
00039 
00040 /*** DOCUMENTATION
00041    <application name="Echo" language="en_US">
00042       <synopsis>
00043          Echo audio, video, DTMF back to the calling party
00044       </synopsis>
00045       <syntax />
00046       <description>
00047          <para>Echos back any audio, video or DTMF frames read from the calling 
00048          channel back to itself. Note: If '#' detected application exits</para>
00049          <para>This application does not automatically answer and should be
00050          preceeded by an application such as Answer() or Progress().</para>
00051       </description>
00052    </application>
00053  ***/
00054 
00055 static const char app[] = "Echo";
00056 
00057 static int echo_exec(struct ast_channel *chan, const char *data)
00058 {
00059    int res = -1;
00060    format_t format;
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.integer == '#')) {
00078          res = 0;
00079          ast_frfree(f);
00080          goto end;
00081       }
00082       ast_frfree(f);
00083    }
00084 end:
00085    return res;
00086 }
00087 
00088 static int unload_module(void)
00089 {
00090    return ast_unregister_application(app);
00091 }
00092 
00093 static int load_module(void)
00094 {
00095    return ast_register_application_xml(app, echo_exec);
00096 }
00097 
00098 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");

Generated on Mon Mar 19 11:30:20 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7