Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
app_echo.c
Go to the documentation of this file.
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
19/*! \file
20 *
21 * \brief Echo application -- play back what you hear to evaluate latency
22 *
23 * \author Mark Spencer <markster@digium.com>
24 *
25 * \ingroup applications
26 */
27
28/*** MODULEINFO
29 <support_level>core</support_level>
30 ***/
31
32#include "asterisk.h"
33
34#include "asterisk/file.h"
35#include "asterisk/module.h"
36#include "asterisk/channel.h"
37
38/*** DOCUMENTATION
39 <application name="Echo" language="en_US">
40 <since>
41 <version>0.1.2</version>
42 </since>
43 <synopsis>
44 Echo media, DTMF back to the calling party
45 </synopsis>
46 <syntax />
47 <description>
48 <para>Echos back any media or DTMF frames read from the calling
49 channel back to itself. This will not echo CONTROL, MODEM, or NULL
50 frames. Note: If '#' detected application exits.</para>
51 <para>This application does not automatically answer and should be
52 preceeded by an application such as Answer() or Progress().</para>
53 </description>
54 </application>
55 ***/
56
57static const char app[] = "Echo";
58
59static int echo_exec(struct ast_channel *chan, const char *data)
60{
61 int res = -1;
62 int fir_sent = 0;
63
64 while (ast_waitfor(chan, -1) > -1) {
65 struct ast_frame *f = ast_read(chan);
66 if (!f) {
67 break;
68 }
69 f->delivery.tv_sec = 0;
70 f->delivery.tv_usec = 0;
73 && !fir_sent) {
74 if (ast_write(chan, f) < 0) {
75 ast_frfree(f);
76 goto end;
77 }
78 fir_sent = 1;
79 }
80 if (!fir_sent && f->frametype == AST_FRAME_VIDEO) {
81 struct ast_frame frame = {
83 .subclass.integer = AST_CONTROL_VIDUPDATE,
84 };
85 ast_write(chan, &frame);
86 fir_sent = 1;
87 }
91 && ast_write(chan, f)) {
92 ast_frfree(f);
93 goto end;
94 }
95 if ((f->frametype == AST_FRAME_DTMF) && (f->subclass.integer == '#')) {
96 res = 0;
97 ast_frfree(f);
98 goto end;
99 }
100 ast_frfree(f);
101 }
102end:
103 return res;
104}
105
106static int unload_module(void)
107{
109}
110
111static int load_module(void)
112{
114}
115
116AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");
static int echo_exec(struct ast_channel *chan, const char *data)
Definition: app_echo.c:59
static const char app[]
Definition: app_echo.c:57
static int load_module(void)
Definition: app_echo.c:111
static int unload_module(void)
Definition: app_echo.c:106
Asterisk main include file. File version handling, generic pbx functions.
General Asterisk PBX channel definitions.
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3190
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:5161
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4274
char * end
Definition: eagi_proxy.c:73
Generic File Format Support. Should be included by clients of the file handling routines....
#define AST_FRAME_DTMF
#define ast_frfree(fr)
@ AST_FRAME_VIDEO
@ AST_FRAME_NULL
@ AST_FRAME_MODEM
@ AST_FRAME_CONTROL
@ AST_CONTROL_VIDUPDATE
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
Main Channel structure associated with a channel.
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
struct timeval delivery
enum ast_frame_type frametype