|
|
@ -123,149 +123,39 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
***/
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! Our own datastore */
|
|
|
|
static int mute_channel(struct ast_channel *chan, const char *direction, int mute)
|
|
|
|
struct mute_information {
|
|
|
|
|
|
|
|
struct ast_audiohook audiohook;
|
|
|
|
|
|
|
|
int mute_write;
|
|
|
|
|
|
|
|
int mute_read;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! Datastore destroy audiohook callback */
|
|
|
|
|
|
|
|
static void destroy_callback(void *data)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct mute_information *mute = data;
|
|
|
|
unsigned int mute_direction = 0;
|
|
|
|
|
|
|
|
enum ast_frame_type frametype = AST_FRAME_VOICE;
|
|
|
|
/* Destroy the audiohook, and destroy ourselves */
|
|
|
|
int ret = 0;
|
|
|
|
ast_audiohook_destroy(&mute->audiohook);
|
|
|
|
|
|
|
|
ast_free(mute);
|
|
|
|
if (!strcmp(direction, "in")) {
|
|
|
|
ast_module_unref(ast_module_info->self);
|
|
|
|
mute_direction = AST_MUTE_DIRECTION_READ;
|
|
|
|
}
|
|
|
|
} else if (!strcmp(direction, "out")) {
|
|
|
|
|
|
|
|
mute_direction = AST_MUTE_DIRECTION_WRITE;
|
|
|
|
/*! \brief Static structure for datastore information */
|
|
|
|
} else if (!strcmp(direction, "all")) {
|
|
|
|
static const struct ast_datastore_info mute_datastore = {
|
|
|
|
mute_direction = AST_MUTE_DIRECTION_READ | AST_MUTE_DIRECTION_WRITE;
|
|
|
|
.type = "mute",
|
|
|
|
} else {
|
|
|
|
.destroy = destroy_callback
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! \brief The callback from the audiohook subsystem. We basically get a frame to have fun with */
|
|
|
|
|
|
|
|
static int mute_callback(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
struct ast_datastore *datastore = NULL;
|
|
|
|
|
|
|
|
struct mute_information *mute = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* If the audiohook is stopping it means the channel is shutting down.... but we let the datastore destroy take care of it */
|
|
|
|
|
|
|
|
if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE) {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
/* Grab datastore which contains our mute information */
|
|
|
|
|
|
|
|
if (!(datastore = ast_channel_datastore_find(chan, &mute_datastore, NULL))) {
|
|
|
|
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
|
|
|
|
ast_debug(2, "Can't find any datastore to use. Bad. \n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mute = datastore->data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mute) {
|
|
|
|
/* If this is audio then allow them to increase/decrease the gains */
|
|
|
|
ret = ast_channel_suppress(chan, mute_direction, frametype);
|
|
|
|
if (frame->frametype == AST_FRAME_VOICE) {
|
|
|
|
} else {
|
|
|
|
ast_debug(2, "Audio frame - direction %s mute READ %s WRITE %s\n", direction == AST_AUDIOHOOK_DIRECTION_READ ? "read" : "write", mute->mute_read ? "on" : "off", mute->mute_write ? "on" : "off");
|
|
|
|
ret = ast_channel_unsuppress(chan, mute_direction, frametype);
|
|
|
|
|
|
|
|
|
|
|
|
/* Based on direction of frame grab the gain, and confirm it is applicable */
|
|
|
|
|
|
|
|
if ((direction == AST_AUDIOHOOK_DIRECTION_READ && mute->mute_read) || (direction == AST_AUDIOHOOK_DIRECTION_WRITE && mute->mute_write)) {
|
|
|
|
|
|
|
|
/* Ok, we just want to reset all audio in this frame. Keep NOTHING, thanks. */
|
|
|
|
|
|
|
|
ast_frame_clear(frame);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! \brief Initialize mute hook on channel, but don't activate it
|
|
|
|
|
|
|
|
\pre Assumes that the channel is locked
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct ast_datastore *initialize_mutehook(struct ast_channel *chan)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
struct ast_datastore *datastore = NULL;
|
|
|
|
|
|
|
|
struct mute_information *mute = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ast_debug(2, "Initializing new Mute Audiohook \n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Allocate a new datastore to hold the reference to this mute_datastore and audiohook information */
|
|
|
|
|
|
|
|
if (!(datastore = ast_datastore_alloc(&mute_datastore, NULL))) {
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!(mute = ast_calloc(1, sizeof(*mute)))) {
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
ast_datastore_free(datastore);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_audiohook_init(&mute->audiohook, AST_AUDIOHOOK_TYPE_MANIPULATE, "Mute", AST_AUDIOHOOK_MANIPULATE_ALL_RATES);
|
|
|
|
|
|
|
|
mute->audiohook.manipulate_callback = mute_callback;
|
|
|
|
|
|
|
|
datastore->data = mute;
|
|
|
|
|
|
|
|
return datastore;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! \brief Add or activate mute audiohook on channel
|
|
|
|
return ret;
|
|
|
|
Assumes channel is locked
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int mute_add_audiohook(struct ast_channel *chan, struct mute_information *mute, struct ast_datastore *datastore)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Activate the settings */
|
|
|
|
|
|
|
|
ast_channel_datastore_add(chan, datastore);
|
|
|
|
|
|
|
|
if (ast_audiohook_attach(chan, &mute->audiohook)) {
|
|
|
|
|
|
|
|
ast_log(LOG_ERROR, "Failed to attach audiohook for muting channel %s\n", ast_channel_name(chan));
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_module_ref(ast_module_info->self);
|
|
|
|
|
|
|
|
ast_debug(2, "Initialized audiohook on channel %s\n", ast_channel_name(chan));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*! \brief Mute dialplan function */
|
|
|
|
/*! \brief Mute dialplan function */
|
|
|
|
static int func_mute_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
|
|
|
|
static int func_mute_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct ast_datastore *datastore = NULL;
|
|
|
|
return mute_channel(chan, data, ast_true(value));
|
|
|
|
struct mute_information *mute = NULL;
|
|
|
|
|
|
|
|
int is_new = 0;
|
|
|
|
|
|
|
|
int turnon;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
|
|
|
|
if (!(datastore = ast_channel_datastore_find(chan, &mute_datastore, NULL))) {
|
|
|
|
|
|
|
|
if (!(datastore = initialize_mutehook(chan))) {
|
|
|
|
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
is_new = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mute = datastore->data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
turnon = ast_true(value);
|
|
|
|
|
|
|
|
if (!strcasecmp(data, "out")) {
|
|
|
|
|
|
|
|
mute->mute_write = turnon;
|
|
|
|
|
|
|
|
ast_debug(1, "%s channel - outbound \n", turnon ? "Muting" : "Unmuting");
|
|
|
|
|
|
|
|
} else if (!strcasecmp(data, "in")) {
|
|
|
|
|
|
|
|
mute->mute_read = turnon;
|
|
|
|
|
|
|
|
ast_debug(1, "%s channel - inbound \n", turnon ? "Muting" : "Unmuting");
|
|
|
|
|
|
|
|
} else if (!strcasecmp(data,"all")) {
|
|
|
|
|
|
|
|
mute->mute_write = mute->mute_read = turnon;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is_new) {
|
|
|
|
|
|
|
|
if (mute_add_audiohook(chan, mute, datastore)) {
|
|
|
|
|
|
|
|
/* Can't add audiohook - already printed error message */
|
|
|
|
|
|
|
|
ast_datastore_free(datastore);
|
|
|
|
|
|
|
|
ast_free(mute);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Function for debugging - might be useful */
|
|
|
|
/* Function for debugging - might be useful */
|
|
|
@ -282,10 +172,6 @@ static int manager_mutestream(struct mansession *s, const struct message *m)
|
|
|
|
const char *direction = astman_get_header(m,"Direction");
|
|
|
|
const char *direction = astman_get_header(m,"Direction");
|
|
|
|
char id_text[256];
|
|
|
|
char id_text[256];
|
|
|
|
struct ast_channel *c = NULL;
|
|
|
|
struct ast_channel *c = NULL;
|
|
|
|
struct ast_datastore *datastore = NULL;
|
|
|
|
|
|
|
|
struct mute_information *mute = NULL;
|
|
|
|
|
|
|
|
int is_new = 0;
|
|
|
|
|
|
|
|
int turnon;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ast_strlen_zero(channel)) {
|
|
|
|
if (ast_strlen_zero(channel)) {
|
|
|
|
astman_send_error(s, m, "Channel not specified");
|
|
|
|
astman_send_error(s, m, "Channel not specified");
|
|
|
@ -307,40 +193,12 @@ static int manager_mutestream(struct mansession *s, const struct message *m)
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ast_channel_lock(c);
|
|
|
|
if (mute_channel(c, direction, ast_true(state))) {
|
|
|
|
|
|
|
|
astman_send_error(s, m, "Failed to mute/unmute stream");
|
|
|
|
if (!(datastore = ast_channel_datastore_find(c, &mute_datastore, NULL))) {
|
|
|
|
ast_channel_unref(c);
|
|
|
|
if (!(datastore = initialize_mutehook(c))) {
|
|
|
|
return 0;
|
|
|
|
ast_channel_unlock(c);
|
|
|
|
|
|
|
|
ast_channel_unref(c);
|
|
|
|
|
|
|
|
astman_send_error(s, m, "Memory allocation failure");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
is_new = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mute = datastore->data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
turnon = ast_true(state);
|
|
|
|
|
|
|
|
if (!strcasecmp(direction, "in")) {
|
|
|
|
|
|
|
|
mute->mute_read = turnon;
|
|
|
|
|
|
|
|
} else if (!strcasecmp(direction, "out")) {
|
|
|
|
|
|
|
|
mute->mute_write = turnon;
|
|
|
|
|
|
|
|
} else if (!strcasecmp(direction, "all")) {
|
|
|
|
|
|
|
|
mute->mute_read = mute->mute_write = turnon;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (is_new) {
|
|
|
|
|
|
|
|
if (mute_add_audiohook(c, mute, datastore)) {
|
|
|
|
|
|
|
|
/* Can't add audiohook */
|
|
|
|
|
|
|
|
ast_datastore_free(datastore);
|
|
|
|
|
|
|
|
ast_free(mute);
|
|
|
|
|
|
|
|
ast_channel_unlock(c);
|
|
|
|
|
|
|
|
ast_channel_unref(c);
|
|
|
|
|
|
|
|
astman_send_error(s, m, "Couldn't add mute audiohook");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_channel_unlock(c);
|
|
|
|
|
|
|
|
ast_channel_unref(c);
|
|
|
|
ast_channel_unref(c);
|
|
|
|
|
|
|
|
|
|
|
|
if (!ast_strlen_zero(id)) {
|
|
|
|
if (!ast_strlen_zero(id)) {
|
|
|
|