[svn-commits] trunk r9001 - in /trunk: ./ apps/ channels/ include/asterisk/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Jan 31 10:19:02 MST 2006


Author: russell
Date: Tue Jan 31 11:18:58 2006
New Revision: 9001

URL: http://svn.digium.com/view/asterisk?rev=9001&view=rev
Log:
define a global null_frame object so when queueing a null frame, you don't
have to allocate one on the stack

Modified:
    trunk/apps/app_meetme.c
    trunk/channel.c
    trunk/channels/chan_agent.c
    trunk/channels/chan_features.c
    trunk/channels/chan_h323.c
    trunk/channels/chan_mgcp.c
    trunk/channels/chan_sip.c
    trunk/frame.c
    trunk/include/asterisk/frame.h
    trunk/rtp.c
    trunk/udptl.c

Modified: trunk/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_meetme.c?rev=9001&r1=9000&r2=9001&view=diff
==============================================================================
--- trunk/apps/app_meetme.c (original)
+++ trunk/apps/app_meetme.c Tue Jan 31 11:18:58 2006
@@ -206,7 +206,6 @@
 };
 
 static int admin_exec(struct ast_channel *chan, void *data);
-static struct ast_frame null_frame = { AST_FRAME_NULL, };
 
 static void *recordthread(void *args);
 
@@ -1574,7 +1573,7 @@
 								if (conf->transpath[index]) {
 									conf->transframe[index] = ast_translate(conf->transpath[index], conf->origframe, 0);
 									if (!conf->transframe[index])
-										conf->transframe[index] = &null_frame;
+										conf->transframe[index] = &ast_null_frame;
 								}
 							}
 						}

Modified: trunk/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/channel.c?rev=9001&r1=9000&r2=9001&view=diff
==============================================================================
--- trunk/channel.c (original)
+++ trunk/channel.c Tue Jan 31 11:18:58 2006
@@ -1760,17 +1760,13 @@
 	void *data;
 	int res;
 #endif
-	static struct ast_frame null_frame = {
-		AST_FRAME_NULL,
-	};
-	
 	ast_mutex_lock(&chan->lock);
 	if (chan->masq) {
 		if (ast_do_masquerade(chan)) {
 			ast_log(LOG_WARNING, "Failed to perform masquerade\n");
 			f = NULL;
 		} else
-			f =  &null_frame;
+			f =  &ast_null_frame;
 		ast_mutex_unlock(&chan->lock);
 		return f;
 	}
@@ -1838,8 +1834,7 @@
 				chan->timingdata = NULL;
 				ast_mutex_unlock(&chan->lock);
 			}
-			f =  &null_frame;
-			return f;
+			return &ast_null_frame;
 		} else
 			ast_log(LOG_NOTICE, "No/unknown event '%d' on timer for '%s'?\n", blah, chan->name);
 	} else
@@ -1851,8 +1846,7 @@
 		chan->generatordata = NULL;     /* reset to let ast_write get through */
 		chan->generator->generate(chan, tmp, -1, -1);
 		chan->generatordata = tmp;
-		f = &null_frame;
-		return f;
+		return &ast_null_frame;
 	}
 
 	/* Check for pending read queue */
@@ -1872,7 +1866,7 @@
 				f = chan->tech->exception(chan);
 			else {
 				ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", chan->name);
-				f = &null_frame;
+				f = &ast_null_frame;
 			}
 			/* Clear the exception flag */
 			ast_clear_flag(chan, AST_FLAG_EXCEPTION);
@@ -1898,7 +1892,7 @@
 			if (f->subclass == AST_CONTROL_ANSWER) {
 				if (prestate == AST_STATE_UP) {
 					ast_log(LOG_DEBUG, "Dropping duplicate answer!\n");
-					f = &null_frame;
+					f = &ast_null_frame;
 				}
 				/* Answer the CDR */
 				ast_setstate(chan, AST_STATE_UP);
@@ -1912,7 +1906,7 @@
 					chan->dtmfq[strlen(chan->dtmfq)] = f->subclass;
 				else
 					ast_log(LOG_WARNING, "Dropping deferred DTMF digits on %s\n", chan->name);
-				f = &null_frame;
+				f = &ast_null_frame;
 			}
 			break;
 		case AST_FRAME_DTMF_BEGIN:
