[svn-commits] file: trunk r403118 - in /trunk: ./ include/asterisk/ main/ res/ res/ari/ res...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Sat Nov 23 06:40:49 CST 2013
Author: file
Date: Sat Nov 23 06:40:46 2013
New Revision: 403118
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403118
Log:
ari: Add Snoop operation for spying/whispering on channels.
The Snoop operation can be invoked on a channel to spy or
whisper on it. It returns a channel that any channel operations
can then be invoked on (such as record to do monitoring).
(closes issue ASTERISK-22780)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3003/
........
Merged revisions 403117 from http://svn.asterisk.org/svn/asterisk/branches/12
Added:
trunk/include/asterisk/stasis_app_snoop.h
- copied unchanged from r403117, branches/12/include/asterisk/stasis_app_snoop.h
trunk/res/res_stasis_snoop.c
- copied unchanged from r403117, branches/12/res/res_stasis_snoop.c
trunk/res/res_stasis_snoop.exports.in
- copied unchanged from r403117, branches/12/res/res_stasis_snoop.exports.in
Modified:
trunk/ (props changed)
trunk/main/audiohook.c
trunk/res/ari/resource_channels.c
trunk/res/ari/resource_channels.h
trunk/res/res_ari_channels.c
trunk/rest-api/api-docs/channels.json
Propchange: trunk/
------------------------------------------------------------------------------
--- branch-12-merged (original)
+++ branch-12-merged Sat Nov 23 06:40:46 2013
@@ -1,1 +1,1 @@
-/branches/12:1-398558,398560-398577,398579-399305,399307-401390,401392-402993,403016,403022,403069,403082,403094
+/branches/12:1-398558,398560-398577,398579-399305,399307-401390,401392-402993,403016,403022,403069,403082,403094,403117
Modified: trunk/main/audiohook.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/audiohook.c?view=diff&rev=403118&r1=403117&r2=403118
==============================================================================
--- trunk/main/audiohook.c (original)
+++ trunk/main/audiohook.c Sat Nov 23 06:40:46 2013
@@ -79,15 +79,12 @@
/* Setup the factories that are needed for this audiohook type */
switch (audiohook->type) {
case AST_AUDIOHOOK_TYPE_SPY:
+ case AST_AUDIOHOOK_TYPE_WHISPER:
if (reset) {
ast_slinfactory_destroy(&audiohook->read_factory);
+ ast_slinfactory_destroy(&audiohook->write_factory);
}
ast_slinfactory_init_with_format(&audiohook->read_factory, &slin);
- /* fall through */
- case AST_AUDIOHOOK_TYPE_WHISPER:
- if (reset) {
- ast_slinfactory_destroy(&audiohook->write_factory);
- }
ast_slinfactory_init_with_format(&audiohook->write_factory, &slin);
break;
default:
@@ -134,8 +131,8 @@
/* Drop the factories used by this audiohook type */
switch (audiohook->type) {
case AST_AUDIOHOOK_TYPE_SPY:
+ case AST_AUDIOHOOK_TYPE_WHISPER:
ast_slinfactory_destroy(&audiohook->read_factory);
- case AST_AUDIOHOOK_TYPE_WHISPER:
ast_slinfactory_destroy(&audiohook->write_factory);
break;
default:
@@ -815,11 +812,12 @@
AST_LIST_TRAVERSE_SAFE_END;
/* If this frame is being written out to the channel then we need to use whisper sources */
- if (direction == AST_AUDIOHOOK_DIRECTION_WRITE && !AST_LIST_EMPTY(&audiohook_list->whisper_list)) {
+ if (!AST_LIST_EMPTY(&audiohook_list->whisper_list)) {
int i = 0;
short read_buf[samples], combine_buf[samples], *data1 = NULL, *data2 = NULL;
memset(&combine_buf, 0, sizeof(combine_buf));
AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->whisper_list, audiohook, list) {
+ struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
ast_audiohook_lock(audiohook);
if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) {
AST_LIST_REMOVE_CURRENT(list);
@@ -829,7 +827,7 @@
continue;
}
audiohook_set_internal_rate(audiohook, audiohook_list->list_internal_samp_rate, 1);
- if (ast_slinfactory_available(&audiohook->write_factory) >= samples && ast_slinfactory_read(&audiohook->write_factory, read_buf, samples)) {
+ if (ast_slinfactory_available(factory) >= samples && ast_slinfactory_read(factory, read_buf, samples)) {
/* Take audio from this whisper source and combine it into our main buffer */
for (i = 0, data1 = combine_buf, data2 = read_buf; i < samples; i++, data1++, data2++)
ast_slinear_saturated_add(data1, data2);
Modified: trunk/res/ari/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/ari/resource_channels.c?view=diff&rev=403118&r1=403117&r2=403118
==============================================================================
--- trunk/res/ari/resource_channels.c (original)
+++ trunk/res/ari/resource_channels.c Sat Nov 23 06:40:46 2013
@@ -39,6 +39,7 @@
#include "asterisk/stasis_app.h"
#include "asterisk/stasis_app_playback.h"
#include "asterisk/stasis_app_recording.h"
+#include "asterisk/stasis_app_snoop.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/causes.h"
#include "resource_channels.h"
@@ -847,3 +848,73 @@
ast_ari_response_no_content(response);
}
+void ast_ari_channels_snoop_channel(struct ast_variable *headers, struct ast_ari_channels_snoop_channel_args *args, struct ast_ari_response *response)
+{
+ enum stasis_app_snoop_direction spy, whisper;
+ RAII_VAR(struct ast_channel *, chan, NULL, ast_channel_cleanup);
+ RAII_VAR(struct ast_channel *, snoop, NULL, ast_channel_cleanup);
+ RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+
+ ast_assert(response != NULL);
+
+ if (ast_strlen_zero(args->spy) || !strcmp(args->spy, "none")) {
+ spy = STASIS_SNOOP_DIRECTION_NONE;
+ } else if (!strcmp(args->spy, "both")) {
+ spy = STASIS_SNOOP_DIRECTION_BOTH;
+ } else if (!strcmp(args->spy, "out")) {
+ spy = STASIS_SNOOP_DIRECTION_OUT;
+ } else if (!strcmp(args->spy, "in")) {
+ spy = STASIS_SNOOP_DIRECTION_IN;
+ } else {
+ ast_ari_response_error(
+ response, 400, "Bad Request",
+ "Invalid direction specified for spy");
+ return;
+ }
+
+ if (ast_strlen_zero(args->whisper) || !strcmp(args->whisper, "none")) {
+ whisper = STASIS_SNOOP_DIRECTION_NONE;
+ } else if (!strcmp(args->whisper, "both")) {
+ whisper = STASIS_SNOOP_DIRECTION_BOTH;
+ } else if (!strcmp(args->whisper, "out")) {
+ whisper = STASIS_SNOOP_DIRECTION_OUT;
+ } else if (!strcmp(args->whisper, "in")) {
+ whisper = STASIS_SNOOP_DIRECTION_IN;
+ } else {
+ ast_ari_response_error(
+ response, 400, "Bad Request",
+ "Invalid direction specified for whisper");
+ return;
+ }
+
+ if (spy == STASIS_SNOOP_DIRECTION_NONE && whisper == STASIS_SNOOP_DIRECTION_NONE) {
+ ast_ari_response_error(
+ response, 400, "Bad Request",
+ "Direction must be specified for at least spy or whisper");
+ return;
+ } else if (ast_strlen_zero(args->app)) {
+ ast_ari_response_error(
+ response, 400, "Bad Request",
+ "Application name is required");
+ return;
+ }
+
+ chan = ast_channel_get_by_name(args->channel_id);
+ if (chan == NULL) {
+ ast_ari_response_error(
+ response, 404, "Channel Not Found",
+ "Provided channel was not found");
+ return;
+ }
+
+ snoop = stasis_app_control_snoop(chan, spy, whisper, args->app, args->app_args);
+ if (snoop == NULL) {
+ ast_ari_response_error(
+ response, 500, "Internal error",
+ "Snoop channel could not be created");
+ return;
+ }
+
+ snapshot = ast_channel_snapshot_create(snoop);
+ ast_ari_response_ok(response, ast_channel_snapshot_to_json(snapshot, NULL));
+}
Modified: trunk/res/ari/resource_channels.h
URL: http://svnview.digium.com/svn/asterisk/trunk/res/ari/resource_channels.h?view=diff&rev=403118&r1=403117&r2=403118
==============================================================================
--- trunk/res/ari/resource_channels.h (original)
+++ trunk/res/ari/resource_channels.h Sat Nov 23 06:40:46 2013
@@ -386,5 +386,28 @@
* \param[out] response HTTP response
*/
void ast_ari_channels_set_channel_var(struct ast_variable *headers, struct ast_ari_channels_set_channel_var_args *args, struct ast_ari_response *response);
+/*! \brief Argument struct for ast_ari_channels_snoop_channel() */
+struct ast_ari_channels_snoop_channel_args {
+ /*! \brief Channel's id */
+ const char *channel_id;
+ /*! \brief Direction of audio to spy on */
+ const char *spy;
+ /*! \brief Direction of audio to whisper into */
+ const char *whisper;
+ /*! \brief Application the snooping channel is placed into */
+ const char *app;
+ /*! \brief The application arguments to pass to the Stasis application */
+ const char *app_args;
+};
+/*!
+ * \brief Start snooping.
+ *
+ * Snoop (spy/whisper) on a specific channel.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_channels_snoop_channel(struct ast_variable *headers, struct ast_ari_channels_snoop_channel_args *args, struct ast_ari_response *response);
#endif /* _ASTERISK_RESOURCE_CHANNELS_H */
Modified: trunk/res/res_ari_channels.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_ari_channels.c?view=diff&rev=403118&r1=403117&r2=403118
==============================================================================
--- trunk/res/res_ari_channels.c (original)
+++ trunk/res/res_ari_channels.c Sat Nov 23 06:40:46 2013
@@ -1384,6 +1384,79 @@
if (!is_valid) {
ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
+ ast_ari_response_error(response, 500,
+ "Internal Server Error", "Response validation failed");
+ }
+#endif /* AST_DEVMODE */
+
+fin: __attribute__((unused))
+ return;
+}
+/*!
+ * \brief Parameter parsing callback for /channels/{channelId}/snoop.
+ * \param get_params GET parameters in the HTTP request.
+ * \param path_vars Path variables extracted from the request.
+ * \param headers HTTP headers.
+ * \param[out] response Response to the HTTP request.
+ */
+static void ast_ari_channels_snoop_channel_cb(
+ struct ast_variable *get_params, struct ast_variable *path_vars,
+ struct ast_variable *headers, struct ast_ari_response *response)
+{
+ struct ast_ari_channels_snoop_channel_args args = {};
+ struct ast_variable *i;
+#if defined(AST_DEVMODE)
+ int is_valid;
+ int code;
+#endif /* AST_DEVMODE */
+
+ for (i = get_params; i; i = i->next) {
+ if (strcmp(i->name, "spy") == 0) {
+ args.spy = (i->value);
+ } else
+ if (strcmp(i->name, "whisper") == 0) {
+ args.whisper = (i->value);
+ } else
+ if (strcmp(i->name, "app") == 0) {
+ args.app = (i->value);
+ } else
+ if (strcmp(i->name, "appArgs") == 0) {
+ args.app_args = (i->value);
+ } else
+ {}
+ }
+ for (i = path_vars; i; i = i->next) {
+ if (strcmp(i->name, "channelId") == 0) {
+ args.channel_id = (i->value);
+ } else
+ {}
+ }
+ ast_ari_channels_snoop_channel(headers, &args, response);
+#if defined(AST_DEVMODE)
+ code = response->response_code;
+
+ switch (code) {
+ case 0: /* Implementation is still a stub, or the code wasn't set */
+ is_valid = response->message == NULL;
+ break;
+ case 500: /* Internal Server Error */
+ case 501: /* Not Implemented */
+ case 400: /* Invalid parameters */
+ case 404: /* Channel not found */
+ is_valid = 1;
+ break;
+ default:
+ if (200 <= code && code <= 299) {
+ is_valid = ast_ari_validate_channel(
+ response->message);
+ } else {
+ ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/snoop\n", code);
+ is_valid = 0;
+ }
+ }
+
+ if (!is_valid) {
+ ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/snoop\n");
ast_ari_response_error(response, 500,
"Internal Server Error", "Response validation failed");
}
@@ -1499,6 +1572,15 @@
.children = { }
};
/*! \brief REST handler for /api-docs/channels.{format} */
+static struct stasis_rest_handlers channels_channelId_snoop = {
+ .path_segment = "snoop",
+ .callbacks = {
+ [AST_HTTP_POST] = ast_ari_channels_snoop_channel_cb,
+ },
+ .num_children = 0,
+ .children = { }
+};
+/*! \brief REST handler for /api-docs/channels.{format} */
static struct stasis_rest_handlers channels_channelId = {
.path_segment = "channelId",
.is_wildcard = 1,
@@ -1506,8 +1588,8 @@
[AST_HTTP_GET] = ast_ari_channels_get_cb,
[AST_HTTP_DELETE] = ast_ari_channels_hangup_cb,
},
- .num_children = 11,
- .children = { &channels_channelId_continue,&channels_channelId_answer,&channels_channelId_ring,&channels_channelId_dtmf,&channels_channelId_mute,&channels_channelId_hold,&channels_channelId_moh,&channels_channelId_silence,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable, }
+ .num_children = 12,
+ .children = { &channels_channelId_continue,&channels_channelId_answer,&channels_channelId_ring,&channels_channelId_dtmf,&channels_channelId_mute,&channels_channelId_hold,&channels_channelId_moh,&channels_channelId_silence,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable,&channels_channelId_snoop, }
};
/*! \brief REST handler for /api-docs/channels.{format} */
static struct stasis_rest_handlers channels = {
Modified: trunk/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/trunk/rest-api/api-docs/channels.json?view=diff&rev=403118&r1=403117&r2=403118
==============================================================================
--- trunk/rest-api/api-docs/channels.json (original)
+++ trunk/rest-api/api-docs/channels.json Sat Nov 23 06:40:46 2013
@@ -950,6 +950,91 @@
{
"code": 409,
"reason": "Channel not in a Stasis application"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "path": "/channels/{channelId}/snoop",
+ "description": "Snoop (spy/whisper) on a channel",
+ "operations": [
+ {
+ "httpMethod": "POST",
+ "summary": "Start snooping.",
+ "notes": "Snoop (spy/whisper) on a specific channel.",
+ "nickname": "snoopChannel",
+ "responseClass": "Channel",
+ "parameters": [
+ {
+ "name": "channelId",
+ "description": "Channel's id",
+ "paramType": "path",
+ "required": true,
+ "allowMultiple": false,
+ "dataType": "string"
+ },
+ {
+ "name": "spy",
+ "description": "Direction of audio to spy on",
+ "paramType": "query",
+ "required": false,
+ "allowMultiple": false,
+ "dataType": "string",
+ "defaultValue": "none",
+ "allowableValues": {
+ "valueType": "LIST",
+ "values": [
+ "none",
+ "both",
+ "out",
+ "in"
+ ]
+ }
+ },
+ {
+ "name": "whisper",
+ "description": "Direction of audio to whisper into",
+ "paramType": "query",
+ "required": false,
+ "allowMultiple": false,
+ "dataType": "string",
+ "defaultValue": "none",
+ "allowableValues": {
+ "valueType": "LIST",
+ "values": [
+ "none",
+ "both",
+ "out",
+ "in"
+ ]
+ }
+ },
+ {
+ "name": "app",
+ "description": "Application the snooping channel is placed into",
+ "paramType": "query",
+ "required": true,
+ "allowMultiple": false,
+ "dataType": "string"
+ },
+ {
+ "name": "appArgs",
+ "description": "The application arguments to pass to the Stasis application",
+ "paramType": "query",
+ "required": false,
+ "allowMultiple": false,
+ "dataType": "string"
+ }
+ ],
+ "errorResponses": [
+ {
+ "code": 400,
+ "reason": "Invalid parameters"
+ },
+ {
+ "code": 404,
+ "reason": "Channel not found"
}
]
}
More information about the svn-commits
mailing list