On 01/05/14 11:39, wm4 wrote:
> On Wed, 30 Apr 2014 22:10:15 +0200
> Luca Barbato <[email protected]> wrote:
> 
>> Utility function to get the upper bound on the number of samples the
>> resampler would output.
>> ---
>>
>> Now also with a check for the null resampler.
>>
>>  doc/APIchanges             |  3 +++
>>  libavresample/avresample.h | 22 ++++++++++++++++++----
>>  libavresample/utils.c      | 18 ++++++++++++++++++
>>  libavresample/version.h    |  2 +-
>>  4 files changed, 40 insertions(+), 5 deletions(-)
>>
>> diff --git a/doc/APIchanges b/doc/APIchanges
>> index 28afc9b..66d3721 100644
>> --- a/doc/APIchanges
>> +++ b/doc/APIchanges
>> @@ -13,6 +13,9 @@ libavutil:     2013-12-xx
>>
>>  API changes, most recent first:
>>
>> +2014-04-xx - xxxxxxx - lavr 1.3.0 - avresample.h
>> +  Add avresample_max_output_samples
>> +
>>  2014-04-xx - xxxxxxx - lavc 55.50.0 - dxva2.h
>>    Add FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO for old Intel GPUs.
>>
>> diff --git a/libavresample/avresample.h b/libavresample/avresample.h
>> index 3358628..691c26a 100644
>> --- a/libavresample/avresample.h
>> +++ b/libavresample/avresample.h
>> @@ -313,11 +313,25 @@ int avresample_set_compensation(AVAudioResampleContext 
>> *avr, int sample_delta,
>>                                  int compensation_distance);
>>
>>  /**
>> + * Provide the upper bound on the number of samples the configured
>> + * conversion would output.
>> + *
>> + * @param avr           audio resample context
>> + * @param in_nb_samples number of input samples
>> + *
>> + * @return              number of samples or AVERROR(EINVAL) if the value
>> + *                      would exceed INT_MAX
>> + */
>> +
>> +int avresample_max_output_samples(AVAudioResampleContext *avr,
>> +                                  int in_nb_samples);
>> +
>> +
>> +/**
>>   * Convert input samples and write them to the output FIFO.
>>   *
>> - * The upper bound on the number of output samples is given by
>> - * avresample_available() + (avresample_get_delay() + number of input 
>> samples) *
>> - * output sample rate / input sample rate.
>> + * The upper bound on the number of output samples can be obtained through
>> + * avresample_max_output_samples().
>>   *
>>   * The output data can be NULL or have fewer allocated samples than 
>> required.
>>   * In this case, any remaining samples not written to the output will be 
>> added
>> @@ -334,7 +348,7 @@ int avresample_set_compensation(AVAudioResampleContext 
>> *avr, int sample_delta,
>>   * samples. To get this data as output, either call avresample_convert() 
>> with
>>   * NULL input or call avresample_read().
>>   *
>> - * @see avresample_available()
>> + * @see avresample_max_output_samples()
>>   * @see avresample_read()
>>   * @see avresample_get_delay()
>>   *
>> diff --git a/libavresample/utils.c b/libavresample/utils.c
>> index 35bee42..0ba4877 100644
>> --- a/libavresample/utils.c
>> +++ b/libavresample/utils.c
>> @@ -622,6 +622,24 @@ int avresample_available(AVAudioResampleContext *avr)
>>      return av_audio_fifo_size(avr->out_fifo);
>>  }
>>
>> +int avresample_max_output_samples(AVAudioResampleContext *avr,
>> +                                  int in_nb_samples)
>> +{
>> +    int64_t samples = avresample_get_delay(avr) + in_nb_samples;
> 
> avresample_get_delay() returns an int - so could this overflow?

Cast added locally since yesterday.

> Why not just return int64_t in the first place?

Because that value is used by functions and structs accepting ints and
I'd be tempted to reject (or clip) at a much smaller fraction of INT_MAX.

> Are the sample rates used below sanitized on initialization so they
> can't cause overflows, or can they be arbitrary?

Might be a good idea checking on avresample_open(), I wouldn't check
here though, thanks for spotting those corner cases.

lu


_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to