@@ -1924,14 +1918,14 @@
 		case AST_FRAME_VOICE:
 			if (dropaudio) {
 				ast_frfree(f);
-				f = &null_frame;
+				f = &ast_null_frame;
 			} else if (!(f->subclass & chan->nativeformats)) {
 				/* This frame can't be from the current native formats -- drop it on the
 				   floor */
 				ast_log(LOG_NOTICE, "Dropping incompatible voice frame on %s of format %s since our native format has changed to %s\n",
 					chan->name, ast_getformatname(f->subclass), ast_getformatname(chan->nativeformats));
 				ast_frfree(f);
-				f = &null_frame;
+				f = &ast_null_frame;
 			} else {
 				if (chan->spies)
 					queue_frame_to_spies(chan, f, SPY_READ);
@@ -1962,7 +1956,7 @@
 
 				if (chan->readtrans) {
 					if (!(f = ast_translate(chan->readtrans, f, 1)))
-						f = &null_frame;
+						f = &ast_null_frame;
 				}
 
 				/* Run any generator sitting on the channel */
@@ -3121,10 +3115,9 @@
 			);
 		ast_channel_free(clone);
 	} else {
-		struct ast_frame null_frame = { AST_FRAME_NULL, };
 		ast_log(LOG_DEBUG, "Released clone lock on '%s'\n", clone->name);
 		ast_set_flag(clone, AST_FLAG_ZOMBIE);
-		ast_queue_frame(clone, &null_frame);
+		ast_queue_frame(clone, &ast_null_frame);
 		ast_mutex_unlock(&clone->lock);
 	}
 	

Modified: trunk/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_agent.c?rev=9001&r1=9000&r2=9001&view=diff
==============================================================================
--- trunk/channels/chan_agent.c (original)
+++ trunk/channels/chan_agent.c Tue Jan 31 11:18:58 2006
@@ -438,7 +438,6 @@
 {
 	struct agent_pvt *p = ast->tech_pvt;
 	struct ast_frame *f = NULL;
-	static struct ast_frame null_frame = { AST_FRAME_NULL, };
 	static struct ast_frame answer_frame = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
 	const char *status;
 	ast_mutex_lock(&p->lock); 
@@ -448,7 +447,7 @@
 		p->chan->fdno = (ast->fdno == AST_AGENT_FD) ? AST_TIMING_FD : ast->fdno;
 		f = ast_read(p->chan);
 	} else
