[MPlayer-dev-eng] [PATCH] af should request format instead of failing

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat Dec 18 12:35:39 CET 2004


Hi,
> > currently audio filters fail (AF_ERROR) when they get an input
> > format they do not support instead of requesting a working one.
> > The following patch changes this.
> > Now I'd like to know: did I miss something or was whoever coded this
> > really as clueless as it seems?
> > If you don't speak up I will probably apply tomorrow.
> 
> Oh well, the usual problem struck ;-). Here is the patch...

Some corrections...

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libaf/af_extrastereo.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_extrastereo.c,v
retrieving revision 1.2
diff -u -r1.2 af_extrastereo.c
--- libaf/af_extrastereo.c	10 Oct 2004 14:20:42 -0000	1.2
+++ libaf/af_extrastereo.c	18 Dec 2004 11:31:02 -0000
@@ -35,10 +35,6 @@
     // Sanity check
     if(!arg) return AF_ERROR;
     
-    if(((af_data_t*)arg)->format != (AF_FORMAT_SI | AF_FORMAT_NE) ||
-       (((af_data_t*)arg)->nch != 2))
-       return AF_ERROR;
-
     af->data->rate   = ((af_data_t*)arg)->rate;
     af->data->nch    = 2;
     af->data->format = AF_FORMAT_SI | AF_FORMAT_NE;
Index: libaf/af_hrtf.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_hrtf.c,v
retrieving revision 1.1
diff -u -r1.1 af_hrtf.c
--- libaf/af_hrtf.c	20 Nov 2004 14:40:52 -0000	1.1
+++ libaf/af_hrtf.c	18 Dec 2004 11:31:04 -0000
@@ -108,6 +108,8 @@
     case AF_CONTROL_REINIT:
 	af->data->rate   = ((af_data_t*)arg)->rate;
 	if(af->data->rate != 48000) {
+	    // automatic samplerate adjustment in the filter chain
+	    // is not yet supported.
 	    af_msg(AF_MSG_ERROR,
 		   "[hrtf] ERROR: Sampling rate is not 48000 Hz (%d)!\n",
 		   af->data->rate);
@@ -115,14 +117,11 @@
 	}
 	af->data->nch    = ((af_data_t*)arg)->nch;
 	if(af->data->nch < 5) {
-	    af_msg(AF_MSG_ERROR,
-		   "[hrtf] ERROR: Insufficient channels (%d < 5).\n",
-		   af->data->nch);
-	    return AF_ERROR;
+	    af->data->nch = 5;
 	}
 	af->data->format = AF_FORMAT_SI | AF_FORMAT_NE;
 	af->data->bps    = 2;
-	return AF_OK;
+	return af_test_output(af, (af_data_t*)arg);
     case AF_CONTROL_COMMAND_LINE:
 	sscanf((char*)arg, "%c", &mode);
 	switch(mode) {
Index: libaf/af_lavcresample.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_lavcresample.c,v
retrieving revision 1.3
diff -u -r1.3 af_lavcresample.c
--- libaf/af_lavcresample.c	3 Nov 2004 01:53:56 -0000	1.3
+++ libaf/af_lavcresample.c	18 Dec 2004 11:31:05 -0000
@@ -43,16 +43,15 @@
   int g;
   af_resample_t* s   = (af_resample_t*)af->setup; 
   af_data_t *data= (af_data_t*)arg;
+  int out_rate, test_output_res; // helpers for checking input format
 
   switch(cmd){
   case AF_CONTROL_REINIT:
     if((af->data->rate == data->rate) || (af->data->rate == 0))
         return AF_DETACH;
 
-    if(data->format != (AF_FORMAT_SI | AF_FORMAT_NE) || data->nch > CHANS)
-       return AF_ERROR;
-
     af->data->nch    = data->nch;
+    if (af->data->nch > CHANS) af->data->nch = CHANS;
     af->data->format = AF_FORMAT_SI | AF_FORMAT_NE;
     af->data->bps    = 2;
     g= ff_gcd(af->data->rate, data->rate);
@@ -63,7 +62,12 @@
     if(s->avrctx) av_resample_close(s->avrctx);
     s->avrctx= av_resample_init(af->mul.n, /*in_rate*/af->mul.d, s->filter_length, s->phase_shift, s->linear, s->cutoff);
 
-    return AF_OK;
+    // hack to make af_test_output ignore the samplerate change
+    out_rate = af->data->rate;
+    af->data->rate = data->rate;
+    test_output_res = af_test_output(af, (af_data_t*)arg);
+    af->data->rate = out_rate;
+    return test_output_res;
   case AF_CONTROL_COMMAND_LINE:{
     sscanf((char*)arg,"%d:%d:%d:%d:%lf", &af->data->rate, &s->filter_length, &s->linear, &s->phase_shift, &s->cutoff);
     if(s->cutoff <= 0.0) s->cutoff= max(1.0 - 1.0/s->filter_length, 0.80);
Index: libaf/af_sweep.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_sweep.c,v
retrieving revision 1.1
diff -u -r1.1 af_sweep.c
--- libaf/af_sweep.c	21 Oct 2004 12:10:55 -0000	1.1
+++ libaf/af_sweep.c	18 Dec 2004 11:31:05 -0000
@@ -24,9 +24,6 @@
 
   switch(cmd){
   case AF_CONTROL_REINIT:
-    if(data->format != (AF_FORMAT_SI | AF_FORMAT_NE))
-       return AF_ERROR;
-
     af->data->nch    = data->nch;
     af->data->format = AF_FORMAT_SI | AF_FORMAT_NE;
     af->data->bps    = 2;
Index: libaf/af_volnorm.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_volnorm.c,v
retrieving revision 1.2
diff -u -r1.2 af_volnorm.c
--- libaf/af_volnorm.c	10 Oct 2004 14:20:42 -0000	1.2
+++ libaf/af_volnorm.c	18 Dec 2004 11:31:05 -0000
@@ -79,10 +79,6 @@
     af->data->rate   = ((af_data_t*)arg)->rate;
     af->data->nch    = ((af_data_t*)arg)->nch;
     
-    if(((af_data_t*)arg)->format != (AF_FORMAT_F | AF_FORMAT_NE) &&
-       ((af_data_t*)arg)->format != (AF_FORMAT_SI | AF_FORMAT_NE))
-       return AF_ERROR;
-    
     if(((af_data_t*)arg)->format == (AF_FORMAT_SI | AF_FORMAT_NE)){
       af->data->format = AF_FORMAT_SI | AF_FORMAT_NE;
       af->data->bps    = 2;


More information about the MPlayer-dev-eng mailing list