[svn-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r302506 - in /team/dvossel/f...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jan 19 11:58:55 CST 2011


Author: dvossel
Date: Wed Jan 19 11:58:51 2011
New Revision: 302506

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=302506
Log:
reverting h323 conversion

Modified:
    team/dvossel/fixtheworld_phase1_step3/channels/chan_h323.c
    team/dvossel/fixtheworld_phase1_step3/channels/h323/ast_h323.cxx
    team/dvossel/fixtheworld_phase1_step3/channels/h323/ast_h323.h
    team/dvossel/fixtheworld_phase1_step3/channels/h323/chan_h323.h

Modified: team/dvossel/fixtheworld_phase1_step3/channels/chan_h323.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/channels/chan_h323.c?view=diff&rev=302506&r1=302505&r2=302506
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/channels/chan_h323.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/channels/chan_h323.c Wed Jan 19 11:58:51 2011
@@ -129,6 +129,7 @@
 static char default_context[AST_MAX_CONTEXT] = "default";
 static struct sockaddr_in bindaddr;
 
+#define GLOBAL_CAPABILITY (AST_FORMAT_G723_1 | AST_FORMAT_GSM | AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_G729A | AST_FORMAT_G726_AAL2 | AST_FORMAT_H261)
 
 /** H.323 configuration values */
 static int h323_signalling_port = 1720;
@@ -165,17 +166,17 @@
 	int amaflags;				/*!< AMA Flags */
 	struct ast_rtp_instance *rtp;		/*!< RTP Session */
 	struct ast_dsp *vad;			/*!< Used for in-band DTMF detection */
+	int nativeformats;			/*!< Codec formats supported by a channel */
 	int needhangup;				/*!< Send hangup when Asterisk is ready */
 	int hangupcause;			/*!< Hangup cause from OpenH323 layer */
 	int newstate;				/*!< Pending state change */
 	int newcontrol;				/*!< Pending control to send */
 	int newdigit;				/*!< Pending DTMF digit to send */
 	int newduration;			/*!< Pending DTMF digit duration to send */
-	struct ast_format pref_codec;     /*!< Preferred codec */
-	struct ast_format_cap *peercap;   /*!< Capabilities learned from peer */
-	struct ast_format_cap *jointcap;  /*!< Common capabilities for local and remote side */
-	struct ast_format_cap *nativeformats; /*!< Codec formats supported by a channel */
-	struct ast_codec_pref peer_prefs;   /*!< Preferenced list of codecs which remote side supports */
+	format_t pref_codec;				/*!< Preferred codec */
+	format_t peercapability;			/*!< Capabilities learned from peer */
+	format_t jointcapability;			/*!< Common capabilities for local and remote side */
+	struct ast_codec_pref peer_prefs;	/*!< Preferenced list of codecs which remote side supports */
 	int dtmf_pt[2];				/*!< Payload code used for RFC2833/CISCO messages */
 	int curDTMF;				/*!< DTMF tone being generated to Asterisk side */
 	int DTMFsched;				/*!< Scheduler descriptor for DTMF */
@@ -230,7 +231,7 @@
 static void delete_aliases(void);
 static void prune_peers(void);
 
-static struct ast_channel *oh323_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
+static struct ast_channel *oh323_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
 static int oh323_digit_begin(struct ast_channel *c, char digit);
 static int oh323_digit_end(struct ast_channel *c, char digit, unsigned int duration);
 static int oh323_call(struct ast_channel *c, char *dest, int timeout);
@@ -241,9 +242,10 @@
 static int oh323_indicate(struct ast_channel *c, int condition, const void *data, size_t datalen);
 static int oh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
 
-static struct ast_channel_tech oh323_tech = {
+static const struct ast_channel_tech oh323_tech = {
 	.type = "H323",
 	.description = tdesc,
+	.capabilities = AST_FORMAT_AUDIO_MASK,
 	.properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
 	.requester = oh323_request,
 	.send_digit_begin = oh323_digit_begin,
@@ -258,14 +260,6 @@
 	.bridge = ast_rtp_instance_bridge,
 };
 
-static void call_options_copy(call_options_t *dst, call_options_t *src)
-{
-	struct ast_format_cap *tmpcap = dst->cap;
-	memcpy(dst, src, sizeof(*dst));
-	dst->cap = tmpcap;
-	ast_format_cap_copy2(dst->cap, src->cap);
-}
-
 static const char* redirectingreason2str(int redirectingreason)
 {
 	switch (redirectingreason) {
@@ -294,7 +288,6 @@
 	if (h323debug)
 		ast_debug(1, "Destroying user '%s'\n", user->name);
 	ast_free_ha(user->ha);
-	user->options.cap = ast_format_cap_destroy(user->options.cap);
 	ast_free(user);
 }
 
@@ -303,7 +296,6 @@
 	if (h323debug)
 		ast_debug(1, "Destroying peer '%s'\n", peer->name);
 	ast_free_ha(peer->ha);
-	peer->options.cap = ast_format_cap_destroy(peer->options.cap);
 	ast_free(peer);
 }
 
@@ -339,12 +331,12 @@
 /*! \brief Channel and private structures should be already locked */
 static void __oh323_update_info(struct ast_channel *c, struct oh323_pvt *pvt)
 {
-	if (!(ast_format_cap_identical(c->nativeformats, pvt->nativeformats))) {
+	if (c->nativeformats != pvt->nativeformats) {
 		if (h323debug)
 			ast_debug(1, "Preparing %s for new native format\n", c->name);
-		ast_format_cap_copy2(c->nativeformats, pvt->nativeformats);
-		ast_set_read_format(c, &c->readformat);
-		ast_set_write_format(c, &c->writeformat);
+		c->nativeformats = pvt->nativeformats;
+		ast_set_read_format(c, c->readformat);
+		ast_set_write_format(c, c->writeformat);
 	}
 	if (pvt->needhangup) {
 		if (h323debug)
@@ -489,10 +481,6 @@
 	} else {
 		ast_mutex_unlock(&pvt->lock);
 		ast_mutex_destroy(&pvt->lock);
-		pvt->peercap = ast_format_cap_destroy(pvt->peercap);
-		pvt->jointcap = ast_format_cap_destroy(pvt->jointcap);
-		pvt->nativeformats = ast_format_cap_destroy(pvt->nativeformats);
-		pvt->options.cap = ast_format_cap_destroy(pvt->options.cap);
 		ast_free(pvt);
 	}
 }
@@ -776,38 +764,31 @@
 	if (pvt->owner) {
 		/* We already hold the channel lock */
 		if (f->frametype == AST_FRAME_VOICE) {
-			if (!(ast_format_cap_iscompatible(pvt->owner->nativeformats, &f->subclass.format))) {
+			if (f->subclass.codec != pvt->owner->nativeformats) {
 				/* Try to avoid deadlock */
 				if (ast_channel_trylock(pvt->owner)) {
 					ast_log(LOG_NOTICE, "Format changed but channel is locked. Ignoring frame...\n");
 					return &ast_null_frame;
 				}
 				if (h323debug)
-					ast_debug(1, "Oooh, format changed to '%s'\n", ast_getformatname(&f->subclass.format));
-				ast_format_cap_remove_all(pvt->owner->nativeformats);
-				ast_format_cap_add(pvt->owner->nativeformats, &f->subclass.format);
-
-				ast_format_cap_remove_all(pvt->nativeformats);
-				ast_format_cap_add(pvt->nativeformats, &f->subclass.format);
-
-				ast_set_read_format(pvt->owner, &pvt->owner->readformat);
-				ast_set_write_format(pvt->owner, &pvt->owner->writeformat);
+					ast_debug(1, "Oooh, format changed to '%s'\n", ast_getformatname(f->subclass.codec));
+				pvt->owner->nativeformats = f->subclass.codec;
+				pvt->nativeformats = f->subclass.codec;
+				ast_set_read_format(pvt->owner, pvt->owner->readformat);
+				ast_set_write_format(pvt->owner, pvt->owner->writeformat);
 				ast_channel_unlock(pvt->owner);
 			}
 			/* Do in-band DTMF detection */
 			if ((pvt->options.dtmfmode & H323_DTMF_INBAND) && pvt->vad) {
-				struct ast_format tmpfmt;
-				if (ast_format_cap_iscompatible(pvt->nativeformats, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0)) ||
-					ast_format_cap_iscompatible(pvt->nativeformats, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0)) ||
-					ast_format_cap_iscompatible(pvt->nativeformats, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0))) {
+				if ((pvt->nativeformats & (AST_FORMAT_SLINEAR | AST_FORMAT_ALAW | AST_FORMAT_ULAW))) {
 					if (!ast_channel_trylock(pvt->owner)) {
 						f = ast_dsp_process(pvt->owner, pvt->vad, f);
 						ast_channel_unlock(pvt->owner);
 					}
 					else
 						ast_log(LOG_NOTICE, "Unable to process inband DTMF while channel is locked\n");
-				} else if (!ast_format_cap_is_empty(pvt->nativeformats) && !pvt->noInbandDtmf) {
-					ast_log(LOG_NOTICE, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(&f->subclass.format));
+				} else if (pvt->nativeformats && !pvt->noInbandDtmf) {
+					ast_log(LOG_NOTICE, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(f->subclass.codec));
 					pvt->noInbandDtmf = 1;
 				}
 				if (f &&(f->frametype == AST_FRAME_DTMF)) {
@@ -857,10 +838,10 @@
 			return 0;
 		}
 	} else {
-		if (!(ast_format_cap_iscompatible(c->nativeformats, &frame->subclass.format))) {
+		if (!(frame->subclass.codec & c->nativeformats)) {
 			char tmp[256];
 			ast_log(LOG_WARNING, "Asked to transmit frame type '%s', while native formats is '%s' (read/write = %s/%s)\n",
-				ast_getformatname(&frame->subclass.format), ast_getformatname_multiple(tmp, sizeof(tmp), c->nativeformats), ast_getformatname(&c->readformat), ast_getformatname(&c->writeformat));
+				ast_getformatname(frame->subclass.codec), ast_getformatname_multiple(tmp, sizeof(tmp), c->nativeformats), ast_getformatname(c->readformat), ast_getformatname(c->writeformat));
 			return 0;
 		}
 	}
@@ -1010,9 +991,8 @@
 	if (pvt->dtmf_pt[1] > 0)
 		ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, pvt->dtmf_pt[1], "audio", "cisco-telephone-event", 0);
 
-	if (!(ast_format_cap_is_empty(pvt->peercap))) {
+	if (pvt->peercapability)
 		ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->peer_prefs);
-	}
 
 	if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
 		ast_jb_configure(pvt->owner, &global_jbconf);
@@ -1031,8 +1011,7 @@
 {
 	struct ast_channel *ch;
 	char *cid_num, *cid_name;
-	struct ast_format_cap *tmpcap; /* SHALLOW COPY DO NOT DESTROY */
-	struct ast_format tmpfmt;
+	int fmt;
 
 	if (!ast_strlen_zero(pvt->options.cid_num))
 		cid_num = pvt->options.cid_num;
@@ -1052,24 +1031,15 @@
 	ast_mutex_lock(&pvt->lock);
 	if (ch) {
 		ch->tech = &oh323_tech;
-		if (!(ast_format_cap_is_empty(pvt->jointcap))) {
-			tmpcap = pvt->jointcap;
-		} else if (!(ast_format_cap_is_empty(pvt->options.cap))) {
-			tmpcap = pvt->options.cap;
-		} else {
-			tmpcap = global_options.cap;
-		}
-
-		ast_codec_choose(&pvt->options.prefs, tmpcap, 1, &tmpfmt)/* | (pvt->jointcapability & AST_FORMAT_VIDEO_MASK)*/;
-		ast_format_cap_add(ch->nativeformats, &tmpfmt);
-		ast_format_cap_copy2(pvt->nativeformats, ch->nativeformats);
-
-		ast_best_codec(ch->nativeformats, &tmpfmt);
-		ast_format_copy(&ch->writeformat, &tmpfmt);
-		ast_format_copy(&ch->rawwriteformat, &tmpfmt);
-		ast_format_copy(&ch->readformat, &tmpfmt);
-		ast_format_copy(&ch->rawreadformat, &tmpfmt);
-
+		if (!(fmt = pvt->jointcapability) && !(fmt = pvt->options.capability))
+			fmt = global_options.capability;
+		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;
 		if (!pvt->rtp)
 			__oh323_rtp_create(pvt);
 #if 0
@@ -1153,15 +1123,6 @@
 		ast_log(LOG_ERROR, "Couldn't allocate private structure. This is bad\n");
 		return NULL;
 	}
-	pvt->peercap = ast_format_cap_alloc_nolock();
-	pvt->jointcap = ast_format_cap_alloc_nolock();
-	pvt->nativeformats = ast_format_cap_alloc_nolock();
-	pvt->options.cap = ast_format_cap_alloc_nolock();
-	if (!pvt->peercap || !pvt->jointcap || !pvt->options.cap || !pvt->nativeformats) {
-		ast_free(pvt);
-		return NULL;
-	}
-
 	pvt->cd.redirect_reason = -1;
 	pvt->cd.transfer_capability = -1;
 	/* Ensure the call token is allocated for outgoing call */
@@ -1178,8 +1139,8 @@
 		memset((char *)(pvt->cd).call_token, 0, 128);
 		pvt->cd.call_reference = callid;
 	}
-	call_options_copy(&pvt->options, &global_options);
-	ast_format_cap_copy2(pvt->jointcap, pvt->options.cap);
+	memcpy(&pvt->options, &global_options, sizeof(pvt->options));
+	pvt->jointcapability = pvt->options.capability;
 	if (pvt->options.dtmfmode & (H323_DTMF_RFC2833 | H323_DTMF_CISCO)) {
 		pvt->nonCodecCapability |= AST_RTP_DTMF;
 	} else {
@@ -1309,11 +1270,11 @@
 	char *val, *opt;
 
 	if (!strcasecmp(v->name, "allow")) {
-		ast_parse_allow_disallow(&options->prefs, options->cap, v->value, 1);
+		ast_parse_allow_disallow(&options->prefs, &options->capability, v->value, 1);
 	} else if (!strcasecmp(v->name, "autoframing")) {
 		options->autoframing = ast_true(v->value);
 	} else if (!strcasecmp(v->name, "disallow")) {
-		ast_parse_allow_disallow(&options->prefs, options->cap, v->value, 0);
+		ast_parse_allow_disallow(&options->prefs, &options->capability, v->value, 0);
 	} else if (!strcasecmp(v->name, "dtmfmode")) {
 		val = ast_strdupa(v->value);
 		if ((opt = strchr(val, ':')) != (char *)NULL) {
@@ -1424,20 +1385,13 @@
 	if (user)
 		found++;
 	else {
-		if (!(user = ast_calloc(1, sizeof(*user)))) {
+		if (!(user = ast_calloc(1, sizeof(*user))))
 			return NULL;
-		}
-		if (!(user->options.cap = ast_format_cap_alloc_nolock())) {
-			ast_free(user);
-			return NULL;
-		}
 		ASTOBJ_INIT(user);
 	}
-
-
 	oldha = user->ha;
 	user->ha = (struct ast_ha *)NULL;
-	call_options_copy(&user->options, &global_options);
+	memcpy(&user->options, &global_options, sizeof(user->options));
 	user->options.dtmfmode = 0;
 	user->options.holdHandling = 0;
 	/* Set default context */
@@ -1553,18 +1507,13 @@
 	if (peer)
 		found++;
 	else {
-		if (!(peer = ast_calloc(1, sizeof(*peer)))) {
+		if (!(peer = ast_calloc(1, sizeof(*peer))))
 			return NULL;
-		}
-		if (!(peer->options.cap = ast_format_cap_alloc_nolock())) {
-			ast_free(peer);
-			return NULL;
-		}
 		ASTOBJ_INIT(peer);
 	}
 	oldha = peer->ha;
 	peer->ha = NULL;
-	call_options_copy(&peer->options, &global_options);
+	memcpy(&peer->options, &global_options, sizeof(peer->options));
 	peer->options.dtmfmode = 0;
 	peer->options.holdHandling = 0;
 	peer->addr.sin_port = htons(h323_signalling_port);
@@ -1745,8 +1694,8 @@
 	p = find_peer(peer, NULL, 1);
 	if (p) {
 		found++;
-		call_options_copy(&pvt->options, &p->options);
-		ast_format_cap_copy2(pvt->jointcap, pvt->options.cap);
+		memcpy(&pvt->options, &p->options, sizeof(pvt->options));
+		pvt->jointcapability = pvt->options.capability;
 		if (pvt->options.dtmfmode) {
 			if (pvt->options.dtmfmode & H323_DTMF_RFC2833) {
 				pvt->nonCodecCapability |= AST_RTP_DTMF;
@@ -1773,8 +1722,8 @@
 			pvt->sa.sin_port = htons(portno);
 			/* Look peer by address */
 			p = find_peer(NULL, &pvt->sa, 1);
-			call_options_copy(&pvt->options, (p ? &p->options : &global_options));
-			ast_format_cap_copy2(pvt->jointcap, pvt->options.cap);
+			memcpy(&pvt->options, (p ? &p->options : &global_options), sizeof(pvt->options));
+			pvt->jointcapability = pvt->options.capability;
 			if (p) {
 				ASTOBJ_UNREF(p, oh323_destroy_peer);
 			}
@@ -1796,8 +1745,9 @@
 		return 0;
 	}
 }
-static struct ast_channel *oh323_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause)
-{
+static struct ast_channel *oh323_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
+{
+	format_t oldformat;
 	struct oh323_pvt *pvt;
 	struct ast_channel *tmpc = NULL;
 	char *dest = (char *)data;
@@ -1806,15 +1756,17 @@
 	char tmp[256], tmp1[256];
 
 	if (h323debug)
-		ast_debug(1, "type=%s, format=%s, data=%s.\n", type, ast_getformatname_multiple(tmp, sizeof(tmp), cap), (char *)data);
+		ast_debug(1, "type=%s, format=%s, data=%s.\n", type, ast_getformatname_multiple(tmp, sizeof(tmp), format), (char *)data);
 
 	pvt = oh323_alloc(0);
 	if (!pvt) {
 		ast_log(LOG_WARNING, "Unable to build pvt data for '%s'\n", (char *)data);
 		return NULL;
 	}
-	if (!(ast_format_cap_has_type(cap, AST_FORMAT_TYPE_AUDIO))) {
-		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), cap));
+	oldformat = format;
+	format &= AST_FORMAT_AUDIO_MASK;
+	if (!format) {
+		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), format));
 		oh323_destroy(pvt);
 		if (cause)
 			*cause = AST_CAUSE_INCOMPATIBLE_DESTINATION;
@@ -1851,8 +1803,8 @@
 		}
 	}
 	else {
-		call_options_copy(&pvt->options, &global_options);
-		ast_format_cap_copy2(pvt->jointcap, pvt->options.cap);
+		memcpy(&pvt->options, &global_options, sizeof(pvt->options));
+		pvt->jointcapability = pvt->options.capability;
 		if (pvt->options.dtmfmode) {
 			if (pvt->options.dtmfmode & H323_DTMF_RFC2833) {
 				pvt->nonCodecCapability |= AST_RTP_DTMF;
@@ -2017,7 +1969,6 @@
 	struct oh323_pvt *pvt;
 	struct sockaddr_in them;
 	int nativeformats_changed;
-	struct ast_format tmpfmt;
 	enum { NEED_NONE, NEED_HOLD, NEED_UNHOLD } rtp_change = NEED_NONE;
 
 	if (h323debug)
@@ -2037,7 +1988,7 @@
 	if (!pvt->rtp)
 		__oh323_rtp_create(pvt);
 
-	if ((pt == 2) && (ast_format_cap_iscompatible(pvt->jointcap, ast_format_set(&tmpfmt, AST_FORMAT_G726_AAL2, 0)))) {
+	if ((pt == 2) && (pvt->jointcapability & AST_FORMAT_G726_AAL2)) {
 		ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, pt, "audio", "G726-32", AST_RTP_OPT_G726_NONSTANDARD);
 	}
 
@@ -2069,18 +2020,11 @@
 	nativeformats_changed = 0;
 	if (pt != 128 && pvt->rtp) {	/* Payload type is invalid, so try to use previously decided */
 		struct ast_rtp_payload_type rtptype = ast_rtp_codecs_payload_lookup(ast_rtp_instance_get_codecs(pvt->rtp), pt);
-		char tmp[256];
-		if (rtptype.asterisk_format) {
-			if (h323debug) {
-				ast_debug(1, "Native format is set to %s from %s by RTP payload type %d\n",
-					ast_getformatname(&rtptype.format),
-					ast_getformatname_multiple(tmp, sizeof(tmp), pvt->nativeformats), pt);
-			}
-			if (!(ast_format_cap_iscompatible(pvt->nativeformats, &rtptype.format))) {
-				ast_format_cap_remove_all(pvt->nativeformats);
-				ast_format_cap_add(pvt->nativeformats, &rtptype.format);
-				nativeformats_changed = 1;
-			}
+		if (h323debug)
+			ast_debug(1, "Native format is set to %llu from %d by RTP payload type %d\n", (unsigned long long) 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");
@@ -2089,14 +2033,14 @@
 	if (nativeformats_changed || pvt->options.progress_audio || (rtp_change != NEED_NONE)) {
 		if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
 			/* Re-build translation path only if native format(s) has been changed */
-			if (!ast_format_cap_identical(pvt->owner->nativeformats, pvt->nativeformats)) {
+			if (pvt->owner->nativeformats != pvt->nativeformats) {
 				if (h323debug) {
 					char tmp[256], tmp2[256];
-					ast_debug(1, "Native format changed to '%s' from '%s', read format is %s, write format is %s\n", ast_getformatname_multiple(tmp, sizeof(tmp), pvt->nativeformats), ast_getformatname_multiple(tmp2, sizeof(tmp2), pvt->owner->nativeformats), ast_getformatname(&pvt->owner->readformat), ast_getformatname(&pvt->owner->writeformat));
+					ast_debug(1, "Native format changed to '%s' from '%s', read format is %s, write format is %s\n", ast_getformatname_multiple(tmp, sizeof(tmp), pvt->nativeformats), ast_getformatname_multiple(tmp2, sizeof(tmp2), pvt->owner->nativeformats), ast_getformatname(pvt->owner->readformat), ast_getformatname(pvt->owner->writeformat));
 				}
-				ast_format_cap_copy2(pvt->owner->nativeformats, pvt->nativeformats);
-				ast_set_read_format(pvt->owner, &pvt->owner->readformat);
-				ast_set_write_format(pvt->owner, &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);
@@ -2210,8 +2154,8 @@
 
 	/* Populate the call details in the private structure */
 	memcpy(&pvt->cd, cd, sizeof(pvt->cd));
-	call_options_copy(&pvt->options, &global_options);
-	ast_format_cap_copy2(pvt->jointcap, pvt->options.cap);
+	memcpy(&pvt->options, &global_options, sizeof(pvt->options));
+	pvt->jointcapability = pvt->options.capability;
 
 	if (h323debug) {
 		ast_verb(3, "Setting up Call\n");
@@ -2286,8 +2230,8 @@
 				}
 			}
 			ast_copy_string(pvt->context, user->context, sizeof(pvt->context));
-			call_options_copy(&pvt->options, &user->options);
-			ast_format_cap_copy2(pvt->jointcap, pvt->options.cap);
+			memcpy(&pvt->options, &user->options, sizeof(pvt->options));
+			pvt->jointcapability = pvt->options.capability;
 			if (!ast_strlen_zero(pvt->cd.call_dest_e164)) {
 				ast_copy_string(pvt->exten, cd->call_dest_e164, sizeof(pvt->exten));
 			} else {
@@ -2528,7 +2472,7 @@
 		ast_debug(1, "DTMF payload on %s set to %d\n", token, payload);
 }
 
-static void set_peer_capabilities(unsigned call_reference, const char *token, struct ast_format_cap *cap, struct ast_codec_pref *prefs)
+static void set_peer_capabilities(unsigned call_reference, const char *token, int capabilities, struct ast_codec_pref *prefs)
 {
 	struct oh323_pvt *pvt;
 
@@ -2538,16 +2482,16 @@
 	pvt = find_call_locked(call_reference, token);
 	if (!pvt)
 		return;
-	ast_format_cap_copy2(pvt->peercap, cap);
-	ast_format_cap_joint_copy(pvt->options.cap, cap, pvt->jointcap);
+	pvt->peercapability = capabilities;
+	pvt->jointcapability = pvt->options.capability & capabilities;
 	if (prefs) {
 		memcpy(&pvt->peer_prefs, prefs, sizeof(pvt->peer_prefs));
 		if (h323debug) {
 			int i;
-			for (i = 0; i < AST_CODEC_PREF_SIZE; ++i) {
+			for (i = 0; i < 32; ++i) {
 				if (!prefs->order[i])
 					break;
-				ast_debug(1, "prefs[%d]=%s:%d\n", i, (prefs->order[i] ? ast_getformatname(&prefs->formats[i]) : "<none>"), prefs->framing[i]);
+				ast_debug(1, "prefs[%d]=%s:%d\n", i, (prefs->order[i] ? ast_getformatname(1 << (prefs->order[i]-1)) : "<none>"), prefs->framing[i]);
 			}
 		}
 		if (pvt->rtp) {
@@ -2566,9 +2510,7 @@
 static void set_local_capabilities(unsigned call_reference, const char *token)
 {
 	struct oh323_pvt *pvt;
-	struct ast_format_cap *cap;
-	int dtmfmode;
-	struct ast_format pref_codec;
+	int capability, dtmfmode, pref_codec;
 	struct ast_codec_pref prefs;
 
 	if (h323debug)
@@ -2577,25 +2519,19 @@
 	pvt = find_call_locked(call_reference, token);
 	if (!pvt)
 		return;
-	cap = ast_format_cap_copy((!(ast_format_cap_is_empty(pvt->jointcap))) ? pvt->jointcap : pvt->options.cap);
+	capability = (pvt->jointcapability) ? pvt->jointcapability : pvt->options.capability;
 	dtmfmode = pvt->options.dtmfmode;
 	prefs = pvt->options.prefs;
-	ast_format_copy(&pref_codec, &pvt->pref_codec);
+	pref_codec = pvt->pref_codec;
 	ast_mutex_unlock(&pvt->lock);
-
-	if (cap) {
-		h323_set_capabilities(token, cap, dtmfmode, &prefs, &pref_codec);
-		cap = ast_format_cap_destroy(cap);
-	} else {
-		return;
-	}
+	h323_set_capabilities(token, capability, dtmfmode, &prefs, pref_codec);
 
 	if (h323debug) {
 		int i;
 		for (i = 0; i < 32; i++) {
 			if (!prefs.order[i])
 				break;
-			ast_debug(1, "local prefs[%d]=%s:%d\n", i, (prefs.order[i] ? ast_getformatname(&prefs.formats[i]) : "<none>"), prefs.framing[i]);
+			ast_debug(1, "local prefs[%d]=%s:%d\n", i, (prefs.order[i] ? ast_getformatname(1 << (prefs.order[i]-1)) : "<none>"), prefs.framing[i]);
 		}
 		ast_debug(1, "Capabilities for connection %s is set\n", token);
 	}
@@ -2944,8 +2880,6 @@
 	char _gatekeeper[100];
 	int gk_discover, gk_disable, gk_changed;
 	struct ast_flags config_flags = { is_reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
-	struct ast_format tmpfmt;
-	struct ast_format_cap *tmpcap;
 
 	cfg = ast_config_load(config, config_flags);
 
@@ -2993,26 +2927,14 @@
 	gk_discover = gatekeeper_discover;
 	gk_disable = gatekeeper_disable;
 	memset(&bindaddr, 0, sizeof(bindaddr));
-
-	tmpcap = global_options.cap;
 	memset(&global_options, 0, sizeof(global_options));
-	global_options.cap = tmpcap;
 	global_options.fastStart = 1;
 	global_options.h245Tunneling = 1;
 	global_options.dtmfcodec[0] = H323_DTMF_RFC2833_PT;
 	global_options.dtmfcodec[1] = H323_DTMF_CISCO_PT;
 	global_options.dtmfmode = 0;
 	global_options.holdHandling = 0;
-	ast_format_cap_remove_all(global_options.cap);
-	/* add the default capabilities */
-	ast_format_cap_add(global_options.cap, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
-	ast_format_cap_add(global_options.cap, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0));
-	ast_format_cap_add(global_options.cap, ast_format_set(&tmpfmt, AST_FORMAT_G723_1, 0));
-	ast_format_cap_add(global_options.cap, ast_format_set(&tmpfmt, AST_FORMAT_GSM, 0));
-	ast_format_cap_add(global_options.cap, ast_format_set(&tmpfmt, AST_FORMAT_G729A, 0));
-	ast_format_cap_add(global_options.cap, ast_format_set(&tmpfmt, AST_FORMAT_G726_AAL2, 0));
-	ast_format_cap_add(global_options.cap, ast_format_set(&tmpfmt, AST_FORMAT_H261, 0));
-
+	global_options.capability = GLOBAL_CAPABILITY;
 	global_options.bridge = 1;		/* Do native bridging by default */
 	global_options.autoframing = 0;
 	strcpy(default_context, "default");
@@ -3269,9 +3191,9 @@
 	return res;
 }
 
-static char *convertformat(struct ast_format *format)
-{
-	switch (format->id) {
+static char *convertcap(format_t cap)
+{
+	switch (cap) {
 	case AST_FORMAT_G723_1:
 		return "G.723";
 	case AST_FORMAT_GSM:
@@ -3291,12 +3213,12 @@
 	case AST_FORMAT_ILBC:
 		return "ILBC";
 	default:
-		ast_log(LOG_NOTICE, "Don't know how to deal with mode %s\n", ast_getformatname(format));
+		ast_log(LOG_NOTICE, "Don't know how to deal with mode %" PRId64 "\n", cap);
 		return NULL;
 	}
 }
 
-static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, const struct ast_format_cap *cap, int nat_active)
+static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active)
 {
 	/* XXX Deal with Video */
 	struct oh323_pvt *pvt;
@@ -3308,7 +3230,7 @@
 		return 0;
 	}
 
-	mode = convertformat(&chan->writeformat);
+	mode = convertcap(chan->writeformat);
 	pvt = (struct oh323_pvt *) chan->tech_pvt;
 	if (!pvt) {
 		ast_log(LOG_ERROR, "No Private Structure, this is bad\n");
@@ -3338,13 +3260,6 @@
 {
 	int res;
 
-	if (!(oh323_tech.capabilities = ast_format_cap_alloc())) {
-		return AST_MODULE_LOAD_FAILURE;
-	}
-	if (!(global_options.cap = ast_format_cap_alloc_nolock())) {
-		return AST_MODULE_LOAD_FAILURE;
-	}
-	ast_format_cap_add_all_by_type(oh323_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
 	h323debug = 0;
 	sched = ast_sched_context_create();
 	if (!sched) {
@@ -3515,8 +3430,6 @@
 	ASTOBJ_CONTAINER_DESTROYALL(&aliasl, oh323_destroy_alias);
 	ASTOBJ_CONTAINER_DESTROY(&aliasl);
 
-	oh323_tech.capabilities = ast_format_cap_destroy(oh323_tech.capabilities);
-	global_options.cap = ast_format_cap_destroy(global_options.cap);
 	return 0;
 }
 

Modified: team/dvossel/fixtheworld_phase1_step3/channels/h323/ast_h323.cxx
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/channels/h323/ast_h323.cxx?view=diff&rev=302506&r1=302505&r2=302506
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/channels/h323/ast_h323.cxx (original)
+++ team/dvossel/fixtheworld_phase1_step3/channels/h323/ast_h323.cxx Wed Jan 19 11:58:51 2011
@@ -1758,11 +1758,7 @@
 	}
 
 	memset(&prefs, 0, sizeof(prefs));
-	struct ast_format_cap *peer_cap = ast_format_cap_alloc();
-	if (!peer_cap) {
-		return FALSE;
-	}
-
+	int peer_capabilities = 0;
 	for (int i = 0; i < remoteCapabilities.GetSize(); ++i) {
 		unsigned int subType = remoteCapabilities[i].GetSubType();
 		if (h323debug) {
@@ -1772,23 +1768,22 @@
 		case H323Capability::e_Audio:
 			for (int x = 0; codecs[x].asterisk_codec > 0; ++x) {
 				if ((subType == codecs[x].h245_cap) && (!codecs[x].formatName || (!strcmp(codecs[x].formatName, (const char *)remoteCapabilities[i].GetFormatName())))) {
-					struct ast_format ast_codec;
+					int ast_codec = codecs[x].asterisk_codec;
 					int ms = 0;
-					ast_format_set(&ast_codec, (enum ast_format_id) codecs[x].asterisk_codec, 0);
-					if (!(ast_format_cap_iscompatible(peer_cap, &ast_codec))) {
+					if (!(peer_capabilities & ast_codec)) {
 						struct ast_format_list format;
-						ast_codec_pref_append(&prefs, &ast_codec);
-						format = ast_codec_pref_getsize(&prefs, &ast_codec);
-						if ((ast_codec.id == AST_FORMAT_ALAW) || (ast_codec.id == AST_FORMAT_ULAW)) {
+						ast_codec_pref_append(&prefs, ast_codec);
+						format = ast_codec_pref_getsize(&prefs, ast_codec);
+						if ((ast_codec == AST_FORMAT_ALAW) || (ast_codec == AST_FORMAT_ULAW)) {
 							ms = remoteCapabilities[i].GetTxFramesInPacket();
 						} else
 							ms = remoteCapabilities[i].GetTxFramesInPacket() * format.inc_ms;
-						ast_codec_pref_setsize(&prefs, &ast_codec, ms);
+						ast_codec_pref_setsize(&prefs, ast_codec, ms);
 					}
 					if (h323debug) {
-						cout << "Found peer capability " << remoteCapabilities[i] << ", Asterisk code is " << ast_getformatname(&ast_codec) << ", frame size (in ms) is " << ms << endl;
+						cout << "Found peer capability " << remoteCapabilities[i] << ", Asterisk code is " << ast_codec << ", frame size (in ms) is " << ms << endl;
 					}
-					ast_format_cap_add(peer_cap, &ast_codec);
+					peer_capabilities |= ast_codec;
 				}
 			}
 			break;
@@ -1854,16 +1849,15 @@
 	if (h323debug) {
 		char caps_str[1024], caps2_str[1024];
 		ast_codec_pref_string(&prefs, caps2_str, sizeof(caps2_str));
-		cout << "Peer capabilities = " << ast_getformatname_multiple(caps_str, sizeof(caps_str), peer_cap)
+		cout << "Peer capabilities = " << ast_getformatname_multiple(caps_str, sizeof(caps_str), peer_capabilities)
 				<< ", ordered list is " << caps2_str << endl;
 	}
 #if 0
 	redir_capabilities &= peer_capabilities;
 #endif
 	if (on_setpeercapabilities)
-		on_setpeercapabilities(GetCallReference(), (const char *)callToken, peer_cap, &prefs);
-
-	ast_format_cap_destroy(peer_cap);
+		on_setpeercapabilities(GetCallReference(), (const char *)callToken, peer_capabilities, &prefs);
+
 	return TRUE;
 }
 
@@ -1897,56 +1891,44 @@
 	return connectionState != ShuttingDownConnection;
 }
 
-void MyH323Connection::SetCapabilities(struct ast_format_cap *astcaps, int dtmf_mode, void *_prefs, struct ast_format *pref_codec)
+void MyH323Connection::SetCapabilities(int caps, int dtmf_mode, void *_prefs, int pref_codec)
 {
 	PINDEX lastcap = -1; /* last common capability index */
-	struct ast_format_cap *alreadysent = ast_format_cap_alloc();
-	struct ast_format tmpfmt;
-	int index;
+	int alreadysent = 0;
+	int codec;
+	int x, y;
 	char caps_str[1024];
 	struct ast_codec_pref *prefs = (struct ast_codec_pref *)_prefs;
 	struct ast_format_list format;
 	int frames_per_packet;
 	H323Capability *cap;
 
-	if (!alreadysent) {
-		return;
-	}
-
 	localCapabilities.RemoveAll();
 
 	if (h323debug) {
-		cout << "Setting capabilities to " << ast_getformatname_multiple(caps_str, sizeof(caps_str), astcaps) << endl;
+		cout << "Setting capabilities to " << ast_getformatname_multiple(caps_str, sizeof(caps_str), caps) << endl;
 		ast_codec_pref_string(prefs, caps_str, sizeof(caps_str));
 		cout << "Capabilities in preference order is " << caps_str << endl;
 	}
 	/* Add audio codecs in preference order first, then
 	   audio codecs without preference as allowed by mask */
-	ast_format_cap_iter_start(astcaps);
-	for (index = -1;;) {
-		ast_format_clear(&tmpfmt);
-		if (index < 0) {
-			ast_format_copy(&tmpfmt, pref_codec);
-		} else if (index < AST_CODEC_PREF_SIZE) {
-			ast_codec_pref_index(prefs, index, &tmpfmt);
-			index++;
-		} else if (!(ast_format_cap_iter_next(astcaps, &tmpfmt))) {
-			/*format is set to next in capabilities iterator */
-		} else {
-			break;
-		}
-		if (!(ast_format_cap_iscompatible(astcaps, &tmpfmt)) ||
-			ast_format_cap_iscompatible(alreadysent, &tmpfmt) ||
-			AST_FORMAT_GET_TYPE(tmpfmt.id) != AST_FORMAT_TYPE_AUDIO) {
+	for (y = 0, x = -1; x < 32 + 32; ++x) {
+		if (x < 0)
+			codec = pref_codec;
+		else if (y || (!(codec = ast_codec_pref_index(prefs, x)))) {
+			if (!y)
+				y = 1;
+			else
+				y <<= 1;
+			codec = y;
+		}
+		if (!(caps & codec) || (alreadysent & codec) || !(codec & AST_FORMAT_AUDIO_MASK))
 			continue;
-		}
-		ast_format_cap_add(alreadysent, &tmpfmt);
-
+		alreadysent |= codec;
 		/* format.cur_ms will be set to default if packetization is not explicitly set */
-		format = ast_codec_pref_getsize(prefs, &tmpfmt);
+		format = ast_codec_pref_getsize(prefs, codec);
 		frames_per_packet = (format.inc_ms ? format.cur_ms / format.inc_ms : format.cur_ms);
-
-		switch(tmpfmt.id) {
+		switch(codec) {
 #if 0
 		case AST_FORMAT_SPEEX:
 			/* Not real sure if Asterisk acutally supports all
@@ -1996,13 +1978,10 @@
 			g726Cap->SetTxFramesInPacket(format.cur_ms);
 			break;
 		default:
-			ast_format_cap_remove(alreadysent, &tmpfmt);
-			break;
-		}
-	}
-	ast_format_cap_iter_end(astcaps);
-	ast_format_cap_destroy(alreadysent);
-	alreadysent = NULL;
+			alreadysent &= ~codec;
+			break;
+		}
+	}
 
 	cap = new H323_UserInputCapability(H323_UserInputCapability::HookFlashH245);
 	if (cap && cap->IsUsable(*this)) {
@@ -2337,7 +2316,7 @@
 /**
  * Add capability to the capability table of the end point.
  */
-int h323_set_capabilities(const char *token, struct ast_format_cap *cap, int dtmf_mode, struct ast_codec_pref *prefs, struct ast_format *pref_codec)
+int h323_set_capabilities(const char *token, int cap, int dtmf_mode, struct ast_codec_pref *prefs, int pref_codec)
 {
 	MyH323Connection *conn;
 

Modified: team/dvossel/fixtheworld_phase1_step3/channels/h323/ast_h323.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/channels/h323/ast_h323.h?view=diff&rev=302506&r1=302505&r2=302506
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/channels/h323/ast_h323.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/channels/h323/ast_h323.h Wed Jan 19 11:58:51 2011
@@ -30,7 +30,6 @@
 #define AST_H323_H
 
 #include "ast_ptlib.h"
-#include "asterisk/format.h"
 
 #define VERSION(a,b,c) ((a)*10000+(b)*100+(c))
 
@@ -86,7 +85,7 @@
 	PBoolean MySendProgress();
 	void OnSendCapabilitySet(H245_TerminalCapabilitySet &);
 	void OnSetLocalCapabilities();
-	void SetCapabilities(struct ast_format_cap *cap, int, void *, struct ast_format *format);
+	void SetCapabilities(int, int, void *, int);
 	PBoolean OnReceivedCapabilitySet(const H323Capabilities &, const H245_MultiplexCapability *,
 			H245_TerminalCapabilitySetReject &);
 	void SetCause(int _cause) { cause = _cause; };

Modified: team/dvossel/fixtheworld_phase1_step3/channels/h323/chan_h323.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/channels/h323/chan_h323.h?view=diff&rev=302506&r1=302505&r2=302506
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/channels/h323/chan_h323.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/channels/h323/chan_h323.h Wed Jan 19 11:58:51 2011
@@ -30,7 +30,7 @@
 #define CHAN_H323_H
 
 #include <arpa/inet.h>
-#include "asterisk/format.h"
+#include "asterisk/frame_defs.h"
 
 /*
  * Enable support for sending/reception of tunnelled Q.SIG messages and
@@ -65,7 +65,7 @@
 	int				progress_audio;
 	int				dtmfcodec[2];
 	int				dtmfmode;
-	struct ast_format_cap *cap;
+	format_t        capability;
 	int				bridge;
 	int				nat;
 	int				tunnelOptions;
@@ -195,7 +195,7 @@
 typedef void (*setcapabilities_cb)(unsigned, const char *);
 extern setcapabilities_cb on_setcapabilities;
 
-typedef void (*setpeercapabilities_cb)(unsigned, const char *, struct ast_format_cap *cap, struct ast_codec_pref *);
+typedef void (*setpeercapabilities_cb)(unsigned, const char *, int, struct ast_codec_pref *);
 extern setpeercapabilities_cb on_setpeercapabilities;
 
 typedef void (*onhold_cb)(unsigned, const char *, int);
@@ -239,7 +239,7 @@
 					setcapabilities_cb,
 					setpeercapabilities_cb,
 					onhold_cb);
-	int h323_set_capabilities(const char *, struct ast_format_cap *cap, int, struct ast_codec_pref *, struct ast_format *format);
+	int h323_set_capabilities(const char *, int, int, struct ast_codec_pref *, int);
 	int h323_set_alias(struct oh323_alias *);
 	int h323_set_gk(int, char *, char *);
 	void h323_set_id(char *);




More information about the svn-commits mailing list