From 1e4fd996bb249a773bad5d57ac5b724be52a09af Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 17 Feb 2017 13:32:27 +0100 Subject: videotoolbox: factor some duplicated code The code for copying a videotoolbox surface to mp_image was duplicated (with some minor differences - I picked the hw_videotoolbox.c version, because it was "better"). mp_imgfmt_from_cvpixelformat() is somewhat duplicated with the vt_formats[] table, but this will be fixed in a later commit, and moving the function to shared code is preparation. --- video/out/opengl/hwdec_osx.c | 41 ++--------------------------------------- 1 file changed, 2 insertions(+), 39 deletions(-) (limited to 'video/out/opengl/hwdec_osx.c') diff --git a/video/out/opengl/hwdec_osx.c b/video/out/opengl/hwdec_osx.c index e0fc5ab19b..ecceab658a 100644 --- a/video/out/opengl/hwdec_osx.c +++ b/video/out/opengl/hwdec_osx.c @@ -25,6 +25,7 @@ #include #include "video/mp_image_pool.h" +#include "video/vt.h" #include "hwdec.h" #include "common/global.h" #include "options/options.h" @@ -107,44 +108,6 @@ static struct vt_format *vt_get_gl_format_from_imgfmt(uint32_t imgfmt) return NULL; } -static struct mp_image *download_image(struct mp_hwdec_ctx *ctx, - struct mp_image *hw_image, - struct mp_image_pool *swpool) -{ - if (hw_image->imgfmt != IMGFMT_VIDEOTOOLBOX) - return NULL; - - struct mp_image *image = NULL; - CVPixelBufferRef pbuf = (CVPixelBufferRef)hw_image->planes[3]; - CVPixelBufferLockBaseAddress(pbuf, kCVPixelBufferLock_ReadOnly); - size_t width = CVPixelBufferGetWidth(pbuf); - size_t height = CVPixelBufferGetHeight(pbuf); - uint32_t cvpixfmt = CVPixelBufferGetPixelFormatType(pbuf); - struct vt_format *f = vt_get_gl_format(cvpixfmt); - if (!f) - goto unlock; - - struct mp_image img = {0}; - mp_image_setfmt(&img, f->imgfmt); - mp_image_set_size(&img, width, height); - - for (int i = 0; i < f->planes; i++) { - void *base = CVPixelBufferGetBaseAddressOfPlane(pbuf, i); - size_t stride = CVPixelBufferGetBytesPerRowOfPlane(pbuf, i); - img.planes[i] = base; - img.stride[i] = stride; - } - - mp_image_copy_attributes(&img, hw_image); - - image = mp_image_pool_new_copy(swpool, &img); - -unlock: - CVPixelBufferUnlockBaseAddress(pbuf, kCVPixelBufferLock_ReadOnly); - - return image; -} - static bool check_hwdec(struct gl_hwdec *hw) { if (hw->gl->version < 300) { @@ -184,7 +147,7 @@ static int create(struct gl_hwdec *hw) }; p->hwctx = (struct mp_hwdec_ctx){ .type = HWDEC_VIDEOTOOLBOX, - .download_image = download_image, + .download_image = mp_vt_download_image, .ctx = &p->vtctx, }; hwdec_devices_add(hw->devs, &p->hwctx); -- cgit v1.2.3