[FFmpeg-devel] [PATCH v2 2/2] lavf/qsv: clone the frame which may be managed by framework
Ruiling Song
ruiling.song at intel.com
Tue Apr 3 04:50:20 EEST 2018
For filters based on framesync, the input frame was managed
by framesync, so we should not directly keep and destroy it,
instead we make a clone of it here, or else double-free will occur.
But for other filters not based on framesync, we still need to
free the input frame inside filter_frame. That's why I made
this v2 to fix the side-effect on normal filters.
v2:
and one av_frame_free() in vf_vpp_qsv.c
Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
libavfilter/qsvvpp.c | 4 ++--
libavfilter/vf_vpp_qsv.c | 5 ++++-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index f32b46d..86787c5 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -296,7 +296,7 @@ static QSVFrame *submit_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *p
av_log(ctx, AV_LOG_ERROR, "QSVVPP gets a wrong frame.\n");
return NULL;
}
- qsv_frame->frame = picref;
+ qsv_frame->frame = av_frame_clone(picref);
qsv_frame->surface = (mfxFrameSurface1 *)qsv_frame->frame->data[3];
} else {
/* make a copy if the input is not padded as libmfx requires */
@@ -318,7 +318,7 @@ static QSVFrame *submit_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *p
av_frame_copy_props(qsv_frame->frame, picref);
av_frame_free(&picref);
} else
- qsv_frame->frame = picref;
+ qsv_frame->frame = av_frame_clone(picref);
if (map_frame_to_surface(qsv_frame->frame,
&qsv_frame->surface_internal) < 0) {
diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index bd5fc32..4ef5bfb 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -326,8 +326,11 @@ static int config_output(AVFilterLink *outlink)
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
{
VPPContext *vpp = inlink->dst->priv;
+ int ret = 0;
- return ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
+ ret = ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
+ av_frame_free(&picref);
+ return ret;
}
static int query_formats(AVFilterContext *ctx)
--
2.7.4
More information about the ffmpeg-devel
mailing list