summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2017-01-03 08:39:07 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2017-01-03 08:39:07 -0600
commitac480686bb90aa2adf83856b3608b6cddfc402cf (patch)
treec464bb0d6ca0628998f6dd06586edf18fe0221e1
parent5a5953f98c2580c7a9b0886c8ebed2a2d2639bec (diff)
parentda6f40c9ff85fa665de30f89071f13d6da8f3cf1 (diff)
Merge "bridge_native_rtp.c: Fix native rtp bridge data race."
-rw-r--r--bridges/bridge_native_rtp.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/bridges/bridge_native_rtp.c b/bridges/bridge_native_rtp.c
index 05ef4ea35..736b0c356 100644
--- a/bridges/bridge_native_rtp.c
+++ b/bridges/bridge_native_rtp.c
@@ -310,10 +310,8 @@ static int native_rtp_bridge_capable(struct ast_channel *chan)
return !ast_channel_has_hook_requiring_audio(chan);
}
-static int native_rtp_bridge_compatible(struct ast_bridge *bridge)
+static int native_rtp_bridge_compatible_check(struct ast_bridge *bridge, struct ast_bridge_channel *bc0, struct ast_bridge_channel *bc1)
{
- struct ast_bridge_channel *bc0 = AST_LIST_FIRST(&bridge->channels);
- struct ast_bridge_channel *bc1 = AST_LIST_LAST(&bridge->channels);
enum ast_rtp_glue_result native_type;
struct ast_rtp_glue *glue0, *glue1;
RAII_VAR(struct ast_rtp_instance *, instance0, NULL, ao2_cleanup);
@@ -324,13 +322,6 @@ static int native_rtp_bridge_compatible(struct ast_bridge *bridge)
RAII_VAR(struct ast_format_cap *, cap1, NULL, ao2_cleanup);
int read_ptime0, read_ptime1, write_ptime0, write_ptime1;
- /* We require two channels before even considering native bridging */
- if (bridge->num_channels != 2) {
- ast_debug(1, "Bridge '%s' can not use native RTP bridge as two channels are required\n",
- bridge->uniqueid);
- return 0;
- }
-
if (!native_rtp_bridge_capable(bc0->chan)) {
ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has features which prevent it\n",
bridge->uniqueid, ast_channel_name(bc0->chan));
@@ -406,6 +397,30 @@ static int native_rtp_bridge_compatible(struct ast_bridge *bridge)
return 1;
}
+static int native_rtp_bridge_compatible(struct ast_bridge *bridge)
+{
+ struct ast_bridge_channel *bc0;
+ struct ast_bridge_channel *bc1;
+ int is_compatible;
+
+ /* We require two channels before even considering native bridging */
+ if (bridge->num_channels != 2) {
+ ast_debug(1, "Bridge '%s' can not use native RTP bridge as two channels are required\n",
+ bridge->uniqueid);
+ return 0;
+ }
+
+ bc0 = AST_LIST_FIRST(&bridge->channels);
+ bc1 = AST_LIST_LAST(&bridge->channels);
+
+ ast_channel_lock_both(bc0->chan, bc1->chan);
+ is_compatible = native_rtp_bridge_compatible_check(bridge, bc0, bc1);
+ ast_channel_unlock(bc0->chan);
+ ast_channel_unlock(bc1->chan);
+
+ return is_compatible;
+}
+
/*! \brief Helper function which adds frame hook to bridge channel */
static int native_rtp_bridge_framehook_attach(struct ast_bridge_channel *bridge_channel)
{