| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 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 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
static 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")) { |
| 138 |
mute_direction = AST_MUTE_DIRECTION_READ | AST_MUTE_DIRECTION_WRITE; |
| 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 |
|
| 157 |
static 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 |
|
| 168 |
static struct ast_custom_function mute_function = { |
| 169 |
.name = "MUTEAUDIO", |
| 170 |
.write = func_mute_write, |
| 171 |
}; |
| 172 |
|
| 173 |
static 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 |
} |
| 190 |
if (ast_strlen_zero(direction)) { |
| 191 |
astman_send_error(s, m, "Direction not specified"); |
| 192 |
return 0; |
| 193 |
} |
| 194 |
|
| 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 |
|
| 202 |
if (mute_channel(c, direction, ast_true(state))) { |
| 203 |
astman_send_error(s, m, "Failed to mute/unmute stream"); |
| 204 |
ast_channel_unref(c); |
| 205 |
return 0; |
| 206 |
} |
| 207 |
|
| 208 |
ast_channel_unref(c); |
| 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 |
|
| 222 |
static int load_module(void) |
| 223 |
{ |
| 224 |
int res; |
| 225 |
|
| 226 |
res = ast_custom_function_register(&mute_function); |
| 227 |
res |= ast_manager_register_xml("MuteAudio", EVENT_FLAG_SYSTEM, manager_mutestream); |
| 228 |
|
| 229 |
return (res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS); |
| 230 |
} |
| 231 |
|
| 232 |
static int unload_module(void) |
| 233 |
{ |
| 234 |
ast_custom_function_unregister(&mute_function); |
| 235 |
|
| 236 |
ast_manager_unregister("MuteAudio"); |
| 237 |
|
| 238 |
return 0; |
| 239 |
} |
| 240 |
|
| 241 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Mute audio stream resources"); |