2 * Copyright © 2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWAR OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Chen, Peng <chen.c.peng@intel.com>
29 #include "intel_driver.h"
30 #include "gen9_hevc_enc_utils.h"
33 hevc_get_max_mbps(unsigned int level_idc)
35 unsigned int max_bps = 0;
83 gen9_hevc_get_profile_level_max_frame(VAEncSequenceParameterBufferHEVC *seq_param,
84 unsigned int user_max_frame_size,
85 unsigned int frame_rate)
87 double bits_per_mb, tmp_f;
89 unsigned int max_mbps;
90 unsigned long long max_byte_per_pic, max_byte_per_pic_not0;
91 int profile_level_max_frame;
92 double frameRateD = 100;
96 if (seq_param->seq_fields.bits.chroma_format_idc == 0)
97 max_mbps = hevc_get_max_mbps(seq_param->general_level_idc) / 16 / 16;
99 max_mbps = (int)(((double)hevc_get_max_mbps(seq_param->general_level_idc)) * 1.5 / 16 / 16);
101 num_mb_per_frame = ALIGN(seq_param->pic_width_in_luma_samples, 16) *
102 ALIGN(seq_param->pic_height_in_luma_samples, 16) / 256;
104 tmp_f = (double)num_mb_per_frame;
105 if (tmp_f < max_mbps / 172)
106 tmp_f = max_mbps / 172;
108 max_byte_per_pic = (unsigned long long)(tmp_f * bits_per_mb);
109 max_byte_per_pic_not0 =
110 (unsigned long long)((((double)max_mbps * frameRateD) /
111 (double)frame_rate) * bits_per_mb);
113 if (user_max_frame_size) {
114 profile_level_max_frame = (unsigned int)MIN(user_max_frame_size, max_byte_per_pic);
115 profile_level_max_frame = (unsigned int)MIN(max_byte_per_pic_not0, profile_level_max_frame);
117 profile_level_max_frame = (unsigned int)MIN(max_byte_per_pic_not0, max_byte_per_pic);
119 return MIN(profile_level_max_frame,
120 seq_param->pic_width_in_luma_samples * seq_param->pic_height_in_luma_samples);