[MPlayer-dev-eng] [PATCH] lavcresample crashes when no AF_CONTROL_COMMAND_LINE

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat Dec 18 13:08:45 CET 2004


Hi,
lavcresample currently crashes when AF_CONTROL_COMMAND_LINE is not sent.
This is because the cutoff values isn't initialized in init.
The attached patch fixes it and also uses a local variable to initialize
setup to avoid doing "hundreds" of typecasts.
I need this fixed because I want to make lavcresample default with
-af-adv force=1.
If nobody speaks up against this I will probably apply tomorrow.

Greetings,
Reimar Döffinger
-------------- next part --------------
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 12:03:19 -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);
@@ -144,16 +148,18 @@
 }
 
 static int open(af_instance_t* af){
+  af_resample_t *s = calloc(1,sizeof(af_resample_t));
   af->control=control;
   af->uninit=uninit;
   af->play=play;
   af->mul.n=1;
   af->mul.d=1;
   af->data=calloc(1,sizeof(af_data_t));
-  af->setup=calloc(1,sizeof(af_resample_t));
-  ((af_resample_t*)af->setup)->filter_length= 16;
-  ((af_resample_t*)af->setup)->phase_shift= 10;
-//  ((af_resample_t*)af->setup)->setup = RSMP_INT | FREQ_SLOPPY;
+  s->filter_length= 16;
+  s->cutoff= max(1.0 - 1.0/s->filter_length, 0.80);
+  s->phase_shift= 10;
+//  s->setup = RSMP_INT | FREQ_SLOPPY;
+  af->setup=s;
   return AF_OK;
 }
 


More information about the MPlayer-dev-eng mailing list