OSDN Git Service

render: clear background using 3D pipeline on GEN8+
[android-x86/hardware-intel-common-vaapi.git] / src / gen9_hevc_enc_utils.c
1 /*
2  * Copyright © 2017 Intel Corporation
3  *
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:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
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.
23  *
24  * Authors:
25  *    Chen, Peng <chen.c.peng@intel.com>
26  *
27  */
28
29 #include "intel_driver.h"
30 #include "gen9_hevc_enc_utils.h"
31
32 static unsigned int
33 hevc_get_max_mbps(unsigned int level_idc)
34 {
35     unsigned int max_bps = 0;
36
37     switch (level_idc) {
38     case 30:
39         max_bps = 552960;
40         break;
41     case 60:
42         max_bps = 686400;
43         break;
44     case 90:
45         max_bps = 13762560;
46         break;
47     case 93:
48         max_bps = 33177600;
49         break;
50     case 120:
51     case 123:
52         max_bps = 62668800;
53         break;
54     case 126:
55     case 129:
56         max_bps = 133693440;
57         break;
58     case 150:
59     case 153:
60         max_bps = 267386880;
61         break;
62     case 156:
63         max_bps = 534773760;
64         break;
65     case 180:
66         max_bps = 1002700800;
67         break;
68     case 183:
69         max_bps = 2005401600;
70         break;
71     case 186:
72         max_bps = 4010803200;
73         break;
74     default:
75         max_bps = 13762560;
76         break;
77     }
78
79     return max_bps;
80 }
81
82 unsigned int
83 gen9_hevc_get_profile_level_max_frame(VAEncSequenceParameterBufferHEVC *seq_param,
84                                       unsigned int user_max_frame_size,
85                                       unsigned int frame_rate)
86 {
87     double bits_per_mb, tmp_f;
88     int num_mb_per_frame;
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;
93
94     bits_per_mb = 192;
95
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;
98     else
99         max_mbps = (int)(((double)hevc_get_max_mbps(seq_param->general_level_idc)) * 1.5 / 16 / 16);
100
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;
103
104     tmp_f = (double)num_mb_per_frame;
105     if (tmp_f < max_mbps / 172)
106         tmp_f = max_mbps / 172;
107
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);
112
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);
116     } else
117         profile_level_max_frame = (unsigned int)MIN(max_byte_per_pic_not0, max_byte_per_pic);
118
119     return MIN(profile_level_max_frame,
120                seq_param->pic_width_in_luma_samples * seq_param->pic_height_in_luma_samples);
121 }