[vlc-devel] [PATCH 2/3] core: add "device-moved" an angle variable to notify device orientation changes

Steve Lhomme robux4 at videolabs.io
Mon Feb 27 17:35:28 CET 2017


To change the viewpoint on VR/360 videos
---
 include/vlc_vout_display.h   | 13 +++++++++++++
 src/video_output/display.c   | 16 ++++++++++++++++
 src/video_output/event.h     |  4 ++++
 src/video_output/vout_intf.c |  3 +++
 4 files changed, 36 insertions(+)

diff --git a/include/vlc_vout_display.h b/include/vlc_vout_display.h
index 46825bea8c..c63efacf09 100644
--- a/include/vlc_vout_display.h
+++ b/include/vlc_vout_display.h
@@ -217,6 +217,9 @@ enum {
     VOUT_DISPLAY_EVENT_MOUSE_PRESSED,
     VOUT_DISPLAY_EVENT_MOUSE_RELEASED,
     VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK,
+
+    /* VR navigation */
+    VOUT_DISPLAY_EVENT_UPDATE_VIEWPOINT,
 };
 
 /**
@@ -396,6 +399,16 @@ static inline void vout_display_SendEventMouseDoubleClick(vout_display_t *vd)
 {
     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK);
 }
+static inline void vout_display_SendEventViewpointChanged(vout_display_t *vd, float yaw, float pitch, float roll)
+{
+    vlc_viewpoint_t vp = {
+        .yaw   = yaw,
+        .pitch = pitch,
+        .roll  = roll,
+        .fov = 0,
+    };
+    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_UPDATE_VIEWPOINT, vp);
+}
 
 /**
  * Asks for a new window of a given type.
diff --git a/src/video_output/display.c b/src/video_output/display.c
index d5bdc693b0..6ad786473b 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -600,6 +600,15 @@ static void VoutDisplayEventMouse(vout_display_t *vd, int event, va_list args)
     vlc_mutex_unlock(&osys->lock);
 }
 
+static void VoutDisplayEventDevice(vout_display_t *vd, const vlc_viewpoint_t *p_viewpoint)
+{
+    vout_display_owner_sys_t *osys = vd->owner.sys;
+
+    vlc_mutex_lock(&osys->lock);
+    vout_SendEventDeviceMoved(osys->vout, p_viewpoint->yaw, p_viewpoint->pitch, p_viewpoint->roll);
+    vlc_mutex_unlock(&osys->lock);
+}
+
 noreturn static void *VoutDisplayEventKeyDispatch(void *data)
 {
     vout_display_owner_sys_t *osys = data;
@@ -667,6 +676,13 @@ static void VoutDisplayEvent(vout_display_t *vd, int event, va_list args)
         VoutDisplayEventMouse(vd, event, args);
         break;
 
+    case VOUT_DISPLAY_EVENT_UPDATE_VIEWPOINT: {
+        msg_Dbg(vd, "update viewpoint");
+        const vlc_viewpoint_t viewpoint = (vlc_viewpoint_t)va_arg(args, vlc_viewpoint_t);
+        VoutDisplayEventDevice(vd, &viewpoint);
+        break;
+    }
+
     case VOUT_DISPLAY_EVENT_FULLSCREEN: {
         const int is_fullscreen = (int)va_arg(args, int);
 
diff --git a/src/video_output/event.h b/src/video_output/event.h
index a5e47da295..2594abcb58 100644
--- a/src/video_output/event.h
+++ b/src/video_output/event.h
@@ -52,6 +52,10 @@ static inline void vout_SendEventMouseMoved(vout_thread_t *vout, int x, int y)
 {
     var_SetCoords(vout, "mouse-moved", x, y);
 }
+static inline void vout_SendEventDeviceMoved(vout_thread_t *vout, float yaw, float pitch, float roll)
+{
+    var_SetAngles(vout, "device-moved", yaw, pitch, roll);
+}
 static inline void vout_SendEventMousePressed(vout_thread_t *vout, int button)
 {
     int key = KEY_UNSET;
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index 262da21e4d..7e0f0f8901 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -303,6 +303,9 @@ void vout_IntfInit( vout_thread_t *p_vout )
     var_Create( p_vout, "mouse-moved", VLC_VAR_COORDS );
     var_Create( p_vout, "mouse-clicked", VLC_VAR_COORDS );
 
+    /* Device orientation */
+    var_Create( p_vout, "device-moved", VLC_VAR_ANGLES );
+
     /* Viewpoint */
     var_Create( p_vout, "viewpoint", VLC_VAR_ADDRESS  | VLC_VAR_DOINHERIT );
     var_AddCallback( p_vout, "viewpoint", ViewpointCallback, NULL );
-- 
2.11.1



More information about the vlc-devel mailing list