From d462a2a32139ea48b63d884d5e991584babbe76a Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 29 Sep 2017 17:54:21 +0200 Subject: vf_vavpp: use libavutil hw frames API for frame pool and upload Another step to get rid of the legacy crap in vaapi.c. (Most is still kept, because it's in use by vo_vaapi.c.) --- video/mp_image_pool.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'video/mp_image_pool.c') diff --git a/video/mp_image_pool.c b/video/mp_image_pool.c index 9a848af925..e993b4e096 100644 --- a/video/mp_image_pool.c +++ b/video/mp_image_pool.c @@ -309,3 +309,37 @@ struct mp_image *mp_image_hw_download(struct mp_image *src, } return dst; } + +bool mp_image_hw_upload(struct mp_image *hw_img, struct mp_image *src) +{ + if (hw_img->w != src->w || hw_img->h != src->h) + return false; + + if (!hw_img->hwctx || src->hwctx) + return false; + + bool ok = false; + AVFrame *dstav = NULL; + AVFrame *srcav = NULL; + + // This means the destination image will not be "writable", which would be + // a pain if Libav enforced this - fortunately it doesn't care. We can + // transfer data to it even if there are multiple refs. + dstav = mp_image_to_av_frame(hw_img); + if (!dstav) + goto done; + + srcav = mp_image_to_av_frame(src); + if (!srcav) + goto done; + + ok = av_hwframe_transfer_data(dstav, srcav, 0) >= 0; + +done: + av_frame_unref(srcav); + av_frame_unref(dstav); + + if (ok) + mp_image_copy_attributes(hw_img, src); + return ok; +} -- cgit v1.2.3