[FFmpeg-devel] [PATCH] Resize AVFilterBuffer data pointers, linesizes. Adjust pic refs to use only four.
Stefano Sabatini
stefano.sabatini-lala
Sun Jul 25 12:13:02 CEST 2010
On date Saturday 2010-07-24 22:04:58 -0700, S.N. Hemanth Meenakshisundaram encoded:
> Removed hack, calling new functions ff_fill_image_linesize and
> ff_fill_image_data_ptr to fill video buffer structure. Right now these
> are added to imgconvert.c in lavc. Should I create libavcore and
> imgutils.c in libavcore?
>
>
> ---
>
> libavcodec/imgconvert.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++
> libavcodec/imgconvert.h | 5 ++
> libavfilter/avfilter.h | 4 +-
> libavfilter/defaults.c | 11 ++--
> 4 files changed, 152 insertions(+), 7 deletions(-)
>
>
>
> diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
> index 8f789c4..1c47b92 100644
> --- a/libavcodec/imgconvert.c
> +++ b/libavcodec/imgconvert.c
> @@ -490,6 +490,145 @@ int ff_set_systematic_pal(uint32_t pal[256], enum PixelFormat pix_fmt){
> return 0;
> }
>
> +int ff_fill_image_linesize(int linesize[4], enum PixelFormat pix_fmt, int width)
> +{
Here you're duplicating the code. What you should do instead is change
the current code to adapt it to the new signature.
Then you redefine the old functions ff_fill_linesize/pointers using
the ff_fill_image* functions.
Then in a second step the new ff_fill_image* functions should be made
public, and moved to libavcore (that would allow to remove the last
libavcodec dependency of lavfi).
[...]
> int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width)
> {
> int i;
> diff --git a/libavcodec/imgconvert.h b/libavcodec/imgconvert.h
> index 48e2f12..22ee6f3 100644
> --- a/libavcodec/imgconvert.h
> +++ b/libavcodec/imgconvert.h
> @@ -27,8 +27,13 @@
> #include <stdint.h>
> #include "avcodec.h"
>
> +int ff_fill_image_linesize(int linesize[4], enum PixelFormat pix_fmt, int width);
> +
> int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width);
>
> +int ff_fill_image_data_ptr(uint8_t *data[4], uint8_t *ptr, enum PixelFormat pix_fmt,
> + int height, const int linesize[4]);
> +
> int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, int height);
missing documentation
> int ff_get_plane_bytewidth(enum PixelFormat pix_fmt, int width, int plane);
> diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> index 066bdc3..a9bec02 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -66,8 +66,8 @@ typedef struct AVFilterPad AVFilterPad;
> */
> typedef struct AVFilterBuffer
> {
> - uint8_t *data[4]; ///< buffer data for each plane
> - int linesize[4]; ///< number of bytes per line
> + uint8_t *data[8]; ///< buffer data for each plane
> + int linesize[8]; ///< number of bytes per line
> int format; ///< media format
>
> unsigned refcount; ///< number of references to this buffer
> diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
> index 27c8a3b..a90288b 100644
> --- a/libavfilter/defaults.c
> +++ b/libavfilter/defaults.c
> @@ -49,18 +49,19 @@ AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link, int perms,
> pic->refcount = 1;
> pic->format = link->format;
> pic->free = avfilter_default_free_buffer;
> - ff_fill_linesize((AVPicture *)pic, pic->format, ref->w);
> + ff_fill_image_linesize(pic->linesize, pic->format, ref->w);
>
> for (i=0; i<4;i++)
> pic->linesize[i] = FFALIGN(pic->linesize[i], 16);
>
> - tempsize = ff_fill_pointer((AVPicture *)pic, NULL, pic->format, ref->h);
> + tempsize = ff_fill_image_data_ptr(pic->data, NULL, pic->format, ref->h, pic->linesize);
> buf = av_malloc(tempsize + 16); // +2 is needed for swscaler, +16 to be
> // SIMD-friendly
> - ff_fill_pointer((AVPicture *)pic, buf, pic->format, ref->h);
> + ff_fill_image_data_ptr(pic->data, buf, pic->format, ref->h, pic->linesize);
>
> - memcpy(ref->data, pic->data, sizeof(pic->data));
> - memcpy(ref->linesize, pic->linesize, sizeof(pic->linesize));
> + /* copy only the four plane pointers and linesizes relevant to video into picture ref */
> + memcpy(ref->data, pic->data, sizeof(pic->data)>>1);
> + memcpy(ref->linesize, pic->linesize, sizeof(pic->linesize)>>1);
>
> return ref;
> }
This hunk looks fine, but I'd prefer to split it into a separate patch.
Regards.
--
FFmpeg = Fast and Frenzy Multipurpose Proud Eretic Guru
More information about the ffmpeg-devel
mailing list