[FFmpeg-devel] [PATCH] libswresample: introduce int swr_set_compensation() instead of void swr_compensate()
Marton Balint
cus at passwd.hu
Mon Jan 9 01:42:38 CET 2012
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 at passwd.hu>
---
ffmpeg.c | 2 +-
libswresample/resample.c | 24 ++++++++++++++++++++----
libswresample/swresample.h | 4 ++--
3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/ffmpeg.c b/ffmpeg.c
index 13d7d6c..a13e33a 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1160,7 +1160,7 @@ need_realloc:
av_log(NULL, AV_LOG_VERBOSE, "compensating audio timestamp drift:%f compensation:%d in:%d\n",
delta, comp, enc->sample_rate);
// fprintf(stderr, "drift:%f len:%d opts:%"PRId64" ipts:%"PRId64" fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(ost->fifo)/(ost->st->codec->channels * 2));
- swr_compensate(ost->swr, comp, enc->sample_rate);
+ swr_set_compensation(ost->swr, comp, enc->sample_rate);
}
}
} else
diff --git a/libswresample/resample.c b/libswresample/resample.c
index 9b582ea..2960a35 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 5b9eed9..8dc4e1f 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.
--
1.7.3.4
More information about the ffmpeg-devel
mailing list