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
13 13
14API changes, most recent first:14API changes, most recent first:
15 15
162014-04-xx - xxxxxxx - lavr 1.3.0 - avresample.h
17 Add avresample_max_output_samples
18
162014-05-24 - xxxxxxx - lavf 55.19.0 - avformat.h192014-05-24 - xxxxxxx - lavf 55.19.0 - avformat.h
17 Add strict_std_compliance and related AVOptions to support experimental20 Add strict_std_compliance and related AVOptions to support experimental
18 muxing.21 muxing.
libavresample/avresample.h+19−7
@@ -76,9 +76,8 @@ · 75 unmodified lines
76 * while (get_input(&input, &in_linesize, &in_samples)) {76 * while (get_input(&input, &in_linesize, &in_samples)) {
77 * uint8_t *output77 * uint8_t *output
78 * int out_linesize;78 * int out_linesize;
79 * int out_samples = avresample_available(avr) +79 * int out_samples = avresample_get_out_samples(avr, in_samples);
80 * av_rescale_rnd(avresample_get_delay(avr) +80 *
81 * in_samples, 44100, 48000, AV_ROUND_UP);
82 * av_samples_alloc(&output, &out_linesize, 2, out_samples,81 * av_samples_alloc(&output, &out_linesize, 2, out_samples,
83 * AV_SAMPLE_FMT_S16, 0);82 * AV_SAMPLE_FMT_S16, 0);
84 * out_samples = avresample_convert(avr, &output, out_linesize, out_samples,83 * out_samples = avresample_convert(avr, &output, out_linesize, out_samples,
@@ -97,6 +96,7 @@ · 12 unmodified lines
97#include "libavutil/channel_layout.h"96#include "libavutil/channel_layout.h"
98#include "libavutil/dict.h"97#include "libavutil/dict.h"
99#include "libavutil/log.h"98#include "libavutil/log.h"
99#include "libavutil/mathematics.h"
100 100
101#include "libavresample/version.h"101#include "libavresample/version.h"
102 102
@@ -312,12 +312,24 @@ int avresample_set_channel_mapping(AVAudioResampleContext *avr, · 209 unmodified lines
312int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta,312int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta,
313 int compensation_distance);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
326int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples);
327
315/**328/**
316 * Convert input samples and write them to the output FIFO.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 by331 * The upper bound on the number of output samples can be obtained through
319 * avresample_available() + (avresample_get_delay() + number of input samples) *332 * avresample_get_out_samples().
320 * output sample rate / input sample rate.
321 *333 *
322 * The output data can be NULL or have fewer allocated samples than required.334 * The output data can be NULL or have fewer allocated samples than required.
323 * In this case, any remaining samples not written to the output will be added335 * 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 * samples. To get this data as output, either call avresample_convert() with346 * samples. To get this data as output, either call avresample_convert() with
335 * NULL input or call avresample_read().347 * NULL input or call avresample_read().
336 *348 *
337 * @see avresample_available()349 * @see avresample_get_out_samples()
338 * @see avresample_read()350 * @see avresample_read()
339 * @see avresample_get_delay()351 * @see avresample_get_delay()
340 *352 *
libavresample/utils.c+19−0
@@ -622,6 +622,25 @@ int avresample_available(AVAudioResampleContext *avr) · 621 unmodified lines
622 return av_audio_fifo_size(avr->out_fifo);622 return av_audio_fifo_size(avr->out_fifo);
623}623}
624 624
625int 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
625int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples)644int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples)
626{645{
627 if (!output)646 if (!output)
libavresample/version.h+1−1
@@ -28,7 +28,7 @@ · 27 unmodified lines
28#include "libavutil/version.h"28#include "libavutil/version.h"
29 29
30#define LIBAVRESAMPLE_VERSION_MAJOR 130#define LIBAVRESAMPLE_VERSION_MAJOR 1
31#define LIBAVRESAMPLE_VERSION_MINOR 231#define LIBAVRESAMPLE_VERSION_MINOR 3
32#define LIBAVRESAMPLE_VERSION_MICRO 032#define LIBAVRESAMPLE_VERSION_MICRO 0
33 33
34#define LIBAVRESAMPLE_VERSION_INT AV_VERSION_INT(LIBAVRESAMPLE_VERSION_MAJOR, \34#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