[vlc-devel] [PATCH 40/42] vout: request the vout with a video context

Steve Lhomme robux4 at ycbcr.xyz
Wed Oct 16 16:59:15 CEST 2019


instead of the decoder device
---
 include/vlc_vout_display.h             |  5 +++--
 modules/video_output/splitter.c        |  7 ++-----
 modules/video_output/win32/direct3d9.c |  6 +++++-
 src/input/decoder.c                    |  5 +----
 src/input/resource.c                   |  4 ++--
 src/input/resource.h                   |  2 +-
 src/video_output/display.c             | 10 ++--------
 src/video_output/video_output.c        | 18 ++++++++++++++----
 src/video_output/vout_internal.h       |  6 +++---
 src/video_output/vout_wrapper.c        |  6 +++---
 10 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/include/vlc_vout_display.h b/include/vlc_vout_display.h
index 1a6afe0da21..ed89eb56d22 100644
--- a/include/vlc_vout_display.h
+++ b/include/vlc_vout_display.h
@@ -307,9 +307,10 @@ struct vout_display_t {
  * Creates video output display.
  */
 VLC_API
-vout_display_t *vout_display_New(vlc_object_t *, const video_format_t *,
+vout_display_t *vout_display_New(vlc_object_t *,
+    const video_format_t *, vlc_video_context *,
     const vout_display_cfg_t *, const char *module,
-    vlc_decoder_device *, const vout_display_owner_t *);
+    const vout_display_owner_t *);
 
 /**
  * Destroys a video output display.
diff --git a/modules/video_output/splitter.c b/modules/video_output/splitter.c
index acfe02df5a5..8d6532ceb49 100644
--- a/modules/video_output/splitter.c
+++ b/modules/video_output/splitter.c
@@ -290,11 +290,8 @@ static int vlc_vidsplit_Open(vout_display_t *vd,
         }
 
         vdcfg.window = part->window;
-        vlc_decoder_device *dec_device = vlc_video_context_HoldDevice(ctx);
-        vout_display_t *display = vout_display_New(obj, &output->fmt, &vdcfg,
-                                                   modname, dec_device, NULL);
-        if (dec_device)
-            vlc_decoder_device_Release(dec_device);
+        vout_display_t *display = vout_display_New(obj, &output->fmt, ctx, &vdcfg,
+                                                   modname, NULL);
         if (display == NULL) {
             vout_window_Disable(part->window);
             vout_window_Delete(part->window);
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index 7c91f72b665..5e8d1d3d189 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -1662,8 +1662,12 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     if (d3d9_decoder != NULL && d3d9_decoder->device != NULL)
         D3D9_CloneExternal( &sys->hd3d, d3d9_decoder->device );
 
+    d3d9_video_context_t *octx = GetD3D9ContextPrivate(context);
     HRESULT hr;
-    hr = D3D9_CreateDevice(vd, &sys->hd3d, d3d9_decoder ? d3d9_decoder->adapter : -1, &sys->d3d_dev);
+    if (octx != NULL)
+        hr = D3D9_CreateDeviceExternal(octx->dev, &sys->hd3d, &sys->d3d_dev);
+    else
+        hr = D3D9_CreateDevice(vd, &sys->hd3d, d3d9_decoder ? d3d9_decoder->adapter : -1, &sys->d3d_dev);
 
     if (FAILED(hr)) {
         msg_Err( vd, "D3D9 Creation failed! (hr=0x%lX)", hr);
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 21f8154f944..7acc828a6fc 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -520,15 +520,12 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec, vlc_video_context *
         .dpb_size = dpb_size + p_dec->i_extra_picture_buffers + 1,
         .mouse_event = MouseEvent, .mouse_opaque = p_dec,
     };
-    vlc_decoder_device *dec_dev = p_owner->vctx ? vlc_video_context_HoldDevice(vctx) : NULL;
-    res = input_resource_StartVout( p_owner->p_resource, dec_dev, &cfg);
+    res = input_resource_StartVout( p_owner->p_resource, vctx, &cfg);
     if (res == 0)
     {
         p_owner->vout_thread_started = true;
         decoder_Notify(p_owner, on_vout_started, p_vout, vout_order);
     }
-    if (dec_dev)
-        vlc_decoder_device_Release(dec_dev);
     return res;
 }
 
diff --git a/src/input/resource.c b/src/input/resource.c
index 6522ad9056c..aa219845c58 100644
--- a/src/input/resource.c
+++ b/src/input/resource.c
@@ -435,11 +435,11 @@ out:
 }
 
 int input_resource_StartVout(input_resource_t *p_resource,
-                              vlc_decoder_device *dec_dev,
+                              vlc_video_context *vctx,
                               const vout_configuration_t *cfg)
 {
     vlc_mutex_lock( &p_resource->lock );
-    if (vout_Request(cfg, dec_dev, p_resource->p_input)) {
+    if (vout_Request(cfg, vctx, p_resource->p_input)) {
         input_resource_PutVoutLocked(p_resource, cfg->vout);
         vlc_mutex_unlock(&p_resource->lock);
         return -1;
diff --git a/src/input/resource.h b/src/input/resource.h
index e559c1633aa..a2990a013fb 100644
--- a/src/input/resource.h
+++ b/src/input/resource.h
@@ -41,7 +41,7 @@ vout_thread_t *input_resource_GetVoutDecoderDevice(input_resource_t *,
                                       const vout_configuration_t *,
                                       enum vlc_vout_order *order,
                                       vlc_decoder_device **);
-int input_resource_StartVout(input_resource_t *, vlc_decoder_device *, const vout_configuration_t *);
+int input_resource_StartVout(input_resource_t *, vlc_video_context *, const vout_configuration_t *);
 void input_resource_PutVout(input_resource_t *, vout_thread_t *);
 
 /**
diff --git a/src/video_output/display.c b/src/video_output/display.c
index f9fb3d0e7c2..556406f7c6d 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -729,9 +729,9 @@ void vout_SetDisplayViewpoint(vout_display_t *vd,
 
 vout_display_t *vout_display_New(vlc_object_t *parent,
                                  const video_format_t *source,
+                                 vlc_video_context *vctx,
                                  const vout_display_cfg_t *cfg,
                                  const char *module,
-                                 vlc_decoder_device *dec_device,
                                  const vout_display_owner_t *owner)
 {
     vout_display_priv_t *osys = vlc_custom_create(parent, sizeof (*osys),
@@ -770,11 +770,9 @@ vout_display_t *vout_display_New(vlc_object_t *parent,
     if (owner)
         vd->owner = *owner;
 
-    vlc_video_context *fake_vctx = vlc_video_context_Create(dec_device, VLC_VIDEO_CONTEXT_NONE, 0, NULL);
-
     if (vlc_module_load(vd, "vout display", module, module && *module != '\0',
                         vout_display_start, vd, &osys->cfg, &vd->fmt,
-                        fake_vctx) == NULL)
+                        vctx) == NULL)
         goto error;
 
 #if defined(__OS2__)
@@ -796,12 +794,8 @@ vout_display_t *vout_display_New(vlc_object_t *parent,
         video_format_Clean(&vd->fmt);
         goto error;
     }
-    if (fake_vctx)
-        vlc_video_context_Release(fake_vctx);
     return vd;
 error:
-    if (fake_vctx)
-        vlc_video_context_Release(fake_vctx);
     video_format_Clean(&vd->source);
     vlc_object_delete(vd);
     return NULL;
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 48b416043c0..86e18b14d5a 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -1499,7 +1499,7 @@ static void ThreadProcessMouseState(vout_thread_t *vout,
         vout->p->mouse_event(m, vout->p->mouse_opaque);
 }
 
-static int vout_Start(vout_thread_t *vout, vlc_decoder_device *dec_dev, const vout_configuration_t *cfg)
+static int vout_Start(vout_thread_t *vout, vlc_video_context *vctx, const vout_configuration_t *cfg)
 {
     vout_thread_sys_t *sys = vout->p;
     assert(!sys->dummy);
@@ -1537,6 +1537,16 @@ static int vout_Start(vout_thread_t *vout, vlc_decoder_device *dec_dev, const vo
     unsigned num, den;
 
     vlc_mutex_lock(&sys->window_lock);
+#ifndef NDEBUG
+    if (vctx)
+    {
+        // make sure the decoder device we receive matches the one we have cached
+        vlc_decoder_device *dec_device = vlc_video_context_HoldDevice(vctx);
+        assert(dec_device && dec_device == sys->dec_device);
+        vlc_decoder_device_Release(dec_device);
+    }
+#endif
+
     dcfg = sys->display_cfg;
 
     switch (sys->source.crop.mode) {
@@ -1565,7 +1575,7 @@ static int vout_Start(vout_thread_t *vout, vlc_decoder_device *dec_dev, const vo
     vlc_mutex_lock(&sys->display_lock);
     vlc_mutex_unlock(&sys->window_lock);
 
-    sys->display = vout_OpenWrapper(vout, sys->splitter_name, &dcfg, dec_dev);
+    sys->display = vout_OpenWrapper(vout, sys->splitter_name, &dcfg, vctx);
     if (sys->display == NULL) {
         vlc_mutex_unlock(&sys->display_lock);
         goto error;
@@ -2006,7 +2016,7 @@ static int vout_EnableWindow(const vout_configuration_t *cfg, const video_format
     return 0;
 }
 
-int vout_Request(const vout_configuration_t *cfg, vlc_decoder_device *dec_dev, input_thread_t *input)
+int vout_Request(const vout_configuration_t *cfg, vlc_video_context *vctx, input_thread_t *input)
 {
     vout_thread_t *vout = cfg->vout;
     vout_thread_sys_t *sys = vout->p;
@@ -2046,7 +2056,7 @@ int vout_Request(const vout_configuration_t *cfg, vlc_decoder_device *dec_dev, i
     sys->clock = cfg->clock;
     sys->delay = 0;
 
-    if (vout_Start(vout, dec_dev, cfg))
+    if (vout_Start(vout, vctx, cfg))
     {
         msg_Err(vout, "video output display creation failed");
         video_format_Clean(&sys->original);
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index 747f8934f71..7de42c39fea 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -215,11 +215,11 @@ vlc_decoder_device *vout_GetDevice(const vout_configuration_t *cfg);
  *
  * \param cfg the video configuration requested.
  * \param input used to get attachments for spu filters
- * \param dec_dev pointer to receive the decoder device reference to use with the vout or NULL
+ * \param vctx pointer to the video context to use with the vout or NULL
  * \retval 0 on success
  * \retval -1 on error
  */
-int vout_Request(const vout_configuration_t *cfg, vlc_decoder_device *dec_dev, input_thread_t *input);
+int vout_Request(const vout_configuration_t *cfg, vlc_video_context *vctx, input_thread_t *input);
 
 /**
  * Disables a vout.
@@ -275,7 +275,7 @@ void vout_IntfDeinit(vlc_object_t *);
 
 /* */
 vout_display_t *vout_OpenWrapper(vout_thread_t *, const char *,
-                     const vout_display_cfg_t *, vlc_decoder_device *);
+                     const vout_display_cfg_t *, vlc_video_context *);
 void vout_CloseWrapper(vout_thread_t *, vout_display_t *vd);
 
 /* */
