From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 11/13] avcodec/mpegpicture: Move caller-specific parts of function to callers Date: Fri, 6 Oct 2023 04:46:34 +0200 Message-ID: <AS8P250MB0744473592A77FB339ADECEB8FC9A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <AS8P250MB074414A7969C8EDBBF6EA09E8FC9A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> Since at least commit c954cf1e1b766a0d1992d5be0a8be0055a8e1a6a (adding ff_encode_alloc_frame()), a large part of ff_alloc_picture() is completely separate for the two callers. Move the caller-specific parts out to the callers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- I know that the name ff_alloc_picture() (like lots of names in mpegpicture) is no longer appropriate; I will fix this later in rewrite of mpegpicture (soon...). libavcodec/mpegpicture.c | 72 ++++++-------------------------------- libavcodec/mpegpicture.h | 6 ++-- libavcodec/mpegvideo_dec.c | 31 ++++++++++++++-- libavcodec/mpegvideo_enc.c | 22 ++++++++++-- 4 files changed, 62 insertions(+), 69 deletions(-) diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index a0f5181325..44c4c8fe93 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -26,9 +26,6 @@ #include "libavutil/imgutils.h" #include "avcodec.h" -#include "encode.h" -#include "internal.h" -#include "decode.h" #include "motion_est.h" #include "mpegpicture.h" #include "mpegutils.h" @@ -124,57 +121,13 @@ int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, } /** - * Allocate a frame buffer + * Check the pic's linesize and allocate linesize dependent scratch buffers */ -static int alloc_frame_buffer(AVCodecContext *avctx, Picture *pic, - MotionEstContext *me, ScratchpadContext *sc, - int chroma_x_shift, int chroma_y_shift, - int linesize, int uvlinesize) +static int handle_pic_linesizes(AVCodecContext *avctx, Picture *pic, + MotionEstContext *me, ScratchpadContext *sc, + int linesize, int uvlinesize) { - int edges_needed = av_codec_is_encoder(avctx->codec); - int r, ret; - - pic->tf.f = pic->f; - - if (edges_needed) { - pic->f->width = avctx->width + 2 * EDGE_WIDTH; - pic->f->height = avctx->height + 2 * EDGE_WIDTH; - - r = ff_encode_alloc_frame(avctx, pic->f); - } else if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE && - avctx->codec_id != AV_CODEC_ID_VC1IMAGE && - avctx->codec_id != AV_CODEC_ID_MSS2) { - r = ff_thread_get_ext_buffer(avctx, &pic->tf, - pic->reference ? AV_GET_BUFFER_FLAG_REF : 0); - } else { - pic->f->width = avctx->width; - pic->f->height = avctx->height; - pic->f->format = avctx->pix_fmt; - r = avcodec_default_get_buffer2(avctx, pic->f, 0); - } - - if (r < 0 || !pic->f->buf[0]) { - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed (%d %p)\n", - r, pic->f->data[0]); - return -1; - } - - if (edges_needed) { - int i; - for (i = 0; pic->f->data[i]; i++) { - int offset = (EDGE_WIDTH >> (i ? chroma_y_shift : 0)) * - pic->f->linesize[i] + - (EDGE_WIDTH >> (i ? chroma_x_shift : 0)); - pic->f->data[i] += offset; - } - pic->f->width = avctx->width; - pic->f->height = avctx->height; - } - - ret = ff_hwaccel_frame_priv_alloc(avctx, &pic->hwaccel_picture_private, - &pic->hwaccel_priv_buf); - if (ret < 0) - return ret; + int ret; if ((linesize && linesize != pic->f->linesize[0]) || (uvlinesize && uvlinesize != pic->f->linesize[1])) { @@ -247,8 +200,7 @@ static int alloc_picture_tables(AVCodecContext *avctx, Picture *pic, int encodin * The pixels are allocated/set by calling get_buffer() if shared = 0 */ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, - ScratchpadContext *sc, int encoding, - int chroma_x_shift, int chroma_y_shift, int out_format, + ScratchpadContext *sc, int encoding, int out_format, int mb_stride, int mb_width, int mb_height, int b8_stride, ptrdiff_t *linesize, ptrdiff_t *uvlinesize) { @@ -259,14 +211,12 @@ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, || pic->alloc_mb_height != mb_height) free_picture_tables(pic); - av_assert0(!pic->f->buf[0]); - if (alloc_frame_buffer(avctx, pic, me, sc, - chroma_x_shift, chroma_y_shift, - *linesize, *uvlinesize) < 0) - return -1; + if (handle_pic_linesizes(avctx, pic, me, sc, + *linesize, *uvlinesize) < 0) + return -1; - *linesize = pic->f->linesize[0]; - *uvlinesize = pic->f->linesize[1]; + *linesize = pic->f->linesize[0]; + *uvlinesize = pic->f->linesize[1]; if (!pic->qscale_table_buf) ret = alloc_picture_tables(avctx, pic, encoding, out_format, diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h index a04820237a..1c1e5ddbd1 100644 --- a/libavcodec/mpegpicture.h +++ b/libavcodec/mpegpicture.h @@ -82,12 +82,10 @@ typedef struct Picture { } Picture; /** - * Allocate a Picture. - * The pixels are allocated/set by calling get_buffer() if shared = 0. + * Allocate a Picture's accessories, but not the AVFrame's buffer itself. */ int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, - ScratchpadContext *sc, int encoding, - int chroma_x_shift, int chroma_y_shift, int out_format, + ScratchpadContext *sc, int encoding, int out_format, int mb_stride, int mb_width, int mb_height, int b8_stride, ptrdiff_t *linesize, ptrdiff_t *uvlinesize); diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 07febcfe55..4e00137cbb 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -31,6 +31,7 @@ #include "libavutil/video_enc_params.h" #include "avcodec.h" +#include "decode.h" #include "h264chroma.h" #include "internal.h" #include "mpegutils.h" @@ -236,10 +237,36 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) static int alloc_picture(MpegEncContext *s, Picture *pic) { - return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, 0, - s->chroma_x_shift, s->chroma_y_shift, s->out_format, + AVCodecContext *avctx = s->avctx; + int ret; + + pic->tf.f = pic->f; + + if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE && + avctx->codec_id != AV_CODEC_ID_VC1IMAGE && + avctx->codec_id != AV_CODEC_ID_MSS2) { + ret = ff_thread_get_ext_buffer(avctx, &pic->tf, + pic->reference ? AV_GET_BUFFER_FLAG_REF : 0); + } else { + pic->f->width = avctx->width; + pic->f->height = avctx->height; + pic->f->format = avctx->pix_fmt; + ret = avcodec_default_get_buffer2(avctx, pic->f, 0); + } + if (ret < 0) + goto fail; + + ret = ff_hwaccel_frame_priv_alloc(avctx, &pic->hwaccel_picture_private, + &pic->hwaccel_priv_buf); + if (ret < 0) + goto fail; + + return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, 0, s->out_format, s->mb_stride, s->mb_width, s->mb_height, s->b8_stride, &s->linesize, &s->uvlinesize); +fail: + ff_mpeg_unref_picture(avctx, pic); + return ret; } static void color_frame(AVFrame *frame, int luma) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index cb6b801b2a..fe097c2c3b 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1092,8 +1092,26 @@ static int get_intra_count(MpegEncContext *s, const uint8_t *src, static int alloc_picture(MpegEncContext *s, Picture *pic) { - return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, 1, - s->chroma_x_shift, s->chroma_y_shift, s->out_format, + AVCodecContext *avctx = s->avctx; + int ret; + + pic->f->width = avctx->width + 2 * EDGE_WIDTH; + pic->f->height = avctx->height + 2 * EDGE_WIDTH; + + ret = ff_encode_alloc_frame(avctx, pic->f); + if (ret < 0) + return ret; + + for (int i = 0; pic->f->data[i]; i++) { + int offset = (EDGE_WIDTH >> (i ? s->chroma_y_shift : 0)) * + pic->f->linesize[i] + + (EDGE_WIDTH >> (i ? s->chroma_x_shift : 0)); + pic->f->data[i] += offset; + } + pic->f->width = avctx->width; + pic->f->height = avctx->height; + + return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, 1, s->out_format, s->mb_stride, s->mb_width, s->mb_height, s->b8_stride, &s->linesize, &s->uvlinesize); } -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-10-06 2:46 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-10-06 2:38 [FFmpeg-devel] [PATCH 01/13] avcodec/mpegvideo_enc: Fix abort on allocation errors Andreas Rheinhardt 2023-10-06 2:46 ` [FFmpeg-devel] [PATCH 02/13] avcodec/mpegvideo_enc: Remove always-false checks Andreas Rheinhardt 2023-10-06 2:46 ` [FFmpeg-devel] [PATCH 03/13] avcodec/mpegvideo_enc: Reindentation Andreas Rheinhardt 2023-10-06 2:46 ` [FFmpeg-devel] [PATCH 04/13] avcodec/mpegvideo_enc: Don't pretend input to be non-refcounted Andreas Rheinhardt 2023-10-06 2:46 ` [FFmpeg-devel] [PATCH 05/13] avcodec/mpegvideo_enc: Don't reget known values Andreas Rheinhardt 2023-10-08 16:51 ` Michael Niedermayer 2023-10-06 2:46 ` [FFmpeg-devel] [PATCH 06/13] avcodec/mpegvideo_enc: Don't overallocate arrays Andreas Rheinhardt 2023-10-07 16:33 ` Michael Niedermayer 2023-10-07 17:28 ` Andreas Rheinhardt 2023-10-09 12:30 ` Andreas Rheinhardt 2023-10-09 17:17 ` Michael Niedermayer 2023-10-06 2:46 ` [FFmpeg-devel] [PATCH 07/13] avcodec/mpegvideo_enc: Don't set write-only properties Andreas Rheinhardt 2023-10-06 2:46 ` [FFmpeg-devel] [PATCH 08/13] avcodec/mpegvideo_enc: Remove dead block Andreas Rheinhardt 2023-10-06 2:46 ` [FFmpeg-devel] [PATCH 09/13] avcodec/mpegvideo_enc: Don't allocate buffers unnecessarily Andreas Rheinhardt 2023-10-06 2:46 ` [FFmpeg-devel] [PATCH 10/13] avcodec/mpegvideo_enc: Don't call av_frame_copy_props() unnecessarily Andreas Rheinhardt 2023-10-06 2:46 ` Andreas Rheinhardt [this message] 2023-10-06 2:46 ` [FFmpeg-devel] [PATCH 12/13] avcodec/mpeg(picture|video_dec): Move comment to more appropriate place Andreas Rheinhardt 2023-10-08 16:48 ` Michael Niedermayer 2023-10-06 2:46 ` [FFmpeg-devel] [PATCH 13/13] avcodec/vdpau_vc1: Fix indentation Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=AS8P250MB0744473592A77FB339ADECEB8FC9A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git