<html><head></head><body><div class="gmail_quote">Le 1 juillet 2017 14:00:54 GMT+02:00, Oliver Collyer <ovcollyer@mac.com> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">Hello<br /><br />A little out of left-field this one but I wrote this vout plugin for a project I've been working on.<br /><br />It's kind of similar to vmem in that an application can use this plugin to retrieve the decoder/filtered surfaces, but rather than receive a system memory copy of the surface (clean but slow) it instead allows these surfaces to be passed through directly to the caller. More importantly, it supports this for certain hardware formats too - currently DXVA2, VideoToolbox and VAAPI. There is no reason why D3D11VA, VDPAU etc couldn't be supported in future.<br /><br />I see this plugin as filling a small niche where an application already manages its own devices, contexts, textures etc and wants to embed video into this, but without losing the benefits of hardware acceleration.<br /><br />Im my video streaming application I take these hardware surfaces and use them to fill out SDL textures, thus avoiding any GPU-CPU-GPU copies. For DXVA2 this is done via StretchRect, for VideoToolbox I used the texture cache on both iOS/tvOS and macOS. For VAAPI I use the GLX extension. I had to add in a couple of functions to SDL to give deeper access to the underling devices/textures/surfaces, but it works very well.<br /><br />Initially I was hacking these changes into vmem but rather than break that interface or get bogged-down trying to support two different methods I thought it cleaner to write this as a new plugin.<br /><br />I understand from jb that there are possible plans in future for a plugin that writes to a texture, so maybe my plugin will be redundant, I'm not sure, but I'm offering it anyway, in case you want to include it, or in case someone wants to use it in their own project.<br /><br />Cheers<br /><br />Oliver<br /><br />---<br /> include/vlc/libvlc_media_player.h | 108 +++++++<br /> lib/libvlc.sym                    |   1 +<br /> lib/media_player.c                |  32 ++<br /> modules/MODULES_LIST              |   1 +<br /> modules/video_output/<a href="http://Makefile.am">Makefile.am</a>  |  33 ++<br /> modules/video_output/vbridge.c    | 615 ++++++++++++++++++++++++++++++++++++++<br /> po/<a href="http://POTFILES.in">POTFILES.in</a>                    |   1 +<br /> 7 files changed, 791 insertions(+)<br /> create mode 100644 modules/video_output/vbridge.c<br /><br />diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h<br />index 160cdfbaa8..72be05bb9b 100644<br />--- a/include/vlc/libvlc_media_player.h<br />+++ b/include/vlc/libvlc_media_player.h<br />@@ -457,6 +457,114 @@ void libvlc_video_set_format_callbacks( libvlc_media_player_t *mp,<br />                                         libvlc_video_cleanup_cb cleanup );<br /> <br /> /**<br />+ * Callback prototype to configure format for video bridge output.<br />+ *<br />+ * This callback gets the format of the video as output by the video decoder<br />+ * and the chain of video filters (if any). It can opt to change any parameter<br />+ * as it needs. In that case, LibVLC will attempt to convert the video format<br />+ * (rescaling and chroma conversion) but these operations can be CPU intensive.<br />+ *<br />+ * The device pointer must be set to a valid D3D9 device in the case of DXVA2 or<br />+ * a valid VADisplay in the case of VAAPI. This is used by libVLC to initialize<br />+ * the hardware decoder and create the hardware surfaces that are later passed<br />+ * to the prepare and display callbacks.<br />+ *<br />+ * \param opaque pointer to the private pointer passed to<br />+ *               libvlc_media_player_set_vbridge_callbacks() [IN/OUT]<br />+ * \param chroma pointer to the 4 bytes video format identifier [IN/OUT]<br />+ * \param width pointer to the pixel width [IN/OUT]<br />+ * \param height pointer to the pixel height [IN/OUT]<br />+ * \param x_offset pointer to the pixel x offset [IN/OUT]<br />+ * \param y_offset pointer to the pixel y offset [IN/OUT]<br />+ * \param visible_width pointer to the pixel visible width [IN/OUT]<br />+ * \param visible_height pointer to the pixel visible height [IN/OUT]<br />+ * \param device pointer to the platform-specific device pointer [OUT]<br />+ *<br />+ */<br />+typedef void (*libvlc_vbridge_format_cb)(void **opaque, char *chroma,<br />+                                         unsigned *width, unsigned *height,<br />+                                         unsigned *x_offset, unsigned *y_offset,<br />+                                         unsigned *visible_width,<br />+                                         unsigned *visible_height,<br />+                                         void **device);<br />+<br />+/**<br />+ * Callback prototype to cleanup resources for video bridge output.<br />+ *<br />+ * \param opaque private pointer as passed to<br />+ *               libvlc_media_player_set_vbridge_callbacks()<br />+ *               (and possibly modified by @ref libvlc_vbridge_format_cb) [IN]<br />+ */<br />+typedef void (*libvlc_vbridge_cleanup_cb)(void *opaque);<br />+<br />+/**<br />+ * Callback prototype to prepare a picture for video bridge output.<br />+ *<br />+ * When the video frame decoding is complete, the prepare callback is invoked.<br />+ * This callback might not be needed at all. It is only an indication that the<br />+ * application can now read the pixel values if it needs to.<br />+ *<br />+ * If the picture is a software surface then planes[] will point to system<br />+ * memory and pitches[] and lines[] will be valid. The number and layout of the<br />+ * planes will depend on the chroma.<br />+ *<br />+ * If the picture is a hardware surface then planes[0] should be cast to the<br />+ * appropriate type (IDirect3D9Surface, CVPixelBuffer or VASurfaceID) and the<br />+ * pitches[0] and lines[0] entries will be zero.<br />+ *<br />+ * \param opaque private pointer as passed to<br />+ *               libvlc_media_player_set_vbridge_callbacks()<br />+ *               (and possibly modified by @ref libvlc_vbridge_format_cb) [IN]<br />+ * \param planes start address of the pixel planes[IN]<br />+ * \param pitches table of scanline pitches in bytes for each pixel plane [IN]<br />+ * \param lines table of scanlines count for each plane [IN]<br />+ */<br />+typedef void (*libvlc_vbridge_prepare_cb)(void *opaque, void *const *planes,<br />+                                          unsigned *pitches, unsigned *lines);<br />+<br />+/**<br />+ * Callback prototype to display a picture for video bridge output.<br />+ *<br />+ * When the video frame needs to be shown, as determined by the media playback<br />+ * clock, the display callback is invoked.<br />+ *<br />+ * If the picture is a software surface then planes[] will point to system<br />+ * memory and pitches[] and lines[] will be valid. The number and layout of the<br />+ * planes will depend on the chroma.<br />+ *<br />+ * If the picture is a hardware surface then planes[0] should be cast to the<br />+ * appropriate type (IDirect3D9Surface, CVPixelBuffer or VASurfaceID) and the<br />+ * pitches[0] and lines[0] entries will be zero.<br />+ *<br />+ * \param opaque private pointer as passed to<br />+ *               libvlc_media_player_set_vbridge_callbacks()<br />+ *               (and possibly modified by @ref libvlc_vbridge_format_cb) [IN]<br />+ * \param planes start address of the pixel planes[IN]<br />+ * \param pitches table of scanline pitches in bytes for each pixel plane [IN]<br />+ * \param lines table of scanlines count for each plane [IN]<br />+ */<br />+typedef void (*libvlc_vbridge_display_cb)(void *opaque, void *const *planes,<br />+                                          unsigned *pitches, unsigned *lines);<br />+<br />+/**<br />+ * Set callbacks and private data for video bridge output.<br />+ *<br />+ * \param mp the media player<br />+ * \param format callback to configure format<br />+ * \param cleanup callback to cleanup resources<br />+ * \param prepare callback to prepare a picture<br />+ * \param display callback to display a picture<br />+ * \param opaque private pointer<br />+ */<br />+LIBVLC_API<br />+void libvlc_media_player_set_vbridge_callbacks(libvlc_media_player_t *mp,<br />+                                               libvlc_vbridge_format_cb format,<br />+                                               libvlc_vbridge_cleanup_cb cleanup,<br />+                                               libvlc_vbridge_prepare_cb prepare,<br />+                                               libvlc_vbridge_display_cb display,<br />+                                               void *opaque);<br />+<br />+/**<br />  * Set the NSView handler where the media player should render its video output.<br />  *<br />  * Use the vout called "macosx".<br />diff --git a/lib/libvlc.sym b/lib/libvlc.sym<br />index caa55981bf..9fb3be8707 100644<br />--- a/lib/libvlc.sym<br />+++ b/lib/libvlc.sym<br />@@ -203,6 +203,7 @@ libvlc_media_player_stop<br /> libvlc_media_player_will_play<br /> libvlc_media_player_navigate<br /> libvlc_media_player_set_video_title_display<br />+libvlc_media_player_set_vbridge_callbacks<br /> libvlc_media_release<br /> libvlc_media_retain<br /> libvlc_media_save_meta<br />diff --git a/lib/media_player.c b/lib/media_player.c<br />index dc17f7765d..9d56402cd7 100644<br />--- a/lib/media_player.c<br />+++ b/lib/media_player.c<br />@@ -693,6 +693,12 @@ libvlc_media_player_new( libvlc_instance_t *instance )<br />     var_Create (mp, "saturation", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);<br />     var_Create (mp, "gamma", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);<br /> <br />+    var_Create (mp, "vbridge-format", VLC_VAR_ADDRESS);<br />+    var_Create (mp, "vbridge-cleanup", VLC_VAR_ADDRESS);<br />+    var_Create (mp, "vbridge-prepare", VLC_VAR_ADDRESS);<br />+    var_Create (mp, "vbridge-display", VLC_VAR_ADDRESS);<br />+    var_Create (mp, "vbridge-opaque", VLC_VAR_ADDRESS);<br />+<br />      /* Audio */<br />     var_Create (mp, "aout", VLC_VAR_STRING | VLC_VAR_DOINHERIT);<br />     var_Create (mp, "audio-device", VLC_VAR_STRING);<br />@@ -1115,6 +1121,32 @@ void libvlc_video_set_format( libvlc_media_player_t *mp, const char *chroma,<br /> }<br /> <br /> /**************************************************************************<br />+ * set_vbridge_callbacks<br />+ **************************************************************************/<br />+void libvlc_media_player_set_vbridge_callbacks(libvlc_media_player_t *mp,<br />+                                               libvlc_vbridge_format_cb format,<br />+                                               libvlc_vbridge_cleanup_cb cleanup,<br />+                                               libvlc_vbridge_prepare_cb prepare,<br />+                                               libvlc_vbridge_display_cb display,<br />+                                               void *opaque)<br />+{<br />+    var_SetAddress(mp, "vbridge-format", format);<br />+    var_SetAddress(mp, "vbridge-cleanup", cleanup);<br />+    var_SetAddress(mp, "vbridge-prepare", prepare);<br />+    var_SetAddress(mp, "vbridge-display", display);<br />+    var_SetAddress(mp, "vbridge-opaque", opaque);<br />+#ifdef _WIN32<br />+    var_SetString(mp, "avcodec-hw", "dxva2");<br />+#elif defined(__linux__)<br />+    var_SetString(mp, "avcodec-hw", "vaapi");<br />+#else<br />+    var_SetString(mp, "avcodec-hw", "none");<br />+#endif<br />+    var_SetString(mp, "vout", "vbridge");<br />+    var_SetString(mp, "window", "none");<br />+}<br />+<br />+/**************************************************************************<br />  * set_nsobject<br />  **************************************************************************/<br /> void libvlc_media_player_set_nsobject( libvlc_media_player_t *p_mi,<br />diff --git a/modules/MODULES_LIST b/modules/MODULES_LIST<br />index 04468e438d..0db5467123 100644<br />--- a/modules/MODULES_LIST<br />+++ b/modules/MODULES_LIST<br />@@ -421,6 +421,7 @@ $Id$<br />  * vaapi_drm: VAAPI hardware-accelerated decoding with drm backend<br />  * vaapi_filters: VAAPI hardware-accelerated deinterlacing/adjust/sharpen/chroma filters<br />  * vaapi_x11: VAAPI hardware-accelerated decoding with x11 backend<br />+ * vbridge: video bridge output<br />  * vc1: VC-1 Video demuxer<br />  * vcd: input module for accessing Video CDs<br />  * vdpau_adjust: VDPAU color adjust video filter<br />diff --git a/modules/video_output/<a href="http://Makefile.am">Makefile.am</a> b/modules/video_output/<a href="http://Makefile.am">Makefile.am</a><br />index 2e7c5d8ba7..7407896569 100644<br />--- a/modules/video_output/<a href="http://Makefile.am">Makefile.am</a><br />+++ b/modules/video_output/<a href="http://Makefile.am">Makefile.am</a><br />@@ -440,6 +440,39 @@ vout_LTLIBRARIES += libevas_<a href="http://plugin.la">plugin.la</a><br /> endif<br /> <br /> <br />+### Video Bridge ###<br />+libvbridge_plugin_la_SOURCES = video_output/vbridge.c<br />+if HAVE_AVCODEC_DXVA2<br />+libvbridge_plugin_la_CFLAGS = $(AM_CFLAGS) -DUSE_DXVA2<br />+libvbridge_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'<br />+endif<br />+if HAVE_OSX<br />+libvbridge_plugin_la_SOURCES += codec/vt_utils.c codec/vt_utils.h<br />+libvbridge_plugin_la_CFLAGS = $(AM_CFLAGS) -DUSE_VTBOX<br />+libvbridge_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)' \<br />+ -Wl,-framework,CoreFoundation,-framework,CoreVideo<br />+endif<br />+if HAVE_IOS<br />+libvbridge_plugin_la_SOURCES += codec/vt_utils.c codec/vt_utils.h<br />+libvbridge_plugin_la_CFLAGS = $(AM_CFLAGS) -DUSE_VTBOX<br />+libvbridge_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)' \<br />+ -Wl,-framework,CoreFoundation,-framework,CoreVideo<br />+endif<br />+if HAVE_TVOS<br />+libvbridge_plugin_la_SOURCES += codec/vt_utils.c codec/vt_utils.h<br />+libvbridge_plugin_la_CFLAGS = $(AM_CFLAGS) -DUSE_VTBOX<br />+libvbridge_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)' \<br />+ -Wl,-framework,CoreFoundation,-framework,CoreVideo<br />+endif<br />+if HAVE_AVCODEC_VAAPI<br />+libvbridge_plugin_la_SOURCES += hw/vaapi/vlc_vaapi.c hw/vaapi/vlc_vaapi.h<br />+libvbridge_plugin_la_CFLAGS = $(AM_CFLAGS) -DUSE_VAAPI<br />+libvbridge_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'<br />+libvbridge_plugin_la_LIBADD = $(LIBVA_LIBS) libvlc_vaapi_<a href="http://instance.la">instance.la</a><br />+endif<br />+vout_LTLIBRARIES += libvbridge_<a href="http://plugin.la">plugin.la</a><br />+<br />+<br /> ### Common ###<br /> <br /> libflaschen_plugin_la_SOURCES = video_output/flaschen.c<br />diff --git a/modules/video_output/vbridge.c b/modules/video_output/vbridge.c<br />new file mode 100644<br />index 0000000000..839b51526e<br />--- /dev/null<br />+++ b/modules/video_output/vbridge.c<br />@@ -0,0 +1,615 @@<br />+/*****************************************************************************<br />+ * vbridge.c: video bridge driver for vlc<br />+ *****************************************************************************<br />+ * Copyright (C) 2017 VLC authors and VideoLAN<br />+ *<br />+ * Authors: Oliver Collyer <ovcollyer@mac.com><br />+ *<br />+ * This program is free software; you can redistribute it and/or modify it<br />+ * under the terms of the GNU Lesser General Public License as published by<br />+ * the Free Software Foundation; either version 2.1 of the License, or<br />+ * (at your option) any later version.<br />+ *<br />+ * This program is distributed in the hope that it will be useful,<br />+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br />+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />+ * GNU Lesser General Public License for more details.<br />+ *<br />+ * You should have received a copy of the GNU Lesser General Public License<br />+ * along with this program; if not, write to the Free Software Foundation,<br />+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br />+ *****************************************************************************/<br />+<br />+/*****************************************************************************<br />+ * Preamble<br />+ *****************************************************************************/<br />+#ifdef HAVE_CONFIG_H<br />+# include "config.h"<br />+#endif<br />+<br />+#include <assert.h><br />+<br />+#include <vlc_common.h><br />+#include <vlc_plugin.h><br />+#include <vlc_vout_display.h><br />+#include <vlc_picture_pool.h><br />+<br />+#ifdef USE_DXVA2<br />+#include <d3d9.h><br />+#include "../video_chroma/d3d9_fmt.h"<br />+#elif defined(USE_VTBOX)<br />+#import <CoreVideo/CoreVideo.h><br />+#include "../codec/vt_utils.h"<br />+#elif defined(USE_VAAPI)<br />+#include <va/va.h><br />+#include "../hw/vaapi/vlc_vaapi.h"<br />+#endif<br />+<br />+/*****************************************************************************<br />+ * Module descriptor<br />+ *****************************************************************************/<br />+static int  Open (vlc_object_t *);<br />+static void Close(vlc_object_t *);<br />+<br />+vlc_module_begin()<br />+    set_shortname(N_("Video bridge"))<br />+    set_description(N_("Video bridge output"))<br />+    set_category(CAT_VIDEO)<br />+    set_subcategory(SUBCAT_VIDEO_VOUT)<br />+    set_capability("vout display", 0)<br />+    set_callbacks(Open, Close)<br />+vlc_module_end()<br />+<br />+/*****************************************************************************<br />+ * Local prototypes<br />+ *****************************************************************************/<br />+struct vout_display_sys_t<br />+{<br />+    picture_pool_t *pool;<br />+    picture_t *prev_pic;<br />+    bool hw_surfaces;<br />+<br />+#ifdef USE_VAAPI<br />+    VADisplay dpy;<br />+    VABufferID config_id;<br />+    VABufferID context_id;<br />+#endif<br />+<br />+    void (*cleanup)(void *);<br />+    void (*prepare)(void *, void *const *, unsigned *, unsigned *);<br />+    void (*display)(void *, void *const *, unsigned *, unsigned *);<br />+    void *opaque;<br />+    void *device;<br />+};<br />+<br />+typedef void (*vlc_format_cb)(void **, char *,<br />+                              unsigned *, unsigned *,<br />+                              unsigned *, unsigned *,<br />+                              unsigned *, unsigned *,<br />+                              void **);<br />+<br />+static picture_pool_t *Pool(vout_display_t *, unsigned);<br />+static void SoftwareSurfacePrepare(vout_display_t *, picture_t *, subpicture_t *);<br />+static void SoftwareSurfaceDisplay(vout_display_t *, picture_t *, subpicture_t *);<br />+static void HardwareSurfacePrepare(vout_display_t *, picture_t *, subpicture_t *);<br />+static void HardwareSurfaceDisplay(vout_display_t *, picture_t *, subpicture_t *);<br />+static int Control(vout_display_t *, int, va_list);<br />+<br />+/*****************************************************************************<br />+ * Create the video bridge output<br />+ *****************************************************************************/<br />+static int Open(vlc_object_t *object)<br />+{<br />+    vout_display_t *vd = (vout_display_t *)object;<br />+<br />+    vlc_format_cb format = var_InheritAddress(vd, "vbridge-format");<br />+    if (!format)<br />+    {<br />+        msg_Err(vd, "Invalid vbridge-format callback");<br />+        return VLC_EGENERIC;<br />+    }<br />+<br />+    vout_display_sys_t *sys = calloc(1, sizeof(*sys));<br />+    if (unlikely(!sys))<br />+        return VLC_ENOMEM;<br />+<br />+    sys->cleanup = var_InheritAddress(vd, "vbridge-cleanup");<br />+    sys->prepare = var_InheritAddress(vd, "vbridge-prepare");<br />+    sys->display = var_InheritAddress(vd, "vbridge-display");<br />+    sys->opaque  = var_InheritAddress(vd, "vbridge-opaque");<br />+<br />+#ifdef USE_VAAPI<br />+    sys->config_id = VA_INVALID_ID;<br />+    sys->context_id = VA_INVALID_ID;<br />+#endif<br />+<br />+    video_format_t fmt;<br />+    video_format_ApplyRotation(&fmt, &vd->fmt);<br />+<br />+    char chroma[5];<br />+    memcpy(chroma, &fmt.i_chroma, 4);<br />+    chroma[4] = '\0';<br />+<br />+    format(&sys->opaque,<br />+          chroma,<br />+          &fmt.i_width, &fmt.i_height,<br />+          &fmt.i_x_offset, &fmt.i_y_offset,<br />+          &fmt.i_visible_width, &fmt.i_visible_height,<br />+          &sys->device);<br />+<br />+    fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma);<br />+    if (!fmt.i_chroma)<br />+    {<br />+        msg_Err(vd, "Invalid chroma requested (%s)", chroma);<br />+        free(sys);<br />+        return VLC_EGENERIC;<br />+    }<br />+<br />+    switch (fmt.i_chroma)<br />+    {<br />+    case VLC_CODEC_RGB15:<br />+        fmt.i_rmask = 0x001f;<br />+        fmt.i_gmask = 0x03e0;<br />+        fmt.i_bmask = 0x7c00;<br />+        break;<br />+    case VLC_CODEC_RGB16:<br />+        fmt.i_rmask = 0x001f;<br />+        fmt.i_gmask = 0x07e0;<br />+        fmt.i_bmask = 0xf800;<br />+        break;<br />+    case VLC_CODEC_RGB24:<br />+    case VLC_CODEC_RGB32:<br />+        fmt.i_rmask = 0xff0000;<br />+        fmt.i_gmask = 0x00ff00;<br />+        fmt.i_bmask = 0x0000ff;<br />+        break;<br />+    default:<br />+        fmt.i_rmask = 0;<br />+        fmt.i_gmask = 0;<br />+        fmt.i_bmask = 0;<br />+        break;<br />+    }<br />+<br />+#ifdef USE_DXVA2<br />+    if (vd->fmt.i_chroma == VLC_CODEC_D3D9_OPAQUE ||<br />+        vd->fmt.i_chroma == VLC_CODEC_D3D9_OPAQUE_10B)<br />+        sys->hw_surfaces = true;<br />+#elif defined(USE_VTBOX)<br />+    if (vd->fmt.i_chroma == VLC_CODEC_CVPX_UYVY ||<br />+        vd->fmt.i_chroma == VLC_CODEC_CVPX_NV12 ||<br />+        vd->fmt.i_chroma == VLC_CODEC_CVPX_I420 ||<br />+        vd->fmt.i_chroma == VLC_CODEC_CVPX_BGRA)<br />+        sys->hw_surfaces = true;<br />+#elif defined(USE_VAAPI)<br />+    if (vd->fmt.i_chroma == VLC_CODEC_VAAPI_420)<br />+        sys->hw_surfaces = true;<br />+#endif<br />+    if (sys->hw_surfaces)<br />+        msg_Dbg(vd, "Using hardware surfaces");<br />+<br />+    vout_display_info_t info = vd->info;<br />+    info.has_hide_mouse = true;<br />+<br />+    vd->sys     = sys;<br />+    vd->fmt     = fmt;<br />+    vd->info    = info;<br />+    vd->pool    = Pool;<br />+    vd->prepare = sys->hw_surfaces ? HardwareSurfacePrepare : SoftwareSurfacePrepare;<br />+    vd->display = sys->hw_surfaces ? HardwareSurfaceDisplay : SoftwareSurfaceDisplay;<br />+    vd->control = Control;<br />+    vd->manage  = NULL;<br />+<br />+    vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height);<br />+    vout_display_DeleteWindow(vd, NULL);<br />+<br />+    return VLC_SUCCESS;<br />+}<br />+<br />+/*****************************************************************************<br />+ * Destroy the video bridge output<br />+ *****************************************************************************/<br />+static void Close(vlc_object_t *object)<br />+{<br />+    vout_display_t *vd = (vout_display_t *)object;<br />+    vout_display_sys_t *sys = vd->sys;<br />+<br />+    if (sys->prev_pic)<br />+        picture_Release(sys->prev_pic);<br />+<br />+#ifdef USE_VAAPI<br />+    if (sys->context_id != VA_INVALID_ID)<br />+        vlc_vaapi_DestroyContext(object, sys->dpy, sys->context_id);<br />+#endif<br />+    if (sys->pool != NULL)<br />+        picture_pool_Release(sys->pool);<br />+#ifdef USE_VAAPI<br />+    if (sys->config_id != VA_INVALID_ID)<br />+        vlc_vaapi_DestroyConfig(object, sys->dpy, sys->config_id);<br />+    if (sys->dpy != NULL)<br />+        vlc_vaapi_ReleaseInstance(sys->dpy);<br />+#endif<br />+<br />+    if (sys->cleanup)<br />+        sys->cleanup(sys->opaque);<br />+<br />+    free(sys);<br />+}<br />+<br />+#ifdef USE_DXVA2<br />+<br />+/*****************************************************************************<br />+ * Destroy a single DXVA2 picture<br />+ *****************************************************************************/<br />+static void DestroyPoolPicture(picture_t *picture)<br />+{<br />+    picture_sys_t *p_sys = (picture_sys_t *)picture->p_sys;<br />+<br />+    if (p_sys->surface)<br />+        IDirect3DSurface9_Release(p_sys->surface);<br />+    free(p_sys);<br />+    free(picture);<br />+}<br />+<br />+/*****************************************************************************<br />+ * Create the DXVA2 picture pool<br />+ *****************************************************************************/<br />+static picture_pool_t *Pool(vout_display_t *vd, unsigned count)<br />+{<br />+    vout_display_sys_t *sys = vd->sys;<br />+<br />+    if (sys->pool != NULL)<br />+        return sys->pool;<br />+<br />+    if (!sys->hw_surfaces)<br />+    {<br />+        sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);<br />+        return sys->pool;<br />+    }<br />+<br />+    LPDIRECT3DDEVICE9 d3ddev = (LPDIRECT3DDEVICE9)sys->device;<br />+    if (!d3ddev)<br />+    {<br />+       msg_Err(vd, "Invalid D3D9 display device");<br />+       return NULL;<br />+    }<br />+<br />+    D3DFORMAT format;<br />+    switch (vd->fmt.i_chroma)<br />+    {<br />+    case VLC_CODEC_D3D9_OPAQUE_10B:<br />+        format = MAKEFOURCC('P','0','1','0');<br />+        break;<br />+    default:<br />+        format = MAKEFOURCC('N','V','1','2');<br />+        break;<br />+    }<br />+<br />+    picture_t** pictures = calloc(count, sizeof(*pictures));<br />+    if (unlikely(!pictures))<br />+        goto error;<br />+<br />+    for (unsigned int i = 0; i < count; i++)<br />+    {<br />+        picture_sys_t *picsys = calloc(1, sizeof(*picsys));<br />+        if (unlikely(!picsys))<br />+            goto error;<br />+<br />+        HRESULT hr = IDirect3DDevice9_CreateOffscreenPlainSurface(d3ddev,<br />+                                                              vd->fmt.i_width,<br />+                                                              vd->fmt.i_height,<br />+                                                              format,<br />+                                                              D3DPOOL_DEFAULT,<br />+                                                              &picsys->surface,<br />+                                                              NULL);<br />+        if (FAILED(hr))<br />+        {<br />+            msg_Err(vd, "Failed to create D3D9 surface");<br />+            free(picsys);<br />+            goto error;<br />+        }<br />+<br />+        picture_resource_t picture_resource;<br />+        picture_resource.p_sys = picsys;<br />+        picture_resource.pf_destroy = DestroyPoolPicture;<br />+<br />+        picture_t *picture = picture_NewFromResource(&vd->fmt, &picture_resource);<br />+        if (unlikely(picture == NULL))<br />+        {<br />+            free(picsys);<br />+            goto error;<br />+        }<br />+<br />+        pictures[i] = picture;<br />+    }<br />+<br />+    picture_pool_configuration_t pool_config;<br />+    memset(&pool_config, 0, sizeof(pool_config));<br />+    pool_config.picture_count = count;<br />+    pool_config.picture = pictures;<br />+<br />+    sys->pool = picture_pool_NewExtended(&pool_config);<br />+    if (!sys->pool)<br />+    {<br />+        msg_Err(vd, "Failed to create picture pool");<br />+        goto error;<br />+    }<br />+<br />+    return sys->pool;<br />+<br />+error:<br />+    if (pictures)<br />+    {<br />+        for (unsigned int i = 0; i < count; i++)<br />+            if (pictures[i])<br />+                DestroyPoolPicture(pictures[i]);<br />+        free(pictures);<br />+    }<br />+<br />+    return NULL;<br />+}<br />+<br />+#elif defined(USE_VAAPI)<br />+<br />+/*****************************************************************************<br />+ * Create the VAAPI picture pool<br />+ *****************************************************************************/<br />+static picture_pool_t *Pool(vout_display_t *vd, unsigned count)<br />+{<br />+    vout_display_sys_t *sys = vd->sys;<br />+    vlc_object_t *o = VLC_OBJECT(vd);<br />+<br />+    if (sys->pool != NULL)<br />+        return sys->pool;<br />+<br />+    if (!sys->hw_surfaces)<br />+    {<br />+        sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);<br />+        return sys->pool;<br />+    }<br />+<br />+    sys->dpy = (VADisplay)sys->device;<br />+    if (!sys->dpy)<br />+    {<br />+        msg_Err(vd, "Invalid VAAPI display device");<br />+        return NULL;<br />+    }<br />+<br />+    if (vlc_vaapi_Initialize(o, sys->dpy))<br />+    {<br />+        msg_Err(vd, "Failed to initialize VAAPI");<br />+        sys->dpy = NULL;<br />+        goto error;<br />+    }<br />+<br />+    if (vlc_vaapi_SetInstance(sys->dpy))<br />+    {<br />+        msg_Err(vd, "Failed to set VAAPI instance");<br />+        sys->dpy = NULL;<br />+        goto error;<br />+    }<br />+<br />+    sys->config_id = vlc_vaapi_CreateConfigChecked(o, sys->dpy, VAProfileNone,<br />+                                                   VAEntrypointVideoProc, 0);<br />+    if (sys->config_id == VA_INVALID_ID)<br />+    {<br />+        msg_Err(vd, "Failed to create VAAPI config");<br />+        goto error;<br />+    }<br />+<br />+    VASurfaceID *surfaces;<br />+    sys->pool = vlc_vaapi_PoolNew(o, sys->dpy, count, &surfaces, &vd->fmt,<br />+                                  VA_RT_FORMAT_YUV420, 0);<br />+    if (!sys->pool)<br />+    {<br />+        msg_Err(vd, "Failed to create VAAPI pool");<br />+        goto error;<br />+    }<br />+<br />+    sys->context_id = vlc_vaapi_CreateContext(o, sys->dpy, sys->config_id,<br />+                                              vd->fmt.i_width, vd->fmt.i_height,<br />+                                              VA_PROGRESSIVE, surfaces, count);<br />+    if (sys->context_id == VA_INVALID_ID)<br />+    {<br />+        msg_Err(vd, "Failed to create VAAPI context");<br />+        goto error;<br />+    }<br />+<br />+    return sys->pool;<br />+<br />+error:<br />+    if (sys->context_id != VA_INVALID_ID)<br />+        vlc_vaapi_DestroyContext(o, sys->dpy, sys->context_id);<br />+    if (sys->pool != NULL)<br />+        picture_pool_Release(sys->pool);<br />+    if (sys->config_id != VA_INVALID_ID)<br />+        vlc_vaapi_DestroyConfig(o, sys->dpy, sys->config_id);<br />+    if (sys->dpy != NULL)<br />+        vlc_vaapi_ReleaseInstance(sys->dpy);<br />+<br />+    return NULL;<br />+}<br />+<br />+#else<br />+<br />+/*****************************************************************************<br />+ * Create the generic picture pool<br />+ *****************************************************************************/<br />+static picture_pool_t *Pool(vout_display_t *vd, unsigned count)<br />+{<br />+    vout_display_sys_t *sys = vd->sys;<br />+<br />+    if (sys->pool != NULL)<br />+        return sys->pool;<br />+<br />+    sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);<br />+<br />+    return sys->pool;<br />+}<br />+<br />+#endif<br />+<br />+/*****************************************************************************<br />+ * Call the software surface prepare<br />+ *****************************************************************************/<br />+static void SoftwareSurfacePrepare(vout_display_t *vd, picture_t *pic, subpicture_t *subpic)<br />+{<br />+    vout_display_sys_t *sys = vd->sys;<br />+<br />+    if (sys->prepare != NULL)<br />+    {<br />+        void *planes[PICTURE_PLANE_MAX];<br />+        unsigned pitches[PICTURE_PLANE_MAX];<br />+        unsigned lines[PICTURE_PLANE_MAX];<br />+        for (unsigned int i = 0; i < PICTURE_PLANE_MAX; i++)<br />+        {<br />+            if (i < (unsigned int)pic->i_planes)<br />+            {<br />+                plane_t *p_src = pic->p+i;<br />+                planes[i] = p_src->p_pixels;<br />+                pitches[i] = p_src->i_pitch;<br />+                lines[i] = p_src->i_lines;<br />+            }<br />+            else<br />+            {<br />+                planes[i] = NULL;<br />+                pitches[i] = 0;<br />+                lines[i] = 0;<br />+            }<br />+        }<br />+        sys->prepare(sys->opaque, planes, pitches, lines);<br />+    }<br />+<br />+    VLC_UNUSED(subpic);<br />+}<br />+<br />+/*****************************************************************************<br />+ * Call the software surface display<br />+ *****************************************************************************/<br />+static void SoftwareSurfaceDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *subpic)<br />+{<br />+    vout_display_sys_t *sys = vd->sys;<br />+<br />+    if (sys->display != NULL)<br />+    {<br />+        void *planes[PICTURE_PLANE_MAX];<br />+        unsigned pitches[PICTURE_PLANE_MAX];<br />+        unsigned lines[PICTURE_PLANE_MAX];<br />+        for (unsigned int i = 0; i < PICTURE_PLANE_MAX; i++)<br />+        {<br />+            if (i < (unsigned int)pic->i_planes)<br />+            {<br />+                plane_t *p_src = pic->p+i;<br />+                planes[i] = p_src->p_pixels;<br />+                pitches[i] = p_src->i_pitch;<br />+                lines[i] = p_src->i_lines;<br />+            }<br />+            else<br />+            {<br />+                planes[i] = NULL;<br />+                pitches[i] = 0;<br />+                lines[i] = 0;<br />+            }<br />+        }<br />+        sys->display(sys->opaque, planes, pitches, lines);<br />+    }<br />+<br />+    if (sys->prev_pic)<br />+        picture_Release(sys->prev_pic);<br />+    sys->prev_pic = pic;<br />+<br />+    VLC_UNUSED(subpic);<br />+}<br />+<br />+/*****************************************************************************<br />+ * Call the hardware surface prepare<br />+ *****************************************************************************/<br />+static void HardwareSurfacePrepare(vout_display_t *vd, picture_t *pic, subpicture_t *subpic)<br />+{<br />+    vout_display_sys_t *sys = vd->sys;<br />+<br />+    if (sys->prepare)<br />+    {<br />+        void *planes[PICTURE_PLANE_MAX];<br />+        unsigned pitches[PICTURE_PLANE_MAX];<br />+        unsigned lines[PICTURE_PLANE_MAX];<br />+        for (unsigned int i = 0; i < PICTURE_PLANE_MAX; i++)<br />+        {<br />+            if (i == 0)<br />+            {<br />+#ifdef USE_DXVA2<br />+                if (pic->context)<br />+                    planes[i] = (void*)((struct va_pic_context*)pic->context)->picsys.surface;<br />+                else<br />+                    planes[i] = (void*)pic->p_sys->surface;<br />+#elif defined(USE_VTBOX)<br />+                planes[i] = (void*)cvpxpic_get_ref(pic);<br />+#elif defined(USE_VAAPI)<br />+                planes[i] = (void*)(uintptr_t)vlc_vaapi_PicGetSurface(pic);<br />+#else<br />+                planes[i] = NULL;<br />+#endif<br />+            }<br />+            else<br />+                planes[i] = NULL;<br />+            pitches[i] = 0;<br />+            lines[i] = 0;<br />+        }<br />+        sys->prepare(sys->opaque, planes, pitches, lines);<br />+    }<br />+<br />+    VLC_UNUSED(subpic);<br />+}<br />+<br />+/*****************************************************************************<br />+ * Call the hardware surface display<br />+ *****************************************************************************/<br />+static void HardwareSurfaceDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *subpic)<br />+{<br />+    vout_display_sys_t *sys = vd->sys;<br />+<br />+    if (sys->display)<br />+    {<br />+        void *planes[PICTURE_PLANE_MAX];<br />+        unsigned pitches[PICTURE_PLANE_MAX];<br />+        unsigned lines[PICTURE_PLANE_MAX];<br />+        for (unsigned int i = 0; i < PICTURE_PLANE_MAX; i++)<br />+        {<br />+            if (i == 0)<br />+            {<br />+#ifdef USE_DXVA2<br />+                if (pic->context)<br />+                    planes[i] = (void*)((struct va_pic_context*)pic->context)->picsys.surface;<br />+                else<br />+                    planes[i] = (void*)pic->p_sys->surface;<br />+#elif defined(USE_VTBOX)<br />+                planes[i] = (void*)cvpxpic_get_ref(pic);<br />+#elif defined(USE_VAAPI)<br />+                planes[i] = (void*)(uintptr_t)vlc_vaapi_PicGetSurface(pic);<br />+#else<br />+                planes[i] = NULL;<br />+#endif<br />+            }<br />+            else<br />+                planes[i] = NULL;<br />+            pitches[i] = 0;<br />+            lines[i] = 0;<br />+        }<br />+        sys->display(sys->opaque, planes, pitches, lines);<br />+    }<br />+<br />+    if (sys->prev_pic)<br />+        picture_Release(sys->prev_pic);<br />+    sys->prev_pic = pic;<br />+<br />+    VLC_UNUSED(subpic);<br />+}<br />+<br />+/* */<br />+static int Control(vout_display_t *vd, int query, va_list args)<br />+{<br />+    VLC_UNUSED(vd);<br />+    VLC_UNUSED(query);<br />+    VLC_UNUSED(args);<br />+<br />+    return VLC_EGENERIC;<br />+}<br />diff --git a/po/<a href="http://POTFILES.in">POTFILES.in</a> b/po/<a href="http://POTFILES.in">POTFILES.in</a><br />index 66ea2ddf6d..3197106a26 100644<br />--- a/po/<a href="http://POTFILES.in">POTFILES.in</a><br />+++ b/po/<a href="http://POTFILES.in">POTFILES.in</a><br />@@ -1138,6 +1138,7 @@ modules/video_output/win32/events.c<br /> modules/video_output/win32/glwin32.c<br /> modules/video_output/win32/wingdi.c<br /> modules/video_output/sdl.c<br />+modules/video_output/vbridge.c<br /> modules/video_output/vdummy.c<br /> modules/video_output/vmem.c<br /> modules/video_output/wayland/shell.c</pre></blockquote></div><br clear="all">No. Just no. This was discussed several times. This creates a tight coupling between the vodeo output core and LibVLC, which *will* break in future versions.<br>
<br>
If you want tight integration with the core, you write a plugin.<br>
-- <br>
Rémi Denis-Courmont<br>
Typed on an inconvenient virtual keyboard</body></html>