]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
app_dial: Flip stream direction of outgoing channel.
authorMaximilian Fridrich <m.fridrich@commend.com>
Wed, 13 Apr 2022 13:12:03 +0000 (15:12 +0200)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Tue, 26 Apr 2022 15:48:48 +0000 (10:48 -0500)
When executing dial, the topology of the incoming channel is cloned and
used for the outgoing channel. This creates issues when an incoming
stream is sendonly or recvonly as the stream state of the outgoing
channel will be the same as the stream state of the incoming channel.

Now the stream state is flipped for the outgoing stream in
dial_exec_full if the incoming stream topology is recvonly or sendonly.

ASTERISK-29655
Reported by: Michael Auracher

ASTERISK-29638
Reported by: Michael Auracher

Change-Id: I294dc834ac9a5f048b101b691669959e9df630e1

apps/app_dial.c

index 8be6effc87900818c2acb4e69c8cc5f716c0d302..7ea23f37996c329cc56988143a70a5fda1b5bd7e 100644 (file)
@@ -2607,9 +2607,11 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
                struct ast_channel *tc; /* channel for this destination */
                char *number;
                char *tech;
+               int i;
                size_t tech_len;
                size_t number_len;
                struct ast_stream_topology *topology;
+               struct ast_stream *stream;
 
                cur = ast_strip(cur);
                if (ast_strlen_zero(cur)) {
@@ -2675,6 +2677,21 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
 
                ast_channel_unlock(chan);
 
+               for (i = 0; i < ast_stream_topology_get_count(topology); ++i) {
+                       stream = ast_stream_topology_get_stream(topology, i);
+                       /* For both recvonly and sendonly the stream state reflects our state, that is we
+                        * are receiving only and we are sending only. Since we are requesting a
+                        * channel for the peer, we need to swap this to reflect what we will be doing.
+                        * That is, if we are receiving from Alice then we want to be sending to Bob,
+                        * so swap recvonly to sendonly and vice versa.
+                        */
+                       if (ast_stream_get_state(stream) == AST_STREAM_STATE_RECVONLY) {
+                               ast_stream_set_state(stream, AST_STREAM_STATE_SENDONLY);
+                       } else if (ast_stream_get_state(stream) == AST_STREAM_STATE_SENDONLY) {
+                               ast_stream_set_state(stream, AST_STREAM_STATE_RECVONLY);
+                       }
+               }
+
                tc = ast_request_with_stream_topology(tmp->tech, topology, NULL, chan, tmp->number, &cause);
 
                ast_stream_topology_free(topology);