[Asterisk-cvs] asterisk app.c,1.9,1.10 channel.c,1.88,1.89 file.c,1.37,1.38 indications.c,1.12,1.13

markster at lists.digium.com markster at lists.digium.com
Sat Mar 27 01:52:45 CST 2004


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv1845

Modified Files:
	app.c channel.c file.c indications.c 
Log Message:
Make read/write mode have a lock parameter and use it properly.


Index: app.c
===================================================================
RCS file: /usr/cvsroot/asterisk/app.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- app.c	11 Jun 2003 12:14:38 -0000	1.9
+++ app.c	27 Mar 2004 06:50:12 -0000	1.10
@@ -86,7 +86,7 @@
 			return res;
 	}
 	rfmt = c->readformat;
-	res = ast_set_read_format(c, AST_FORMAT_SLINEAR);
+	res = ast_set_read_format(c, AST_FORMAT_SLINEAR, 1);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
 		return -1;
@@ -135,7 +135,7 @@
 			ast_frfree(f);
 		}
 	}
-	res = ast_set_read_format(c, rfmt);
+	res = ast_set_read_format(c, rfmt, 1);
 	if (res)
 		ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", c->name);
 	ast_dsp_free(sildet);

Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- channel.c	19 Mar 2004 09:37:28 -0000	1.88
+++ channel.c	27 Mar 2004 06:50:12 -0000	1.89
@@ -1499,12 +1499,13 @@
 	return res;
 }
 
-int ast_set_write_format(struct ast_channel *chan, int fmts)
+int ast_set_write_format(struct ast_channel *chan, int fmts, int needlock)
 {
 	int fmt;
 	int native;
 	int res;
 	
+	ast_mutex_lock(&chan->lock);
 	native = chan->nativeformats;
 	fmt = fmts;
 	
@@ -1512,6 +1513,7 @@
 	if (res < 0) {
 		ast_log(LOG_NOTICE, "Unable to find a path from %s to %s\n",
 			ast_getformatname(fmts), ast_getformatname(chan->nativeformats));
+		ast_mutex_unlock(&chan->lock);
 		return -1;
 	}
 	
@@ -1526,15 +1528,18 @@
 	chan->pvt->writetrans = ast_translator_build_path(chan->pvt->rawwriteformat, chan->writeformat);
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Set channel %s to write format %s\n", chan->name, ast_getformatname(chan->writeformat));
+	ast_mutex_unlock(&chan->lock);
 	return 0;
 }
 
-int ast_set_read_format(struct ast_channel *chan, int fmts)
+int ast_set_read_format(struct ast_channel *chan, int fmts, int needlock)
 {
 	int fmt;
 	int native;
 	int res;
 	
+	if (needlock)
+		ast_mutex_lock(&chan->lock);
 	native = chan->nativeformats;
 	fmt = fmts;
 	/* Find a translation path from the native read format to one of the user's read formats */
@@ -1542,6 +1547,7 @@
 	if (res < 0) {
 		ast_log(LOG_NOTICE, "Unable to find a path from %s to %s\n",
 			ast_getformatname(chan->nativeformats), ast_getformatname(fmts));
+		ast_mutex_unlock(&chan->lock);
 		return -1;
 	}
 	
@@ -1557,6 +1563,7 @@
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Set channel %s to read format %s\n", 
 			chan->name, ast_getformatname(chan->readformat));
+	ast_mutex_unlock(&chan->lock);
 	return 0;
 }
 
@@ -1913,21 +1920,25 @@
 	int peerf;
 	int chanf;
 	int res;
+	ast_mutex_lock(&peer->lock);
 	peerf = peer->nativeformats;
+	ast_mutex_unlock(&peer->lock);
+	ast_mutex_lock(&chan->lock);
 	chanf = chan->nativeformats;
+	ast_mutex_unlock(&chan->lock);
 	res = ast_translator_best_choice(&peerf, &chanf);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", chan->name, chan->nativeformats, peer->name, peer->nativeformats);
 		return -1;
 	}
 	/* Set read format on channel */
