summaryrefslogtreecommitdiffstats
path: root/video/decode
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-01-11 16:07:53 +0100
committerwm4 <wm4@nowhere>2017-01-11 16:34:18 +0100
commit9fd986b53a319d449ae09a51729ca7dc89146941 (patch)
tree0c0e8dd8ab9e5592179f7c34707ff1e950bac20f /video/decode
parent7dc74ee03721e8ccfa09122c56e76a9c62c68db4 (diff)
downloadmpv-9fd986b53a319d449ae09a51729ca7dc89146941.tar.bz2
mpv-9fd986b53a319d449ae09a51729ca7dc89146941.tar.xz
vaapi: move standalone display creation code to common code
Preparation for the following commits.
Diffstat (limited to 'video/decode')
-rw-r--r--video/decode/vaapi_old.c145
1 files changed, 9 insertions, 136 deletions
diff --git a/video/decode/vaapi_old.c b/video/decode/vaapi_old.c
index c095868816..9c0907d0d4 100644
--- a/video/decode/vaapi_old.c
+++ b/video/decode/vaapi_old.c
@@ -52,11 +52,9 @@
struct priv {
struct mp_log *log;
struct mp_vaapi_ctx *ctx;
+ bool own_ctx;
VADisplay display;
- const struct va_native_display *native_display_fns;
- void *native_display;
-
// libavcodec shared struct
struct vaapi_context *va_context;
struct vaapi_context va_context_storage;
@@ -67,98 +65,6 @@ struct priv {
struct mp_image_pool *sw_pool;
};
-struct va_native_display {
- void (*create)(struct priv *p);
- void (*destroy)(struct priv *p);
-};
-
-#if HAVE_VAAPI_X11
-#include <X11/Xlib.h>
-#include <va/va_x11.h>
-
-static void x11_destroy(struct priv *p)
-{
- if (p->native_display)
- XCloseDisplay(p->native_display);
- p->native_display = NULL;
-}
-
-static void x11_create(struct priv *p)
-{
- p->native_display = XOpenDisplay(NULL);
- if (!p->native_display)
- return;
- p->display = vaGetDisplay(p->native_display);
- if (!p->display)
- x11_destroy(p);
-}
-
-static const struct va_native_display disp_x11 = {
- .create = x11_create,
- .destroy = x11_destroy,
-};
-#endif
-
-#if HAVE_VAAPI_DRM
-#include <unistd.h>
-#include <fcntl.h>
-#include <va/va_drm.h>
-
-struct va_native_display_drm {
- int drm_fd;
-};
-
-static void drm_destroy(struct priv *p)
-{
- struct va_native_display_drm *native_display = p->native_display;
- if (native_display) {
- if (native_display->drm_fd >= 0)
- close(native_display->drm_fd);
- talloc_free(native_display);
- p->native_display = NULL;
- }
-}
-
-static void drm_create(struct priv *p)
-{
- static const char *drm_device_paths[] = {
- "/dev/dri/renderD128",
- "/dev/dri/card0",
- NULL
- };
-
- for (int i = 0; drm_device_paths[i]; i++) {
- int drm_fd = open(drm_device_paths[i], O_RDWR);
- if (drm_fd < 0)
- continue;
-
- struct va_native_display_drm *native_display = talloc_ptrtype(NULL, native_display);
- native_display->drm_fd = drm_fd;
- p->native_display = native_display;
- p->display = vaGetDisplayDRM(drm_fd);
- if (p->display)
- return;
-
- drm_destroy(p);
- }
-}
-
-static const struct va_native_display disp_drm = {
- .create = drm_create,
- .destroy = drm_destroy,
-};
-#endif
-
-static const struct va_native_display *const native_displays[] = {
-#if HAVE_VAAPI_DRM
- &disp_drm,
-#endif
-#if HAVE_VAAPI_X11
- &disp_x11,
-#endif
- NULL
-};
-
#define HAS_HEVC VA_CHECK_VERSION(0, 38, 0)
#define HAS_VP9 (VA_CHECK_VERSION(0, 38, 1) && defined(FF_PROFILE_VP9_0))
@@ -397,40 +303,6 @@ static struct mp_image *update_format(struct lavc_ctx *ctx, struct mp_image *img
return img;
}
-static void destroy_va_dummy_ctx(struct priv *p)
-{
- va_destroy(p->ctx);
- p->ctx = NULL;
- p->display = NULL;
- if (p->native_display_fns)
- p->native_display_fns->destroy(p);
-}
-
-// Creates a "private" VADisplay, disconnected from the VO. We just create a
-// new X connection, because that's simpler. (We could also pass the X
-// connection along with struct mp_hwdec_devices, if we wanted.)
-static bool create_va_dummy_ctx(struct priv *p)
-{
- for (int n = 0; native_displays[n]; n++) {
- native_displays[n]->create(p);
- if (p->display) {
- p->native_display_fns = native_displays[n];
- break;
- }
- }
- if (!p->display)
- goto destroy_ctx;
- p->ctx = va_initialize(p->display, p->log, true);
- if (!p->ctx) {
- vaTerminate(p->display);
- goto destroy_ctx;
- }
- return true;
-destroy_ctx:
- destroy_va_dummy_ctx(p);
- return false;
-}
-
static void uninit(struct lavc_ctx *ctx)
{
struct priv *p = ctx->hwdec_priv;
@@ -443,8 +315,8 @@ static void uninit(struct lavc_ctx *ctx)
talloc_free(p->pool);
p->pool = NULL;
- if (p->native_display_fns)
- destroy_va_dummy_ctx(p);
+ if (p->own_ctx)
+ va_destroy(p->ctx);
talloc_free(p);
ctx->hwdec_priv = NULL;
@@ -462,11 +334,12 @@ static int init(struct lavc_ctx *ctx, bool direct)
if (direct) {
p->ctx = hwdec_devices_get(ctx->hwdec_devs, HWDEC_VAAPI)->ctx;
} else {
- create_va_dummy_ctx(p);
+ p->ctx = va_create_standalone(ctx->log, false);
if (!p->ctx) {
talloc_free(p);
return -1;
}
+ p->own_ctx = true;
}
p->display = p->ctx->display;
@@ -502,11 +375,11 @@ static int probe(struct lavc_ctx *ctx, struct vd_lavc_hwdec *hwdec,
static int probe_copy(struct lavc_ctx *ctx, struct vd_lavc_hwdec *hwdec,
const char *codec)
{
- struct priv dummy = {mp_null_log};
- if (!create_va_dummy_ctx(&dummy))
+ struct mp_vaapi_ctx *dummy = va_create_standalone(ctx->log, true);
+ if (!dummy)
return HWDEC_ERR_NO_CTX;
- bool emulated = va_guess_if_emulated(dummy.ctx);
- destroy_va_dummy_ctx(&dummy);
+ bool emulated = va_guess_if_emulated(dummy);
+ va_destroy(dummy);
if (!hwdec_check_codec_support(codec, profiles))
return HWDEC_ERR_NO_CODEC;
if (emulated)