From patchwork Mon May 6 21:02:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 13014 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 A85CD4421C4 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 DC30568ADC9; Tue, 7 May 2019 00:02:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E1C8268AD77 for ; Tue, 7 May 2019 00:02:35 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id y2so17211754wmi.5 for ; Mon, 06 May 2019 14:02:35 -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:mime-version :content-transfer-encoding; bh=3Olkh9eKifO33iGOjX7sy6wpV5CPcN6GaM0IxsGcECo=; b=sm0p/d69w7RKTf2NlCR8ab++zMpBuXhiKEwXNiIWI0jpk4nk/8qMM0RnCab4i1EUml tPiOzgBLWOW20u4BB4mzCSWU7fErSNCqBSGpUOklmqlCsqKOTcqhZJYUPZQkByjSiPOA gA7UJcO4TzwEwqkmqXDNF/NGsNymJ/W6g48NOnG680niIBpiGf/JYaZUSvtdqNuNsevu e1Z4L+veASwyWnkqQxapfZ8h2pQwMTbFHij2XELmuYD+2KskD44JVvelXmfzgmfuE/G5 NjTOl28MUIi7ixLTw1KaHjl9bc2bbyLL02gLSWxDnlGxaKID3o/YV0QcSJJQ1XrlyErd 8R0Q== 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:mime-version:content-transfer-encoding; bh=3Olkh9eKifO33iGOjX7sy6wpV5CPcN6GaM0IxsGcECo=; b=IchdzOZvZujXHVxeLGXYoEkA68Gm3Z1143BKrO2xYU/gEVBoByNXBrA1O7oI0CHI0t UzZoDJc7P+uMjGuLSx7s19gv7CmPbVmbKh6PB6p+mA6hD9C9UX624wfHsxl2BwCK7q2Y 4tasgTfDCrC/T+iXrRAyGEc1s3x4/JZnydZ+MGw9sYx+wMh/EUqNcqSxFvCP9mGxVOrF Me2TF9HK5czw/vv+TuMrvljceuAHiuenST4369+4BGC/1Ace1Hid0R9U5dw7xAgNuBSo K1BVT5MtfGVb9BDp7Qacx8HhFjeroRQJGThj8C/EHK54bV7iUpMpbH5PxwVtNTQ7o7sH vbYg== X-Gm-Message-State: APjAAAW63+hY0xi8h2yrbL44d3y1oDLjkMGfCe2A+hrCDvhRLouMKCDn N5O9jiZk7ecC3R/F5Ymj/YSxOiuSZ+U= X-Google-Smtp-Source: APXvYqz8VXqprFqF34Pfnh0g/QSiC8epQ4vgQP+UOSw/mQNlzMKDW4DmiXSTsLGY0VoJDgTBO+f88w== X-Received: by 2002:a1c:f910:: with SMTP id x16mr17959989wmh.114.1557176554979; Mon, 06 May 2019 14:02:34 -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.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 14:02:34 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 6 May 2019 22:02:22 +0100 Message-Id: <20190506210223.25159-4-sw@jkqxz.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190506210223.25159-1-sw@jkqxz.net> References: <20190506210223.25159-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 4/5] lavc/h265_profile_level: Add unit test 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" Operates in the same way as the h264-levels test. --- libavcodec/Makefile | 1 + libavcodec/tests/h265_levels.c | 297 +++++++++++++++++++++++++++++++++ tests/fate/libavcodec.mak | 5 + 3 files changed, 303 insertions(+) create mode 100644 libavcodec/tests/h265_levels.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 489820eead..76be867028 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1161,6 +1161,7 @@ TESTPROGS-$(CONFIG_IIRFILTER) += iirfilter TESTPROGS-$(HAVE_MMX) += motion TESTPROGS-$(CONFIG_MPEGVIDEO) += mpeg12framerate TESTPROGS-$(CONFIG_H264_METADATA_BSF) += h264_levels +TESTPROGS-$(CONFIG_HEVC_METADATA_BSF) += h265_levels TESTPROGS-$(CONFIG_RANGECODER) += rangecoder TESTPROGS-$(CONFIG_SNOW_ENCODER) += snowenc diff --git a/libavcodec/tests/h265_levels.c b/libavcodec/tests/h265_levels.c new file mode 100644 index 0000000000..66d72c63a3 --- /dev/null +++ b/libavcodec/tests/h265_levels.c @@ -0,0 +1,297 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "libavcodec/h265_profile_level.h" + +static const struct { + int width; + int height; + int level_idc; +} test_sizes[] = { + // First level usable at standard sizes, from H.265 table A.9. + { 176, 144, 30 }, // QCIF + { 352, 288, 60 }, // CIF + { 640, 480, 90 }, // VGA + { 720, 480, 90 }, // NTSC + { 720, 576, 90 }, // PAL + { 1024, 768, 93 }, // XGA + { 1280, 720, 93 }, // 720p + { 1280, 1024, 120 }, // SXGA + { 1920, 1080, 120 }, // 1080p + { 2048, 1080, 120 }, // 2Kx1080 + { 2048, 1536, 150 }, // 4XGA + { 3840, 2160, 150 }, // 4K + { 7680, 4320, 180 }, // 8K + + // Overly wide or tall sizes. + { 1, 512, 30 }, + { 1, 1024, 63 }, + { 1, 2048, 90 }, + { 1, 4096, 120 }, + { 1, 8192, 150 }, + { 1, 16384, 180 }, + { 1, 32768, 0 }, + { 512, 1, 30 }, + { 1024, 1, 63 }, + { 2048, 1, 90 }, + { 4096, 1, 120 }, + { 8192, 1, 150 }, + { 16384, 1, 180 }, + { 32768, 1, 0 }, + { 2800, 256, 93 }, + { 2816, 128, 120 }, + { 256, 4208, 120 }, + { 128, 4224, 150 }, + { 8432, 256, 150 }, + { 8448, 128, 180 }, + { 256, 16880, 180 }, + { 128, 16896, 0 }, +}; + +static const struct { + int width; + int height; + int dpb_size; + int level_idc; +} test_dpb[] = { + // First level usable for some DPB sizes. + + // L1: 176 * 144 = 25344 <= 36864 * 3/4 = 27648 + // L2: <= 122880 * 1/4 = 30720 + { 176, 144, 8, 30 }, + { 176, 144, 9, 60 }, + + // L2: 352 * 288 = 101376 <= 122880 + // L2.1: <= 245760 * 1/2 = 122880 + // L3: <= 552960 * 1/4 = 138240 + { 352, 288, 6, 60 }, + { 352, 288, 7, 63 }, + { 352, 288, 13, 90 }, + + // L3.1: 1280 * 720 = 921600 <= 983040 + // L4: <= 2228224 * 1/2 = 1114112 + // L5: <= 8912896 * 1/4 = 2228224 + { 1280, 720, 6, 93 }, + { 1280, 720, 12, 120 }, + { 1280, 720, 16, 150 }, + + // L5: 3840 * 2160 = 8294400 <= 8912896 + // L6: <= 35651584 * 1/4 = 8912896 + { 3840, 2160, 6, 150 }, + { 3840, 2160, 7, 180 }, + { 3840, 2160, 16, 180 }, +}; + +static const H265RawProfileTierLevel profile_main = { + // CpbNalFactor = 1100 + .general_profile_space = 0, + .general_profile_idc = 1, + .general_tier_flag = 0, + .general_profile_compatibility_flag[1] = 1, +}; + +static const H265RawProfileTierLevel profile_main_12 = { + // CpbNalFactor = 1650 + .general_profile_space = 0, + .general_profile_idc = 4, + .general_tier_flag = 0, + .general_profile_compatibility_flag[4] = 1, + .general_max_12bit_constraint_flag = 1, + .general_max_10bit_constraint_flag = 0, + .general_max_8bit_constraint_flag = 0, + .general_max_422chroma_constraint_flag = 1, + .general_max_420chroma_constraint_flag = 1, + .general_max_monochrome_constraint_flag = 0, + .general_intra_constraint_flag = 0, + .general_one_picture_only_constraint_flag = 0, + .general_lower_bit_rate_constraint_flag = 1, +}; + +static const H265RawProfileTierLevel profile_main_422_12_intra = { + // CpbNalFactor = 2200 + .general_profile_space = 0, + .general_profile_idc = 4, + .general_tier_flag = 0, + .general_profile_compatibility_flag[4] = 1, + .general_max_12bit_constraint_flag = 1, + .general_max_10bit_constraint_flag = 0, + .general_max_8bit_constraint_flag = 0, + .general_max_422chroma_constraint_flag = 1, + .general_max_420chroma_constraint_flag = 0, + .general_max_monochrome_constraint_flag = 0, + .general_intra_constraint_flag = 1, + .general_one_picture_only_constraint_flag = 0, +}; + +static const H265RawProfileTierLevel profile_ht_444_14 = { + // CpbNalFactor = 3850 + .general_profile_space = 0, + .general_profile_idc = 5, + .general_tier_flag = 0, + .general_profile_compatibility_flag[5] = 1, + .general_max_14bit_constraint_flag = 1, + .general_max_12bit_constraint_flag = 0, + .general_max_10bit_constraint_flag = 0, + .general_max_8bit_constraint_flag = 0, + .general_max_422chroma_constraint_flag = 0, + .general_max_420chroma_constraint_flag = 0, + .general_max_monochrome_constraint_flag = 0, + .general_intra_constraint_flag = 0, + .general_one_picture_only_constraint_flag = 0, + .general_lower_bit_rate_constraint_flag = 1, +}; + +static const H265RawProfileTierLevel profile_main_high_tier = { + // CpbNalFactor = 1100 + .general_profile_space = 0, + .general_profile_idc = 1, + .general_tier_flag = 1, + .general_profile_compatibility_flag[1] = 1, +}; + +static const struct { + int64_t bitrate; + const H265RawProfileTierLevel *ptl; + int level_idc; +} test_bitrate[] = { + // First level usable for some bitrates and profiles. + + // L2.1: 3000 * 1100 = 3300000 + // L3: 6000 * 1100 = 6600000 + { 4000000, &profile_main, 90 }, + // L2: 1500 * 1650 = 2475000 + // L2.1: 3000 * 1650 = 4950000 + { 4000000, &profile_main_12, 63 }, + // L1: 350 * 2200 * 2 = 1540000 + // L2: 1500 * 2200 * 2 = 6600000 + { 4000000, &profile_main_422_12_intra, 60 }, + + // L5.1: 40000 * 1100 = 44000000 + // L5.2: 60000 * 1100 = 66000000 + { 50000000, &profile_main, 156 }, + // L5: 25000 * 1650 = 41250000 + // L5.1: 40000 * 1650 = 66000000 + { 50000000, &profile_main_12, 153 }, + // L3.1: 10000 * 2200 * 2 = 44000000 + // L4: 12000 * 2200 * 2 = 52800000 + { 50000000, &profile_main_422_12_intra, 120 }, + // L2: 1500 * 3850 * 6 = 34650000 + // L2.1: 3000 * 3850 * 6 = 69300000 + { 50000000, &profile_ht_444_14, 63 }, + + // Level changes based on tier. + { 1000, &profile_main, 30 }, + { 1000, &profile_main_high_tier, 120 }, + { 40000000, &profile_main, 153 }, + { 40000000, &profile_main_high_tier, 123 }, + { 200000000, &profile_main, 186 }, + { 200000000, &profile_main_high_tier, 156 }, + + // Overflowing 32-bit integers. + // L6: 60000 * 3850 * 6 = 1386000000 + // L6.1: 120000 * 3850 * 6 = 2772000000 + // L6.2: 240000 * 3850 * 6 = 5544000000 + { INT64_C(2700000000), &profile_ht_444_14, 183 }, + { INT64_C(4200000000), &profile_ht_444_14, 186 }, + { INT64_C(5600000000), &profile_ht_444_14, 0 }, +}; + +static const struct { + int slice_segments; + int tile_rows; + int tile_cols; + int level_idc; +} test_fragments[] = { + // Slices. + { 4, 1, 1, 30 }, + { 32, 1, 1, 93 }, + { 70, 1, 1, 120 }, + { 80, 1, 1, 150 }, + { 201, 1, 1, 180 }, + { 600, 1, 1, 180 }, + { 601, 1, 1, 0 }, + + // Tiles. + { 1, 2, 1, 90 }, + { 1, 1, 2, 90 }, + { 1, 3, 3, 93 }, + { 1, 4, 2, 120 }, + { 1, 2, 4, 120 }, + { 1, 11, 10, 150 }, + { 1, 10, 11, 180 }, + { 1, 22, 20, 180 }, + { 1, 20, 22, 0 }, +}; + +int main(void) +{ + const H265ProfileDescriptor *profile; + const H265LevelDescriptor *level; + int i; + +#define CHECK(expected, format, ...) do { \ + if (expected ? (!level || level->level_idc != expected) \ + : !!level) { \ + av_log(NULL, AV_LOG_ERROR, "Incorrect level for " \ + format ": expected %d, got %d.\n", __VA_ARGS__, \ + expected, level ? level->level_idc : -1); \ + return 1; \ + } \ + } while (0) + + for (i = 0; i < FF_ARRAY_ELEMS(test_sizes); i++) { + level = ff_h265_guess_level(&profile_main, 0, + test_sizes[i].width, + test_sizes[i].height, + 0, 0, 0, 0); + CHECK(test_sizes[i].level_idc, "size %dx%d", + test_sizes[i].width, test_sizes[i].height); + } + + for (i = 0; i < FF_ARRAY_ELEMS(test_dpb); i++) { + level = ff_h265_guess_level(&profile_main, 0, + test_dpb[i].width, + test_dpb[i].height, + 0, 0, 0, test_dpb[i].dpb_size); + CHECK(test_dpb[i].level_idc, "size %dx%d dpb %d", + test_dpb[i].width, test_dpb[i].height, + test_dpb[i].dpb_size); + } + + for (i = 0; i < FF_ARRAY_ELEMS(test_bitrate); i++) { + profile = ff_h265_get_profile(test_bitrate[i].ptl); + level = ff_h265_guess_level(test_bitrate[i].ptl, + test_bitrate[i].bitrate, + 0, 0, 0, 0, 0, 0); + CHECK(test_bitrate[i].level_idc, "bitrate %"PRId64" profile %s", + test_bitrate[i].bitrate, profile->name); + } + + for (i = 0; i < FF_ARRAY_ELEMS(test_fragments); i++) { + level = ff_h265_guess_level(&profile_main, 0, 0, 0, + test_fragments[i].slice_segments, + test_fragments[i].tile_rows, + test_fragments[i].tile_cols, 0); + CHECK(test_fragments[i].level_idc, "%d slices %dx%d tiles", + test_fragments[i].slice_segments, + test_fragments[i].tile_cols, test_fragments[i].tile_rows); + } + + return 0; +} diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak index 548417e7d8..d9b26bae93 100644 --- a/tests/fate/libavcodec.mak +++ b/tests/fate/libavcodec.mak @@ -51,6 +51,11 @@ fate-h264-levels: libavcodec/tests/h264_levels$(EXESUF) fate-h264-levels: CMD = run libavcodec/tests/h264_levels$(EXESUF) fate-h264-levels: REF = /dev/null +FATE_LIBAVCODEC-$(CONFIG_HEVC_METADATA_BSF) += fate-h265-levels +fate-h265-levels: libavcodec/tests/h265_levels$(EXESUF) +fate-h265-levels: CMD = run libavcodec/tests/h265_levels +fate-h265-levels: REF = /dev/null + FATE_LIBAVCODEC-$(CONFIG_IIRFILTER) += fate-iirfilter fate-iirfilter: libavcodec/tests/iirfilter$(EXESUF) fate-iirfilter: CMD = run libavcodec/tests/iirfilter$(EXESUF)