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

Steve Lhomme robux4 at videolabs.io
Wed Sep 14 16:32:30 CEST 2016


--
replaces older patch fixing the missing viewpoint values init
---
 include/vlc_vout_display.h       | 12 ++++++++++
 include/vlc_vout_wrapper.h       |  2 ++
 src/video_output/control.h       |  6 +++++
 src/video_output/display.c       | 44 +++++++++++++++++++++++++++++++++++-
 src/video_output/video_output.c  | 25 ++++++++++++++++++++
 src/video_output/vout_internal.h |  1 +
 src/video_output/vout_intf.c     | 49 ++++++++++++++++++++++++++++++++++++++++
 7 files changed, 138 insertions(+), 1 deletion(-)

diff --git a/include/vlc_vout_display.h b/include/vlc_vout_display.h
index 817f770..d65cd8a 100644
--- a/include/vlc_vout_display.h
+++ b/include/vlc_vout_display.h
@@ -115,6 +115,14 @@ typedef struct {
         int den;
     } zoom;
 
+    struct {
+        float f_yaw_degrees;
+        float f_pitch_degrees;
+        float f_roll_degrees;
+    } viewpoint;
+
+    projection_mode projection;
+
 } vout_display_cfg_t;
 
 /**
@@ -175,6 +183,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 vout_display_cfg_t *p_cfg */
 };
 
 /**
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..29bfebf 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,24 @@ bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
             osys->crop.den    = crop_den;
             osys->ch_crop = false;
         }
+        if (osys->ch_viewpoint) {
+            vout_display_cfg_t cfg = osys->cfg;
+
+            cfg.viewpoint.f_yaw_degrees   = osys->viewpoint.yaw;
+            cfg.viewpoint.f_pitch_degrees = osys->viewpoint.pitch;
+            cfg.viewpoint.f_roll_degrees  = osys->viewpoint.roll;
+
+            if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_VIEWPOINT, &cfg)) {
+                msg_Err(vd, "Failed to change Viewpoint");
+                osys->viewpoint.yaw   = cfg.viewpoint.f_yaw_degrees;
+                osys->viewpoint.pitch = cfg.viewpoint.f_pitch_degrees;
+                osys->viewpoint.roll  = cfg.viewpoint.f_roll_degrees;
+            }
+            osys->cfg.viewpoint.f_yaw_degrees   = osys->viewpoint.yaw;
+            osys->cfg.viewpoint.f_pitch_degrees = osys->viewpoint.pitch;
+            osys->cfg.viewpoint.f_roll_degrees  = osys->viewpoint.roll;
+            osys->ch_viewpoint  = false;
+        }
 
         /* */
         if (reset_pictures) {
@@ -1193,6 +1219,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..8609569 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)
@@ -546,6 +557,9 @@ static void VoutGetDisplayCfg(vout_thread_t *vout, vout_display_cfg_t *cfg, cons
     /* Load configuration */
     cfg->is_fullscreen = var_CreateGetBool(vout, "fullscreen")
                          || var_InheritBool(vout, "video-wallpaper");
+    cfg->viewpoint.f_yaw_degrees = 0.0f;
+    cfg->viewpoint.f_pitch_degrees = 0.0f;
+    cfg->viewpoint.f_roll_degrees = 0.0f;
     cfg->display.title = title;
     const int display_width = var_CreateGetInteger(vout, "width");
     const int display_height = var_CreateGetInteger(vout, "height");
@@ -1289,6 +1303,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 +1569,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..debdb2b 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 viewport 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.7.2.windows.1



More information about the vlc-devel mailing list