[vlc-devel] [PATCH 2/3] make use of VLC_UPPER_DIV and VLC_UPPER_MODULO where possible

Steve Lhomme robux4 at videolabs.io
Fri Mar 17 09:36:09 CET 2017


---
 modules/access/linsys/linsys_hdsdi.c |  6 ++----
 modules/access/linsys/linsys_sdi.c   |  3 +--
 modules/codec/wmafixed/wmadeci.c     |  6 +++---
 modules/demux/avi/avi.c              |  6 +++---
 modules/mux/mpeg/ps.c                |  2 +-
 modules/stream_out/rtp.c             |  2 +-
 modules/stream_out/rtpfmt.c          | 22 +++++++++++-----------
 modules/video_chroma/copy.c          |  2 +-
 modules/video_filter/puzzle_mgt.c    | 16 ++++++++--------
 src/misc/picture.c                   |  4 ++--
 10 files changed, 33 insertions(+), 36 deletions(-)

diff --git a/modules/access/linsys/linsys_hdsdi.c b/modules/access/linsys/linsys_hdsdi.c
index f97fa89b4d..d38423d311 100644
--- a/modules/access/linsys/linsys_hdsdi.c
+++ b/modules/access/linsys/linsys_hdsdi.c
@@ -839,8 +839,7 @@ static int InitCapture( demux_t *p_demux )
         }
 
 #ifdef HAVE_MMAP_SDIAUDIO
-        i_bufmemsize = ((p_sys->i_abuffer_size + i_page_size - 1) / i_page_size)
-                         * i_page_size;
+        i_bufmemsize = VLC_UPPER_MODULO( p_sys->i_abuffer_size, i_page_size );
         p_sys->pp_abuffers = malloc( p_sys->i_abuffers * sizeof(uint8_t *) );
         if( unlikely( !p_sys->pp_abuffers ) )
             return VLC_ENOMEM;
@@ -894,8 +893,7 @@ static int InitCapture( demux_t *p_demux )
 
 #ifdef HAVE_MMAP_SDIVIDEO
     p_sys->i_current_vbuffer = 0;
-    i_bufmemsize = ((p_sys->i_vbuffer_size + i_page_size - 1) / i_page_size)
-                     * i_page_size;
+    i_bufmemsize = VLC_UPPER_MODULO( p_sys->i_vbuffer_size, i_page_size );
     p_sys->pp_vbuffers = malloc( p_sys->i_vbuffers * sizeof(uint8_t *) );
     if( unlikely( !p_sys->pp_vbuffers ) )
         return VLC_ENOMEM;
diff --git a/modules/access/linsys/linsys_sdi.c b/modules/access/linsys/linsys_sdi.c
index 18bd07baf5..305d035a58 100644
--- a/modules/access/linsys/linsys_sdi.c
+++ b/modules/access/linsys/linsys_sdi.c
@@ -1736,8 +1736,7 @@ static int InitCapture( demux_t *p_demux )
         return VLC_EGENERIC;
     }
 
-    i_bufmemsize = ((p_sys->i_buffer_size + i_page_size - 1) / i_page_size)
-                     * i_page_size;
+    i_bufmemsize = VLC_UPPER_MODULO( p_sys->i_buffer_size, i_page_size );
     p_sys->pp_buffers = malloc( p_sys->i_buffers * sizeof(uint8_t *) );
     if( !p_sys->pp_buffers )
         return VLC_ENOMEM;
diff --git a/modules/codec/wmafixed/wmadeci.c b/modules/codec/wmafixed/wmadeci.c
index b0997cc651..77fe9fc15a 100644
--- a/modules/codec/wmafixed/wmadeci.c
+++ b/modules/codec/wmafixed/wmadeci.c
@@ -38,13 +38,13 @@
 #include <string.h> /* memcpy() */
 
 #define VLCBITS 7       /*7 is the lowest without glitching*/
-#define VLCMAX ((22+VLCBITS-1)/VLCBITS)
+#define VLCMAX VLC_UPPER_DIV(22,VLCBITS)
 
 #define EXPVLCBITS 7
-#define EXPMAX ((19+EXPVLCBITS-1)/EXPVLCBITS)
+#define EXPMAX VLC_UPPER_DIV(19,EXPVLCBITS)
 
 #define HGAINVLCBITS 9
-#define HGAINMAX ((13+HGAINVLCBITS-1)/HGAINVLCBITS)
+#define HGAINMAX VLC_UPPER_DIV(13,HGAINVLCBITS)
 
 
 typedef struct CoefVLCTable
