[asterisk-commits] qwell: branch qwell/ari_channel_mute r393425 - in /team/qwell/ari_channel_mut...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 2 10:37:13 CDT 2013
Author: qwell
Date: Tue Jul 2 10:37:11 2013
New Revision: 393425
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393425
Log:
Add mute/unmute to core.
Modified:
team/qwell/ari_channel_mute/include/asterisk/channel.h
team/qwell/ari_channel_mute/include/asterisk/stasis_app.h
team/qwell/ari_channel_mute/main/channel.c
team/qwell/ari_channel_mute/res/stasis/control.c
team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c
Modified: team/qwell/ari_channel_mute/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/include/asterisk/channel.h?view=diff&rev=393425&r1=393424&r2=393425
==============================================================================
--- team/qwell/ari_channel_mute/include/asterisk/channel.h (original)
+++ team/qwell/ari_channel_mute/include/asterisk/channel.h Tue Jul 2 10:37:11 2013
@@ -4363,5 +4363,32 @@
*/
const char *ast_channel_oldest_linkedid(const char *a, const char *b);
+enum ast_mute_direction {
+ AST_MUTE_DIRECTION_READ,
+ AST_MUTE_DIRECTION_WRITE,
+};
+
+/*!
+ * \brief Mute a stream on a channel
+ *
+ * \param chan The channel to mute
+ * \param direction The direction of the stream to mute
+ * \param frametype The type of frame (AST_FRAME_VOICE, etc) to mute
+ *
+ * \retval 0 Success
+ * \retval -1 Failure
+ */
+int ast_channel_mute(struct ast_channel *chan, enum ast_mute_direction direction, int frametype);
+/*!
+ * \brief Unmute a stream on a channel
+ *
+ * \param chan The channel to unmute
+ * \param direction The direction of the stream to unmute
+ * \param frametype The type of frame (AST_FRAME_VOICE, etc) to unmute
+ *
+ * \retval 0 Success
+ * \retval -1 Failure
+ */
+int ast_channel_unmute(struct ast_channel *chan, enum ast_mute_direction direction, int frametype);
#endif /* _ASTERISK_CHANNEL_H */
Modified: team/qwell/ari_channel_mute/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/include/asterisk/stasis_app.h?view=diff&rev=393425&r1=393424&r2=393425
==============================================================================
--- team/qwell/ari_channel_mute/include/asterisk/stasis_app.h (original)
+++ team/qwell/ari_channel_mute/include/asterisk/stasis_app.h Tue Jul 2 10:37:11 2013
@@ -165,22 +165,29 @@
*/
int stasis_app_control_continue(struct stasis_app_control *control, const char *context, const char *extension, int priority);
-enum stasis_mute_direction {
- STASIS_MUTE_READ,
- STASIS_MUTE_WRITE,
-};
-
/*!
* \brief Mute the channel associated with this control.
*
* \param control Control for \c res_stasis.
* \param direction The direction in which the audio should be muted.
- * \param stream_type The type of stream that should be muted.
- *
- * \return 0 for success
- * \return -1 for error.
- */
-int stasis_app_control_mute(struct stasis_app_control *control, enum stasis_mute_direction direction, int stream_type);
+ * \param frametype The type of stream that should be muted.
+ *
+ * \return 0 for success
+ * \return -1 for error.
+ */
+int stasis_app_control_mute(struct stasis_app_control *control, enum ast_mute_direction direction, int frametype);
+
+/*!
+ * \brief Unmute the channel associated with this control.
+ *
+ * \param control Control for \c res_stasis.
+ * \param direction The direction in which the audio should be unmuted.
+ * \param frametype The type of stream that should be unmuted.
+ *
+ * \return 0 for success
+ * \return -1 for error.
+ */
+int stasis_app_control_unmute(struct stasis_app_control *control, enum ast_mute_direction direction, int frametype);
/*!
* \brief Answer the channel associated with this control.
Modified: team/qwell/ari_channel_mute/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/main/channel.c?view=diff&rev=393425&r1=393424&r2=393425
==============================================================================
--- team/qwell/ari_channel_mute/main/channel.c (original)
+++ team/qwell/ari_channel_mute/main/channel.c Tue Jul 2 10:37:11 2013
@@ -10523,3 +10523,159 @@
ast_do_masquerade(dest);
return 0;
}
+
+static void mute_datastore_destroy_cb(void *data)
+{
+ ast_free(data);
+}
+
+static const struct ast_datastore_info mute_datastore_voice_read = {
+ .type = "mutevoiceread",
+ .destroy = mute_datastore_destroy_cb
+};
+
+static const struct ast_datastore_info mute_datastore_voice_write = {
+ .type = "mutevoicewrite",
+ .destroy = mute_datastore_destroy_cb
+};
+
+static void mute_framehook_destroy_cb(void *data)
+{
+ ast_free(data);
+}
+
+struct mute_data {
+ int frametype;
+ enum ast_mute_direction direction;
+};
+
+static const struct ast_datastore_info *mute_get_datastore_information(enum ast_mute_direction direction, int frametype)
+{
+ switch (direction) {
+ case AST_MUTE_DIRECTION_READ:
+ if (frametype == AST_FRAME_VOICE) {
+ return &mute_datastore_voice_read;
+ }
+ break;
+ case AST_MUTE_DIRECTION_WRITE:
+ if (frametype == AST_FRAME_VOICE) {
+ return &mute_datastore_voice_write;
+ }
+ break;
+ }
+
+ return NULL;
+}
+
+static struct ast_frame *mute_framehook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
+{
+ struct mute_data *mute = data;
+ int mute_frame = 0;
+
+ if (!frame) {
+ return NULL;
+ }
+
+ if (frame->frametype != mute->frametype) {
+ return frame;
+ }
+
+ if (event == AST_FRAMEHOOK_EVENT_READ && mute->direction == AST_MUTE_DIRECTION_READ) {
+ mute_frame = 1;
+ } else if (event == AST_FRAMEHOOK_EVENT_WRITE && mute->direction == AST_MUTE_DIRECTION_WRITE) {
+ mute_frame = 1;
+ }
+
+ if (mute_frame) {
+ switch (frame->frametype) {
+ case AST_FRAME_VOICE:
+ frame = &ast_null_frame;
+ break;
+ default:
+ break;
+ }
+ }
+
+ return frame;
+}
+
+int ast_channel_mute(struct ast_channel *chan, enum ast_mute_direction direction, int frametype)
+{
+ SCOPED_CHANNELLOCK(lockvar, chan);
+ struct mute_data *mute;
+ struct ast_framehook_interface interface = {
+ .version = AST_FRAMEHOOK_INTERFACE_VERSION,
+ .event_cb = mute_framehook_event_cb,
+ .destroy_cb = mute_framehook_destroy_cb,
+ };
+ int hook_id;
+ struct ast_datastore *datastore = NULL;
+ const struct ast_datastore_info *datastore_info = NULL;
+
+ if (!(datastore_info = mute_get_datastore_information(direction, frametype))) {
+ ast_log(LOG_NOTICE, "Attempted to mute an unsupported frame type (%d).\n", frametype);
+ return -1;
+ }
+
+ if (!(mute = ast_calloc(1, sizeof(*mute)))) {
+ ast_log(LOG_NOTICE, "Failed to allocate data while attempting to mute channel.\n");
+ return -1;
+ }
+
+ mute->frametype = frametype;
+ mute->direction = direction;
+
+ interface.data = mute;
+
+ hook_id = ast_framehook_attach(chan, &interface);
+ if (hook_id < 0) {
+ /* Hook attach failed. Get rid of the evidence. */
+ ast_log(LOG_NOTICE, "Failed to attach framehook while attempting to mute channel.\n");
+ ast_free(mute);
+ return -1;
+ }
+
+ if ((datastore = ast_channel_datastore_find(chan, datastore_info, NULL))) {
+ /* A datastore/audiohook already existed for this type of mute. Kill them. */
+ ast_framehook_detach(chan, *(int *)datastore->data);
+ ast_channel_datastore_remove(chan, datastore);
+ }
+
+ if (!(datastore = ast_datastore_alloc(datastore_info, NULL))) {
+ ast_log(LOG_NOTICE, "Failed to allocate datastore while attempting to mute channel.\n");
+ ast_framehook_detach(chan, hook_id);
+ return -1;
+ }
+
+ if (!(datastore->data = ast_calloc(1, sizeof(int)))) {
+ ast_datastore_free(datastore);
+ ast_framehook_detach(chan, hook_id);
+ }
+
+ *(int *)datastore->data = hook_id;
+
+ ast_channel_datastore_add(chan, datastore);
+
+ return 0;
+}
+
+int ast_channel_unmute(struct ast_channel *chan, enum ast_mute_direction direction, int frametype)
+{
+ struct ast_datastore *datastore = NULL;
+ const struct ast_datastore_info *datastore_info = NULL;
+
+ if (!(datastore_info = mute_get_datastore_information(direction, frametype))) {
+ ast_log(LOG_NOTICE, "Attempted to unmute an unsupported frame type (%d).\n", frametype);
+ return -1;
+ }
+
+ if (!(datastore = ast_channel_datastore_find(chan, datastore_info, NULL))) {
+ /* Nothing to do! */
+ return 0;
+ }
+
+ ast_framehook_detach(chan, *(int *)datastore->data);
+ ast_channel_datastore_remove(chan, datastore);
+
+ return 0;
+}
Modified: team/qwell/ari_channel_mute/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/res/stasis/control.c?view=diff&rev=393425&r1=393424&r2=393425
==============================================================================
--- team/qwell/ari_channel_mute/res/stasis/control.c (original)
+++ team/qwell/ari_channel_mute/res/stasis/control.c Tue Jul 2 10:37:11 2013
@@ -207,135 +207,14 @@
return 0;
}
-static void mute_datastore_destroy_cb(void *data)
-{
- ast_free(data);
-}
-
-static const struct ast_datastore_info mute_datastore_voice_read = {
- .type = "mutevoiceread",
- .destroy = mute_datastore_destroy_cb
-};
-
-static const struct ast_datastore_info mute_datastore_voice_write = {
- .type = "mutevoicewrite",
- .destroy = mute_datastore_destroy_cb
-};
-
-static void mute_framehook_destroy_cb(void *data)
-{
- ast_free(data);
-}
-
-struct mute_data {
- int frametype;
- enum stasis_mute_direction direction;
-};
-
-static const struct ast_datastore_info *mute_get_datastore_information(enum stasis_mute_direction direction, int frametype)
-{
- switch (direction) {
- case STASIS_MUTE_READ:
- if (frametype == AST_FRAME_VOICE) {
- return &mute_datastore_voice_read;
- }
- break;
- case STASIS_MUTE_WRITE:
- if (frametype == AST_FRAME_VOICE) {
- return &mute_datastore_voice_write;
- }
- break;
- }
-
- return NULL;
-}
-
-static struct ast_frame *mute_framehook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
-{
- struct mute_data *mute = data;
- int mute_frame = 0;
-
- if (!frame) {
- return NULL;
- }
-
- if (frame->frametype != mute->frametype) {
- return frame;
- }
-
- if (event == AST_FRAMEHOOK_EVENT_READ && mute->direction == STASIS_MUTE_READ) {
- mute_frame = 1;
- } else if (event == AST_FRAMEHOOK_EVENT_WRITE && mute->direction == STASIS_MUTE_WRITE) {
- mute_frame = 1;
- }
-
- if (mute_frame) {
- switch (frame->frametype) {
- case AST_FRAME_VOICE:
- frame = &ast_null_frame;
- break;
- default:
- break;
- }
- }
-
- return frame;
-}
-
-int stasis_app_control_mute(struct stasis_app_control *control, enum stasis_mute_direction direction, int frametype)
-{
- SCOPED_CHANNELLOCK(lockvar, control->channel);
- struct mute_data *mute;
- struct ast_framehook_interface interface = {
- .version = AST_FRAMEHOOK_INTERFACE_VERSION,
- .event_cb = mute_framehook_event_cb,
- .destroy_cb = mute_framehook_destroy_cb,
- };
- int hook_id;
- struct ast_datastore *datastore = NULL;
- const struct ast_datastore_info *datastore_info = NULL;
-
- if (!(datastore_info = mute_get_datastore_information(direction, frametype))) {
- return -1;
- }
-
- if (!(mute = ast_calloc(1, sizeof(*mute)))) {
- return -1;
- }
-
- mute->frametype = frametype;
- mute->direction = direction;
-
- interface.data = mute;
-
- hook_id = ast_framehook_attach(control->channel, &interface);
- if (hook_id < 0) {
- /* Hook attach failed. Get rid of the evidence. */
- ast_free(mute);
- return -1;
- }
-
- if ((datastore = ast_channel_datastore_find(control->channel, datastore_info, NULL))) {
- /* A datastore/audiohook already existed for this type of mute. Kill them. */
- ast_framehook_detach(control->channel, *(int *)datastore->data);
- ast_channel_datastore_remove(control->channel, datastore);
- }
-
- if (!(datastore = ast_datastore_alloc(datastore_info, NULL))) {
- ast_framehook_detach(control->channel, hook_id);
- return 0;
- }
-
- if (!(datastore->data = ast_calloc(1, sizeof(int)))) {
- ast_datastore_free(datastore);
- ast_framehook_detach(control->channel, hook_id);
- }
-
- *(int *)datastore->data = hook_id;
-
- ast_channel_datastore_add(control->channel, datastore);
-
- return 0;
+int stasis_app_control_mute(struct stasis_app_control *control, enum ast_mute_direction direction, int frametype)
+{
+ return ast_channel_mute(control->channel, direction, frametype);
+}
+
+int stasis_app_control_unmute(struct stasis_app_control *control, enum ast_mute_direction direction, int frametype)
+{
+ return ast_channel_unmute(control->channel, direction, frametype);
}
static void *app_control_hold(struct stasis_app_control *control,
Modified: team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c?view=diff&rev=393425&r1=393424&r2=393425
==============================================================================
--- team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c (original)
+++ team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c Tue Jul 2 10:37:11 2013
@@ -167,19 +167,53 @@
}
if (mute_in) {
- stasis_app_control_mute(control, STASIS_MUTE_READ, stream_type);
+ stasis_app_control_mute(control, AST_MUTE_DIRECTION_READ, stream_type);
}
if (mute_out) {
- stasis_app_control_mute(control, STASIS_MUTE_WRITE, stream_type);
- }
-
- stasis_http_response_no_content(response);
-}
+ stasis_app_control_mute(control, AST_MUTE_DIRECTION_WRITE, stream_type);
+ }
+
+ 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);
+ int unmute_in = 0;
+ int unmute_out = 0;
+ int stream_type = AST_FRAME_VOICE;
+
+ control = find_control(response, args->channel_id);
+ if (control == NULL) {
+ return;
+ }
+
+ if (!strcmp(args->direction, "in")) {
+ unmute_in = 1;
+ } else if (!strcmp(args->direction, "out")) {
+ unmute_out = 1;
+ } else if (!strcmp(args->direction, "both")) {
+ unmute_in = 1;
+ unmute_out = 1;
+ } else {
+ stasis_http_response_error(
+ response, 400, "Bad Request",
+ "Invalid direction specified");
+ return;
+ }
+
+ if (unmute_in) {
+ stasis_app_control_unmute(control, AST_MUTE_DIRECTION_READ, stream_type);
+ }
+
+ if (unmute_out) {
+ stasis_app_control_unmute(control, AST_MUTE_DIRECTION_WRITE, stream_type);
+ }
+
+ 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);
More information about the asterisk-commits
mailing list