This avoids creating unwieldy large packets, which is allowed but
does not seem to be a good idea
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -41,6 +41,7 @@ typedef struct { |
41 | 41 |
struct SwrContext *swr; |
42 | 42 |
int64_t next_pts; |
43 | 43 |
int req_fullfilled; |
44 |
+ int more_data; |
|
44 | 45 |
} AResampleContext; |
45 | 46 |
|
46 | 47 |
static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts) |
... | ... |
@@ -186,7 +187,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) |
186 | 186 |
|
187 | 187 |
delay = swr_get_delay(aresample->swr, outlink->sample_rate); |
188 | 188 |
if (delay > 0) |
189 |
- n_out += delay; |
|
189 |
+ n_out += FFMIN(delay, FFMAX(4096, n_out)); |
|
190 | 190 |
|
191 | 191 |
outsamplesref = ff_get_audio_buffer(outlink, n_out); |
192 | 192 |
|
... | ... |
@@ -215,6 +216,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) |
215 | 215 |
return 0; |
216 | 216 |
} |
217 | 217 |
|
218 |
+ aresample->more_data = outsamplesref->nb_samples == n_out; // Indicate that there is probably more data in our buffers |
|
219 |
+ |
|
218 | 220 |
outsamplesref->nb_samples = n_out; |
219 | 221 |
|
220 | 222 |
ret = ff_filter_frame(outlink, outsamplesref); |
... | ... |
@@ -261,11 +264,23 @@ static int request_frame(AVFilterLink *outlink) |
261 | 261 |
AVFilterLink *const inlink = outlink->src->inputs[0]; |
262 | 262 |
int ret; |
263 | 263 |
|
264 |
+ // First try to get data from the internal buffers |
|
265 |
+ if (aresample->more_data) { |
|
266 |
+ AVFrame *outsamplesref; |
|
267 |
+ |
|
268 |
+ if (flush_frame(outlink, 0, &outsamplesref) >= 0) { |
|
269 |
+ return ff_filter_frame(outlink, outsamplesref); |
|
270 |
+ } |
|
271 |
+ } |
|
272 |
+ aresample->more_data = 0; |
|
273 |
+ |
|
274 |
+ // Second request more data from the input |
|
264 | 275 |
aresample->req_fullfilled = 0; |
265 | 276 |
do{ |
266 | 277 |
ret = ff_request_frame(ctx->inputs[0]); |
267 | 278 |
}while(!aresample->req_fullfilled && ret>=0); |
268 | 279 |
|
280 |
+ // Third if we hit the end flush |
|
269 | 281 |
if (ret == AVERROR_EOF) { |
270 | 282 |
AVFrame *outsamplesref; |
271 | 283 |
|