Ticket #1685: af_ladspa_c_fixes.patch

File af_ladspa_c_fixes.patch, 4.5 KB (added by wbreyha@…, 16 years ago)

fix for both boundary check and crash

  • libaf/af_ladspa.c

    old new  
    5757                     *   the data unchanged.
    5858                     */
    5959
    60     int activated;  /**< 0 or 1. Activate LADSPA filters only once, even
    61                      *   if the buffers get resized, to avoid a stuttering
    62                      *   filter.
    63                      */
    64 
    6560    char *file;
    6661    char *label;
    6762
     
    9186    float **inbufs;
    9287    float **outbufs;
    9388    LADSPA_Handle *chhandles;
     89    int *activated;  /**< 0 or 1. Activate LADSPA filters only once, even
     90                      *   if the buffers get resized, to avoid a stuttering
     91                      *   filter.
     92                      */
    9493
    9594} af_ladspa_t;
    9695
     
    252251        }
    253252
    254253        if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) {
    255             mp_msg(MSGT_AFILTER, MSGL_V, "%0.2f]\n", hint.UpperBound);
     254            mp_msg(MSGT_AFILTER, MSGL_V, "%0.2f]", hint.UpperBound);
    256255        } else {
    257             mp_msg(MSGT_AFILTER, MSGL_V, "...]\n");
     256            mp_msg(MSGT_AFILTER, MSGL_V, "...]");
    258257        }
    259258
     259        if (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor)) {
     260            mp_msg(MSGT_AFILTER, MSGL_V, "*srate\n");
     261        } else {
     262            mp_msg(MSGT_AFILTER, MSGL_V, "\n");
     263        }
    260264    }
    261265
    262266    return AF_OK;
     
    615619                                setup->plugin_descriptor->PortRangeHints[p];
    616620            val = setup->inputcontrols[p];
    617621
    618             if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor) &&
    619                     val < hint.LowerBound) {
    620                 mp_msg(MSGT_AFILTER, MSGL_ERR, MSGTR_AF_LADSPA_ErrControlBelow,
    621                                             setup->myname, i, hint.LowerBound);
    622                 return AF_ERROR;
    623             }
    624             if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor) &&
    625                     val > hint.UpperBound) {
    626                 mp_msg(MSGT_AFILTER, MSGL_ERR, MSGTR_AF_LADSPA_ErrControlAbove,
    627                                             setup->myname, i, hint.UpperBound);
    628                 return AF_ERROR;
     622            if (!LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor))
     623            {
     624                if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor) &&
     625                        val < hint.LowerBound ) {
     626                    mp_msg(MSGT_AFILTER, MSGL_ERR, MSGTR_AF_LADSPA_ErrControlBelow,
     627                                                setup->myname, i, hint.LowerBound);
     628                    return AF_ERROR;
     629                }
     630                if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor) &&
     631                        val > hint.UpperBound ) {
     632                    mp_msg(MSGT_AFILTER, MSGL_ERR, MSGTR_AF_LADSPA_ErrControlAbove,
     633                                                setup->myname, i, hint.UpperBound);
     634                    return AF_ERROR;
     635                }
     636            } else {
     637                mp_msg(MSGT_AFILTER, MSGL_V, "%s: WARNING: boundaries depend on sample rate. not checked. take care\n",
     638                                                                setup->myname);
    629639            }
    630640        }
    631641        mp_msg(MSGT_AFILTER, MSGL_V, "%s: all controls have sane values\n",
     
    704714            }
    705715            free(setup->outbufs);
    706716        }
     717        if (setup->activated)
     718            free(setup->activated);
    707719
    708720        if (setup->libhandle)
    709721            dlclose(setup->libhandle);
     
    787799
    788800        if (!setup->chhandles) {
    789801            setup->chhandles = calloc(nch, sizeof(LADSPA_Handle));
     802            setup->activated = calloc(nch, sizeof(int));
    790803
    791804            /* create handles
    792805             * for stereo effects, create one handle for two channels
     
    801814                }
    802815
    803816                setup->chhandles[i] = pdes->instantiate(pdes, rate);
     817                setup->activated[i] = 0;
    804818            }
    805819        }
    806820
     
    832846                }
    833847            }
    834848
     849        mp_msg(MSGT_AFILTER, MSGL_DBG3, "%s: ch = %d, act = %d\n",
     850                                        setup->myname, i, setup->activated[i]);
    835851            /* Activate filter (if it isn't already :) ) */
    836852
    837             if ( (pdes->activate) && (setup->activated == 0) ) {
     853            if ( (pdes->activate) && (setup->activated[i] == 0) ) {
    838854                pdes->activate(setup->chhandles[i]);
    839                 setup->activated = 1;
     855                setup->activated[i] = 1;
    840856            }
    841857
    842858        } /* All channels/filters done! except for... */