From patchwork Mon May 6 21:02:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 13017 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id AD78E4421E2 for ; Tue, 7 May 2019 00:11:38 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 58FAD68AD3F; Tue, 7 May 2019 00:02:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2B4DD68AB00 for ; Tue, 7 May 2019 00:02:32 +0300 (EEST) Received: by mail-wr1-f43.google.com with SMTP id f7so8804183wrq.1 for ; Mon, 06 May 2019 14:02:32 -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:mime-version :content-transfer-encoding; bh=o+LiHTo/26weGqRjGNKUXEUpJXHA2TM4vPCM9R2ydDg=; b=NMMVPksKSHjKGu1Jd7VFEbTerJQQQJpsqIXxw5F8UGO7KxISQ5CaIodwJPw5CCjm2g IAsiWr9eZjgv3trJxrCYmed4XfSsVQyzWPFTm8WjuVXjkPmTt7gbk1qExUk7Qe2Kvamm ECOm1B003hmiFpbF6HM8MHGhZOcBIo1s3/hoKpSxx/K24T/toIQEJxKhxnUy0QIccsHi ft8NMg/RYeuhKo60tNgepRn9AUfNzc6l+SmZXDIP0AFHxAuYXjbOgIa3P+gHqwHDa8bz +uxzSEBMJ6K6QyGnL/m+BTMJUDMf/OJz9ym8oP3WCiDd0O0iFL59SJ4HzdHwd0eILdfQ vgRQ== 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:mime-version :content-transfer-encoding; bh=o+LiHTo/26weGqRjGNKUXEUpJXHA2TM4vPCM9R2ydDg=; b=NIMXcUQKmJ1BQbDbpLmK8yZ7wUgx8tDSIr866gDJjqnim7xTg2hSpyr4C+eCfDZhsc J4boHzRFq9B7gShSHHU62CVhf2PXToBt1zoRM17IsTQwuFgT+9L5tCUbqQKGVsr0B8i6 OQ9f4m9rX48dWbkgY5sacaAECfXUh7xBAyKovGcWHezg8rpDJKaGfjZXIP281nJsfW// 8hWNGxexfjtMCBQVD8pHd688Tc1i1JMFgEjTv6HmMza96VBcAMYk+/LrbHRo1+Dsl1l0 R/jYC1Ge2Xlf6ru5PlZqjAc/5ZUvFwv2hoOUsuvrto/Dcthi4wr9s8nPZjoJjbYQM8Cf /+rA== X-Gm-Message-State: APjAAAXjdpCkvBwAHAHTWnHgH6z2IK8Kv/1DZ7ejWb4rWftUjxhYxXFG YlQWXEl/xJ0L+g73RFUdw4Mf2+bcVGk= X-Google-Smtp-Source: APXvYqzjfa5x+UFXDCSXdn+NU1r9SSF7ZsrcSfjENp7gK/n4lMKi2Kul8MlzdXl+NbfVtOD7ZPAbrQ== X-Received: by 2002:adf:cf04:: with SMTP id o4mr6578717wrj.212.1557176550756; Mon, 06 May 2019 14:02:30 -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 u11sm20777747wmu.15.2019.05.06.14.02.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 14:02:29 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 6 May 2019 22:02:19 +0100 Message-Id: <20190506210223.25159-1-sw@jkqxz.net> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 1/5] 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 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;