/src/libhevc/encoder/mb_model_based.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2018 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | /*! |
21 | | ****************************************************************************** |
22 | | * \file mb_model_based.c |
23 | | * |
24 | | * \brief |
25 | | * This file contain mb level API functions |
26 | | * |
27 | | * \date |
28 | | * |
29 | | * \author |
30 | | * ittiam |
31 | | * |
32 | | ****************************************************************************** |
33 | | */ |
34 | | /*****************************************************************************/ |
35 | | /* File Includes */ |
36 | | /*****************************************************************************/ |
37 | | /* User include files */ |
38 | | #include "ittiam_datatypes.h" |
39 | | #include "rc_common.h" |
40 | | #include "rc_cntrl_param.h" |
41 | | #include "var_q_operator.h" |
42 | | #include "mem_req_and_acq.h" |
43 | | #include "mb_model_based.h" |
44 | | |
45 | | typedef struct mb_rate_control_t |
46 | | { |
47 | | /* Frame Qp */ |
48 | | UWORD8 u1_frm_qp; |
49 | | /* Estimated average activity for the current frame (updated with the previous |
50 | | frame activity since it is independent of picture type whether it is I or P) */ |
51 | | WORD32 i4_avg_activity; |
52 | | } mb_rate_control_t; |
53 | | |
54 | | WORD32 mbrc_num_fill_use_free_memtab( |
55 | | mb_rate_control_t **pps_mb_rate_control, itt_memtab_t *ps_memtab, ITT_FUNC_TYPE_E e_func_type) |
56 | 61.9k | { |
57 | 61.9k | WORD32 i4_mem_tab_idx = 0; |
58 | 61.9k | static mb_rate_control_t s_mb_rate_control_temp; |
59 | | |
60 | | /* Hack for al alloc, during which we dont have any state memory. |
61 | | Dereferencing can cause issues */ |
62 | 61.9k | if(e_func_type == GET_NUM_MEMTAB || e_func_type == FILL_MEMTAB) |
63 | 53.1k | (*pps_mb_rate_control) = &s_mb_rate_control_temp; |
64 | | |
65 | | /*for src rate control state structure*/ |
66 | 61.9k | if(e_func_type != GET_NUM_MEMTAB) |
67 | 26.5k | { |
68 | 26.5k | fill_memtab( |
69 | 26.5k | &ps_memtab[i4_mem_tab_idx], |
70 | 26.5k | sizeof(mb_rate_control_t), |
71 | 26.5k | MEM_TAB_ALIGNMENT, |
72 | 26.5k | PERSISTENT, |
73 | 26.5k | DDR); |
74 | 26.5k | use_or_fill_base(&ps_memtab[0], (void **)pps_mb_rate_control, e_func_type); |
75 | 26.5k | } |
76 | 61.9k | i4_mem_tab_idx++; |
77 | | |
78 | 61.9k | return (i4_mem_tab_idx); |
79 | 61.9k | } |
80 | | |
81 | | /******************************************************************************** |
82 | | MB LEVEL API FUNCTIONS |
83 | | ********************************************************************************/ |
84 | | /****************************************************************************** |
85 | | Function Name : init_mb_level_rc |
86 | | Description : Initialise the mb model and the average activity to default values |
87 | | Arguments : |
88 | | Return Values : void |
89 | | Revision History: |
90 | | 13 03 2008 KJN Creation |
91 | | *********************************************************************************/ |
92 | | void init_mb_level_rc(mb_rate_control_t *ps_mb_rate_control) |
93 | 18.2k | { |
94 | | /* Set values to default */ |
95 | 18.2k | ps_mb_rate_control->i4_avg_activity = 0; |
96 | 18.2k | } |
97 | | /****************************************************************************** |
98 | | Function Name : mb_init_frame_level |
99 | | Description : Initialise the mb state with frame level decisions |
100 | | Arguments : u1_frame_qp - Frame level qp |
101 | | Return Values : void |
102 | | Revision History: |
103 | | 13 03 2008 KJN Creation |
104 | | *********************************************************************************/ |
105 | | void mb_init_frame_level(mb_rate_control_t *ps_mb_rate_control, UWORD8 u1_frame_qp) |
106 | 0 | { |
107 | | /* Update frame level QP */ |
108 | 0 | ps_mb_rate_control->u1_frm_qp = u1_frame_qp; |
109 | 0 | } |
110 | | /****************************************************************************** |
111 | | Function Name : reset_mb_activity |
112 | | Description : Reset the mb activity - Whenever there is SCD |
113 | | the mb activity is reset |
114 | | Arguments : |
115 | | Return Values : void |
116 | | Revision History: |
117 | | 13 03 2008 KJN Creation |
118 | | *********************************************************************************/ |
119 | | void reset_mb_activity(mb_rate_control_t *ps_mb_rate_control) |
120 | 0 | { |
121 | 0 | ps_mb_rate_control->i4_avg_activity = 0; |
122 | 0 | } |
123 | | |
124 | | /****************************************************************************** |
125 | | Function Name : get_mb_qp |
126 | | Description : Calculates the mb level qp |
127 | | Arguments : i4_cur_mb_activity - current frame mb activity |
128 | | pi4_mb_qp - Array of 2 values for before and after mb activity |
129 | | modulation |
130 | | Return Values : void |
131 | | |
132 | | Revision History: |
133 | | 13 03 2008 KJN Creation |
134 | | *********************************************************************************/ |
135 | | void get_mb_qp(mb_rate_control_t *ps_mb_rate_control, WORD32 i4_cur_mb_activity, WORD32 *pi4_mb_qp) |
136 | 0 | { |
137 | 0 | WORD32 i4_qp; |
138 | | /* Initialise the mb level qp with the frame level qp */ |
139 | 0 | i4_qp = ps_mb_rate_control->u1_frm_qp; |
140 | | |
141 | | /* Store the model based QP - This is used for updating the rate control model */ |
142 | 0 | pi4_mb_qp[0] = i4_qp; |
143 | | |
144 | | /* Modulate the Qp based on the activity */ |
145 | 0 | if((ps_mb_rate_control->i4_avg_activity) && (i4_qp < 100)) |
146 | 0 | { |
147 | 0 | i4_qp = ((((2 * i4_cur_mb_activity)) + ps_mb_rate_control->i4_avg_activity) * i4_qp + |
148 | 0 | ((i4_cur_mb_activity + 2 * ps_mb_rate_control->i4_avg_activity) >> 1)) / |
149 | 0 | (i4_cur_mb_activity + 2 * ps_mb_rate_control->i4_avg_activity); |
150 | |
|
151 | 0 | if(i4_qp > ((3 * ps_mb_rate_control->u1_frm_qp) >> 1)) |
152 | 0 | i4_qp = ((3 * ps_mb_rate_control->u1_frm_qp) >> 1); |
153 | 0 | } |
154 | | |
155 | | /* Store the qp modulated by mb activity - This is used for encoding the MB */ |
156 | 0 | pi4_mb_qp[1] = i4_qp; |
157 | 0 | } |
158 | | /****************************************************************************** |
159 | | Function Name : get_frm_level_qp |
160 | | Description : Returns the stored frame level QP |
161 | | Arguments : |
162 | | Revision History: |
163 | | 13 03 2008 KJN Creation |
164 | | *********************************************************************************/ |
165 | | UWORD8 get_frm_level_qp(mb_rate_control_t *ps_mb_rate_control) |
166 | 0 | { |
167 | 0 | return (ps_mb_rate_control->u1_frm_qp); |
168 | 0 | } |
169 | | /****************************************************************************** |
170 | | Function Name : mb_update_frame_level |
171 | | Description : Update the frame level info collected |
172 | | Arguments : i4_avg_activity - Average activity fot frame |
173 | | Return Values : |
174 | | Revision History: |
175 | | 13 03 2008 KJN Creation |
176 | | *********************************************************************************/ |
177 | | void mb_update_frame_level(mb_rate_control_t *ps_mb_rate_control, WORD32 i4_avg_activity) |
178 | 114k | { |
179 | | /***************************************************************************** |
180 | | Update the Average Activity |
181 | | *****************************************************************************/ |
182 | 114k | ps_mb_rate_control->i4_avg_activity = i4_avg_activity; |
183 | 114k | } |