From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 6BDAF47387 for ; Fri, 6 Oct 2023 02:46:57 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 92CA568CC59; Fri, 6 Oct 2023 05:46:11 +0300 (EEST) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2011.outbound.protection.outlook.com [40.92.65.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AEA7A68CBE9 for ; Fri, 6 Oct 2023 05:46:09 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aMnrYB41JPWgLVMLvqQn2k8ZPJ0M2m6jp/nDcKGcM7w5tIpHUp9hcWv8FP/Ee9rmFl5VNxTbfVZQaRySNOdZyEYPVk8lznMCGqUH1n6U71ihYslC8cnw2bOAP+ZrFzm4PMmPI9Sc5P5DjS39QM7v6IYv1zaS7WxUxQhPrcut3TJAtyHU6zoNZxQf3clJxl6sfMRUPpnsZn1+zX3tdp+y9d6pdvXqwxhNlvjokTlRFE62uAY/0tgnkUQY0dnBltF8CU2ECgBtnXeJLH3ftXXkeH+/Ifl5lnNwc+7SmmCqhW0BJQkijobEKBLYrRUoLBP6UXywmsAY5yd8JUNDkgJaQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Jpwmf588koEJ3w74pv8MsURZ7PW8AsVOZezbYW7txF4=; b=m3nwZkW+H7lGW3a7Nm9utHml4LEDKqLekr6W+pgSGaD08M8T7HuNNZhfu0jCSxOS3cND4zw1wdxOcTMRigApUUDWksVx9fjLMg5B9FpVjddJbqzVgM6QnPF5svwrKFK2D3gSuOZuBZN9ZtaPEbciVv7krW9wgWfUPeHxguFfMtXVsKZxqGd+FSq+Qs7vXfEJPuRYfGG4kGC4Xp1gBhDEBOhIvk4eyt7IrKxmelvtoVjihKO36zydaxI2/zo/z4KBpAvUcnIXqLK+oWCedqq7SpsYmfQQX0cv+KgbrAM5T6trAEKlfpbpNMwD1GLEx4wZL9VSO+hJlSbjxIAAUnH6SA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Jpwmf588koEJ3w74pv8MsURZ7PW8AsVOZezbYW7txF4=; b=pW5A+B6+nzOoz/n7EhP26xzopBvoVhLyQf9PQMAPPMc4GPCVyGvLaBN+ot8NuzsjDerLfgz3/fPQqCtGbmFdJagAEGVEpxGA2HBpgZJ4V70edWcCNM49fY6GwOWiLWWBt0sRYQqNElh9wnvK0qopxrZejbVfUe2LFE116EAyM/1Zadj6z1lTFkLuPKNpIj70KFUzJdN0+6MY33Xoby2OphRus+/Z974dU97sDExoTQZ1cbVC2kjB92LneMa8F1Keujq34w+sB5lv++jTPFPdhU9A5jqSJxQUr1jrLgyZR8B93uwoMoSPwkOCQWWhD7+ZjXcw4SMH1RTlRo0drfFKRA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0148.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:275::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.37; Fri, 6 Oct 2023 02:46:08 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Fri, 6 Oct 2023 02:46:08 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 6 Oct 2023 04:46:34 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [uwBllcxIZuHH+hNl8YZySejkJpXHZKXq] X-ClientProxiedBy: FR4P281CA0094.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:cb::11) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20231006024636.1005349-10-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0148:EE_ X-MS-Office365-Filtering-Correlation-Id: 109e2688-03a3-419f-57ac-08dbc6166481 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U3srwfOl0PSXWkgB34OkElZHpdLjwfEbhXDh6f9u/Imzfy1Bdi+pSiQ0nkW6npE+xMpXTaJoW5bx4CJMWlGaJ8WzDDbzY/uCZCH7GBmSZBGNGW2Srn+LqkiGGuTQvSNxeCv+ImXC5QM+5ih/2zVe348bdNZvqoj6eQYDnjxXu7yzRGaas6Gu+Fgv5Sl0/AmKCdeMkHnSH+uNPpk6PTQL5kAZsloRQgj4oXHi1uj+Z1evTk6yzLL80/Dc7R9jDmcO0Sqvz+YMQtiqZDf7DVZGNpdYwJajv8RAwcg59MVqvx5OfMK8+cMj8E1x5oguPHiGHH+9IWH0b8NHhCR1ztrsNcYR6wT3H0PfLZV/C2OiYE5cLbnXPspvtDAumUdoTmo4bKUdHIWUG5trPVIayrc4snIJSA780nr6i9ngNCUzrIa3IA9b7+RoBkhRHX18LNMtLIbJTgUMaHIN7q2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4+RLcOtl9sJeEyQsx4ad2+XFTKHDZWI2U2btuf1TvqlGKw9VxsKFPsqkSY9?= =?us-ascii?Q?h1icFOlGfs54EUP0qg2I64cHAld7gdcC9xtI6+vCR49GP87EqwyqqEE7ITzj?= =?us-ascii?Q?fEggixBVNVnOrfqPKM4wJtzom3t6OETVFUUOORi6Mblqyb/hKW+W7t6aLy1W?= =?us-ascii?Q?O3614YPjn/v1hb9rV/Hg4kk0ISBNJ5G0Fc2N/MAX7h+O6elcPbSoUSxZrj1J?= =?us-ascii?Q?mxu+8QJXyeeTbh5OrKha5C/v1ymZzt0zZUY2ceE8mF63D6np4Mi1tXsUQMfW?= =?us-ascii?Q?RXtDlvkKMZDOV/24rxUHkk4sKEQYc4cEoXAolfw0fsGoo459pfh4VljG8nLV?= =?us-ascii?Q?ysqBwMGFu/DdqN4sQOyFKpUZX+xB3cJ7jP27bBfmNVbtyLZF0GmR1P+OWKGJ?= =?us-ascii?Q?pPRm1P6RD5l5YSrk3Z7LK/7bbjq3CLorTuO8Llieiinqi2/PgUumIk3n43rf?= =?us-ascii?Q?W56YjfWotocpiYpSg1GYIoYJpO/NqZbUbM+APjUhBqOO7TSjvKkb+odKZEyB?= =?us-ascii?Q?j/KdwiMZO7k1/K1eyZnE+upvdSmVFSQm3uSH+pOrAOMlR8mwWkssubjwrFtU?= =?us-ascii?Q?sYKa5C3BgUtCE9oRswOy?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 109e2688-03a3-419f-57ac-08dbc6166481 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Oct 2023 02:46:08.3156 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2P250MB0148 Subject: [FFmpeg-devel] [PATCH 11/13] avcodec/mpegpicture: Move caller-specific parts of function to callers X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 --- 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".