[vlc-commits] hw: vaapi: move instance management into decoder_device.c
Thomas Guillem
git at videolan.org
Sun Feb 24 15:21:46 CET 2019
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Sun Feb 24 12:56:08 2019 +0100| [8c5c9471c5c3b38b28c6e29efa7a927c8366ca7d] | committer: Thomas Guillem
hw: vaapi: move instance management into decoder_device.c
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8c5c9471c5c3b38b28c6e29efa7a927c8366ca7d
---
modules/hw/vaapi/decoder_device.c | 133 +++++++++++++++++++++++++++++++++++---
modules/hw/vaapi/vlc_vaapi.c | 100 ----------------------------
modules/hw/vaapi/vlc_vaapi.h | 28 --------
3 files changed, 123 insertions(+), 138 deletions(-)
diff --git a/modules/hw/vaapi/decoder_device.c b/modules/hw/vaapi/decoder_device.c
index 1dbb69ec16..5efe9e635b 100644
--- a/modules/hw/vaapi/decoder_device.c
+++ b/modules/hw/vaapi/decoder_device.c
@@ -26,6 +26,7 @@
#include <vlc_plugin.h>
#include <vlc_vout_window.h>
#include <vlc_codec.h>
+#include <vlc_fs.h>
#include "hw/vaapi/vlc_vaapi.h"
#include <va/va_drmcommon.h>
@@ -45,6 +46,57 @@
# include <fcntl.h>
#endif
+typedef void (*vaapi_native_destroy_cb)(VANativeDisplay);
+struct vaapi_instance;
+
+struct vaapi_instance
+{
+ VADisplay dpy;
+ VANativeDisplay native;
+ vaapi_native_destroy_cb native_destroy_cb;
+};
+
+/* Initializes the VADisplay. If not NULL, native_destroy_cb will be called
+ * when the instance is released in order to destroy the native holder (that
+ * can be a drm/x11/wl). On error, dpy is terminated and the destroy callback
+ * is called. */
+static struct vaapi_instance *
+vaapi_InitializeInstance(vlc_object_t *o, VADisplay dpy,
+ VANativeDisplay native,
+ vaapi_native_destroy_cb native_destroy_cb)
+{
+ int major = 0, minor = 0;
+ VAStatus s = vaInitialize(dpy, &major, &minor);
+ if (s != VA_STATUS_SUCCESS)
+ {
+ msg_Err(o, "vaInitialize: %s", vaErrorStr(s));
+ goto error;
+ }
+ struct vaapi_instance *inst = malloc(sizeof(*inst));
+
+ if (unlikely(inst == NULL))
+ goto error;
+ inst->dpy = dpy;
+ inst->native = native;
+ inst->native_destroy_cb = native_destroy_cb;
+
+ return inst;
+error:
+ vaTerminate(dpy);
+ if (native != NULL && native_destroy_cb != NULL)
+ native_destroy_cb(native);
+ return NULL;
+}
+
+static void
+vaapi_DestroyInstance(struct vaapi_instance *inst)
+{
+ vaTerminate(inst->dpy);
+ if (inst->native != NULL && inst->native_destroy_cb != NULL)
+ inst->native_destroy_cb(inst->native);
+ free(inst);
+}
+
#ifdef HAVE_VA_X11
static void
x11_native_destroy_cb(VANativeDisplay native)
@@ -52,7 +104,7 @@ x11_native_destroy_cb(VANativeDisplay native)
XCloseDisplay(native);
}
-static struct vlc_vaapi_instance *
+static struct vaapi_instance *
x11_init_vaapi_instance(vlc_decoder_device *device, vout_window_t *window,
VADisplay *vadpyp)
{
@@ -70,22 +122,83 @@ x11_init_vaapi_instance(vlc_decoder_device *device, vout_window_t *window,
return NULL;
}
- return vlc_vaapi_InitializeInstance(VLC_OBJECT(device), vadpy,
- x11dpy, x11_native_destroy_cb);
+ return vaapi_InitializeInstance(VLC_OBJECT(device), vadpy,
+ x11dpy, x11_native_destroy_cb);
}
#endif
#ifdef HAVE_VA_DRM
-static struct vlc_vaapi_instance *
+
+static void
+native_drm_destroy_cb(VANativeDisplay native)
+{
+ vlc_close((intptr_t) native);
+}
+
+/* Get and Initializes a VADisplay from a DRM device. If device is NULL, this
+ * function will try to open default devices. */
+static struct vaapi_instance *
+vaapi_InitializeInstanceDRM(vlc_object_t *o,
+ VADisplay (*pf_getDisplayDRM)(int),
+ VADisplay *pdpy, const char *device)
+{
+ static const char *default_drm_device_paths[] = {
+ "/dev/dri/renderD128",
+ "/dev/dri/card0",
+ "/dev/dri/renderD129",
+ "/dev/dri/card1",
+ };
+
+ const char *user_drm_device_paths[] = { device };
+ const char **drm_device_paths;
+ size_t drm_device_paths_count;
+
+ if (device != NULL)
+ {
+ drm_device_paths = user_drm_device_paths;
+ drm_device_paths_count = 1;
+ }
+ else
+ {
+ drm_device_paths = default_drm_device_paths;
+ drm_device_paths_count = ARRAY_SIZE(default_drm_device_paths);
+ }
+
+ for (size_t i = 0; i < drm_device_paths_count; i++)
+ {
+ int drm_fd = vlc_open(drm_device_paths[i], O_RDWR);
+ if (drm_fd < 0)
+ continue;
+
+ VADisplay dpy = pf_getDisplayDRM(drm_fd);
+ if (dpy)
+ {
+ struct vaapi_instance *va_inst =
+ vaapi_InitializeInstance(o, dpy,
+ (VANativeDisplay)(intptr_t)drm_fd,
+ native_drm_destroy_cb);
+ if (va_inst)
+ {
+ *pdpy = dpy;
+ return va_inst;
+ }
+ }
+ else
+ vlc_close(drm_fd);
+ }
+ return NULL;
+}
+
+static struct vaapi_instance *
drm_init_vaapi_instance(vlc_decoder_device *device, VADisplay *vadpyp)
{
- return vlc_vaapi_InitializeInstanceDRM(VLC_OBJECT(device), vaGetDisplayDRM,
- vadpyp, NULL);
+ return vaapi_InitializeInstanceDRM(VLC_OBJECT(device), vaGetDisplayDRM,
+ vadpyp, NULL);
}
#endif
#ifdef HAVE_VA_WL
-static struct vlc_vaapi_instance *
+static struct vaapi_instance *
wl_init_vaapi_instance(vlc_decoder_device *device, vout_window_t *window,
VADisplay *vadpyp)
{
@@ -93,21 +206,21 @@ wl_init_vaapi_instance(vlc_decoder_device *device, vout_window_t *window,
if (vadpy == NULL)
return NULL;
- return vlc_vaapi_InitializeInstance(VLC_OBJECT(device), vadpy, NULL, NULL);
+ return vaapi_InitializeInstance(VLC_OBJECT(device), vadpy, NULL, NULL);
}
#endif
static void
Close(vlc_decoder_device *device)
{
- vlc_vaapi_DestroyInstance(device->sys);
+ vaapi_DestroyInstance(device->sys);
}
static int
Open(vlc_decoder_device *device, vout_window_t *window)
{
VADisplay vadpy = NULL;
- struct vlc_vaapi_instance *vainst = NULL;
+ struct vaapi_instance *vainst = NULL;
#if defined (HAVE_VA_X11)
if (window && window->type == VOUT_WINDOW_TYPE_XID)
vainst = x11_init_vaapi_instance(device, window, &vadpy);
diff --git a/modules/hw/vaapi/vlc_vaapi.c b/modules/hw/vaapi/vlc_vaapi.c
index 6fa00d0731..05184a013b 100644
--- a/modules/hw/vaapi/vlc_vaapi.c
+++ b/modules/hw/vaapi/vlc_vaapi.c
@@ -38,7 +38,6 @@
#include <va/va.h>
#include <vlc_common.h>
-#include <vlc_fs.h>
#include <vlc_fourcc.h>
#include <vlc_filter.h>
#include <vlc_picture_pool.h>
@@ -76,105 +75,6 @@ vlc_chroma_to_vaapi(int i_vlc_chroma, unsigned *va_rt_format, int *va_fourcc)
}
/**************************
- * VA instance management *
- **************************/
-
-struct vlc_vaapi_instance {
- VADisplay dpy;
- VANativeDisplay native;
- vlc_vaapi_native_destroy_cb native_destroy_cb;
-};
-
-struct vlc_vaapi_instance *
-vlc_vaapi_InitializeInstance(vlc_object_t *o, VADisplay dpy,
- VANativeDisplay native,
- vlc_vaapi_native_destroy_cb native_destroy_cb)
-{
- int major = 0, minor = 0;
- VA_CALL(o, vaInitialize, dpy, &major, &minor);
- struct vlc_vaapi_instance *inst = malloc(sizeof(*inst));
-
- if (unlikely(inst == NULL))
- goto error;
- inst->dpy = dpy;
- inst->native = native;
- inst->native_destroy_cb = native_destroy_cb;
-
- return inst;
-error:
- vaTerminate(dpy);
- if (native != NULL && native_destroy_cb != NULL)
- native_destroy_cb(native);
- return NULL;
-}
-
-static void native_drm_destroy_cb(VANativeDisplay native)
-{
- vlc_close((intptr_t) native);
-}
-
-struct vlc_vaapi_instance *
-vlc_vaapi_InitializeInstanceDRM(vlc_object_t *o,
- VADisplay (*pf_getDisplayDRM)(int),
- VADisplay *pdpy, const char *device)
-{
- static const char *default_drm_device_paths[] = {
- "/dev/dri/renderD128",
- "/dev/dri/card0",
- "/dev/dri/renderD129",
- "/dev/dri/card1",
- };
-
- const char *user_drm_device_paths[] = { device };
- const char **drm_device_paths;
- size_t drm_device_paths_count;
-
- if (device != NULL)
- {
- drm_device_paths = user_drm_device_paths;
- drm_device_paths_count = 1;
- }
- else
- {
- drm_device_paths = default_drm_device_paths;
- drm_device_paths_count = ARRAY_SIZE(default_drm_device_paths);
- }
-
- for (size_t i = 0; i < drm_device_paths_count; i++)
- {
- int drm_fd = vlc_open(drm_device_paths[i], O_RDWR);
- if (drm_fd < 0)
- continue;
-
- VADisplay dpy = pf_getDisplayDRM(drm_fd);
- if (dpy)
- {
- struct vlc_vaapi_instance *va_inst =
- vlc_vaapi_InitializeInstance(o, dpy,
- (VANativeDisplay)(intptr_t)drm_fd,
- native_drm_destroy_cb);
- if (va_inst)
- {
- *pdpy = dpy;
- return va_inst;
- }
- }
- else
- vlc_close(drm_fd);
- }
- return NULL;
-}
-
-void
-vlc_vaapi_DestroyInstance(struct vlc_vaapi_instance *inst)
-{
- vaTerminate(inst->dpy);
- if (inst->native != NULL && inst->native_destroy_cb != NULL)
- inst->native_destroy_cb(inst->native);
- free(inst);
-}
-
-/**************************
* VAAPI create & destroy *
**************************/
diff --git a/modules/hw/vaapi/vlc_vaapi.h b/modules/hw/vaapi/vlc_vaapi.h
index a3f0169d9f..ede4ff01dd 100644
--- a/modules/hw/vaapi/vlc_vaapi.h
+++ b/modules/hw/vaapi/vlc_vaapi.h
@@ -41,34 +41,6 @@
#include <vlc_picture_pool.h>
/**************************
- * VA instance management *
- **************************/
-
-typedef void (*vlc_vaapi_native_destroy_cb)(VANativeDisplay);
-struct vlc_vaapi_instance;
-
-/* Initializes the VADisplay and sets the reference counter to 1. If not NULL,
- * native_destroy_cb will be called when the instance is released in order to
- * destroy the native holder (that can be a drm/x11/wl). On error, dpy is
- * terminated and the destroy callback is called. */
-struct vlc_vaapi_instance *
-vlc_vaapi_InitializeInstance(vlc_object_t *o, VADisplay dpy,
- VANativeDisplay native,
- vlc_vaapi_native_destroy_cb native_destroy_cb);
-
-/* Get and Initializes a VADisplay from a DRM device. If device is NULL, this
- * function will try to open default devices. */
-struct vlc_vaapi_instance *
-vlc_vaapi_InitializeInstanceDRM(vlc_object_t *o,
- VADisplay (*pf_getDisplayDRM)(int),
- VADisplay *pdpy, const char *device);
-
-
-/* Destroy the VAAPI instance refcount, and call vaTerminate */
-void
-vlc_vaapi_DestroyInstance(struct vlc_vaapi_instance *inst);
-
-/**************************
* VAAPI create & destroy *
**************************/
More information about the vlc-commits
mailing list