[vlc-commits] libvlc: add the API needed to update the viewpoint in 360° videos

Steve Lhomme git at videolan.org
Tue Nov 15 18:14:01 CET 2016


vlc | branch: master | Steve Lhomme <robux4 at videolabs.io> | Tue Nov 15 16:19:25 2016 +0100| [e23cb34d2cc7eea0a173e84281205653acdecf64] | committer: Thomas Guillem

libvlc: add the API needed to update the viewpoint in 360° videos

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e23cb34d2cc7eea0a173e84281205653acdecf64
---

 include/vlc/libvlc_media_player.h | 42 ++++++++++++++++++++++++++++++++++
 lib/libvlc.sym                    |  2 ++
 lib/media_player.c                |  4 ++++
 lib/media_player_internal.h       |  2 ++
 lib/video.c                       | 47 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 97 insertions(+)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index 9a73b4f..b6e697e 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -1167,6 +1167,48 @@ LIBVLC_API char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi );
 LIBVLC_API void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi, const char *psz_aspect );
 
 /**
+ * Viewpoint for video outputs
+ *
+ * \warning allocate using libvlc_video_new_viewpoint()
+ */
+typedef struct libvlc_video_viewpoint_t
+{
+    float f_yaw;           /**< view point yaw in degrees */
+    float f_pitch;         /**< view point pitch in degrees */
+    float f_roll;          /**< view point roll in degrees */
+    float f_field_of_view; /**< field of view in degrees (default 80.0f) */
+} libvlc_video_viewpoint_t;
+
+/**
+ * Create a video viewpoint structure.
+ *
+ * \version LibVLC 3.0.0 and later
+ *
+ * \return video viewpoint or NULL
+ *         (the result must be released with free() or libvlc_free()).
+ */
+LIBVLC_API libvlc_video_viewpoint_t *libvlc_video_new_viewpoint(void);
+
+/**
+ * Update the video viewpoint information.
+ *
+ * \note It is safe to call this function before the media player is started.
+ *
+ * \version LibVLC 3.0.0 and later
+ *
+ * \param p_mi the media player
+ * \param p_viewpoint video viewpoint allocated via libvlc_video_new_viewpoint()
+ * \param b_absolute if true replace the old viewpoint with the new one. If
+ * false, increase/decrease it.
+ * \return -1 in case of error, 0 otherwise
+ *
+ * \note the values are set asynchronously, it will be used by the next frame displayed.
+ */
+LIBVLC_API int libvlc_video_update_viewpoint( libvlc_media_player_t *p_mi,
+                                              const libvlc_video_viewpoint_t *p_viewpoint,
+                                              bool b_absolute);
+
+/**
  * Get current video subtitle.
  *
  * \param p_mi the media player
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index b994384..caa5598 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -283,6 +283,8 @@ libvlc_video_set_subtitle_file
 libvlc_video_set_teletext
 libvlc_video_set_track
 libvlc_video_take_snapshot
+libvlc_video_new_viewpoint
+libvlc_video_update_viewpoint
 libvlc_vlm_add_broadcast
 libvlc_vlm_add_vod
 libvlc_vlm_add_input
diff --git a/lib/media_player.c b/lib/media_player.c
index db08274..ba7554c 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -719,6 +719,10 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     if( aout != NULL )
         input_resource_PutAout(mp->input.p_resource, aout);
 
+    vlc_viewpoint_init(&mp->viewpoint);
+
+    var_Create (mp, "viewpoint", VLC_VAR_ADDRESS);
+    var_SetAddress( mp, "viewpoint", &mp->viewpoint );
     vlc_mutex_init (&mp->input.lock);
     mp->i_refcount = 1;
     mp->p_event_manager = libvlc_event_manager_new(mp);
diff --git a/lib/media_player_internal.h b/lib/media_player_internal.h
index f5f101b..1eca3c3 100644
--- a/lib/media_player_internal.h
+++ b/lib/media_player_internal.h
@@ -32,6 +32,7 @@
 #include <vlc/vlc.h>
 #include <vlc/libvlc_media.h>
 #include <vlc_input.h>
+#include <vlc_vout.h>
 
 #include "../modules/audio_filter/equalizer_presets.h"
 
@@ -53,6 +54,7 @@ struct libvlc_media_player_t
     libvlc_media_t * p_md; /* current media descriptor */
     libvlc_event_manager_t * p_event_manager;
     libvlc_state_t state;
+    vlc_viewpoint_t viewpoint;
 };
 
 /* Media player - audio, video */
diff --git a/lib/video.c b/lib/video.c
index 1046fba..4b16564 100644
--- a/lib/video.c
+++ b/lib/video.c
@@ -282,6 +282,53 @@ void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
     free (pp_vouts);
 }
 
+libvlc_video_viewpoint_t *libvlc_video_new_viewpoint(void)
+{
+    libvlc_video_viewpoint_t *p_vp = malloc(sizeof *p_vp);
+    if (unlikely(p_vp == NULL))
+        return NULL;
+    p_vp->f_yaw = p_vp->f_pitch = p_vp->f_roll = p_vp->f_field_of_view = 0.0f;
+    return p_vp;
+}
+
+int libvlc_video_update_viewpoint( libvlc_media_player_t *p_mi,
+                                   const libvlc_video_viewpoint_t *p_viewpoint,
+                                   bool b_absolute )
+{
+    vlc_viewpoint_t update = {
+        .yaw   = p_viewpoint->f_yaw,
+        .pitch = p_viewpoint->f_pitch,
+        .roll  = p_viewpoint->f_roll,
+        .fov   = p_viewpoint->f_field_of_view,
+        .zoom  = 0.0f,
+    };
+
+    input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
+    if( p_input_thread != NULL )
+    {
+        if( input_UpdateViewpoint( p_input_thread, &update,
+                                   b_absolute ) != VLC_SUCCESS )
+        {
+            vlc_object_release( p_input_thread );
+            return -1;
+        }
+        vlc_object_release( p_input_thread );
+    }
+
+    /* Save the viewpoint in case the input is not created yet */
+    if( !b_absolute )
+    {
+        p_mi->viewpoint.yaw += p_mi->viewpoint.yaw;
+        p_mi->viewpoint.pitch += p_mi->viewpoint.pitch;
+        p_mi->viewpoint.roll += p_mi->viewpoint.roll;
+        p_mi->viewpoint.fov += p_mi->viewpoint.fov;
+    }
+    else
+        p_mi->viewpoint = update;
+
+    return 0;
+}
+
 int libvlc_video_get_spu( libvlc_media_player_t *p_mi )
 {
     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );



More information about the vlc-commits mailing list