Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Functions | Variables
res_mutestream.c File Reference

MUTESTREAM audiohooks. More...

#include "asterisk.h"
#include "asterisk/options.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/file.h"
#include "asterisk/pbx.h"
#include "asterisk/frame.h"
#include "asterisk/utils.h"
#include "asterisk/audiohook.h"
#include "asterisk/manager.h"
Include dependency graph for res_mutestream.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int func_mute_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 Mute dialplan function. More...
 
static int load_module (void)
 
static int manager_mutestream (struct mansession *s, const struct message *m)
 
static int mute_channel (struct ast_channel *chan, const char *direction, int mute)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Mute audio stream resources" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function mute_function
 

Detailed Description

MUTESTREAM audiohooks.

Author
Olle E. Johansson oej@e.nosp@m.dvin.nosp@m.a.net
Note
This module only handles audio streams today, but can easily be appended to also zero out text streams if there's an application for it. When we know and understand what happens if we zero out video, we can do that too.

Definition in file res_mutestream.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 241 of file res_mutestream.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 241 of file res_mutestream.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 241 of file res_mutestream.c.

◆ func_mute_write()

static int func_mute_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)
static

Mute dialplan function.

Definition at line 157 of file res_mutestream.c.

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}
#define ast_log
Definition: astobj2.c:42
#define LOG_WARNING
static int mute_channel(struct ast_channel *chan, const char *direction, int mute)
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
int value
Definition: syslog.c:37

References ast_log, ast_true(), LOG_WARNING, mute_channel(), and value.

◆ load_module()

static int load_module ( void  )
static

Definition at line 222 of file res_mutestream.c.

223{
224 int res;
225
228
230}
#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
@ 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
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1559
static struct ast_custom_function mute_function
static int manager_mutestream(struct mansession *s, const struct message *m)

References ast_custom_function_register, ast_manager_register_xml, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, EVENT_FLAG_SYSTEM, manager_mutestream(), and mute_function.

◆ manager_mutestream()

static int manager_mutestream ( struct mansession s,
const struct message m 
)
static

Definition at line 173 of file res_mutestream.c.

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}
struct ast_channel * ast_channel_get_by_name(const char *search)
Find a channel by name or uniqueid.
Definition: channel.c:1397
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:3008
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
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.
static struct test_val c

References ast_channel_get_by_name(), ast_channel_unref, ast_strlen_zero(), ast_true(), astman_append(), astman_get_header(), astman_send_error(), c, mute_channel(), and NULL.

Referenced by load_module().

◆ mute_channel()

static int mute_channel ( struct ast_channel chan,
const char *  direction,
int  mute 
)
static

Definition at line 127 of file res_mutestream.c.

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}
#define ast_channel_lock(chan)
Definition: channel.h:2972
#define AST_MUTE_DIRECTION_READ
Definition: channel.h:4790
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:10782
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:10844
#define AST_MUTE_DIRECTION_WRITE
Definition: channel.h:4791
#define ast_channel_unlock(chan)
Definition: channel.h:2973
ast_frame_type
Frame types.
@ AST_FRAME_VOICE

References ast_channel_lock, ast_channel_suppress(), ast_channel_unlock, ast_channel_unsuppress(), AST_FRAME_VOICE, AST_MUTE_DIRECTION_READ, and AST_MUTE_DIRECTION_WRITE.

Referenced by func_mute_write(), and manager_mutestream().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 232 of file res_mutestream.c.

233{
235 /* Unregister AMI actions */
236 ast_manager_unregister("MuteAudio");
237
238 return 0;
239}
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7697
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), ast_manager_unregister(), and mute_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Mute audio stream resources" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 241 of file res_mutestream.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 241 of file res_mutestream.c.

◆ mute_function

struct ast_custom_function mute_function
static
Initial value:
= {
.name = "MUTEAUDIO",
.write = func_mute_write,
}
static int func_mute_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
Mute dialplan function.

Definition at line 168 of file res_mutestream.c.

Referenced by load_module(), and unload_module().