[vlc-devel] [PATCH 1/8] core: add viewpoint variables to change the yaw/pitch/roll view during playback

Steve Lhomme robux4 at videolabs.io
Thu Sep 8 17:35:28 CEST 2016


--
fix typos
---
 include/vlc_vout_display.h       |  4 ++++
 include/vlc_vout_wrapper.h       |  2 ++
 src/video_output/control.h       |  6 +++++
 src/video_output/display.c       | 40 +++++++++++++++++++++++++++++++-
 src/video_output/video_output.c  | 22 ++++++++++++++++++
 src/video_output/vout_internal.h |  1 +
 src/video_output/vout_intf.c     | 49 ++++++++++++++++++++++++++++++++++++++++
 7 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/include/vlc_vout_display.h b/include/vlc_vout_display.h
index 817f770..7f6037c 100644
--- a/include/vlc_vout_display.h
+++ b/include/vlc_vout_display.h
@@ -175,6 +175,10 @@ enum {
      * The cropping requested is stored by video_format_t::i_x/y_offset and
      * video_format_t::i_visible_width/height */
     VOUT_DISPLAY_CHANGE_SOURCE_CROP,   /* const video_format_t *p_source */
+
+    /* Ask the module to acknowledge/refuse VR/360° viewing direction after
+     * being requested externally */
+    VOUT_DISPLAY_CHANGE_VIEWPOINT,   /* const video_format_t *p_source */
 };
 
 /**
diff --git a/include/vlc_vout_wrapper.h b/include/vlc_vout_wrapper.h
index 419bfc8..006bb51 100644
--- a/include/vlc_vout_wrapper.h
+++ b/include/vlc_vout_wrapper.h
@@ -93,6 +93,8 @@ void vout_SetDisplayZoom(vout_display_t *, unsigned num, unsigned den);
 void vout_SetDisplayAspect(vout_display_t *, unsigned num, unsigned den);
 void vout_SetDisplayCrop(vout_display_t *, unsigned num, unsigned den,
                          unsigned left, unsigned top, int right, int bottom);
+void vout_SetDisplayViewpoint(vout_display_t *,
+                              float yaw, float pitch, float roll);
 
 #endif /* VLC_VOUT_WRAPPER_H */
 
diff --git a/src/video_output/control.h b/src/video_output/control.h
index eff9aa1..dae850f 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -58,6 +58,7 @@ enum {
     VOUT_CONTROL_CROP_BORDER,           /* border */
     VOUT_CONTROL_CROP_RATIO,            /* pair */
     VOUT_CONTROL_CROP_WINDOW,           /* window */
+    VOUT_CONTROL_VIEWPOINT,             /* viewpoint */
 };
 
 typedef struct {
@@ -93,6 +94,11 @@ typedef struct {
             unsigned width;
             unsigned height;
         } window;
+        struct {
+            float yaw;
+            float pitch;
+            float roll;
+        } viewpoint;
         const vout_configuration_t *cfg;
         subpicture_t *subpicture;
     } u;
diff --git a/src/video_output/display.c b/src/video_output/display.c
index ecf661a..723e22b 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -373,6 +373,13 @@ struct vout_display_owner_sys_t {
         unsigned den;
     } crop;
 
+    bool ch_viewpoint;
+    struct {
+        float    yaw;
+        float    pitch;
+        float    roll;
+    } viewpoint;
+
     /* */
     video_format_t source;
     filter_chain_t *filters;
@@ -850,7 +857,8 @@ bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
             !ch_wm_state &&
 #endif
             !osys->ch_sar &&
-            !osys->ch_crop) {
+            !osys->ch_crop &&
+            !osys->ch_viewpoint) {
 
             if (!osys->cfg.is_fullscreen && osys->fit_window != 0) {
                 VoutDisplayFitWindow(vd, osys->fit_window == -1);
@@ -1034,6 +1042,20 @@ bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
             osys->crop.den    = crop_den;
             osys->ch_crop = false;
         }
+        if (osys->ch_viewpoint) {
+            video_format_t source = vd->source;
+
+            source.f_pose_yaw_degrees   = osys->viewpoint.yaw;
+            source.f_pose_pitch_degrees = osys->viewpoint.pitch;
+            source.f_pose_roll_degrees  = osys->viewpoint.roll;
+
+            if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_VIEWPOINT, &source)) {
+                msg_Err(vd, "Failed to change Viewpoint");
+                source = vd->source;
+            }
+            vd->source = source;
+            osys->ch_viewpoint  = false;
+        }
 
         /* */
         if (reset_pictures) {
@@ -1193,6 +1215,22 @@ void vout_SetDisplayCrop(vout_display_t *vd,
     }
 }
 