-		f = &null_frame;
+		f = &ast_null_frame;
 	if (!f) {
 		/* If there's a channel, hang it up (if it's on a callback) make it NULL */
 		if (p->chan) {
@@ -486,7 +485,7 @@
  						ast_verbose(VERBOSE_PREFIX_3 "%s answered, waiting for '#' to acknowledge\n", p->chan->name);
  					/* Don't pass answer along */
  					ast_frfree(f);
- 					f = &null_frame;
+ 					f = &ast_null_frame;
  				} else {
  					p->acknowledged = 1;
  					/* Use the builtin answer frame for the 
@@ -513,7 +512,7 @@
  			/* don't pass voice until the call is acknowledged */
  			if (!p->acknowledged) {
  				ast_frfree(f);
- 				f = &null_frame;
+ 				f = &ast_null_frame;
  			}
  			break;
   		}
@@ -899,7 +898,6 @@
 static struct ast_channel *agent_new(struct agent_pvt *p, int state)
 {
 	struct ast_channel *tmp;
-	struct ast_frame null_frame = { AST_FRAME_NULL };
 #if 0
 	if (!p->chan) {
 		ast_log(LOG_WARNING, "No channel? :(\n");
@@ -950,7 +948,7 @@
 		if( ast_mutex_trylock(&p->app_lock) )
 		{
 			if (p->chan) {
-				ast_queue_frame(p->chan, &null_frame);
+				ast_queue_frame(p->chan, &ast_null_frame);
 				ast_mutex_unlock(&p->lock);	/* For other thread to read the condition. */
 				ast_mutex_lock(&p->app_lock);
 				ast_mutex_lock(&p->lock);

Modified: trunk/channels/chan_features.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_features.c?rev=9001&r1=9000&r2=9001&view=diff
==============================================================================
--- trunk/channels/chan_features.c (original)
+++ trunk/channels/chan_features.c Tue Jan 31 11:18:58 2006
@@ -241,12 +241,11 @@
 
 static struct ast_frame  *features_read(struct ast_channel *ast)
 {
-	static struct ast_frame null_frame = { AST_FRAME_NULL, };
 	struct feature_pvt *p = ast->tech_pvt;
 	struct ast_frame *f;
 	int x;
 	
-	f = &null_frame;
+	f = &ast_null_frame;
 	ast_mutex_lock(&p->lock);
 	x = indexof(p, ast, 0);
 	if (!x && p->subchan) {

Modified: trunk/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_h323.c?rev=9001&r1=9000&r2=9001&view=diff
==============================================================================
--- trunk/channels/chan_h323.c (original)
+++ trunk/channels/chan_h323.c Tue Jan 31 11:18:58 2006
@@ -543,7 +543,6 @@
 {
 	/* Retrieve audio/etc from channel.  Assumes pvt->lock is already held. */
 	struct ast_frame *f;
-	static struct ast_frame null_frame = { AST_FRAME_NULL, };
 
 	/* Only apply it for the first packet, we just need the correct ip/port */
 	if (pvt->options.nat) {
@@ -554,7 +553,7 @@
 	f = ast_rtp_read(pvt->rtp);
 	/* Don't send RFC2833 if we're not supposed to */
 	if (f && (f->frametype == AST_FRAME_DTMF) && !(pvt->options.dtmfmode & H323_DTMF_RFC2833)) {
-		return &null_frame;
+		return &ast_null_frame;
 	}
 	if (pvt->owner) {
 		/* We already hold the channel lock */
@@ -563,7 +562,7 @@
 				/* Try to avoid deadlock */
 				if (ast_mutex_trylock(&pvt->owner->lock)) {
 					ast_log(LOG_NOTICE, "Format changed but channel is locked. Ignoring frame...\n");
-					return &null_frame;
+					return &ast_null_frame;
 				}
 				ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
 				pvt->owner->nativeformats = f->subclass;

Modified: trunk/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_mgcp.c?rev=9001&r1=9000&r2=9001&view=diff
==============================================================================
--- trunk/channels/chan_mgcp.c (original)
+++ trunk/channels/chan_mgcp.c Tue Jan 31 11:18:58 2006
@@ -1219,12 +1219,11 @@
 {
 	/* Retrieve audio/etc from channel.  Assumes sub->lock is already held. */
 	struct ast_frame *f;
-	static struct ast_frame null_frame = { AST_FRAME_NULL, };
 
 	f = ast_rtp_read(sub->rtp);
 	/* Don't send RFC2833 if we're not supposed to */
 	if (f && (f->frametype == AST_FRAME_DTMF) && !(sub->parent->dtmfmode & MGCP_DTMF_RFC2833))
-		return &null_frame;
+		return &ast_null_frame;
 	if (sub->owner) {
 		/* We already hold the channel lock */
 		if (f->frametype == AST_FRAME_VOICE) {

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=9001&r1=9000&r2=9001&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Tue Jan 31 11:18:58 2006
@@ -3051,11 +3051,10 @@
 {
 	/* Retrieve audio/etc from channel.  Assumes p->lock is already held. */
 	struct ast_frame *f;
-	static struct ast_frame null_frame = { AST_FRAME_NULL, };
 	
 	if (!p->rtp) {
 		/* We have no RTP allocated for this channel */
-		return &null_frame;
+		return &ast_null_frame;
 	}
 
 	switch(ast->fdno) {
@@ -3072,11 +3071,11 @@
 		f = ast_rtcp_read(p->vrtp);	/* RTCP Control Channel for video */
 		break;
 	default:
-		f = &null_frame;
+		f = &ast_null_frame;
 	}
 	/* Don't forward RFC2833 if we're not supposed to */
 	if (f && (f->frametype == AST_FRAME_DTMF) && (ast_test_flag(p, SIP_DTMF) != SIP_DTMF_RFC2833))
-		return &null_frame;
+		return &ast_null_frame;
 
 	if (p->owner) {
 		/* We already hold the channel lock */

Modified: trunk/frame.c
URL: http://svn.digium.com/view/asterisk/trunk/frame.c?rev=9001&r1=9000&r2=9001&view=diff
==============================================================================
--- trunk/frame.c (original)
+++ trunk/frame.c Tue Jan 31 11:18:58 2006
@@ -56,13 +56,6 @@
 #define TYPE_DONTSEND	 0x3
 #define TYPE_MASK	 0x3
 
-struct ast_format_list {
-	int visible;	/*!< Can we see this entry */
-	int bits;	/*!< bitmask value */
-	char *name;	/*!< short name */
-	char *desc;	/*!< Description */
-};
-
 struct ast_smoother {
 	int size;
 	int format;
@@ -79,7 +72,12 @@
 };
 
 /*! \brief Definition of supported media formats (codecs) */
-static struct ast_format_list AST_FORMAT_LIST[] = {
+static struct ast_format_list {
+	int visible;	/*!< Can we see this entry */
+	int bits;	/*!< bitmask value */
+	char *name;	/*!< short name */
+	char *desc;	/*!< Description */
+} AST_FORMAT_LIST[] = {
 	{ 1, AST_FORMAT_G723_1 , "g723" , "G.723.1"},	/*!< codec_g723_1.c */
 	{ 1, AST_FORMAT_GSM, "gsm" , "GSM"},		/*!< codec_gsm.c */
 	{ 1, AST_FORMAT_ULAW, "ulaw", "G.711 u-law" },	/*!< codec_ulaw.c */
@@ -107,6 +105,8 @@
 	{ 0, 0, "nothing", "undefined" },
 	{ 0, AST_FORMAT_MAX_VIDEO, "maxvideo", "Maximum video format" },
 };
+
+struct ast_frame ast_null_frame = { AST_FRAME_NULL, };
 
 void ast_smoother_reset(struct ast_smoother *s, int size)
 {

Modified: trunk/include/asterisk/frame.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/frame.h?rev=9001&r1=9000&r2=9001&view=diff
==============================================================================
--- trunk/include/asterisk/frame.h (original)
+++ trunk/include/asterisk/frame.h Tue Jan 31 11:18:58 2006
@@ -110,6 +110,10 @@
 	/*! Next/Prev for linking stand alone frames */
 	struct ast_frame *next;			
 };
+
+/*! Queueing a null frame is fairly common, so we declare a global null frame object
+    for this purpose instead of having to declare one on the stack */
+extern struct ast_frame ast_null_frame;
 
 #define AST_FRIENDLY_OFFSET 	64	/*! It's polite for a a new frame to
 					  have this number of bytes for additional

Modified: trunk/rtp.c
URL: http://svn.digium.com/view/asterisk/trunk/rtp.c?rev=9001&r1=9000&r2=9001&view=diff
==============================================================================
--- trunk/rtp.c (original)
+++ trunk/rtp.c Tue Jan 31 11:18:58 2006
@@ -174,7 +174,6 @@
 
 static struct ast_frame *send_dtmf(struct ast_rtp *rtp)
 {
-	static struct ast_frame null_frame = { AST_FRAME_NULL, };
 	char iabuf[INET_ADDRSTRLEN];
 
 	if (ast_tvcmp(ast_tvnow(), rtp->dtmfmute) < 0) {
@@ -182,7 +181,7 @@
 			ast_log(LOG_DEBUG, "Ignore potential DTMF echo from '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr));
 		rtp->resp = 0;
 		rtp->dtmfduration = 0;
-		return &null_frame;
+		return &ast_null_frame;
 	}
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Sending dtmf: %d (%c), at %s\n", rtp->resp, rtp->resp, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr));
@@ -364,7 +363,6 @@
 
 struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp)
 {
-	static struct ast_frame null_frame = { AST_FRAME_NULL, };
 	socklen_t len;
 	int hdrlen = 8;
 	int res;
@@ -373,7 +371,7 @@
 	char iabuf[INET_ADDRSTRLEN];
 	
 	if (!rtp || !rtp->rtcp)
-		return &null_frame;
+		return &ast_null_frame;
 
 	len = sizeof(sin);
 	
@@ -385,12 +383,12 @@
 			ast_log(LOG_WARNING, "RTP Read error: %s\n", strerror(errno));
 		if (errno == EBADF)
 			CRASH;
-		return &null_frame;
+		return &ast_null_frame;
 	}
 
 	if (res < hdrlen) {
 		ast_log(LOG_WARNING, "RTP Read too short\n");
-		return &null_frame;
+		return &ast_null_frame;
 	}
 
 	if (rtp->nat) {
@@ -404,7 +402,7 @@
 	}
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Got RTCP report of %d bytes\n", res);
-	return &null_frame;
+	return &ast_null_frame;
 }
 
 static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int timestamp, int mark)
@@ -434,7 +432,7 @@
 	char iabuf[INET_ADDRSTRLEN];
 	unsigned int timestamp;
 	unsigned int *rtpheader;
-	static struct ast_frame *f, null_frame = { AST_FRAME_NULL, };
+	static struct ast_frame *f;
 	struct rtpPayloadType rtpPT;
 	
 	len = sizeof(sin);
@@ -450,17 +448,17 @@
 			ast_log(LOG_WARNING, "RTP Read error: %s\n", strerror(errno));
 		if (errno == EBADF)
 			CRASH;
-		return &null_frame;
+		return &ast_null_frame;
 	}
 	if (res < hdrlen) {
 		ast_log(LOG_WARNING, "RTP Read too short\n");
-		return &null_frame;
+		return &ast_null_frame;
 	}
 
 	/* Ignore if the other side hasn't been given an address
 	   yet.  */
 	if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port)
-		return &null_frame;
+		return &ast_null_frame;
 
 	if (rtp->nat) {
 		/* Send to whoever sent to us */
@@ -480,7 +478,7 @@
 	/* Check RTP version */
 	version = (seqno & 0xC0000000) >> 30;
 	if (version != 2)
-		return &null_frame;
+		return &ast_null_frame;
 	
 	payloadtype = (seqno & 0x7f0000) >> 16;
 	padding = seqno & (1 << 29);
@@ -502,7 +500,7 @@
 
 	if (res < hdrlen) {
 		ast_log(LOG_WARNING, "RTP Read too short (%d, expecting %d)\n", res, hdrlen);
-		return &null_frame;
+		return &ast_null_frame;
 	}
 
 	if(rtp_debug_test_addr(&sin))
@@ -537,7 +535,7 @@
 			if (f)
 				return f;
 			else
-				return &null_frame;
+				return &ast_null_frame;
 		} else if (rtpPT.code == AST_RTP_CISCO_DTMF) {
 			/* It's really special -- process it the Cisco way */
 			if (rtp->lasteventseqn <= seqno || rtp->resp == 0 || (rtp->lasteventseqn >= 65530 && seqno <= 6)) {
@@ -548,17 +546,17 @@
 				if (f) 
 				return f; 
 			else 
-				return &null_frame;
+				return &ast_null_frame;
 		} else if (rtpPT.code == AST_RTP_CN) {
 			/* Comfort Noise */
 			f = process_rfc3389(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen);
 			if (f) 
 				return f; 
 			else 
-				return &null_frame;
+				return &ast_null_frame;
 		} else {
 			ast_log(LOG_NOTICE, "Unknown RTP codec %d received\n", payloadtype);
-			return &null_frame;
+			return &ast_null_frame;
 		}
 	}
 	rtp->f.subclass = rtpPT.code;

Modified: trunk/udptl.c
URL: http://svn.digium.com/view/asterisk/trunk/udptl.c?rev=9001&r1=9000&r2=9001&view=diff
==============================================================================
--- trunk/udptl.c (original)
+++ trunk/udptl.c Tue Jan 31 11:18:58 2006
@@ -645,7 +645,6 @@
 	uint16_t seqno = 0;
 	char iabuf[INET_ADDRSTRLEN];
 	uint16_t *udptlheader;
-	static struct ast_frame null_frame = { AST_FRAME_NULL, };
 
 	len = sizeof(sin);
 	
@@ -662,12 +661,12 @@
 			ast_log(LOG_WARNING, "UDPTL read error: %s\n", strerror(errno));
 		if (errno == EBADF)
 			CRASH;
-		return &null_frame;
+		return &ast_null_frame;
 	}
 
 	/* Ignore if the other side hasn't been given an address yet. */
 	if (!udptl->them.sin_addr.s_addr || !udptl->them.sin_port)
-		return &null_frame;
+		return &ast_null_frame;
 
 	if (udptl->nat) {
 		/* Send to whoever sent to us */



More information about the svn-commits mailing list