From patchwork Fri Apr 5 12:41:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 47814 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp935892pzd; Fri, 5 Apr 2024 05:42:19 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU74vOEG8V2mWSycjseTQSLkeWG2wx8PunTh0oI3MCWwMReaBpHig1OQ2yNfQnKVZWwTbkoGV8DIyiwUdSHyc/PlodjEUMA/BwVpQ== X-Google-Smtp-Source: AGHT+IGrWKbHHsNW06HdjnHa+MM8Q3JANslpixj6PcUCXrgekAw+Jenf4YPPpW35+Tfa+UjIz/0L X-Received: by 2002:a17:907:28d1:b0:a51:a1e8:3ccd with SMTP id en17-20020a17090728d100b00a51a1e83ccdmr756831ejc.6.1712320938718; Fri, 05 Apr 2024 05:42:18 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h5-20020a1709062dc500b00a471c15c9d6si664894eji.127.2024.04.05.05.42.18; Fri, 05 Apr 2024 05:42:18 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=LHjSns9N; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 332B168D10C; Fri, 5 Apr 2024 15:42:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2087.outbound.protection.outlook.com [40.92.91.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0273668D06F for ; Fri, 5 Apr 2024 15:42:02 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HwzPUuPwgK0Y/ae3ir+voQKZCcsvT7uG8O48E348Ty6I5syCvSCvPiQ5pmlENU4p+I24pS2KI1v6A12csC1VQklHgjyeYf7Q8ZBhDU2U84NYrdGH7Q3dcUTAvCMpeCycUMYQziRXH9dAMRbWU17CROKV3b5qiAJ3ZLUIK+5n1jEAs3WYCIn+bfGXx8zmZkj5M6pR31tWgjW89J2yCSp4m/vF+5JA2iTBj8p0JX8Gjwefgyj3oGNao1cBUhsl+SOejQZ4ZsKKVSEhm0YP/+Awma3ImDPVRB5DO6hY5rnRWb8WngSyn4lg37DcxvhoOt6MsmygdHM6WwCQ4jNsXquMjg== 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=ox9GsmtOQfyZqdBCLCToEA/7gPcLZPpQo+zEzzYAc3I=; b=ZNDUGhH9PwI46SDWTP3G3JBSZWGTRRACptSICd+P2Pr+g+dOxwnPlRQ0xjosNauV5uF8JqWNwreP/t+lNdgFbHsQtOc0J+ByOu8hdvF1r72YeV/sn7zZWVS4gzS+y0INg1We7IpUWi62Jyso0L4e1/ZipsVDHh8+ER34Iqf4n7ISFdG7GWJbG6+Xl22CGNuV9FIYb9eUrvvOfsVbWyunAwLfOziU+hJYRt0WoZqL+dQhfoIttNsaqPlcIJXd9QkXTwkEnOg2WBCDmEVc4WBPNy2ugwhyhBxUoq5fpGDrI/zcD39cMusil7FdFUAd1YX08TvZpzHAspaQTDrIQr7dRg== 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=ox9GsmtOQfyZqdBCLCToEA/7gPcLZPpQo+zEzzYAc3I=; b=LHjSns9Nw9P/YrIF+LS3B6o3nMiGgQXt9W4f3bcFyNBso1Qn6hBVrLpWGTwiqvX2FTO24vGMPIM71IwVcuvDJSfP6PP5fDMJPPQF3C/HhIhUr83qBcbH9Kr6IC7OWtDNBG63cY03t0eHNkQ+fuesRSNMwnso9MBCiWg6rhB3eGBj41AM4Rny619wSrhzV4s1XfhJNzdMPg077fpXA02HoVkpMPGdBFaOYM2pls+0v5lh6AmdrYb4n/QRkQ3HReOZ7TUEmV1MmwmSmpYWVa5LkNqj3jkj4gZA8lACHA5CVITKAy6jowKAX98XYqGwvWzZNKX/lqKbmKLXJznCsCGMHg== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by AM8P250MB0278.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:329::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Fri, 5 Apr 2024 12:41:59 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d%4]) with mapi id 15.20.7409.042; Fri, 5 Apr 2024 12:41:59 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Apr 2024 14:41:27 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [PDNRdC7hOkKbrFMbiaQoCnQPPmd+ILlb9BgV1hsoXh4=] X-ClientProxiedBy: ZR2P278CA0074.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:52::8) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20240405124138.2343725-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|AM8P250MB0278:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d423ad6-f56c-4547-2eda-08dc556dc8d9 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gj5qy//rrEJ0AbLRr3u9ViMJvQhEeddgokbV8ahWqhL6kScHk+fKUrzzxz3da83KwjxeTA/UtFML80q7IUnyhYhsxqrMnAzLEKwFN5SwwrzNJDAz8BvH45arL9Hc+5Cjn+dvkfdznH+eOxY8vJGZ+aMgUGsZkDF3SxO3YnKamWwvm8xVRxIe5/5lFIQZpt5zfJk14g77IvYvi7yniwuZ4FXNPYMceJmpIgTsvVM11EbpcGCkrs2wuOd3T+3cvdLp4b7IPHBw/SAbW8Z0SstiQPl9oUKfcu2tpJypkyFrgxUaJoiY+GJRctGptdbplWArGGwwPBZcQo/CbiOGOXiBJKGPrxigHgQ6yn+9FwzJlU1fwI2u6OyUOjLO40AjWxigEYenKMWRjvdfWVOlGMkNhkBYuShEvPrWghmc9MaLhDpa13T0XrvrQaQ8aWVDZiBXViXphg7lOZGKWFnzC86cXzl81CI94kGUaHcLHpjeJun6HM4Sy63WeMJjfunkryzZK3qz1qv1DjOI2KwVnGGoY9RzO1z2+FhypBp057pkGbSdWAJcV7fa2WESxOcY80S/7rrtiE/a6QTeBX9ycjKBwsVA5teqrSJcFhe4NAt5S+A3hWd2ukvyfuw5t0FTfKtB X-MS-Exchange-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O8zpf98jdkUayVKamzQw9Hnd5JuqfNk4ltSHJ3fdc0YNDxo/KWmCOsPokMYT9UnHW5xmzCOXp0CghBpq4fE/ZnOh6gDWP3Ug3ujpx5Ie/FosT/iTYH2ZJnDx1RHnalE47rHyWjQTd4LA8ivR9FqoUQq4Tb/QpdZtzPmQNrHxhBmLEQ+z5Du9apmBPiFSaxA1Qim4F4EL+ClQglbfNt1teqIYrjjz2rWTsj9HQtf5hHBw+x2YIBPD5+eDY4yA/i/6fcNN1F+HZzGJmSbr5Jw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d423ad6-f56c-4547-2eda-08dc556dc8d9 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2024 12:41:59.1286 (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: AM8P250MB0278 Subject: [FFmpeg-devel] [PATCH 04/15] avcodec/mpegvideo_dec, mpeg12dec: Move MPEG1/2 code to mpeg12dec.c 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Rai3WUF0DAhU Up until now, ff_mpv_frame_start() offsets the data of the current picture and doubles the linesizes of all pictures if the current picture is field-based so that data and linesize allow to address the current field only. This is done based upon the current picture_structure value. Only two mpegvideo-based decoders ever set this field: mpeg1/2 and VC-1; but the latter only does it after ff_mpv_frame_start() (when using hardware-acceleration and in order to signal it to the DXVA2 hwaccel) in which case no offset is applied in ff_mpv_frame_start(). So only one decoder actually wants this offset*; therefore move the code performing it to mpeg12dec.c. *: VC-1 doubles linesize when using field_mode (not only the picture's linesize, but also uvlinesize and linesize), yet it does not offset anything. This is further proof that this should not be performed generically. Also move MPEG-1/2 specific setting of the top-field-first flag. (The change here implies that the AVFrame in current_picture may have different top-field-first flags than the AVFrame from current_picture_ptr, but this doesn't matter as only the latter's are used.) Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg12dec.c | 15 +++++++++++++++ libavcodec/mpegvideo_dec.c | 19 ------------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 4ad1eb6572..fb8bba3287 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1299,6 +1299,21 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) if ((ret = ff_mpv_frame_start(s, avctx)) < 0) return ret; + if (s->picture_structure != PICT_FRAME) { + s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * + ((s->picture_structure == PICT_TOP_FIELD) == s->first_field); + + for (int i = 0; i < 4; i++) { + if (s->picture_structure == PICT_BOTTOM_FIELD) { + s->current_picture.f->data[i] = FF_PTR_ADD(s->current_picture.f->data[i], + s->current_picture.f->linesize[i]); + } + s->current_picture.f->linesize[i] *= 2; + s->last_picture.f->linesize[i] *= 2; + s->next_picture.f->linesize[i] *= 2; + } + } + ff_mpeg_er_frame_start(s); /* first check if we must repeat the frame */ diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 88facfc39d..1ced9a52ed 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -348,14 +348,7 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) return -1; s->current_picture_ptr = pic; - // FIXME use only the vars from current_pic s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * !!s->top_field_first; - if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO || - s->codec_id == AV_CODEC_ID_MPEG2VIDEO) { - if (s->picture_structure != PICT_FRAME) - s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * - ((s->picture_structure == PICT_TOP_FIELD) == s->first_field); - } s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_INTERLACED * (!s->progressive_frame && !s->progressive_sequence); s->current_picture_ptr->field_picture = s->picture_structure != PICT_FRAME; @@ -454,18 +447,6 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr && s->last_picture_ptr->f->buf[0])); - if (s->picture_structure != PICT_FRAME) { - for (int i = 0; i < 4; i++) { - if (s->picture_structure == PICT_BOTTOM_FIELD) { - s->current_picture.f->data[i] = FF_PTR_ADD(s->current_picture.f->data[i], - s->current_picture.f->linesize[i]); - } - s->current_picture.f->linesize[i] *= 2; - s->last_picture.f->linesize[i] *= 2; - s->next_picture.f->linesize[i] *= 2; - } - } - /* set dequantizer, we can't do it during init as * it might change for MPEG-4 and we can't do it in the header * decode as init is not called for MPEG-4 there yet */