Coverage Report

Created: 2026-04-12 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/encoder/ih264e_rc_mem_interface.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_rc_mem_interface.c
25
*
26
* @brief
27
*  This file contains api function definitions for rate control memtabs
28
*
29
* @author
30
*  ittiam
31
*
32
* List of Functions
33
*  - ih264e_map_rc_mem_recs_to_itt_api
34
*  - ih264e_map_itt_mem_rec_to_rc_mem_rec
35
*  - ih264e_get_rate_control_mem_tab
36
*
37
* @remarks
38
*  none
39
*
40
*******************************************************************************
41
*/
42
43
44
/*****************************************************************************/
45
/* File Includes                                                             */
46
/*****************************************************************************/
47
48
/* System Include Files */
49
#include <stdio.h>
50
#include <stddef.h>
51
#include <stdlib.h>
52
#include <string.h>
53
#include <assert.h>
54
55
/* User Include Files */
56
#include "ih264e_config.h"
57
#include "ih264_typedefs.h"
58
59
#include "ih264_debug.h"
60
#include "ih264_defs.h"
61
#include "ih264_mem_fns.h"
62
#include "ih264_padding.h"
63
#include "ih264_structs.h"
64
#include "ih264_size_defs.h"
65
#include "ih264_trans_quant_itrans_iquant.h"
66
#include "ih264_inter_pred_filters.h"
67
#include "ih264_intra_pred_filters.h"
68
#include "ih264_deblk_edge_filters.h"
69
#include "ih264_cabac_tables.h"
70
71
#include "ime_defs.h"
72
#include "ime_distortion_metrics.h"
73
#include "ime_structs.h"
74
75
#include "irc_mem_req_and_acq.h"
76
#include "irc_cntrl_param.h"
77
#include "irc_frame_info_collector.h"
78
#include "irc_rate_control_api.h"
79
#include "irc_common.h"
80
#include "irc_rd_model.h"
81
#include "irc_est_sad.h"
82
#include "irc_fixed_point_error_bits.h"
83
#include "irc_vbr_storage_vbv.h"
84
#include "irc_picture_type.h"
85
#include "irc_bit_allocation.h"
86
#include "irc_mb_model_based.h"
87
#include "irc_cbr_buffer_control.h"
88
#include "irc_vbr_str_prms.h"
89
#include "irc_rate_control_api_structs.h"
90
91
#include "ih264e.h"
92
#include "ih264e_error.h"
93
#include "ih264e_defs.h"
94
#include "ih264e_time_stamp.h"
95
#include "ih264e_modify_frm_rate.h"
96
#include "ih264e_rate_control.h"
97
#include "ih264e_bitstream.h"
98
#include "ih264e_cabac_structs.h"
99
#include "ih264e_structs.h"
100
101
102
/*****************************************************************************/
103
/* Function Definitions                                                      */
104
/*****************************************************************************/
105
106
/**
107
******************************************************************************
108
*
109
* @brief This function maps rc mem records structure to encoder lib mem records
110
*  structure
111
*
112
* @par   Description
113
*  This function maps rc mem records structure to encoder lib mem records
114
*  structure
115
*
116
* @param[in]   ps_mem
117
*  pointer to encoder lib mem records
118
*
119
* @param[in]   rc_memtab
120
*  pointer to rc mem records
121
*
122
* @param[in]   num_mem_recs
123
*  number of memory records
124
*
125
* @return      void
126
*
127
******************************************************************************
128
*/
129
void ih264e_map_rc_mem_recs_to_itt_api(iv_mem_rec_t *ps_mem,
130
                                       itt_memtab_t *rc_memtab,
131
                                       UWORD32 num_mem_recs)
