From patchwork Wed Sep 26 23:17:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 10502 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:1286:0:0:0:0:0 with SMTP id 6-v6csp1293073jap; Wed, 26 Sep 2018 16:17:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV63PTAFuctemleMzclruYjYFzkjlnnrKc8biz9K0BmoIodubd9J2PLYmgyJ4oic68HWaSIm4 X-Received: by 2002:a1c:7015:: with SMTP id l21-v6mr5668645wmc.81.1538003863373; Wed, 26 Sep 2018 16:17:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538003863; cv=none; d=google.com; s=arc-20160816; b=T//DJBJ16MUqfSFRvHlR4/3H0jrxxc0xYpP3HaaPSutcGREjZmmMM+38zpYw5UO8P7 sDOs2CtMtycbPXecZvlmuQccbJdPMEAdpdMjI7STgggewDd5Ro82csSMfjye+wxw/vRN l9MjDZB3EH/8AUdhies3iik5+O64vGlHEuAKgRD2dI9d0HqGM7GFKWuf7A9GmYeZh6nn ws/EhbZHC7XxRjGB28Daj1zjitsu9eJxxfC8RgMC828iXwvbOpXWowcD/SBPbFcQL0Kp 0CrDYVBVOZ8W++pYpaSMeQPSZPQwHsnxeWoNJX1LcVjwXbc83/QKLm5QkCnFxSx28hhM pVCw== 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; bh=bebfohWQUJCdyKgKGe/TaleZs/oQb+xR2mJ7kTJ30ps=; b=jAbZr7rOK23OlG8iA5dyIobnXMtPFGu7lwgVHpl+j2Ap+ZlmX4IZ0A1VciCFizUvVB hhAZX0UmGEK5/QiqmpymSQQ9+Z7KkSFDH5jO0ApY/ZArAkd5FDQlEXGj30JBzn5t7x6w eJTKcoha5m118sVfuDhcSR39nniYnagrMihLj/Bz9XP3Z7Ye+X5TG8TkARqygV9BaD0x wsFVFmSev849X1TQwcFi3Hst3rZSpP7w+55lAZDgdJ0YFPfsx6OYxCW8hdrwtr9Sv52g Mhy4C0Sw5Bb1Z80+gcJZjd0dg/BlDkcYLo6yl7PhaK/PN6JHp/RYor9b5toFzMspUJwP gbjQ== 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=r0pTAYBt; 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 141-v6si699335wml.12.2018.09.26.16.17.43; Wed, 26 Sep 2018 16:17:43 -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=r0pTAYBt; 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 4856D689FFB; Thu, 27 Sep 2018 02:17:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0DE4B6899D2 for ; Thu, 27 Sep 2018 02:17:09 +0300 (EEST) Received: by mail-wr1-f45.google.com with SMTP id m16so541582wrx.12 for ; Wed, 26 Sep 2018 16:17:25 -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=mtVtI3Mksq8hofxQM6FHvtkOoHNdSzxJ3AxggrBRYnE=; b=r0pTAYBtpags39ZXzGLvvxZoSqFGZ+0CL1tZjvujDSpnBDZG7n01hI3cVA7zFD3wdE e6mowDe2LAiY0tmOxR7KIe27ZwwkjifGT6H0lqrP26VS4EKrAbf229pgZg7bP9Owm2Pu eQ8dbxU8PcMFveoNIQU1kByyHCR8NWh1eLZ26jHD/4vVQRkEnDD4NcPHW5EA1X9F7bi8 f/GU/nuMCufEI1K00HgyD/rPnIs0aVlfHYQ8wnffqWAwwDiV7a9bGYjLkulp8+Rq9vaj XZdJ7W1hrHOlZT8s65xf/1BalcE2rIKF9KELtPvP0m2n85AY+L/FgQDub8baqGgiM5Lh QdiA== 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=mtVtI3Mksq8hofxQM6FHvtkOoHNdSzxJ3AxggrBRYnE=; b=PZl+FduE80mLK/y53OWexPyfZ2DzH8XCm2eKiBpp0QtrCbUwSJ2aieb2j57bsWtPMp OX3OE7HhZTu2yN1Y4iT8lmzNK6LlNii9VdOr7KayAW3TtGrtd4cpQhuXlBeXPDTO/G9d XK3THh5aISQDA/OxGntJy46jgZU+58iy5n64ju+L5X406LosYtf1lYDiaHo7734GUfsg lg9/F4oYcv6JOZYXUTF6qx9BPzQNPZ8CpDqvrVxYIifTfxzINzAv9D4azMA6IBfn1Qlq uYQb33VvwOJKomMEGoZubpSDb1VNThFaZba47kVuAdhIwzZyaSrGWJk4TWeCTLlZ+mUl HRwg== X-Gm-Message-State: ABuFfoi0o2FETezP4f52p3i2q4RYtU88Esq+gSLATbfALU4+3sxRlfA+ lBHjOq8zdzCRWnAlLpMstsChkSeVOpA= X-Received: by 2002:adf:9464:: with SMTP id 91-v6mr6196253wrq.200.1538003844931; Wed, 26 Sep 2018 16:17:24 -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 o23-v6sm484449wmh.13.2018.09.26.16.17.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Sep 2018 16:17:24 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Thu, 27 Sep 2018 00:17:05 +0100 Message-Id: <20180926231707.6723-2-sw@jkqxz.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180926231707.6723-1-sw@jkqxz.net> References: <20180926231707.6723-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH 2/4] lavc/h265_profile_level: Fix DPB size calculation 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" The maxDpbPicBuf value which is used in the DPB size calculation depends on the profile (it's usually 6, but 7 for screen-extended profiles). --- libavcodec/h265_profile_level.c | 86 ++++++++++++++++----------------- libavcodec/h265_profile_level.h | 1 + 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/libavcodec/h265_profile_level.c b/libavcodec/h265_profile_level.c index 6604ca254d..692252bb4d 100644 --- a/libavcodec/h265_profile_level.c +++ b/libavcodec/h265_profile_level.c @@ -43,76 +43,76 @@ static const H265ProfileDescriptor h265_profiles[] = { // profile_idc 8bit one-picture // HT-profile | 422chroma | lower-bit-rate // | 14bit | | 420chroma | | CpbVclFactor MinCrScaleFactor - // | | 12bit | | | monochrome| | CpbNalFactor | + // | | 12bit | | | monochrome| | CpbNalFactor | maxDpbPicBuf // | | | 10bit | | | intra | | | FormatCapabilityFactor - { "Monochrome", // | | | | | | | | | | - 4, 0, 2, 1, 1, 1, 1, 1, 1, 0, 0, 1, 667, 733, 1.000, 1.0 }, + { "Monochrome", // | | | | | | | | | | | + 4, 0, 2, 1, 1, 1, 1, 1, 1, 0, 0, 1, 667, 733, 1.000, 1.0, 6 }, { "Monochrome 12", - 4, 0, 2, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1000, 1100, 1.500, 1.0 }, + 4, 0, 2, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1000, 1100, 1.500, 1.0, 6 }, { "Monochrome 16", - 4, 0, 2, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1333, 1467, 2.000, 1.0 }, + 4, 0, 2, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1333, 1467, 2.000, 1.0, 6 }, { "Main", - 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1000, 1100, 1.500, 1.0 }, + 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1000, 1100, 1.500, 1.0, 6 }, { "Screen-Extended Main", - 9, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1000, 1100, 1.500, 1.0 }, + 9, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1000, 1100, 1.500, 1.0, 7 }, { "Main 10", - 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1000, 1100, 1.875, 1.0 }, + 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1000, 1100, 1.875, 1.0, 6 }, { "Screen-Extended Main 10", - 9, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1000, 1100, 1.875, 1.0 }, + 9, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1000, 1100, 1.875, 1.0, 7 }, { "Main 12", - 4, 0, 2, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1500, 1650, 2.250, 1.0 }, + 4, 0, 2, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1500, 1650, 2.250, 1.0, 6 }, { "Main Still Picture", - 3, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1000, 1100, 1.500, 1.0 }, + 3, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1000, 1100, 1.500, 1.0, 6 }, { "Main 4:2:2 10", - 4, 0, 2, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1667, 1833, 2.500, 0.5 }, + 4, 0, 2, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1667, 1833, 2.500, 0.5, 6 }, { "Main 4:2:2 12", - 4, 0, 2, 1, 0, 0, 1, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5 }, + 4, 0, 2, 1, 0, 0, 1, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5, 6 }, { "Main 4:4:4", - 4, 0, 2, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5 }, + 4, 0, 2, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5, 6 }, { "High Throughput 4:4:4", - 5, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5 }, + 5, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5, 6 }, { "Screen-Extended Main 4:4:4", - 9, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5 }, + 9, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5, 7 }, { "Screen-Extended High Throughput 4:4:4", - 9, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5 }, + 9, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5, 7 }, { "Main 4:4:4 10", - 4, 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2500, 2750, 3.750, 0.5 }, + 4, 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2500, 2750, 3.750, 0.5, 6 }, { "High Throughput 4:4:4 10", - 5, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2500, 2750, 3.750, 0.5 }, + 5, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2500, 2750, 3.750, 0.5, 6 }, { "Screen-Extended Main 4:4:4 10", - 9, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2500, 2750, 3.750, 0.5 }, + 9, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2500, 2750, 3.750, 0.5, 7 }, { "Screen-Extended High Throughput 4:4:4 10", - 9, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2500, 2750, 3.750, 0.5 }, + 9, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2500, 2750, 3.750, 0.5, 7 }, { "Main 4:4:4 12", - 4, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 1, 3000, 3300, 4.500, 0.5 }, + 4, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 1, 3000, 3300, 4.500, 0.5, 6 }, { "High Throughput 4:4:4 14", - 5, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3500, 3850, 5.250, 0.5 }, + 5, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3500, 3850, 5.250, 0.5, 6 }, { "Screen-Extended High Throughput 4:4:4 14", - 9, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3500, 3850, 5.250, 0.5 }, + 9, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3500, 3850, 5.250, 0.5, 7 }, { "Main Intra", - 4, 0, 2, 1, 1, 1, 1, 1, 0, 1, 0, 2, 1000, 1100, 1.500, 1.0 }, + 4, 0, 2, 1, 1, 1, 1, 1, 0, 1, 0, 2, 1000, 1100, 1.500, 1.0, 6 }, { "Main 10 Intra", - 4, 0, 2, 1, 1, 0, 1, 1, 0, 1, 0, 2, 1000, 1100, 1.875, 1.0 }, + 4, 0, 2, 1, 1, 0, 1, 1, 0, 1, 0, 2, 1000, 1100, 1.875, 1.0, 6 }, { "Main 12 Intra", - 4, 0, 2, 1, 0, 0, 1, 1, 0, 1, 0, 2, 1500, 1650, 2.250, 1.0 }, + 4, 0, 2, 1, 0, 0, 1, 1, 0, 1, 0, 2, 1500, 1650, 2.250, 1.0, 6 }, { "Main 4:2:2 10 Intra", - 4, 0, 2, 1, 1, 0, 1, 0, 0, 1, 0, 2, 1667, 1833, 2.500, 0.5 }, + 4, 0, 2, 1, 1, 0, 1, 0, 0, 1, 0, 2, 1667, 1833, 2.500, 0.5, 6 }, { "Main 4:2:2 12 Intra", - 4, 0, 2, 1, 0, 0, 1, 0, 0, 1, 0, 2, 2000, 2200, 3.000, 0.5 }, + 4, 0, 2, 1, 0, 0, 1, 0, 0, 1, 0, 2, 2000, 2200, 3.000, 0.5, 6 }, { "Main 4:4:4 Intra", - 4, 0, 2, 1, 1, 1, 0, 0, 0, 1, 0, 2, 2000, 2200, 3.000, 0.5 }, + 4, 0, 2, 1, 1, 1, 0, 0, 0, 1, 0, 2, 2000, 2200, 3.000, 0.5, 6 }, { "Main 4:4:4 10 Intra", - 4, 0, 2, 1, 1, 0, 0, 0, 0, 1, 0, 2, 2500, 2750, 3.750, 0.5 }, + 4, 0, 2, 1, 1, 0, 0, 0, 0, 1, 0, 2, 2500, 2750, 3.750, 0.5, 6 }, { "Main 4:4:4 12 Intra", - 4, 0, 2, 1, 0, 0, 0, 0, 0, 1, 0, 2, 3000, 3300, 4.500, 0.5 }, + 4, 0, 2, 1, 0, 0, 0, 0, 0, 1, 0, 2, 3000, 3300, 4.500, 0.5, 6 }, { "Main 4:4:4 16 Intra", - 4, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 2, 4000, 4400, 6.000, 0.5 }, + 4, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 2, 4000, 4400, 6.000, 0.5, 6 }, { "Main 4:4:4 Still Picture", - 4, 0, 2, 1, 1, 1, 0, 0, 0, 1, 1, 2, 2000, 2200, 3.000, 0.5 }, + 4, 0, 2, 1, 1, 1, 0, 0, 0, 1, 1, 2, 2000, 2200, 3.000, 0.5, 6 }, { "Main 4:4:4 16 Still Picture", - 4, 0, 2, 0, 0, 0, 0, 0, 0, 1, 1, 2, 4000, 4400, 6.000, 0.5 }, + 4, 0, 2, 0, 0, 0, 0, 0, 0, 1, 1, 2, 4000, 4400, 6.000, 0.5, 6 }, { "High Throughput 4:4:4 16 Intra", - 5, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 4000, 4400, 6.000, 0.5 }, + 5, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 4000, 4400, 6.000, 0.5, 6 }, }; @@ -231,14 +231,14 @@ const H265LevelDescriptor *ff_h265_guess_level(const H265RawProfileTierLevel *pt if (bitrate > (int64_t)profile->cpb_nal_factor * hbr_factor * max_br) continue; - if (pic_size < (level->max_luma_ps >> 2)) - max_dpb_size = 16; - else if (pic_size < (level->max_luma_ps >> 1)) - max_dpb_size = 14; - else if (pic_size < (3 * level->max_luma_ps >> 2)) - max_dpb_size = 9; + if (pic_size <= (level->max_luma_ps >> 2)) + max_dpb_size = FFMIN(4 * profile->max_dpb_pic_buf, 16); + else if (pic_size <= (level->max_luma_ps >> 1)) + max_dpb_size = FFMIN(2 * profile->max_dpb_pic_buf, 16); + else if (pic_size <= (3 * level->max_luma_ps >> 2)) + max_dpb_size = FFMIN(4 * profile->max_dpb_pic_buf / 3, 16); else - max_dpb_size = 7; + max_dpb_size = profile->max_dpb_pic_buf; if (max_dec_pic_buffering > max_dpb_size) continue; diff --git a/libavcodec/h265_profile_level.h b/libavcodec/h265_profile_level.h index 12c00f0077..2d5bebaecd 100644 --- a/libavcodec/h265_profile_level.h +++ b/libavcodec/h265_profile_level.h @@ -66,6 +66,7 @@ typedef struct H265ProfileDescriptor { uint16_t cpb_nal_factor; float format_capability_factor; float min_cr_scale_factor; + uint8_t max_dpb_pic_buf; } H265ProfileDescriptor;