[vlc-devel] [PATCH 06/28] always call var_InheritURational with a vlc_rational_t based output

Steve Lhomme robux4 at videolabs.io
Mon Apr 3 10:21:54 CEST 2017


--
replaces https://patches.videolan.org/patch/16225/
- fix missing replacement of aspect_num/den
---
 modules/access/decklink.cpp              | 10 +++---
 modules/access/imem.c                    | 14 ++++----
 modules/access/timecode.c                |  8 ++---
 modules/access/v4l2/video.c              | 10 ++++--
 modules/demux/image.c                    | 14 ++++----
 modules/demux/rawvid.c                   | 46 ++++++++++++-------------
 modules/stream_out/transcode/transcode.c |  2 +-
 modules/stream_out/transcode/transcode.h |  2 +-
 modules/stream_out/transcode/video.c     |  6 ++--
 modules/video_filter/fps.c               | 10 +++---
 src/video_output/video_output.c          | 12 +++----
 test/src/misc/variables.c                | 58 ++++++++++++++++----------------
 12 files changed, 96 insertions(+), 96 deletions(-)

diff --git a/modules/access/decklink.cpp b/modules/access/decklink.cpp
index 872a4bdaa7..b4d054c6fa 100644
--- a/modules/access/decklink.cpp
+++ b/modules/access/decklink.cpp
@@ -196,11 +196,11 @@ static es_format_t GetModeSettings(demux_t *demux, IDeckLinkDisplayMode *m)
     video_fmt.video.i_frame_rate_base = frame_duration;
     video_fmt.i_bitrate = video_fmt.video.i_width * video_fmt.video.i_height * video_fmt.video.i_frame_rate * 2 * 8;
 
