Modifying data pointer when skipping samples may make it unaligned. Workaround for Ticket6349. This should fix the crash of ticket's testcase and a crash/regression with avxsynth (reported by Michael Niedermayer). Also change frame->nb_samples < max to frame->nb_samples <= max. This improves performance. Benchmark: ./ffmpeg -filter_complex "aevalsrc=0:n=1166,firequalizer=fixed=on" -f null null old: 25767 decicycles in take_samples, 1023 runs, 1 skips 25422 decicycles in take_samples, 2047 runs, 1 skips 25181 decicycles in take_samples, 4095 runs, 1 skips 24904 decicycles in take_samples, 8191 runs, 1 skips new: 550 decicycles in take_samples, 1024 runs, 0 skips 548 decicycles in take_samples, 2048 runs, 0 skips 545 decicycles in take_samples, 4096 runs, 0 skips 544 decicycles in take_samples, 8192 runs, 0 skips
Showing the changes to libavfilter/avfilter.c (1 of 3 files). Show all
Unified · Split
| @@ -1191,7 +1191,7 @@ static int take_samples(AVFilterLink *link, unsigned min, unsigned max, · 1190 unmodified lines | ||
| 1191 | 1191 | called with enough samples. */ |
| 1192 | 1192 | av_assert1(samples_ready(link, link->min_samples)); |
| 1193 | 1193 | frame0 = frame = ff_framequeue_peek(&link->fifo, 0); |
| 1194 | − if (frame->nb_samples >= min && frame->nb_samples < max) { | |
| 1194 | + if (!link->fifo.samples_skipped && frame->nb_samples >= min && frame->nb_samples <= max) { | |
| 1195 | 1195 | *rframe = ff_framequeue_take(&link->fifo); |
| 1196 | 1196 | return 0; |
| 1197 | 1197 | } |
| @@ -1522,6 +1522,12 @@ int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe) · 324 unmodified lines | ||
| 1522 | 1522 | *rframe = NULL; |
| 1523 | 1523 | if (!ff_inlink_check_available_frame(link)) |
| 1524 | 1524 | return 0; |
| 1525 | + | |
| 1526 | + if (link->fifo.samples_skipped) { | |
| 1527 | + frame = ff_framequeue_peek(&link->fifo, 0); | |
| 1528 | + return ff_inlink_consume_samples(link, frame->nb_samples, frame->nb_samples, rframe); | |
| 1529 | + } | |
| 1530 | + | |
| 1525 | 1531 | frame = ff_framequeue_take(&link->fifo); |
| 1526 | 1532 | consume_update(link, frame); |
| 1527 | 1533 | *rframe = frame; |