[vlc-commits] display: use an optional callback to set the viewpoint

Steve Lhomme git at videolan.org
Fri Sep 11 13:35:23 CEST 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Wed Sep  2 10:54:44 2020 +0200| [e41f98e9c2315f34586f23e22a6501d3a33c90c3] | committer: Steve Lhomme

display: use an optional callback to set the viewpoint

In the future it may be called directly from the thread generating the event to
lower the latency.

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

 include/vlc_vout_display.h              | 14 +++++++++-----
 modules/video_output/caopengllayer.m    | 25 ++++++++++++-------------
 modules/video_output/ios.m              | 12 ++++++++----
 modules/video_output/macosx.m           | 11 +++++++----
 modules/video_output/opengl/display.c   | 10 +++++++---
 modules/video_output/win32/direct3d11.c | 28 +++++++++++++++-------------
 modules/video_output/win32/glwin32.c    | 13 ++++++++-----
 src/video_output/display.c              | 10 ++++++----
 8 files changed, 72 insertions(+), 51 deletions(-)

diff --git a/include/vlc_vout_display.h b/include/vlc_vout_display.h
index c0014b2924..ad78cc6c95 100644
--- a/include/vlc_vout_display.h
+++ b/include/vlc_vout_display.h
@@ -214,11 +214,6 @@ enum vout_display_query {
      *                      is necessary
      */
     VOUT_DISPLAY_CHANGE_SOURCE_CROP,
-
-    /**
-     * Notifies a change of VR/360° viewpoint.
-     */
-    VOUT_DISPLAY_CHANGE_VIEWPOINT,   /* const vlc_viewpoint_t * */
 };
 
 /**
@@ -359,6 +354,15 @@ struct vout_display_t {
      */
     int        (*control)(vout_display_t *, int query, va_list);
 
+    /**
+     * Notifies a change of VR/360° viewpoint.
+     *
+     * May be NULL.
+     *
+     * \param vp viewpoint to use on the next render
+     */
+    int (*set_viewpoint)(vout_display_t *, const vlc_viewpoint_t *vp);
+
     /**
      * Destroys the display.
      */
diff --git a/modules/video_output/caopengllayer.m b/modules/video_output/caopengllayer.m
index 5bf846ff0c..e322941003 100644
--- a/modules/video_output/caopengllayer.m
+++ b/modules/video_output/caopengllayer.m
@@ -107,6 +107,17 @@ struct gl_sys
     VLCCAOpenGLLayer *cgLayer;
 };
 
+static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
+{
+    vout_display_sys_t *sys = vd->sys;
+    if (OpenglLock(sys->gl))
+        return VLC_EGENERIC;
+
+    int ret = vout_display_opengl_SetViewpoint(sys->vgl, vp);
+    OpenglUnlock(sys->gl);
+    return ret;
+}
+
 /*****************************************************************************
  * Open: This function allocates and initializes the OpenGL vout method.
  *****************************************************************************/
@@ -201,6 +212,7 @@ static int Open (vout_display_t *vd, const vout_display_cfg_t *cfg,
         vd->prepare = PictureRender;
         vd->display = PictureDisplay;
         vd->control = Control;
+        vd->set_viewpoint = SetViewpoint;
         vd->close   = Close;
 
         if (OSX_SIERRA_AND_HIGHER) {
@@ -341,19 +353,6 @@ static int Control (vout_display_t *vd, int query, va_list ap)
             return VLC_SUCCESS;
         }
 
-        case VOUT_DISPLAY_CHANGE_VIEWPOINT:
-        {
-            int ret;
-
-            if (OpenglLock(sys->gl))
-                return VLC_EGENERIC;
-
-            ret = vout_display_opengl_SetViewpoint(sys->vgl,
-                                                   va_arg(ap, const vlc_viewpoint_t*));
-            OpenglUnlock(sys->gl);
-            return ret;
-        }
-
         case VOUT_DISPLAY_RESET_PICTURES:
             vlc_assert_unreachable ();
         default:
diff --git a/modules/video_output/ios.m b/modules/video_output/ios.m
index 2fb38e50b0..caaac6a947 100644
--- a/modules/video_output/ios.m
+++ b/modules/video_output/ios.m
@@ -144,6 +144,13 @@ static void *OurGetProcAddress(vlc_gl_t *gl, const char *name)
     return dlsym(RTLD_DEFAULT, name);
 }
 
