[FFmpeg-devel] avfilter: do not write to unwritable frame

Submitted by Muhammad Faiz on Jan. 27, 2017, 6:12 p.m.

Details

Message ID 1485540744-13947-1-git-send-email-mfcc64@gmail.com
State New
Headers show

Commit Message

Muhammad Faiz Jan. 27, 2017, 6:12 p.m.
affect filters that set partial_buf_size
test-case
ffplay -i lavfi 'aevalsrc=sin(1000*t*t), aformat=sample_fmts=fltp, asplit [a][b];
[a] firequalizer=fixed=on, showcqt=s=1280x360 [a1];
[b] firequalizer=fixed=on, showcqt=s=1280x360 [b1];
[a1][b1] vstack'

Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
---
 libavfilter/avfilter.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index c12d491..9b28842 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -1235,6 +1235,22 @@  static int take_samples(AVFilterLink *link, unsigned min, unsigned max,
         frame = ff_framequeue_peek(&link->fifo, 0);
         av_samples_copy(buf->extended_data, frame->extended_data, p, 0, n,
                         link->channels, link->format);
+
+        if (!av_frame_is_writable(frame)) {
+            AVFrame *new = ff_get_audio_buffer(link, frame->nb_samples);
+            if (!new)
+                return AVERROR(ENOMEM);
+            ret = av_frame_copy_props(new, frame);
+            if (ret < 0) {
+                av_frame_free(&new);
+                return ret;
+            }
+            av_frame_copy(new, frame);
+            av_frame_unref(frame);
+            av_frame_move_ref(frame, new);
+            av_frame_free(&new);
+        }
+
         frame->nb_samples -= n;
         av_samples_copy(frame->extended_data, frame->extended_data, 0, n,
                         frame->nb_samples, link->channels, link->format);