1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 23:32:26 +00:00

videotoolbox: remove weird format-negotiation between VO and decoder

Originally, there was probably some sort of intention to restrict it to
formats supported by the interop, or something. But in the end it was
overcomplicated nonsense.

In the future, we could use mp_hwdec_ctx.supported_formats or other
mechanisms to handle this in a better way.

mp_hwdec_ctx.ctx is not set to a dummy pointer - hwdec_devices_load() is
only used to detect whether to vo_opengl interop is present, and the
common hwdec code expects that the .ctx field is not NULL.

This also changes videotoolbox-copy to use --videotoolbox-format,
instead of the FFmpeg-set default.
This commit is contained in:
wm4 2017-02-17 13:54:17 +01:00
parent b5bbcc9f93
commit 2b5577901d
3 changed files with 12 additions and 38 deletions

View File

@ -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,
};

View File

@ -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;

View File

@ -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);