[MPlayer-cvslog] CVS: main/libaf af.c, 1.38, 1.39 af_format.c, 1.21, 1.22 af_format.h, 1.5, 1.6 control.h, 1.7, 1.8

Alex Beregszaszi syncmail at mplayerhq.hu
Mon Jan 3 19:59:19 CET 2005


CVS change done by Alex Beregszaszi

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

Modified Files:
	af.c af_format.c af_format.h control.h 
Log Message:
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c

Index: af.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- af.c	3 Jan 2005 14:05:38 -0000	1.38
+++ af.c	3 Jan 2005 18:59:16 -0000	1.39
@@ -270,8 +270,8 @@
 	  if(NULL == (new = af_prepend(s,af,"format")))
 	    return AF_ERROR;
 	  // Set output bits per sample
-	  if(AF_OK != (rv = new->control(new,AF_CONTROL_FORMAT_BPS,&in.bps)) || 
-	     AF_OK != (rv = new->control(new,AF_CONTROL_FORMAT_FMT,&in.format)))
+	  in.format |= af_bits2fmt(in.bps*8);
+	  if(AF_OK != (rv = new->control(new,AF_CONTROL_FORMAT_FMT,&in.format)))
 	    return rv;
 	  // Initialize format filter
 	  if(!new->prev) 
@@ -444,8 +444,8 @@
       else
 	af = s->last;
       // Init the new filter
-      if(!af ||(AF_OK != af->control(af,AF_CONTROL_FORMAT_BPS,&(s->output.bps))) 
-	 || (AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT,&(s->output.format))))
+      s->output.format |= af_bits2fmt(s->output.bps*8);
+      if(!af || (AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT,&(s->output.format))))
 	return -1;
       if(AF_OK != af_reinit(s,af))
 	return -1;

Index: af_format.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_format.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- af_format.c	29 Dec 2004 19:05:29 -0000	1.21
+++ af_format.c	3 Jan 2005 18:59:16 -0000	1.22
@@ -110,6 +110,11 @@
     return -1;
 }
 
+inline int af_bits2fmt(int bits)
+{
+    return (bits/8 - 1) << 3;
+}
+
 /* Convert format to str input str is a buffer for the 
    converted string, size is the size of the buffer */
 char* af_fmt2str(int format, char* str, int size)
@@ -194,6 +199,53 @@
     return "??";
 }
 
+int af_str2fmt_short(char* str)
+{
+    int i;
+    static struct {
+	const char *name;
+	const int format;
+    } table[] = {
+	{ "mulaw", AF_FORMAT_MU_LAW },
+	{ "alaw", AF_FORMAT_A_LAW },
+	{ "mpeg2", AF_FORMAT_MPEG2 },
+	{ "ac3", AF_FORMAT_AC3 },
+	{ "imaadpcm", AF_FORMAT_IMA_ADPCM },
+
+	{ "u8", AF_FORMAT_U8 },
+	{ "s8", AF_FORMAT_S8 },
+	{ "u16le", AF_FORMAT_U16_LE },
+	{ "u16be", AF_FORMAT_U16_BE },
+	{ "u16ne", AF_FORMAT_U16_NE },
+	{ "s16le", AF_FORMAT_S16_LE },
+	{ "s16be", AF_FORMAT_S16_BE },
+	{ "s16ne", AF_FORMAT_S16_NE },
+	{ "u24le", AF_FORMAT_U24_LE },
+	{ "u24be", AF_FORMAT_U24_BE },
+	{ "u24ne", AF_FORMAT_U24_NE },
+	{ "s24le", AF_FORMAT_S24_LE },
+	{ "s24be", AF_FORMAT_S24_BE },
+	{ "s24ne", AF_FORMAT_S24_NE },
+	{ "u32le", AF_FORMAT_U32_LE },
+	{ "u32be", AF_FORMAT_U32_BE },
+	{ "u32ne", AF_FORMAT_U32_NE },
+	{ "s32le", AF_FORMAT_S32_LE },
+	{ "s32be", AF_FORMAT_S32_BE },
+	{ "s32ne", AF_FORMAT_S32_NE },
+	{ "floatle", AF_FORMAT_FLOAT_LE },
+	{ "floatbe", AF_FORMAT_FLOAT_BE },
+	{ "floatne", AF_FORMAT_FLOAT_NE },
+	
+	{ NULL, 0 }
+    };
+    
+    for (i = 0; table[i].name; i++)
+	if (!strcasecmp(str, table[i].name))
+	    return table[i].format;
+
+    return -1;
+}
+
 // Helper functions to check sanity for input arguments
 
 // Sanity check for bytes per sample
