| @@ -76,9 +76,8 @@ · 75 unmodified lines |
| 76 | 76 | * while (get_input(&input, &in_linesize, &in_samples)) { |
| 77 | 77 | * uint8_t *output |
| 78 | 78 | * int out_linesize; |
| 79 | | − * int out_samples = avresample_available(avr) + |
| 80 | | − * av_rescale_rnd(avresample_get_delay(avr) + |
| 81 | | − * in_samples, 44100, 48000, AV_ROUND_UP); |
| 79 | + * int out_samples = avresample_get_out_samples(avr, in_samples); |
| 80 | + * |
| 82 | 81 | * av_samples_alloc(&output, &out_linesize, 2, out_samples, |
| 83 | 82 | * AV_SAMPLE_FMT_S16, 0); |
| 84 | 83 | * out_samples = avresample_convert(avr, &output, out_linesize, out_samples, |
| @@ -97,6 +96,7 @@ · 12 unmodified lines |
| 97 | 96 | #include "libavutil/channel_layout.h" |
| 98 | 97 | #include "libavutil/dict.h" |
| 99 | 98 | #include "libavutil/log.h" |
| 99 | +#include "libavutil/mathematics.h" |
| 100 | 100 | |
| 101 | 101 | #include "libavresample/version.h" |
| 102 | 102 | |
| @@ -312,12 +312,24 @@ int avresample_set_channel_mapping(AVAudioResampleContext *avr, · 209 unmodified lines |
| 312 | 312 | int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta, |
| 313 | 313 | int compensation_distance); |
| 314 | 314 | |
| 315 | +/** |
| 316 | + * Provide the upper bound on the number of samples the configured |
| 317 | + * conversion would output. |
| 318 | + * |
| 319 | + * @param avr audio resample context |
| 320 | + * @param in_nb_samples number of input samples |
| 321 | + * |
| 322 | + * @return number of samples or AVERROR(EINVAL) if the value |
| 323 | + * would exceed INT_MAX |
| 324 | + */ |
| 325 | + |
| 326 | +int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples); |
| 327 | + |
| 315 | 328 | /** |
| 316 | 329 | * Convert input samples and write them to the output FIFO. |
| 317 | 330 | * |
| 318 | | − * The upper bound on the number of output samples is given by |
| 319 | | − * avresample_available() + (avresample_get_delay() + number of input samples) * |
| 320 | | − * output sample rate / input sample rate. |
| 331 | + * The upper bound on the number of output samples can be obtained through |
| 332 | + * avresample_get_out_samples(). |
| 321 | 333 | * |
| 322 | 334 | * The output data can be NULL or have fewer allocated samples than required. |
| 323 | 335 | * In this case, any remaining samples not written to the output will be added |
| @@ -334,7 +346,7 @@ int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta, · 10 unmodified lines |
| 334 | 346 | * samples. To get this data as output, either call avresample_convert() with |
| 335 | 347 | * NULL input or call avresample_read(). |
| 336 | 348 | * |
| 337 | | − * @see avresample_available() |
| 349 | + * @see avresample_get_out_samples() |
| 338 | 350 | * @see avresample_read() |
| 339 | 351 | * @see avresample_get_delay() |
| 340 | 352 | * |