[svn-commits] file: branch group/media_formats r411009 - /team/group/media_formats/channels/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Mar 21 14:13:59 CDT 2014


Author: file
Date: Fri Mar 21 14:13:50 2014
New Revision: 411009

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=411009
Log:
Add progress on chan_h323.

Modified:
    team/group/media_formats/channels/chan_h323.c

Modified: team/group/media_formats/channels/chan_h323.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/channels/chan_h323.c?view=diff&rev=411009&r1=411008&r2=411009
==============================================================================
--- team/group/media_formats/channels/chan_h323.c (original)
+++ team/group/media_formats/channels/chan_h323.c Fri Mar 21 14:13:50 2014
@@ -97,6 +97,8 @@
 #include "asterisk/astobj.h"
 #include "asterisk/format.h"
 #include "asterisk/format_cap.h"
+#include "asterisk/format_cache.h"
+#include "asterisk/format_compatibility.h"
 
 #ifdef __cplusplus
 }
@@ -142,13 +144,13 @@
 static char default_context[AST_MAX_CONTEXT] = "default";
 static struct sockaddr_in bindaddr;
 
-#define GLOBAL_CAPABILITY (ast_format_id_to_old_bitfield(AST_FORMAT_G723_1) | \
-	ast_format_id_to_old_bitfield(AST_FORMAT_GSM) | \
-	ast_format_id_to_old_bitfield(AST_FORMAT_ULAW) | \
-	ast_format_id_to_old_bitfield(AST_FORMAT_ALAW) | \
-	ast_format_id_to_old_bitfield(AST_FORMAT_G729A) | \
-	ast_format_id_to_old_bitfield(AST_FORMAT_G726_AAL2) | \
-	ast_format_id_to_old_bitfield(AST_FORMAT_H261)) \
+#define GLOBAL_CAPABILITY (ast_format_compatibility_format2bitfield(ast_format_g723) | \
+	ast_format_compatibility_format2bitfield(ast_format_gsm) | \
+	ast_format_compatibility_format2bitfield(ast_format_ulaw) | \
+	ast_format_compatibility_format2bitfield(ast_format_alaw) | \
+	ast_format_compatibility_format2bitfield(ast_format_g729) | \
+	ast_format_compatibility_format2bitfield(ast_format_g726_aal2) | \
+	ast_format_compatibility_format2bitfield(ast_format_h261)) \
 
 /** H.323 configuration values */
 static int h323_signalling_port = 1720;
@@ -784,25 +786,27 @@
 	if (f && pvt->owner) {
 		/* We already hold the channel lock */
 		if (f->frametype == AST_FRAME_VOICE) {
-			if (!ast_format_cap_iscompatible(ast_channel_nativeformats(pvt->owner), &f->subclass.format)) {
+			if (!ast_format_cap_iscompatible_format(ast_channel_nativeformats(pvt->owner), f->subclass.format)) {
 				/* 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_debug(1, "Oooh, format changed to '%s'\n", f->subclass.format->codec->name);
 				ast_format_cap_set(ast_channel_nativeformats(pvt->owner), &f->subclass.format);
 
-				pvt->nativeformats = ast_format_to_old_bitfield(&f->subclass.format);
+				pvt->nativeformats = ast_format_compatibility_format2bitfield(f->subclass.format);
 
 				ast_set_read_format(pvt->owner, ast_channel_readformat(pvt->owner));
-				ast_set_write_format(pvt->owner,ast_channel_writeformat(pvt->owner));
+				ast_set_write_format(pvt->owner, ast_channel_writeformat(pvt->owner));
 				ast_channel_unlock(pvt->owner);
 			}
 			/* Do in-band DTMF detection */
 			if ((pvt->options.dtmfmode & H323_DTMF_INBAND) && pvt->vad) {
-				if ((pvt->nativeformats & (AST_FORMAT_SLINEAR | AST_FORMAT_ALAW | AST_FORMAT_ULAW))) {
+				if ((pvt->nativeformats & (ast_format_compatibility_format2bitfield(ast_format_slin) |
+					ast_format_compatibility_format2bitfield(ast_format_alaw) |
+					ast_format_compatibility_format2bitfield(ast_format_ulaw)))) {
 					if (!ast_channel_trylock(pvt->owner)) {
 						f = ast_dsp_process(pvt->owner, pvt->vad, f);
 						ast_channel_unlock(pvt->owner);
@@ -810,7 +814,7 @@
 					else
 						ast_log(LOG_NOTICE, "Unable to process inband DTMF while channel is locked\n");
 				} 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.format));
+					ast_log(LOG_NOTICE, "Inband DTMF is not supported on codec %s. Use RFC2833\n", f->subclass.format->codec->name);
 					pvt->noInbandDtmf = 1;
 				}
 				if (f &&(f->frametype == AST_FRAME_DTMF)) {
@@ -860,13 +864,13 @@
 			return 0;
 		}
 	} else {
-		if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(c), &frame->subclass.format))) {
+		if (!(ast_format_cap_iscompatible_format(ast_channel_nativeformats(c), frame->subclass.format))) {
 			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),
+				frame->subclass.format->codec->name,
 				ast_getformatname_multiple(tmp, sizeof(tmp), ast_channel_nativeformats(c)),
-				ast_getformatname(ast_channel_readformat(c)),
-				ast_getformatname(ast_channel_writeformat(c)));
+				ast_channel_readformat(c)->codec->name,
+				ast_channel_writeformat(c)->codec->name);
 			return 0;
 		}
 	}