+void vout_SetDisplayViewpoint(vout_display_t *vd,
+                               float yaw, float pitch, float roll)
+{
+    vout_display_owner_sys_t *osys = vd->owner.sys;
+
+    if (osys->viewpoint.yaw != yaw  || osys->viewpoint.pitch != pitch ||
+        osys->viewpoint.roll != roll) {
+
+        osys->viewpoint.yaw   = yaw;
+        osys->viewpoint.pitch = pitch;
+        osys->viewpoint.roll  = roll;
+
+        osys->ch_viewpoint = true;
+    }
+}
+
 static vout_display_t *DisplayNew(vout_thread_t *vout,
                                   const video_format_t *source,
                                   const vout_display_state_t *state,
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 7994bec..203b871 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -539,6 +539,17 @@ void vout_ControlChangeSubMargin(vout_thread_t *vout, int margin)
     vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_MARGIN,
                              margin);
 }
+void vout_ControlChangeViewpoint(vout_thread_t *vout,
+                                 float yaw, float pitch, float roll)
+{
+    vout_control_cmd_t cmd;
+    vout_control_cmd_Init(&cmd, VOUT_CONTROL_VIEWPOINT);
+    cmd.u.viewpoint.yaw   = yaw;
+    cmd.u.viewpoint.pitch = pitch;
+    cmd.u.viewpoint.roll  = roll;
+
+    vout_control_Push(&vout->p->control, &cmd);
+}
 
 /* */
 static void VoutGetDisplayCfg(vout_thread_t *vout, vout_display_cfg_t *cfg, const char *title)
@@ -1289,6 +1300,13 @@ static void ThreadExecuteCropRatio(vout_thread_t *vout,
                         0, 0, 0, 0);
 }
 
+static void ThreadExecuteViewpoint(vout_thread_t *vout,
+                                    float yaw, float pitch, float roll)
+{
+    msg_Dbg(vout, "ThreadExecuteViewpoint %f %f %f", yaw, pitch, roll);
+    vout_SetDisplayViewpoint(vout->p->display.vd, yaw, pitch, roll);
+}
+
 static int ThreadStart(vout_thread_t *vout, vout_display_state_t *state)
 {
     vlc_mouse_Init(&vout->p->mouse);
@@ -1548,6 +1566,10 @@ static int ThreadControl(vout_thread_t *vout, vout_control_cmd_t cmd)
                 cmd.u.border.left,  cmd.u.border.top,
                 cmd.u.border.right, cmd.u.border.bottom);
         break;
