mirror of https://github.com/mpv-player/mpv
vaapi: always create AVHWDeviceContext on init
For convenience. Since we still have code that works even if creating a AVHWDeviceContext fails, failure is ignored. (Although currently, it succeeds creation even with the stale/abandoned vdpau wrapper driver.)
This commit is contained in:
parent
b26ab4d08c
commit
d9376fc86f
|
@ -41,7 +41,6 @@ struct priv {
|
|||
struct mp_vaapi_ctx *ctx;
|
||||
bool own_ctx;
|
||||
|
||||
AVBufferRef *device_ref;
|
||||
AVBufferRef *frames_ref;
|
||||
};
|
||||
|
||||
|
@ -72,7 +71,7 @@ static int init_decoder(struct lavc_ctx *ctx, int w, int h)
|
|||
}
|
||||
|
||||
if (!p->frames_ref) {
|
||||
p->frames_ref = av_hwframe_ctx_alloc(p->device_ref);
|
||||
p->frames_ref = av_hwframe_ctx_alloc(p->ctx->av_device_ref);
|
||||
if (!p->frames_ref)
|
||||
return -1;
|
||||
|
||||
|
@ -114,7 +113,6 @@ static void uninit(struct lavc_ctx *ctx)
|
|||
return;
|
||||
|
||||
av_buffer_unref(&p->frames_ref);
|
||||
av_buffer_unref(&p->device_ref);
|
||||
|
||||
if (p->own_ctx)
|
||||
va_destroy(p->ctx);
|
||||
|
@ -143,16 +141,7 @@ static int init(struct lavc_ctx *ctx, bool direct)
|
|||
|
||||
ctx->hwdec_priv = p;
|
||||
|
||||
p->device_ref = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_VAAPI);
|
||||
if (!p->device_ref)
|
||||
return -1;
|
||||
|
||||
AVHWDeviceContext *hwctx = (void *)p->device_ref->data;
|
||||
AVVAAPIDeviceContext *vactx = hwctx->hwctx;
|
||||
|
||||
vactx->display = p->ctx->display;
|
||||
|
||||
if (av_hwdevice_ctx_init(p->device_ref) < 0)
|
||||
if (!p->ctx->av_device_ref)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -151,6 +151,21 @@ static void va_info_callback(const char *msg)
|
|||
va_message_callback(msg, MSGL_V);
|
||||
}
|
||||
|
||||
static void open_lavu_vaapi_device(struct mp_vaapi_ctx *ctx)
|
||||
{
|
||||
ctx->av_device_ref = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_VAAPI);
|
||||
if (!ctx->av_device_ref)
|
||||
return;
|
||||
|
||||
AVHWDeviceContext *hwctx = (void *)ctx->av_device_ref->data;
|
||||
AVVAAPIDeviceContext *vactx = hwctx->hwctx;
|
||||
|
||||
vactx->display = ctx->display;
|
||||
|
||||
if (av_hwdevice_ctx_init(ctx->av_device_ref) < 0)
|
||||
av_buffer_unref(&ctx->av_device_ref);
|
||||
}
|
||||
|
||||
struct mp_vaapi_ctx *va_initialize(VADisplay *display, struct mp_log *plog,
|
||||
bool probing)
|
||||
{
|
||||
|
@ -189,6 +204,11 @@ struct mp_vaapi_ctx *va_initialize(VADisplay *display, struct mp_log *plog,
|
|||
va_get_formats(res);
|
||||
if (!res->image_formats)
|
||||
goto error;
|
||||
|
||||
// For now, some code will still work even if libavutil fails on old crap
|
||||
// libva drivers (such as the vdpau wraper). So don't error out on failure.
|
||||
open_lavu_vaapi_device(res);
|
||||
|
||||
return res;
|
||||
|
||||
error:
|
||||
|
|
|
@ -33,6 +33,7 @@ struct mp_vaapi_ctx {
|
|||
struct mp_hwdec_ctx hwctx;
|
||||
struct mp_log *log;
|
||||
VADisplay display;
|
||||
struct AVBufferRef *av_device_ref; // AVVAAPIDeviceContext*
|
||||
struct va_image_formats *image_formats;
|
||||
bool gpu_memcpy_message;
|
||||
pthread_mutex_t lock;
|
||||
|
|
Loading…
Reference in New Issue