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 B6C0446A38 for ; Mon, 29 Apr 2024 00:36:12 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EE5A068D43D; Mon, 29 Apr 2024 03:36:01 +0300 (EEST) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03olkn2092.outbound.protection.outlook.com [40.92.59.92]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6944268D428 for ; Mon, 29 Apr 2024 03:35:55 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hDuY+oTfD8nR1Rr5TRCd2FXmc7a0PqRJl3cZTlFXRufoHcS7QRN6QQXIYU+zKj2Mk9E10eJTQN2WrzSGQw32dxj/Jctbn5X2bYS734VuX0ebbtLU+Co/y5B9VwwhzMCmBnqqHd2d7FpozWIuqkfRZGr69zrYh8youq4spv6OESAgM8L93lWshYX7KRuELjf9+6g+g4iIHCvURdiJGQ0StRCGiLuOzlbZ7oXlvg182tckmEdaqNScGTAnhrwO+yJMZdszSCtvYC8r5gqW+zUjVPOp5FYcRrhPorUicmKThGundm8PREcNxdwZJARSGwxfFXvVNVBgHopdurw/HLxJKw== 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=lI9JdPRx0oo0qr0wNqHPlkFLPIfn3JzI0Vkx4XD/lYc=; b=ndQkTne4/nd5zVGzTLjOqYRGgdK8FILleA3nCR0PAz7jqqjyRBKXXVHd0WRzsF/Es7MSsQFbHJugilZ2/DJNRjtszJGWelSxCqEeuVQ0uugVYkzCgpwKCV3MLJ56tMS+wOMHOZzX5tNq9Kgb0Y5Iknr3fFzpi41OQh6HZiw7nmV7lGxXkCvqdEPEOh8eq0n6H671cyBqEUalw2GA0vbgvfOmBAjAQag66yenfJ+yKTaTEwLrzWilqD9n0mTTlaI+wBRqEAXrfbXFK6VAQ2FULdo3+TU0aRveOrnu3zj8qtUSCUhhE9nAshS8znDA670aRq9UvKjl8eTxYRBjSgGriQ== 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=lI9JdPRx0oo0qr0wNqHPlkFLPIfn3JzI0Vkx4XD/lYc=; b=e47cOcZT5AhI1bNyg1w08GRv37gQyMzggz2WI7htqbBOAye8s8bI7IWWecr1T17ZTbKQtqMJAPa+RWoxglJjIdykcSfVMU5R13B0qTCF6WkzEl5SWyzpUv+joUF5Ah+Ax0VuZsRDoUos6/Sx6ov7SuLvRvEjgcrnIUUK1XiP/dDvsT2fwObSVzKm9O8PJvGkMQEbDgnL/zE2aqK98IFNPQ8f1eJpWdnZRvuUB+PwfLxXOrRMvTZGkHGldu1fsVxwlAYKsqmH47obkoI9yPhaUVFidWLFHAx5SasMWrtv1cB+P2+lYKJPjKAx0hWaEX1dWw5a5A+rkccD1UWT5wIUXw== Received: from GV1SPRMB0021.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:60::6) by PR3P250MB0068.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:173::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Mon, 29 Apr 2024 00:35:48 +0000 Received: from GV1SPRMB0021.EURP250.PROD.OUTLOOK.COM ([fe80::4eb:f54f:b451:34fd]) by GV1SPRMB0021.EURP250.PROD.OUTLOOK.COM ([fe80::4eb:f54f:b451:34fd%4]) with mapi id 15.20.7519.021; Mon, 29 Apr 2024 00:35:48 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Apr 2024 02:35:25 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [SDo68Xpt7by4fj3CaQFnseyuv0KqabjKWPXoAIWwdNw=] X-ClientProxiedBy: FR2P281CA0080.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9a::13) To GV1SPRMB0021.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:60::6) X-Microsoft-Original-Message-ID: <20240429003535.1516058-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1SPRMB0021:EE_|PR3P250MB0068:EE_ X-MS-Office365-Filtering-Correlation-Id: 3fb69eee-5427-4942-c669-08dc67e45061 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|440099019|3412199016|1710799017; X-Microsoft-Antispam-Message-Info: 6VJkWn0wC3yR++nqJT29JbN/LnNVRyckFU9eTwxRG1GEbkqP6zIB6a4OHMXzlrBCb0u5OrTUGBL4hOnVgGb8AiRYZWlyyQbbZvkOyva3b1HuWm9P0tpAF9TC7Dy7N6kfnlobnK7FNRvT2iORSbBTMDJfN/Acr4wmXfzYRPZHuNhmEIivgDSUHmbk2sSf5Y8DxKyfzErh1i179Qr2TCYflsuJcq6ycfAu+iwYqn/ChrWcJTdJrGsNgJWuqASP6Jg0uQH1iSTfmFeJHyAE5qRDRhiKiX/reIXYYwKmMNU4Iy1403RAisH6hwrU8xfhmPHo7gabne6+YMRvDQZ/PrCGU32lrZtN39f3Ya5IHeu3ZxUXRYQs7McqHaRm6xs8YY1z+Kx6lIZ7Dv+yEDBY+EGcQYR28CfsVMwD5LjpMxBHBXRiDy8rqikrq8gVjz980bQqe0UUyqOkjp+NSOBgDMcfc2QoiQyVn4646O1ADhG/AhEZ5CF2AaTx744AbQXmoBXskhwbdKFfpy0kL3xSlj0eDdagbDtRaoRPihVvbekp6hpR/PHii3xau+AT3hFI+CP2HBLPyeWR1aicuRI4ZlozPr8XeKzvrTh9dNg0Zf6kuNCexuVFRhSDRdENpwMLB3rr X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?k6+RL84lnefi64dpqQZl0QsYAGFYmo/D+RALOfSB8a4Clzq/QmaO402AQEuR?= =?us-ascii?Q?CJy5aayVPa3SFluhC5Zj23LQLV4D0iyKlUdcVsLhUoxNJrQgNYOSp+3y+Sbs?= =?us-ascii?Q?paPEXN8Qzf0qon+SHJFixTE4AuZmEVgGTjULouY151DaLo5QfaT7GBjy+AeF?= =?us-ascii?Q?I9I4yN+zISHETJNm7KgK26QnJOIZu38+zuO9DwzwMZpsGV/YyKDn7emTBzMi?= =?us-ascii?Q?ZXQWmDQybEmOhW6a8dldSKhVMbp9s79dIwdfFV4fSRsrho36kbhDTurS7jaL?= =?us-ascii?Q?UuJw4+fzTt2sewRbNVk+YbPf76Uk27IFZFUFJpHG2zCrWw/0GepRF4dtqIxh?= =?us-ascii?Q?xzS9IPeC8ngxJfI8CO1qHdQOm/+AlFy/wBLxkODAx36YRVVYOfF5DyGsQy/J?= =?us-ascii?Q?1CMd1vog9PgiSU5kaEYKQT8NsVGABNIFGzMbOY/U5SqRVmii19B7F6ufYWlV?= =?us-ascii?Q?75uohbyc3HEQ4+JZGSsBlb/OhvjKvuriM31tu9l6rwP1ApKR921i+VZO8P+x?= =?us-ascii?Q?eRUmTq8A7jNsv8G0e0u95zHkR6MzpKbfoQuJHuUr/o55jR2bfwqWJPJhXuWm?= =?us-ascii?Q?6NCqPVgfdrlxjhX74524+8QxLX0j9U+l4bQAqv9gCRtIlWVBjdK6x2CMgy0x?= =?us-ascii?Q?kqbHb96hscuiTRFKhaNyr7DtJvHkoS2IH4DjlqIGhhOto02Mc0GMWukzl/88?= =?us-ascii?Q?bvIFI6vTRMwQfXs0VjvJV3ahb8dLP36S2hnV9e4wmDKn7CfjFzDOWyAqgW1r?= =?us-ascii?Q?ok4xbmA0WHIGBRlXIzgXjMBVj0THUb9RzrFRZWB8urrtWU9Pc/+yRq/tNq8q?= =?us-ascii?Q?xkPH46EMoN6ItvoYSMUKLoM5TMFmpYFu8ubh66JWl0W6KVo20usUf8gJ2yb2?= =?us-ascii?Q?k5xXBaz1kqKosCPFX/ErYVSktM7/bifaDQWgQJkzM0ZHIBcSaA9xM9MpwOAW?= =?us-ascii?Q?paaXwSkYZLv3GlMCSf678VgcjRyYjET/w3qAcY2uGu3OKbUrBW2U+lefSk7z?= =?us-ascii?Q?ivKCoFjQNfOtFe3ptPhdwReUQu825iu2bWKmocxawi0J2aJndpCwSMSWV+r+?= =?us-ascii?Q?wn7sCcUL0iu7U2UNSmg+13Y5qHbeUhad84opTDE3M5t+4X66xYpUfyZLhhiI?= =?us-ascii?Q?8T0zKy1AJYAziUMDqUhnRLmT9fikCT/Gi6T5d9IOPZ8fs/DXzNPvaAR6rocZ?= =?us-ascii?Q?0NTsGs3eTzuCzXc9IT3rEgVYKBbrjK7uN/4cnwETsqqPUr/eK0FW5hbmnxQM?= =?us-ascii?Q?Njhx0oD8wmZrfb0PCvyPPoHM2aBHinDD/1THgxRM+g=3D=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3fb69eee-5427-4942-c669-08dc67e45061 X-MS-Exchange-CrossTenant-AuthSource: GV1SPRMB0021.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 00:35:48.0055 (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: PR3P250MB0068 Subject: [FFmpeg-devel] [PATCH 04/14] avcodec/mpegvideo_dec: Factor allocating dummy frames out 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: This will allow to reuse it to allocate dummy frames for the second field (which can be a P-field even if the first field was an intra field). Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_dec.c | 85 +++++++++++++++++++++++--------------- libavcodec/mpegvideodec.h | 4 ++ 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 597ffde7f8..efc257d43e 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -281,14 +281,21 @@ fail: return ret; } -static int av_cold alloc_dummy_frame(MpegEncContext *s, Picture **picp) +static int av_cold alloc_dummy_frame(MpegEncContext *s, Picture **picp, Picture *wpic) { Picture *pic; - int ret = alloc_picture(s, picp, 1); + int ret = alloc_picture(s, &pic, 1); if (ret < 0) return ret; - pic = *picp; + ff_mpeg_unref_picture(wpic); + ret = ff_mpeg_ref_picture(wpic, pic); + if (ret < 0) { + ff_mpeg_unref_picture(pic); + return ret; + } + + *picp = pic; ff_thread_report_progress(&pic->tf, INT_MAX, 0); ff_thread_report_progress(&pic->tf, INT_MAX, 1); @@ -314,6 +321,45 @@ static void color_frame(AVFrame *frame, int luma) } } +int ff_mpv_alloc_dummy_frames(MpegEncContext *s) +{ + AVCodecContext *avctx = s->avctx; + int ret; + + if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) && + (s->pict_type != AV_PICTURE_TYPE_I)) { + if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0]) + av_log(avctx, AV_LOG_DEBUG, + "allocating dummy last picture for B frame\n"); + else if (s->codec_id != AV_CODEC_ID_H261 /* H.261 has no keyframes */ && + (s->picture_structure == PICT_FRAME || s->first_field)) + av_log(avctx, AV_LOG_ERROR, + "warning: first frame is no keyframe\n"); + + /* Allocate a dummy frame */ + ret = alloc_dummy_frame(s, &s->last_picture_ptr, &s->last_picture); + if (ret < 0) + return ret; + + if (!avctx->hwaccel) { + int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263 ? 16 : 0x80; + color_frame(s->last_picture_ptr->f, luma_val); + } + } + if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) && + s->pict_type == AV_PICTURE_TYPE_B) { + /* Allocate a dummy frame */ + ret = alloc_dummy_frame(s, &s->next_picture_ptr, &s->next_picture); + if (ret < 0) + return ret; + } + + av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr && + s->last_picture_ptr->f->buf[0])); + + return 0; +} + /** * generic function called after decoding * the header and before a frame is decoded. @@ -382,34 +428,6 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) s->current_picture_ptr ? s->current_picture_ptr->f->data[0] : NULL, s->pict_type, s->droppable); - if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) && - (s->pict_type != AV_PICTURE_TYPE_I)) { - if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0]) - av_log(avctx, AV_LOG_DEBUG, - "allocating dummy last picture for B frame\n"); - else if (s->codec_id != AV_CODEC_ID_H261) - av_log(avctx, AV_LOG_ERROR, - "warning: first frame is no keyframe\n"); - - /* Allocate a dummy frame */ - ret = alloc_dummy_frame(s, &s->last_picture_ptr); - if (ret < 0) - return ret; - - if (!avctx->hwaccel) { - int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263 ? 16 : 0x80; - color_frame(s->last_picture_ptr->f, luma_val); - } - - } - if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) && - s->pict_type == AV_PICTURE_TYPE_B) { - /* Allocate a dummy frame */ - ret = alloc_dummy_frame(s, &s->next_picture_ptr); - if (ret < 0) - return ret; - } - if (s->last_picture_ptr) { if (s->last_picture_ptr->f->buf[0] && (ret = ff_mpeg_ref_picture(&s->last_picture, @@ -423,8 +441,9 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) return ret; } - av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr && - s->last_picture_ptr->f->buf[0])); + ret = ff_mpv_alloc_dummy_frames(s); + if (ret < 0) + return ret; /* 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 diff --git a/libavcodec/mpegvideodec.h b/libavcodec/mpegvideodec.h index 0b841bc1a1..42c2697749 100644 --- a/libavcodec/mpegvideodec.h +++ b/libavcodec/mpegvideodec.h @@ -50,6 +50,10 @@ void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx); int ff_mpv_common_frame_size_change(MpegEncContext *s); int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx); +/** + * Ensure that the dummy frames are allocated according to pict_type if necessary. + */ +int ff_mpv_alloc_dummy_frames(MpegEncContext *s); void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]); void ff_mpv_report_decode_progress(MpegEncContext *s); void ff_mpv_frame_end(MpegEncContext *s); -- 2.40.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".