diff options
author | wm4 <wm4@nowhere> | 2017-09-29 17:54:21 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-09-29 18:17:51 +0200 |
commit | d462a2a32139ea48b63d884d5e991584babbe76a (patch) | |
tree | 6120aeaea62e9262b4cc6d2ce9356a9e346a64a4 /video/mp_image_pool.c | |
parent | 1f79b2652924cec703627edc92abff4d349aec26 (diff) | |
download | mpv-d462a2a32139ea48b63d884d5e991584babbe76a.tar.bz2 mpv-d462a2a32139ea48b63d884d5e991584babbe76a.tar.xz |
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.)
Diffstat (limited to 'video/mp_image_pool.c')
-rw-r--r-- | video/mp_image_pool.c | 34 |
1 files changed, 34 insertions, 0 deletions
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; +} |