[vlc-devel] [PATCH 3/8] libvlc: add the API needed to set/get the viewpoint in 360° videos

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


--
replaces https://patches.videolan.org/patch/14420/
* redo the API so that the structure is allocated and released via the API
* add missing libvlc.sym changes
* add API tests
* media_player variables are not inherited
---
 include/vlc/libvlc_media_player.h | 43 +++++++++++++++++++++++++++++++++++++
 lib/libvlc.sym                    |  3 +++
 lib/media_player.c                |  3 +++
 lib/video.c                       | 45 +++++++++++++++++++++++++++++++++++++++
 test/libvlc/media_player.c        | 37 ++++++++++++++++++++++++++++++++
 5 files changed, 131 insertions(+)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index 2718a33..25c1982 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -104,6 +104,16 @@ typedef struct libvlc_audio_output_device_t
 } libvlc_audio_output_device_t;
 
 /**
+ * Viewpoint for video outputs
+ */
+typedef struct libvlc_video_viewpoint_t
+{
+    float f_yaw;   /**< view point yaw in degrees ]-180;180] */
+    float f_pitch; /**< view point pitch in degrees ]-180;180] */
+    float f_roll;  /**< view point roll in degrees ]-180;180] */
+} libvlc_video_viewpoint_t;
+
+/**
  * Marq options definition
  */
 typedef enum libvlc_video_marquee_option_t {
@@ -1127,6 +1137,39 @@ 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 );
 
 /**
+ * Get current video viewpoint.
+ *
+ * \version LibVLC 3.0.0 and later
+ *
+ * \param p_mi the media player
+ * \param p_viewpoint video viewpoint that will be filled or NULL, must be released with
+ * libvlc_video_viewpoint_release()). [OUT]
+ */
+LIBVLC_API void libvlc_video_get_viewpoint( libvlc_media_player_t *p_mi,
+                                            libvlc_video_viewpoint_t **p_viewpoint );
+
+/**
+ * Set new video viewpoint information.
+ *
+ * \version LibVLC 3.0.0 and later
+ *
+ * \param p_mi the media player
+ * \param p_viewpoint new video viewpoint allocated via libvlc_video_get_viewpoint()
+ * or NULL to reset to default
+ */
+LIBVLC_API void libvlc_video_set_viewpoint( libvlc_media_player_t *p_mi,
+                                            const libvlc_video_viewpoint_t *p_viewpoint );
+
+/**
+ * Release a video viewpoint
+ *
+ * \version LibVLC 3.0.0 and later
+ *
+ * \param p_viewpoint video viewpoint to release
+ */
+LIBVLC_API void libvlc_video_viewpoint_release( libvlc_video_viewpoint_t *p_viewpoint );
+
+/**
  * Get current video subtitle.
  *
  * \param p_mi the media player
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index 733a4dd..aede27d 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -271,6 +271,9 @@ libvlc_video_set_subtitle_file
 libvlc_video_set_teletext
 libvlc_video_set_track
 libvlc_video_take_snapshot
+libvlc_video_get_viewpoint
+libvlc_video_set_viewpoint
+libvlc_video_viewpoint_release
 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 69d3523..9f28fad 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -640,6 +640,9 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     var_Create (mp, "zoom", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
     var_Create (mp, "aspect-ratio", VLC_VAR_STRING);
     var_Create (mp, "crop", VLC_VAR_STRING);
+    var_Create (mp, "viewpoint-yaw", VLC_VAR_FLOAT);
+    var_Create (mp, "viewpoint-pitch", VLC_VAR_FLOAT);
+    var_Create (mp, "viewpoint-roll", VLC_VAR_FLOAT);
     var_Create (mp, "deinterlace", VLC_VAR_INTEGER);
     var_Create (mp, "deinterlace-mode", VLC_VAR_STRING);
 
diff --git a/lib/video.c b/lib/video.c
index b2c9b34..08bfb7e 100644
--- a/lib/video.c
+++ b/lib/video.c
@@ -281,6 +281,51 @@ void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
     free (pp_vouts);
 }
 
+void libvlc_video_get_viewpoint( libvlc_media_player_t *p_mi, libvlc_video_viewpoint_t **p_viewpoint )
+{
+    *p_viewpoint = malloc(sizeof(libvlc_video_viewpoint_t));
+    if (*p_viewpoint == NULL)
+        return;
+
+    (*p_viewpoint)->f_yaw   = var_GetFloat( p_mi, "viewpoint-yaw" );
+    (*p_viewpoint)->f_pitch = var_GetFloat( p_mi, "viewpoint-pitch" );
+    (*p_viewpoint)->f_roll  = var_GetFloat( p_mi, "viewpoint-roll" );
+}
+
+void libvlc_video_set_viewpoint( libvlc_media_player_t *p_mi,
+                                 const libvlc_video_viewpoint_t *p_viewpoint )
+{
+    char psz_viewpoint[4 * 13];
+    if (p_viewpoint == NULL)
+        psz_viewpoint[0] = '\0';
+    else
+    {
+        var_SetFloat(p_mi, "viewpoint-yaw",   p_viewpoint->f_yaw);
+        var_SetFloat(p_mi, "viewpoint-pitch", p_viewpoint->f_pitch);
+        var_SetFloat(p_mi, "viewpoint-roll",  p_viewpoint->f_roll);
+
+        sprintf( psz_viewpoint, "%.7f:%.7f:%.7f",
+                 p_viewpoint->f_yaw, p_viewpoint->f_pitch,
+                 p_viewpoint->f_roll );
+    }
+
+    size_t n;
+    vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
+    for (size_t i = 0; i < n; i++)
+    {
+        vout_thread_t *p_vout = pp_vouts[i];
+
+        var_SetString (p_vout, "viewpoint", psz_viewpoint);
+        vlc_object_release (p_vout);
+    }
+    free (pp_vouts);
+}
+
+void libvlc_video_viewpoint_release( libvlc_video_viewpoint_t *p_viewpoint )
+{
+    free( p_viewpoint );
+}
+
 int libvlc_video_get_spu( libvlc_media_player_t *p_mi )
 {
     input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
diff --git a/test/libvlc/media_player.c b/test/libvlc/media_player.c
index f3198b5..ee7ad0b 100644
--- a/test/libvlc/media_player.c
+++ b/test/libvlc/media_player.c
@@ -190,6 +190,42 @@ static void test_media_player_pause_stop(const char** argv, int argc)
     libvlc_release (vlc);
 }
 
+static void test_media_player_viewpoint(const char** argv, int argc)
+{
+    libvlc_instance_t *vlc;
+    libvlc_media_t *md;
+    libvlc_media_player_t *mi;
+    const char * file = test_default_sample;
+
+    log ("Testing viewpoint for %s\n", file);
+
+    vlc = libvlc_new (argc, argv);
+    assert (vlc != NULL);
+
+    md = libvlc_media_new_path (vlc, file);
+    assert (md != NULL);
+
+    mi = libvlc_media_player_new_from_media (md);
+    assert (mi != NULL);
+
+    libvlc_media_release (md);
+
+    libvlc_video_viewpoint_t *p_viewpoint;
+    libvlc_video_get_viewpoint(mi, &p_viewpoint);
+    assert(p_viewpoint != NULL);
+
+    p_viewpoint->f_yaw = 1.57f;
+    libvlc_video_set_viewpoint(mi, p_viewpoint);
+    libvlc_video_viewpoint_release(p_viewpoint);
+
+    libvlc_video_get_viewpoint(mi, &p_viewpoint);
+    assert(p_viewpoint != NULL);
+    assert(p_viewpoint->f_yaw == 1.57f);
+    libvlc_video_viewpoint_release(p_viewpoint);
+
+    libvlc_media_player_release (mi);
+    libvlc_release (vlc);
+}
 
 int main (void)
 {
@@ -198,6 +234,7 @@ int main (void)
     test_media_player_set_media (test_defaults_args, test_defaults_nargs);
     test_media_player_play_stop (test_defaults_args, test_defaults_nargs);
     test_media_player_pause_stop (test_defaults_args, test_defaults_nargs);
+    test_media_player_viewpoint (test_defaults_args, test_defaults_nargs);
 
     return 0;
 }
-- 
2.7.2.windows.1



More information about the vlc-devel mailing list