+static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
+{
+    vout_display_sys_t *sys = vd->sys;
+    struct gl_sys *glsys = sys->gl->sys;
+    return vout_display_opengl_SetViewpoint (glsys->vgl, vp);
+}
+
 static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
                 video_format_t *fmt, vlc_video_context *context)
 {
@@ -212,6 +219,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
         vd->prepare = PictureRender;
         vd->display = PictureDisplay;
         vd->control = Control;
+        vd->set_viewpoint = SetViewpoint;
         vd->close   = Close;
 
         return VLC_SUCCESS;
@@ -273,10 +281,6 @@ static int Control(vout_display_t *vd, int query, va_list ap)
             return VLC_SUCCESS;
         }
 
-        case VOUT_DISPLAY_CHANGE_VIEWPOINT:
-            return vout_display_opengl_SetViewpoint(glsys->vgl,
-                                                    va_arg(ap, const vlc_viewpoint_t*));
-
         case VOUT_DISPLAY_RESET_PICTURES:
             vlc_assert_unreachable ();
         default:
diff --git a/modules/video_output/macosx.m b/modules/video_output/macosx.m
index b5075a83be..c8e8c0caef 100644
--- a/modules/video_output/macosx.m
+++ b/modules/video_output/macosx.m
@@ -131,6 +131,12 @@ static void *OurGetProcAddress(vlc_gl_t *gl, const char *name)
     return dlsym(RTLD_DEFAULT, name);
 }
 
+static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
+{
+    vout_display_sys_t *sys = vd->sys;
+    return vout_display_opengl_SetViewpoint (sys->vgl, vp);
+}
+
 static int Open (vout_display_t *vd, const vout_display_cfg_t *cfg,
                  video_format_t *fmt, vlc_video_context *context)
 {
@@ -244,6 +250,7 @@ static int Open (vout_display_t *vd, const vout_display_cfg_t *cfg,
         vd->prepare = PictureRender;
         vd->display = PictureDisplay;
         vd->control = Control;
+        vd->set_viewpoint = SetViewpoint;
         vd->close   = Close;
 
         /* */
@@ -387,10 +394,6 @@ static int Control (vout_display_t *vd, int query, va_list ap)
                 return VLC_SUCCESS;
             }
 
-            case VOUT_DISPLAY_CHANGE_VIEWPOINT:
-                return vout_display_opengl_SetViewpoint (sys->vgl,
-                                                         va_arg(ap, const vlc_viewpoint_t*));
-
             case VOUT_DISPLAY_RESET_PICTURES:
                 vlc_assert_unreachable ();
             default:
diff --git a/modules/video_output/opengl/display.c b/modules/video_output/opengl/display.c
index 084411d14b..cfe35db0f7 100644
--- a/modules/video_output/opengl/display.c
+++ b/modules/video_output/opengl/display.c
@@ -87,6 +87,12 @@ static void PictureRender (vout_display_t *, picture_t *, subpicture_t *, vlc_ti
 static void PictureDisplay (vout_display_t *, picture_t *);
 static int Control (vout_display_t *, int, va_list);
 
+static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
+{
+    vout_display_sys_t *sys = vd->sys;
+    return vout_display_opengl_SetViewpoint (sys->vgl, vp);
+}
+
 /**
  * Allocates a surface and an OpenGL context for video output.
  */
@@ -152,6 +158,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     vd->prepare = PictureRender;
     vd->display = PictureDisplay;
     vd->control = Control;
+    vd->set_viewpoint = SetViewpoint;
     vd->close = Close;
     return VLC_SUCCESS;
 
@@ -258,9 +265,6 @@ static int Control (vout_display_t *vd, int query, va_list ap)
         sys->place_changed = true;
         return VLC_SUCCESS;
       }
-      case VOUT_DISPLAY_CHANGE_VIEWPOINT:
-        return vout_display_opengl_SetViewpoint (sys->vgl,
-                                                 va_arg(ap, const vlc_viewpoint_t*));
       default:
         msg_Err (vd, "Unknown request %d", query);
     }
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index c4d5b488ab..a9405da65e 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -291,6 +291,19 @@ static void UpdateSize(vout_display_t *vd)
 #endif
 }
 
