Ticket #1561: mplayer-audio-formats-filter-fix-ver3.patch

File mplayer-audio-formats-filter-fix-ver3.patch, 3.2 KB (added by rotmer@…, 16 years ago)

Initial patch for this bug.

  • libaf/af.c

     
    255255   failure */
    256256static int af_reinit(af_stream_t* s, af_instance_t* af)
    257257{
     258  int rv=0; // Return value
     259  af_instance_t* new = NULL;
     260
    258261  do{
    259262    af_data_t in; // Format of the input to current filter
    260     int rv=0; // Return value
    261 
    262263    // Check if there are any filters left in the list
    263264    if(NULL == af){
    264265      if(!(af=af_append(s,s->first,"dummy")))
     
    284285    case AF_FALSE:{ // Configuration filter is needed
    285286      // Do auto insertion only if force is not specified
    286287      if((AF_INIT_TYPE_MASK & s->cfg.force) != AF_INIT_FORCE){
    287         af_instance_t* new = NULL;
    288288        // Insert channels filter
    289289        if((af->prev?af->prev->data->nch:s->input.nch) != in.nch){
    290290          // Create channels filter
     
    350350      return AF_ERROR;
    351351    }
    352352  }while(af);
     353 
     354  if((AF_INIT_TYPE_MASK & s->cfg.force) != AF_INIT_FORCE){
     355    // Check number of output channels fix if not OK
     356    // If needed always inserted last -> easy to screw up other filters
     357    if(s->output.nch && s->last->data->nch!=s->output.nch){
     358      if(!strcmp(s->last->info->name,"format"))
     359        new = af_prepend(s,s->last,"channels");
     360      else
     361        new = af_append(s,s->last,"channels");
     362      // Init the new filter
     363      if(NULL == new)
     364        return AF_ERROR;
     365      if(AF_OK != (rv = new->control(new,AF_CONTROL_CHANNELS,&(s->output.nch))))
     366        return rv;
     367      if(AF_OK != (rv = af_reinit(s,new)))
     368        return rv;
     369    }
     370
     371    // Check output format fix if not OK
     372    if(s->output.format != AF_FORMAT_UNKNOWN &&
     373       s->last->data->format != s->output.format){
     374      if(strcmp(s->last->info->name,"format")){
     375        if(NULL == (new = af_append(s,s->last,"format")))
     376          return AF_ERROR;
     377      }
     378      else
     379        new = s->last;
     380      // Set output bits per sample
     381      s->output.format |= af_bits2fmt(s->output.bps*8);
     382      if(AF_OK != (rv = new->control(new,AF_CONTROL_FORMAT_FMT,&(s->output.format))))
     383        return rv;
     384      if(AF_OK != (rv = af_reinit(s, new)))
     385        return rv;
     386    }
     387  }
     388
    353389  return AF_OK;
    354390}
    355391
     
    455491        return -1;
    456492    }
    457493
    458     // Check number of output channels fix if not OK
    459     // If needed always inserted last -> easy to screw up other filters
    460     if(s->output.nch && s->last->data->nch!=s->output.nch){
    461       if(!strcmp(s->last->info->name,"format"))
    462         af = af_prepend(s,s->last,"channels");
    463       else
    464         af = af_append(s,s->last,"channels");
    465       // Init the new filter
    466       if(!af || (AF_OK != af->control(af,AF_CONTROL_CHANNELS,&(s->output.nch))))
    467         return -1;
    468       if(AF_OK != af_reinit(s,af))
    469         return -1;
    470     }
    471 
    472     // Check output format fix if not OK
    473     if(s->output.format != AF_FORMAT_UNKNOWN &&
    474                 s->last->data->format != s->output.format){
    475       if(strcmp(s->last->info->name,"format"))
    476         af = af_append(s,s->last,"format");
    477       else
    478         af = s->last;
    479       // Init the new filter
    480       s->output.format |= af_bits2fmt(s->output.bps*8);
    481       if(!af || (AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT,&(s->output.format))))
    482         return -1;
    483       if(AF_OK != af_reinit(s,af))
    484         return -1;
    485     }
    486 
    487494    // Re init again just in case
    488495    if(AF_OK != af_reinit(s,s->first))
    489496      return -1;