summaryrefslogtreecommitdiffstats
path: root/video/out/opengl
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-02-17 13:32:27 +0100
committerwm4 <wm4@nowhere>2017-02-17 13:32:27 +0100
commit1e4fd996bb249a773bad5d57ac5b724be52a09af (patch)
treeb8d866473894b8087b941b4fee21bbfd317a8d92 /video/out/opengl
parente8137ee88154b496b2370bbdd93cd3cb3564dc86 (diff)
downloadmpv-1e4fd996bb249a773bad5d57ac5b724be52a09af.tar.bz2
mpv-1e4fd996bb249a773bad5d57ac5b724be52a09af.tar.xz
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.
Diffstat (limited to 'video/out/opengl')
-rw-r--r--video/out/opengl/hwdec_osx.c41
1 files changed, 2 insertions, 39 deletions
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 <OpenGL/CGLIOSurface.h>
#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);