[asterisk-commits] tilghman: branch group/codec_bits r114136 - in /team/group/codec_bits: channe...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 15 11:28:21 CDT 2008


Author: tilghman
Date: Tue Apr 15 11:28:21 2008
New Revision: 114136

URL: http://svn.digium.com/view/asterisk?view=rev&rev=114136
Log:
Some of the more difficult changes for codec_zap and chan_iax

Modified:
    team/group/codec_bits/channels/chan_iax2.c
    team/group/codec_bits/channels/iax2.h
    team/group/codec_bits/codecs/codec_zap.c
    team/group/codec_bits/include/asterisk/frame.h

Modified: team/group/codec_bits/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_iax2.c?view=diff&rev=114136&r1=114135&r2=114136
==============================================================================
--- team/group/codec_bits/channels/chan_iax2.c (original)
+++ team/group/codec_bits/channels/chan_iax2.c Tue Apr 15 11:28:21 2008
@@ -186,16 +186,16 @@
 int (*iax2_regfunk)(const char *username, int onoff) = NULL;
 
 /* Ethernet, etc */
-const struct ast_extended_codec IAX_CAPABILITY_FULLBANDWIDTH = { { -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1 }, -1 };
+const struct ast_extended_codec IAX_CAPABILITY_FULLBANDWIDTH = AST_FMT_FULL_MASK_INIT;
 
 /* T1, maybe ISDN */
