aboutsummaryrefslogtreecommitdiffstats
path: root/libavresample
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-04-13 14:00:20 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-04-13 14:03:02 +0200
commitcbfa71d689a193b7f327dceb6320ab09497757da (patch)
treeec8b64b10c82d1df6ef387aa72ec3d0f6bc9bfc8 /libavresample
parent7e6b3ad6930c2f1daa5c4831bbeda3fb931921e6 (diff)
parentf7c5fd81516fb7b186c64c66dc080e1139586226 (diff)
downloadffmpeg-cbfa71d689a193b7f327dceb6320ab09497757da.tar.gz
Merge commit 'f7c5fd81516fb7b186c64c66dc080e1139586226'
* commit 'f7c5fd81516fb7b186c64c66dc080e1139586226': resample: implement flushing Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavresample')
-rw-r--r--libavresample/resample.c46
1 files changed, 39 insertions, 7 deletions
diff --git a/libavresample/resample.c b/libavresample/resample.c
index 79275950b1..7eb14c0836 100644
--- a/libavresample/resample.c
+++ b/libavresample/resample.c
@@ -52,6 +52,8 @@ struct ResampleContext {
int padding_size;
int initial_padding_filled;
int initial_padding_samples;
+ int final_padding_filled;
+ int final_padding_samples;
};
@@ -433,27 +435,57 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
ret = ff_audio_data_combine(c->buffer, in_leftover, src, 0, in_samples);
if (ret < 0)
return ret;
- } else if (!in_leftover) {
+ } else if (in_leftover <= c->final_padding_samples) {
/* no remaining samples to flush */
return 0;
- } else {
- /* TODO: pad buffer to flush completely */
}
if (!c->initial_padding_filled) {
int bps = av_get_bytes_per_sample(c->avr->internal_sample_fmt);
int i;
- if (c->buffer->nb_samples < 2 * c->padding_size)
+ if (src && c->buffer->nb_samples < 2 * c->padding_size)
return 0;
for (i = 0; i < c->padding_size; i++)
- for (ch = 0; ch < c->buffer->channels; ch++)
- memcpy(c->buffer->data[ch] + bps * i,
- c->buffer->data[ch] + bps * (2 * c->padding_size - i), bps);
+ for (ch = 0; ch < c->buffer->channels; ch++) {
+ if (c->buffer->nb_samples > 2 * c->padding_size - i) {
+ memcpy(c->buffer->data[ch] + bps * i,
+ c->buffer->data[ch] + bps * (2 * c->padding_size - i), bps);
+ } else {
+ memset(c->buffer->data[ch] + bps * i, 0, bps);
+ }
+ }
c->initial_padding_filled = 1;
}
+ if (!src && !c->final_padding_filled) {
+ int bps = av_get_bytes_per_sample(c->avr->internal_sample_fmt);
+ int i;
+
+ ret = ff_audio_data_realloc(c->buffer, in_samples + c->padding_size);
+ if (ret < 0) {
+ av_log(c->avr, AV_LOG_ERROR, "Error reallocating resampling buffer\n");
+ return AVERROR(ENOMEM);
+ }
+
+ for (i = 0; i < c->padding_size; i++)
+ for (ch = 0; ch < c->buffer->channels; ch++) {
+ if (in_leftover > i) {
+ memcpy(c->buffer->data[ch] + bps * (in_leftover + i),
+ c->buffer->data[ch] + bps * (in_leftover - i - 1),
+ bps);
+ } else {
+ memset(c->buffer->data[ch] + bps * (in_leftover + i),
+ 0, bps);
+ }
+ }
+ c->buffer->nb_samples += c->padding_size;
+ c->final_padding_samples = c->padding_size;
+ c->final_padding_filled = 1;
+ }
+
+
/* calculate output size and reallocate output buffer if needed */
/* TODO: try to calculate this without the dummy resample() run */
if (!dst->read_only && dst->allow_realloc) {