[vlc-devel] [PATCH 2/2] modules: use VLC_ALIGN macro

Marvin Scholz epirat07 at gmail.com
Fri Jan 10 20:05:05 CET 2020


---
 modules/audio_filter/converter/tospdif.c   |  5 ++---
 modules/codec/avcodec/directx_va.c         |  6 +++---
 modules/codec/qsv.c                        |  9 +++------
 modules/hw/nvdec/nvdec.c                   |  5 ++---
 modules/video_output/kms.c                 | 19 ++++++++-----------
 modules/video_output/opengl/converter_sw.c |  4 +---
 6 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/modules/audio_filter/converter/tospdif.c b/modules/audio_filter/converter/tospdif.c
index 239deae26f..1a0f84e6c2 100644
--- a/modules/audio_filter/converter/tospdif.c
+++ b/modules/audio_filter/converter/tospdif.c
@@ -519,9 +519,8 @@ static int write_buffer_dtshd( filter_t *p_filter, block_t *p_in_buf )
 
     /* Align so that (length_code & 0xf) == 0x8. This is reportedly needed
      * with some receivers, but the exact requirement is unconfirmed. */
-#define ALIGN(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
-    size_t i_align = ALIGN( i_in_size + 0x8, 0x10 ) - 0x8;
-#undef ALIGN
+    size_t i_align = VLC_ALIGN( i_in_size + 0x8, 0x10 ) - 0x8;
+
     if( i_align > i_in_size && i_align - i_in_size
         <= p_sys->p_out_buf->i_buffer - p_sys->i_out_offset )
         write_padding( p_filter, i_align - i_in_size );
diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index d7a1e7edea..a641783b2c 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -326,9 +326,9 @@ const directx_va_mode_t *directx_va_Setup(vlc_va_t *va, const directx_sys_t *dx_
         return NULL;
 
     assert((surface_alignment & (surface_alignment - 1)) == 0); /* power of 2 */
-#define ALIGN(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
-    int surface_width  = ALIGN(avctx->coded_width,  surface_alignment);
-    int surface_height = ALIGN(avctx->coded_height, surface_alignment);
+
+    int surface_width  = VLC_ALIGN(avctx->coded_width,  surface_alignment);
+    int surface_height = VLC_ALIGN(avctx->coded_height, surface_alignment);
 
     if (avctx->coded_width != surface_width || avctx->coded_height != surface_height)
         msg_Warn( va, "surface dimensions (%dx%d) differ from avcodec dimensions (%dx%d)",
diff --git a/modules/codec/qsv.c b/modules/codec/qsv.c
index b9e69bb322..76e04ef7dd 100644
--- a/modules/codec/qsv.c
+++ b/modules/codec/qsv.c
@@ -49,9 +49,6 @@
 /* The SDK doesn't have a default bitrate, so here's one. */
 #define QSV_BITRATE_DEFAULT (842)
 
-/* Makes x a multiple of 'align'. 'align' must be a power of 2 */
-#define QSV_ALIGN(align, x)     (((x)+(align)-1)&~((align)-1))
-
 /*****************************************************************************
  * Modules descriptor
  *****************************************************************************/
@@ -459,8 +456,8 @@ static int Open(vlc_object_t *this)
     sys->params.mfx.FrameInfo.FrameRateExtD = enc->fmt_in.video.i_frame_rate_base;
     sys->params.mfx.FrameInfo.FourCC        = MFX_FOURCC_NV12;
     sys->params.mfx.FrameInfo.ChromaFormat  = MFX_CHROMAFORMAT_YUV420;
-    sys->params.mfx.FrameInfo.Width         = QSV_ALIGN(16, enc->fmt_in.video.i_width);
-    sys->params.mfx.FrameInfo.Height        = QSV_ALIGN(32, enc->fmt_in.video.i_height);
+    sys->params.mfx.FrameInfo.Width         = VLC_ALIGN(enc->fmt_in.video.i_width, 16);
+    sys->params.mfx.FrameInfo.Height        = VLC_ALIGN(enc->fmt_in.video.i_height, 32);
     sys->params.mfx.FrameInfo.CropW         = enc->fmt_in.video.i_visible_width;
     sys->params.mfx.FrameInfo.CropH         = enc->fmt_in.video.i_visible_height;
     sys->params.mfx.FrameInfo.PicStruct     = MFX_PICSTRUCT_PROGRESSIVE;
@@ -762,7 +759,7 @@ static int submit_frame(encoder_t *enc, picture_t *pic, QSVFrame **new_frame)
     else
         qf->surface.Info.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
 
-    //qf->surface.Data.Pitch = QSV_ALIGN(16, qf->surface.Info.Width);
+    //qf->surface.Data.Pitch = VLC_ALIGN(qf->surface.Info.Width, 16);
 
     qf->surface.Data.PitchLow  = qf->pic->p[0].i_pitch;
     qf->surface.Data.Y         = qf->pic->p[0].p_pixels;
diff --git a/modules/hw/nvdec/nvdec.c b/modules/hw/nvdec/nvdec.c
index 19b45e2529..bb21a0ea6c 100644
--- a/modules/hw/nvdec/nvdec.c
+++ b/modules/hw/nvdec/nvdec.c
@@ -794,7 +794,6 @@ static int OpenDecoder(vlc_object_t *p_this)
     int i_sar_num, i_sar_den = 0;
 
     // try different output
-#define ALIGN(v, mod) ((v + (mod - 1)) & ~(mod - 1))
     if (p_sys->b_is_hxxx)
     {
         uint8_t i_chroma_idc, i_depth_chroma;
@@ -831,7 +830,7 @@ static int OpenDecoder(vlc_object_t *p_this)
             }
         }
 
-        p_dec->fmt_out.video.i_width = ALIGN(i_w, OUTPUT_WIDTH_ALIGN);
+        p_dec->fmt_out.video.i_width = VLC_ALIGN(i_w, OUTPUT_WIDTH_ALIGN);
         p_dec->fmt_out.video.i_height = i_h;
 
         if (!p_dec->fmt_in.video.i_visible_width || !p_dec->fmt_in.video.i_visible_height)
@@ -848,7 +847,7 @@ static int OpenDecoder(vlc_object_t *p_this)
     }
     else
     {
-        p_dec->fmt_out.video.i_width = ALIGN(p_dec->fmt_in.video.i_width, OUTPUT_WIDTH_ALIGN);
+        p_dec->fmt_out.video.i_width = VLC_ALIGN(p_dec->fmt_in.video.i_width, OUTPUT_WIDTH_ALIGN);
         p_dec->fmt_out.video.i_height = p_dec->fmt_in.video.i_height;
         cudaChroma = cudaVideoChromaFormat_420;
         i_depth_luma = 8;
diff --git a/modules/video_output/kms.c b/modules/video_output/kms.c
index 34ef0b0df5..fcd25f9b7c 100644
--- a/modules/video_output/kms.c
+++ b/modules/video_output/kms.c
@@ -115,9 +115,6 @@ static void DestroyFB(vout_display_sys_t const *sys, uint32_t const buf)
     drmIoctl(sys->drm_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_req);
 }
 