-    unsigned aspect_num, aspect_den;
-    if (!var_InheritURational(demux, &aspect_num, &aspect_den, "decklink-aspect-ratio") &&
-         aspect_num > 0 && aspect_den > 0) {
-        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;
+    vlc_rational_t aspect;
+    if (!var_InheritURational(demux, &aspect.num, &aspect.den, "decklink-aspect-ratio") &&
+         aspect.num > 0 && aspect.den > 0) {
+        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;
     }
 
     sys->dominance_flags = flags;
diff --git a/modules/access/imem.c b/modules/access/imem.c
index 73b0c34ef2..dbdc982075 100644
--- a/modules/access/imem.c
+++ b/modules/access/imem.c
@@ -430,16 +430,16 @@ static int OpenDemux(vlc_object_t *object)
         fmt.i_cat = VIDEO_ES;
         fmt.video.i_width  = var_InheritInteger(object, "imem-width");
         fmt.video.i_height = var_InheritInteger(object, "imem-height");
-        unsigned num, den;
-        if (!var_InheritURational(object, &num, &den, "imem-dar") && num > 0 && den > 0) {
+        vlc_rational_t rat;
+        if (!var_InheritURational(object, &rat.num, &rat.den, "imem-dar") && rat.num && rat.den) {
             if (fmt.video.i_width > 0 && fmt.video.i_height > 0) {
-                fmt.video.i_sar_num = num * fmt.video.i_height;
-                fmt.video.i_sar_den = den * fmt.video.i_width;
+                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, &num, &den, "imem-fps") && num > 0 && den > 0) {
-            fmt.video.i_frame_rate      = num;
-            fmt.video.i_frame_rate_base = den;
+        if (!var_InheritURational(object, &rat.num, &rat.den, "imem-fps") && rat.num && rat.den) {
+            fmt.video.i_frame_rate      = rat.num;
+            fmt.video.i_frame_rate_base = rat.den;
         }
 
         msg_Dbg(object, "Video %4.4s %dx%d  SAR %d:%d frame rate %u/%u",
diff --git a/modules/access/timecode.c b/modules/access/timecode.c
index 8e37e2ca16..fd579792ca 100644
--- a/modules/access/timecode.c
+++ b/modules/access/timecode.c
@@ -177,16 +177,16 @@ static int Open (vlc_object_t *obj)
     es_format_Init (&fmt, SPU_ES, VLC_CODEC_ITU_T140);
     sys->es = es_out_Add (demux->out, &fmt);
 
-    unsigned num, den;
-    if (var_InheritURational (demux, &num, &den, "timecode-fps")
-     || !num || !den)
+    vlc_rational_t fps;
+    if (var_InheritURational (demux, &fps.num, &fps.den, "timecode-fps")
+     || !fps.num || !fps.den)
     {
         msg_Err (demux, "invalid frame rate");
         free (sys);
         return VLC_EGENERIC;
     }
 
-    date_Init (&sys->date, num, den);
+    date_Init (&sys->date, fps.num, fps.den);
     date_Set (&sys->date, VLC_TS_0);
     sys->next_time = VLC_TS_INVALID;
 
diff --git a/modules/access/v4l2/video.c b/modules/access/v4l2/video.c
index b8544ea7ec..96bd3bb91e 100644
--- a/modules/access/v4l2/video.c
+++ b/modules/access/v4l2/video.c
@@ -437,10 +437,14 @@ int SetupFormat (vlc_object_t *obj, int fd, uint32_t fourcc,
     struct v4l2_fract best_it = infinity, min_it;
     uint64_t best_area = 0;
 
-    if (var_InheritURational(obj, &min_it.denominator, &min_it.numerator,
+    vlc_rational_t fps;
+    if (var_InheritURational(obj, &fps.den, &fps.num,
                              CFG_PREFIX"fps") == VLC_SUCCESS)
-        msg_Dbg (obj, " requested frame internal: %"PRIu32"/%"PRIu32,
-                 min_it.numerator, min_it.denominator);
+    {
+        msg_Dbg (obj, " requested frame internal: %u/%u", fps.num, fps.den);
+        min_it.numerator   = fps.num;
+        min_it.denominator = fps.den;
+    }
     else
         min_it = zero;
 
diff --git a/modules/demux/image.c b/modules/demux/image.c
index 6ccca310ce..9663fb516a 100644
--- a/modules/demux/image.c
+++ b/modules/demux/image.c
@@ -665,15 +665,15 @@ static int Open(vlc_object_t *object)
     }
     fmt.i_id    = var_InheritInteger(demux, "image-id");
     fmt.i_group = var_InheritInteger(demux, "image-group");
-    if (var_InheritURational(demux,
-                             &fmt.video.i_frame_rate,
-                             &fmt.video.i_frame_rate_base,
-                             "image-fps") ||
-        fmt.video.i_frame_rate <= 0 || fmt.video.i_frame_rate_base <= 0) {
+    vlc_rational_t fps;
+    if (var_InheritURational(demux, &fps.num, &fps.den, "image-fps") ||
+        !fps.num || !fps.den) {
         msg_Err(demux, "Invalid frame rate, using 10/1 instead");
-        fmt.video.i_frame_rate      = 10;
-        fmt.video.i_frame_rate_base = 1;
+        fps.num      = 10;
+        fps.den      = 1;
     }
+    fmt.video.i_frame_rate      = fps.num;
+    fmt.video.i_frame_rate_base = fps.den;
 
     /* If loadind failed, we still continue to avoid mis-detection
      * by other demuxers. */
diff --git a/modules/demux/rawvid.c b/modules/demux/rawvid.c
index 11d27a145b..d503f856fb 100644
--- a/modules/demux/rawvid.c
+++ b/modules/demux/rawvid.c
@@ -103,10 +103,8 @@ struct preset_t
     const char *psz_ext;
     int i_width;
     int i_height;
-    unsigned u_fps_num;
-    unsigned u_fps_den;
-    unsigned u_ar_num;
-    unsigned u_ar_den;
+    vlc_rational_t fps;
+    vlc_rational_t ar;
     vlc_fourcc_t i_chroma;
 };
 
@@ -129,10 +127,9 @@ static int Open( vlc_object_t * p_this )
     demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys;
     int i_width=-1, i_height=-1;
-    unsigned u_fps_num, u_fps_den;
+    vlc_rational_t fps;
     vlc_fourcc_t i_chroma = 0;
-    unsigned int i_sar_num;
-    unsigned int i_sar_den;
+    vlc_rational_t sar;
     const struct preset_t *p_preset = NULL;
     const uint8_t *p_peek;
     bool b_y4m = false;
@@ -180,10 +177,9 @@ valid:
     {
         i_width = p_preset->i_width;
         i_height = p_preset->i_height;
-        u_fps_num = p_preset->u_fps_num;
-        u_fps_den = p_preset->u_fps_den;
-        i_sar_num = p_preset->u_ar_num * p_preset->i_height;
-        i_sar_den = p_preset->u_ar_den * p_preset->i_width;
+        fps = p_preset->fps;
+        sar.num = p_preset->ar.num * p_preset->i_height;
+        sar.den = p_preset->ar.den * p_preset->i_width;
         i_chroma = p_preset->i_chroma;
     }
 
@@ -225,13 +221,13 @@ valid:
         } } while(0)
         READ_FRAC( " W", i_width, a );
         READ_FRAC( " H", i_height, a );
-        READ_FRAC( " F", u_fps_num, u_fps_den );
+        READ_FRAC( " F", fps.num, fps.den );
         READ_FRAC( " A", a, b );
 #undef READ_FRAC
         if( b != 0 )
         {
-            i_sar_num = a;
-            i_sar_den = b;
+            sar.num = a;
+            sar.den = b;
         }
 
         psz_buf = strstr( psz+9, " C" );
@@ -295,15 +291,15 @@ valid:
         free( psz_tmp );
     }
 
-    if( var_InheritURational( p_demux, &u_fps_num, &u_fps_den, "rawvid-fps" ) )
+    if( var_InheritURational( p_demux, &fps.num, &fps.den, "rawvid-fps" ) )
     {
-        u_fps_num = 0;
-        u_fps_den = 1;
+        fps.num = 0;
+        fps.den = 1;
     }
 
-    if( var_InheritURational( p_demux, &i_sar_num, &i_sar_den,
+    if( var_InheritURational( p_demux, &sar.num, &sar.den,
                               "rawvid-aspect-ratio" ) )
-        i_sar_num = i_sar_den = 1;
+        sar.num = sar.den = 1;
 
     /* moan about anything wrong */
     if( i_width <= 0 || i_height <= 0 )
@@ -312,7 +308,7 @@ valid:
         goto error;
     }
 
-    if( !u_fps_num || !u_fps_den )
+    if( !fps.num || !fps.den )
     {
         msg_Err( p_demux, "invalid or no framerate specified." );
         goto error;
@@ -325,21 +321,21 @@ valid:
     }
 
     /* fixup anything missing with sensible assumptions */
-    if( i_sar_num <= 0 || i_sar_den <= 0 )
+    if( sar.num <= 0 || sar.den <= 0 )
     {
         /* assume 1:1 sar */
-        i_sar_num = 1;
-        i_sar_den = 1;
+        sar.num = 1;
+        sar.den = 1;
     }
 
     es_format_Init( &p_sys->fmt_video, VIDEO_ES, i_chroma );
     video_format_Setup( &p_sys->fmt_video.video, i_chroma,
                         i_width, i_height, i_width, i_height,
-                        i_sar_num, i_sar_den );
+                        sar.num, sar.den );
 
     vlc_ureduce( &p_sys->fmt_video.video.i_frame_rate,
                  &p_sys->fmt_video.video.i_frame_rate_base,
-                 u_fps_num, u_fps_den, 0);
+                 fps.num, fps.den, 0);
     date_Init( &p_sys->pcr, p_sys->fmt_video.video.i_frame_rate,
                p_sys->fmt_video.video.i_frame_rate_base );
     date_Set( &p_sys->pcr, 0 );
diff --git a/modules/stream_out/transcode/transcode.c b/modules/stream_out/transcode/transcode.c
index ebfcf14ebe..0f91d252c6 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.num, &p_sys->fps.den, SOUT_CFG_PREFIX "fps" ) == VLC_SUCCESS;
 
     p_sys->i_width = var_GetInteger( p_stream, SOUT_CFG_PREFIX "width" );
 
diff --git a/modules/stream_out/transcode/transcode.h b/modules/stream_out/transcode/transcode.h
index 7a1a3918dc..cea6eb59a0 100644
--- a/modules/stream_out/transcode/transcode.h
+++ b/modules/stream_out/transcode/transcode.h
@@ -50,7 +50,7 @@ struct sout_stream_sys_t
     int             i_threads;
     bool            b_high_priority;
     bool            b_hurry_up;
-    unsigned int    fps_num,fps_den;
+    vlc_rational_t  fps;
 
     char            *psz_vf2;
 
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 079fad2bd4..bd282007d3 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -954,10 +954,10 @@ bool transcode_video_add( sout_stream_t *p_stream, const es_format_t *p_fmt,
      * all the characteristics of the decoded stream yet */
     id->b_transcode = true;
 
-    if( p_sys->fps_num )
+    if( p_sys->fps.num )
     {
-        id->p_encoder->fmt_in.video.i_frame_rate = id->p_encoder->fmt_out.video.i_frame_rate = (p_sys->fps_num );
-        id->p_encoder->fmt_in.video.i_frame_rate_base = id->p_encoder->fmt_out.video.i_frame_rate_base = (p_sys->fps_den ? p_sys->fps_den : 1);
+        id->p_encoder->fmt_in.video.i_frame_rate = id->p_encoder->fmt_out.video.i_frame_rate = p_sys->fps.num;
+        id->p_encoder->fmt_in.video.i_frame_rate_base = id->p_encoder->fmt_out.video.i_frame_rate_base = (p_sys->fps.den ? p_sys->fps.den : 1);
     }
 
     return true;
diff --git a/modules/video_filter/fps.c b/modules/video_filter/fps.c
index c4bc35e1e6..5222b17233 100644
--- a/modules/video_filter/fps.c
+++ b/modules/video_filter/fps.c
@@ -137,6 +137,7 @@ static int Open( vlc_object_t *p_this)
 {
     filter_t *p_filter = (filter_t*)p_this;
     filter_sys_t *p_sys;
+    vlc_rational_t fps;
 
     p_sys = p_filter->p_sys = malloc( sizeof( *p_sys ) );
 
@@ -150,12 +151,13 @@ 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, &p_filter->fmt_out.video.i_frame_rate,
-                                        &p_filter->fmt_out.video.i_frame_rate_base, CFG_PREFIX "fps" ) )
+    if( var_InheritURational( p_filter, &fps.num, &fps.den, CFG_PREFIX "fps" ) )
     {
-        p_filter->fmt_out.video.i_frame_rate = p_filter->fmt_in.video.i_frame_rate;
-        p_filter->fmt_out.video.i_frame_rate_base = p_filter->fmt_in.video.i_frame_rate_base;
+        fps.num = p_filter->fmt_in.video.i_frame_rate;
+        fps.den = p_filter->fmt_in.video.i_frame_rate_base;
     }
+    p_filter->fmt_out.video.i_frame_rate      = fps.num;
+    p_filter->fmt_out.video.i_frame_rate_base = fps.den;
 
     msg_Dbg( p_filter, "Converting fps from %d/%d -> %d/%d",
             p_filter->fmt_in.video.i_frame_rate, p_filter->fmt_in.video.i_frame_rate_base,
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 155d6a9e30..a9abda4342 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -576,14 +576,12 @@ 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");
-    unsigned msar_num, msar_den;
-    if (var_InheritURational(vout, &msar_num, &msar_den, "monitor-par") ||
-        msar_num <= 0 || msar_den <= 0) {
-        msar_num = 1;
-        msar_den = 1;
+    if (var_InheritURational(vout, &cfg->display.sar.num, &cfg->display.sar.den,
+                             "monitor-par") |
+            !cfg->display.sar.num  || !cfg->display.sar.den) {
+        cfg->display.sar.num = 1;
+        cfg->display.sar.den = 1;
     }
-    cfg->display.sar.num = msar_num;
-    cfg->display.sar.den = msar_den;
     unsigned zoom_den = 1000;
     unsigned zoom_num = zoom_den * var_GetFloat(vout, "zoom");
     vlc_ureduce(&zoom_num, &zoom_den, zoom_num, zoom_den, 0);
diff --git a/test/src/misc/variables.c b/test/src/misc/variables.c
index 7469a0c441..3d95c9f465 100644
--- a/test/src/misc/variables.c
+++ b/test/src/misc/variables.c
@@ -101,67 +101,67 @@ static void test_floats( libvlc_int_t *p_libvlc )
 static void test_fracts( libvlc_int_t *p_libvlc )
 {
     const char *name = psz_var_name[0];
-    unsigned num, den;
+    vlc_rational_t frac;
 
     var_Create( p_libvlc, name, VLC_VAR_STRING );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) != 0 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) != 0 );
 
     var_SetString( p_libvlc, name, "123garbage" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) != 0 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) != 0 );
 
     var_SetString( p_libvlc, name, "4/5garbage" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) != 0 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) != 0 );
 
     var_SetString( p_libvlc, name, "6.7garbage" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) != 0 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) != 0 );
 
     var_SetString( p_libvlc, name, "." );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 0 && den == 1 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 0 && frac.den == 1 );
 
     var_SetString( p_libvlc, name, "010" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 10 && den == 1 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 10 && frac.den == 1 );
 
     var_SetString( p_libvlc, name, "30" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 30 && den == 1 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 30 && frac.den == 1 );
 
     var_SetString( p_libvlc, name, "30.0" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 30 && den == 1 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 30 && frac.den == 1 );
 
     var_SetString( p_libvlc, name, "030.030" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 3003 && den == 100 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 3003 && frac.den == 100 );
 
     var_SetString( p_libvlc, name, "60/2" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 30 && den == 1 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 30 && frac.den == 1 );
 
     var_SetString( p_libvlc, name, "29.97" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 2997 && den == 100 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 2997 && frac.den == 100 );
 
     var_SetString( p_libvlc, name, "30000/1001" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 30000 && den == 1001 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 30000 && frac.den == 1001 );
 
     var_SetString( p_libvlc, name, ".125" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 1 && den == 8 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 1 && frac.den == 8 );
 
     var_SetString( p_libvlc, name, "12:9" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 4 && den == 3 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 4 && frac.den == 3 );
 
     var_SetString( p_libvlc, name, "000000/00000000" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 0 && den == 0 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 0 && frac.den == 0 );
 
     var_SetString( p_libvlc, name, "12345/0" );
-    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
-    assert( num == 1 && den == 0 );
+    assert( var_InheritURational( p_libvlc, &frac.num, &frac.den, name ) == 0 );
+    assert( frac.num == 1 && frac.den == 0 );
 
     var_Destroy( p_libvlc, name );
 }
-- 
2.11.1



More information about the vlc-devel mailing list