[vlc-commits] hw: vaapi: add wrappers functions

Victorien Le Couviour--Tuffet git at videolan.org
Fri Jun 16 16:48:21 CEST 2017


vlc | branch: master | Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet at gmail.com> | Fri Jun 16 11:14:45 2017 +0200| [e8772f9b1c4bf7d42569d75040b139b1b5d91316] | committer: Thomas Guillem

hw: vaapi: add wrappers functions

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e8772f9b1c4bf7d42569d75040b139b1b5d91316
---

 modules/hw/vaapi/vlc_vaapi.c | 253 +++++++++++++++++++++++++++++++++++++++++++
 modules/hw/vaapi/vlc_vaapi.h | 116 ++++++++++++++++++++
 2 files changed, 369 insertions(+)

diff --git a/modules/hw/vaapi/vlc_vaapi.c b/modules/hw/vaapi/vlc_vaapi.c
new file mode 100644
index 0000000000..89052998ea
--- /dev/null
+++ b/modules/hw/vaapi/vlc_vaapi.c
@@ -0,0 +1,253 @@
+/*****************************************************************************
+ * vlc_vaapi.c: VAAPI helper for VLC
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors, VideoLAN and VideoLabs
+ *
+ * Authors: Thomas Guillem <thomas at gllm.fr>
+ *          Petri Hintukainen <phintuka at gmail.com>
+ *          Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "vlc_vaapi.h"
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include <va/va.h>
+
+/* This macro is designed to wrap any VA call, and in case of failure,
+   display the VA error string then goto the 'error' label (which you must
+   define). */
+#define VA_CALL(o, f, args...)                          \
+    do                                                  \
+    {                                                   \
+        VAStatus s = f(args);                           \
+        if (s != VA_STATUS_SUCCESS)                     \
+        {                                               \
+            msg_Err(o, "%s: %s", #f, vaErrorStr(s));    \
+            goto error;                                 \
+        }                                               \
+    } while (0)
+
+/*****************
+ * VAAPI display *
+ *****************/
+
+int
+vlc_vaapi_Initialize(vlc_object_t *o, VADisplay dpy)
+{
+    int major = 0, minor = 0;
+    VA_CALL(o, vaInitialize, dpy, &major, &minor);
+    return VLC_SUCCESS;
+error:
+    vaTerminate(dpy);
+    return VLC_EGENERIC;
+}
+
+/**************************
+ * VAAPI create & destroy *
+ **************************/
+
+VAContextID
+vlc_vaapi_CreateContext(vlc_object_t *o, VADisplay dpy, VAConfigID conf,
+                        int pic_w, int pic_h, int flag,
+                        VASurfaceID *render_targets, int num_render_targets)
+{
+    VAContextID ctx;
+    VA_CALL(o, vaCreateContext, dpy, conf, pic_w, pic_h, flag,
+            render_targets, num_render_targets, &ctx);
+    return ctx;
+error: return VA_INVALID_ID;
+}
+
+VABufferID
+vlc_vaapi_CreateBuffer(vlc_object_t *o, VADisplay dpy, VAContextID ctx,
+                       VABufferType type, unsigned int size,
+                       unsigned int num_elements, void *data)
+{
+    VABufferID buf_id;
+    VA_CALL(o, vaCreateBuffer, dpy, ctx, type,
+            size, num_elements, data, &buf_id);
+    return buf_id;
+error: return VA_INVALID_ID;
+}
+
+int
+vlc_vaapi_DeriveImage(vlc_object_t *o,
+                      VADisplay dpy, VASurfaceID surface, VAImage *image)
+{
+    VA_CALL(o, vaDeriveImage, dpy, surface, image);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_CreateImage(vlc_object_t *o, VADisplay dpy, VAImageFormat *format,
+                      int width, int height, VAImage *image)
+{
+    VA_CALL(o, vaCreateImage, dpy, format, width, height, image);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_DestroyConfig(vlc_object_t *o, VADisplay dpy, VAConfigID conf)
+{
+    VA_CALL(o, vaDestroyConfig, dpy, conf);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_DestroyContext(vlc_object_t *o, VADisplay dpy, VAContextID ctx)
+{
+    VA_CALL(o, vaDestroyContext, dpy, ctx);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_DestroyBuffer(vlc_object_t *o, VADisplay dpy, VABufferID buf)
+{
+    VA_CALL(o, vaDestroyBuffer, dpy, buf);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_DestroyImage(vlc_object_t *o, VADisplay dpy, VAImageID image)
+{
+    VA_CALL(o, vaDestroyImage, dpy, image);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+/***********************
+ * VAAPI buffer access *
+ ***********************/
+
+int
+vlc_vaapi_MapBuffer(vlc_object_t *o, VADisplay dpy,
+                    VABufferID buf_id, void **p_buf)
+{
+    VA_CALL(o, vaMapBuffer, dpy, buf_id, p_buf);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_UnmapBuffer(vlc_object_t *o, VADisplay dpy, VABufferID buf_id)
+{
+    VA_CALL(o, vaUnmapBuffer, dpy, buf_id);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_AcquireBufferHandle(vlc_object_t *o, VADisplay dpy, VABufferID buf_id,
+                              VABufferInfo *buf_info)
+{
+    VA_CALL(o, vaAcquireBufferHandle, dpy, buf_id, buf_info);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_ReleaseBufferHandle(vlc_object_t *o, VADisplay dpy, VABufferID buf_id)
+{
+    VA_CALL(o, vaReleaseBufferHandle, dpy, buf_id);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+/*****************
+ * VAAPI queries *
+ *****************/
+
+int
+vlc_vaapi_IsVideoProcFilterAvailable(vlc_object_t *o, VADisplay dpy,
+                                     VAContextID ctx, VAProcFilterType filter)
+{
+    VAProcFilterType    filters[VAProcFilterCount];
+    unsigned int        num_filters = VAProcFilterCount;
+
+    VA_CALL(o, vaQueryVideoProcFilters, dpy, ctx, filters, &num_filters);
+    for (unsigned int i = 0; i < num_filters; ++i)
+        if (filter == filters[i])
+            return VLC_SUCCESS;
+    return VLC_EGENERIC;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_QueryVideoProcFilterCaps(vlc_object_t *o, VADisplay dpy,
+                                   VAContextID ctx, VAProcFilterType filter,
+                                   void *caps, unsigned int *p_num_caps)
+{
+    VA_CALL(o, vaQueryVideoProcFilterCaps, dpy,
+            ctx, filter, caps, p_num_caps);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_QueryVideoProcPipelineCaps(vlc_object_t *o, VADisplay dpy,
+                                     VAContextID ctx, VABufferID *filters,
+                                     unsigned int num_filters,
+                                     VAProcPipelineCaps *pipeline_caps)
+{
+    VA_CALL(o, vaQueryVideoProcPipelineCaps, dpy,
+            ctx, filters, num_filters, pipeline_caps);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+/*******************
+ * VAAPI rendering *
+ *******************/
+
+int
+vlc_vaapi_BeginPicture(vlc_object_t *o, VADisplay dpy,
+                       VAContextID ctx, VASurfaceID surface)
+{
+    VA_CALL(o, vaBeginPicture, dpy, ctx, surface);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_RenderPicture(vlc_object_t *o, VADisplay dpy, VAContextID ctx,
+                        VABufferID *buffers, int num_buffers)
+{
+    VA_CALL(o, vaRenderPicture, dpy, ctx, buffers, num_buffers);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
+
+int
+vlc_vaapi_EndPicture(vlc_object_t *o, VADisplay dpy, VAContextID ctx)
+{
+    VA_CALL(o, vaEndPicture, dpy, ctx);
+    return VLC_SUCCESS;
+error: return VLC_EGENERIC;
+}
diff --git a/modules/hw/vaapi/vlc_vaapi.h b/modules/hw/vaapi/vlc_vaapi.h
index 92ef9b1ace..564057b833 100644
--- a/modules/hw/vaapi/vlc_vaapi.h
+++ b/modules/hw/vaapi/vlc_vaapi.h
@@ -44,4 +44,120 @@ vlc_vaapi_GetInstance(void);
 void
 vlc_vaapi_ReleaseInstance(VADisplay *);
 
+/*****************
+ * VAAPI display *
+ *****************/
+
+int
+vlc_vaapi_Initialize(vlc_object_t *o, VADisplay va_dpy);
+
+/**************************
+ * VAAPI create & destroy *
+ **************************/
+
+/* Creates a VA context from the VA configuration and the width / height of the
+ * pictures to process. */
+VAContextID
+vlc_vaapi_CreateContext(vlc_object_t *o, VADisplay dpy, VAConfigID conf,
+                        int pic_w, int pic_h, int flag,
+                        VASurfaceID *render_targets, int num_render_targets);
+
+/* Creates a VA buffer for 'num_elements' elements of 'size' bytes and
+ * initalized with 'data'. If 'data' is NULL, then the content of the buffer is
+ * undefined. */
+VABufferID
+vlc_vaapi_CreateBuffer(vlc_object_t *o, VADisplay dpy, VAContextID ctx,
+                       VABufferType type, unsigned int size,
+                       unsigned int num_elements, void *data);
+
+/* Creates a VA image from a VA surface. */
+int
+vlc_vaapi_DeriveImage(vlc_object_t *o, VADisplay dpy,
+                      VASurfaceID surface, VAImage *image);
+
+/* Creates a VA image */
+int
+vlc_vaapi_CreateImage(vlc_object_t *o, VADisplay dpy, VAImageFormat *format,
+                      int width, int height, VAImage *image);
+
+/* Destroys a VA configuration. */
+int
+vlc_vaapi_DestroyConfig(vlc_object_t *o, VADisplay dpy, VAConfigID conf);
+
+/* Destroys a VA context. */
+int
+vlc_vaapi_DestroyContext(vlc_object_t *o, VADisplay dpy, VAContextID ctx);
+
+/* Destroys a VA buffer. */
+int
+vlc_vaapi_DestroyBuffer(vlc_object_t *o, VADisplay dpy, VABufferID buf);
+
+/* Destroys a VA image. */
+int
+vlc_vaapi_DestroyImage(vlc_object_t *o, VADisplay dpy, VAImageID image);
+
+/***********************
+ * VAAPI buffer access *
+ ***********************/
+
+/* Maps the specified buffer to '*p_buf'. */
+int
+vlc_vaapi_MapBuffer(vlc_object_t *o, VADisplay dpy,
+                    VABufferID buf_id, void **p_buf);
+
+/* Unmaps the specified buffer so that the driver can read from it. */
+int
+vlc_vaapi_UnmapBuffer(vlc_object_t *o, VADisplay dpy, VABufferID buf_id);
+
+int
+vlc_vaapi_AcquireBufferHandle(vlc_object_t *o, VADisplay dpy, VABufferID buf_id,
+                              VABufferInfo *buf_info);
+
+int
+vlc_vaapi_ReleaseBufferHandle(vlc_object_t *o, VADisplay dpy, VABufferID buf_id);
+
+/*****************
+ * VAAPI queries *
+ *****************/
+
+/* Checks if the specified filter is available. */
+int
+vlc_vaapi_IsVideoProcFilterAvailable(vlc_object_t *o,
+                                     VADisplay dpy, VAContextID ctx,
+                                     VAProcFilterType filter);
+
+/* Retrieves the list of available capabilities of a filter. */
+int
+vlc_vaapi_QueryVideoProcFilterCaps(vlc_object_t *o, VADisplay dpy,
+                                   VAContextID ctx,
+                                   VAProcFilterType filter, void *caps,
+                                   unsigned int *p_num_caps);
+
+/* Retrieves the available capabilities of the pipeline. */
+int
+vlc_vaapi_QueryVideoProcPipelineCaps(vlc_object_t *o, VADisplay dpy,
+                                     VAContextID ctx, VABufferID *filters,
+                                     unsigned int num_filters,
+                                     VAProcPipelineCaps *pipeline_caps);
+
+/*******************
+ * VAAPI rendering *
+ *******************/
+
+/* Tells the driver the specified surface is the next surface to render. */
+int
+vlc_vaapi_BeginPicture(vlc_object_t *o, VADisplay dpy,
+                       VAContextID ctx, VASurfaceID surface);
+
+/* Send buffers (describing rendering operations to perform on the current
+ * surface) to the driver, which are automatically destroyed afterwards. */
+int
+vlc_vaapi_RenderPicture(vlc_object_t *o, VADisplay dpy, VAContextID ctx,
+                        VABufferID *buffers, int num_buffers);
+
+/* Tells the driver it can begins to process all the pending operations
+ * (specified with vlc_vaapi_RenderPicture) on the current surface. */
+int
+vlc_vaapi_EndPicture(vlc_object_t *o, VADisplay dpy, VAContextID ctx);
+
 #endif /* VLC_VAAPI_H */



More information about the vlc-commits mailing list