[asterisk-commits] file: trunk r48507 - in /trunk: ./ main/rtp.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Dec 15 12:57:05 MST 2006


Author: file
Date: Fri Dec 15 13:57:04 2006
New Revision: 48507

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48507
Log:
Merged revisions 48506 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r48506 | file | 2006-12-15 14:55:28 -0500 (Fri, 15 Dec 2006) | 2 lines

Turn payload_lock into bridge_lock and make it encompass all RTP structure contents that may relate to bridge information, including who we are bridged to.

........

Modified:
    trunk/   (props changed)
    trunk/main/rtp.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/main/rtp.c
URL: http://svn.digium.com/view/asterisk/trunk/main/rtp.c?view=diff&rev=48507&r1=48506&r2=48507
==============================================================================
--- trunk/main/rtp.c (original)
+++ trunk/main/rtp.c Fri Dec 15 13:57:04 2006
@@ -160,13 +160,11 @@
 	struct io_context *io;
 	void *data;
 	ast_rtp_callback callback;
-
-	ast_mutex_t payload_lock;
+	ast_mutex_t bridge_lock;
 	struct rtpPayloadType current_RTP_PT[MAX_RTP_PT];
 	int rtp_lookup_code_cache_isAstFormat; /*!< a cache for the result of rtp_lookup_code(): */
 	int rtp_lookup_code_cache_code;
 	int rtp_lookup_code_cache_result;
-
 	struct ast_rtcp *rtcp;
 	struct ast_codec_pref pref;
 	struct ast_rtp *bridged;        /*!< Who we are Packet bridged to */
@@ -1064,9 +1062,8 @@
 }
 
 /*! \brief Perform a Packet2Packet RTP write */
-static int bridge_p2p_rtp_write(struct ast_rtp *rtp, unsigned int *rtpheader, int len, int hdrlen)
-{
-	struct ast_rtp *bridged = ast_rtp_get_bridged(rtp);
+static int bridge_p2p_rtp_write(struct ast_rtp *rtp, struct ast_rtp *bridged, unsigned int *rtpheader, int len, int hdrlen)
+{
 	int res = 0, payload = 0, bridged_payload = 0, version, padding, mark, ext;
 	struct rtpPayloadType rtpPT;
 	unsigned int seqno;
@@ -1134,6 +1131,7 @@
 	unsigned int timestamp;
 	unsigned int *rtpheader;
 	struct rtpPayloadType rtpPT;
+	struct ast_rtp *bridged = NULL;
 	
 	/* If time is up, kill it */
 	if (rtp->send_digit)
@@ -1195,7 +1193,7 @@
 	}
 
 	/* If we are bridged to another RTP stream, send direct */
-	if (ast_rtp_get_bridged(rtp) && !bridge_p2p_rtp_write(rtp, rtpheader, res, hdrlen))
+	if ((bridged = ast_rtp_get_bridged(rtp)) && !bridge_p2p_rtp_write(rtp, bridged, rtpheader, res, hdrlen))
 		return &ast_null_frame;
 
 	if (version != 2)
@@ -1423,7 +1421,7 @@
 	if (!rtp)
 		return;
 
-	ast_mutex_lock(&rtp->payload_lock);
+	ast_mutex_lock(&rtp->bridge_lock);
 
 	for (i = 0; i < MAX_RTP_PT; ++i) {
 		rtp->current_RTP_PT[i].isAstFormat = 0;
@@ -1434,14 +1432,14 @@
 	rtp->rtp_lookup_code_cache_code = 0;
 	rtp->rtp_lookup_code_cache_result = 0;
 
-	ast_mutex_unlock(&rtp->payload_lock);
+	ast_mutex_unlock(&rtp->bridge_lock);
 }
 
 void ast_rtp_pt_default(struct ast_rtp* rtp) 
 {
 	int i;
 
-	ast_mutex_lock(&rtp->payload_lock);
+	ast_mutex_lock(&rtp->bridge_lock);
 
 	/* Initialize to default payload types */
 	for (i = 0; i < MAX_RTP_PT; ++i) {
@@ -1453,15 +1451,15 @@
 	rtp->rtp_lookup_code_cache_code = 0;
 	rtp->rtp_lookup_code_cache_result = 0;
 
-	ast_mutex_unlock(&rtp->payload_lock);
+	ast_mutex_unlock(&rtp->bridge_lock);
 }
 
 void ast_rtp_pt_copy(struct ast_rtp *dest, struct ast_rtp *src)
 {
 	unsigned int i;
 
-	ast_mutex_lock(&dest->payload_lock);
-	ast_mutex_lock(&src->payload_lock);
+	ast_mutex_lock(&dest->bridge_lock);
+	ast_mutex_lock(&src->bridge_lock);
 
 	for (i=0; i < MAX_RTP_PT; ++i) {
 		dest->current_RTP_PT[i].isAstFormat = 
@@ -1473,8 +1471,8 @@
 	dest->rtp_lookup_code_cache_code = 0;
 	dest->rtp_lookup_code_cache_result = 0;
 
-	ast_mutex_unlock(&src->payload_lock);
-	ast_mutex_unlock(&dest->payload_lock);
+	ast_mutex_unlock(&src->bridge_lock);
+	ast_mutex_unlock(&dest->bridge_lock);
 }
 
 /*! \brief Get channel driver interface structure */
@@ -1643,9 +1641,9 @@
 	if (pt < 0 || pt > MAX_RTP_PT || static_RTP_PT[pt].code == 0) 
 		return; /* bogus payload type */
 
-	ast_mutex_lock(&rtp->payload_lock);
+	ast_mutex_lock(&rtp->bridge_lock);
 	rtp->current_RTP_PT[pt] = static_RTP_PT[pt];
-	ast_mutex_unlock(&rtp->payload_lock);
+	ast_mutex_unlock(&rtp->bridge_lock);
 } 
 
 /*! \brief Make a note of a RTP payload type (with MIME type) that was seen in
@@ -1660,7 +1658,7 @@
 	if (pt < 0 || pt > MAX_RTP_PT) 
 		return; /* bogus payload type */
 	
-	ast_mutex_lock(&rtp->payload_lock);
+	ast_mutex_lock(&rtp->bridge_lock);
 
 	for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) {
 		if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 &&
@@ -1674,7 +1672,7 @@
 		}
 	}
 
