[vlc-devel] [PATCH 3/5] demux: mp4: read the 360° yaw/picth/roll with the projection

Hugo Beauzée-Luyssen hugo at beauzee.fr
Thu Nov 10 15:28:04 CET 2016


On 11/10/2016 03:19 PM, Steve Lhomme wrote:
> ---
>  modules/demux/mp4/essetup.c |  5 +++++
>  modules/demux/mp4/libmp4.c  | 30 ++++++++++++++++++++++++++++++
>  modules/demux/mp4/libmp4.h  |  3 +++
>  3 files changed, 38 insertions(+)
>
> diff --git a/modules/demux/mp4/essetup.c b/modules/demux/mp4/essetup.c
> index d85bd8b..1aff644 100644
> --- a/modules/demux/mp4/essetup.c
> +++ b/modules/demux/mp4/essetup.c
> @@ -352,7 +352,12 @@ int SetupVideoES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
>          if( p_uuid->i_type == ATOM_uuid
>              && !CmpUUID( &p_uuid->i_uuid, &XML360BoxUUID )
>              && p_uuid->data.p_360 )
> +        {
>              p_track->fmt.video.projection_mode = p_uuid->data.p_360->i_projection_mode;
> +            p_track->fmt.video.f_pose_yaw_degrees = p_uuid->data.p_360->f_heading;
> +            p_track->fmt.video.f_pose_pitch_degrees = p_uuid->data.p_360->f_pitch;
> +            p_track->fmt.video.f_pose_roll_degrees = p_uuid->data.p_360->f_roll;
> +        }
>      }
>
>      /* It's a little ugly but .. there are special cases */
> diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
> index e121dfe..8cf26ff 100644
> --- a/modules/demux/mp4/libmp4.c
> +++ b/modules/demux/mp4/libmp4.c
> @@ -713,6 +713,26 @@ static int MP4_ReadBox_tfrf(  stream_t *p_stream, MP4_Box_t *p_box )
>      MP4_READBOX_EXIT( 1 );
>  }
>
> +static bool getRDFFloat(const char *psz_rdf, const char *psz_var, float *out)
> +{
> +    size_t varlen = strlen(psz_var);

You can compute this after checking if it's worth it I guess

> +    char *p_start = strcasestr( psz_rdf, psz_var );
> +    if (p_start == NULL)
> +        return false;
> +
> +    char *p_end = strchr( p_start + varlen, '"');
> +    if (unlikely(p_end == NULL))
> +        return false;
> +
> +    char pose[p_end - p_start + 1];
> +    memcpy(pose, p_start + varlen, p_end - p_start - varlen);
> +    pose[p_end - p_start - varlen] = 0;
> +    if (sscanf(pose, "%f", out) != 1)

Couldn't you achieve the same result without memcpy/sscanf by using strtod?

> +        return false;
> +
> +    return true;
> +}
> +
>  static int MP4_ReadBox_XML360( stream_t *p_stream, MP4_Box_t *p_box )
>  {
>      MP4_READBOX_ENTER( MP4_Box_data_360_t, NULL );
> @@ -732,6 +752,16 @@ static int MP4_ReadBox_XML360( stream_t *p_stream, MP4_Box_t *p_box )
>      if ( strcasestr( psz_rdf, "Gspherical:Spherical" ) )
>          p_360_data->i_projection_mode = PROJECTION_MODE_EQUIRECTANGULAR;
>
> +    float value;
> +    if (getRDFFloat( psz_rdf, "InitialViewHeadingDegrees=\"", &value ))
> +        p_360_data->f_heading = value;
> +
> +    if (getRDFFloat( psz_rdf, "InitialViewPitchDegrees=\"", &value ))
> +        p_360_data->f_pitch = value;
> +
> +    if (getRDFFloat( psz_rdf, "InitialViewRollDegrees=\"", &value ))
> +        p_360_data->f_roll = value;
> +
>      /* Try to find the stero mode. */
>      if ( strcasestr( psz_rdf, "left-right" ) )
>          msg_Dbg( p_stream, "Left-right stereo mode" );
> diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
> index c72f85a..0209652 100644
> --- a/modules/demux/mp4/libmp4.h
> +++ b/modules/demux/mp4/libmp4.h
> @@ -1541,6 +1541,9 @@ typedef struct
>  typedef struct
>  {
>      uint32_t i_projection_mode;
> +    float f_heading;
> +    float f_pitch;
> +    float f_roll;
>  } MP4_Box_data_360_t;
>
>  /*
>



More information about the vlc-devel mailing list