[asterisk-commits] tilghman: branch group/codec_bits r112823 - in /team/group/codec_bits: includ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 4 15:10:39 CDT 2008


Author: tilghman
Date: Fri Apr  4 15:10:38 2008
New Revision: 112823

URL: http://svn.digium.com/view/asterisk?view=rev&rev=112823
Log:
Implementing bitwise operations

Modified:
    team/group/codec_bits/include/asterisk/frame.h
    team/group/codec_bits/main/frame.c

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=112823&r1=112822&r2=112823
==============================================================================
--- team/group/codec_bits/include/asterisk/frame.h (original)
+++ team/group/codec_bits/include/asterisk/frame.h Fri Apr  4 15:10:38 2008
@@ -652,12 +652,69 @@
 #define BITSTRING_SIZE	60
 
 /*! Common bitwise operations, now that codec is no longer a 32-bit integer. */
-int ast_extended_codec_not(struct ast_extended_codec format);
-int ast_extended_codec_nonzero(struct ast_extended_codec format);
-int ast_extended_codec_equal(struct ast_extended_codec format1, struct ast_extended_codec format2);
-struct ast_extended_codec ast_extended_codec_compl(struct ast_extended_codec format);
-struct ast_extended_codec ast_extended_codec_and(struct ast_extended_codec format1, struct ast_extended_codec format2);
-struct ast_extended_codec ast_extended_codec_or(struct ast_extended_codec format1, struct ast_extended_codec format2);
+
+AST_INLINE_API(
+int ast_extended_codec_not(struct ast_extended_codec format),
+{
+	int i;
+	int max = sizeof(format) / sizeof(int);
+	union {
+		struct ast_extended_codec c;
+		int bits[sizeof(format) / sizeof(int)];
+	} u = { format };
+	for (i = 0; i < max; i++) {
+		if (u.bits[i]) {
+			return 0;
+		}
+	}
+	return 1;
+}
+)
+
+AST_INLINE_API(
+int ast_extended_codec_nonzero(struct ast_extended_codec format),
+{
+	int i;
+	int max = sizeof(format) / sizeof(int);
+	union {
+		struct ast_extended_codec c;
+		int bits[sizeof(format) / sizeof(int)];
+	} u = { format };
+	for (i = 0; i < max; i++) {
+		if (u.bits[i]) {
+			return 1;
+		}
+	}
+	return 0;
+}
+)
+
+AST_INLINE_API(
+int ast_extended_codec_equal(struct ast_extended_codec format1, struct ast_extended_codec format2),
+{
+	return memcmp(&format1, &format2, sizeof(format1)) == 0 ? 1 : 0;
+}
+)
+
+AST_INLINE_API(
+struct ast_extended_codec ast_extended_codec_compl(struct ast_extended_codec format),
+{
+	int i;
+	int max = sizeof(format) / sizeof(int);
+	union {
+		struct ast_extended_codec c;
+		int bits[sizeof(format) / sizeof(int)];
+	} u = { format };
+	for (i = 0; i < max; i++) {
+		u.bits[i] = ~u.bits[i];
+	}
+	return u.c;
+}
+)
+
+extern struct ast_extended_codec ast_extended_codec_and(struct ast_extended_codec format1, struct ast_extended_codec format2);
+extern struct ast_extended_codec ast_extended_codec_or(struct ast_extended_codec format1, struct ast_extended_codec format2);
+
 #define FMT_AND(a,b)	ast_extended_codec_and(a,b)
 #define FMT_OR(a,b)	ast_extended_codec_or(a,b)
 #define FMT_EQ(a,b)	ast_extended_codec_equal(a,b)
@@ -665,9 +722,44 @@
 #define FMT_NZ(a)	ast_extended_codec_nonzero(a)
 #define FMT_NOT(a)	ast_extended_codec_not(a)
 
-int ast_extended_codec_isaudio(struct ast_extended_codec format);
-int ast_extended_codec_isvideo(struct ast_extended_codec format);
-int ast_extended_codec_isimage(struct ast_extended_codec format);
+AST_INLINE_API(
+int ast_extended_codec_isaudio(struct ast_extended_codec format),
+{
+	unsigned int i;
+	for (i = 0; i < sizeof(format.audio) / sizeof(format.audio[0]); i++) {
+		if (format.audio[i]) {
+			return 1;
+		}
+	}
+	return 0;
+}
+)
+
+AST_INLINE_API(
+int ast_extended_codec_isvideo(struct ast_extended_codec format),
+{
+	unsigned int i;
+	for (i = 0; i < sizeof(format.video) / sizeof(format.video[0]); i++) {
+		if (format.video[i]) {
+			return 1;
+		}
+	}
+	return 0;
+}
+)
+
+AST_INLINE_API(
+int ast_extended_codec_isimage(struct ast_extended_codec format),
+{
+	unsigned int i;
+	for (i = 0; i < sizeof(format.image) / sizeof(format.image[0]); i++) {
+		if (format.image[i]) {
+			return 1;
+		}
+	}
+	return 0;
+}
+)
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/group/codec_bits/main/frame.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/main/frame.c?view=diff&rev=112823&r1=112822&r2=112823
==============================================================================
--- team/group/codec_bits/main/frame.c (original)
+++ team/group/codec_bits/main/frame.c Fri Apr  4 15:10:38 2008
@@ -1679,3 +1679,30 @@
 
 	return 0;
 }
+
+struct ast_extended_codec ast_extended_codec_and(struct ast_extended_codec format1, struct ast_extended_codec format2)
+{
+	int i, max = sizeof(format1) / sizeof(int);
+	union {
+		struct ast_extended_codec c;
+		int bits[sizeof(format1) / sizeof(int)];
+	} f1 = { format1 }, f2 = { format2 }, answer;
+	for (i = 0; i < max; i++) {
+		answer.bits[i] = f1.bits[i] & f2.bits[i];
+	}
+	return answer.c;
+}
+
+struct ast_extended_codec ast_extended_codec_or(struct ast_extended_codec format1, struct ast_extended_codec format2)
+{
+	int i, max = sizeof(format1) / sizeof(int);
+	union {
+		struct ast_extended_codec c;
+		int bits[sizeof(format1) / sizeof(int)];
+	} f1 = { format1 }, f2 = { format2 }, answer = { { { 0 } } };
+	for (i = 0; i < max; i++) {
+		answer.bits[i] = f1.bits[i] | f2.bits[i];
+	}
+	return answer.c;
+}
+




More information about the asterisk-commits mailing list