[vlc-devel] [PATCH 27/28] simplifying copying data between vlc_rational_t

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


---
 modules/access/dvdnav.c                |  3 +--
 modules/access/dvdread.c               |  3 +--
 modules/codec/avcodec/video.c          |  6 ++----
 modules/codec/dmo/dmo.c                |  3 +--
 modules/codec/libmpeg2.c               |  6 ++----
 modules/codec/omxil/omxil.c            |  3 +--
 modules/codec/vpx.c                    |  3 +--
 modules/demux/avformat/demux.c         |  6 ++----
 modules/demux/ogg.c                    |  3 +--
 modules/hw/mmal/vout.c                 |  3 +--
 modules/packetizer/h264.c              |  3 +--
 modules/stream_out/transcode/video.c   | 12 ++++--------
 modules/video_filter/transform.c       |  3 +--
 modules/video_output/android/display.c |  3 +--
 modules/video_output/yuv.c             |  3 +--
 src/video_output/display.c             | 18 ++++++------------
 src/video_output/video_output.c        |  6 ++----
 17 files changed, 29 insertions(+), 58 deletions(-)

diff --git a/modules/access/dvdnav.c b/modules/access/dvdnav.c
index e1e1051e8f..3766ea4a0d 100644
--- a/modules/access/dvdnav.c
+++ b/modules/access/dvdnav.c
@@ -1447,8 +1447,7 @@ static void ESNew( demux_t *p_demux, int i_id )
     /* Add a new ES */
     if( tk->fmt.i_cat == VIDEO_ES )
     {
-        tk->fmt.video.sar.num = p_sys->sar.num;
-        tk->fmt.video.sar.den = p_sys->sar.den;
+        tk->fmt.video.sar = p_sys->sar;
         b_select = true;
     }
     else if( tk->fmt.i_cat == AUDIO_ES )
