[vlc-devel] [PATCH 08/17] input: add INPUT_SET_VIEWPOINT

Steve Lhomme robux4 at videolabs.io
Mon Nov 14 15:16:17 CET 2016


From: Thomas Guillem <thomas at gllm.fr>

This new control allows us to change the viewpoint of a given input thread. The
viewpoint will be applied to all vouts (and later all aouts) of the input.

The current viewpoint is stored by the input thread.

--
replaces https://patches.videolan.org/patch/15003/
* Inherit the initial value from the "viewpoint" variable.
* add input_SetViewpoint()
---
 include/vlc_input.h        |  7 +++++++
 src/input/control.c        | 12 ++++++++++++
 src/input/input.c          | 35 +++++++++++++++++++++++++++++++++++
 src/input/input_internal.h |  9 +++++++++
 4 files changed, 63 insertions(+)

diff --git a/include/vlc_input.h b/include/vlc_input.h
index a2ddaad..b93ee24 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -472,6 +472,7 @@ enum input_query_e
 
     /* ES */
     INPUT_RESTART_ES,       /* arg1=int (-AUDIO/VIDEO/SPU_ES for the whole category) */
+    INPUT_SET_VIEWPOINT,    /* arg1=(const vlc_viewpoint_t*), arg2=bool b_absolute */
 
     /* Input ressources
      * XXX You must call vlc_object_release as soon as possible */
@@ -597,6 +598,12 @@ static inline int input_AddSlave( input_thread_t *p_input, enum slave_type type,
     return input_Control( p_input, INPUT_ADD_SLAVE, type, psz_uri, b_forced );
 }
 
+static inline int input_SetViewpoint( input_thread_t *p_input,
+                                      const vlc_viewpoint_t *p_viewpoint,
+                                      int b_absolute )
+{
+    return input_Control( p_input, INPUT_SET_VIEWPOINT, p_viewpoint, b_absolute );
+}
 
 /**
  * Return the audio output (if any) associated with an input.
diff --git a/src/input/control.c b/src/input/control.c
index bb5100c..2e37f25 100644
--- a/src/input/control.c
+++ b/src/input/control.c
@@ -519,6 +519,18 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             input_ControlPush( p_input, INPUT_CONTROL_RESTART_ES, &val );
             return VLC_SUCCESS;
 
+        case INPUT_SET_VIEWPOINT:
+        {
+            struct input_viewpoint_req *p_req = malloc( sizeof(*p_req) );
+            if( unlikely(p_req == NULL) )
+                return VLC_ENOMEM;
+            p_req->vp = *va_arg( args, const vlc_viewpoint_t* );
+            p_req->absolute = va_arg( args, int );
+            val.p_address = p_req;
+            input_ControlPush( p_input, INPUT_CONTROL_SET_VIEWPOINT, &val );
+            return VLC_SUCCESS;
+        }
+
         case INPUT_GET_AOUT:
         {
             audio_output_t *p_aout = input_resource_HoldAout( priv->p_resource );
diff --git a/src/input/input.c b/src/input/input.c
index fcba5f2..5b986ec 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -324,6 +324,12 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     priv->p_sout   = NULL;
     priv->b_out_pace_control = false;
 
+    vlc_viewpoint_t *p_viewpoint = var_InheritAddress( p_input, "viewpoint" );
+    if (likely(p_viewpoint != NULL))
+        priv->viewpoint = *p_viewpoint;
+    else
+        vlc_viewpoint_init( &priv->viewpoint );
+
     vlc_gc_incref( p_item ); /* Released in Destructor() */
     priv->p_item = p_item;
 
@@ -1655,6 +1661,9 @@ static void ControlRelease( int i_type, vlc_value_t val )
         if( val.p_address )
             input_item_slave_Delete( val.p_address );
         break;
+    case INPUT_CONTROL_SET_VIEWPOINT:
+        free( val.p_address );
+        break;
 
     default:
         break;
@@ -1918,6 +1927,32 @@ static bool Control( input_thread_t *p_input,
                             ES_OUT_RESTART_ES_BY_ID, (int)val.i_int );
             break;
 
+        case INPUT_CONTROL_SET_VIEWPOINT:
+        {
+            input_thread_private_t *priv = input_priv(p_input);
+            struct input_viewpoint_req *p_req = val.p_address;
+            if( p_req->absolute )
+                priv->viewpoint = p_req->vp;
+            else
+            {
+                priv->viewpoint.yaw += p_req->vp.yaw;
+                priv->viewpoint.pitch += p_req->vp.pitch;
+                priv->viewpoint.roll += p_req->vp.roll;
+                priv->viewpoint.fov += p_req->vp.fov;
+                priv->viewpoint.zoom += p_req->vp.zoom;
+            }
+            vout_thread_t **pp_vout;
+            size_t i_vout;
+            input_resource_HoldVouts( priv->p_resource, &pp_vout, &i_vout );
+
+            for( size_t i = 0; i < i_vout; ++i )
+            {
+                vout_SetViewpoint( pp_vout[i], &priv->viewpoint );
+                vlc_object_release( pp_vout[i] );
+            }
+            break;
+        }
+
         case INPUT_CONTROL_SET_AUDIO_DELAY:
             input_SendEventAudioDelay( p_input, val.i_int );
             UpdatePtsDelay( p_input );
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 0bc1de0..437979f 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -29,6 +29,7 @@
 #include <vlc_access.h>
 #include <vlc_demux.h>
 #include <vlc_input.h>
+#include <vlc_vout.h>
 #include <libvlc.h>
 #include "input_interface.h"
 #include "misc/interrupt.h"
@@ -80,6 +81,12 @@ typedef struct
     vlc_value_t val;
 } input_control_t;
 
+struct input_viewpoint_req
+{
+    vlc_viewpoint_t vp;
+    bool            absolute;
+};
+
 /** Private input fields */
 typedef struct input_thread_private_t
 {
@@ -109,6 +116,7 @@ typedef struct input_thread_private_t
     sout_instance_t *p_sout;            /* Idem ? */
     es_out_t        *p_es_out;
     es_out_t        *p_es_out_display;
+    vlc_viewpoint_t viewpoint;
 
     /* Title infos FIXME multi-input (not easy) ? */
     int          i_title;
@@ -214,6 +222,7 @@ enum input_control_e
 
     INPUT_CONTROL_SET_ES,
     INPUT_CONTROL_RESTART_ES,
+    INPUT_CONTROL_SET_VIEWPOINT,
 
     INPUT_CONTROL_SET_AUDIO_DELAY,
     INPUT_CONTROL_SET_SPU_DELAY,
-- 
2.10.1



More information about the vlc-devel mailing list