summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
authorJason Parker <jparker@digium.com>2013-07-18 16:03:12 +0000
committerJason Parker <jparker@digium.com>2013-07-18 16:03:12 +0000
commitc1a7567d24a08377438837ed26b1f8a886867c10 (patch)
tree4e137b98205c9c96b590b3707ec81c69df84f96b /res
parent3a2a12ca1ad8097482fe621e8b877db682601905 (diff)
ARI: Add support for suppressing media streams.
Also convert res_mutestream to use the core feature behind this. (closes issue ASTERISK-21618) Review: https://reviewboard.asterisk.org/r/2652/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@394715 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res')
-rw-r--r--res/res_mutestream.c190
-rw-r--r--res/stasis/control.c60
-rw-r--r--res/stasis_http/resource_channels.c54
3 files changed, 136 insertions, 168 deletions
diff --git a/res/res_mutestream.c b/res/res_mutestream.c
index f7032eacf..b907fbe3a 100644
--- a/res/res_mutestream.c
+++ b/res/res_mutestream.c
@@ -123,149 +123,39 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
***/
-/*! Our own datastore */
-struct mute_information {
- struct ast_audiohook audiohook;
- int mute_write;
- int mute_read;
-};
-
-
-/*! Datastore destroy audiohook callback */
-static void destroy_callback(void *data)
+static int mute_channel(struct ast_channel *chan, const char *direction, int mute)
{
- struct mute_information *mute = data;
-
- /* Destroy the audiohook, and destroy ourselves */
- ast_audiohook_destroy(&mute->audiohook);
- ast_free(mute);
- ast_module_unref(ast_module_info->self);
-}
-
-/*! \brief Static structure for datastore information */
-static const struct ast_datastore_info mute_datastore = {
- .type = "mute",
- .destroy = destroy_callback
-};
-
-/*! \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;
+ unsigned int mute_direction = 0;
+ enum ast_frame_type frametype = AST_FRAME_VOICE;
+ int ret = 0;
+
+ if (!strcmp(direction, "in")) {
+ mute_direction = AST_MUTE_DIRECTION_READ;
+ } else if (!strcmp(direction, "out")) {
+ mute_direction = AST_MUTE_DIRECTION_WRITE;
+ } else if (!strcmp(direction, "all")) {
+ mute_direction = AST_MUTE_DIRECTION_READ | AST_MUTE_DIRECTION_WRITE;
+ } else {
+ return -1;
}
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 this is audio then allow them to increase/decrease the gains */
- if (frame->frametype == AST_FRAME_VOICE) {
- 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");
-
- /* 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) {
+ ret = ast_channel_suppress(chan, mute_direction, frametype);
+ } else {
+ ret = ast_channel_unsuppress(chan, mute_direction, frametype);
}
- if (!(mute = ast_calloc(1, sizeof(*mute)))) {
- 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;
-}
+ ast_channel_unlock(chan);
-/*! \brief Add or activate mute audiohook on channel
- 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;
+ return ret;
}
/*! \brief Mute dialplan function */
static int func_mute_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
{
- struct ast_datastore *datastore = NULL;
- 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;
+ return mute_channel(chan, data, ast_true(value));
}
/* 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");
char id_text[256];
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)) {
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;
}
- ast_channel_lock(c);
-
- if (!(datastore = ast_channel_datastore_find(c, &mute_datastore, NULL))) {
- if (!(datastore = initialize_mutehook(c))) {
- 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 (mute_channel(c, direction, ast_true(state))) {
+ astman_send_error(s, m, "Failed to mute/unmute stream");
+ ast_channel_unref(c);
+ return 0;
}
- 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);
if (!ast_strlen_zero(id)) {
diff --git a/res/stasis/control.c b/res/stasis/control.c
index 1fdcb8ded..df57a90a7 100644
--- a/res/stasis/control.c
+++ b/res/stasis/control.c
@@ -35,6 +35,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/bridging.h"
#include "asterisk/bridging_basic.h"
#include "asterisk/bridging_features.h"
+#include "asterisk/frame.h"
#include "asterisk/pbx.h"
struct stasis_app_control {
@@ -207,6 +208,65 @@ int stasis_app_control_continue(struct stasis_app_control *control, const char *
return 0;
}
+struct stasis_app_control_mute_data {
+ enum ast_frame_type frametype;
+ unsigned int direction;
+};
+
+static void *app_control_mute(struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ RAII_VAR(struct stasis_app_control_mute_data *, mute_data, data, ast_free);
+ SCOPED_CHANNELLOCK(lockvar, chan);
+
+ ast_channel_suppress(control->channel, mute_data->direction, mute_data->frametype);
+
+ return NULL;
+}
+
+int stasis_app_control_mute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype)
+{
+ struct stasis_app_control_mute_data *mute_data;
+
+ if (!(mute_data = ast_calloc(1, sizeof(*mute_data)))) {
+ return -1;
+ }
+
+ mute_data->direction = direction;
+ mute_data->frametype = frametype;
+
+ stasis_app_send_command_async(control, app_control_mute, mute_data);
+
+ return 0;
+}
+
+static void *app_control_unmute(struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ RAII_VAR(struct stasis_app_control_mute_data *, mute_data, data, ast_free);
+ SCOPED_CHANNELLOCK(lockvar, chan);
+
+ ast_channel_unsuppress(control->channel, mute_data->direction, mute_data->frametype);
+
+ return NULL;
+}
+
+int stasis_app_control_unmute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype)
+{
+ struct stasis_app_control_mute_data *mute_data;
+
+ if (!(mute_data = ast_calloc(1, sizeof(*mute_data)))) {
+ return -1;
+ }
+
+ mute_data->direction = direction;
+ mute_data->frametype = frametype;
+
+ stasis_app_send_command_async(control, app_control_unmute, mute_data);
+
+ return 0;
+}
+
char *stasis_app_control_get_channel_var(struct stasis_app_control *control, const char *variable)
{
RAII_VAR(struct ast_str *, tmp, ast_str_create(32), ast_free);
diff --git a/res/stasis_http/resource_channels.c b/res/stasis_http/resource_channels.c
index 1700b86ca..f0bbd4b1f 100644
--- a/res/stasis_http/resource_channels.c
+++ b/res/stasis_http/resource_channels.c
@@ -143,12 +143,62 @@ void stasis_http_answer_channel(struct ast_variable *headers,
void stasis_http_mute_channel(struct ast_variable *headers, struct ast_mute_channel_args *args, struct stasis_http_response *response)
{
- ast_log(LOG_ERROR, "TODO: stasis_http_mute_channel\n");
+ RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+ unsigned int direction = 0;
+ enum ast_frame_type frametype = AST_FRAME_VOICE;
+
+ control = find_control(response, args->channel_id);
+ if (control == NULL) {
+ return;
+ }
+
+ if (!strcmp(args->direction, "in")) {
+ direction = AST_MUTE_DIRECTION_READ;
+ } else if (!strcmp(args->direction, "out")) {
+ direction = AST_MUTE_DIRECTION_WRITE;
+ } else if (!strcmp(args->direction, "both")) {
+ direction = AST_MUTE_DIRECTION_READ | AST_MUTE_DIRECTION_WRITE;
+ } else {
+ stasis_http_response_error(
+ response, 400, "Bad Request",
+ "Invalid direction specified");
+ return;
+ }
+
+ stasis_app_control_mute(control, direction, frametype);
+
+ stasis_http_response_no_content(response);
}
+
void stasis_http_unmute_channel(struct ast_variable *headers, struct ast_unmute_channel_args *args, struct stasis_http_response *response)
{
- ast_log(LOG_ERROR, "TODO: stasis_http_unmute_channel\n");
+ RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+ unsigned int direction = 0;
+ enum ast_frame_type frametype = AST_FRAME_VOICE;
+
+ control = find_control(response, args->channel_id);
+ if (control == NULL) {
+ return;
+ }
+
+ if (!strcmp(args->direction, "in")) {
+ direction = AST_MUTE_DIRECTION_READ;
+ } else if (!strcmp(args->direction, "out")) {
+ direction = AST_MUTE_DIRECTION_WRITE;
+ } else if (!strcmp(args->direction, "both")) {
+ direction = AST_MUTE_DIRECTION_READ | AST_MUTE_DIRECTION_WRITE;
+ } else {
+ stasis_http_response_error(
+ response, 400, "Bad Request",
+ "Invalid direction specified");
+ return;
+ }
+
+ stasis_app_control_unmute(control, direction, frametype);
+
+ stasis_http_response_no_content(response);
}
+
void stasis_http_hold_channel(struct ast_variable *headers, struct ast_hold_channel_args *args, struct stasis_http_response *response)
{
RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);