[Asterisk-code-review] channel: Add ability to request an outgoing channel with str... (asterisk[master])
Joshua Colp
asteriskteam at digium.com
Mon Apr 24 16:45:16 CDT 2017
Joshua Colp has uploaded a new change for review. ( https://gerrit.asterisk.org/5522 )
Change subject: channel: Add ability to request an outgoing channel with stream topology.
......................................................................
channel: Add ability to request an outgoing channel with stream topology.
This change extends the ast_request functionality by adding another
function and callback to create an outgoing channel with a requested
stream topology. Fallback is provided by either converting the
requested stream topology into a format capabilities structure if
the channel driver does not support streams or by converting the
requested format capabilities into a stream topology if the channel
driver does support streams.
The Dial application has also been updated to request an outgoing
channel with the stream topology of the calling channel.
ASTERISK-26959
Change-Id: Ifa9037a672ac21d42dd7125aa09816dc879a70e6
---
M apps/app_dial.c
M include/asterisk/channel.h
M include/asterisk/stream.h
M main/channel.c
M main/stream.c
5 files changed, 175 insertions(+), 46 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/22/5522/1
diff --git a/apps/app_dial.c b/apps/app_dial.c
index c8fcf46..79e2a9b 100644
--- a/apps/app_dial.c
+++ b/apps/app_dial.c
@@ -66,6 +66,7 @@
#include "asterisk/bridge_after.h"
#include "asterisk/features_config.h"
#include "asterisk/max_forwards.h"
+#include "asterisk/stream.h"
/*** DOCUMENTATION
<application name="Dial" language="en_US">
@@ -970,16 +971,16 @@
c = o->chan = NULL;
cause = AST_CAUSE_BUSY;
} else {
- struct ast_format_cap *nativeformats;
+ struct ast_stream_topology *topology;
ast_channel_lock(in);
- nativeformats = ao2_bump(ast_channel_nativeformats(in));
+ topology = ast_stream_topology_clone(ast_channel_get_stream_topology(in));
ast_channel_unlock(in);
/* Setup parameters */
- c = o->chan = ast_request(tech, nativeformats, NULL, in, stuff, &cause);
+ c = o->chan = ast_request_with_stream_topology(tech, topology, NULL, in, stuff, &cause);
- ao2_cleanup(nativeformats);
+ ast_stream_topology_free(topology);
if (c) {
if (single && !caller_entertained) {
@@ -2444,7 +2445,7 @@
char *tech = strsep(&number, "/");
size_t tech_len;
size_t number_len;
- struct ast_format_cap *nativeformats;
+ struct ast_stream_topology *topology;
num_dialed++;
if (ast_strlen_zero(number)) {
@@ -2496,13 +2497,13 @@
*/
ast_party_connected_line_copy(&tmp->connected, ast_channel_connected(chan));
- nativeformats = ao2_bump(ast_channel_nativeformats(chan));
+ topology = ast_stream_topology_clone(ast_channel_get_stream_topology(chan));
ast_channel_unlock(chan);
- tc = ast_request(tmp->tech, nativeformats, NULL, chan, tmp->number, &cause);
+ tc = ast_request_with_stream_topology(tmp->tech, topology, NULL, chan, tmp->number, &cause);
- ao2_cleanup(nativeformats);
+ ast_stream_topology_free(topology);
if (!tc) {
/* If we can't, just go on to the next call */
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 32c9c7f..70856a9 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -203,6 +203,8 @@
typedef unsigned long long ast_group_t;
+struct ast_stream_topology;
+
/*! \todo Add an explanation of an Asterisk generator
*/
struct ast_generator {
@@ -629,6 +631,26 @@
* \retval non-NULL channel on success
*/
struct ast_channel *(* const requester)(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause);
+
+ /*!
+ * \brief Requester - to set up call data structures (pvt's) with stream topology
+ *
+ * \param type type of channel to request
+ * \param topology Stream topology for requested channel
+ * \param assignedid Unique ID string to assign to channel
+ * \param requestor channel asking for data
+ * \param addr destination of the call
+ * \param cause Cause of failure
+ *
+ * \details
+ * Request a channel of a given type, with addr as optional information used
+ * by the low level module
+ *
+ * \retval NULL failure
+ * \retval non-NULL channel on success
+ */
+ struct ast_channel *(* const requester_with_stream_topology)(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause);
+
int (* const devicestate)(const char *device_number); /*!< Devicestate call back */
int (* const presencestate)(const char *presence_provider, char **subtype, char **message); /*!< Presencestate callback */
@@ -1393,6 +1415,25 @@
*/
struct ast_channel *ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause);
+/*!
+ * \brief Requests a channel (specifying stream topology)
+ *
+ * \param type type of channel to request
+ * \param topology Stream topology for requested channel
+ * \param assignedids Unique ID to create channel with
+ * \param requestor channel asking for data
+ * \param addr destination of the call
+ * \param cause Cause of failure
+ *
+ * \details
+ * Request a channel of a given type, with addr as optional information used
+ * by the low level module
+ *
+ * \retval NULL failure
+ * \retval non-NULL channel on success
+ */
+struct ast_channel *ast_request_with_stream_topology(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause);
+
enum ast_channel_requestor_relationship {
/*! The requestor is the future bridge peer of the channel. */
AST_CHANNEL_REQUESTOR_BRIDGE_PEER,
diff --git a/include/asterisk/stream.h b/include/asterisk/stream.h
index 1becae2..924bfb6 100644
--- a/include/asterisk/stream.h
+++ b/include/asterisk/stream.h
@@ -375,6 +375,22 @@
struct ast_format_cap *cap);
/*!
+ * \brief A helper function that, given a stream topology, creates a format
+ * capabilities structure containing all formats from all streams.
+ *
+ * \param topology The topology of streams
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * \note The stream topology is NOT altered by this function.
+ *
+ * \since 15
+ */
+struct ast_format_cap *ast_format_cap_from_stream_topology(
+ struct ast_stream_topology *topology);
+
+/*!
* \brief Gets the first stream of a specific type from the topology
*
* \param topology The topology of streams
diff --git a/main/channel.c b/main/channel.c
index 31f3639..6529943 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -5976,7 +5976,8 @@
return 0;
}
-struct ast_channel *ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
+static struct ast_channel *request_channel(const char *type, struct ast_format_cap *request_cap, struct ast_stream_topology *topology,
+ const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
{
struct chanlist *chan;
struct ast_channel *c;
@@ -5993,13 +5994,48 @@
}
AST_RWLIST_TRAVERSE(&backends, chan, list) {
+ if (strcasecmp(type, chan->tech->type)) {
+ continue;
+ }
+
+ break;
+ }
+
+ if (!chan) {
+ AST_RWLIST_UNLOCK(&backends);
+ ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
+ *cause = AST_CAUSE_NOSUCHDRIVER;
+ return NULL;
+ }
+
+ /* Allow either format capabilities or stream topology to be provided and adapt */
+ if (chan->tech->requester_with_stream_topology) {
+ struct ast_stream_topology *tmp_converted_topology = NULL;
+
+ if (!topology && request_cap) {
+ /* Turn the requested capabilities into a stream topology */
+ topology = tmp_converted_topology = ast_stream_topology_create_from_format_cap(request_cap);
+ }
+
+ c = chan->tech->requester_with_stream_topology(type, topology, assignedids, requestor, addr, cause);
+
+ AST_RWLIST_UNLOCK(&backends);
+
+ ast_stream_topology_free(tmp_converted_topology);
+ if (!c) {
+ return NULL;
+ }
+ } else if (chan->tech->requester) {
+ struct ast_format_cap *tmp_converted_cap = NULL;
struct ast_format_cap *tmp_cap;
RAII_VAR(struct ast_format *, tmp_fmt, NULL, ao2_cleanup);
RAII_VAR(struct ast_format *, best_audio_fmt, NULL, ao2_cleanup);
struct ast_format_cap *joint_cap;
- if (strcasecmp(type, chan->tech->type))
- continue;
+ if (!request_cap && topology) {
+ /* Turn the request stream topology into capabilities */
+ request_cap = tmp_converted_cap = ast_format_cap_from_stream_topology(topology);
+ }
/* find the best audio format to use */
tmp_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
@@ -6019,12 +6055,10 @@
ast_format_cap_get_names(request_cap, &request_codecs));
*cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
AST_RWLIST_UNLOCK(&backends);
+ ao2_cleanup(tmp_converted_cap);
return NULL;
}
}
- AST_RWLIST_UNLOCK(&backends);
- if (!chan->tech->requester)
- return NULL;
/* XXX Only the audio format calculated as being the best for translation
* purposes is used for the request. This is because we don't have the ability
@@ -6033,50 +6067,61 @@
*/
joint_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!joint_cap) {
+ AST_RWLIST_UNLOCK(&backends);
+ ao2_cleanup(tmp_converted_cap);
return NULL;
}
ast_format_cap_append_from_cap(joint_cap, request_cap, AST_MEDIA_TYPE_UNKNOWN);
ast_format_cap_remove_by_type(joint_cap, AST_MEDIA_TYPE_AUDIO);
ast_format_cap_append(joint_cap, best_audio_fmt, 0);
+ ao2_cleanup(tmp_converted_cap);
- if (!(c = chan->tech->requester(type, joint_cap, assignedids, requestor, addr, cause))) {
+ c = chan->tech->requester(type, joint_cap, assignedids, requestor, addr, cause);
+ AST_RWLIST_UNLOCK(&backends);
+
+ if (!c) {
ao2_ref(joint_cap, -1);
return NULL;
}
-
- if (requestor) {
- ast_callid callid;
-
- ast_channel_lock_both(c, (struct ast_channel *) requestor);
-
- /* Set the newly created channel's callid to the same as the requestor. */
- callid = ast_channel_callid(requestor);
- if (callid) {
- ast_channel_callid_set(c, callid);
- }
-
- ast_channel_unlock(c);
- ast_channel_unlock((struct ast_channel *) requestor);
- }
-
- ao2_ref(joint_cap, -1);
-
- if (set_security_requirements(requestor, c)) {
- ast_log(LOG_WARNING, "Setting security requirements failed\n");
- ast_hangup(c);
- *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
- return NULL;
- }
-
- /* no need to generate a Newchannel event here; it is done in the channel_alloc call */
- return c;
+ } else {
+ AST_RWLIST_UNLOCK(&backends);
+ return NULL;
}
- ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
- *cause = AST_CAUSE_NOSUCHDRIVER;
- AST_RWLIST_UNLOCK(&backends);
+ if (requestor) {
+ ast_callid callid;
- return NULL;
+ ast_channel_lock_both(c, (struct ast_channel *) requestor);
+
+ /* Set the newly created channel's callid to the same as the requestor. */
+ callid = ast_channel_callid(requestor);
+ if (callid) {
+ ast_channel_callid_set(c, callid);
+ }
+
+ ast_channel_unlock(c);
+ ast_channel_unlock((struct ast_channel *) requestor);
+ }
+
+ if (set_security_requirements(requestor, c)) {
+ ast_log(LOG_WARNING, "Setting security requirements failed\n");
+ ast_hangup(c);
+ *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
+ return NULL;
+ }
+
+ /* no need to generate a Newchannel event here; it is done in the channel_alloc call */
+ return c;
+}
+
+struct ast_channel *ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
+{
+ return request_channel(type, request_cap, NULL, assignedids, requestor, addr, cause);
+}
+
+struct ast_channel *ast_request_with_stream_topology(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
+{
+ return request_channel(type, NULL, topology, assignedids, requestor, addr, cause);
}
/*!
diff --git a/main/stream.c b/main/stream.c
index 9d36dbf..cf2633e 100644
--- a/main/stream.c
+++ b/main/stream.c
@@ -392,6 +392,32 @@
return topology;
}
+struct ast_format_cap *ast_format_cap_from_stream_topology(
+ struct ast_stream_topology *topology)
+{
+ struct ast_format_cap *caps;
+ int i;
+
+ ast_assert(topology != NULL);
+
+ caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (!caps) {
+ return NULL;
+ }
+
+ for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {
+ struct ast_stream *stream = AST_VECTOR_GET(&topology->streams, i);
+
+ if (!stream->formats) {
+ continue;
+ }
+
+ ast_format_cap_append_from_cap(caps, stream->formats, AST_MEDIA_TYPE_UNKNOWN);
+ }
+
+ return caps;
+}
+
struct ast_stream *ast_stream_topology_get_first_stream_by_type(
const struct ast_stream_topology *topology,
enum ast_media_type type)
--
To view, visit https://gerrit.asterisk.org/5522
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifa9037a672ac21d42dd7125aa09816dc879a70e6
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
More information about the asterisk-code-review
mailing list