[Asterisk-code-review] bridge simple: Improve renegotiation success rate. (asterisk[master])
Joshua Colp
asteriskteam at digium.com
Thu Oct 12 12:10:31 CDT 2017
Joshua Colp has uploaded this change for review. ( https://gerrit.asterisk.org/6760
Change subject: bridge_simple: Improve renegotiation success rate.
......................................................................
bridge_simple: Improve renegotiation success rate.
When making channels compatible the bridge_simple module
will renegotiate one to better match the other. Some
endpoints incorrectly terminate the call if this process
fails.
To better handle this scenario the audio streams present
on the new requested topology will include any existing
negotiated formats that happen to exist on the first
valid audio stream. This ensures formats are persent that
are known to be acceptable to the remote endpoint.
ASTERISK-27259
Change-Id: I8fc0cc03e8bcfd0be8302f13b9f32d8268977f43
---
M bridges/bridge_simple.c
1 file changed, 65 insertions(+), 2 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/60/6760/1
diff --git a/bridges/bridge_simple.c b/bridges/bridge_simple.c
index a49bc39..d9d5148 100644
--- a/bridges/bridge_simple.c
+++ b/bridges/bridge_simple.c
@@ -113,6 +113,69 @@
.stream_topology_changed = simple_bridge_stream_topology_changed,
};
+static void simple_bridge_request_stream_topology_change(struct ast_channel *chan,
+ struct ast_stream_topology *requested_topology)
+{
+ struct ast_stream_topology *existing_topology = ast_channel_get_stream_topology(chan);
+ struct ast_stream *stream;
+ struct ast_format_cap *audio_formats = NULL;
+ struct ast_stream_topology *new_topology;
+ int i;
+
+ /* We find an existing stream with negotiated audio formats that we can place into
+ * any audio streams in the new topology to ensure that negotiation succeeds. Some
+ * endpoints incorrectly terminate the call if SDP negotiation fails.
+ */
+ for (i = 0; i < ast_stream_topology_get_count(existing_topology); ++i) {
+ stream = ast_stream_topology_get_stream(existing_topology, i);
+
+ if (ast_stream_get_type(stream) != AST_MEDIA_TYPE_AUDIO ||
+ ast_stream_get_state(stream) == AST_STREAM_STATE_REMOVED) {
+ continue;
+ }
+
+ audio_formats = ast_stream_get_formats(stream);
+ break;
+ }
+
+ new_topology = ast_stream_topology_clone(requested_topology);
+
+ /* If an existing audio stream existed with formats then we add them to the
+ * new streams in the topology as needed.
+ */
+ if (audio_formats) {
+ for (i = 0; i < ast_stream_topology_get_count(new_topology); ++i) {
+ int format_index;
+
+ stream = ast_stream_topology_get_stream(new_topology, i);
+
+ if (ast_stream_get_type(stream) != AST_MEDIA_TYPE_AUDIO ||
+ ast_stream_get_state(stream) == AST_STREAM_STATE_REMOVED) {
+ continue;
+ }
+
+ /* We go through the formats individually to ensure we don't have
+ * duplicates.
+ */
+ for (format_index = 0; format_index < ast_format_cap_count(audio_formats); ++format_index) {
+ struct ast_format *format = ast_format_cap_get_format(audio_formats, format_index);
+
+ if (ast_format_cap_iscompatible_format(ast_stream_get_formats(stream), format) != AST_FORMAT_CMP_NOT_EQUAL) {
+ ao2_ref(format, -1);
+ continue;
+ }
+
+ ast_format_cap_append(ast_stream_get_formats(stream), format, ast_format_cap_get_framing(audio_formats));
+ ao2_ref(format, -1);
+ }
+ }
+ }
+
+ ast_channel_request_stream_topology_change(chan, new_topology, &simple_bridge);
+
+ ast_stream_topology_free(new_topology);
+}
+
static void simple_bridge_stream_topology_changed(struct ast_bridge *bridge,
struct ast_bridge_channel *bridge_channel)
{
@@ -135,9 +198,9 @@
/* Align topologies according to size or first channel to join */
if (ast_stream_topology_get_count(t0) < ast_stream_topology_get_count(t1)) {
- ast_channel_request_stream_topology_change(c0, t1, &simple_bridge);
+ simple_bridge_request_stream_topology_change(c0, t1);
} else {
- ast_channel_request_stream_topology_change(c1, t0, &simple_bridge);
+ simple_bridge_request_stream_topology_change(c1, t0);
}
}
--
To view, visit https://gerrit.asterisk.org/6760
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8fc0cc03e8bcfd0be8302f13b9f32d8268977f43
Gerrit-Change-Number: 6760
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171012/845478b5/attachment.html>
More information about the asterisk-code-review
mailing list