aboutsummaryrefslogtreecommitdiffstats
path: root/libavresample
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-05-29 01:18:17 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-05-29 01:23:22 +0200
commitbdb2e80e88e76cc39c6d85a8f1c1712d36e18966 (patch)
tree230646af1610b055a198af67574b1d823fc50d76 /libavresample
parenta8499cbbe87d00456c391f41207e1981bd7f746a (diff)
parentb2d45654220503224aa94e78cdff19ec624e9342 (diff)
downloadandroid_external_ffmpeg-bdb2e80e88e76cc39c6d85a8f1c1712d36e18966.tar.gz
android_external_ffmpeg-bdb2e80e88e76cc39c6d85a8f1c1712d36e18966.tar.bz2
android_external_ffmpeg-bdb2e80e88e76cc39c6d85a8f1c1712d36e18966.zip
Merge commit 'b2d45654220503224aa94e78cdff19ec624e9342'
* commit 'b2d45654220503224aa94e78cdff19ec624e9342': avresample: Add avresample_get_out_samples Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavresample')
-rw-r--r--libavresample/avresample.h26
-rw-r--r--libavresample/utils.c19
-rw-r--r--libavresample/version.h2
3 files changed, 39 insertions, 8 deletions
diff --git a/libavresample/avresample.h b/libavresample/avresample.h
index dc392ad076..6e3cf35fd4 100644
--- a/libavresample/avresample.h
+++ b/libavresample/avresample.h
@@ -76,9 +76,8 @@
* while (get_input(&input, &in_linesize, &in_samples)) {
* uint8_t *output
* int out_linesize;
- * int out_samples = avresample_available(avr) +
- * av_rescale_rnd(avresample_get_delay(avr) +
- * in_samples, 44100, 48000, AV_ROUND_UP);
+ * int out_samples = avresample_get_out_samples(avr, in_samples);
+ *
* av_samples_alloc(&output, &out_linesize, 2, out_samples,
* AV_SAMPLE_FMT_S16, 0);
* out_samples = avresample_convert(avr, &output, out_linesize, out_samples,
@@ -97,6 +96,7 @@
#include "libavutil/channel_layout.h"
#include "libavutil/dict.h"
#include "libavutil/log.h"
+#include "libavutil/mathematics.h"
#include "libavresample/version.h"
@@ -313,11 +313,23 @@ 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_get_out_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_get_out_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 +346,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_get_out_samples()
* @see avresample_read()
* @see avresample_get_delay()
*
diff --git a/libavresample/utils.c b/libavresample/utils.c
index 3a335c0587..48874d6103 100644
--- a/libavresample/utils.c
+++ b/libavresample/utils.c
@@ -622,6 +622,25 @@ int avresample_available(AVAudioResampleContext *avr)
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)
{
if (!output)
diff --git a/libavresample/version.h b/libavresample/version.h
index d865ad2d23..0431badf5e 100644
--- a/libavresample/version.h
+++ b/libavresample/version.h
@@ -28,7 +28,7 @@
#include "libavutil/version.h"
#define LIBAVRESAMPLE_VERSION_MAJOR 1
-#define LIBAVRESAMPLE_VERSION_MINOR 2
+#define LIBAVRESAMPLE_VERSION_MINOR 3
#define LIBAVRESAMPLE_VERSION_MICRO 0
#define LIBAVRESAMPLE_VERSION_INT AV_VERSION_INT(LIBAVRESAMPLE_VERSION_MAJOR, \