[vlc-devel] [PATCH 07/28] core: change var_InheritURational to output a vlc_rational_t

Filip Roséen filip at atch.se
Sun Apr 2 23:24:35 CEST 2017



On 2017-03-31 18:14, Steve Lhomme wrote:

> ---
>  include/vlc_variables.h                  |  4 ++--
>  modules/access/decklink.cpp              |  2 +-
>  modules/access/imem.c                    |  4 ++--
>  modules/access/timecode.c                |  3 +--
>  modules/access/v4l2/video.c              |  9 ++++-----
>  modules/demux/image.c                    |  4 ++--
>  modules/demux/rawvid.c                   |  5 ++---
>  modules/stream_out/transcode/transcode.c |  2 +-
>  modules/video_filter/fps.c               |  2 +-
>  src/misc/variables.c                     | 16 ++++++++--------
>  src/video_output/video_output.c          |  3 +--
>  test/src/misc/variables.c                | 32 ++++++++++++++++----------------
>  12 files changed, 41 insertions(+), 45 deletions(-)
> 
> diff --git a/include/vlc_variables.h b/include/vlc_variables.h
> index 83752b171f..59ad99367c 100644
> --- a/include/vlc_variables.h
> +++ b/include/vlc_variables.h
> @@ -652,8 +652,8 @@ static inline void *var_InheritAddress( vlc_object_t *obj, const char *name )
>  }
>  #define var_InheritAddress(o, n) var_InheritAddress(VLC_OBJECT(o), n)
>  
> -VLC_API int var_InheritURational( vlc_object_t *, unsigned *num, unsigned *den, const char *var );
> -#define var_InheritURational(a,b,c,d) var_InheritURational(VLC_OBJECT(a), b, c, d)
> +VLC_API int var_InheritURational( vlc_object_t *, vlc_rational_t *dst, const char *var );
> +#define var_InheritURational(a,b,d) var_InheritURational(VLC_OBJECT(a), b, d)
>  
>  #define var_GetInteger(a,b)   var_GetInteger( VLC_OBJECT(a),b)
>  #define var_GetBool(a,b)   var_GetBool( VLC_OBJECT(a),b)
> diff --git a/modules/access/decklink.cpp b/modules/access/decklink.cpp
> index c4c043559b..248009ed15 100644
> --- a/modules/access/decklink.cpp
> +++ b/modules/access/decklink.cpp
> @@ -197,7 +197,7 @@ static es_format_t GetModeSettings(demux_t *demux, IDeckLinkDisplayMode *m)
>      video_fmt.i_bitrate = video_fmt.video.i_width * video_fmt.video.i_height * video_fmt.video.i_frame_rate * 2 * 8;
>  
>      vlc_rational_t aspect;
> -    if (!var_InheritURational(demux, &aspect.num, &aspect.den, "decklink-aspect-ratio") &&
> +    if (!var_InheritURational(demux, &aspect, "decklink-aspect-ratio") &&
>           aspect_num > 0 && aspect_den > 0) {

The above leaves usage of `aspect_num` and `aspect_den`, even though
these are no longer written to by `var_InheritURational` - which
cannot be correct.

>          video_fmt.video.i_sar_num = aspect.num * video_fmt.video.i_height;
>          video_fmt.video.i_sar_den = aspect.den * video_fmt.video.i_width;
> diff --git a/modules/access/imem.c b/modules/access/imem.c
> index dbdc982075..e6974e1182 100644
> --- a/modules/access/imem.c
> +++ b/modules/access/imem.c
> @@ -431,13 +431,13 @@ static int OpenDemux(vlc_object_t *object)
>          fmt.video.i_width  = var_InheritInteger(object, "imem-width");
>          fmt.video.i_height = var_InheritInteger(object, "imem-height");
>          vlc_rational_t rat;
> -        if (!var_InheritURational(object, &rat.num, &rat.den, "imem-dar") && rat.num && rat.den) {
> +        if (!var_InheritURational(object, &rat, "imem-dar") && rat.num && rat.den) {
>              if (fmt.video.i_width > 0 && fmt.video.i_height > 0) {
>                  fmt.video.i_sar_num = rat.num * fmt.video.i_height;
>                  fmt.video.i_sar_den = rat.den * fmt.video.i_width;
>              }
>          }
> -        if (!var_InheritURational(object, &rat.num, &rat.den, "imem-fps") && rat.num && rat.den) {
> +        if (!var_InheritURational(object, &rat, "imem-fps") && rat.num && rat.den) {
>              fmt.video.i_frame_rate      = rat.num;
>              fmt.video.i_frame_rate_base = rat.den;
>          }
> diff --git a/modules/access/timecode.c b/modules/access/timecode.c
> index fd579792ca..18d8ed40ce 100644
> --- a/modules/access/timecode.c
> +++ b/modules/access/timecode.c
> @@ -178,8 +178,7 @@ static int Open (vlc_object_t *obj)
>      sys->es = es_out_Add (demux->out, &fmt);
>  
>      vlc_rational_t fps;
> -    if (var_InheritURational (demux, &fps.num, &fps.den, "timecode-fps")
> -     || !fps.num || !fps.den)
> +    if (var_InheritURational (demux, &fps, "timecode-fps") || !fps.num || !fps.den)
>      {
>          msg_Err (demux, "invalid frame rate");
>          free (sys);
> diff --git a/modules/access/v4l2/video.c b/modules/access/v4l2/video.c
> index 96bd3bb91e..c36945c049 100644
> --- a/modules/access/v4l2/video.c
> +++ b/modules/access/v4l2/video.c
> @@ -438,12 +438,11 @@ int SetupFormat (vlc_object_t *obj, int fd, uint32_t fourcc,
>      uint64_t best_area = 0;
>  
>      vlc_rational_t fps;
> -    if (var_InheritURational(obj, &fps.den, &fps.num,
> -                             CFG_PREFIX"fps") == VLC_SUCCESS)
> +    if (var_InheritURational(obj, &fps, CFG_PREFIX"fps") == VLC_SUCCESS)
>      {
> -        msg_Dbg (obj, " requested frame internal: %u/%u", fps.num, fps.den);
> -        min_it.numerator   = fps.num;
> -        min_it.denominator = fps.den;
> +        msg_Dbg (obj, " requested frame internal: %u/%u", fps.den, fps.num);
> +        min_it.numerator   = fps.den;
> +        min_it.denominator = fps.num;
>      }
>      else
>          min_it = zero;
> diff --git a/modules/demux/image.c b/modules/demux/image.c
> index 9663fb516a..1904d20119 100644
> --- a/modules/demux/image.c
> +++ b/modules/demux/image.c
> @@ -666,8 +666,8 @@ static int Open(vlc_object_t *object)
>      fmt.i_id    = var_InheritInteger(demux, "image-id");
>      fmt.i_group = var_InheritInteger(demux, "image-group");
>      vlc_rational_t fps;
> -    if (var_InheritURational(demux, &fps.num, &fps.den, "image-fps") ||
> -        !fps.num || !fps.den) {
> +    if (var_InheritURational(demux, &fps, "image-fps") || !fps.num || !fps.den)
> +    {
>          msg_Err(demux, "Invalid frame rate, using 10/1 instead");
>          fps.num      = 10;
>          fps.den      = 1;
> diff --git a/modules/demux/rawvid.c b/modules/demux/rawvid.c
> index d503f856fb..d92fd9e842 100644
> --- a/modules/demux/rawvid.c
> +++ b/modules/demux/rawvid.c
> @@ -291,14 +291,13 @@ valid:
>          free( psz_tmp );
>      }
>  
> -    if( var_InheritURational( p_demux, &fps.num, &fps.den, "rawvid-fps" ) )
> +    if( var_InheritURational( p_demux, &fps, "rawvid-fps" ) )
>      {
>          fps.num = 0;
>          fps.den = 1;
>      }
>  
> -    if( var_InheritURational( p_demux, &sar.num, &sar.den,
> -                              "rawvid-aspect-ratio" ) )
> +    if( var_InheritURational( p_demux, &sar, "rawvid-aspect-ratio" ) )
>          sar.num = sar.den = 1;
>  
>      /* moan about anything wrong */
> diff --git a/modules/stream_out/transcode/transcode.c b/modules/stream_out/transcode/transcode.c
> index 0f91d252c6..e22e256a80 100644
> --- a/modules/stream_out/transcode/transcode.c
> +++ b/modules/stream_out/transcode/transcode.c
> @@ -346,7 +346,7 @@ static int Open( vlc_object_t *p_this )
>  
>      p_sys->f_scale = var_GetFloat( p_stream, SOUT_CFG_PREFIX "scale" );
>  
> -    p_sys->b_master_sync = var_InheritURational( p_stream, &p_sys->fps.num, &p_sys->fps.den, SOUT_CFG_PREFIX "fps" ) == VLC_SUCCESS;
> +    p_sys->b_master_sync = var_InheritURational( p_stream, &p_sys->fps, SOUT_CFG_PREFIX "fps" ) == VLC_SUCCESS;
>  
>      p_sys->i_width = var_GetInteger( p_stream, SOUT_CFG_PREFIX "width" );
>  
> diff --git a/modules/video_filter/fps.c b/modules/video_filter/fps.c
> index 5222b17233..146c870e72 100644
> --- a/modules/video_filter/fps.c
> +++ b/modules/video_filter/fps.c
> @@ -151,7 +151,7 @@ static int Open( vlc_object_t *p_this)
>      video_format_Copy( &p_filter->fmt_out.video, &p_filter->fmt_in.video );
>  
>      /* If we don't have fps option, use filter output values */
> -    if( var_InheritURational( p_filter, &fps.num, &fps.den, CFG_PREFIX "fps" ) )
> +    if( var_InheritURational( p_filter, &fps, CFG_PREFIX "fps" ) )
>      {
>          fps.num = p_filter->fmt_in.video.i_frame_rate;
>          fps.den = p_filter->fmt_in.video.i_frame_rate_base;
> diff --git a/src/misc/variables.c b/src/misc/variables.c
> index 72296111e1..53a35f03a2 100644
> --- a/src/misc/variables.c
> +++ b/src/misc/variables.c
> @@ -1214,7 +1214,7 @@ int var_Inherit( vlc_object_t *p_this, const char *psz_name, int i_type,
>   * The rational is already reduced.
>   */
>  int (var_InheritURational)(vlc_object_t *object,
> -                           unsigned *num, unsigned *den,
> +                           vlc_rational_t *dst,
>                             const char *var)
>  {
>      char *str = var_InheritString(object, var);
> @@ -1263,20 +1263,20 @@ int (var_InheritURational)(vlc_object_t *object,
>      free(str);
>  
>      if (n == 0) {
> -        *num = 0;
> -        *den = d ? 1 : 0;
> +        dst->num = 0;
> +        dst->den = d ? 1 : 0;
>      } else if (d == 0) {
> -        *num = 1;
> -        *den = 0;
> +        dst->num = 1;
> +        dst->den = 0;
>      } else
> -        vlc_ureduce(num, den, n, d, 0);
> +        vlc_ureduce(&dst->num, &dst->den, n, d, 0);
>  
>      return VLC_SUCCESS;
>  
>  error:
>      free(str);
> -    *num = 0;
> -    *den = 0;
> +    dst->num = 0;
> +    dst->den = 0;
>      return VLC_EGENERIC;
>  }
>  
> diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
> index a9abda4342..ec052f9585 100644
> --- a/src/video_output/video_output.c
> +++ b/src/video_output/video_output.c
> @@ -576,8 +576,7 @@ static void VoutGetDisplayCfg(vout_thread_t *vout, vout_display_cfg_t *cfg, cons
>      cfg->display.width   = display_width > 0  ? display_width  : 0;
>      cfg->display.height  = display_height > 0 ? display_height : 0;
>      cfg->is_display_filled  = var_GetBool(vout, "autoscale");
> -    if (var_InheritURational(vout, &cfg->display.sar.num, &cfg->display.sar.den,
> -                             "monitor-par") |
> +    if (var_InheritURational(vout, &cfg->display.sar, "monitor-par") ||
>              !cfg->display.sar.num  || !cfg->display.sar.den) {
>          cfg->display.sar.num = 1;
>          cfg->display.sar.den = 1;
> diff --git a/test/src/misc/variables.c b/test/src/misc/variables.c
> index 3d95c9f465..20fc302f7e 100644
> --- a/test/src/misc/variables.c
> +++ b/test/src/misc/variables.c
> @@ -104,63 +104,63 @@ static void test_fracts( libvlc_int_t *p_libvlc )
>      vlc_rational_t frac;
>  
>      var_Create( p_libvlc, name, VLC_VAR_STRING );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) != 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) != 0 );
>  
>      var_SetString( p_libvlc, name, "123garbage" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) != 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) != 0 );
>  
>      var_SetString( p_libvlc, name, "4/5garbage" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) != 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) != 0 );
>  
>      var_SetString( p_libvlc, name, "6.7garbage" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) != 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) != 0 );
>  
>      var_SetString( p_libvlc, name, "." );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 0 && frac.den == 1 );
>  
>      var_SetString( p_libvlc, name, "010" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 10 && frac.den == 1 );
>  
>      var_SetString( p_libvlc, name, "30" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 30 && frac.den == 1 );
>  
>      var_SetString( p_libvlc, name, "30.0" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 30 && frac.den == 1 );
>  
>      var_SetString( p_libvlc, name, "030.030" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 3003 && frac.den == 100 );
>  
>      var_SetString( p_libvlc, name, "60/2" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 30 && frac.den == 1 );
>  
>      var_SetString( p_libvlc, name, "29.97" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 2997 && frac.den == 100 );
>  
>      var_SetString( p_libvlc, name, "30000/1001" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 30000 && frac.den == 1001 );
>  
>      var_SetString( p_libvlc, name, ".125" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 1 && frac.den == 8 );
>  
>      var_SetString( p_libvlc, name, "12:9" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 4 && frac.den == 3 );
>  
>      var_SetString( p_libvlc, name, "000000/00000000" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 0 && frac.den == 0 );
>  
>      var_SetString( p_libvlc, name, "12345/0" );
> -    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
> +    assert( var_InheritURational( p_libvlc, &frac, name ) == 0 );
>      assert( frac.num == 1 && frac.den == 0 );
>  
>      var_Destroy( p_libvlc, name );
> -- 
> 2.11.1
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20170402/5c9f45e1/attachment.html>


More information about the vlc-devel mailing list