History

avresample: Add avresample_get_out_samples

Utility function to get the upper bound on the number of samples the resampler would output.

Luca Barbato committed 12 years ago

Commit b2d45651 parent c94e2e84 files · +42 −8Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavresample/avresample.h +19 −7
  3. libavresample/utils.c +19 −0
  4. libavresample/version.h +1 −1
doc/APIchanges+3−0
@@ -13,6 +13,9 @@ libavutil: 2013-12-xx · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2014-04-xx - xxxxxxx - lavr 1.3.0 - avresample.h
17+ Add avresample_max_output_samples
18+
1619 2014-05-24 - xxxxxxx - lavf 55.19.0 - avformat.h
1720 Add strict_std_compliance and related AVOptions to support experimental
1821 muxing.
libavresample/avresample.h+19−7
@@ -76,9 +76,8 @@ · 75 unmodified lines
7676 * while (get_input(&input, &in_linesize, &in_samples)) {
7777 * uint8_t *output
7878 * 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+ *
8281 * av_samples_alloc(&output, &out_linesize, 2, out_samples,
8382 * AV_SAMPLE_FMT_S16, 0);
8483 * out_samples = avresample_convert(avr, &output, out_linesize, out_samples,
@@ -97,6 +96,7 @@ · 12 unmodified lines
9796 #include "libavutil/channel_layout.h"
9897 #include "libavutil/dict.h"
9998 #include "libavutil/log.h"
99+#include "libavutil/mathematics.h"
100100
101101 #include "libavresample/version.h"
102102
@@ -312,12 +312,24 @@ int avresample_set_channel_mapping(AVAudioResampleContext *avr, · 209 unmodified lines
312312 int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta,
313313 int compensation_distance);
314314
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+
315328 /**
316329 * Convert input samples and write them to the output FIFO.
317330 *
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().
321333 *
322334 * The output data can be NULL or have fewer allocated samples than required.
323335 * 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
334346 * samples. To get this data as output, either call avresample_convert() with
335347 * NULL input or call avresample_read().
336348 *
337− * @see avresample_available()
349+ * @see avresample_get_out_samples()
338350 * @see avresample_read()
339351 * @see avresample_get_delay()
340352 *
libavresample/utils.c+19−0
@@ -622,6 +622,25 @@ int avresample_available(AVAudioResampleContext *avr) · 621 unmodified lines
622622 return av_audio_fifo_size(avr->out_fifo);
623623 }
624624
625+int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples)
626+{
627+ int64_t samples = avresample_get_delay(avr) + (int64_t)in_nb_samples;
628+
629+ if (avr->resample_needed) {
630+ samples = av_rescale_rnd(samples,
631+ avr->out_sample_rate,
632+ avr->in_sample_rate,
633+ AV_ROUND_UP);
634+ }
635+
636+ samples += avresample_available(avr);
637+
638+ if (samples > INT_MAX)
639+ return AVERROR(EINVAL);
640+
641+ return samples;
642+}
643+
625644 int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples)
626645 {
627646 if (!output)
libavresample/version.h+1−1
@@ -28,7 +28,7 @@ · 27 unmodified lines
2828 #include "libavutil/version.h"
2929
3030 #define LIBAVRESAMPLE_VERSION_MAJOR 1
31−#define LIBAVRESAMPLE_VERSION_MINOR 2
31+#define LIBAVRESAMPLE_VERSION_MINOR 3
3232 #define LIBAVRESAMPLE_VERSION_MICRO 0
3333
3434 #define LIBAVRESAMPLE_VERSION_INT AV_VERSION_INT(LIBAVRESAMPLE_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t