[vlc-devel] [PATCH 4/7] core: add an option to set the projection mode

Steve Lhomme robux4 at videolabs.io
Wed Sep 14 16:37:48 CEST 2016


--
fix older patch with proper value initialization
---
 include/vlc_vout.h               |  6 ++++++
 include/vlc_vout_display.h       |  3 +++
 include/vlc_vout_wrapper.h       |  2 ++
 src/libvlc-module.c              | 11 +++++++++++
 src/video_output/control.h       |  1 +
 src/video_output/display.c       | 28 +++++++++++++++++++++++++++-
 src/video_output/video_output.c  | 15 +++++++++++++++
 src/video_output/vout_internal.h |  1 +
 src/video_output/vout_intf.c     | 37 +++++++++++++++++++++++++++++++++++++
 9 files changed, 103 insertions(+), 1 deletion(-)

diff --git a/include/vlc_vout.h b/include/vlc_vout.h
index 600cb56..5b78ad8 100644
--- a/include/vlc_vout.h
+++ b/include/vlc_vout.h
@@ -82,6 +82,12 @@ struct vout_thread_t {
 #define VOUT_ALIGN_BOTTOM       0x0008
 #define VOUT_ALIGN_VMASK        0x000C
 
+typedef enum {
+    PROJECTION_AUTO, PROJECTION_FLAT, PROJECTION_SPHERE,
+    PROJECTION_CUBEMAP, PROJECTION_LITTLE_PLANET,
+    PROJECTION_CARDBOARD, PROJECTION_SIDEBYSIDE
+} projection_mode;
+
 /*****************************************************************************
  * Prototypes
  *****************************************************************************/
diff --git a/include/vlc_vout_display.h b/include/vlc_vout_display.h
index d65cd8a..6bdb04d 100644
--- a/include/vlc_vout_display.h
+++ b/include/vlc_vout_display.h
@@ -30,6 +30,7 @@
 #include <vlc_subpicture.h>
 #include <vlc_keys.h>
 #include <vlc_mouse.h>
+#include <vlc_vout.h>
 #include <vlc_vout_window.h>
 
 /**
@@ -187,6 +188,8 @@ enum {
     /* 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 */
+
+    VOUT_DISPLAY_CHANGE_PROJECTION, /* const vout_display_cfg_t *p_cfg */
 };
 
 /**
diff --git a/include/vlc_vout_wrapper.h b/include/vlc_vout_wrapper.h
index 006bb51..adac35d 100644
--- a/include/vlc_vout_wrapper.h
+++ b/include/vlc_vout_wrapper.h
@@ -24,6 +24,7 @@
 #ifndef VLC_VOUT_WRAPPER_H
 #define VLC_VOUT_WRAPPER_H 1
 
+#include <vlc_vout.h>
 #include <vlc_vout_display.h>
 
 /* XXX DO NOT use it outside the vout module wrapper XXX */
@@ -95,6 +96,7 @@ 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);
+void vout_SetDisplayProjection(vout_display_t *, projection_mode);
 
 #endif /* VLC_VOUT_WRAPPER_H */
 
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 7f720cd..09c4be3 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -438,6 +438,15 @@ static const char *const ppsz_pos_descriptions[] =
     "This forces the viewpoint for the displayed video. " \
     "Accepted formats are yaw:pitch:roll expressing the user viewpoint.")
 
+#define PROJECTION_TEXT N_("Projection")
+#define PROJECTION_LONGTEXT N_( \
+    "Change the way the video is displayed.")
+static const int pi_projection_values[] = { 0, 1, 2, 3, 4, 5, 6 };
+static const char *const ppsz_projection_descriptions[] =
+{ N_("Automatic"), N_("Flat/2D"), N_("360° Sphere"),
+  N_("360° Cubemap"), N_("Little Planet"), N_("360° Cardboard"),
+  N_("Side By Side 2D") };
+
 #define AUTOSCALE_TEXT N_("Video Auto Scaling")
 #define AUTOSCALE_LONGTEXT N_( \
     "Let the video scale to fit a given window or fullscreen.")