@@ -1023,8 +1027,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 (pvt->peercapability)
-		ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->peer_prefs);
+//	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);
@@ -1041,10 +1045,17 @@
 /*! \brief Private structure should be locked on a call */
 static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const char *host, const char *linkedid)
 {
+	struct ast_format_cap *nativeformats;
 	struct ast_channel *ch;
 	char *cid_num, *cid_name;
 	h323_format fmt;
-	struct ast_format tmpfmt;
+	struct ast_format *tmpfmt;
+
+	nativeformats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!nativeformats) {
+		ast_log(LOG_WARNING, "Unable to allocate memory for native formats\n");
+		return NULL;
+	}
 
 	if (!ast_strlen_zero(pvt->options.cid_num))
 		cid_num = pvt->options.cid_num;
@@ -1067,17 +1078,21 @@
 		if (!(fmt = pvt->jointcapability) && !(fmt = pvt->options.capability))
 			fmt = global_options.capability;
 
-		ast_format_cap_from_old_bitfield(ast_channel_nativeformats(ch), fmt);
-		ast_codec_choose(&pvt->options.prefs, ast_channel_nativeformats(ch), 1, &tmpfmt)/* | (pvt->jointcapability & AST_FORMAT_VIDEO_MASK)*/;
+		ast_format_compatibility_bitfield2cap(fmt, nativeformats);
+		ast_channel_nativeformats_set(ch, nativeformats);
+
+		ast_best_codec(nativeformats, &tmpfmt);
 
 		ast_format_cap_set(ast_channel_nativeformats(ch), &tmpfmt);
 
 		pvt->nativeformats = ast_format_cap_to_old_bitfield(ast_channel_nativeformats(ch));
 		ast_best_codec(ast_channel_nativeformats(ch), &tmpfmt);
-		ast_format_copy(ast_channel_writeformat(ch), &tmpfmt);
-		ast_format_copy(ast_channel_rawwriteformat(ch), &tmpfmt);
-		ast_format_copy(ast_channel_readformat(ch), &tmpfmt);
-		ast_format_copy(ast_channel_rawreadformat(ch), &tmpfmt);
+		ast_channel_set_writeformat(ch, tmpfmt);
+		ast_channel_set_rawwriteformat(ch, tmpfmt);
+		ast_channel_set_readformat(ch, tmpfmt);
+		ast_channel_set_rawreadformat(ch, tmpfmt);
+
+		ao2_ref(tmpfmt, -1);
 		if (!pvt->rtp)
 			__oh323_rtp_create(pvt);
 #if 0
@@ -1150,6 +1165,9 @@
 	} else {
 		ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
 	}
+
+	ao2_ref(nativeformats, -1);
+
 	return ch;
 }
 
@@ -1314,15 +1332,15 @@
 static int h323_parse_allow_disallow(struct ast_codec_pref *pref, h323_format *formats, const char *list, int allowing)
 {
 	int res;
-	struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+	struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	if (!cap) {
 		return 1;
 	}
 
-	ast_format_cap_from_old_bitfield(cap, *formats);
-	res = ast_parse_allow_disallow(pref, cap, list, allowing);
-	*formats = ast_format_cap_to_old_bitfield(cap);
-	cap = ast_format_cap_destroy(cap);
+	ast_format_compatibility_bitfield2cap(*formats, cap);
+	res = ast_parse_allow_disallow(cap, list, allowing);
+	*formats = ast_format_compatibility_cap2bitfield(cap);
+	ao2_ref(cap, -1);
 	return res;
 
 }
@@ -1835,7 +1853,7 @@
 		ast_log(LOG_WARNING, "Unable to build pvt data for '%s'\n", dest);
 		return NULL;
 	}
-	if (!(ast_format_cap_has_type(cap, AST_FORMAT_TYPE_AUDIO))) {
+	if (!(ast_format_cap_has_type(cap, AST_MEDIA_TYPE_AUDIO))) {
 		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), cap));
 		oh323_destroy(pvt);
 		if (cause)
