summaryrefslogtreecommitdiff
path: root/res/ari
diff options
context:
space:
mode:
authorzuul <zuul@gerrit.asterisk.org>2016-11-16 16:48:09 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2016-11-16 16:48:09 -0600
commitd0474f632208e7bc160c0d04fc65d8d5e6b6c7e3 (patch)
tree2a3ccd5c41a665ab737b0983ee30878928802b79 /res/ari
parent732ab6a045e1d4de5bf7a8256376dbe24406eed6 (diff)
parenta72ef381135639c62d97b9f6b1964403c9c92b78 (diff)
Merge "res/ari/resource_bridges: Add the ability to manipulate the video source"
Diffstat (limited to 'res/ari')
-rw-r--r--res/ari/ari_model_validators.c121
-rw-r--r--res/ari/ari_model_validators.h27
-rw-r--r--res/ari/resource_bridges.c66
-rw-r--r--res/ari/resource_bridges.h28
4 files changed, 242 insertions, 0 deletions
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c
index 9fd844c4d..ea5a88599 100644
--- a/res/ari/ari_model_validators.c
+++ b/res/ari/ari_model_validators.c
@@ -1367,6 +1367,24 @@ int ast_ari_validate_bridge(struct ast_json *json)
res = 0;
}
} else
+ if (strcmp("video_mode", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Bridge field video_mode failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("video_source_id", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Bridge field video_source_id failed validation\n");
+ res = 0;
+ }
+ } else
{
ast_log(LOG_ERROR,
"ARI Bridge has undocumented field %s\n",
@@ -2722,6 +2740,103 @@ ari_validator ast_ari_validate_bridge_merged_fn(void)
return ast_ari_validate_bridge_merged;
}
+int ast_ari_validate_bridge_video_source_changed(struct ast_json *json)
+{
+ int res = 1;
+ struct ast_json_iter *iter;
+ int has_type = 0;
+ int has_application = 0;
+ int has_bridge = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI BridgeVideoSourceChanged field asterisk_id failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_type = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI BridgeVideoSourceChanged field type failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_application = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI BridgeVideoSourceChanged field application failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_date(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI BridgeVideoSourceChanged field timestamp failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("bridge", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_bridge = 1;
+ prop_is_valid = ast_ari_validate_bridge(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI BridgeVideoSourceChanged field bridge failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("old_video_source_id", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI BridgeVideoSourceChanged field old_video_source_id failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI BridgeVideoSourceChanged has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_type) {
+ ast_log(LOG_ERROR, "ARI BridgeVideoSourceChanged missing required field type\n");
+ res = 0;
+ }
+
+ if (!has_application) {
+ ast_log(LOG_ERROR, "ARI BridgeVideoSourceChanged missing required field application\n");
+ res = 0;
+ }
+
+ if (!has_bridge) {
+ ast_log(LOG_ERROR, "ARI BridgeVideoSourceChanged missing required field bridge\n");
+ res = 0;
+ }
+
+ return res;
+}
+
+ari_validator ast_ari_validate_bridge_video_source_changed_fn(void)
+{
+ return ast_ari_validate_bridge_video_source_changed;
+}
+
int ast_ari_validate_channel_caller_id(struct ast_json *json)
{
int res = 1;
@@ -4928,6 +5043,9 @@ int ast_ari_validate_event(struct ast_json *json)
if (strcmp("BridgeMerged", discriminator) == 0) {
return ast_ari_validate_bridge_merged(json);
} else
+ if (strcmp("BridgeVideoSourceChanged", discriminator) == 0) {
+ return ast_ari_validate_bridge_video_source_changed(json);
+ } else
if (strcmp("ChannelCallerId", discriminator) == 0) {
return ast_ari_validate_channel_caller_id(json);
} else
@@ -5123,6 +5241,9 @@ int ast_ari_validate_message(struct ast_json *json)
if (strcmp("BridgeMerged", discriminator) == 0) {
return ast_ari_validate_bridge_merged(json);
} else
+ if (strcmp("BridgeVideoSourceChanged", discriminator) == 0) {
+ return ast_ari_validate_bridge_video_source_changed(json);
+ } else
if (strcmp("ChannelCallerId", discriminator) == 0) {
return ast_ari_validate_channel_caller_id(json);
} else
diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h
index fcd9fc11c..093e3f4f5 100644
--- a/res/ari/ari_model_validators.h
+++ b/res/ari/ari_model_validators.h
@@ -717,6 +717,24 @@ int ast_ari_validate_bridge_merged(struct ast_json *json);
ari_validator ast_ari_validate_bridge_merged_fn(void);
/*!
+ * \brief Validator for BridgeVideoSourceChanged.
+ *
+ * Notification that the source of video in a bridge has changed.
+ *
+ * \param json JSON object to validate.
+ * \returns True (non-zero) if valid.
+ * \returns False (zero) if invalid.
+ */
+int ast_ari_validate_bridge_video_source_changed(struct ast_json *json);
+
+/*!
+ * \brief Function pointer to ast_ari_validate_bridge_video_source_changed().
+ *
+ * See \ref ast_ari_model_validators.h for more details.
+ */
+ari_validator ast_ari_validate_bridge_video_source_changed_fn(void);
+
+/*!
* \brief Validator for ChannelCallerId.
*
* Channel changed Caller ID.
@@ -1453,6 +1471,8 @@ ari_validator ast_ari_validate_application_fn(void);
* - id: string (required)
* - name: string (required)
* - technology: string (required)
+ * - video_mode: string
+ * - video_source_id: string
* LiveRecording
* - cause: string
* - duration: int
@@ -1544,6 +1564,13 @@ ari_validator ast_ari_validate_application_fn(void);
* - timestamp: Date
* - bridge: Bridge (required)
* - bridge_from: Bridge (required)
+ * BridgeVideoSourceChanged
+ * - asterisk_id: string
+ * - type: string (required)
+ * - application: string (required)
+ * - timestamp: Date
+ * - bridge: Bridge (required)
+ * - old_video_source_id: string
* ChannelCallerId
* - asterisk_id: string
* - type: string (required)
diff --git a/res/ari/resource_bridges.c b/res/ari/resource_bridges.c
index f5ae1c003..f243086c9 100644
--- a/res/ari/resource_bridges.c
+++ b/res/ari/resource_bridges.c
@@ -35,6 +35,7 @@
#include "asterisk/stasis.h"
#include "asterisk/stasis_bridges.h"
#include "asterisk/stasis_app.h"
+#include "asterisk/stasis_app_impl.h"
#include "asterisk/stasis_app_playback.h"
#include "asterisk/stasis_app_recording.h"
#include "asterisk/stasis_channels.h"
@@ -1003,3 +1004,68 @@ void ast_ari_bridges_create_with_id(struct ast_variable *headers,
ast_ari_response_ok(response,
ast_bridge_snapshot_to_json(snapshot, stasis_app_get_sanitizer()));
}
+
+static int bridge_set_video_source_cb(struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ struct ast_bridge *bridge = data;
+
+ ast_bridge_lock(bridge);
+ ast_bridge_set_single_src_video_mode(bridge, chan);
+ ast_bridge_unlock(bridge);
+
+ return 0;
+}
+
+void ast_ari_bridges_set_video_source(struct ast_variable *headers,
+ struct ast_ari_bridges_set_video_source_args *args, struct ast_ari_response *response)
+{
+ struct ast_bridge *bridge;
+ struct stasis_app_control *control;
+
+ bridge = find_bridge(response, args->bridge_id);
+ if (!bridge) {
+ return;
+ }
+
+ control = find_channel_control(response, args->channel_id);
+ if (!control) {
+ ao2_ref(bridge, -1);
+ return;
+ }
+
+ if (stasis_app_get_bridge(control) != bridge) {
+ ast_ari_response_error(response, 422,
+ "Unprocessable Entity",
+ "Channel not in this bridge");
+ ao2_ref(bridge, -1);
+ ao2_ref(control, -1);
+ return;
+ }
+
+ stasis_app_send_command(control, bridge_set_video_source_cb,
+ ao2_bump(bridge), __ao2_cleanup);
+
+ ao2_ref(bridge, -1);
+ ao2_ref(control, -1);
+
+ ast_ari_response_no_content(response);
+}
+
+void ast_ari_bridges_clear_video_source(struct ast_variable *headers,
+ struct ast_ari_bridges_clear_video_source_args *args, struct ast_ari_response *response)
+{
+ struct ast_bridge *bridge;
+
+ bridge = find_bridge(response, args->bridge_id);
+ if (!bridge) {
+ return;
+ }
+
+ ast_bridge_lock(bridge);
+ ast_bridge_set_talker_src_video_mode(bridge);
+ ast_bridge_unlock(bridge);
+
+ ao2_ref(bridge, -1);
+ ast_ari_response_no_content(response);
+}
diff --git a/res/ari/resource_bridges.h b/res/ari/resource_bridges.h
index 17a3b8365..e75d8e028 100644
--- a/res/ari/resource_bridges.h
+++ b/res/ari/resource_bridges.h
@@ -200,6 +200,34 @@ int ast_ari_bridges_remove_channel_parse_body(
* \param[out] response HTTP response
*/
void ast_ari_bridges_remove_channel(struct ast_variable *headers, struct ast_ari_bridges_remove_channel_args *args, struct ast_ari_response *response);
+/*! Argument struct for ast_ari_bridges_set_video_source() */
+struct ast_ari_bridges_set_video_source_args {
+ /*! Bridge's id */
+ const char *bridge_id;
+ /*! Channel's id */
+ const char *channel_id;
+};
+/*!
+ * \brief Set a channel as the video source in a multi-party mixing bridge. This operation has no effect on bridges with two or fewer participants.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_bridges_set_video_source(struct ast_variable *headers, struct ast_ari_bridges_set_video_source_args *args, struct ast_ari_response *response);
+/*! Argument struct for ast_ari_bridges_clear_video_source() */
+struct ast_ari_bridges_clear_video_source_args {
+ /*! Bridge's id */
+ const char *bridge_id;
+};
+/*!
+ * \brief Removes any explicit video source in a multi-party mixing bridge. This operation has no effect on bridges with two or fewer participants. When no explicit video source is set, talk detection will be used to determine the active video stream.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_bridges_clear_video_source(struct ast_variable *headers, struct ast_ari_bridges_clear_video_source_args *args, struct ast_ari_response *response);
/*! Argument struct for ast_ari_bridges_start_moh() */
struct ast_ari_bridges_start_moh_args {
/*! Bridge's id */