[FFmpeg-devel] [PATCH 1/3] lavu/frame: add av_frame_check_align().

Muhammad Faiz mfcc64 at gmail.com
Thu May 18 13:18:46 EEST 2017


On Thu, May 18, 2017 at 3:11 PM, Nicolas George <george at nsup.org> wrote:
> Signed-off-by: Nicolas George <george at nsup.org>
> ---
>  doc/APIchanges    |  3 +++
>  libavutil/frame.c | 17 +++++++++++++++++
>  libavutil/frame.h |  8 ++++++++
>  3 files changed, 28 insertions(+)
>
>
> With the linesize check and without the 1<<.
>
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 67a6142401..6d3b573c2d 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil:     2015-08-28
>
>  API changes, most recent first:
>
> +2017-05-18 - xxxxxxxxxx - lavu 55.63.100 - frame.h
> +  Add av_frame_check_align().
> +
>  2017-05-15 - xxxxxxxxxx - lavc 57.96.100 - avcodec.h
>    VideoToolbox hardware-accelerated decoding now supports the new hwaccel API,
>    which can create the decoder context and allocate hardware frames automatically.
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index 24d5d5f184..aed3cd04ec 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -781,3 +781,20 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type)
>      }
>      return NULL;
>  }
> +
> +int av_frame_check_align(const AVFrame *frame, unsigned align)
> +{
> +    unsigned mask = align - 1;
> +    unsigned i;
> +
> +    for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
> +        if (((intptr_t)frame->data[i] & mask) ||
> +            (frame->linesize[i] & mask))
> +            return 0;
> +    if (!frame->extended_data || frame->extended_data == frame->data)
> +        return 1;
> +    for (i = AV_NUM_DATA_POINTERS; i < frame->channels; i++)
> +        if (((intptr_t)frame->extended_data[i] & mask))
> +            return 0;

Missing linesize check.


> +    return 1;
> +}
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 26261d7e40..1cbf7c7a5a 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -772,6 +772,14 @@ void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);
>  const char *av_frame_side_data_name(enum AVFrameSideDataType type);
>
>  /**
> + * Check if the data pointers of a frame are aligned enough.
> + * Test if all frame data pointers have the alignment lower bits cleared,
> + * i.e. are a multiple of alignment.
> + * @return  >0 if aligned, 0 if not
> + */
> +int av_frame_check_align(const AVFrame *frame, unsigned align);
> +
> +/**
>   * @}
>   */
>
> --
> 2.11.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

I tested the behaviour of av_frame_get_buffer(frame, 32) and check
linesize[0], here the result of some different pixel formats:
yuv420p: 32
rgb24: 96
rgba: 32

So linesize constraint acutually depends on pixel format.

IMHO, because the fact of crop filter, actually (probably all) video
filters and codecs accept unaligned data pointer but (some of them)
require aligned linesize.

Thank's.


More information about the ffmpeg-devel mailing list