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

Steve Lhomme robux4 at videolabs.io
Tue Feb 28 13:23:48 CET 2017


To change the viewpoint on VR/360 videos

--
replaces https://patches.videolan.org/patch/15767/
- fit the 3 float values in an int64 (16 bits signed for each)
- add missing hotkeys.c additions
---
 include/vlc_vout_display.h   | 13 +++++++++++++
 modules/control/hotkeys.c    | 25 +++++++++++++++++++++++++
 src/video_output/display.c   | 16 ++++++++++++++++
 src/video_output/event.h     |  9 +++++++++
 src/video_output/vout_intf.c |  3 +++
 5 files changed, 66 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/modules/control/hotkeys.c b/modules/control/hotkeys.c
index 4e4f36897e..0f0a1f49c7 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -133,6 +133,25 @@ static int MovedEvent( vlc_object_t *p_this, char const *psz_var,
     return VLC_SUCCESS;
 }
 
+static int DeviceMovedEvent( vlc_object_t *p_this, char const *psz_var,
+                             vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    intf_thread_t *p_intf = (intf_thread_t *)p_data;
+    intf_sys_t    *p_sys = p_intf->p_sys;
+
+    (void) p_this; (void) psz_var; (void) oldval;
+
+    vlc_viewpoint_t viewpoint = {
+        .yaw   = (int16_t)((newval.i_int >> 32) & 0xFFFF) / 100.f,
+        .pitch = (int16_t)((newval.i_int >> 16) & 0xFFFF) / 100.f,
+        .roll  = (int16_t)((newval.i_int >>  0) & 0xFFFF) / 100.f,
+    };
+
+    input_UpdateViewpoint( p_sys->p_input, &viewpoint, false );
+
+    return VLC_SUCCESS;
+}
+
 static int ButtonEvent( vlc_object_t *p_this, char const *psz_var,
                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
@@ -189,6 +208,8 @@ static void ChangeVout( intf_thread_t *p_intf, vout_thread_t *p_vout )
                              p_intf );
             var_DelCallback( p_old_vout, "mouse-button-down", ButtonEvent,
                              p_intf );
+            var_DelCallback( p_old_vout, "device-moved", DeviceMovedEvent,
+                             p_intf );
         }
         vlc_object_release( p_old_vout );
     }
@@ -200,6 +221,8 @@ static void ChangeVout( intf_thread_t *p_intf, vout_thread_t *p_vout )
                          p_intf );
         var_AddCallback( p_sys->p_vout, "mouse-button-down", ButtonEvent,
                          p_intf );
+        var_AddCallback( p_sys->p_vout, "device-moved", DeviceMovedEvent,
+                         p_intf );
     }
 }
 
@@ -238,6 +261,8 @@ static void ChangeInput( intf_thread_t *p_intf, input_thread_t *p_input )
                              p_intf );
             var_DelCallback( p_old_vout, "mouse-button-down", ButtonEvent,
                              p_intf );
+            var_DelCallback( p_old_vout, "device-moved", DeviceMovedEvent,
+                             p_intf );
         }
     }
 
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..02923ca0af 100644
--- a/src/video_output/event.h
+++ b/src/video_output/event.h
@@ -52,6 +52,15 @@ 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)
+{
+    int64_t value;
+    value  = (((int64_t)lround(yaw   * 100) % (360*100)) & 0xFFFF) << 32;
+    value |= (((int64_t)lround(pitch * 100) % (360*100)) & 0xFFFF) << 16;
+    value |= (((int64_t)lround(roll  * 100) % (360*100)) & 0xFFFF) <<  0;
+
+    var_SetInteger(vout, "device-moved", value);
+}
 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..a10590059d 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_INTEGER );
+
     /* 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