@@ -1598,6 +1607,8 @@ vlc_module_begin ()
     add_string( "viewpoint", NULL,
                 VIEWPOINT_TEXT, VIEWPOINT_LONGTEXT, false )
         change_safe ()
+    add_integer( "projection", 0, PROJECTION_TEXT, PROJECTION_LONGTEXT, false )
+        change_integer_list( pi_projection_values, ppsz_projection_descriptions )
     add_bool( "autoscale", true, AUTOSCALE_TEXT, AUTOSCALE_LONGTEXT, false )
         change_safe ()
     add_obsolete_float( "scale" ) /* since 3.0.0 */
diff --git a/src/video_output/control.h b/src/video_output/control.h
index dae850f..972a4ec 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -59,6 +59,7 @@ enum {
     VOUT_CONTROL_CROP_RATIO,            /* pair */
     VOUT_CONTROL_CROP_WINDOW,           /* window */
     VOUT_CONTROL_VIEWPOINT,             /* viewpoint */
+    VOUT_CONTROL_PROJECTION,            /* integer */
 };
 
 typedef struct {
diff --git a/src/video_output/display.c b/src/video_output/display.c
index 29bfebf..3fc160e 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -380,6 +380,9 @@ struct vout_display_owner_sys_t {
         float    roll;
     } viewpoint;
 
+    bool ch_projection;
+    projection_mode proj_mode;
+
     /* */
     video_format_t source;
     filter_chain_t *filters;
@@ -858,7 +861,8 @@ bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
 #endif
             !osys->ch_sar &&
             !osys->ch_crop &&
-            !osys->ch_viewpoint) {
+            !osys->ch_viewpoint &&
+            !osys->ch_projection) {
 
             if (!osys->cfg.is_fullscreen && osys->fit_window != 0) {
                 VoutDisplayFitWindow(vd, osys->fit_window == -1);
@@ -1060,6 +1064,18 @@ bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
             osys->cfg.viewpoint.f_roll_degrees  = osys->viewpoint.roll;
             osys->ch_viewpoint  = false;
         }
+        if (osys->ch_projection) {
+            vout_display_cfg_t cfg = osys->cfg;
+
+            cfg.projection = osys->proj_mode;
+
+            if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_PROJECTION, &cfg)) {
+                msg_Err(vd, "Failed to change Viewpoint");
+                osys->proj_mode = osys->cfg.projection;
+            }
+            osys->cfg.projection = osys->proj_mode;
+            osys->ch_projection = false;
+        }
 
         /* */
         if (reset_pictures) {
@@ -1235,6 +1251,16 @@ void vout_SetDisplayViewpoint(vout_display_t *vd,
     }
 }
 
+void vout_SetDisplayProjection(vout_display_t *vd, projection_mode proj)
+{
+    vout_display_owner_sys_t *osys = vd->owner.sys;
+
+    if (osys->proj_mode != proj) {
+        osys->proj_mode = proj;
+        osys->ch_projection = 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 8609569..ca826b3 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -550,6 +550,11 @@ void vout_ControlChangeViewpoint(vout_thread_t *vout,
 
     vout_control_Push(&vout->p->control, &cmd);
 }
+void vout_ControlChangeProjection(vout_thread_t *vout, projection_mode proj)
+{
+    vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_PROJECTION,
+                             proj);
+}
 
 /* */
 static void VoutGetDisplayCfg(vout_thread_t *vout, vout_display_cfg_t *cfg, const char *title)
@@ -557,6 +562,7 @@ 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->projection = var_CreateGetInteger(vout, "projection");
     cfg->viewpoint.f_yaw_degrees = 0.0f;
     cfg->viewpoint.f_pitch_degrees = 0.0f;
     cfg->viewpoint.f_roll_degrees = 0.0f;
@@ -1310,6 +1316,12 @@ static void ThreadExecuteViewpoint(vout_thread_t *vout,
     vout_SetDisplayViewpoint(vout->p->display.vd, yaw, pitch, roll);
 }
 
+static void ThreadExecuteProjection(vout_thread_t *vout, projection_mode proj)
+{
+    msg_Dbg(vout, "ThreadExecuteProjection %d", proj);
+    vout_SetDisplayProjection(vout->p->display.vd, proj);
+}
+
 static int ThreadStart(vout_thread_t *vout, vout_display_state_t *state)
 {
     vlc_mouse_Init(&vout->p->mouse);
@@ -1573,6 +1585,9 @@ static int ThreadControl(vout_thread_t *vout, vout_control_cmd_t cmd)
         ThreadExecuteViewpoint(vout,
                 cmd.u.viewpoint.yaw, cmd.u.viewpoint.pitch, cmd.u.viewpoint.roll);
         break;
+    case VOUT_CONTROL_PROJECTION:
+        ThreadExecuteProjection(vout, (projection_mode) cmd.u.integer);
+        break;
     default:
         break;
     }
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index 473d2dd..a76448a 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -142,6 +142,7 @@ 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_ControlChangeProjection(vout_thread_t *vout, projection_mode projection);
 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 0842770..f56ca32 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -126,6 +126,20 @@ static const struct
     { "5:4", "5:4" },
 };
 
