From patchwork Sun Aug 25 17:45:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Plowman X-Patchwork-Id: 51142 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:b3c7:0:b0:48e:c0f8:d0de with SMTP id g7csp1410628vqt; Sun, 25 Aug 2024 11:10:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVROed2GnHzX9j+oCBMqJDBkCE0iyNm7BVvOdMKrQgzsoi3FvcPTA6S1Jjz5snQn97pIpT+xAzQq65Kgwk/U/3R@gmail.com X-Google-Smtp-Source: AGHT+IHIeS7VS1tViwT5quO2SqFndS6J53nW56kg6vNropjeOGMY6IDZnqI30R9GH/7/TKOSt5y9 X-Received: by 2002:a05:6512:10c6:b0:52e:fd7c:8b9b with SMTP id 2adb3069b0e04-534387bf0c6mr2748546e87.7.1724609405967; Sun, 25 Aug 2024 11:10:05 -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 2adb3069b0e04-5334ea2b4ccsi2909932e87.72.2024.08.25.11.10.05; Sun, 25 Aug 2024 11:10:05 -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=@frankplowman.com header.s=zmail header.b=MlaC7bUl; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B268768D9C8; Sun, 25 Aug 2024 20:50:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from sender-op-o11.zoho.eu (sender-op-o11.zoho.eu [136.143.169.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1B61168DA2C for ; Sun, 25 Aug 2024 20:50:35 +0300 (EEST) Delivered-To: post@frankplowman.com ARC-Seal: i=1; a=rsa-sha256; t=1724608233; cv=none; d=zohomail.eu; s=zohoarc; b=hdMqDd+yhNXJKV6dk8ECNYtuRiO9d+zPswZ98NXvSidkwih3Eyoo7KP2KySf+YXZWJd6GDFeMx4FyM78SIDb+0da9Y6Z9n3O1lR5qpQr47Aavv+Cf3kLAdxb73Wp+xH0Fyiri861NFy+ymRi/uybOVxLW+SY39I8dMrKs+FWIeY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1724608233; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=2mVN03LB8cxMgND9AUjylx6J208MV2PYz7YmFVa8EG8=; b=bEcybW9cQDYVoA1iUFSk80ZKdLXy+tZSeE1G396vF3R9UM82UVSRv7QyAHESgjLfhypp48UprT3sxJEXaDqgYTJiwS6aHft+q/pxJ2rmuSHAoJyV5L1D/YSHRjZ2FSs3XG9Rod3miigkiebyes+v1sj4qvPiUWY8kCUZqgB3HAs= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=frankplowman.com; spf=pass smtp.mailfrom=post@frankplowman.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1724608233; s=zmail; d=frankplowman.com; i=post@frankplowman.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=2mVN03LB8cxMgND9AUjylx6J208MV2PYz7YmFVa8EG8=; b=MlaC7bUlVaxDkRG7zRAFqBNw9VDyvcQcPz0bHbUXkBNaciT42mvPZ/4Z4SsP2qmb +2Wqjjo9vrt2avwHVB3tlswBXcIFgz5HighaFhwyVffmxMOIyLr5Os5vIY97Lqlan4R qzLVVeyOxC2iQO6m/6JCZi0VhXa6dFlg8PMK3Jck= Received: by mx.zoho.eu with SMTPS id 1724608232638806.0009650138464; Sun, 25 Aug 2024 19:50:32 +0200 (CEST) From: Frank Plowman To: ffmpeg-devel@ffmpeg.org Date: Sun, 25 Aug 2024 18:45:36 +0100 Message-ID: <20240825175027.40160-1-post@frankplowman.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-ZohoMailClient: External Subject: [FFmpeg-devel] [PATCH v2] lavc/vvc: Validate explicit subpic locations 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: Frank Plowman , nuomi2021@gmail.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Ttifs1YkQMbu Implement the missing requirements from H.266 (V3) p. 106 on the position and size of subpictures whose dimensions are provided explicitly. Signed-off-by: Frank Plowman --- Changes since v1 (20240824092827.68912-1-post@frankplowman.com): * Use temporary variables and AV_CEIL_RSHIFT to make bound calculations more readable. * Fix bounds on size. The calculated values are minimums, not maximums as in v1. Additionally, fix an integer overflow in the bound calculations. libavcodec/cbs_h266_syntax_template.c | 49 +++++++++++++++++++++------ 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c index 9c37996947..a8f5af04d0 100644 --- a/libavcodec/cbs_h266_syntax_template.c +++ b/libavcodec/cbs_h266_syntax_template.c @@ -1061,7 +1061,7 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, unsigned int ctb_log2_size_y, min_cb_log2_size_y, min_qt_log2_size_intra_y, min_qt_log2_size_inter_y, ctb_size_y, max_num_merge_cand, tmp_width_val, tmp_height_val; - uint8_t qp_bd_offset; + uint8_t qp_bd_offset, sub_width_c, sub_height_c; static const uint8_t h266_sub_width_c[] = { 1, 2, 2, 1 @@ -1089,6 +1089,9 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, u(3, sps_max_sublayers_minus1, 0, VVC_MAX_SUBLAYERS - 1); u(2, sps_chroma_format_idc, 0, 3); + sub_width_c = h266_sub_width_c[current->sps_chroma_format_idc]; + sub_height_c = h266_sub_height_c[current->sps_chroma_format_idc]; + u(2, sps_log2_ctu_size_minus5, 0, 3); ctb_log2_size_y = current->sps_log2_ctu_size_minus5 + 5; ctb_size_y = 1 << ctb_log2_size_y; @@ -1110,8 +1113,6 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, flag(sps_conformance_window_flag); if (current->sps_conformance_window_flag) { - uint8_t sub_width_c = h266_sub_width_c[current->sps_chroma_format_idc]; - uint8_t sub_height_c = h266_sub_height_c[current->sps_chroma_format_idc]; uint16_t width = current->sps_pic_width_max_in_luma_samples / sub_width_c; uint16_t height = current->sps_pic_height_max_in_luma_samples / sub_height_c; ue(sps_conf_win_left_offset, 0, width); @@ -1160,19 +1161,37 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, } for (i = 1; i <= current->sps_num_subpics_minus1; i++) { if (!current->sps_subpic_same_size_flag) { - if (current->sps_pic_width_max_in_luma_samples > ctb_size_y) - ubs(wlen, sps_subpic_ctu_top_left_x[i], 1, i); - else + if (current->sps_pic_width_max_in_luma_samples > ctb_size_y) { + const unsigned int win_right_edge = + current->sps_pic_width_max_in_luma_samples + - current->sps_conf_win_right_offset * sub_width_c; + us(wlen, sps_subpic_ctu_top_left_x[i], 0, + AV_CEIL_RSHIFT(win_right_edge, ctb_log2_size_y) - 1, + 1, i); + } else infer(sps_subpic_ctu_top_left_x[i], 0); if (current->sps_pic_height_max_in_luma_samples > - ctb_size_y) - ubs(hlen, sps_subpic_ctu_top_left_y[i], 1, i); - else + ctb_size_y) { + const unsigned int win_bottom_edge = + current->sps_pic_height_max_in_luma_samples + - current->sps_conf_win_bottom_offset * sub_height_c; + us(hlen, sps_subpic_ctu_top_left_y[i], 0, + AV_CEIL_RSHIFT(win_bottom_edge, ctb_log2_size_y) - 1, + 1, i); + } else infer(sps_subpic_ctu_top_left_y[i], 0); if (i < current->sps_num_subpics_minus1 && current->sps_pic_width_max_in_luma_samples > ctb_size_y) { - ubs(wlen, sps_subpic_width_minus1[i], 1, i); + const unsigned int win_left_edge = + current->sps_conf_win_left_offset * sub_width_c; + const unsigned int win_left_edge_ctus = + AV_CEIL_RSHIFT(win_left_edge, ctb_log2_size_y); + us(wlen, sps_subpic_width_minus1[i], + win_left_edge_ctus > current->sps_subpic_ctu_top_left_x[i] + ? win_left_edge_ctus - current->sps_subpic_ctu_top_left_x[i] + : 0, + MAX_UINT_BITS(wlen), 1, i); } else { infer(sps_subpic_width_minus1[i], tmp_width_val - @@ -1181,7 +1200,15 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, if (i < current->sps_num_subpics_minus1 && current->sps_pic_height_max_in_luma_samples > ctb_size_y) { - ubs(hlen, sps_subpic_height_minus1[i], 1, i); + const unsigned int win_top_edge = + current->sps_conf_win_top_offset * sub_height_c; + const unsigned int win_top_edge_ctus = + AV_CEIL_RSHIFT(win_top_edge, ctb_log2_size_y); + us(hlen, sps_subpic_height_minus1[i], + win_top_edge_ctus > current->sps_subpic_ctu_top_left_y[i] + ? win_top_edge_ctus - current->sps_subpic_ctu_top_left_y[i] + : 0, + MAX_UINT_BITS(wlen), 1, i); } else { infer(sps_subpic_height_minus1[i], tmp_height_val -