-	res = ast_set_read_format(chan, peerf);
+	res = ast_set_read_format(chan, peerf, 1);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", chan->name, chanf);
 		return -1;
 	}
 	/* Set write format on peer channel */
-	res = ast_set_write_format(peer, peerf);
+	res = ast_set_write_format(peer, peerf, 1);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", peer->name, peerf);
 		return -1;
@@ -1941,13 +1952,13 @@
 		return -1;
 	}
 	/* Set writeformat on channel */
-	res = ast_set_write_format(chan, chanf);
+	res = ast_set_write_format(chan, chanf, 1);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", chan->name, chanf);
 		return -1;
 	}
 	/* Set read format on peer channel */
-	res = ast_set_read_format(peer, chanf);
+	res = ast_set_read_format(peer, chanf, 1);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", peer->name, peerf);
 		return -1;
@@ -2154,10 +2165,10 @@
 	/* pvt switches.  pbx stays the same, as does next */
 	
 	/* Set the write format */
-	ast_set_write_format(original, wformat);
+	ast_set_write_format(original, wformat, 0);
 
 	/* Set the read format */
-	ast_set_read_format(original, rformat);
+	ast_set_read_format(original, rformat, 0);
 
 	ast_log(LOG_DEBUG, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat);
 
@@ -2453,7 +2464,7 @@
 {
 	struct tonepair_state *ts = params;
 	if (chan) {
-		ast_set_write_format(chan, ts->origwfmt);
+		ast_set_write_format(chan, ts->origwfmt, 0);
 	}
 	free(ts);
 }
@@ -2467,7 +2478,7 @@
 		return NULL;
 	memset(ts, 0, sizeof(struct tonepair_state));
 	ts->origwfmt = chan->writeformat;
-	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
+	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR, 1)) {
 		ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
 		tonepair_release(NULL, ts);
 		ts = NULL;

Index: file.c
===================================================================
RCS file: /usr/cvsroot/asterisk/file.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- file.c	25 Feb 2004 22:31:50 -0000	1.37
+++ file.c	27 Mar 2004 06:50:12 -0000	1.38
@@ -166,7 +166,7 @@
 		ast_closestream(tmp->vstream);
 	if (tmp->stream) {
 		ast_closestream(tmp->stream);
-		if (tmp->oldwriteformat && ast_set_write_format(tmp, tmp->oldwriteformat))
+		if (tmp->oldwriteformat && ast_set_write_format(tmp, tmp->oldwriteformat, 1))
 			ast_log(LOG_WARNING, "Unable to restore format back to %d\n", tmp->oldwriteformat);
 	}
 	return 0;
@@ -464,7 +464,7 @@
 	}
 	chan->oldwriteformat = chan->writeformat;
 	/* Set the channel to a format we can work with */
-	res = ast_set_write_format(chan, fmts);
+	res = ast_set_write_format(chan, fmts, 1);
 	
  	fd = ast_filehelper(filename2, (char *)chan, NULL, ACTION_OPEN);
 	if(fd >= 0)

Index: indications.c
===================================================================
RCS file: /usr/cvsroot/asterisk/indications.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- indications.c	21 Mar 2004 07:35:40 -0000	1.12
+++ indications.c	27 Mar 2004 06:50:12 -0000	1.13
@@ -58,7 +58,7 @@
 {
 	struct playtones_state *ps = params;
 	if (chan) {
-		ast_set_write_format(chan, ps->origwfmt);
+		ast_set_write_format(chan, ps->origwfmt, 0);
 	}
 	if (ps->items) free(ps->items);
 	free(ps);
@@ -72,7 +72,7 @@
 		return NULL;
 	memset(ps, 0, sizeof(struct playtones_state));
 	ps->origwfmt = chan->writeformat;
-	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
+	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR, 1)) {
 		ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
 		playtones_release(NULL, ps);
 		ps = NULL;




More information about the svn-commits mailing list