Asterisk - The Open Source Telephony Project  18.5.0
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 <[email protected]>
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 <[email protected]>
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  <synopsis>
41  Echo media, DTMF back to the calling party
42  </synopsis>
43  <syntax />
44  <description>
45  <para>Echos back any media or DTMF frames read from the calling
46  channel back to itself. This will not echo CONTROL, MODEM, or NULL
47  frames. Note: If '#' detected application exits.</para>
48  <para>This application does not automatically answer and should be
49  preceeded by an application such as Answer() or Progress().</para>
50  </description>
51  </application>
52  ***/
53 
54 static const char app[] = "Echo";
55 
56 static int echo_exec(struct ast_channel *chan, const char *data)
57 {
58  int res = -1;
59  int fir_sent = 0;
60 
61  while (ast_waitfor(chan, -1) > -1) {
62  struct ast_frame *f = ast_read(chan);
63  if (!f) {
64  break;
65  }
66  f->delivery.tv_sec = 0;
67  f->delivery.tv_usec = 0;
70  && !fir_sent) {
71  if (ast_write(chan, f) < 0) {
72  ast_frfree(f);
73  goto end;
74  }
75  fir_sent = 1;
76  }
77  if (!fir_sent && f->frametype == AST_FRAME_VIDEO) {
78  struct ast_frame frame = {
80  .subclass.integer = AST_CONTROL_VIDUPDATE,
81  };
82  ast_write(chan, &frame);
83  fir_sent = 1;
84  }
86  && f->frametype != AST_FRAME_MODEM
87  && f->frametype != AST_FRAME_NULL
88  && ast_write(chan, f)) {
89  ast_frfree(f);
90  goto end;
91  }
92  if ((f->frametype == AST_FRAME_DTMF) && (f->subclass.integer == '#')) {
93  res = 0;
94  ast_frfree(f);
95  goto end;
96  }
97  ast_frfree(f);
98  }
99 end:
100  return res;
101 }
102 
103 static int unload_module(void)
104 {
106 }
107 
108 static int load_module(void)
109 {
111 }
112 
113 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");
Main Channel structure associated with a channel.
static int echo_exec(struct ast_channel *chan, const char *data)
Definition: app_echo.c:56
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:567
Asterisk main include file. File version handling, generic pbx functions.
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4302
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
char * end
Definition: eagi_proxy.c:73
#define AST_FRAME_DTMF
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
struct ast_frame_subclass subclass
General Asterisk PBX channel definitions.
static const char app[]
Definition: app_echo.c:54
static int unload_module(void)
Definition: app_echo.c:103
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:5189
struct timeval delivery
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3171
#define ast_frfree(fr)
Data structure associated with a single frame of data.
enum ast_frame_type frametype
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
static int load_module(void)
Definition: app_echo.c:108
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626