Commit e23cb34d authored by Steve Lhomme's avatar Steve Lhomme Committed by Thomas Guillem

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

Signed-off-by: Thomas Guillem's avatarThomas Guillem <thomas@gllm.fr>
parent 562a5f59
......@@ -1166,6 +1166,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.
*
......
......@@ -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
......
......@@ -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);
......
......@@ -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 */
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment