From patchwork Sun Aug 20 22:41:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 4766 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.37.132 with SMTP id g126csp2343342jag; Sun, 20 Aug 2017 15:42:52 -0700 (PDT) X-Received: by 10.223.200.69 with SMTP id e5mr10812061wrh.261.1503268971936; Sun, 20 Aug 2017 15:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503268971; cv=none; d=google.com; s=arc-20160816; b=hsHD60mI/0dKzNrIPZ3wK5eg2un6F4Djtyq+FlliHVDWIT8rmGg6LYRe7RPg2yGrJm W4139Y6aJECdx3K2TpMZk0Suba78Ypv4cS9zqcrFSYiDlSSGWMyg3nsvHGBKbS8e1Esu vKJPYxcICCt7Jlv0KlFF0zKety2d6Whg0vQqJfQ7wy5M4QaG2J1t9pGA1jt865l/GDbN rujuZtwTTkiVoE0cPIVXXMd6/IRePhCEWj5Wv4KVCcqVxZeMqmhLQuZnNzNIvqphEKPW nQVkq2tZeCT/EOUy99PLCasV8U1np8rb2f14cU+pq8ykqmtM+WbEfArQY5ii5HXeWuPD A5tQ== 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=3GWwuX1kRq3ByLinoLaYXjW9GeF16VqlldRZfRlGCLg=; b=ja2OfgRF9ZuJg84+nMr9yiM5UzwheZo4cG6SXNzt0X2xpSd/QC7oi4CWnavCawbxQH JC14fMHt7D+63ZBfRgyWPnmhZt78DmODORVeFTQMtgkv49BisrMPZUhZdQ+v3C7CzP5o tFZ20E0Pa2SxUEwgbUIoZsFC7wBcYnUv664GqULMe/dN9k0GcLSFxyYos6EAVhLJwz+x rNuLk4mPq97WQmMVu7u8Oor9C/z2Xzb4Sys8qXpxVeaQVG9VaTOu9bbb9hzamgyqV9T7 XTrs0DKj1copQZyO4CIQQVceS5KTIlXlj/IWPp06li9P4tg7od8G2ZrSTtdNMQe9InjS yYSw== 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=ppaprXfp; 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 v194si3802349wmd.176.2017.08.20.15.42.51; Sun, 20 Aug 2017 15:42:51 -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=ppaprXfp; 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 72D666882E3; Mon, 21 Aug 2017 01:42:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8DE2E680A44 for ; Mon, 21 Aug 2017 01:41:56 +0300 (EEST) Received: by mail-wr0-f180.google.com with SMTP id f8so48166154wrf.3 for ; Sun, 20 Aug 2017 15:42:03 -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=2LPOScOvYoTLVxgg9klAM3WVJT4TjFD1mThtEP1pmY4=; b=ppaprXfp6ipZ4oGEHXsMBr2WDQyyn52ugZHDUIPS6zH0+ml6iS71S5L9yyXE/TsN0l TnCJGferP6YzR39/y6PQAQtyGcsFy7cyjAivpwDVwmIR42WkJ6SjmGHbaDgkU1ShuApr VDtqjrxRXBhCb8hTpPyzVPB6DTwUrlOXZ/jgyUFMFUbh2Vsp54j/qyYXzun8wEsMQrXl bZQgVWM6Yw6lGGYWrrq7cxfyszig/E0ZvtBmLXSMaVK5BFkwssiIbbTJu5FnsgJlywwQ ZW9amUp8fm1uBeQmTjNYwB3HsAWe70T0T222+4ftyt3JHWzlcCTCVq858CqdCvKOQtqR +oYA== 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=2LPOScOvYoTLVxgg9klAM3WVJT4TjFD1mThtEP1pmY4=; b=FPOdogzAgWnGEtghPCGoU3ya8YWPcv5qRb8iDeX2cax1PoNiLZno81U4Y2DkVSl9Ma UX8/VF2fsGapfGaSOoDBNUXdPUhe3OoczLDwUIx8nrgyjV9k/Y1j3MmgrsGDQGC/RwCR xWSFnyjt6oJ0rc+dUqy+Sx4CXym9wWN/d0BgtDrbhkqTECam7E58/rBVi0dU1Xe0jH0r IBd0auBsJGtCAQljHi/+YaL7SqZqF9RJFi2+oWj+lTs1z4q9JXmjXXrTO0xIonMIiRkp 3hjx51IiyffKpbJkduBt0dBqc2AYpUlP2myYoWMpwrlDv7gnbC9nkr9lhEyBG4B/S8xq KPMg== X-Gm-Message-State: AHYfb5j0VtkeL6W7Hjdg0EYkJAKSEnsnxyeQKayFDuPPxwWFlitD6Wr1 aHkT+HeDmdTD+WS10jc= X-Received: by 10.28.20.18 with SMTP id 18mr5065821wmu.153.1503268922670; Sun, 20 Aug 2017 15:42:02 -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 f9sm5391116wmf.18.2017.08.20.15.42.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Aug 2017 15:42:02 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Aug 2017 23:41:32 +0100 Message-Id: <20170820224146.21289-5-sw@jkqxz.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170820224146.21289-1-sw@jkqxz.net> References: <20170820224146.21289-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH 04/18] 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 21dbaf85a5..014b68e6db 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -1027,7 +1027,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 78f9dd876e..7f71a71ef0 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++) {