[vlc-devel] [PATCH 3/8] libvlc: add the API needed to set/get the viewpoint in 360° videos
Steve Lhomme
robux4 at gmail.com
Thu Sep 15 10:19:55 CEST 2016
On Thu, Sep 15, 2016 at 9:55 AM, Rémi Denis-Courmont <remi at remlab.net> wrote:
> Le torstaina 15. syyskuuta 2016, 9.44.11 EEST Steve Lhomme a écrit :
>> --
>> 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
>>
>> replaces https://patches.videolan.org/patch/14457/
>> * warn the user the structure must be allocated with get_viewpoint()
>> * get_viewpoint() returns the allocated structure directly
>> * use libvlc_free instead of a release function
>> * move the structure so it's in a libvlc video doc
>> ---
>> include/vlc/libvlc_media_player.h | 35 +++++++++++++++++++++++++++++++++
>> lib/libvlc.sym | 2 ++
>> lib/media_player.c | 3 +++
>> lib/video.c | 41
>> +++++++++++++++++++++++++++++++++++++++ test/libvlc/media_player.c |
>> 36 ++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+)
>>
>> diff --git a/include/vlc/libvlc_media_player.h
>> b/include/vlc/libvlc_media_player.h index 2718a33..4681497 100644
>> --- a/include/vlc/libvlc_media_player.h
>> +++ b/include/vlc/libvlc_media_player.h
>> @@ -1127,6 +1127,41 @@ 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_get_viewpoint()
>> + */
>> +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;
>> +
>> +/**
>> + * Get current video viewpoint.
>> + *
>> + * \version LibVLC 3.0.0 and later
>> + *
>> + * \param p_mi the media player
>> + * \return video viewpoint that will be filled or NULL
>> + * (the result must be released with free() or libvlc_free()).
>> + */
>> +LIBVLC_API libvlc_video_viewpoint_t *libvlc_video_get_viewpoint(
>> libvlc_media_player_t *p_mi ); +
>> +/**
>> + * 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 ); +
>> +/**
>> * Get current video subtitle.
>> *
>> * \param p_mi the media player
>> diff --git a/lib/libvlc.sym b/lib/libvlc.sym
>> index 733a4dd..dbfad1e 100644
>> --- a/lib/libvlc.sym
>> +++ b/lib/libvlc.sym
>> @@ -271,6 +271,8 @@ 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_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..dae9539 100644
>> --- a/lib/video.c
>> +++ b/lib/video.c
>> @@ -281,6 +281,47 @@ void libvlc_video_set_aspect_ratio(
>> libvlc_media_player_t *p_mi, free (pp_vouts);
>> }
>>
>> +libvlc_video_viewpoint_t *libvlc_video_get_viewpoint( libvlc_media_player_t
>> *p_mi )
>
> How does this work with multiple vouts?
They all share the same value. But maybe some callers may want to set
different values on different vouts. I'll change that.
>> +{
>> + libvlc_video_viewpoint_t *p_viewpoint =
>> malloc(sizeof(libvlc_video_viewpoint_t)); + if (p_viewpoint == NULL)
>> + return NULL;
>> +
>> + 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" );
>> + return p_viewpoint;
>> +}
>> +
>> +void libvlc_video_set_viewpoint( libvlc_media_player_t *p_mi,
>> + const libvlc_video_viewpoint_t
>> *p_viewpoint )
>
> Ditto.
I'll add a parameter to define with vout to target.
>> +{
>> + 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 );
>
> I really dislike this. If you want to set/get multiple parameters atomically,
> just don´t use object variables.
I'll add vout_SetViewpoint() since we address a vout_thread_t* directly anyway.
>> + }
>> +
>> + 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);
>> +}
>> +
>> 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..1fec83f 100644
>> --- a/test/libvlc/media_player.c
>> +++ b/test/libvlc/media_player.c
>> @@ -190,6 +190,41 @@ 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);
>> + assert(p_viewpoint != NULL);
>> +
>> + p_viewpoint->f_yaw = 1.57f;
>> + libvlc_video_set_viewpoint(mi, p_viewpoint);
>> + libvlc_free(p_viewpoint);
>> +
>> + p_viewpoint = libvlc_video_get_viewpoint(mi);
>> + assert(p_viewpoint != NULL);
>> + assert(p_viewpoint->f_yaw == 1.57f);
>> + libvlc_free(p_viewpoint);
>> +
>> + libvlc_media_player_release (mi);
>> + libvlc_release (vlc);
>> +}
>>
>> int main (void)
>> {
>> @@ -198,6 +233,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;
>> }
>
>
> --
> Rémi Denis-Courmont
> http://www.remlab.net/
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list