[MPlayer-cvslog] CVS: main/libaf af_format.c, 1.16, 1.17 af_format.h, 1.3, 1.4

Alex Beregszaszi syncmail at mplayerhq.hu
Sun Dec 19 17:52:30 CET 2004


CVS change done by Alex Beregszaszi

Update of /cvsroot/mplayer/main/libaf
In directory mail:/var2/tmp/cvs-serv15332

Modified Files:
	af_format.c af_format.h 
Log Message:
libaf formats v2

Index: af_format.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_format.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- af_format.c	20 Nov 2004 10:32:52 -0000	1.16
+++ af_format.c	19 Dec 2004 16:52:28 -0000	1.17
@@ -43,7 +43,7 @@
 static void int2float(void* in, void* out, int len, int bps);
 
 // Convert from string to format
-static int str2fmt(char* str)
+int af_str2fmt(char* str)
 {
   int format=0;
   // Scan for endianess
@@ -87,9 +87,22 @@
   return format;
 }
 
+int af_fmt2bits(int format)
+{
+    switch(format & AF_FORMAT_BITS_MASK)
+    {
+	case AF_FORMAT_8BIT: return 8;
+	case AF_FORMAT_16BIT: return 16;
+	case AF_FORMAT_24BIT: return 24;
+	case AF_FORMAT_32BIT: return 32;
+	case AF_FORMAT_48BIT: return 48;
+    }
+    return -1;
+}
+
 /* Convert format to str input str is a buffer for the 
    converted string, size is the size of the buffer */
-char* fmt2str(int format, char* str, size_t size)
+char* af_fmt2str(int format, char* str, int size)
 {
   int i=0;
   // Print endinaness
@@ -113,7 +126,7 @@
   else{
     // Point
     if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK))
-      i+=snprintf(&str[i],size,"float ");
+      i+=snprintf(&str[i],size-i,"float ");
     else{
       // Sign
       if(AF_FORMAT_US == (format & AF_FORMAT_SIGN_MASK))
@@ -121,7 +134,10 @@
       else
 	i+=snprintf(&str[i],size-i,"signed ");
 
-      i+=snprintf(&str[i],size,"int ");
+      // Bits
+      i+=snprintf(&str[i],size-i,"%d-bit ", af_fmt2bits(format));
+
+      i+=snprintf(&str[i],size-i,"int ");
     }
   }
   return str;
@@ -148,7 +164,7 @@
   case(AF_FORMAT_MPEG2): 
   case(AF_FORMAT_AC3):
     af_msg(AF_MSG_ERROR,"[format] Sample format %s not yet supported \n",
-	 fmt2str(format,buf,255)); 
+	 af_fmt2str(format,buf,255)); 
     return AF_ERROR;
   }
   return AF_OK;
@@ -174,8 +190,8 @@
       return AF_ERROR;
 
     af_msg(AF_MSG_VERBOSE,"[format] Changing sample format from %ibit %sto %ibit %s \n",
-	   ((af_data_t*)arg)->bps*8,fmt2str(((af_data_t*)arg)->format,buf1,255),
-	   af->data->bps*8,fmt2str(af->data->format,buf2,255));
+	   ((af_data_t*)arg)->bps*8,af_fmt2str(((af_data_t*)arg)->format,buf1,255),
+	   af->data->bps*8,af_fmt2str(af->data->format,buf2,255));
 
     af->data->rate = ((af_data_t*)arg)->rate;
     af->data->nch  = ((af_data_t*)arg)->nch;
@@ -190,7 +206,7 @@
     str[0] = '\0';
     sscanf((char*)arg,"%i:%s",&bps,str);
     // Convert string to format
