[vlc-devel] [PATCH v2 2/3] modules: use vlc_align helper

Alexandre Janniaux ajanni at videolabs.io
Tue Mar 24 10:02:38 CET 2020


Hi,

Just to be in sync between ML and private discussion, like
Thomas mentioned, you can probably split in multiple commits
before merging. It's ok for review though.

Regards,
--
Alexandre Janniaux
Videolabs

On Mon, Mar 23, 2020 at 11:16:44PM +0100, Marvin Scholz wrote:
> ---
>  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/interop_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..1029e911a8 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 5f5da23b7f..0b5ff68a04 100644
> --- a/modules/codec/avcodec/directx_va.c
> +++ b/modules/codec/avcodec/directx_va.c
> @@ -348,9 +348,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..8571b499dc 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 321815071d..8285bf5ffe 100644
> --- a/modules/hw/nvdec/nvdec.c
> +++ b/modules/hw/nvdec/nvdec.c
> @@ -803,7 +803,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;
> @@ -840,7 +839,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)
> @@ -857,7 +856,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..be4a666978 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/interop_sw.c b/modules/video_output/opengl/interop_sw.c
> index b872f511eb..a553f4f2b4 100644
> --- a/modules/video_output/opengl/interop_sw.c
> +++ b/modules/video_output/opengl/interop_sw.c
> @@ -220,9 +220,7 @@ upload_plane(const struct vlc_gl_interop *interop, 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.21.1 (Apple Git-122.3)
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list