summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/hwdec_osx.c
diff options
context:
space:
mode:
Diffstat (limited to 'video/out/opengl/hwdec_osx.c')
-rw-r--r--video/out/opengl/hwdec_osx.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/video/out/opengl/hwdec_osx.c b/video/out/opengl/hwdec_osx.c
index 78d01b3894..addc16f404 100644
--- a/video/out/opengl/hwdec_osx.c
+++ b/video/out/opengl/hwdec_osx.c
@@ -101,16 +101,15 @@ static struct mp_image *download_image(struct mp_hwdec_ctx *ctx,
if (hw_image->imgfmt != IMGFMT_VIDEOTOOLBOX)
return NULL;
+ struct mp_image *image = NULL;
CVPixelBufferRef pbuf = (CVPixelBufferRef)hw_image->planes[3];
- CVPixelBufferLockBaseAddress(pbuf, 0);
+ 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) {
- CVPixelBufferUnlockBaseAddress(pbuf, 0);
- return NULL;
- }
+ if (!f)
+ goto unlock;
struct mp_image img = {0};
mp_image_setfmt(&img, f->imgfmt);
@@ -125,8 +124,10 @@ static struct mp_image *download_image(struct mp_hwdec_ctx *ctx,
mp_image_copy_attributes(&img, hw_image);
- struct mp_image *image = mp_image_pool_new_copy(swpool, &img);
- CVPixelBufferUnlockBaseAddress(pbuf, 0);
+ image = mp_image_pool_new_copy(swpool, &img);
+
+unlock:
+ CVPixelBufferUnlockBaseAddress(pbuf, kCVPixelBufferLock_ReadOnly);
return image;
}
@@ -146,14 +147,21 @@ static bool check_hwdec(struct gl_hwdec *hw)
return true;
}
+static uint32_t get_vt_fmt(struct mp_hwdec_ctx *ctx)
+{
+ struct gl_hwdec *hw = ctx->priv;
+ struct vt_format *f =
+ vt_get_gl_format_from_imgfmt(hw->global->opts->videotoolbox_format);
+ return f ? f->cvpixfmt : (uint32_t)-1;
+}
+
static int create(struct gl_hwdec *hw)
{
if (!check_hwdec(hw))
return -1;
struct priv *p = talloc_zero(hw, struct priv);
- struct vt_format *f =
- vt_get_gl_format_from_imgfmt(hw->global->opts->videotoolbox_format);
+ struct vt_format *f = vt_get_gl_format_from_imgfmt(IMGFMT_NV12);
if (!f)
return -1;
@@ -162,17 +170,26 @@ static int create(struct gl_hwdec *hw)
hw->hwctx = &p->hwctx;
hw->hwctx->download_image = download_image;
hw->hwctx->type = HWDEC_VIDEOTOOLBOX;
- hw->hwctx->priv = (void *)(uintptr_t)f->cvpixfmt;
+ hw->hwctx->get_vt_fmt = get_vt_fmt;
hw->gl_texture_target = GL_TEXTURE_RECTANGLE;
hw->gl->GenTextures(MP_MAX_PLANES, p->gl_planes);
+ hw->hwctx->priv = hw;
return 0;
}
static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
{
assert(params->imgfmt == hw->driver->imgfmt);
+
+ struct vt_format *f = vt_get_gl_format(params->hw_subfmt);
+ if (!f) {
+ MP_ERR(hw, "Unsupported CVPixelBuffer format.\n");
+ return -1;
+ }
+
+ hw->converted_imgfmt = f->imgfmt;
return 0;
}