+    case VOUT_CONTROL_VIEWPOINT:
+        ThreadExecuteViewpoint(vout,
+                cmd.u.viewpoint.yaw, cmd.u.viewpoint.pitch, cmd.u.viewpoint.roll);
+        break;
     default:
         break;
     }
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index 4d63fbf..473d2dd 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -141,6 +141,7 @@ void vout_ControlChangeSampleAspectRatio(vout_thread_t *, unsigned num, unsigned
 void vout_ControlChangeCropRatio(vout_thread_t *, unsigned num, unsigned den);
 void vout_ControlChangeCropWindow(vout_thread_t *, int x, int y, int width, int height);
 void vout_ControlChangeCropBorder(vout_thread_t *, int left, int top, int right, int bottom);
+void vout_ControlChangeViewpoint(vout_thread_t *vout,float yaw, float pitch, float roll);
 void vout_ControlChangeFilters(vout_thread_t *, const char *);
 void vout_ControlChangeSubSources(vout_thread_t *, const char *);
 void vout_ControlChangeSubFilters(vout_thread_t *, const char *);
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index 11240c8..b265ea6 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -57,6 +57,10 @@ static int AutoScaleCallback( vlc_object_t *, char const *,
                               vlc_value_t, vlc_value_t, void * );
 static int ZoomCallback( vlc_object_t *, char const *,
                          vlc_value_t, vlc_value_t, void * );
+static int ViewpointCallback( vlc_object_t *, char const *,
+                              vlc_value_t, vlc_value_t, void * );
+static int ViewpointValCallback( vlc_object_t *, char const *,
+                                 vlc_value_t, vlc_value_t, void * );
 static int AboveCallback( vlc_object_t *, char const *,
                           vlc_value_t, vlc_value_t, void * );
 static int WallPaperCallback( vlc_object_t *, char const *,
@@ -252,6 +256,21 @@ void vout_IntfInit( vout_thread_t *p_vout )
     var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
     var_AddCallback( p_vout, "video-on-top", AboveCallback, NULL );
 
+    /* Add a variable to indicate if the viewpoint to use to display the video */
+    var_Create( p_vout, "viewpoint-yaw",   VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND );
+    var_Create( p_vout, "viewpoint-pitch", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND );
+    var_Create( p_vout, "viewpoint-roll",  VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND );
+
+    var_AddCallback( p_vout, "viewpoint-yaw", ViewpointValCallback, NULL );
+    var_AddCallback( p_vout, "viewpoint-pitch", ViewpointValCallback, NULL );
+    var_AddCallback( p_vout, "viewpoint-roll", ViewpointValCallback, NULL );
+
+    var_Create( p_vout, "viewpoint", VLC_VAR_STRING | VLC_VAR_DOINHERIT
+                | VLC_VAR_ISCOMMAND );
+    text.psz_string = _("Viewpoint");
+    var_Change( p_vout, "viewpoint", VLC_VAR_SETTEXT, &text, NULL );
+    var_AddCallback( p_vout, "viewpoint", ViewpointCallback, NULL );
+
     /* Add a variable to indicate if the window should be below all others */
     var_Create( p_vout, "video-wallpaper", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_AddCallback( p_vout, "video-wallpaper", WallPaperCallback,
@@ -309,6 +328,7 @@ void vout_IntfReinit( vout_thread_t *p_vout )
     var_TriggerCallback( p_vout, "zoom" );
     var_TriggerCallback( p_vout, "crop" );
     var_TriggerCallback( p_vout, "aspect-ratio" );
+    var_TriggerCallback( p_vout, "viewpoint" );
 
     var_TriggerCallback( p_vout, "video-on-top" );
     var_TriggerCallback( p_vout, "video-wallpaper" );
@@ -602,6 +622,35 @@ static int ZoomCallback( vlc_object_t *obj, char const *name,
     return VLC_SUCCESS;
 }
 
+static int ViewpointCallback(vlc_object_t *obj, char const *cmd,
+                             vlc_value_t oldval, vlc_value_t newval, void *data)
+{
+    float f_yaw, f_pitch, f_roll;
+    if (sscanf(newval.psz_string, "%f:%f:%f", &f_yaw, &f_pitch, &f_roll) == 3) {
+        vout_ControlChangeViewpoint((vout_thread_t *)obj, f_yaw, f_pitch, f_roll);
+    } else {
+        msg_Err(obj, "Unknown viewpoint format (%s)", newval.psz_string);
+    }
+
+    VLC_UNUSED(cmd); VLC_UNUSED(oldval); VLC_UNUSED(data);
+    return VLC_SUCCESS;
+}
+
+static int ViewpointValCallback(vlc_object_t *object, char const *cmd,
+                                vlc_value_t oldval, vlc_value_t newval, void *data)
+{
+    char buf[3 * 13];
+
+    snprintf(buf, sizeof (buf), "%.7f:%.7f:%.7f",
+             var_GetFloat(object, "viewpoint-yaw"),
+             var_GetFloat(object, "viewpoint-pitch"),
+             var_GetFloat(object, "viewpoint-roll"));
+    var_SetString(object, "viewpoint", buf);
+
+    VLC_UNUSED(cmd); VLC_UNUSED(oldval); VLC_UNUSED(data); VLC_UNUSED(newval);
+    return VLC_SUCCESS;
+}
+
 static int AboveCallback( vlc_object_t *obj, char const *name,
                           vlc_value_t prev, vlc_value_t cur, void *data )
 {
-- 
2.8.2



More information about the vlc-devel mailing list