diff --git a/src/video_output/vout_wrapper.c b/src/video_output/vout_wrapper.c
index db2d36e67c0..48e1ad8a88a 100644
--- a/src/video_output/vout_wrapper.c
+++ b/src/video_output/vout_wrapper.c
@@ -56,7 +56,7 @@ static void VoutViewpointMoved(void *sys, const vlc_viewpoint_t *vp)
  *****************************************************************************/
 vout_display_t *vout_OpenWrapper(vout_thread_t *vout,
                      const char *splitter_name, const vout_display_cfg_t *cfg,
-                     vlc_decoder_device *dec_device)
+                     vlc_video_context *vctx)
 {
     vout_thread_sys_t *sys = vout->p;
     vout_display_t *vd;
@@ -73,8 +73,8 @@ vout_display_t *vout_OpenWrapper(vout_thread_t *vout,
     else
         modlist = "splitter,none";
 
-    vd = vout_display_New(VLC_OBJECT(vout), &sys->original, cfg,
-                          modlist, sys->dec_device, &owner);
+    vd = vout_display_New(VLC_OBJECT(vout), &sys->original, vctx, cfg,
+                          modlist, &owner);
     free(modlistbuf);
 
     if (vd == NULL)
-- 
2.17.1



More information about the vlc-devel mailing list