Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
res_mutestream.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2009, Olle E. Johansson
5 *
6 * Olle E. Johansson <oej@edvina.net>
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 MUTESTREAM audiohooks
22 *
23 * \author Olle E. Johansson <oej@edvina.net>
24 *
25 * \ingroup functions
26 *
27 * \note This module only handles audio streams today, but can easily be appended to also
28 * zero out text streams if there's an application for it.
29 * When we know and understand what happens if we zero out video, we can do that too.
30 */
31
32/*** MODULEINFO
33 <support_level>core</support_level>
34 ***/
35
36#include "asterisk.h"
37
38#include "asterisk/options.h"
39#include "asterisk/logger.h"
40#include "asterisk/channel.h"
41#include "asterisk/module.h"
42#include "asterisk/config.h"
43#include "asterisk/file.h"
44#include "asterisk/pbx.h"
45#include "asterisk/frame.h"
46#include "asterisk/utils.h"
47#include "asterisk/audiohook.h"
48#include "asterisk/manager.h"
49
50/*** DOCUMENTATION
51 <function name="MUTEAUDIO" language="en_US">
52 <since>
53 <version>1.8.0</version>
54 </since>
55 <synopsis>
56 Muting audio streams in the channel
57 </synopsis>
58 <syntax>
59 <parameter name="direction" required="true">
60 <para>Must be one of </para>
61 <enumlist>
62 <enum name="in">
63 <para>Inbound stream (to the PBX)</para>
64 </enum>
65 <enum name="out">
66 <para>Outbound stream (from the PBX)</para>
67 </enum>
68 <enum name="all">
69 <para>Both streams</para>
70 </enum>
71 </enumlist>
72 </parameter>
73 </syntax>
74 <description>
75 <para>The MUTEAUDIO function can be used to mute inbound (to the PBX) or outbound audio in a call.</para>
76 <example title="Mute incoming audio">
77 exten => s,1,Set(MUTEAUDIO(in)=on)
78 </example>
79 <example title="Do not mute incoming audio">
80 exten => s,1,Set(MUTEAUDIO(in)=off)
81 </example>
82 </description>
83 </function>
84 <manager name="MuteAudio" language="en_US">
85 <since>
86 <version>1.8.0</version>
87 </since>
88 <synopsis>
89 Mute an audio stream.
90 </synopsis>
91 <syntax>
92 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
93 <parameter name="Channel" required="true">
94 <para>The channel you want to mute.</para>
95 </parameter>
96 <parameter name="Direction" required="true">
97 <enumlist>
98 <enum name="in">
99 <para>Set muting on inbound audio stream. (to the PBX)</para>
100 </enum>
101 <enum name="out">
102 <para>Set muting on outbound audio stream. (from the PBX)</para>
103 </enum>
104 <enum name="all">
105 <para>Set muting on inbound and outbound audio streams.</para>
106 </enum>
107 </enumlist>
108 </parameter>
109 <parameter name="State" required="true">
110 <enumlist>
111 <enum name="on">
112 <para>Turn muting on.</para>
113 </enum>
114 <enum name="off">
115 <para>Turn muting off.</para>
116 </enum>
117 </enumlist>
118 </parameter>
119 </syntax>
120 <description>
121 <para>Mute an incoming or outgoing audio stream on a channel.</para>
122 </description>
123 </manager>
124 ***/
125
126
127static int mute_channel(struct ast_channel *chan, const char *direction, int mute)
128{
129 unsigned int mute_direction = 0;
130 enum ast_frame_type frametype = AST_FRAME_VOICE;
131 int ret = 0;
132
133 if (!strcmp(direction, "in")) {
134 mute_direction = AST_MUTE_DIRECTION_READ;
135 } else if (!strcmp(direction, "out")) {
136 mute_direction = AST_MUTE_DIRECTION_WRITE;
137 } else if (!strcmp(direction, "all")) {
139 } else {
140 return -1;
141 }
142
143 ast_channel_lock(chan);
144
145 if (mute) {
146 ret = ast_channel_suppress(chan, mute_direction, frametype);
147 } else {
148 ret = ast_channel_unsuppress(chan, mute_direction, frametype);
149 }
150
151 ast_channel_unlock(chan);
152
153 return ret;
154}
155
156/*! \brief Mute dialplan function */
157static int func_mute_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
158{
159 if (!chan) {
160 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
161 return -1;
162 }
163
164 return mute_channel(chan, data, ast_true(value));
165}
166
167/* Function for debugging - might be useful */
169 .name = "MUTEAUDIO",
170 .write = func_mute_write,
171};
172
173static int manager_mutestream(struct mansession *s, const struct message *m)
174{
175 const char *channel = astman_get_header(m, "Channel");
176 const char *id = astman_get_header(m,"ActionID");
177 const char *state = astman_get_header(m,"State");
178 const char *direction = astman_get_header(m,"Direction");
179 char id_text[256];
180 struct ast_channel *c = NULL;
181
182 if (ast_strlen_zero(channel)) {
183 astman_send_error(s, m, "Channel not specified");
184 return 0;
185 }
186 if (ast_strlen_zero(state)) {
187 astman_send_error(s, m, "State not specified");
188 return 0;
189 }
191 astman_send_error(s, m, "Direction not specified");
192 return 0;
193 }
194 /* Ok, we have everything */
195
196 c = ast_channel_get_by_name(channel);
197 if (!c) {
198 astman_send_error(s, m, "No such channel");
199 return 0;
200 }
201
203 astman_send_error(s, m, "Failed to mute/unmute stream");
205 return 0;
206 }
207
209
210 if (!ast_strlen_zero(id)) {
211 snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id);
212 } else {
213 id_text[0] = '\0';
214 }
215 astman_append(s, "Response: Success\r\n"
216 "%s"
217 "\r\n", id_text);
218 return 0;
219}
220
221
222static int load_module(void)
223{
224 int res;
225
228
230}
231
232static int unload_module(void)
233{
235 /* Unregister AMI actions */
236 ast_manager_unregister("MuteAudio");
237
238 return 0;
239}
240
241AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Mute audio stream resources");
Asterisk main include file. File version handling, generic pbx functions.
#define ast_log
Definition: astobj2.c:42
Audiohooks Architecture.
General Asterisk PBX channel definitions.
#define ast_channel_lock(chan)
Definition: channel.h:2970
#define AST_MUTE_DIRECTION_READ
Definition: channel.h:4762
int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
Suppress passing of a frame type on a channel.
Definition: channel.c:10803
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:3006
int ast_channel_unsuppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
Stop suppressing of a frame type on a channel.
Definition: channel.c:10865
#define AST_MUTE_DIRECTION_WRITE
Definition: channel.h:4763
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1481
#define ast_channel_unlock(chan)
Definition: channel.h:2971
Generic File Format Support. Should be included by clients of the file handling routines....
direction
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:1986
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition: manager.c:1647
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:1907
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7697
Configuration File Parser.
Asterisk internal frame definitions.
ast_frame_type
Frame types.
@ AST_FRAME_VOICE
Support for logging to various files, console and syslog Configuration in file logger....
#define LOG_WARNING
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define EVENT_FLAG_SYSTEM
Definition: manager.h:75
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:192
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
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
Options provided by main asterisk program.
Core PBX routines and definitions.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1559
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static int mute_channel(struct ast_channel *chan, const char *direction, int mute)
static int func_mute_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
Mute dialplan function.
static struct ast_custom_function mute_function
static int load_module(void)
static int unload_module(void)
static int manager_mutestream(struct mansession *s, const struct message *m)
#define NULL
Definition: resample.c:96
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
In case you didn't read that giant block of text above the mansession_session struct,...
Definition: manager.c:327
int value
Definition: syslog.c:37
static struct test_val c
Utility functions.