-
-#define ALIGN(v, a) (((v) + (a)-1) & ~((a)-1))
-
 static deviceRval CreateFB(vout_display_t *vd, const int buf)
 {
     vout_display_sys_t *sys = vd->sys;
@@ -143,23 +140,23 @@ static deviceRval CreateFB(vout_display_t *vd, const int buf)
     case DRM_FORMAT_P016:
 #endif
 #if defined(DRM_FORMAT_P010) || defined(DRM_FORMAT_P012) || defined(DRM_FORMAT_P016)
-        sys->stride = ALIGN(sys->width*2, tile_width);
-        sys->offsets[1] = sys->stride*ALIGN(sys->height, tile_height);
-        create_req.height = 2*ALIGN(sys->height, tile_height);
+        sys->stride = VLC_ALIGN(sys->width*2, tile_width);
+        sys->offsets[1] = sys->stride*VLC_ALIGN(sys->height, tile_height);
+        create_req.height = 2*VLC_ALIGN(sys->height, tile_height);
         break;
 #endif
     case DRM_FORMAT_NV12:
-        sys->stride = ALIGN(sys->width, tile_width);
-        sys->offsets[1] = sys->stride*ALIGN(sys->height, tile_height);
-        create_req.height = 2*ALIGN(sys->height, tile_height);
+        sys->stride = VLC_ALIGN(sys->width, tile_width);
+        sys->offsets[1] = sys->stride*VLC_ALIGN(sys->height, tile_height);
+        create_req.height = 2*VLC_ALIGN(sys->height, tile_height);
         break;
     default:
-        create_req.height = ALIGN(sys->height, tile_height);
+        create_req.height = VLC_ALIGN(sys->height, tile_height);
 
         /*
          * width *4 so there's enough space for anything.
          */
-        sys->stride = ALIGN(sys->width*4, tile_width);
+        sys->stride = VLC_ALIGN(sys->width*4, tile_width);
         break;
     }
 
diff --git a/modules/video_output/opengl/converter_sw.c b/modules/video_output/opengl/converter_sw.c
index 3eb3eeb3ae..c80ac93bfe 100644
--- a/modules/video_output/opengl/converter_sw.c
+++ b/modules/video_output/opengl/converter_sw.c
@@ -230,9 +230,7 @@ upload_plane(const opengl_tex_converter_t *tc, unsigned tex_idx,
     {
         if (pitch != visible_pitch)
         {
-#define ALIGN(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
-            visible_pitch = ALIGN(visible_pitch, 4);
-#undef ALIGN
+            visible_pitch = VLC_ALIGN(visible_pitch, 4);
             size_t buf_size = visible_pitch * height;
             const uint8_t *source = pixels;
             uint8_t *destination;
-- 
2.20.1 (Apple Git-117)



More information about the vlc-devel mailing list