+static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *viewpoint)
+{
+    vout_display_sys_t *sys = vd->sys;
+    if ( sys->picQuad.pVertexShaderConstants )
+    {
+        d3d11_device_lock( sys->d3d_dev );
+        D3D11_UpdateViewpoint( vd, sys->d3d_dev, &sys->picQuad, viewpoint,
+                                (float) vd->cfg->display.width / vd->cfg->display.height );
+        d3d11_device_unlock( sys->d3d_dev );
+    }
+    return VLC_SUCCESS;
+}
+
 static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
                 video_format_t *fmtp, vlc_video_context *context)
 {
@@ -380,6 +393,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     vd->prepare = Prepare;
     vd->display = Display;
     vd->control = Control;
+    vd->set_viewpoint = SetViewpoint;
     vd->close = Close;
 
     msg_Dbg(vd, "Direct3D11 Open Succeeded");
@@ -402,22 +416,10 @@ static void Close(vout_display_t *vd)
 }
 static int Control(vout_display_t *vd, int query, va_list args)
 {
+    VLC_UNUSED(args);
     vout_display_sys_t *sys = vd->sys;
     int res = CommonControl( vd, &sys->area, &sys->sys, query );
 
-    if (query == VOUT_DISPLAY_CHANGE_VIEWPOINT)
-    {
-        if ( sys->picQuad.pVertexShaderConstants )
-        {
-            const vlc_viewpoint_t *viewpoint = va_arg(args, const vlc_viewpoint_t*);
-            d3d11_device_lock( sys->d3d_dev );
-            D3D11_UpdateViewpoint( vd, sys->d3d_dev, &sys->picQuad, viewpoint,
-                                   (float) vd->cfg->display.width / vd->cfg->display.height );
-            d3d11_device_unlock( sys->d3d_dev );
-            res = VLC_SUCCESS;
-        }
-    }
-
     if ( sys->area.place_changed )
     {
         UpdateSize(vd);
diff --git a/modules/video_output/win32/glwin32.c b/modules/video_output/win32/glwin32.c
index 81f7d621bf..9d1917dde0 100644
--- a/modules/video_output/win32/glwin32.c
+++ b/modules/video_output/win32/glwin32.c
@@ -78,14 +78,16 @@ struct vout_display_sys_t
 static void           Prepare(vout_display_t *, picture_t *, subpicture_t *, vlc_tick_t);
 static void           Display(vout_display_t *, picture_t *);
 
-static int Control(vout_display_t *vd, int query, va_list args)
+static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
 {
     vout_display_sys_t *sys = vd->sys;
+    return vout_display_opengl_SetViewpoint(sys->vgl, vp);
+}
 
-    if (query == VOUT_DISPLAY_CHANGE_VIEWPOINT)
-        return vout_display_opengl_SetViewpoint(sys->vgl,
-                                                va_arg(args, const vlc_viewpoint_t*));
-
+static int Control(vout_display_t *vd, int query, va_list args)
+{
+    VLC_UNUSED(args);
+    vout_display_sys_t *sys = vd->sys;
     return CommonControl(vd, &sys->area, &sys->sys, query);
 }
 
@@ -166,6 +168,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     vd->prepare = Prepare;
     vd->display = Display;
     vd->control = Control;
+    vd->set_viewpoint = SetViewpoint;
     vd->close = Close;
 
     return VLC_SUCCESS;
diff --git a/src/video_output/display.c b/src/video_output/display.c
index b76de8ed26..b340b4711e 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -685,10 +685,12 @@ void vout_SetDisplayViewpoint(vout_display_t *vd,
 
         osys->cfg.viewpoint = *p_viewpoint;
 
-        if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_VIEWPOINT,
-                                 &osys->cfg.viewpoint)) {
-            msg_Err(vd, "Failed to change Viewpoint");
-            osys->cfg.viewpoint = old_vp;
+        if (vd->set_viewpoint)
+        {
+            if (vd->set_viewpoint(vd, &osys->cfg.viewpoint)) {
+                msg_Err(vd, "Failed to change Viewpoint");
+                osys->cfg.viewpoint = old_vp;
+            }
         }
     }
 }



More information about the vlc-commits mailing list