Coverage Report

Created: 2026-02-14 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/encoder/svc/isvce_rc_utils.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2022 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
*  isvce_rc_utils.c
25
*
26
* @brief
27
*  Contains get gpp function required by the SVC encoder
28
*
29
* @author
30
*  ittiam
31
*
32
* @par List of Functions:
33
*  - isvce_get_gpp()
34
*  - isvce_rc_utils_init()
35
*  - isvce_get_rc_utils_data_size()
36
*  - isvce_compute_gpp()
37
*  - isvce_get_gpp_function_selector()
38
*
39
* @remarks
40
*  None
41
*
42
*******************************************************************************
43
*/
44
45
#include "ih264_typedefs.h"
46
#include "ih264_macros.h"
47
#include "isvc_structs.h"
48
#include "isvce_rc_utils.h"
49
#include "isvce_rc_utils_private_defs.h"
50
51
/**
52
*******************************************************************************
53
*
54
* @brief
55
*   get gpp function
56
*
57
* @par Description:
58
*   computes gradient per pixel value for a given frame
59
*
60
* @param[in] ps_input_buf
61
*  pointer to yuv buffer properties
62
*
63
* @returns
64
*  calculated gpp value
65
*
66
* @remarks
67
*  none
68
*
69
*******************************************************************************
70
*/
71
72
static DOUBLE isvce_get_gpp(yuv_buf_props_t *ps_input_buf)
73
0
{
74
0
    UWORD32 i, j;
75
76
0
    DOUBLE d_gpp_y = 0;
77
0
    DOUBLE d_gpp_u = 0;
78
0
    DOUBLE d_gpp_v = 0;
79
80
0
    DOUBLE d_gpp = 0;
81
82
0
    UWORD32 u4_width = ps_input_buf->u4_width;
83
0
    UWORD32 u4_height = ps_input_buf->u4_height;
84
85
0
    UWORD8 *pu1_input_buf = (UWORD8 *) ps_input_buf->as_component_bufs[0].pv_data;
86
0
    WORD32 i4_input_stride = ps_input_buf->as_component_bufs[0].i4_data_stride;
87
88
0
    for(i = 0; i < u4_height - 1; i++)
89
0
    {
90
0
        for(j = 0; j < u4_width - 1; j++)
91
0
        {
92
0
            UWORD8 u1_cur_pix = pu1_input_buf[j];
93
0
            UWORD8 u1_bot_pix = pu1_input_buf[i4_input_stride + j];
94
0
            UWORD8 u1_right_pix = pu1_input_buf[j + 1];
95
96
0
            d_gpp_y += (ABS(u1_cur_pix - u1_bot_pix) + ABS(u1_cur_pix - u1_right_pix));
97
0
        }
98
0
        pu1_input_buf += i4_input_stride;
99
0
    }
100
101
0
    pu1_input_buf = (UWORD8 *) ps_input_buf->as_component_bufs[1].pv_data;
102
0
    i4_input_stride = ps_input_buf->as_component_bufs[1].i4_data_stride;
103
104
0
    for(i = 0; i < (u4_height >> 1) - 1; i++)
105
0
    {
106
0
        for(j = 0; j < u4_width - 2; j += 2)
107
0
        {
108
0
            UWORD8 u1_cur_pix = pu1_input_buf[j];
109
0
            UWORD8 u1_bot_pix = pu1_input_buf[i4_input_stride + j];
110
0
            UWORD8 u1_right_pix = pu1_input_buf[j + 2];
111
112
0
            d_gpp_u += (ABS(u1_cur_pix - u1_bot_pix) + ABS(u1_cur_pix - u1_right_pix));
113
114
0
            u1_cur_pix = pu1_input_buf[j + 1];
115
0
            u1_bot_pix = pu1_input_buf[i4_input_stride + j + 1];
116
0
            u1_right_pix = pu1_input_buf[j + 2 + 1];
117
118
0
            d_gpp_v += (ABS(u1_cur_pix - u1_bot_pix) + ABS(u1_cur_pix - u1_right_pix));
119
0
        }
120
0
        pu1_input_buf += i4_input_stride;
121
0
    }
122
123
0
    d_gpp_y /= (u4_width * u4_height);
124
0
    d_gpp_u /= ((u4_width >> 1) * (u4_height >> 1));
125
0
    d_gpp_v /= ((u4_width >> 1) * (u4_height >> 1));
126
127
0
    d_gpp = (DOUBLE) ((4 * d_gpp_y) + d_gpp_u + d_gpp_v) / 6;
128
129
0
    return d_gpp;
130
0
}
131
132
/**
133
*******************************************************************************
134
*
135
* @brief
136
*   gets the memory size required for compute gpp
137
*
138
* @par Description:
139
*   returns the memory required by the rc utils context and state structs
140
*   for allocation.
141
*
142
* @returns
143
*
144
* @remarks
145
*
146
*
147
*******************************************************************************
148
*/
149
150
8.39k
UWORD32 isvce_get_rc_utils_data_size() { return sizeof(svc_rc_utils_state_t); }
151
152
/**
153
*******************************************************************************
154
*
155
* @brief
156
*   compute gpp process
157
*
158
* @par Description:
159
*   calls the function to compute gpp
160
*
161
* @param[in] ps_svc_rc_utils_ctxt
162
*  pointer to svc rc utils context
163
*
164
* @param[in] ps_input_buf
165
*  pointer to yuv buffer properties
166
*
167
* @returns
168
*  calculated gpp value
169
*
170
* @remarks
171
*  none
172
*
173
*******************************************************************************
174
*/
175
176
DOUBLE isvce_compute_gpp(svc_rc_utils_ctxt_t *ps_svc_rc_utils_ctxt, yuv_buf_props_t *ps_input_buf)
177
0
{
178
0
    svc_rc_utils_state_t *ps_rc_utils_state =
179
0
        (svc_rc_utils_state_t *) ps_svc_rc_utils_ctxt->pv_rc_utils_state;
180
181
0
    return ps_rc_utils_state->pf_get_gpp(ps_input_buf);
182
0
}
183
184
/**
185
*******************************************************************************
186
*
187
* @brief
188
*   selects which function to call for get gpp based on e_arch
189
*
190
* @par Description:
191
*
192
* @param[in] ps_rc_utils_state
193
*  pointer to svc rc utils state
194
*
195
* @param[in] e_arch
196
*  architecure type
197
*
198
* @returns
199
*
200
* @remarks
201
*
202
*******************************************************************************
203
*/
204
205
static void isvce_get_gpp_function_selector(svc_rc_utils_state_t *ps_rc_utils_state,
206
                                            IV_ARCH_T e_arch)