diff --git a/modules/demux/avi/avi.c b/modules/demux/avi/avi.c
index ddde3b1576..8cfa38971b 100644
--- a/modules/demux/avi/avi.c
+++ b/modules/demux/avi/avi.c
@@ -1303,7 +1303,7 @@ static int Demux_Seekable( demux_t *p_demux )
             tk->i_idxposc++;
             if( tk->i_cat == AUDIO_ES )
             {
-                tk->i_blockno += tk->i_blocksize > 0 ? ( i_length + tk->i_blocksize - 1 ) / tk->i_blocksize : 1;
+                tk->i_blockno += tk->i_blocksize > 0 ? VLC_UPPER_DIV( i_length, tk->i_blocksize ) : 1;
             }
             toread[i_track].i_toread--;
         }
@@ -1481,7 +1481,7 @@ static int Demux_UnSeekable( demux_t *p_demux )
             {
                 if( p_stream->i_cat == AUDIO_ES )
                 {
-                    p_stream->i_blockno += p_stream->i_blocksize > 0 ? ( avi_pk.i_size + p_stream->i_blocksize - 1 ) / p_stream->i_blocksize : 1;
+                    p_stream->i_blockno += p_stream->i_blocksize > 0 ? VLC_UPPER_DIV( avi_pk.i_size, p_stream->i_blocksize ) : 1;
                 }
                 p_stream->i_idxposc++;
             }