-const struct ast_extended_codec IAX_CAPABILITY_MEDBANDWIDTH = { { (-1 & 	\
+const struct ast_extended_codec IAX_CAPABILITY_MEDBANDWIDTH = { .audio = { (-1 & 	\
 					 ~AST_FORMAT_AUDIO_SLINEAR &			\
 					 ~AST_FORMAT_AUDIO_ULAW &			\
 					 ~AST_FORMAT_AUDIO_ALAW &			\
 					 ~AST_FORMAT_AUDIO_G722) }, };
 /* A modem */
-const struct ast_extended_codec IAX_CAPABILITY_LOWBANDWIDTH	= { { (-1 &		\
+const struct ast_extended_codec IAX_CAPABILITY_LOWBANDWIDTH	= { .audio = { (-1 &		\
 					 ~AST_FORMAT_AUDIO_SLINEAR &			\
 					 ~AST_FORMAT_AUDIO_ULAW &			\
 					 ~AST_FORMAT_AUDIO_ALAW &			\
@@ -204,7 +204,7 @@
 					 ~AST_FORMAT_AUDIO_G726_AAL2 &		\
 					 ~AST_FORMAT_AUDIO_ADPCM) }, };
 
-const struct ast_extended_codec IAX_CAPABILITY_LOWFREE = { { (-1 & 		\
+const struct ast_extended_codec IAX_CAPABILITY_LOWFREE = { .audio = { (-1 & 		\
 					 ~AST_FORMAT_AUDIO_SLINEAR &			\
 					 ~AST_FORMAT_AUDIO_ULAW &			\
 					 ~AST_FORMAT_AUDIO_ALAW &			\
@@ -222,7 +222,7 @@
 static	struct io_context *io;
 static	struct sched_context *sched;
 
-static struct ast_extended_codec iax2_capability = { { -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1 }, -1 };
+static struct ast_extended_codec iax2_capability = AST_FMT_FULL_MASK_INIT;
 
 static int iaxdebug = 0;
 
@@ -3482,6 +3482,7 @@
 	if (pds.password)
 		ast_string_field_set(iaxs[callno], secret, pds.password);
 
+	/* FIXME */
 	iax_ie_append_int(&ied, IAX_IE_FORMAT, c->nativeformats);
 	iax_ie_append_int(&ied, IAX_IE_CAPABILITY, iaxs[callno]->capability);
 	iax_ie_append_short(&ied, IAX_IE_ADSICPE, c->adsicpe);

Modified: team/group/codec_bits/channels/iax2.h
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/iax2.h?view=diff&rev=114136&r1=114135&r2=114136
==============================================================================
--- team/group/codec_bits/channels/iax2.h (original)
+++ team/group/codec_bits/channels/iax2.h Tue Apr 15 11:28:21 2008
@@ -169,6 +169,7 @@
 #define IAX_IE_RR_OOO				51		/*!< Frames received Out of Order u32 */
 #define IAX_IE_VARIABLE				52		/*!< Remote variables */
 #define IAX_IE_OSPTOKEN				53		/*!< OSP token */
+#define IAX_IE_FORMAT2				54		/*!< Extended codec support */
 
 #define IAX_MAX_OSPBLOCK_SIZE		254		/*!< Max OSP token block size, 255 bytes - 1 byte OSP token block index */
 #define IAX_MAX_OSPBLOCK_NUM		4

Modified: team/group/codec_bits/codecs/codec_zap.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/codecs/codec_zap.c?view=diff&rev=114136&r1=114135&r2=114136
==============================================================================
--- team/group/codec_bits/codecs/codec_zap.c (original)
+++ team/group/codec_bits/codecs/codec_zap.c Tue Apr 15 11:28:21 2008
@@ -52,7 +52,7 @@
 
 #define BUFFER_SAMPLES	8000
 
-static const struct ast_extended_codec either_codec = { { AST_FORMAT_AUDIO_G729A | AST_FORMAT_AUDIO_G723_1 } };
+static const int either_codec = AST_FORMAT_AUDIO_G729A | AST_FORMAT_AUDIO_G723_1;
 
 static unsigned int global_useplc = 0;
 
@@ -124,7 +124,7 @@
 	struct pvt *ztp = pvt->pvt;
 	struct zt_transcode_header *hdr = ztp->hdr;
 
-	if (!f->subclass) {
+	if (FMT_NOT(f->codec)) {
 		/* Fake a return frame for calculation purposes */
 		ztp->fake = 2;
 		pvt->samples = f->samples;
@@ -163,6 +163,7 @@
 		ztp->fake = 1;
 		pvt->f.frametype = AST_FRAME_VOICE;
 		pvt->f.subclass = 0;
+		pvt->f.codec = AST_FMT_NULL_MASK;
 		pvt->f.samples = 160;
 		pvt->f.data = NULL;
 		pvt->f.offset = 0;
@@ -182,7 +183,8 @@
 			}
 #endif
 			pvt->f.frametype = AST_FRAME_VOICE;
-			pvt->f.subclass = hdr->dstfmt;
+			pvt->f.subclass = 0;
+			pvt->f.codec = ast_codec2extended(hdr->dstfmt);
 			pvt->f.samples = hdr->dstsamples;
 			pvt->f.data = hdr->dstdata + hdr->dstoffset;
 			pvt->f.offset = hdr->dstoffset;
@@ -215,7 +217,7 @@
 	if (ioctl(ztp->fd, ZT_TRANSCODE_OP, &x))
 		ast_log(LOG_WARNING, "Failed to release transcoder channel: %s\n", strerror(errno));
 
-	if (FMT_NZ(FMT_AND(ztp->hdr->dstfmt, either_codec))) {
+	if (ztp->hdr->dstfmt & either_codec) {
 		ast_atomic_fetchadd_int(&channels.encoders, -1);
 	} else {
 		ast_atomic_fetchadd_int(&channels.decoders, -1);
@@ -258,8 +260,6 @@
 		return -1;
 	}
 	
-	hdr->srcfmt = (1 << source);
-	hdr->dstfmt = (1 << dest);
 	if (ioctl(fd, ZT_TRANSCODE_OP, &x)) {
 		ast_log(LOG_ERROR, "Unable to attach transcoder: %s\n", strerror(errno));
 		munmap(hdr, sizeof(*hdr));
@@ -272,7 +272,7 @@
 	ztp->fd = fd;
 	ztp->hdr = hdr;
 
-	if (FMT_NZ(FMT_AND(hdr->dstfmt, either_codec))) {
+	if (hdr->dstfmt & either_codec) {
 		ast_atomic_fetchadd_int(&channels.encoders, +1);
 	} else {
 		ast_atomic_fetchadd_int(&channels.decoders, +1);
@@ -283,7 +283,7 @@
 
 static int zap_new(struct ast_trans_pvt *pvt)
 {
-	return zap_translate(pvt, pvt->t->dstfmt, pvt->t->srcfmt);
+	return zap_translate(pvt, ast_extended2codec(pvt->t->dstfmt), ast_extended2codec(pvt->t->srcfmt));
 }
 
 static struct ast_frame *fakesrc_sample(void)
@@ -307,9 +307,9 @@
 		return -1;
 
 	snprintf((char *) (zt->t.name), sizeof(zt->t.name), "zap%sto%s", 
-		 ast_getformatname((1 << src)), ast_getformatname((1 << dst)));
-	zt->t.srcfmt = (1 << src);
-	zt->t.dstfmt = (1 << dst);
+		 ast_getformatname(ast_codec2extended(src)), ast_getformatname(ast_codec2extended(dst)));
+	zt->t.srcfmt = ast_codec2extended(src);
+	zt->t.dstfmt = ast_codec2extended(dst);
 	zt->t.newpvt = zap_new;
 	zt->t.framein = zap_framein;
 	zt->t.frameout = zap_frameout;
@@ -338,10 +338,10 @@
 
 	AST_LIST_LOCK(&translators);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&translators, cur, entry) {
-		if (cur->t.srcfmt != src)
+		if (ast_extended2codec(cur->t.srcfmt) != src)
 			continue;
 
-		if (cur->t.dstfmt != dst)
+		if (ast_extended2codec(cur->t.dstfmt) != dst)
 			continue;
 
 		AST_LIST_REMOVE_CURRENT(entry);
@@ -403,7 +403,7 @@
 			if (global_format_map.map[dst][src])
 				continue;
 
-			if (!register_translator(dst, src))
+			if (!register_translator(1 << dst, 1 << src))
 				map->map[dst][src] = 1;
 		}
 	}

Modified: team/group/codec_bits/include/asterisk/frame.h
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/include/asterisk/frame.h?view=diff&rev=114136&r1=114135&r2=114136
==============================================================================
--- team/group/codec_bits/include/asterisk/frame.h (original)
+++ team/group/codec_bits/include/asterisk/frame.h Tue Apr 15 11:28:21 2008
@@ -759,6 +759,36 @@
 }
 )
 
+AST_INLINE_API(
+struct ast_extended_codec ast_codec2extended(int format),
+{
+	int audio = format & ((1 << 16) - 1);
+	int image = format & ((1 << 16) | (1 << 17));
+	int video = format & ((1 << 18) | (1 << 19) | (1 << 20) | (1 << 21) | (1 << 22));
+	int text = format & (1 << 25);
+	struct ast_extended_codec codec = AST_FMT_NULL_MASK_INIT;
+
+	codec.audio[0] = audio;
+	codec.video[0] = video >> 18;
+	codec.image[0] = image >> 16;
+	codec.text[0] = text >> 25;
+
+	return codec;
+}
+)
+
+AST_INLINE_API(
+int ast_extended2codec(struct ast_extended_codec codec),
+{
+	int audio = codec.audio[0] & ((1 << 16) - 1);
+	int image = codec.image[0] & 3;
+	int video = codec.image[0] & ((1 << 5) - 1);
+	int text = codec.text[0] & 1;
+
+	return (audio & (image << 16) & (video << 18) & (text < 25));
+}
+)
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif




More information about the asterisk-commits mailing list