diff --git a/video/decode/hw_videotoolbox.c b/video/decode/hw_videotoolbox.c index 8edffb5453..8d8c165a84 100644 --- a/video/decode/hw_videotoolbox.c +++ b/video/decode/hw_videotoolbox.c @@ -22,6 +22,7 @@ #include "common/av_common.h" #include "common/msg.h" +#include "options/options.h" #include "video/mp_image.h" #include "video/decode/lavc.h" #include "video/mp_image_pool.h" @@ -96,10 +97,17 @@ static void print_videotoolbox_error(struct mp_log *log, int lev, char *message, mp_msg(log, lev, "%s: %d\n", message, error_code); } -static int init_decoder_common(struct lavc_ctx *ctx, int w, int h, AVVideotoolboxContext *vtctx) +static int init_decoder(struct lavc_ctx *ctx, int w, int h) { av_videotoolbox_default_free(ctx->avctx); + AVVideotoolboxContext *vtctx = av_videotoolbox_alloc_context(); + if (!vtctx) + return -1; + + vtctx->cv_pix_fmt_type = + mp_imgfmt_to_cvpixelformat(ctx->opts->videotoolbox_format); + int err = av_videotoolbox_default_init2(ctx->avctx, vtctx); if (err < 0) { print_videotoolbox_error(ctx->log, MSGL_ERR, "failed to init videotoolbox decoder", err); @@ -109,20 +117,6 @@ static int init_decoder_common(struct lavc_ctx *ctx, int w, int h, AVVideotoolbo return 0; } -static int init_decoder(struct lavc_ctx *ctx, int w, int h) -{ - AVVideotoolboxContext *vtctx = av_videotoolbox_alloc_context(); - struct mp_vt_ctx *vt = hwdec_devices_load(ctx->hwdec_devs, HWDEC_VIDEOTOOLBOX); - vtctx->cv_pix_fmt_type = vt->get_vt_fmt(vt); - - return init_decoder_common(ctx, w, h, vtctx); -} - -static int init_decoder_copy(struct lavc_ctx *ctx, int w, int h) -{ - return init_decoder_common(ctx, w, h, NULL); -} - static void uninit(struct lavc_ctx *ctx) { if (ctx->avctx) @@ -179,7 +173,7 @@ const struct vd_lavc_hwdec mp_vd_lavc_videotoolbox_copy = { .probe = probe_copy, .init = init, .uninit = uninit, - .init_decoder = init_decoder_copy, + .init_decoder = init_decoder, .process_image = copy_image, .delay_queue = HWDEC_DELAY_QUEUE_COUNT, }; diff --git a/video/hwdec.h b/video/hwdec.h index 9d1035cd6e..f8a089e8c6 100644 --- a/video/hwdec.h +++ b/video/hwdec.h @@ -39,7 +39,7 @@ struct mp_hwdec_ctx { // This is never NULL. Its meaning depends on the .type field: // HWDEC_VDPAU: struct mp_vaapi_ctx* - // HWDEC_VIDEOTOOLBOX: struct mp_vt_ctx* + // HWDEC_VIDEOTOOLBOX: non-NULL dummy pointer // HWDEC_VAAPI: struct mp_vaapi_ctx* // HWDEC_D3D11VA: ID3D11Device* // HWDEC_DXVA2: IDirect3DDevice9* @@ -64,11 +64,6 @@ struct mp_hwdec_ctx { struct mp_image_pool *swpool); }; -struct mp_vt_ctx { - void *priv; - uint32_t (*get_vt_fmt)(struct mp_vt_ctx *ctx); -}; - // Used to communicate hardware decoder device handles from VO to video decoder. struct mp_hwdec_devices; diff --git a/video/out/opengl/hwdec_osx.c b/video/out/opengl/hwdec_osx.c index ecceab658a..aa350209ec 100644 --- a/video/out/opengl/hwdec_osx.c +++ b/video/out/opengl/hwdec_osx.c @@ -27,8 +27,6 @@ #include "video/mp_image_pool.h" #include "video/vt.h" #include "hwdec.h" -#include "common/global.h" -#include "options/options.h" struct vt_gl_plane_format { GLenum gl_format; @@ -46,7 +44,6 @@ struct vt_format { struct priv { struct mp_hwdec_ctx hwctx; - struct mp_vt_ctx vtctx; CVPixelBufferRef pbuf; GLuint gl_planes[MP_MAX_PLANES]; @@ -123,14 +120,6 @@ static bool check_hwdec(struct gl_hwdec *hw) return true; } -static uint32_t get_vt_fmt(struct mp_vt_ctx *vtctx) -{ - struct gl_hwdec *hw = vtctx->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)) @@ -141,14 +130,10 @@ static int create(struct gl_hwdec *hw) hw->gl->GenTextures(MP_MAX_PLANES, p->gl_planes); - p->vtctx = (struct mp_vt_ctx){ - .priv = hw, - .get_vt_fmt = get_vt_fmt, - }; p->hwctx = (struct mp_hwdec_ctx){ .type = HWDEC_VIDEOTOOLBOX, .download_image = mp_vt_download_image, - .ctx = &p->vtctx, + .ctx = &p->hwctx, }; hwdec_devices_add(hw->devs, &p->hwctx);