@@ -2019,7 +2019,7 @@ static int AVI_TrackSeek( demux_t *p_demux,
             {
                 if( tk->i_blocksize > 0 )
                 {
-                    tk->i_blockno += ( tk->idx.p_entry[i].i_length + tk->i_blocksize - 1 ) / tk->i_blocksize;
+                    tk->i_blockno += VLC_UPPER_DIV( tk->idx.p_entry[i].i_length, tk->i_blocksize );
                 }
                 else
                 {
diff --git a/modules/mux/mpeg/ps.c b/modules/mux/mpeg/ps.c
index 41d040078f..ef8af2d217 100644
--- a/modules/mux/mpeg/ps.c
+++ b/modules/mux/mpeg/ps.c
@@ -581,7 +581,7 @@ static void MuxWritePackHeader( sout_mux_t *p_mux, block_t **p_buf,
     bits_write( &bits, 32, 0x01ba );
 
     /* The spec specifies that the mux rate must be rounded upwards */
-    i_mux_rate = (p_sys->i_instant_bitrate + 8 * 50 - 1 ) / (8 * 50);
+    i_mux_rate = VLC_UPPER_DIV(p_sys->i_instant_bitrate, 8 * 50);
 
     if( p_sys->b_mpeg2 )
     {
diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c
index 671ba73965..5b4a10f35a 100644
--- a/modules/stream_out/rtp.c
+++ b/modules/stream_out/rtp.c
@@ -1726,7 +1726,7 @@ static ssize_t AccessOutGrabberWriteBuffer( sout_stream_t *p_stream,
     size_t          i_data  = p_buffer->i_buffer;
     size_t          i_max   = id->i_mtu - 12;
 
-    size_t i_packet = ( p_buffer->i_buffer + i_max - 1 ) / i_max;
+    size_t i_packet = VLC_UPPER_DIV( p_buffer->i_buffer, i_max );
 
     while( i_data > 0 )
     {
diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c
index 6b67fee587..5e799d55fb 100644
--- a/modules/stream_out/rtpfmt.c
+++ b/modules/stream_out/rtpfmt.c
@@ -612,7 +612,7 @@ int rtp_packetize_xiph_config( sout_stream_id_sys_t *id, const char *fmtp,
     p_data = p_orig + 9;
     i_data -= 9;
 
-    int i_count = ( i_data + i_max - 1 ) / i_max;
+    int i_count = VLC_UPPER_DIV( i_data, i_max );
 
     for( int i = 0; i < i_count; i++ )
     {
@@ -663,7 +663,7 @@ int rtp_packetize_xiph_config( sout_stream_id_sys_t *id, const char *fmtp,
 static int rtp_packetize_xiph( sout_stream_id_sys_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 6; /* payload max in one packet */
-    int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
+    int     i_count = VLC_UPPER_DIV( in->i_buffer, i_max );
 
     uint8_t *p_data = in->p_buffer;
     int     i_data  = in->i_buffer;
@@ -718,7 +718,7 @@ static int rtp_packetize_xiph( sout_stream_id_sys_t *id, block_t *in )
 static int rtp_packetize_mpa( sout_stream_id_sys_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 4; /* payload max in one packet */
-    int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
+    int     i_count = VLC_UPPER_DIV( in->i_buffer, i_max );
 
     uint8_t *p_data = in->p_buffer;
     int     i_data  = in->i_buffer;
@@ -754,7 +754,7 @@ static int rtp_packetize_mpa( sout_stream_id_sys_t *id, block_t *in )
 static int rtp_packetize_mpv( sout_stream_id_sys_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 4; /* payload max in one packet */
-    int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
+    int     i_count = VLC_UPPER_DIV( in->i_buffer, i_max );
 
     uint8_t *p_data = in->p_buffer;
     int     i_data  = in->i_buffer;
@@ -852,7 +852,7 @@ static int rtp_packetize_mpv( sout_stream_id_sys_t *id, block_t *in )
 static int rtp_packetize_ac3( sout_stream_id_sys_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 2; /* payload max in one packet */
-    int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
+    int     i_count = VLC_UPPER_DIV( in->i_buffer, i_max );
 
     uint8_t *p_data = in->p_buffer;
     int     i_data  = in->i_buffer;
@@ -901,7 +901,7 @@ static int rtp_packetize_simple(sout_stream_id_sys_t *id, block_t *block)
 static int rtp_packetize_split( sout_stream_id_sys_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id); /* payload max in one packet */
-    int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
+    int     i_count = VLC_UPPER_DIV( in->i_buffer, i_max );
 
     uint8_t *p_data = in->p_buffer;
     int     i_data  = in->i_buffer;
@@ -998,7 +998,7 @@ static int rtp_packetize_mp4a_latm( sout_stream_id_sys_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 2;              /* payload max in one packet */
     int     latmhdrsize = in->i_buffer / 0xff + 1;
-    int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
+    int     i_count = VLC_UPPER_DIV( in->i_buffer, i_max );
 
     uint8_t *p_data = in->p_buffer, *p_header = NULL;
     int     i_data  = in->i_buffer;
@@ -1049,7 +1049,7 @@ static int rtp_packetize_mp4a_latm( sout_stream_id_sys_t *id, block_t *in )
 static int rtp_packetize_mp4a( sout_stream_id_sys_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 4; /* payload max in one packet */
-    int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
+    int     i_count = VLC_UPPER_DIV( in->i_buffer, i_max );
 
     uint8_t *p_data = in->p_buffer;
     int     i_data  = in->i_buffer;
@@ -1263,7 +1263,7 @@ static int rtp_packetize_h264( sout_stream_id_sys_t *id, block_t *in )
 static int rtp_packetize_amr( sout_stream_id_sys_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 2; /* payload max in one packet */
-    int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
+    int     i_count = VLC_UPPER_DIV( in->i_buffer, i_max );
 
     uint8_t *p_data = in->p_buffer;
     int     i_data  = in->i_buffer;
@@ -1430,7 +1430,7 @@ static int rtp_packetize_spx( sout_stream_id_sys_t *id, block_t *in )
 static int rtp_packetize_g726( sout_stream_id_sys_t *id, block_t *in, int i_pad )
 {
     int     i_max   = (rtp_mtu( id )- 12 + i_pad - 1) & ~i_pad;
-    int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
+    int     i_count = VLC_UPPER_DIV( in->i_buffer, i_max );
 
     uint8_t *p_data = in->p_buffer;
     int     i_data  = in->i_buffer;
@@ -1486,7 +1486,7 @@ static int rtp_packetize_g726_40( sout_stream_id_sys_t *id, block_t *in )
 static int rtp_packetize_vp8( sout_stream_id_sys_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - RTP_VP8_HEADER_SIZE;
-    int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
+    int     i_count = VLC_UPPER_DIV( in->i_buffer, i_max );
 
     uint8_t *p_data = in->p_buffer;
     int     i_data  = in->i_buffer;
diff --git a/modules/video_chroma/copy.c b/modules/video_chroma/copy.c
index 444d47a7a7..f7e82f52d9 100644
--- a/modules/video_chroma/copy.c
+++ b/modules/video_chroma/copy.c
@@ -347,7 +347,7 @@ static void SSE_CopyFromYv12(picture_t *dst,
         SSE_CopyPlane(dst->p[n].p_pixels, dst->p[n].i_pitch,
                       src[n], src_pitch[n],
                       cache->buffer, cache->size,
-                      (height+d-1)/d, cpu);
+                      VLC_UPPER_DIV(height,d), cpu);
     }
     asm volatile ("emms");
 }
diff --git a/modules/video_filter/puzzle_mgt.c b/modules/video_filter/puzzle_mgt.c
index 2e085e8d80..80965b5e1e 100644
--- a/modules/video_filter/puzzle_mgt.c
+++ b/modules/video_filter/puzzle_mgt.c
@@ -108,10 +108,10 @@ int puzzle_bake( filter_t *p_filter, picture_t *p_pic_out, picture_t *p_pic_in)
         p_sys->ps_desk_planes[i_plane].i_border_width = p_sys->ps_desk_planes[i_plane].i_width * p_sys->s_current_param.i_border / 2 / 100;
         p_sys->ps_desk_planes[i_plane].i_border_lines = p_sys->ps_desk_planes[i_plane].i_lines * p_sys->s_current_param.i_border / 2 / 100;
 
-        p_sys->ps_desk_planes[i_plane].i_pce_max_width = (( p_sys->ps_desk_planes[i_plane].i_width
-                - 2 * p_sys->ps_desk_planes[i_plane].i_border_width ) + p_sys->s_allocated.i_cols - 1 ) / p_sys->s_allocated.i_cols;
-        p_sys->ps_desk_planes[i_plane].i_pce_max_lines = (( p_sys->ps_desk_planes[i_plane].i_lines
-                - 2 * p_sys->ps_desk_planes[i_plane].i_border_lines ) + p_sys->s_allocated.i_rows - 1 ) / p_sys->s_allocated.i_rows;
+        p_sys->ps_desk_planes[i_plane].i_pce_max_width = VLC_UPPER_DIV( p_sys->ps_desk_planes[i_plane].i_width
+                - 2 * p_sys->ps_desk_planes[i_plane].i_border_width,  p_sys->s_allocated.i_cols );
+        p_sys->ps_desk_planes[i_plane].i_pce_max_lines = VLC_UPPER_DIV( p_sys->ps_desk_planes[i_plane].i_lines
+                - 2 * p_sys->ps_desk_planes[i_plane].i_border_lines, p_sys->s_allocated.i_rows );
 
         p_sys->ps_pict_planes[i_plane].i_lines = p_pic_in->p[i_plane].i_visible_lines;
         p_sys->ps_pict_planes[i_plane].i_pitch = p_pic_in->p[i_plane].i_pitch;
@@ -125,10 +125,10 @@ int puzzle_bake( filter_t *p_filter, picture_t *p_pic_out, picture_t *p_pic_in)
         p_sys->ps_pict_planes[i_plane].i_border_width = p_sys->ps_pict_planes[i_plane].i_width * p_sys->s_current_param.i_border / 2 / 100;
         p_sys->ps_pict_planes[i_plane].i_border_lines = p_sys->ps_pict_planes[i_plane].i_lines * p_sys->s_current_param.i_border / 2 / 100;
 
-        p_sys->ps_pict_planes[i_plane].i_pce_max_width = (( p_sys->ps_desk_planes[i_plane].i_width
-                - 2 * p_sys->ps_pict_planes[i_plane].i_border_width ) + p_sys->s_allocated.i_cols - 1 ) / p_sys->s_allocated.i_cols;
-        p_sys->ps_pict_planes[i_plane].i_pce_max_lines = (( p_sys->ps_pict_planes[i_plane].i_lines
-                - 2 * p_sys->ps_pict_planes[i_plane].i_border_lines ) + p_sys->s_allocated.i_rows - 1 ) / p_sys->s_allocated.i_rows;
+        p_sys->ps_pict_planes[i_plane].i_pce_max_width = VLC_UPPER_DIV( p_sys->ps_desk_planes[i_plane].i_width
+                - 2 * p_sys->ps_pict_planes[i_plane].i_border_width, p_sys->s_allocated.i_cols );
+        p_sys->ps_pict_planes[i_plane].i_pce_max_lines = ( p_sys->ps_pict_planes[i_plane].i_lines
+                - 2 * p_sys->ps_pict_planes[i_plane].i_border_lines, p_sys->s_allocated.i_rows );
 
         for (int32_t r = 0; r < p_sys->s_allocated.i_rows; r++)
             for (int32_t c = 0; c < p_sys->s_allocated.i_cols; c++) {
diff --git a/src/misc/picture.c b/src/misc/picture.c
index 0a2dc8f69a..c69ea72b76 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -177,8 +177,8 @@ int picture_Setup( picture_t *p_picture, const video_format_t *restrict fmt )
     }
     i_modulo_h = LCM( i_modulo_h, 32 );
 
-    const int i_width_aligned  = ( fmt->i_width  + i_modulo_w - 1 ) / i_modulo_w * i_modulo_w;
-    const int i_height_aligned = ( fmt->i_height + i_modulo_h - 1 ) / i_modulo_h * i_modulo_h;
+    const int i_width_aligned  = VLC_UPPER_MODULO( fmt->i_width,  i_modulo_w );
+    const int i_height_aligned = VLC_UPPER_MODULO( fmt->i_height, i_modulo_h );
     const int i_height_extra   = 2 * i_ratio_h; /* This one is a hack for some ASM functions */
     for( unsigned i = 0; i < p_dsc->plane_count; i++ )
     {
-- 
2.11.1



More information about the vlc-devel mailing list