From patchwork Sun Oct 8 20:01:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 5463 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp1904659jah; Sun, 8 Oct 2017 13:02:28 -0700 (PDT) X-Received: by 10.28.0.7 with SMTP id 7mr6202484wma.109.1507492948202; Sun, 08 Oct 2017 13:02:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507492948; cv=none; d=google.com; s=arc-20160816; b=m2FFK1IZIylRw8dQWTwjAvHUGua411bwGMmO6WUXjszASVlQg7mdUiK1h+sygkAbN3 lDxXQ8gfLHz0e8crGu5bXeJOvulXqLZIcVxRYzHaFn9ZBfANebrIBLgsmnR9cg2VdHr/ dSVQftd/dF7QQshnD80G6Kj6xnRnqBOJld1MUHuFifErQoXdDfyX/8mFmj/LsyNHwlQ3 NBhzNgZW6VLhddnhenq8/G3zOXIejJ7lBI080t3l7ineqfu+eLQ+d0UHHIvC7ucWbafS 5PAbrOUgPTFrRXohNu4aYpjITEOGm0LWp9TZKxfvKmEhMdXKCo7syivCUOmzYKgGZGOa BQhg== 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=CA6u6a5a77qWS4m4S7mlBWBPQJt0lel7f/3Iq4wO8hs=; b=J92IZGicUyJG/XV3Kc5WLfwXmFxUgLw7eyInuP7vBucl+WBnr8H71DXWWLn/DbOnSx HQw2BhEFEnALfGGfRH6RzBMSklz4QwCPPqsCbDc3mz69Zl4Q1lZduqaK1hGOe9jlvSbO ynQBznlWSN7a1HYnFAPnjVZZ89IZjMRGDuG+DIqdiJnGfPtbe1Aa6uSFtjpjYi/v/vxu pHduzHMtJ9pIB0HVWsduFkenGIYQpGYuaZpDR6kNqT6Rb8rQ2TuaMnoXxSYfEOF+lsA8 5Q69K/q0OXjs1Gxvg2F9lcRSnkegeouyMRhRZ4NhQsDVzCbXkVyvM1IcY3fCl0ToXOB8 TpBw== 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=nH5E+RUf; 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 b18si5814812wrf.215.2017.10.08.13.02.27; Sun, 08 Oct 2017 13:02:28 -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=nH5E+RUf; 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 CDCE8689D2F; Sun, 8 Oct 2017 23:02:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 99BCF689B97 for ; Sun, 8 Oct 2017 23:01:58 +0300 (EEST) Received: by mail-wm0-f45.google.com with SMTP id i124so17608856wmf.3 for ; Sun, 08 Oct 2017 13:02:00 -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=6s6iuBOPEm4GzFJJXkUxsZPzpoyIcYx8y5QDqnBm6sA=; b=nH5E+RUfweGdi2xu3Y3f75LSaeMwqqHrUf423d+Aahy1oyQBatLSyC/sEMy8QiyxBW 4a4pGRfL/ZELaLCDaeqAR2kWigPB4YDmlIVpqpWLUL5KoSe+DC3AvLM9aWDlTm/GTZ7u g4KqTFTTy0/e02jpNARs34GJPgufcPfp0O/4JIBGlSv9GG18LorBtDYjCfhY9WwfSoi7 QKw9GFHf91vWUjzD9YZRC2/0s1+I1O36gRdoCJIeHK5iknV14gimXb9a2fSnZ9WlVL9X JJyEWfe9RGTO2Q40jgDzNCL45zXaBp+RQsx1D2VdF+nMo/TKkvp5rDpTtthgl1KyAIuB hqhA== 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=6s6iuBOPEm4GzFJJXkUxsZPzpoyIcYx8y5QDqnBm6sA=; b=TI8UmU0UoaP0zFvxlVpr6gzVuXLlIn3BqYWfafPmq1pRZYKl0G+/jjV5bDo54lxRrJ Xn/H7ZI1sLMnEcnwJNBUr8UhW3bFvGBYsjjWGhYsAMM9gooZno8ejP5yopL9+FEygHvS VItcYmnpv2ZY8YNCUq6Qs1zQcC+IwF4Zd4pvcwsfQoh1xiN5mf7xuEE7/9m0R6MO4a9U VBBIurl/KHfH7cKtDSDrnf0Rng0OOe1xmStlDabbD533Cf9bal4I5ytFFiisZdKWdW0y t847HNLGcQ+l+9SjHgSLzpRksEupnGHjqBx7dqnpr9JfI8l2kmvR83ZCL9lEaFY559WK mhhQ== X-Gm-Message-State: AMCzsaXNurTpT6nrcLJlQXq7tlaHFD6QU2EIW+i29+cW8gPnhmTAHyEy z/eZR5w54bHqjOkasmNsT0Azu276 X-Google-Smtp-Source: AOwi7QBXGUDIulF3OxCRwzp0H4HBCYmrCaoUtwonSNhIEttDkDD41RyZEed+gqgWqFERmIM7ZFE/jQ== X-Received: by 10.223.199.18 with SMTP id k18mr8154589wrg.145.1507492919633; Sun, 08 Oct 2017 13:01:59 -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 x49sm2897856wrb.25.2017.10.08.13.01.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Oct 2017 13:01:58 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Sun, 8 Oct 2017 21:01:36 +0100 Message-Id: <20171008200154.4873-3-sw@jkqxz.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171008200154.4873-1-sw@jkqxz.net> References: <20171008200154.4873-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 902917d4dd..72d02c8372 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -1061,7 +1061,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 76f8eb31e6..477ee4299a 100644 --- a/libavcodec/hevc_ps.h +++ b/libavcodec/hevc_ps.h @@ -254,14 +254,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++) {