1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avresample: Add avresample_get_out_samples

Utility function to get the upper bound on the number of samples the
resampler would output.
This commit is contained in:
Luca Barbato 2014-04-30 19:56:05 +02:00
parent c94e2e85cb
commit b2d4565422
4 changed files with 42 additions and 8 deletions

View File

@ -13,6 +13,9 @@ libavutil: 2013-12-xx
API changes, most recent first: API changes, most recent first:
2014-04-xx - xxxxxxx - lavr 1.3.0 - avresample.h
Add avresample_max_output_samples
2014-05-24 - xxxxxxx - lavf 55.19.0 - avformat.h 2014-05-24 - xxxxxxx - lavf 55.19.0 - avformat.h
Add strict_std_compliance and related AVOptions to support experimental Add strict_std_compliance and related AVOptions to support experimental
muxing. muxing.

View File

@ -76,9 +76,8 @@
* while (get_input(&input, &in_linesize, &in_samples)) { * while (get_input(&input, &in_linesize, &in_samples)) {
* uint8_t *output * uint8_t *output
* int out_linesize; * int out_linesize;
* int out_samples = avresample_available(avr) + * int out_samples = avresample_get_out_samples(avr, in_samples);
* av_rescale_rnd(avresample_get_delay(avr) + *
* in_samples, 44100, 48000, AV_ROUND_UP);
* av_samples_alloc(&output, &out_linesize, 2, out_samples, * av_samples_alloc(&output, &out_linesize, 2, out_samples,
* AV_SAMPLE_FMT_S16, 0); * AV_SAMPLE_FMT_S16, 0);
* out_samples = avresample_convert(avr, &output, out_linesize, out_samples, * out_samples = avresample_convert(avr, &output, out_linesize, out_samples,
@ -97,6 +96,7 @@
#include "libavutil/channel_layout.h" #include "libavutil/channel_layout.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "libavutil/log.h" #include "libavutil/log.h"
#include "libavutil/mathematics.h"
#include "libavresample/version.h" #include "libavresample/version.h"
@ -312,12 +312,24 @@ int avresample_set_channel_mapping(AVAudioResampleContext *avr,
int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta, int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta,
int compensation_distance); 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_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples);
/** /**
* Convert input samples and write them to the output FIFO. * Convert input samples and write them to the output FIFO.
* *
* The upper bound on the number of output samples is given by * The upper bound on the number of output samples can be obtained through
* avresample_available() + (avresample_get_delay() + number of input samples) * * avresample_get_out_samples().
* output sample rate / input sample rate.
* *
* The output data can be NULL or have fewer allocated samples than required. * 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 * 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,
* samples. To get this data as output, either call avresample_convert() with * samples. To get this data as output, either call avresample_convert() with
* NULL input or call avresample_read(). * NULL input or call avresample_read().
* *
* @see avresample_available() * @see avresample_get_out_samples()
* @see avresample_read() * @see avresample_read()
* @see avresample_get_delay() * @see avresample_get_delay()
* *

View File

@ -622,6 +622,25 @@ int avresample_available(AVAudioResampleContext *avr)
return av_audio_fifo_size(avr->out_fifo); return av_audio_fifo_size(avr->out_fifo);
} }
int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples)
{
int64_t samples = avresample_get_delay(avr) + (int64_t)in_nb_samples;
if (avr->resample_needed) {
samples = av_rescale_rnd(samples,
avr->out_sample_rate,
avr->in_sample_rate,
AV_ROUND_UP);
}
samples += avresample_available(avr);
if (samples > INT_MAX)
return AVERROR(EINVAL);
return samples;
}
int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples) int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples)
{ {
if (!output) if (!output)

View File

@ -28,7 +28,7 @@
#include "libavutil/version.h" #include "libavutil/version.h"
#define LIBAVRESAMPLE_VERSION_MAJOR 1 #define LIBAVRESAMPLE_VERSION_MAJOR 1
#define LIBAVRESAMPLE_VERSION_MINOR 2 #define LIBAVRESAMPLE_VERSION_MINOR 3
#define LIBAVRESAMPLE_VERSION_MICRO 0 #define LIBAVRESAMPLE_VERSION_MICRO 0
#define LIBAVRESAMPLE_VERSION_INT AV_VERSION_INT(LIBAVRESAMPLE_VERSION_MAJOR, \ #define LIBAVRESAMPLE_VERSION_INT AV_VERSION_INT(LIBAVRESAMPLE_VERSION_MAJOR, \