[vlc-devel] [PATCH 16/28] simplify some frame rate checks

Steve Lhomme robux4 at videolabs.io
Mon Apr 3 10:22:04 CEST 2017


The frame rate values cannot be negative so we only need to check for 0 values.
---
 modules/codec/avcodec/dxva2.c | 2 +-
 modules/codec/avcodec/video.c | 6 ++----
 modules/codec/omxil/omxil.c   | 6 ++----
 modules/codec/x264.c          | 2 +-
 modules/demux/vc1.c           | 4 ++--
 src/input/es_out.c            | 3 +--
 6 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 2399677b5e..1bed5b858d 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -759,7 +759,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id, const video_format_t
     dsc.SampleWidth     = fmt->i_width;
     dsc.SampleHeight    = fmt->i_height;
     dsc.Format          = p_sys->render;
-    if (fmt->frame_rate.num > 0 && fmt->frame_rate.den > 0) {
+    if (fmt->frame_rate.num && fmt->frame_rate.den) {
         dsc.InputSampleFreq.Numerator   = fmt->frame_rate.num;
         dsc.InputSampleFreq.Denominator = fmt->frame_rate.den;
     } else {
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 5afab55875..ed3f2ae4d5 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -173,8 +173,7 @@ static int lavc_GetVideoFormat(decoder_t *dec, video_format_t *restrict fmt,
             fmt->i_sar_num = fmt->i_sar_den = 1;
     }
 
-    if (dec->fmt_in.video.frame_rate.num > 0
-     && dec->fmt_in.video.frame_rate.den > 0)
+    if (dec->fmt_in.video.frame_rate.num && dec->fmt_in.video.frame_rate.den)
     {
         fmt->frame_rate = dec->fmt_in.video.frame_rate;
     }
@@ -679,8 +678,7 @@ static void interpolate_next_pts( decoder_t *p_dec, AVFrame *frame )
         return;
 
     /* interpolate the next PTS */
-    if( p_dec->fmt_in.video.frame_rate.num > 0 &&
-        p_dec->fmt_in.video.frame_rate.den > 0 )
+    if( p_dec->fmt_in.video.frame_rate.num && p_dec->fmt_in.video.frame_rate.den )
     {
         p_sys->i_pts += CLOCK_FREQ * (2 + frame->repeat_pict) *
             p_dec->fmt_in.video.frame_rate.den /
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index ba52fdca53..105bbb597c 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -262,8 +262,7 @@ static OMX_ERRORTYPE SetPortDefinition(decoder_t *p_dec, OmxPort *p_port,
         def->format.video.nFrameHeight = p_fmt->video.i_height;
         if(def->format.video.eCompressionFormat == OMX_VIDEO_CodingUnused)
             def->format.video.nStride = def->format.video.nFrameWidth;
-        if( p_fmt->video.frame_rate.num > 0 &&
-            p_fmt->video.frame_rate.den > 0 )
+        if( p_fmt->video.frame_rate.num && p_fmt->video.frame_rate.den )
             def->format.video.xFramerate = (p_fmt->video.frame_rate.num << 16) /
                 p_fmt->video.frame_rate.den;
 
@@ -595,8 +594,7 @@ static OMX_ERRORTYPE GetPortDefinition(decoder_t *p_dec, OmxPort *p_port,
         p_fmt->video.i_visible_width = def->format.video.nFrameWidth;
         p_fmt->video.i_height = def->format.video.nFrameHeight;
         p_fmt->video.i_visible_height = def->format.video.nFrameHeight;
-        p_fmt->video.frame_rate.num = p_dec->fmt_in.video.frame_rate.num;
-        p_fmt->video.frame_rate.den = p_dec->fmt_in.video.frame_rate.den;
+        p_fmt->video.frame_rate = p_dec->fmt_in.video.frame_rate;
 
         OMX_INIT_STRUCTURE(crop_rect);
         crop_rect.nPortIndex = def->nPortIndex;
diff --git a/modules/codec/x264.c b/modules/codec/x264.c
index 65b973a2a8..57654f134c 100644
--- a/modules/codec/x264.c
+++ b/modules/codec/x264.c
@@ -1334,7 +1334,7 @@ static int  Open ( vlc_object_t *p_this )
     p_sys->param.i_timebase_num = 1;
     p_sys->param.i_timebase_den = CLOCK_FREQ;
 
-    if( p_enc->fmt_in.video.frame_rate.den > 0 )
+    if( p_enc->fmt_in.video.frame_rate.den )
     {
         p_sys->param.i_fps_num = p_enc->fmt_in.video.frame_rate.num;
         p_sys->param.i_fps_den = p_enc->fmt_in.video.frame_rate.den;
diff --git a/modules/demux/vc1.c b/modules/demux/vc1.c
index b1967bcbec..9d3c390975 100644
--- a/modules/demux/vc1.c
+++ b/modules/demux/vc1.c
@@ -178,8 +178,8 @@ static int Demux( demux_t *p_demux)
 
             p_block_out = p_next;
 
-            if( p_sys->p_packetizer->fmt_out.video.frame_rate.num > 0 &&
-                p_sys->p_packetizer->fmt_out.video.frame_rate.den > 0 )
+            if( p_sys->p_packetizer->fmt_out.video.frame_rate.num &&
+                p_sys->p_packetizer->fmt_out.video.frame_rate.den )
                 p_sys->i_dts += CLOCK_FREQ *
                     p_sys->p_packetizer->fmt_out.video.frame_rate.den /
                     p_sys->p_packetizer->fmt_out.video.frame_rate.num;
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 6a95939dae..3418678f01 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -3069,8 +3069,7 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
             info_category_AddInfo( p_cat, _("Buffer dimensions"), "%ux%u",
                                    fmt->video.i_width, fmt->video.i_height );
 
-       if( fmt->video.frame_rate.num > 0 &&
-           fmt->video.frame_rate.den > 0 )
+       if( fmt->video.frame_rate.num && fmt->video.frame_rate.den )
        {
            div = lldiv( (float)fmt->video.frame_rate.num /
                                fmt->video.frame_rate.den * 1000000,
-- 
2.11.1



More information about the vlc-devel mailing list