From patchwork Tue Sep 12 23:43:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 5107 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.36.26 with SMTP id f26csp295741jaa; Tue, 12 Sep 2017 16:44:42 -0700 (PDT) X-Received: by 10.28.19.76 with SMTP id 73mr872635wmt.122.1505259882109; Tue, 12 Sep 2017 16:44:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505259882; cv=none; d=google.com; s=arc-20160816; b=eCA5dvBzz48TnUPVmBDyrfMZrOvTvuOz9Zo9ZNpjPlmDa5l6P3drWwh5mPkiko9sXt cgjFa5gdRMX1cAOjxzRi8hBfx0QPm4uiUaLWQOTkDLRIkU74GTpoLu8/WMkCpG62Zw85 YU8uLDC6H3zxU7ItVbcO4ZUYysyNZjEZKuLtNZ/O8Twh4bdru9aM3gPTJbmQ8aPbbwb5 2qTkLSt0hNWw9D2z0KlOfv1JEmEZnhCJY8PW+GHaKG4eZR1PtUTZvfQd1wKB+iQ3XDo+ 742jFfCuZuhRP4GgHI5WtFQX9hPCfqP74n4kVnNb4VsVz4M1LUPcs7VHw/hkxegitlSX milw== 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:dkim-signature:delivered-to:arc-authentication-results; bh=0SlZs6+YaybebT04VESIixyIPKw0vfSBVZde5NQn2EQ=; b=ZwyRORxy6xuLA7dFYsgB2qJIzuOIzi5cWNBvlWCHrdehpbQPUPMMo/hPV/k6JtgnVN 86xl0g3Yjx0Wi+tVxjQaJvYO+zEM3ZbbsybR84WC8fnedZKA6+dFSI11nEDKokhLo4Wo zGLnGC7rfXzEtl7JgwOEN5auA2YweHlTHOKSyb/GERzE3aIuDwmSGMwxX2RTUaMavRdF zpuAwvysdagqSt2r8oza1+6x9148U104Nm1KOq03BmoiU8ZzacNKset5N9WuJTzTtvdv zm11XOnduUJqLzG6SfBMgi9Ri91+GE60GcrODArEeHqNxtUSOyQdZD/OifZ5A5kE0qIC ZNIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=L0jEELx1; 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 o7si9848118wre.228.2017.09.12.16.44.41; Tue, 12 Sep 2017 16:44:42 -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=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=L0jEELx1; 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 17B36689D2D; Wed, 13 Sep 2017 02:44:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 56211689C92 for ; Wed, 13 Sep 2017 02:44:10 +0300 (EEST) Received: by mail-wm0-f43.google.com with SMTP id g206so1773319wme.0 for ; Tue, 12 Sep 2017 16:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=vSJqxiXXgTj9FDUnLJ2jR4AYB7EOW1xyqStv1ucOGU0=; b=L0jEELx1bSyLx82uJXA39BLgt3SLr/ejgPUsuaW3OPsErIgXQ3W//k8w4gHOA6wwa8 htekN0TyNviOxDPSQtjAze49dNgJqtsQtsQr71xNDdUhZ0BIl/a97EtUGUSUt/RdwKJv v3aY/rdQdA0JJYfLgvQLdVca96vGXPoacmQfrBxaQO58DmHOIW0H6MmgslW5IuO4nZnn bV4+fzKcch/13Hnm7G0Wx5sqyGhBlGFPJpgahVX/47JJJqNzpDSc6qxQzgM9F1ljpivG sy2PiyPtb10ddNmONu4DrL6vaTTa0ZQooEzAeABld/8WeaV0LgoULr9/7+yWDOfrt6If 4GVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=vSJqxiXXgTj9FDUnLJ2jR4AYB7EOW1xyqStv1ucOGU0=; b=MqXl8m8GsblEgZ9On04VwyUd7oZnx6ONTCsmsc9GziBwgp0AJLnX4pOEAX9Y2sNjAF 72ptWGtbHkeZVQvyynBLwAPi7bx8alT5EBrcIQ/pSKAFLLyho+V5tYdYsvdi24zEa7PV R53Ye77FJZ65P2B2zeIqLCwMnFcoyGquPQ0ZuLyBVW3sb1AuHllhjyjr824BMYIki58J aX8St516mgp1e1SGxNi9jaCtWDlvfRvtJH/+nhlQhte/EB9Wlrt5eiQN6bdP/qLLy7MN t/v8Gs+chhEeuyWJdTOY0gw42m44ffrmaNNc5w0kJnLcIEhJKW/Ao8HKNuU1ImZW5M8x XSOw== X-Gm-Message-State: AHPjjUiSkObN3lFM2ArhSadv8qw85q0C02H4RKATj9NIeoGXi90l4S1E XL1zXAJ4Y5kLHCzcRr4= X-Google-Smtp-Source: AOwi7QA8mlcxQDKbcsPYThAC6ON5cNYFd93MA2iiN6sD3IJnCK8/1chqlZL0GrGycwk07QqogfdwgA== X-Received: by 10.28.174.80 with SMTP id x77mr942343wme.83.1505259855673; Tue, 12 Sep 2017 16:44:15 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id p193sm4378138wmg.37.2017.09.12.16.44.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Sep 2017 16:44:15 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Sep 2017 00:43:52 +0100 Message-Id: <20170912234410.14093-3-sw@jkqxz.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170912234410.14093-1-sw@jkqxz.net> References: <20170912234410.14093-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH 02/20] hevc: Improve stream constraint values in common header X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" Add comments to describe the sources of the constraint values expressed here, and add some more related values which will be used in following patches. Fix the incorrect values for SPS and PPS count (they are not the same as those used for H.264), and remove HEVC_MAX_CU_SIZE because it is not used anywhere. (cherry picked from commit b88da98b34809dedf8882d43ed543632ed233538) --- libavcodec/hevc.h | 65 ++++++++++++++++++++++++++++++++++++++++++---------- libavcodec/hevc_ps.c | 2 +- libavcodec/hevc_ps.h | 6 ++--- libavformat/hevc.c | 6 ++--- 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h index f0fb919a7f..2f20db8285 100644 --- a/libavcodec/hevc.h +++ b/libavcodec/hevc.h @@ -74,19 +74,60 @@ enum HEVCSliceType { HEVC_SLICE_I = 2, }; -/** - * 7.4.2.1 - */ -#define HEVC_MAX_SUB_LAYERS 7 -#define HEVC_MAX_VPS_COUNT 16 -#define HEVC_MAX_SPS_COUNT 32 -#define HEVC_MAX_PPS_COUNT 256 -#define HEVC_MAX_SHORT_TERM_RPS_COUNT 64 -#define HEVC_MAX_CU_SIZE 128 +enum { + // 7.4.3.1: vps_max_layers_minus1 is in [0, 62]. + HEVC_MAX_LAYERS = 63, + // 7.4.3.1: vps_max_sub_layers_minus1 is in [0, 6]. + HEVC_MAX_SUB_LAYERS = 7, + // 7.4.3.1: vps_num_layer_sets_minus1 is in [0, 1023]. + HEVC_MAX_LAYER_SETS = 1024, + + // 7.4.2.1: vps_video_parameter_set_id is u(4). + HEVC_MAX_VPS_COUNT = 16, + // 7.4.3.2.1: sps_seq_parameter_set_id is in [0, 15]. + HEVC_MAX_SPS_COUNT = 16, + // 7.4.3.3.1: pps_pic_parameter_set_id is in [0, 63]. + HEVC_MAX_PPS_COUNT = 64, + + // A.4.2: MaxDpbSize is bounded above by 16. + HEVC_MAX_DPB_SIZE = 16, + // 7.4.3.1: vps_max_dec_pic_buffering_minus1[i] is in [0, MaxDpbSize - 1]. + HEVC_MAX_REFS = HEVC_MAX_DPB_SIZE, + + // 7.4.3.2.1: num_short_term_ref_pic_sets is in [0, 64]. + HEVC_MAX_SHORT_TERM_REF_PIC_SETS = 64, + // 7.4.3.2.1: num_long_term_ref_pics_sps is in [0, 32]. + HEVC_MAX_LONG_TERM_REF_PICS = 32, -#define HEVC_MAX_REFS 16 -#define HEVC_MAX_DPB_SIZE 16 // A.4.1 + // A.3: all profiles require that CtbLog2SizeY is in [4, 6]. + HEVC_MIN_LOG2_CTB_SIZE = 4, + HEVC_MAX_LOG2_CTB_SIZE = 6, + + // E.3.2: cpb_cnt_minus1[i] is in [0, 31]. + HEVC_MAX_CPB_CNT = 32, + + // A.4.1: in table A.6 the highest level allows a MaxLumaPs of 35 651 584. + HEVC_MAX_LUMA_PS = 35651584, + // A.4.1: pic_width_in_luma_samples and pic_height_in_luma_samples are + // constrained to be not greater than sqrt(MaxLumaPs * 8). Hence height/ + // width are bounded above by sqrt(8 * 35651584) = 16888.2 samples. + HEVC_MAX_WIDTH = 16888, + HEVC_MAX_HEIGHT = 16888, + + // A.4.1: table A.6 allows at most 22 tile rows for any level. + HEVC_MAX_TILE_ROWS = 22, + // A.4.1: table A.6 allows at most 20 tile columns for any level. + HEVC_MAX_TILE_COLUMNS = 20, + + // 7.4.7.1: in the worst case (tiles_enabled_flag and + // entropy_coding_sync_enabled_flag are both set), entry points can be + // placed at the beginning of every Ctb row in every tile, giving an + // upper bound of (num_tile_columns_minus1 + 1) * PicHeightInCtbsY - 1. + // Only a stream with very high resolution and perverse parameters could + // get near that, though, so set a lower limit here with the maximum + // possible value for 4K video (at most 135 16x16 Ctb rows). + HEVC_MAX_ENTRY_POINT_OFFSETS = HEVC_MAX_TILE_COLUMNS * 135, +}; -#define HEVC_MAX_LOG2_CTB_SIZE 6 #endif /* AVCODEC_HEVC_H */ diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index 500fee03d8..b2b6f343eb 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -1060,7 +1060,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, } sps->nb_st_rps = get_ue_golomb_long(gb); - if (sps->nb_st_rps > HEVC_MAX_SHORT_TERM_RPS_COUNT) { + if (sps->nb_st_rps > HEVC_MAX_SHORT_TERM_REF_PIC_SETS) { av_log(avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n", sps->nb_st_rps); return AVERROR_INVALIDDATA; diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h index 4e6c3bc849..2507c34098 100644 --- a/libavcodec/hevc_ps.h +++ b/libavcodec/hevc_ps.h @@ -252,14 +252,14 @@ typedef struct HEVCSPS { ScalingList scaling_list; unsigned int nb_st_rps; - ShortTermRPS st_rps[HEVC_MAX_SHORT_TERM_RPS_COUNT]; + ShortTermRPS st_rps[HEVC_MAX_SHORT_TERM_REF_PIC_SETS]; uint8_t amp_enabled_flag; uint8_t sao_enabled; uint8_t long_term_ref_pics_present_flag; - uint16_t lt_ref_pic_poc_lsb_sps[32]; - uint8_t used_by_curr_pic_lt_sps_flag[32]; + uint16_t lt_ref_pic_poc_lsb_sps[HEVC_MAX_LONG_TERM_REF_PICS]; + uint8_t used_by_curr_pic_lt_sps_flag[HEVC_MAX_LONG_TERM_REF_PICS]; uint8_t num_long_term_ref_pics_sps; struct { diff --git a/libavformat/hevc.c b/libavformat/hevc.c index 1a2d6cdd2b..e45d2c08d2 100644 --- a/libavformat/hevc.c +++ b/libavformat/hevc.c @@ -417,7 +417,7 @@ static void skip_scaling_list_data(GetBitContext *gb) static int parse_rps(GetBitContext *gb, unsigned int rps_idx, unsigned int num_rps, - unsigned int num_delta_pocs[HEVC_MAX_SHORT_TERM_RPS_COUNT]) + unsigned int num_delta_pocs[HEVC_MAX_SHORT_TERM_REF_PIC_SETS]) { unsigned int i; @@ -486,7 +486,7 @@ static int hvcc_parse_sps(GetBitContext *gb, HEVCDecoderConfigurationRecord *hvcc) { unsigned int i, sps_max_sub_layers_minus1, log2_max_pic_order_cnt_lsb_minus4; - unsigned int num_short_term_ref_pic_sets, num_delta_pocs[HEVC_MAX_SHORT_TERM_RPS_COUNT]; + unsigned int num_short_term_ref_pic_sets, num_delta_pocs[HEVC_MAX_SHORT_TERM_REF_PIC_SETS]; skip_bits(gb, 4); // sps_video_parameter_set_id @@ -556,7 +556,7 @@ static int hvcc_parse_sps(GetBitContext *gb, } num_short_term_ref_pic_sets = get_ue_golomb_long(gb); - if (num_short_term_ref_pic_sets > HEVC_MAX_SHORT_TERM_RPS_COUNT) + if (num_short_term_ref_pic_sets > HEVC_MAX_SHORT_TERM_REF_PIC_SETS) return AVERROR_INVALIDDATA; for (i = 0; i < num_short_term_ref_pic_sets; i++) {