132
46.9k
{
133
46.9k
    UWORD32 j;
134
46.9k
    UWORD32 Size, align;
135
136
246k
    for (j = 0; j < num_mem_recs; j++)
137
199k
    {
138
199k
        Size = rc_memtab->u4_size;
139
199k
        align = rc_memtab->i4_alignment;
140
141
        /* we always ask for external persistent cacheable memory */
142
199k
        FILL_MEMTAB(ps_mem, j, Size, align, IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM);
143
144
199k
        rc_memtab++;
145
199k
    }
146
46.9k
}
147
148
/**
149
*******************************************************************************
150
*
151
* @brief This function maps encoder lib mem records structure to RC memory
152
* records structure
153
*
154
* @par   Description
155
*  This function maps encoder lib mem records structure to RC memory
156
*  records structure
157
*
158
* @param[in] ps_mem
159
*  pointer to encoder lib mem records
160
*
161
* @param[in] rc_memtab
162
*  pointer to rc mem records
163
*
164
* @param[in] num_mem_recs
165
*  Number of memory records
166
167
* @returns none
168
*
169
* @remarks
170
*
171
*******************************************************************************
172
*/
173
void ih264e_map_itt_mem_rec_to_rc_mem_rec(iv_mem_rec_t *ps_mem,
174
                                          itt_memtab_t *rc_memtab,
175
                                          UWORD32 num_mem_recs)
176
46.9k
{
177
46.9k
    UWORD32 i;
178
179
246k
    for (i = 0; i < num_mem_recs; i++)
180
199k
    {
181
199k
        rc_memtab->i4_alignment = ps_mem->u4_mem_alignment;
182
199k
        rc_memtab->u4_size = ps_mem->u4_mem_size;
183
199k
        rc_memtab->pv_base = ps_mem->pv_base;
184
185
        /* only DDR memory is available */
186
199k
        rc_memtab->e_mem_region = DDR;
187
199k
        rc_memtab->e_usage = PERSISTENT;
188
189
199k
        rc_memtab++;
190
199k
        ps_mem++;
191
199k
    }
192
46.9k
}
193
194
/**
195
******************************************************************************
196
*
197
* @brief Get/Init memtabs for rate control
198
*
199
* @par   Description
200
*  This routine is used to Get/init memtabs for rate control
201
*
202
* @param[in] pv_rate_control
203
*  pointer to rate control context (handle)
204
*
205
* @param[in] ps_mem
206
*  pointer to encoder lib mem records
207
*
208
* @param[in] e_func_type
209
*  enum that dictates fill memory records or Init memory records
210
*
211
* @return total number of mem records
212
*
213
******************************************************************************
214
*/
215
WORD32 ih264e_get_rate_control_mem_tab(void *pv_rate_control,
216
                                       iv_mem_rec_t  *ps_mem,
217
                                       ITT_FUNC_TYPE_E e_func_type)