207
4.19k
{
208
4.19k
    switch(e_arch)
209
4.19k
    {
210
0
#if defined(X86)
211
1.63k
        case ARCH_X86_SSE42:
212
1.63k
        {
213
1.63k
            ps_rc_utils_state->pf_get_gpp = isvce_get_gpp_sse42;
214
215
1.63k
            break;
216
0
        }
217
#elif defined(ARMV8)
218
        case ARCH_ARM_A53:
219
        case ARCH_ARM_A57:
220
        case ARCH_ARM_V8_NEON:
221
        {
222
            ps_rc_utils_state->pf_get_gpp = isvce_get_gpp_neon;
223
224
            break;
225
        }
226
#elif defined(ARM) && !defined(DISABLE_NEON)
227
        case ARCH_ARM_A9Q:
228
        case ARCH_ARM_A9A:
229
        case ARCH_ARM_A9:
230
        case ARCH_ARM_A7:
231
        case ARCH_ARM_A5:
232
        case ARCH_ARM_A15:
233
        {
234
            ps_rc_utils_state->pf_get_gpp = isvce_get_gpp_neon;
235
236
            break;
237
        }
238
#endif
239
2.56k
        default:
240
2.56k
        {
241
2.56k
            ps_rc_utils_state->pf_get_gpp = isvce_get_gpp;
242
243
2.56k
            break;
244
0
        }
245
4.19k
    }
246
4.19k
}
247
248
/**
249
*******************************************************************************
250
*
251
* @brief
252
*   initializes the rc utils context
253
*
254
* @par Description:
255
*   initializes the rc utils context
256
*
257
* @param[in] ps_svc_rc_utils_ctxt
258
*   pointer to svc rc utils context
259
*
260
* @param[in] ps_mem_rec
261
*   pointer to memory allocated to compute gpp process
262
*
263
* @param[in] e_arch
264
*   architecure type
265
*
266
* @returns
267
*
268
* @remarks
269
*  none
270
*
271
*******************************************************************************
272
*/
273
274
void isvce_rc_utils_init(svc_rc_utils_ctxt_t *ps_svc_rc_utils_ctxt, iv_mem_rec_t *ps_mem_rec,
275
                         IV_ARCH_T e_arch)
276
4.19k
{
277
4.19k
    svc_rc_utils_state_t *ps_rc_utils_state;
278
279
4.19k
    UWORD8 *pu1_buf = (UWORD8 *) ps_mem_rec->pv_base;
280
281
4.19k
    ps_rc_utils_state = (svc_rc_utils_state_t *) pu1_buf;
282
283
4.19k
    ps_svc_rc_utils_ctxt->pv_rc_utils_state = ps_rc_utils_state;
284
285
4.19k
    isvce_get_gpp_function_selector(ps_rc_utils_state, e_arch);
286
4.19k
}