@@ -212,6 +264,7 @@
 {
   char buf[256];
   switch(format & AF_FORMAT_SPECIAL_MASK){
+  case(AF_FORMAT_IMA_ADPCM): 
   case(AF_FORMAT_MPEG2): 
   case(AF_FORMAT_AC3):
     af_msg(AF_MSG_ERROR,"[format] Sample format %s not yet supported \n",
@@ -279,52 +332,22 @@
     return AF_OK;
   }
   case AF_CONTROL_COMMAND_LINE:{
-    int bps = 2;
-    int format = AF_FORMAT_NE;
-    char str[256];
-    str[0] = '\0';
-    sscanf((char*)arg,"%i:%s",&bps,str);
-    // Convert string to format
-    format = af_str2fmt(str);
-    
-    // Automatic correction of errors
-    switch(format & AF_FORMAT_SPECIAL_MASK){
-    case(AF_FORMAT_A_LAW):
-    case(AF_FORMAT_MU_LAW): 
-      bps=1; break;
-    case(AF_FORMAT_AC3):
-      bps=4; break; // I think
-    }
-    if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK))
-      bps=4;
-
-    // set appropriate AF_FORMAT_BITS
-    format |= (bps-1)<<3; // hack
-    
-    if((AF_OK != af->control(af,AF_CONTROL_FORMAT_BPS | AF_CONTROL_SET,&bps)) ||
-       (AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format)))
+    int format = af_str2fmt_short(arg);
+    if(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format))
       return AF_ERROR;
     return AF_OK;
   }
-  case AF_CONTROL_FORMAT_BPS | AF_CONTROL_SET:
-    // Reinit must be called after this function has been called
-    
-    // Check for errors in configuraton
-    if(AF_OK != check_bps(*(int*)arg))
-      return AF_ERROR;
-
-    af->data->bps = *(int*)arg;
-    return AF_OK;
-  case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:
-    // Reinit must be called after this function has been called
-
+  case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{
     // Check for errors in configuraton
     if(AF_OK != check_format(*(int*)arg))
       return AF_ERROR;
 
     af->data->format = *(int*)arg;
+    af->data->bps = af_fmt2bits(af->data->format)/8;
+
     return AF_OK;
   }
+  }
   return AF_UNKNOWN;
 }
 

Index: af_format.h
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_format.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- af_format.h	28 Dec 2004 18:13:09 -0000	1.5
+++ af_format.h	3 Jan 2005 18:59:16 -0000	1.6
@@ -81,7 +81,9 @@
 #endif
 
 extern int af_str2fmt(char *str);
+extern int af_str2fmt_short(char *str);
 extern int af_fmt2bits(int format);
+extern int af_bits2fmt(int bits);
 extern char* af_fmt2str(int format, char* str, int size);
 extern char* af_fmt2str_short(int format);
 

Index: control.h
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/control.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- control.h	4 Oct 2004 19:11:05 -0000	1.7
+++ control.h	3 Jan 2005 18:59:16 -0000	1.8
@@ -113,13 +113,9 @@
 // Set resampling accuracy
 #define AF_CONTROL_RESAMPLE_ACCURACY	0x00000300 | AF_CONTROL_FILTER_SPECIFIC
 
-// Format 
+// Format
 
-// Set output format bits per sample
-#define AF_CONTROL_FORMAT_BPS		0x00000400 | AF_CONTROL_FILTER_SPECIFIC
-
-// Set output format sample format
-#define AF_CONTROL_FORMAT_FMT		0x00000500 | AF_CONTROL_FILTER_SPECIFIC
+#define AF_CONTROL_FORMAT_FMT		0x00000400 | AF_CONTROL_FILTER_SPECIFIC
 
 // Channels
 




More information about the MPlayer-cvslog mailing list