218
11.7k
{
219
11.7k
    itt_memtab_t as_itt_memtab[NUM_RC_MEMTABS];
220
11.7k
    WORD32 i4_num_memtab = 0, j = 0;
221
11.7k
    void *refptr2[4];
222
11.7k
    void **refptr1[4];
223
11.7k
    rate_control_ctxt_t *ps_rate_control = pv_rate_control;
224
225
58.6k
    for (j = 0; j < 4; j++)
226
46.9k
        refptr1[j] = &(refptr2[j]);
227
228
11.7k
    j = 0;
229
230
11.7k
    if (e_func_type == USE_BASE || e_func_type == FILL_BASE)
231
3.90k
    {
232
3.90k
        refptr1[1] = &ps_rate_control->pps_frame_time;
233
3.90k
        refptr1[2] = &ps_rate_control->pps_time_stamp;
234
3.90k
        refptr1[3] = &ps_rate_control->pps_pd_frm_rate;
235
3.90k
        refptr1[0] = &ps_rate_control->pps_rate_control_api;
236
3.90k
    }
237
238
    /* Get the total number of memtabs used by Rate Controller */
239
11.7k
    i4_num_memtab = irc_rate_control_num_fill_use_free_memtab((rate_control_api_t **)refptr1[0], NULL, GET_NUM_MEMTAB);
240
    /* Few extra steps during init */
241
11.7k
    ih264e_map_itt_mem_rec_to_rc_mem_rec((&ps_mem[j]), as_itt_memtab+j, i4_num_memtab);
242
    /* Fill the memtabs used by Rate Controller */
243
11.7k
    i4_num_memtab = irc_rate_control_num_fill_use_free_memtab((rate_control_api_t **)refptr1[0],as_itt_memtab+j,e_func_type);
244
    /* Mapping ittiam memtabs to App. memtabs */
245
11.7k
    ih264e_map_rc_mem_recs_to_itt_api((&ps_mem[j]), as_itt_memtab+j, i4_num_memtab);
246
11.7k
    j += i4_num_memtab;
247
248
    /* Get the total number of memtabs used by Frame time Module */
249
11.7k
    i4_num_memtab = ih264e_frame_time_get_init_free_memtab((frame_time_t **)refptr1[1], NULL, GET_NUM_MEMTAB);
250
    /* Few extra steps during init */
251
11.7k
    ih264e_map_itt_mem_rec_to_rc_mem_rec((&ps_mem[j]), as_itt_memtab+j, i4_num_memtab);
252
    /* Fill the memtabs used by Frame time Module */
253
11.7k
    i4_num_memtab = ih264e_frame_time_get_init_free_memtab((frame_time_t **)refptr1[1], as_itt_memtab+j, e_func_type);
254
    /* Mapping ittiam memtabs to App. memtabs */
255
11.7k
    ih264e_map_rc_mem_recs_to_itt_api((&ps_mem[j]), as_itt_memtab+j, i4_num_memtab);
256
11.7k
    j += i4_num_memtab;
257
258
    /* Get the total number of memtabs used by Time stamp Module */
259
11.7k
    i4_num_memtab = ih264e_time_stamp_get_init_free_memtab((time_stamp_t **)refptr1[2], NULL, GET_NUM_MEMTAB);
260
    /* Few extra steps during init */
261
11.7k
    ih264e_map_itt_mem_rec_to_rc_mem_rec((&ps_mem[j]), as_itt_memtab+j, i4_num_memtab);
262
    /* Fill the memtabs used by Time Stamp Module */
263
11.7k
    i4_num_memtab = ih264e_time_stamp_get_init_free_memtab((time_stamp_t **)refptr1[2], as_itt_memtab+j, e_func_type);
264
    /* Mapping ittiam memtabs to App. memtabs */
265
11.7k
    ih264e_map_rc_mem_recs_to_itt_api((&ps_mem[j]), as_itt_memtab+j, i4_num_memtab);
266
11.7k
    j += i4_num_memtab;
267
268
    /* Get the total number of memtabs used by Frame rate Module */
269
11.7k
    i4_num_memtab = ih264e_pd_frm_rate_get_init_free_memtab((pd_frm_rate_t **)refptr1[3], NULL, GET_NUM_MEMTAB);
270
    /* Few extra steps during init */
271
11.7k
    ih264e_map_itt_mem_rec_to_rc_mem_rec((&ps_mem[j]), as_itt_memtab+j, i4_num_memtab);
272
    /* Fill the memtabs used by Frame Rate Module */
273
11.7k
    i4_num_memtab = ih264e_pd_frm_rate_get_init_free_memtab((pd_frm_rate_t **)refptr1[3], as_itt_memtab+j, e_func_type);
274
    /* Mapping ittiam memtabs to App. memtabs */
275
11.7k
    ih264e_map_rc_mem_recs_to_itt_api((&ps_mem[j]), as_itt_memtab+j, i4_num_memtab);
276
11.7k
    j += i4_num_memtab;
277
278
11.7k
    return j; /* Total MemTabs Needed by Rate Control Module */
279
11.7k
}