diff --git a/modules/access/dvdread.c b/modules/access/dvdread.c
index c075ec8613..6e7a4f8a10 100644
--- a/modules/access/dvdread.c
+++ b/modules/access/dvdread.c
@@ -664,8 +664,7 @@ static void ESNew( demux_t *p_demux, int i_id, int i_lang )
     /* Add a new ES */
     if( tk->fmt.i_cat == VIDEO_ES )
     {
-        tk->fmt.video.sar.num = p_sys->sar.num;
-        tk->fmt.video.sar.den = p_sys->sar.den;
+        tk->fmt.video.sar = p_sys->sar;
     }
     else if( tk->fmt.i_cat == AUDIO_ES )
     {
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 5c3fa5969b..d0f923e5ae 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -161,13 +161,11 @@ static int lavc_GetVideoFormat(decoder_t *dec, video_format_t *restrict fmt,
     /* If an aspect-ratio was specified in the input format then force it */
     if (dec->fmt_in.video.sar.num > 0 && dec->fmt_in.video.sar.den > 0)
     {
-        fmt->sar.num = dec->fmt_in.video.sar.num;
-        fmt->sar.den = dec->fmt_in.video.sar.den;
+        fmt->sar= dec->fmt_in.video.sar;
     }
     else
     {
-        fmt->sar.num = ctx->sample_aspect_ratio.num;
-        fmt->sar.den = ctx->sample_aspect_ratio.den;
+        fmt->sar = FromAVRational(ctx->sample_aspect_ratio);
 
         if (fmt->sar.num == 0 || fmt->sar.den == 0)
             fmt->sar.num = fmt->sar.den = 1;
diff --git a/modules/codec/dmo/dmo.c b/modules/codec/dmo/dmo.c
index 6550cfa54e..e90dbbc8a8 100644
--- a/modules/codec/dmo/dmo.c
+++ b/modules/codec/dmo/dmo.c
@@ -513,8 +513,7 @@ static int DecOpen( decoder_t *p_dec )
         if( p_dec->fmt_in.video.sar.num > 0 &&
             p_dec->fmt_in.video.sar.den > 0 )
         {
-            p_dec->fmt_out.video.sar.num = p_dec->fmt_in.video.sar.num;
-            p_dec->fmt_out.video.sar.den = p_dec->fmt_in.video.sar.den;
+            p_dec->fmt_out.video.sar= p_dec->fmt_in.video.sar;
         }
         else
         {
diff --git a/modules/codec/libmpeg2.c b/modules/codec/libmpeg2.c
index 6d9352948f..8f4eef8543 100644
--- a/modules/codec/libmpeg2.c
+++ b/modules/codec/libmpeg2.c
@@ -671,8 +671,7 @@ static picture_t *GetNewPicture( decoder_t *p_dec )
     p_dec->fmt_out.video.i_height = p_sys->p_info->sequence->height;
     p_dec->fmt_out.video.i_visible_height =
         p_sys->p_info->sequence->picture_height;
-    p_dec->fmt_out.video.sar.num = p_sys->sar.num;
-    p_dec->fmt_out.video.sar.den = p_sys->sar.den;
+    p_dec->fmt_out.video.sar = p_sys->sar;
 
     if( p_sys->p_info->sequence->frame_period > 0 )
     {
@@ -717,8 +716,7 @@ static void GetAR( decoder_t *p_dec )
     if( p_dec->fmt_in.video.sar.num > 0 &&
         p_dec->fmt_in.video.sar.den > 0 )
     {
-        p_sys->sar.num = p_dec->fmt_in.video.sar.num;
-        p_sys->sar.den = p_dec->fmt_in.video.sar.den;
+        p_sys->sar = p_dec->fmt_in.video.sar;
     }
     else
     {
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index bda25dec92..723ba7d10e 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -1573,8 +1573,7 @@ static int DecodeVideo( decoder_t *p_dec, block_t *p_block )
        (p_dec->fmt_out.video.sar.num == 0 || p_dec->fmt_out.video.sar.den == 0 ||
              !p_sys->b_aspect_ratio_handled))
     {
-        p_dec->fmt_out.video.sar.num = p_dec->fmt_in.video.sar.num;
-        p_dec->fmt_out.video.sar.den = p_dec->fmt_in.video.sar.den;
+        p_dec->fmt_out.video.sar = p_dec->fmt_in.video.sar;
     }
 
     /* Loop as long as we haven't either got an input buffer (and cleared
diff --git a/modules/codec/vpx.c b/modules/codec/vpx.c
index d7438e1d74..9180b4889d 100644
--- a/modules/codec/vpx.c
+++ b/modules/codec/vpx.c
@@ -328,8 +328,7 @@ static int OpenDecoder(vlc_object_t *p_this)
     dec->fmt_out.video.i_height = dec->fmt_in.video.i_height;
 
     if (dec->fmt_in.video.sar.num > 0 && dec->fmt_in.video.sar.den > 0) {
-        dec->fmt_out.video.sar.num = dec->fmt_in.video.sar.num;
-        dec->fmt_out.video.sar.den = dec->fmt_in.video.sar.den;
+        dec->fmt_out.video.sar = dec->fmt_in.video.sar;
     }
 
     return VLC_SUCCESS;
diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index 6fb7be51e7..b7c92fa674 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -447,10 +447,8 @@ int OpenDemux( vlc_object_t *p_this )
             psz_type = "video";
             fmt.video.frame_rate.num = s->codec->time_base.num;
             fmt.video.frame_rate.den = s->codec->time_base.den * __MAX( s->codec->ticks_per_frame, 1 );
-            fmt.video.sar.num = s->sample_aspect_ratio.num;
-            if (s->sample_aspect_ratio.num > 0)
-                fmt.video.sar.den = s->sample_aspect_ratio.den;
-            else
+            fmt.video.sar = FromAVRational(s->sample_aspect_ratio);
+            if (s->sample_aspect_ratio.num < 0)
                 fmt.video.sar.den = 0;
             break;
 
diff --git a/modules/demux/ogg.c b/modules/demux/ogg.c
index e6de8971d1..b4e23a54c2 100644
--- a/modules/demux/ogg.c
+++ b/modules/demux/ogg.c
@@ -2576,8 +2576,7 @@ static bool Ogg_ReadTheoraHeader( logical_stream_t *p_stream,
     bs_read( &bitstream, 24 ); /* aspect_numerator */
     bs_read( &bitstream, 24 ); /* aspect_denominator */
 
-    p_stream->fmt.video.frame_rate.num = fps.num;
-    p_stream->fmt.video.frame_rate.den = fps.den;
+    p_stream->fmt.video.frame_rate = fps;
 
     bs_read( &bitstream, 8 ); /* colorspace */
     p_stream->fmt.i_bitrate = bs_read( &bitstream, 24 );
diff --git a/modules/hw/mmal/vout.c b/modules/hw/mmal/vout.c
index a300920b42..3ba38ed87a 100644
--- a/modules/hw/mmal/vout.c
+++ b/modules/hw/mmal/vout.c
@@ -563,8 +563,7 @@ static void vd_display(vout_display_t *vd, picture_t *picture,
         picture->b_top_field_first != sys->b_top_field_first) {
         sys->b_top_field_first = picture->b_top_field_first;
         sys->b_progressive = picture->b_progressive;
-        sys->frame_rate.num = picture->format.frame_rate.num;
-        sys->frame_rate.den = picture->format.frame_rate.den;
+        sys->frame_rate = picture->format.frame_rate;
         configure_display(vd, NULL, &picture->format);
     }
 
diff --git a/modules/packetizer/h264.c b/modules/packetizer/h264.c
index 542663d1b3..ed28bbbfc3 100644
--- a/modules/packetizer/h264.c
+++ b/modules/packetizer/h264.c
@@ -201,8 +201,7 @@ static void ActivateSets( decoder_t *p_dec, const h264_sequence_parameter_set_t
 
         if( p_sps->vui.sar.num != 0 && p_sps->vui.sar.den != 0 )
         {
-            p_dec->fmt_out.video.sar.num = p_sps->vui.sar.num;
-            p_dec->fmt_out.video.sar.den = p_sps->vui.sar.den;
+            p_dec->fmt_out.video.sar = p_sps->vui.sar;
         }
 
         if( p_sps->vui.b_valid )
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index a5c882b353..9e2f55677d 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -367,10 +367,8 @@ static void transcode_video_filter_init( sout_stream_t *p_stream,
             id->p_encoder->fmt_in.video.i_width;
         id->p_encoder->fmt_out.video.i_height =
             id->p_encoder->fmt_in.video.i_height;
-        id->p_encoder->fmt_out.video.sar.num =
-            id->p_encoder->fmt_in.video.sar.num;
-        id->p_encoder->fmt_out.video.sar.den =
-            id->p_encoder->fmt_in.video.sar.den;
+        id->p_encoder->fmt_out.video.sar =
+            id->p_encoder->fmt_in.video.sar;
     }
 
     /* Keep colorspace etc info along */
@@ -592,10 +590,8 @@ static void transcode_video_sar_init( sout_stream_t *p_stream,
                      0 );
     }
 
-    id->p_encoder->fmt_in.video.sar.num =
-        id->p_encoder->fmt_out.video.sar.num;
-    id->p_encoder->fmt_in.video.sar.den =
-        id->p_encoder->fmt_out.video.sar.den;
+    id->p_encoder->fmt_in.video.sar =
+        id->p_encoder->fmt_out.video.sar;
 
     msg_Dbg( p_stream, "encoder aspect is %i:%i",
              id->p_encoder->fmt_out.video.sar.num * id->p_encoder->fmt_out.video.i_width,
diff --git a/modules/video_filter/transform.c b/modules/video_filter/transform.c
index 11c280c542..61a586d55f 100644
--- a/modules/video_filter/transform.c
+++ b/modules/video_filter/transform.c
@@ -406,8 +406,7 @@ static int Open(vlc_object_t *object)
         dst->i_visible_width  = src_trans.i_visible_width;
         dst->i_height         = src_trans.i_height;
         dst->i_visible_height = src_trans.i_visible_height;
-        dst->sar.num        = src_trans.sar.num;
-        dst->sar.den        = src_trans.sar.den;
+        dst->sar              = src_trans.sar;
         dst->i_x_offset       = src_trans.i_x_offset;
         dst->i_y_offset       = src_trans.i_y_offset;
     }
diff --git a/modules/video_output/android/display.c b/modules/video_output/android/display.c
index 14b2518284..625a8b7c84 100644
--- a/modules/video_output/android/display.c
+++ b/modules/video_output/android/display.c
@@ -1164,8 +1164,7 @@ static void Display(vout_display_t *vd, picture_t *picture,
 static void CopySourceAspect(video_format_t *p_dest,
                              const video_format_t *p_src)
 {
-    p_dest->sar.num = p_src->sar.num;
-    p_dest->sar.den = p_src->sar.den;
+    p_dest->sar = p_src->sar;
 }
 
 static int Control(vout_display_t *vd, int query, va_list args)
diff --git a/modules/video_output/yuv.c b/modules/video_output/yuv.c
index ef02af91c4..e833707e1e 100644
--- a/modules/video_output/yuv.c
+++ b/modules/video_output/yuv.c
@@ -207,8 +207,7 @@ static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
     }
     else
     {
-        fmt.sar.num = vd->source.sar.num;
-        fmt.sar.den = vd->source.sar.den;
+        fmt.sar = vd->source.sar;
     }
 
     /* */
diff --git a/src/video_output/display.c b/src/video_output/display.c
index 8af0cca708..b8c8a13ae9 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -945,11 +945,9 @@ bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
             video_format_t source = vd->source;
 
             if (osys->sar.num > 0 && osys->sar.den > 0) {
-                source.sar.num = osys->sar.num;
-                source.sar.den = osys->sar.den;
+                source.sar = osys->sar;
             } else {
-                source.sar.num = osys->source.sar.num;
-                source.sar.den = osys->source.sar.den;
+                source.sar = osys->source.sar;
             }
 
             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, &source)) {
@@ -964,8 +962,7 @@ bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
                 osys->fit_window = 1;
             }
             vd->source = source;
-            osys->sar.num = source.sar.num;
-            osys->sar.den = source.sar.den;
+            osys->sar = source.sar;
             osys->ch_sar  = false;
 
             /* If a crop ratio is requested, recompute the parameters */
@@ -980,8 +977,7 @@ bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
             unsigned crop_den = osys->crop.den;
             if (crop_num > 0 && crop_den > 0) {
                 video_format_t fmt = osys->source;
-                fmt.sar.num = source.sar.num;
-                fmt.sar.den = source.sar.den;
+                fmt.sar = source.sar;
                 VoutDisplayCropRatio(&osys->crop.left,  &osys->crop.top,
                                      &osys->crop.right, &osys->crop.bottom,
                                      &fmt, crop_num, crop_den);
@@ -1099,15 +1095,13 @@ void vout_UpdateDisplaySourceProperties(vout_display_t *vd, const video_format_t
     if (source->sar.num * osys->source.sar.den !=
         source->sar.den * osys->source.sar.num) {
 
-        osys->source.sar.num = source->sar.num;
-        osys->source.sar.den = source->sar.den;
+        osys->source.sar = source->sar;
         vlc_ureduce(&osys->source.sar.num, &osys->source.sar.den,
                     osys->source.sar.num, osys->source.sar.den, 0);
 
         /* FIXME it will override any AR that the user would have forced */
         osys->ch_sar = true;
-        osys->sar.num = osys->source.sar.num;
-        osys->sar.den = osys->source.sar.den;
+        osys->sar = osys->source.sar;
     }
     if (source->i_x_offset       != osys->source.i_x_offset ||
         source->i_y_offset       != osys->source.i_y_offset ||
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 6150a7061e..a30da09933 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -98,8 +98,7 @@ static void VideoFormatCopyCropAr(video_format_t *dst,
                                   const video_format_t *src)
 {
     video_format_CopyCrop(dst, src);
-    dst->sar.num = src->sar.num;
-    dst->sar.den = src->sar.den;
+    dst->sar = src->sar;
 }
 static bool VideoFormatIsCropArEqual(video_format_t *dst,
                                      const video_format_t *src)
@@ -915,8 +914,7 @@ static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
             fmt_spu = vd->source;
         } else {
             fmt_spu = vd->fmt;
-            fmt_spu.sar.num = vd->cfg->display.sar.num;
-            fmt_spu.sar.den = vd->cfg->display.sar.den;
+            fmt_spu.sar = vd->cfg->display.sar;
         }
         subpicture_chromas = NULL;
 
-- 
2.11.1



More information about the vlc-devel mailing list