/src/libavc/encoder/ih264e_modify_frm_rate.c
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2015 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 | | ******************************************************************************* |
23 | | * @file |
24 | | * ih264e_modify_frm_rate.c |
25 | | * |
26 | | * @brief |
27 | | * Handle source frame rate pulldown |
28 | | * |
29 | | * @author |
30 | | * ittiam |
31 | | * |
32 | | * @par List of Functions: |
33 | | * - ih264e_pd_frm_rate_get_init_free_memtab |
34 | | * - ih264e_init_pd_frm_rate |
35 | | * - ih264e_update_pd_frm_rate |
36 | | * - ih264e_get_pd_avg_frm_rate |
37 | | * |
38 | | * @remarks |
39 | | * none |
40 | | * |
41 | | ******************************************************************************* |
42 | | */ |
43 | | |
44 | | /*****************************************************************************/ |
45 | | /* File Includes */ |
46 | | /*****************************************************************************/ |
47 | | |
48 | | /* User Include Files */ |
49 | | #include "ih264_typedefs.h" |
50 | | #include "iv2.h" |
51 | | #include "ive2.h" |
52 | | |
53 | | #include "ih264_defs.h" |
54 | | #include "ih264_mem_fns.h" |
55 | | #include "ih264_padding.h" |
56 | | #include "ih264_structs.h" |
57 | | #include "ih264_trans_quant_itrans_iquant.h" |
58 | | #include "ih264_inter_pred_filters.h" |
59 | | #include "ih264_intra_pred_filters.h" |
60 | | #include "ih264_deblk_edge_filters.h" |
61 | | #include "ih264_cabac_tables.h" |
62 | | |
63 | | #include "ime_defs.h" |
64 | | #include "ime_distortion_metrics.h" |
65 | | #include "ime_structs.h" |
66 | | |
67 | | #include "irc_mem_req_and_acq.h" |
68 | | #include "irc_cntrl_param.h" |
69 | | #include "irc_frame_info_collector.h" |
70 | | |
71 | | #include "ih264e_error.h" |
72 | | #include "ih264e_defs.h" |
73 | | #include "ih264e_rate_control.h" |
74 | | #include "ih264e_bitstream.h" |
75 | | #include "ih264e_cabac_structs.h" |
76 | | #include "ih264e_structs.h" |
77 | | #include "ih264e_time_stamp.h" |
78 | | #include "ih264e_modify_frm_rate.h" |
79 | | |
80 | | |
81 | | /*****************************************************************************/ |
82 | | /* Function Definitions */ |
83 | | /*****************************************************************************/ |
84 | | |
85 | | /** |
86 | | ******************************************************************************* |
87 | | * |
88 | | * @brief Function to init pd frame rate memtab |
89 | | * |
90 | | * @par Description |
91 | | * Function to init pull down frame rate memtab |
92 | | * |
93 | | * @param[in] pps_pd_frm_rate |
94 | | * pull down frame rate context |
95 | | * |
96 | | * @param[in] ps_memtab |
97 | | * Handle to memtab |
98 | | * |
99 | | * @param[in] e_func_type |
100 | | * Function type (get memtab/ update memtab) |
101 | | * |
102 | | * @returns Number of memtabs used |
103 | | * |
104 | | * @remarks None |
105 | | * |
106 | | ******************************************************************************* |
107 | | */ |
108 | | WORD32 ih264e_pd_frm_rate_get_init_free_memtab(pd_frm_rate_handle *pps_pd_frm_rate, |
109 | | itt_memtab_t *ps_memtab, |
110 | | ITT_FUNC_TYPE_E e_func_type) |
111 | 59.4k | { |
112 | 59.4k | WORD32 i4_mem_tab_idx = 0; |
113 | 59.4k | pd_frm_rate_t s_temp_pd_frm_rate_t; |
114 | | |
115 | | /* Hack for al alloc, during which we dont have any state memory. |
116 | | Dereferencing can cause issues */ |
117 | 59.4k | if (e_func_type == GET_NUM_MEMTAB || e_func_type == FILL_MEMTAB) |
118 | 49.5k | (*pps_pd_frm_rate) = &s_temp_pd_frm_rate_t; |
119 | | |
120 | | /* for src rate control state structure */ |
121 | 59.4k | if (e_func_type != GET_NUM_MEMTAB) |
122 | 29.7k | { |
123 | 29.7k | fill_memtab(&ps_memtab[i4_mem_tab_idx], sizeof(pd_frm_rate_t), |
124 | 29.7k | ALIGN_128_BYTE, PERSISTENT, DDR); |
125 | 29.7k | use_or_fill_base(&ps_memtab[0], (void**) pps_pd_frm_rate, e_func_type); |
126 | 29.7k | } |
127 | 59.4k | i4_mem_tab_idx++; |
128 | | |
129 | 59.4k | return (i4_mem_tab_idx); |
130 | 59.4k | } |
131 | | |
132 | | /** |
133 | | ******************************************************************************* |
134 | | * |
135 | | * @brief Initializes the pull down frame rate state structure based on input |
136 | | * frame rate |
137 | | * |
138 | | * @par Description |
139 | | * Initializes the pull down frame rate state structure based on input frame rate |
140 | | * |
141 | | * @param[in] ps_pd_frm_rate |
142 | | * Pull down frame rate context |
143 | | * |
144 | | * @param[in] u4_input_frm_rate |
145 | | * Input frame rate in frame per 1000sec |
146 | | * |
147 | | * @returns none |
148 | | * |
149 | | * @remarks |
150 | | * |
151 | | ******************************************************************************* |
152 | | */ |
153 | | void ih264e_init_pd_frm_rate(pd_frm_rate_t *ps_pd_frm_rate, |
154 | | UWORD32 u4_input_frm_rate) |
155 | 55.5k | { |
156 | 55.5k | WORD32 i; |
157 | | |
158 | 55.5k | ps_pd_frm_rate->u4_input_frm_rate = u4_input_frm_rate; |
159 | | |
160 | 1.97M | for (i = 0; i < (WORD32) (u4_input_frm_rate / 1000); i++) |
161 | 1.91M | { |
162 | 1.91M | ps_pd_frm_rate->u4_cur_frm_rate[i] = u4_input_frm_rate; |
163 | 1.91M | } |
164 | | |
165 | 55.5k | ps_pd_frm_rate->u4_frm_num = 0; |
166 | | |
167 | 55.5k | ps_pd_frm_rate->u4_tot_frm_encoded = 0; |
168 | 55.5k | } |
169 | | |
170 | | /** |
171 | | ******************************************************************************* |
172 | | * |
173 | | * @brief Function to update pull down frame rate |
174 | | * |
175 | | * @par Description |
176 | | * For each frame a run time frame rate value is sent based on whether a frame |
177 | | * is skipped or not. If it is skipped for pull down then the current frame |
178 | | * rate for the pull down period is signaled as 4/5th of the original frame |
179 | | * rate. Thus when this is averaged the frame rate gradually switches from the |
180 | | * input frame rate to 4/5th of input frame rate as and when more 3:2 pull |
181 | | * down patterns are detected |
182 | | * |
183 | | * @param[in] ps_pd_frm_rate |
184 | | * Pull down frame rate context |
185 | | * |
186 | | * @param[in] u4_input_frm_rate |
187 | | * Input frame rate in frame per 1000sec |
188 | | * |
189 | | * @returns none |
190 | | * |
191 | | * @remarks |
192 | | * |
193 | | ******************************************************************************* |
194 | | */ |
195 | | void ih264e_update_pd_frm_rate(pd_frm_rate_t *ps_pd_frm_rate, |
196 | | UWORD32 u4_cur_frm_rate) |
197 | 140k | { |
198 | 140k | ps_pd_frm_rate->u4_cur_frm_rate[ps_pd_frm_rate->u4_frm_num] = u4_cur_frm_rate; |
199 | | |
200 | 140k | ps_pd_frm_rate->u4_frm_num++; |
201 | | |
202 | | /* Increment the frame number */ |
203 | 140k | if (ps_pd_frm_rate->u4_tot_frm_encoded < (ps_pd_frm_rate->u4_input_frm_rate / 1000)) |
204 | 96.5k | { |
205 | 96.5k | ps_pd_frm_rate->u4_tot_frm_encoded++; |
206 | 96.5k | } |
207 | | |
208 | | /* Reset frm_num to zero */ |
209 | 140k | if (ps_pd_frm_rate->u4_frm_num >= (ps_pd_frm_rate->u4_input_frm_rate / 1000)) |
210 | 10.2k | { |
211 | 10.2k | ps_pd_frm_rate->u4_frm_num = 0; |
212 | 10.2k | } |
213 | 140k | } |
214 | | |
215 | | /** |
216 | | ******************************************************************************* |
217 | | * |
218 | | * @brief returns average frame rate in 1 sec duration |
219 | | * |
220 | | * @par Description |
221 | | * Averages the last N frame in period(1 sec) and then gives that |
222 | | * as the current frames frame rate. Thus this averages out the sudden |
223 | | * variation in frame rate |
224 | | * |
225 | | * @param[in] ps_pd_frm_rate |
226 | | * Handle to pull down frame rate context |
227 | | * |
228 | | * @returns average frame rate |
229 | | * |
230 | | * @remarks |
231 | | * |
232 | | ******************************************************************************* |
233 | | */ |
234 | | UWORD32 ih264e_get_pd_avg_frm_rate(pd_frm_rate_t *ps_pd_frm_rate) |
235 | 140k | { |
236 | 140k | WORD32 i; |
237 | 140k | WORD32 i4_avg_frm_rate = 0; |
238 | | |
239 | 2.13M | for (i = 0; i < (WORD32) ps_pd_frm_rate->u4_tot_frm_encoded; i++) |
240 | 1.99M | { |
241 | 1.99M | i4_avg_frm_rate += ps_pd_frm_rate->u4_cur_frm_rate[i]; |
242 | 1.99M | } |
243 | | |
244 | 140k | i4_avg_frm_rate = i4_avg_frm_rate / ps_pd_frm_rate->u4_tot_frm_encoded; |
245 | | |
246 | 140k | return i4_avg_frm_rate; |
247 | 140k | } |