@@ -2058,7 +2076,7 @@
 	if (!pvt->rtp)
 		__oh323_rtp_create(pvt);
 
-	if ((pt == 2) && (pvt->jointcapability & AST_FORMAT_G726_AAL2)) {
+	if ((pt == 2) && (pvt->jointcapability & ast_format_compatibility_format2bitfield(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);
 	}
 
@@ -2102,23 +2120,20 @@
 	/* Don't try to lock the channel if nothing changed */
 	if (nativeformats_changed || pvt->options.progress_audio || (rtp_change != NEED_NONE)) {
 		if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
-			struct ast_format_cap *pvt_native = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-			ast_format_cap_from_old_bitfield(pvt_native, pvt->nativeformats);
-
-			/* Re-build translation path only if native format(s) has been changed */
-			if (!(ast_format_cap_identical(ast_channel_nativeformats(pvt->owner), pvt_native))) {
-				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_native),
-						ast_getformatname_multiple(tmp2, sizeof(tmp2), ast_channel_nativeformats(pvt->owner)),
-						ast_getformatname(ast_channel_readformat(pvt->owner)),
-						ast_getformatname(ast_channel_writeformat(pvt->owner)));
-				}
-				ast_format_cap_copy(ast_channel_nativeformats(pvt->owner), pvt_native);
-				ast_set_read_format(pvt->owner, ast_channel_readformat(pvt->owner));
-				ast_set_write_format(pvt->owner, ast_channel_writeformat(pvt->owner));
-			}
+			struct ast_format_cap *pvt_native = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+			ast_format_compatibility_bitfield2cap(pvt->nativeformats, pvt_native);
+
+			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_native),
+					ast_getformatname_multiple(tmp2, sizeof(tmp2), ast_channel_nativeformats(pvt->owner)),
+					ast_channel_readformat(pvt->owner)->codec->name,
+					ast_channel_writeformat(pvt->owner)->codec->name);
+			}
+			ast_channel_nativeformats_set(pvt->owner, pvt_native);
+			ast_set_read_format(pvt->owner, ast_channel_readformat(pvt->owner));
+			ast_set_write_format(pvt->owner, ast_channel_writeformat(pvt->owner));
 			if (pvt->options.progress_audio)
 				ast_queue_control(pvt->owner, AST_CONTROL_PROGRESS);
 			switch (rtp_change) {
@@ -2132,7 +2147,7 @@
 				break;
 			}
 			ast_channel_unlock(pvt->owner);
-			pvt_native = ast_format_cap_destroy(pvt_native);
+			ao2_ref(pvt_native, -1);
 		} else {
 			if (pvt->options.progress_audio)
 				pvt->newcontrol = AST_CONTROL_PROGRESS;
@@ -2565,19 +2580,20 @@
 		memcpy(&pvt->peer_prefs, prefs, sizeof(pvt->peer_prefs));
 		if (h323debug) {
 			int i;
+			struct ast_format *fmt;
 			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\n", i, ast_codec_pref_index(prefs, i, &fmt)->codec->name);
 			}
 		}
 		if (pvt->rtp) {
 			if (pvt->options.autoframing) {
 				ast_debug(2, "Autoframing option set, using peer's packetization settings\n");
-				ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->peer_prefs);
+//				ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->peer_prefs);
 			} else {
 				ast_debug(2, "Autoframing option not set, ignoring peer's packetization settings\n");
-				ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->options.prefs);
+//				ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->options.prefs);
 			}
 		}
 	}
@@ -2605,10 +2621,11 @@
 
 	if (h323debug) {
 		int i;
+		struct ast_format *fmt;
 		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\n", i, ast_codec_pref_index(&prefs, i, &fmt)->codec->name);
 		}
 		ast_debug(1, "Capabilities for connection %s is set\n", token);
 	}
@@ -3345,10 +3362,10 @@
 {
 	int res;
 
-	if (!(oh323_tech.capabilities = ast_format_cap_alloc(0))) {
+	if (!(oh323_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_FAILURE;
 	}
-	ast_format_cap_add_all_by_type(oh323_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
+	ast_format_cap_add_all_by_type(oh323_tech.capabilities, AST_MEDIA_TYPE_AUDIO);
 
 	h323debug = 0;
 	sched = ast_sched_context_create();
@@ -3520,7 +3537,8 @@
 	ASTOBJ_CONTAINER_DESTROYALL(&aliasl, oh323_destroy_alias);
 	ASTOBJ_CONTAINER_DESTROY(&aliasl);
 
-	oh323_tech.capabilities = ast_format_cap_destroy(oh323_tech.capabilities);
+	ao2_ref(oh323_tech.capabilities, -1);
+	oh323_tech.capabilities = NULL;
 	return 0;
 }
 




More information about the svn-commits mailing list