-	ast_mutex_unlock(&rtp->payload_lock);
+	ast_mutex_unlock(&rtp->bridge_lock);
 
 	return;
 } 
@@ -1686,7 +1684,7 @@
 {
 	int pt;
 	
-	ast_mutex_lock(&rtp->payload_lock);
+	ast_mutex_lock(&rtp->bridge_lock);
 	
 	*astFormats = *nonAstFormats = 0;
 	for (pt = 0; pt < MAX_RTP_PT; ++pt) {
@@ -1697,7 +1695,7 @@
 		}
 	}
 	
-	ast_mutex_unlock(&rtp->payload_lock);
+	ast_mutex_unlock(&rtp->bridge_lock);
 	
 	return;
 }
@@ -1712,9 +1710,9 @@
 		return result; /* bogus payload type */
 
 	/* Start with negotiated codecs */
-	ast_mutex_lock(&rtp->payload_lock);
+	ast_mutex_lock(&rtp->bridge_lock);
 	result = rtp->current_RTP_PT[pt];
-	ast_mutex_unlock(&rtp->payload_lock);
+	ast_mutex_unlock(&rtp->bridge_lock);
 
 	/* If it doesn't exist, check our static RTP type list, just in case */
 	if (!result.code) 
@@ -1728,13 +1726,13 @@
 {
 	int pt = 0;
 
-	ast_mutex_lock(&rtp->payload_lock);
+	ast_mutex_lock(&rtp->bridge_lock);
 
 	if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat &&
 		code == rtp->rtp_lookup_code_cache_code) {
 		/* Use our cached mapping, to avoid the overhead of the loop below */
 		pt = rtp->rtp_lookup_code_cache_result;
-		ast_mutex_unlock(&rtp->payload_lock);
+		ast_mutex_unlock(&rtp->bridge_lock);
 		return pt;
 	}
 
@@ -1744,7 +1742,7 @@
 			rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat;
 			rtp->rtp_lookup_code_cache_code = code;
 			rtp->rtp_lookup_code_cache_result = pt;
-			ast_mutex_unlock(&rtp->payload_lock);
+			ast_mutex_unlock(&rtp->bridge_lock);
 			return pt;
 		}
 	}
@@ -1755,12 +1753,12 @@
 			rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat;
   			rtp->rtp_lookup_code_cache_code = code;
 			rtp->rtp_lookup_code_cache_result = pt;
-			ast_mutex_unlock(&rtp->payload_lock);
+			ast_mutex_unlock(&rtp->bridge_lock);
 			return pt;
 		}
 	}
 
-	ast_mutex_unlock(&rtp->payload_lock);
+	ast_mutex_unlock(&rtp->bridge_lock);
 
 	return -1;
 }