+static const struct
+{
+    projection_mode value;
+    char psz_label[20];
+} p_projection_values[] = {
+    { PROJECTION_AUTO, N_("Automatic Selection") },
+    { PROJECTION_FLAT, N_("Flat/2D") },
+    { PROJECTION_SPHERE, N_("360° Sphere") },
+    { PROJECTION_CUBEMAP, N_("360° Cubemap") },
+    { PROJECTION_LITTLE_PLANET, N_("Little Planet") },
+    { PROJECTION_CARDBOARD, N_("360° Cardboard") },
+    { PROJECTION_SIDEBYSIDE, N_("Side By Side 2D") },
+};
+
 static void AddCustomRatios( vout_thread_t *p_vout, const char *psz_var,
                              char *psz_list )
 {
@@ -149,6 +163,14 @@ static void AddCustomRatios( vout_thread_t *p_vout, const char *psz_var,
     }
 }
 
+static int ProjectionCallback(vlc_object_t *obj, char const *cmd,
+                              vlc_value_t oldval, vlc_value_t newval, void *data)
+{
+    vout_ControlChangeProjection((vout_thread_t *)obj, (projection_mode) newval.i_int);
+    VLC_UNUSED(cmd); VLC_UNUSED(oldval); VLC_UNUSED(data);
+    return VLC_SUCCESS;
+}
+
 void vout_IntfInit( vout_thread_t *p_vout )
 {
     vlc_value_t val, text;
@@ -271,6 +293,20 @@ void vout_IntfInit( vout_thread_t *p_vout )
     var_Change( p_vout, "viewpoint", VLC_VAR_SETTEXT, &text, NULL );
     var_AddCallback( p_vout, "viewpoint", ViewpointCallback, NULL );
 
+    var_Create( p_vout, "projection", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT
+                | VLC_VAR_ISCOMMAND );
+    text.psz_string = _("Projection");
+    var_Change( p_vout, "projection", VLC_VAR_SETTEXT, &text, NULL );
+
+    for( size_t i = 0; i < ARRAY_SIZE(p_projection_values); i++ )
+    {
+        val.i_int = p_projection_values[i].value;
+        text.psz_string = _( p_projection_values[i].psz_label );
+        var_Change( p_vout, "projection", VLC_VAR_ADDCHOICE, &val, &text );
+    }
+
+    var_AddCallback( p_vout, "projection", ProjectionCallback, 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,
@@ -329,6 +365,7 @@ void vout_IntfReinit( vout_thread_t *p_vout )
     var_TriggerCallback( p_vout, "crop" );
     var_TriggerCallback( p_vout, "aspect-ratio" );
     var_TriggerCallback( p_vout, "viewpoint" );
+    var_TriggerCallback( p_vout, "projection" );
 
     var_TriggerCallback( p_vout, "video-on-top" );
     var_TriggerCallback( p_vout, "video-wallpaper" );
-- 
2.7.2.windows.1



More information about the vlc-devel mailing list