summaryrefslogtreecommitdiff
path: root/libswresample
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2012-01-09 01:42:38 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-01-09 04:16:06 +0100
commit741aca793623afeff1d18816f416cc65104b7ef9 (patch)
tree50059d3289edecf10112d626c4c821c72847c440 /libswresample
parent3e9668501dea070c0a1bd6c721eab1af09b26339 (diff)
libswresample: introduce int swr_set_compensation() instead of void swr_compensate()
The new version returns AVERROR(EINVAL) is the specified paramters are invalid, and also creates the resampler if none was used so far. Signed-off-by: Marton Balint <cus@passwd.hu> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswresample')
-rw-r--r--libswresample/resample.c24
-rw-r--r--libswresample/swresample.h4
2 files changed, 22 insertions, 6 deletions
diff --git a/libswresample/resample.c b/libswresample/resample.c
index 9b582eac84..2960a35745 100644
--- a/libswresample/resample.c
+++ b/libswresample/resample.c
@@ -245,11 +245,27 @@ void swri_resample_free(ResampleContext **c){
av_freep(c);
}
-void swr_compensate(struct SwrContext *s, int sample_delta, int compensation_distance){
- ResampleContext *c= s->resample;
-// sample_delta += (c->ideal_dst_incr - c->dst_incr)*(int64_t)c->compensation_distance / c->ideal_dst_incr;
+int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance){
+ ResampleContext *c;
+ int ret;
+
+ if (!s || compensation_distance < 0)
+ return AVERROR(EINVAL);
+ if (!compensation_distance && sample_delta)
+ return AVERROR(EINVAL);
+ if (!s->resample) {
+ s->flags |= SWR_FLAG_RESAMPLE;
+ ret = swr_init(s);
+ if (ret < 0)
+ return ret;
+ }
+ c= s->resample;
c->compensation_distance= compensation_distance;
- c->dst_incr = c->ideal_dst_incr - c->ideal_dst_incr * (int64_t)sample_delta / compensation_distance;
+ if (compensation_distance)
+ c->dst_incr = c->ideal_dst_incr - c->ideal_dst_incr * (int64_t)sample_delta / compensation_distance;
+ else
+ c->dst_incr = c->ideal_dst_incr;
+ return 0;
}
int swri_resample(ResampleContext *c, int16_t *dst, const int16_t *src, int *consumed, int src_size, int dst_size, int update_ctx){
diff --git a/libswresample/swresample.h b/libswresample/swresample.h
index 5b9eed926f..8dc4e1f348 100644
--- a/libswresample/swresample.h
+++ b/libswresample/swresample.h
@@ -30,7 +30,7 @@
#include "libavutil/samplefmt.h"
#define LIBSWRESAMPLE_VERSION_MAJOR 0
-#define LIBSWRESAMPLE_VERSION_MINOR 5
+#define LIBSWRESAMPLE_VERSION_MINOR 6
#define LIBSWRESAMPLE_VERSION_MICRO 100
#define LIBSWRESAMPLE_VERSION_INT AV_VERSION_INT(LIBSWRESAMPLE_VERSION_MAJOR, \
@@ -114,7 +114,7 @@ int swr_convert(struct SwrContext *s, uint8_t *out[SWR_CH_MAX], int out_count,
/**
* Activate resampling compensation.
*/
-void swr_compensate(struct SwrContext *s, int sample_delta, int compensation_distance);
+int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance);
/**
* Set a customized input channel mapping.