@@ -1872,7 +1870,7 @@
 	if (!(rtp = ast_calloc(1, sizeof(*rtp))))
 		return NULL;
 
-	ast_mutex_init(&rtp->payload_lock);
+	ast_mutex_init(&rtp->bridge_lock);
 
 	rtp->them.sin_family = AF_INET;
 	rtp->us.sin_family = AF_INET;
@@ -2003,7 +2001,13 @@
 
 struct ast_rtp *ast_rtp_get_bridged(struct ast_rtp *rtp)
 {
-	return rtp->bridged;
+	struct ast_rtp *bridged = NULL;
+
+	ast_mutex_lock(&rtp->bridge_lock);
+	bridged = rtp->bridged;
+	ast_mutex_unlock(&rtp->bridge_lock);
+
+	return bridged;
 }
 
 void ast_rtp_stop(struct ast_rtp *rtp)
@@ -2096,7 +2100,7 @@
 		rtp->rtcp=NULL;
 	}
 
-	ast_mutex_destroy(&rtp->payload_lock);
+	ast_mutex_destroy(&rtp->bridge_lock);
 
 	free(rtp);
 }
@@ -2935,7 +2939,7 @@
 	struct sockaddr_in sin;
 	socklen_t len;
 	unsigned int *header;
-	struct ast_rtp *rtp = cbdata;
+	struct ast_rtp *rtp = cbdata, *bridged = NULL;
 
 	if (!rtp)
 		return 1;
@@ -2958,8 +2962,8 @@
 	}
 
 	/* Write directly out to other RTP stream if bridged */
-	if (ast_rtp_get_bridged(rtp))
-		bridge_p2p_rtp_write(rtp, header, res, hdrlen);
+	if ((bridged = ast_rtp_get_bridged(rtp)))
+		bridge_p2p_rtp_write(rtp, bridged, header, res, hdrlen);
 
 	return 1;
 }
@@ -3003,6 +3007,16 @@
 		rtp->ioid = ast_io_add(rtp->io, ast_rtp_fd(rtp), rtpread, AST_IO_IN, rtp);
 
 	return 0;
+}
+
+/*! \brief Helper function that sets what an RTP structure is bridged to */
+static void p2p_set_bridge(struct ast_rtp *rtp0, struct ast_rtp *rtp1)
+{
+        ast_mutex_lock(&rtp0->bridge_lock);
+        rtp0->bridged = rtp1;
+        ast_mutex_unlock(&rtp0->bridge_lock);
+
+        return;
 }
 
 /*! \brief Bridge loop for partial native bridge (packet2packet) 
@@ -3021,9 +3035,9 @@
 
 	/* Okay, setup each RTP structure to do P2P forwarding */
 	ast_clear_flag(p0, FLAG_P2P_SENT_MARK);
-	p0->bridged = p1;
+	p2p_set_bridge(p0, p1);
 	ast_clear_flag(p1, FLAG_P2P_SENT_MARK);
-	p1->bridged = p0;
+	p2p_set_bridge(p1, p0);
 
 	/* Activate callback modes if possible */
 	p0_callback = p2p_callback_enable(c0, p0, &p0_iod[0]);
@@ -3083,14 +3097,14 @@
 						p0_callback = p2p_callback_disable(c0, p0, &p0_iod[0]);
 					if (p1_callback)
 						p1_callback = p2p_callback_disable(c1, p1, &p1_iod[0]);
-					p0->bridged = NULL;
-					p1->bridged = NULL;
+					p2p_set_bridge(p0, NULL);
+					p2p_set_bridge(p1, NULL);
 				} else if (fr->subclass == AST_CONTROL_UNHOLD) {
 					/* If we are off hold, then go back to callback mode and P2P bridging */
 					ast_clear_flag(p0, FLAG_P2P_SENT_MARK);
-					p0->bridged = p1;
+					p2p_set_bridge(p0, p1);
 					ast_clear_flag(p1, FLAG_P2P_SENT_MARK);
-					p1->bridged = p0;
+					p2p_set_bridge(p1, p0);
 					p0_callback = p2p_callback_enable(c0, p0, &p0_iod[0]);
 					p1_callback = p2p_callback_enable(c1, p1, &p1_iod[0]);
 				}
@@ -3126,8 +3140,8 @@
 		p1_callback = p2p_callback_disable(c1, p1, &p1_iod[0]);
 
 	/* Break out of the direct bridge */
-	p0->bridged = NULL;
-	p1->bridged = NULL;
+	p2p_set_bridge(p0, NULL);
+	p2p_set_bridge(p1, NULL);
 
 	return res;
 }



More information about the asterisk-commits mailing list