[vlc-commits] vaapi: add support for DRM backend

Rémi Denis-Courmont git at videolan.org
Sat Mar 22 17:15:31 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Mar 22 18:10:17 2014 +0200| [2f3c89c94ef51705ff6461c0357df8da9ded4e80] | committer: Rémi Denis-Courmont

vaapi: add support for DRM backend

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

 configure.ac                  |   56 ++++++++++++++++++++++++++++-------------
 modules/codec/Makefile.am     |   23 +++++++++++++----
 modules/codec/avcodec/vaapi.c |   53 ++++++++++++++++++++++++++++++++++----
 3 files changed, 104 insertions(+), 28 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4fd0e0b..3094c7f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2289,30 +2289,50 @@ AC_ARG_ENABLE(libva,
 AS_IF([test "${enable_libva}" = "yes" -a "${have_avcodec}" != "yes" ], [
   AC_MSG_ERROR([--enable-libva and --disable-avcodec options are mutually exclusive. Use --enable-avcodec.])
 ])
-have_avcodec_vaapi="no"
-AS_IF([test "${enable_libva}" != "no" -a "${have_avcodec}" = "yes"], [
-  PKG_CHECK_MODULES(LIBVA, [libva libva-x11], [
-    VLC_SAVE_FLAGS
-    CPPFLAGS="${CPPFLAGS} ${AVCODEC_CFLAGS}"
-    CFLAGS="${CFLAGS} ${AVCODEC_CFLAGS}"
-    AC_CHECK_HEADERS(libavcodec/vaapi.h, [
-      AC_MSG_NOTICE([VAAPI acceleration activated])
-      have_avcodec_vaapi="yes"
-    ],[
-      AS_IF([test -n "${enable_libva}"], [
-        AC_MSG_ERROR([libva is present but libavcodec/vaapi.h is missing])
-      ], [
-        AC_MSG_WARN([libva is present but libavcodec/vaapi.h is missing ])
-      ])
-    ])
-    VLC_RESTORE_FLAGS
-  ],[
+
+have_vaapi="no"
+have_vaapi_drm="no"
+have_vaapi_x11="no"
+AS_IF([test "${enable_libva}" != "no"], [
+  PKG_CHECK_EXISTS([libva], [
+    have_vaapi="yes"
+  ], [
     AS_IF([test -n "${enable_libva}"], [
       AC_MSG_ERROR([${LIBVA_PKG_ERRORS}.])
     ], [
       AC_MSG_WARN([${LIBVA_PKG_ERRORS}.])
     ])
   ])
+  PKG_CHECK_MODULES([LIBVA_DRM], [libva-drm], [
+    have_vaapi_drm="yes"
+  ], [
+    AC_MSG_WARN([${LIBVA_DRM_PKG_ERRORS}.])
+  ])
+  PKG_CHECK_MODULES(LIBVA_X11, [libva-x11], [
+    have_vaapi_x11="yes"
+  ], [
+    AC_MSG_WARN([${LIBVA_X11_PKG_ERRORS}.])
+  ])
+])
+AM_CONDITIONAL([HAVE_VAAPI_DRM], [test "${have_vaapi_drm}" = "yes"])
+AM_CONDITIONAL([HAVE_VAAPI_X11], [test "${have_vaapi_x11}" = "yes"])
+
+have_avcodec_vaapi="no"
+AS_IF([test "${have_vaapi}" = "yes" -a "${have_avcodec}" = "yes"], [
+  VLC_SAVE_FLAGS
+  CPPFLAGS="${CPPFLAGS} ${AVCODEC_CFLAGS}"
+  CFLAGS="${CFLAGS} ${AVCODEC_CFLAGS}"
+  AC_CHECK_HEADERS([libavcodec/vaapi.h], [
+    AC_MSG_NOTICE([VAAPI acceleration activated])
+    have_avcodec_vaapi="yes"
+  ],[
+    AS_IF([test -n "${enable_libva}"], [
+      AC_MSG_ERROR([libva is present but libavcodec/vaapi.h is missing])
+    ], [
+      AC_MSG_WARN([libva is present but libavcodec/vaapi.h is missing ])
+    ])
+  ])
+  VLC_RESTORE_FLAGS
 ])
 AM_CONDITIONAL([HAVE_AVCODEC_VAAPI], [test "${have_avcodec_vaapi}" = "yes"])
 
diff --git a/modules/codec/Makefile.am b/modules/codec/Makefile.am
index e013263..d1d7332 100644
--- a/modules/codec/Makefile.am
+++ b/modules/codec/Makefile.am
@@ -270,14 +270,27 @@ endif
 
 ### avcodec hardware acceleration ###
 
-libvaapi_plugin_la_SOURCES = \
+libvaapi_drm_plugin_la_SOURCES = \
 	video_chroma/copy.c video_chroma/copy.h \
 	codec/avcodec/vaapi.c
-libvaapi_plugin_la_CFLAGS = $(AM_CFLAGS) \
-	$(LIBVA_CFLAGS) $(X_CFLAGS) $(AVCODEC_CFLAGS)
-libvaapi_plugin_la_LIBADD = $(LIBVA_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lX11
+libvaapi_drm_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DVLC_VA_BACKEND_DRM
+libvaapi_drm_plugin_la_CFLAGS = $(AM_CFLAGS) \
+	$(LIBVA_DRM_CFLAGS) $(AVCODEC_CFLAGS)
+libvaapi_drm_plugin_la_LIBADD = $(LIBVA_DRM_LIBS)
+libvaapi_x11_plugin_la_SOURCES = \
+	video_chroma/copy.c video_chroma/copy.h \
+	codec/avcodec/vaapi.c
+libvaapi_x11_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DVLC_VA_BACKEND_XLIB
+libvaapi_x11_plugin_la_CFLAGS = $(AM_CFLAGS) \
+	$(LIBVA_X11_CFLAGS) $(X_CFLAGS) $(AVCODEC_CFLAGS)
+libvaapi_x11_plugin_la_LIBADD = $(LIBVA_X11_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lX11
 if HAVE_AVCODEC_VAAPI
-codec_LTLIBRARIES += libvaapi_plugin.la
+if HAVE_VAAPI_DRM
+codec_LTLIBRARIES += libvaapi_drm_plugin.la
+endif
+if HAVE_VAAPI_X11
+codec_LTLIBRARIES += libvaapi_x11_plugin.la
+endif
 endif
 
 libdxva2_plugin_la_SOURCES = \
diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
index c85e122..cd0a278 100644
--- a/modules/codec/avcodec/vaapi.c
+++ b/modules/codec/avcodec/vaapi.c
@@ -30,12 +30,20 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_fourcc.h>
-#include <vlc_xlib.h>
 
+#ifdef VLC_VA_BACKEND_XLIB
+# include <vlc_xlib.h>
+# include <va/va_x11.h>
+#endif
+#ifdef VLC_VA_BACKEND_DRM
+# include <sys/types.h>
+# include <sys/stat.h>
+# include <fcntl.h>
+# include <vlc_fs.h>
+# include <va/va_drm.h>
+#endif
 #include <libavcodec/avcodec.h>
 #include <libavcodec/vaapi.h>
-#include <X11/Xlib.h>
-#include <va/va_x11.h>
 
 #include "avcodec.h"
 #include "va.h"
@@ -50,11 +58,16 @@ static int Create( vlc_va_t *, AVCodecContext *, const es_format_t * );
 static void Delete( vlc_va_t * );
 
 vlc_module_begin ()
-    set_description( N_("Video Acceleration (VA) API") )
+#if defined (VLC_VA_BACKEND_XLIB)
+    set_description( N_("Video Acceleration (VA) API / X11") )
+#elif defined (VLC_VA_BACKEND_DRM)
+    set_description( N_("Video Acceleration (VA) API / DRM") )
+#endif
     set_capability( "hw decoder", 0 )
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_VCODEC )
     set_callbacks( Create, Delete )
+    add_shortcut( "vaapi" )
 vlc_module_end ()
 
 typedef struct
@@ -67,7 +80,12 @@ typedef struct
 
 struct vlc_va_sys_t
 {
-    Display      *p_display_x11;
+#ifdef VLC_VA_BACKEND_XLIB
+        Display  *p_display_x11;
+#endif
+#ifdef VLC_VA_BACKEND_DRM
+        int       drm_fd;
+#endif
     VADisplay     p_display;
 
     VAConfigID    i_config_id;
@@ -138,6 +156,7 @@ static int Open( vlc_va_t *va, int i_codec_id, int i_thread_count )
     sys->image.image_id = VA_INVALID_ID;
 
     /* Create a VA display */
+#ifdef VLC_VA_BACKEND_XLIB
     sys->p_display_x11 = XOpenDisplay(NULL);
     if( !sys->p_display_x11 )
     {
@@ -146,6 +165,17 @@ static int Open( vlc_va_t *va, int i_codec_id, int i_thread_count )
     }
 
     sys->p_display = vaGetDisplay( sys->p_display_x11 );
+#endif
+#ifdef VLC_VA_BACKEND_DRM
+    sys->drm_fd = vlc_open("/dev/dri/card0", O_RDWR);
+    if( sys->drm_fd == -1 )
+    {
+        msg_Err( va, "Could not access rendering device: %m" );
+        goto error;
+    }
+
+    sys->p_display = vaGetDisplayDRM( sys->drm_fd );
+#endif
     if( !sys->p_display )
     {
         msg_Err( va, "Could not get a VAAPI device" );
@@ -219,8 +249,14 @@ error:
     free( va->description );
     if( sys->p_display != NULL )
         vaTerminate( sys->p_display );
+#ifdef VLC_VA_BACKEND_XLIB
     if( sys->p_display_x11 != NULL )
         XCloseDisplay( sys->p_display_x11 );
+#endif
+#ifdef VLC_VA_BACKEND_DRM
+    if( sys->drm_fd != -1 )
+        close( sys->drm_fd );
+#endif
     free( sys );
     return VLC_EGENERIC;
 }
@@ -531,7 +567,12 @@ static void Close( vlc_va_sys_t *sys )
     if( sys->i_config_id != VA_INVALID_ID )
         vaDestroyConfig( sys->p_display, sys->i_config_id );
     vaTerminate( sys->p_display );
+#ifdef VLC_VA_BACKEND_XLIB
     XCloseDisplay( sys->p_display_x11 );
+#endif
+#ifdef VLC_VA_BACKEND_DRM
+    close( sys->drm_fd );
+#endif
 }
 
 static void Delete( vlc_va_t *va )
@@ -545,11 +586,13 @@ static void Delete( vlc_va_t *va )
 static int Create( vlc_va_t *p_va, AVCodecContext *ctx,
                    const es_format_t *fmt )
 {
+#ifdef VLC_VA_BACKEND_XLIB
     if( !vlc_xlib_init( VLC_OBJECT(p_va) ) )
     {
         msg_Warn( p_va, "Ignoring VA API" );
         return VLC_EGENERIC;
     }
+#endif
 
     (void) fmt;
 



More information about the vlc-commits mailing list