-    format = str2fmt(str);
+    format = af_str2fmt(str);
     
     // Automatic correction of errors
     switch(format & AF_FORMAT_SPECIAL_MASK){

Index: af_format.h
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_format.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- af_format.h	4 Oct 2004 19:11:05 -0000	1.3
+++ af_format.h	19 Dec 2004 16:52:28 -0000	1.4
@@ -1,11 +1,13 @@
 /* The sample format system used lin libaf is based on bitmasks. The
    format definition only refers to the storage format not the
    resolution. */
+#ifndef __af_format_h__
+#define __af_format_h__
 
 // Endianess
-#define AF_FORMAT_BE		(0<<0) // Big Endian
-#define AF_FORMAT_LE		(1<<0) // Little Endian
-#define AF_FORMAT_END_MASK	(1<<0)
+#define AF_FORMAT_LE		0x0 // Little Endian
+#define AF_FORMAT_BE		0x1 // Big Endian
+#define AF_FORMAT_END_MASK	0x1
 
 #if WORDS_BIGENDIAN	       	// Native endian of cpu
 #define	AF_FORMAT_NE		AF_FORMAT_BE
@@ -14,22 +16,69 @@
 #endif
 
 // Signed/unsigned
-#define AF_FORMAT_SI		(0<<1) // SIgned
-#define AF_FORMAT_US		(1<<1) // Un Signed
-#define AF_FORMAT_SIGN_MASK	(1<<1)
+#define AF_FORMAT_SI		0x2 // Signed
+#define AF_FORMAT_US		0x4 // Unsigned
+#define AF_FORMAT_SIGN_MASK	0x6
 
 // Fixed or floating point
-#define AF_FORMAT_I		(0<<2) // Int
-#define AF_FORMAT_F		(1<<2) // Foating point
-#define AF_FORMAT_POINT_MASK	(1<<2)
+#define AF_FORMAT_I		0x8 // Int
+#define AF_FORMAT_F		0x10 // Foating point
+#define AF_FORMAT_SPECIAL	0x20 // Must be set if below values used
+#define AF_FORMAT_POINT_MASK	0xf0
+
+// Bits used
+#define AF_FORMAT_8BIT		0x100
+#define AF_FORMAT_16BIT		0x200
+#define AF_FORMAT_24BIT		0x400
+#define AF_FORMAT_32BIT		0x800
+#define AF_FORMAT_48BIT		0x1000
+#define AF_FORMAT_BITS_MASK	0xff00
 
 // Special flags refering to non pcm data
-#define AF_FORMAT_MU_LAW	(1<<3) // 
-#define AF_FORMAT_A_LAW		(2<<3) // 
-#define AF_FORMAT_MPEG2		(3<<3) // MPEG(2) audio
-#define AF_FORMAT_AC3		(4<<3) // Dolby Digital AC3
-#define AF_FORMAT_IMA_ADPCM	AF_FORMAT_LE|AF_FORMAT_SI // Same as 16 bit signed int 
-#define AF_FORMAT_SPECIAL_MASK	(7<<3)
+#define AF_FORMAT_MU_LAW	(AF_FORMAT_SPECIAL|0x10000)
+#define AF_FORMAT_A_LAW		(AF_FORMAT_SPECIAL|0x20000)
+#define AF_FORMAT_MPEG2		(AF_FORMAT_SPECIAL|0x40000) // MPEG(2) audio
+#define AF_FORMAT_AC3		(AF_FORMAT_SPECIAL|0x80000) // Dolby Digital AC3
+#define AF_FORMAT_IMA_ADPCM	(AF_FORMAT_SPECIAL|0x100000)
+#define AF_FORMAT_SPECIAL_MASK	0xff0000
+
+// PREDEFINED formats
+
+#define AF_FORMAT_U8		(AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_8BIT)
+#define AF_FORMAT_S8		(AF_FORMAT_I|AF_FORMAT_SI|AF_FORMAT_8BIT)
+#define AF_FORMAT_U16_LE	(AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_16BIT|AF_FORMAT_LE)
+#define AF_FORMAT_U16_BE	(AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_16BIT|AF_FORMAT_BE)
+#define AF_FORMAT_S16_LE	(AF_FORMAT_I|AF_FORMAT_SI|AF_FORMAT_16BIT|AF_FORMAT_LE)
+#define AF_FORMAT_S16_BE	(AF_FORMAT_I|AF_FORMAT_SI|AF_FORMAT_16BIT|AF_FORMAT_BE)
+#define AF_FORMAT_U24_LE	(AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_24BIT|AF_FORMAT_LE)
+#define AF_FORMAT_U24_BE	(AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_24BIT|AF_FORMAT_BE)
+#define AF_FORMAT_S24_LE	(AF_FORMAT_I|AF_FORMAT_SI|AF_FORMAT_24BIT|AF_FORMAT_LE)
+#define AF_FORMAT_S24_BE	(AF_FORMAT_I|AF_FORMAT_SI|AF_FORMAT_24BIT|AF_FORMAT_BE)
+#define AF_FORMAT_U32_LE	(AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_32BIT|AF_FORMAT_LE)
+#define AF_FORMAT_U32_BE	(AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_32BIT|AF_FORMAT_BE)
+#define AF_FORMAT_S32_LE	(AF_FORMAT_I|AF_FORMAT_SI|AF_FORMAT_32BIT|AF_FORMAT_LE)
+#define AF_FORMAT_S32_BE	(AF_FORMAT_I|AF_FORMAT_SI|AF_FORMAT_32BIT|AF_FORMAT_BE)
+
+#define AF_FORMAT_FLOAT		(AF_FORMAT_F|AF_FORMAT_32BIT|AF_FORMAT_NE)
+
+#ifdef WORDS_BIGENDIAN
+#define AF_FORMAT_U16_NE AF_FORMAT_U16_BE
+#define AF_FORMAT_S16_NE AF_FORMAT_S16_BE
+#define AF_FORMAT_U24_NE AF_FORMAT_U24_BE
+#define AF_FORMAT_S24_NE AF_FORMAT_S24_BE
+#define AF_FORMAT_U32_NE AF_FORMAT_U32_BE
+#define AF_FORMAT_S32_NE AF_FORMAT_S32_BE
+#else
+#define AF_FORMAT_U16_NE AF_FORMAT_U16_LE
+#define AF_FORMAT_S16_NE AF_FORMAT_S16_LE
+#define AF_FORMAT_U24_NE AF_FORMAT_U24_LE
+#define AF_FORMAT_S24_NE AF_FORMAT_S24_LE
+#define AF_FORMAT_U32_NE AF_FORMAT_U32_LE
+#define AF_FORMAT_S32_NE AF_FORMAT_S32_LE
+#endif
 
-extern char* fmt2str(int format, char* str, size_t size);
+extern int af_str2fmt(char *str);
+extern int af_fmt2bits(int format);
+extern char* af_fmt2str(int format, char* str, int size);
 
+#endif /* __af_format_h__ */




More information about the MPlayer-cvslog mailing list