[vlc-commits] hw: vaapi: add instance dynamic library

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


vlc | branch: master | Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet at gmail.com> | Tue Aug 23 12:50:49 2016 +0300| [a7c9dab0a1d426b3a77992d68105ba74aeb9879e] | committer: Thomas Guillem

hw: vaapi: add instance dynamic library

This dynamic library holds the current VADisplay instance.

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

 modules/Makefile.am          |  1 +
 modules/hw/vaapi/Makefile.am | 11 ++++++
 modules/hw/vaapi/instance.c  | 93 ++++++++++++++++++++++++++++++++++++++++++++
 modules/hw/vaapi/vlc_vaapi.h | 47 ++++++++++++++++++++++
 4 files changed, 152 insertions(+)

diff --git a/modules/Makefile.am b/modules/Makefile.am
index 5e9e079a91..0276e271a9 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -31,6 +31,7 @@ include codec/Makefile.am
 include control/Makefile.am
 include demux/Makefile.am
 include gui/Makefile.am
+include hw/vaapi/Makefile.am
 include hw/vdpau/Makefile.am
 include keystore/Makefile.am
 include logger/Makefile.am
diff --git a/modules/hw/vaapi/Makefile.am b/modules/hw/vaapi/Makefile.am
new file mode 100644
index 0000000000..92eb10c2bd
--- /dev/null
+++ b/modules/hw/vaapi/Makefile.am
@@ -0,0 +1,11 @@
+vaapidir = $(pluginsdir)/vaapi
+
+libvlc_vaapi_instance_la_SOURCES = hw/vaapi/instance.c hw/vaapi/vlc_vaapi.h
+libvlc_vaapi_instance_la_CFLAGS = $(LIBVA_CFLAGS)
+libvlc_vaapi_instance_la_LIBADD = $(LIBVA_LIBS) $(LIBPTHREAD)
+libvlc_vaapi_instance_la_LDFLAGS = -no-undefined	\
+				   -version-info 0:0:0
+
+if HAVE_VAAPI
+vaapi_LTLIBRARIES = libvlc_vaapi_instance.la
+endif
diff --git a/modules/hw/vaapi/instance.c b/modules/hw/vaapi/instance.c
new file mode 100644
index 0000000000..3f70fe7ebc
--- /dev/null
+++ b/modules/hw/vaapi/instance.c
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * instance.c: VAAPI instance management for VLC
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors, VideoLAN and VideoLabs
+ *
+ * Author: 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 <assert.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <vlc_common.h>
+#include "vlc_vaapi.h"
+
+#pragma GCC visibility push(default)
+
+static struct
+{
+    pthread_mutex_t     lock;
+    VADisplay           dpy;
+    unsigned            refcount;
+} va_instance = { PTHREAD_MUTEX_INITIALIZER, NULL, 0 };
+
+/* Set the VA instance and sets the reference counter to 1. */
+int
+vlc_vaapi_SetInstance(VADisplay dpy)
+{
+    pthread_mutex_lock(&va_instance.lock);
+    if (va_instance.refcount != 0)
+    {
+        vaTerminate(dpy);
+        pthread_mutex_unlock(&va_instance.lock);
+        return VLC_EGENERIC;
+    }
+    va_instance.refcount = 1;
+    va_instance.dpy = dpy;
+    pthread_mutex_unlock(&va_instance.lock);
+    return VLC_SUCCESS;
+}
+
+/* Retrieve the VA instance and increases the reference counter by 1. */
+VADisplay
+vlc_vaapi_GetInstance(void)
+{
+    VADisplay dpy;
+    pthread_mutex_lock(&va_instance.lock);
+    if (!va_instance.dpy)
+        dpy = NULL;
+    else
+    {
+        dpy = va_instance.dpy;
+        ++va_instance.refcount;
+    }
+    pthread_mutex_unlock(&va_instance.lock);
+    return dpy;
+}
+
+/* Decreases the reference counter by 1 and frees the instance if that counter
+   reaches 0. */
+void
+vlc_vaapi_ReleaseInstance(VADisplay *dpy)
+{
+    assert(va_instance.dpy == dpy && va_instance.refcount > 0);
+    (void) dpy;
+
+    pthread_mutex_lock(&va_instance.lock);
+    if (--va_instance.refcount == 0)
+    {
+        vaTerminate(va_instance.dpy);
+        va_instance.dpy = NULL;
+    }
+    pthread_mutex_unlock(&va_instance.lock);
+}
+
+#pragma GCC visibility pop
diff --git a/modules/hw/vaapi/vlc_vaapi.h b/modules/hw/vaapi/vlc_vaapi.h
new file mode 100644
index 0000000000..92ef9b1ace
--- /dev/null
+++ b/modules/hw/vaapi/vlc_vaapi.h
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * vlc_vaapi.h: 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.
+ *****************************************************************************/
+
+#ifndef VLC_VAAPI_H
+# define VLC_VAAPI_H
+
+#include <va/va.h>
+
+/**************************
+ * VA instance management *
+ **************************/
+
+/* Allocates the VA instance and sets the reference counter to 1. */
+int
+vlc_vaapi_SetInstance(VADisplay dpy);
+
+/* Retrieve the VA instance and increases the reference counter by 1. */
+VADisplay
+vlc_vaapi_GetInstance(void);
+
+/* Decreases the reference counter by 1 and frees the instance if that counter
+   reaches 0. */
+void
+vlc_vaapi_ReleaseInstance(VADisplay *);
+
+#endif /* VLC_VAAPI_H */



More information about the vlc-commits mailing list