From patchwork Tue Nov 14 17:20:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44661 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:92a5:b0:181:818d:5e7f with SMTP id q37csp2134521pzg; Tue, 14 Nov 2023 09:21:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGc5mUQT16Fk3O427wIjuu2luUL5HjB+8uwqHQeeDoYP7zkNaFLjS6/YvcGphLykoYa49Ou X-Received: by 2002:a50:ee1a:0:b0:532:bf2a:8cbc with SMTP id g26-20020a50ee1a000000b00532bf2a8cbcmr7399585eds.16.1699982490808; Tue, 14 Nov 2023 09:21:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699982490; cv=none; d=google.com; s=arc-20160816; b=rojnYjJ0W+Eqx/y+aFoZXPaxIn7q8LZjX+Rr0TVWhz5kWZhRJJOM+i3mWma1IuZdL3 EoQEznZjqfo6UosLx3Ns1HEUZwvD8uONSk6der8roR6JOcV68370REEw9MyJORNN0M/Z StBPE1la3Wd114nyccW9J2Wcu1VHLf0fA5PP/r/XCTfFkDb7awg+2YbwH5E86rEZDM2X /apk06CanHDIQwX45mlXW3EzGS+6O7i2uMRDky6XNE8Nh6VC/V94F9djVxYRZ2LGA8/N DvufTYVPTL9iL2qK33Yr/vN1miKJ3XoW19BDfk00bKOHEpHpXnZXfyfHWCh1poAyYR6k 2pHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=PwkUfVEUpuNuPQhP1EGP1aoJJ7AZ+QZ3dXxtAJ/skjo=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=McV4b1jg96t29ecnFDa65SWd6yN5v6dDj0+xjMC1PKb5H/P82h3Z1PCbwia0gUqixc 2t/Wa0ODaFBGnnI3WcDfuz15Fb1GDkrOiNSZUPghuNIrFlvArnwBZUU1V+gbhYD+AvtS z8K2D4GqzO46vwxxiZYV8PZqsYpg/LyrGaA2Wbo9rw0k3Mw2FBUrvYGVx+UPph6V0ISQ sNaY6MeKxRN6G1shldGixIk3e55/4pcbwJ+hSIDjVtIyQAf2RIcWtkgG6nPzQM5HJttV HJsQNiCyAiV1JexGX6o342WjyRRiRb2fZxM/nH0MOe+SYGT0EPW09dYo5DjxUqU/lstk AluQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f8-20020a056402354800b005455445041asi4361658edd.346.2023.11.14.09.21.30; Tue, 14 Nov 2023 09:21:30 -0800 (PST) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7C96568CD7D; Tue, 14 Nov 2023 19:21:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E3D6E68CD32 for ; Tue, 14 Nov 2023 19:20:55 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 072DEC0009 for ; Tue, 14 Nov 2023 17:20:54 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 14 Nov 2023 18:20:49 +0100 Message-Id: <20231114172051.13872-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231114172051.13872-1-michael@niedermayer.cc> References: <20231114172051.13872-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 4/6] avcodec/h264: keep track of which frames used gray references 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: V0myLJj7fEX+ Signed-off-by: Michael Niedermayer --- libavcodec/h264_picture.c | 1 + libavcodec/h264_slice.c | 19 ++++++++++++++++++- libavcodec/h264dec.c | 1 + libavcodec/h264dec.h | 4 ++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c index 691c61eea23..3234141dbd6 100644 --- a/libavcodec/h264_picture.c +++ b/libavcodec/h264_picture.c @@ -96,6 +96,7 @@ static void h264_copy_picture_params(H264Picture *dst, const H264Picture *src) dst->field_picture = src->field_picture; dst->reference = src->reference; dst->recovered = src->recovered; + dst->gray = src->gray; dst->invalid_gap = src->invalid_gap; dst->sei_recovery_frame_cnt = src->sei_recovery_frame_cnt; dst->mb_width = src->mb_width; diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 4861a2cabba..2c4ab89dae1 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -457,6 +457,7 @@ int ff_h264_update_thread_context(AVCodecContext *dst, h->poc.prev_frame_num = h->poc.frame_num; h->recovery_frame = h1->recovery_frame; + h->non_gray = h1->non_gray; return err; } @@ -1544,11 +1545,14 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl, if (ret < 0) return ret; h->short_ref[0]->poc = prev->poc + 2U; + h->short_ref[0]->gray = prev->gray; ff_thread_report_progress(&h->short_ref[0]->tf, INT_MAX, 0); if (h->short_ref[0]->field_picture) ff_thread_report_progress(&h->short_ref[0]->tf, INT_MAX, 1); - } else if (!h->frame_recovered && !h->avctx->hwaccel) + } else if (!h->frame_recovered && !h->avctx->hwaccel) { color_frame(h->short_ref[0]->f, c); + h->short_ref[0]->gray = 1; + } h->short_ref[0]->frame_num = h->poc.prev_frame_num; } } @@ -2007,6 +2011,19 @@ static int h264_slice_init(H264Context *h, H264SliceContext *sl, (sl->ref_list[j][i].reference & 3); } + if (sl->slice_type_nos == AV_PICTURE_TYPE_I) { + h->cur_pic_ptr->gray = 0; + h->non_gray = 1; + } else { + int gray = 0; + for (j = 0; j < sl->list_count; j++) { + for (i = 0; i < sl->ref_count[j]; i++) { + gray |= sl->ref_list[j][i].parent->gray; + } + } + h->cur_pic_ptr->gray = gray; + } + if (h->avctx->debug & FF_DEBUG_PICT_INFO) { av_log(h->avctx, AV_LOG_DEBUG, "slice:%d %c mb:%d %c%s%s frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index ef9e60bbf33..7ea55db75dd 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -492,6 +492,7 @@ static void h264_decode_flush(AVCodecContext *avctx) ff_h264_unref_picture(&h->cur_pic); h->mb_y = 0; + h->non_gray = 0; ff_h264_free_tables(h); h->context_initialized = 0; diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index ede51951727..366626c056c 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -154,6 +154,8 @@ typedef struct H264Picture { /// RefStruct reference; its pointee is shared between decoding threads. atomic_int *decode_error_flags; + + int gray; } H264Picture; typedef struct H264Ref { @@ -567,6 +569,8 @@ typedef struct H264Context { struct FFRefStructPool *ref_index_pool; struct FFRefStructPool *decode_error_flags_pool; int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1 + + int non_gray; ///< Did we encounter a intra frame after a gray gap frame } H264Context; extern const uint16_t ff_h264_mb_sizes[4];