[asterisk-commits] pcadach: branch pcadach/chan_h323-live r42082 - /team/pcadach/chan_h323-live/...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Sep 5 21:27:25 MST 2006


Author: pcadach
Date: Tue Sep  5 23:27:25 2006
New Revision: 42082

URL: http://svn.digium.com/view/asterisk?rev=42082&view=rev
Log:
1) Don't change channel's status when AST_CONTROL_ASNWER is queued,
   this will be done by Asterisk's core;
2) Handle invalid payload types reported by OpenH323 (when no OpalMediaFormat
   is available for choosen media format);
3) Don't try to touch a channel if nothing changed on RTP startup.

Modified:
    team/pcadach/chan_h323-live/channels/chan_h323.c

Modified: team/pcadach/chan_h323-live/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/team/pcadach/chan_h323-live/channels/chan_h323.c?rev=42082&r1=42081&r2=42082&view=diff
==============================================================================
--- team/pcadach/chan_h323-live/channels/chan_h323.c (original)
+++ team/pcadach/chan_h323-live/channels/chan_h323.c Tue Sep  5 23:27:25 2006
@@ -861,6 +861,10 @@
 		ch->nativeformats = ast_codec_choose(&pvt->options.prefs, fmt, 1)/* | (pvt->jointcapability & AST_FORMAT_VIDEO_MASK)*/;
 		pvt->nativeformats = ch->nativeformats;
 		fmt = ast_best_codec(ch->nativeformats);
+		ch->writeformat = fmt;
+		ch->rawwriteformat = fmt;
+		ch->readformat = fmt;
+		ch->rawreadformat = fmt;
 		ch->fds[0] = ast_rtp_fd(pvt->rtp);
 		ch->fds[1] = ast_rtcp_fd(pvt->rtp);
 #ifdef VIDEO_SUPPORT
@@ -877,10 +881,6 @@
 		if (state == AST_STATE_RING) {
 			ch->rings = 1;
 		}
-		ch->writeformat = fmt;
-		ch->rawwriteformat = fmt;
-		ch->readformat = fmt;
-		ch->rawreadformat = fmt;
 		/* Allocate dsp for in-band DTMF support */
 		if (pvt->options.dtmfmode & H323_DTMF_INBAND) {
 			pvt->vad = ast_dsp_new();
@@ -1682,6 +1682,7 @@
 	struct oh323_pvt *pvt;
 	struct sockaddr_in them;
 	struct rtpPayloadType rtptype;
+	int nativeformats_changed;
 
 	if (h323debug)
 		ast_log(LOG_DEBUG, "Setting up RTP connection for %s\n", token);
@@ -1696,21 +1697,41 @@
 		ast_mutex_unlock(&pvt->lock);
 		return;
 	}
-	rtptype = ast_rtp_lookup_pt(pvt->rtp, pt);
-	pvt->nativeformats = rtptype.code;
-	if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
-		pvt->owner->nativeformats = pvt->nativeformats;
-		ast_set_read_format(pvt->owner, pvt->owner->readformat);
-		ast_set_write_format(pvt->owner, pvt->owner->writeformat);
-		if (pvt->options.progress_audio)
-			ast_queue_control(pvt->owner, AST_CONTROL_PROGRESS);
-		ast_channel_unlock(pvt->owner);
-	}
-	else {
-		if (pvt->options.progress_audio)
-			pvt->newcontrol = AST_CONTROL_PROGRESS;
+
+	/* Change native format to reflect information taken from OLC/OLCAck */
+	nativeformats_changed = 0;
+	if (pt != 128) {	/* Payload type is invalid, so try to use previously decided */
+		rtptype = ast_rtp_lookup_pt(pvt->rtp, pt);
 		if (h323debug)
-			ast_log(LOG_DEBUG, "RTP connection preparation for %s is pending...\n", token);
+			ast_log(LOG_DEBUG, "Native format is set to %d from %d by RTP payload type %d\n", rtptype.code, pvt->nativeformats, pt);
+		if (pvt->nativeformats != rtptype.code) {
+			pvt->nativeformats = rtptype.code;
+			nativeformats_changed = 1;
+		}
+	} else if (h323debug)
+		ast_log(LOG_NOTICE, "Payload type is unknown, formats isn't changed\n");
+
+	/* Don't try to lock the channel if nothing changed */
+	if (nativeformats_changed || pvt->options.progress_audio) {
+		if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
+			/* Re-build translation path only if native format(s) has been changed */
+			if (pvt->owner->nativeformats != pvt->nativeformats) {
+				if (h323debug)
+					ast_log(LOG_DEBUG, "Native format changed to %d from %d, read format is %d, write format is %d\n", pvt->nativeformats, pvt->owner->nativeformats, pvt->owner->readformat, pvt->owner->writeformat);
+				pvt->owner->nativeformats = pvt->nativeformats;
+				ast_set_read_format(pvt->owner, pvt->owner->readformat);
+				ast_set_write_format(pvt->owner, pvt->owner->writeformat);
+			}
+			if (pvt->options.progress_audio)
+				ast_queue_control(pvt->owner, AST_CONTROL_PROGRESS);
+			ast_channel_unlock(pvt->owner);
+		}
+		else {
+			if (pvt->options.progress_audio)
+				pvt->newcontrol = AST_CONTROL_PROGRESS;
+			if (h323debug)
+				ast_log(LOG_DEBUG, "RTP connection preparation for %s is pending...\n", token);
+		}
 	}
 
 	them.sin_family = AF_INET;
@@ -1749,7 +1770,7 @@
 		ast_mutex_unlock(&pvt->lock);
 		return;
 	}
-	update_state(pvt, AST_STATE_UP, AST_CONTROL_ANSWER);
+	update_state(pvt, -1, AST_CONTROL_ANSWER);
 	ast_mutex_unlock(&pvt->lock);
 	return;
 }



More information about the asterisk-commits mailing list