Coverage Report

Created: 2026-01-10 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/decoder/mvc/imvcd_api_utils.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2021 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 Name         : imvcd_api_utils.c                                    */
24
/*                                                                           */
25
/*  Description       : Utility functions used by 'imvcd_api.c'              */
26
/*                                                                           */
27
/*****************************************************************************/
28
#include <string.h>
29
30
#include "ih264_typedefs.h"
31
#include "iv.h"
32
#include "imvcd.h"
33
#include "ih264_disp_mgr.h"
34
#include "ih264d_structs.h"
35
#include "ih264d_tables.h"
36
#include "ih264d_utils.h"
37
#include "imvcd_structs.h"
38
#include "imvcd_utils.h"
39
40
IV_API_CALL_STATUS_T imvcd_check_dec_handle(iv_obj_t *ps_handle)
41
204k
{
42
204k
    if(ps_handle == NULL)
43
0
    {
44
0
        return IV_FAIL;
45
0
    }
46
47
204k
    if(ps_handle->pv_codec_handle == NULL)
48
0
    {
49
0
        return IV_FAIL;
50
0
    }
51
52
204k
    return IV_SUCCESS;
53
204k
}
54
55
IV_API_CALL_STATUS_T imvcd_check_create_structs(imvcd_create_ip_t *ps_ip, imvcd_create_op_t *ps_op)
56
3.73k
{
57
3.73k
    if(NULL == ps_ip)
58
0
    {
59
0
        return IV_FAIL;
60
0
    }
61
62
3.73k
    if(NULL == ps_op)
63
0
    {
64
0
        return IV_FAIL;
65
0
    }
66
67
3.73k
    if(ps_ip->s_ivd_ip.e_output_format != IV_YUV_420P)
68
0
    {
69
0
        return IV_FAIL;
70
0
    }
71
72
3.73k
    if(NULL == ps_ip->s_ivd_ip.pf_aligned_alloc)
73
0
    {
74
0
        return IV_FAIL;
75
0
    }
76
77
3.73k
    if(NULL == ps_ip->s_ivd_ip.pf_aligned_free)
78
0
    {
79
0
        return IV_FAIL;
80
0
    }
81
82
3.73k
    if(0 != ps_ip->s_ivd_ip.u4_share_disp_buf)
83
0
    {
84
0
        return IV_FAIL;
85
0
    }
86
87
3.73k
    return IV_SUCCESS;
88
3.73k
}
89
90
IV_API_CALL_STATUS_T imvcd_check_ctl_structs(void *pv_ip, void *pv_op)
91
105k
{
92
105k
    ivd_ctl_set_config_ip_t *ps_ip = (ivd_ctl_set_config_ip_t *) pv_ip;
93
105k
    ivd_ctl_set_config_op_t *ps_op = (ivd_ctl_set_config_op_t *) pv_op;
94
95
105k
    WORD32 i4_sub_cmd = ps_ip->e_sub_cmd;
96
97
105k
    if(NULL == ps_ip)
98
0
    {
99
0
        return IV_FAIL;
100
0
    }
101
102
105k
    if(NULL == ps_op)
103
0
    {
104
0
        return IV_FAIL;
105
0
    }
106
107
105k
    switch(i4_sub_cmd)
108
105k
    {
109
94.8k
        case IVD_CMD_CTL_SETPARAMS:
110
94.8k
        {
111
94.8k
            if((ps_ip->u4_size != sizeof(ivd_ctl_set_config_ip_t)) ||
112
94.8k
               (ps_op->u4_size != sizeof(ivd_ctl_set_config_op_t)))
113
0
            {
114
0
                return IV_FAIL;
115
0
            }
116
94.8k
            else
117
94.8k
            {
118
94.8k
                return IV_SUCCESS;
119
94.8k
            }
120
94.8k
        }
121
3.73k
        case IMVCD_CTL_SET_NUM_CORES:
122
3.73k
        {
123
3.73k
            if((ps_ip->u4_size != sizeof(imvcd_set_num_cores_ip_t)) ||
124
3.73k
               (ps_op->u4_size != sizeof(imvcd_set_num_cores_op_t)))
125
0
            {
126
0
                return IV_FAIL;
127
0
            }
128
3.73k
            else
129
3.73k
            {
130
3.73k
                return IV_SUCCESS;
131
3.73k
            }
132
3.73k
        }
133
3.73k
        case IMVCD_CTL_SET_PROCESSOR:
134
3.73k
        {
135
3.73k
            if((ps_ip->u4_size != sizeof(imvcd_set_arch_ip_t)) ||
136
3.73k
               (ps_op->u4_size != sizeof(imvcd_set_arch_op_t)))
137
0
            {
138
0
                return IV_FAIL;
139
0
            }
140
3.73k
            else
141
3.73k
            {
142
3.73k
                return IV_SUCCESS;
143
3.73k
            }
144
3.73k
        }
145
0
        case IMVCD_CTL_DEGRADE:
146
0
        {
147
0
            if((ps_ip->u4_size != sizeof(imvcd_set_degrade_mode_ip_t)) ||
148
0
               (ps_op->u4_size != sizeof(imvcd_set_degrade_mode_op_t)))
149
0
            {
150
0
                return IV_FAIL;
151
0
            }
152
0
            else
153
0
            {
154
0
                return IV_SUCCESS;
155
0
            }
156
0
        }
157
0
        case IVD_CMD_CTL_FLUSH:
158
0
        {
159
0
            if((ps_ip->u4_size != sizeof(ivd_ctl_flush_ip_t)) ||
160
0
               (ps_op->u4_size != sizeof(ivd_ctl_flush_op_t)))
161
0
            {
162
0
                return IV_FAIL;
163
0
            }
164
0
            else
165
0
            {
166
0
                return IV_SUCCESS;
167
0
            }
168
0
        }
169
3.67k
        case IVD_CMD_CTL_GETBUFINFO:
170
3.67k
        {
171
3.67k
            if((ps_ip->u4_size != sizeof(ivd_ctl_getbufinfo_ip_t)) ||
172
3.67k
               (ps_op->u4_size != sizeof(ivd_ctl_getbufinfo_op_t)))
173
0
            {
174
0
                return IV_FAIL;
175
0
            }
176
3.67k
            else
177
3.67k
            {
178
3.67k
                return IV_SUCCESS;
179
3.67k
            }
180
3.67k
        }
181
0
        case IMVCD_CTL_GET_VUI_PARAMS:
182
0
        {
183
0
            if((ps_ip->u4_size != sizeof(imvcd_get_vui_ip_t)) ||
184
0
               (ps_op->u4_size != sizeof(imvcd_get_vui_op_t)))
185
0
            {
186
0
                return IV_FAIL;
187
0
            }
188
0
            else
189
0
            {
190
0
                return IV_SUCCESS;
191
0
            }
192
0
        }
193
0
        default:
194
0
        {
195
0
            return IV_FAIL;
196
0
        }
197
105k
    }
198
105k
}
199
200
IV_API_CALL_STATUS_T imvcd_check_decode_structs(iv_obj_t *ps_dec_hdl,
201
                                                imvcd_video_decode_ip_t *ps_ip,
202
                                                imvcd_video_decode_op_t *ps_op)
203
94.8k
{
204
94.8k
    WORD32 i, j;
205
206
94.8k
    mvc_dec_ctxt_t *ps_mvcd_ctxt = (mvc_dec_ctxt_t *) ps_dec_hdl->pv_codec_handle;
207
208
94.8k
    UWORD16 u2_num_views = 1;
209
210
94.8k
    if(NULL == ps_ip)
211
0
    {
212
0
        return IV_FAIL;
213
0
    }
214
215
94.8k
    if(NULL == ps_op)
216
0
    {
217
0
        return IV_FAIL;
218
0
    }
219
220
94.8k
    if(!ps_mvcd_ctxt->b_flush_enabled && !ps_mvcd_ctxt->b_header_only_decode)
221
91.0k
    {
222
91.0k
        if(NULL == ps_ip->s_ivd_ip.pv_stream_buffer)
223
0
        {
224
0
            return IV_FAIL;
225
0
        }
226
227
182k
        for(i = 0; i < u2_num_views; i++)
228
91.0k
        {
229
364k
            for(j = 0; j < NUM_COMPONENTS; j++)
230
273k
            {
231
273k
                if(NULL == ps_ip->s_ivd_ip.s_out_buffer.pu1_bufs[i * NUM_COMPONENTS + j])
232
0
                {
233
0
                    return IV_FAIL;
234
0
                }
235
273k
            }
236
91.0k
        }
237
238
91.0k
        if(0 == ps_ip->s_ivd_ip.u4_num_Bytes)
239
0
        {
240
0
            return IV_FAIL;
241
0
        }
242
91.0k
    }
243
244
94.8k
    return IV_SUCCESS;
245
94.8k
}
246
247
static void imvcd_convert_app_out_buf(mvc_dec_ctxt_t *ps_mvcd_ctxt,
248
                                      ivd_out_bufdesc_t *ps_app_buffer)
249
94.3k
{
250
94.3k
    if(!ps_mvcd_ctxt->b_header_only_decode)
251
90.5k
    {
252
90.5k
        WORD32 i, j;
253
254
90.5k
        subset_sps_t *ps_subset_sps = imvcd_get_valid_subset_sps(ps_mvcd_ctxt);
255
90.5k
        dec_struct_t *ps_view_ctxt = &ps_mvcd_ctxt->s_view_dec_ctxt;
256
257
90.5k
        UWORD16 u2_num_views =
258
90.5k
            (NULL == ps_subset_sps) ? 1 : ps_subset_sps->s_sps_mvc_ext.u2_num_views;
259
260
182k
        for(i = 0; i < u2_num_views; i++)
261
92.4k
        {
262
92.4k
            yuv_buf_props_t *ps_view_buf = &ps_mvcd_ctxt->s_out_buffer.as_view_buf_props[i];
263
264
92.4k
            ps_view_buf->u1_bit_depth = 8;
265
92.4k
            ps_view_buf->u2_height = ps_view_ctxt->u2_disp_height;
266
92.4k
            ps_view_buf->u2_width = ps_view_ctxt->u2_disp_width;
267
268
369k
            for(j = 0; j < NUM_COMPONENTS; j++)
269
277k
            {
270
277k
                buffer_container_t *ps_component_buf = &ps_view_buf->as_component_bufs[j];
271
277k
                bool b_is_chroma = (((COMPONENT_TYPES_T) j) != Y);
272
273
277k
                ps_component_buf->pv_data = ps_app_buffer->pu1_bufs[i * NUM_COMPONENTS + j];
274
277k
                ps_component_buf->i4_data_stride = ps_view_buf->u2_width >> b_is_chroma;
275
277k
            }
276
92.4k
        }
277
90.5k
    }
278
94.3k
}
279
280
void imvcd_convert_to_app_disp_buf(mvc_dec_ctxt_t *ps_mvcd_ctxt, iv_yuv_buf_t *ps_view_disp_bufs)
281
73.4k
{
282
73.4k
    WORD32 i;
283
284
73.4k
    UWORD16 u2_num_views = ps_mvcd_ctxt->u2_num_views;
285
286
148k
    for(i = 0; i < u2_num_views; i++)
287
75.2k
    {
288
75.2k
        yuv_buf_props_t *ps_view_buf = &ps_mvcd_ctxt->s_out_buffer.as_view_buf_props[i];
289
290
75.2k
        ps_view_disp_bufs[i].u4_size = sizeof(ps_view_disp_bufs[i]);
291
292
75.2k
        ps_view_disp_bufs[i].pv_y_buf = ps_view_buf->as_component_bufs[Y].pv_data;
293
75.2k
        ps_view_disp_bufs[i].u4_y_strd = ps_view_buf->as_component_bufs[Y].i4_data_stride;
294
75.2k
        ps_view_disp_bufs[i].u4_y_wd = ps_view_buf->u2_width;
295
75.2k
        ps_view_disp_bufs[i].u4_y_ht = ps_view_buf->u2_height;
296
297
75.2k
        ps_view_disp_bufs[i].pv_u_buf = ps_view_buf->as_component_bufs[U].pv_data;
298
75.2k
        ps_view_disp_bufs[i].u4_u_strd = ps_view_buf->as_component_bufs[U].i4_data_stride;
299
75.2k
        ps_view_disp_bufs[i].u4_u_wd = ps_view_buf->u2_width / 2;
300
75.2k
        ps_view_disp_bufs[i].u4_u_ht = ps_view_buf->u2_height / 2;
301
302
75.2k
        ps_view_disp_bufs[i].pv_v_buf = ps_view_buf->as_component_bufs[V].pv_data;
303
75.2k
        ps_view_disp_bufs[i].u4_v_strd = ps_view_buf->as_component_bufs[V].i4_data_stride;
304
75.2k
        ps_view_disp_bufs[i].u4_v_wd = ps_view_buf->u2_width / 2;
305
75.2k
        ps_view_disp_bufs[i].u4_v_ht = ps_view_buf->u2_height / 2;
306
75.2k
    }
307
73.4k
}
308
309
void imvcd_au_init(iv_obj_t *ps_dec_hdl, imvcd_video_decode_ip_t *ps_ip,
310
                   imvcd_video_decode_op_t *ps_op)
311
94.3k
{
312
94.3k
    subset_sps_t *ps_subset_sps;
313
314
94.3k
    mvc_dec_ctxt_t *ps_mvcd_ctxt = (mvc_dec_ctxt_t *) ps_dec_hdl->pv_codec_handle;
315
94.3k
    dec_struct_t *ps_view_ctxt = &ps_mvcd_ctxt->s_view_dec_ctxt;
316
317
94.3k
    ps_mvcd_ctxt->u2_num_views_decoded = 0;
318
94.3k
    ps_subset_sps = imvcd_get_valid_subset_sps(ps_mvcd_ctxt);
319
94.3k
    ps_mvcd_ctxt->u2_num_views =
320
94.3k
        (NULL == ps_subset_sps) ? 1 : ps_subset_sps->s_sps_mvc_ext.u2_num_views;
321
94.3k
    imvcd_convert_app_out_buf(ps_mvcd_ctxt, &ps_ip->s_ivd_ip.s_out_buffer);
322
323
94.3k
    ps_op->s_ivd_op.u4_num_bytes_consumed = 0;
324
94.3k
    ps_op->s_ivd_op.u4_output_present = 0;
325
94.3k
    ps_op->s_ivd_op.u4_error_code = 0;
326
94.3k
    ps_op->s_ivd_op.e_pic_type = IV_FRAMETYPE_DEFAULT;
327
94.3k
    ps_op->s_ivd_op.u4_frame_decoded_flag = 0;
328
94.3k
    ps_op->s_ivd_op.u4_new_seq = 0;
329
94.3k
    ps_op->s_ivd_op.u4_progressive_frame_flag = 1;
330
94.3k
    ps_op->s_ivd_op.u4_is_ref_flag = 1;
331
94.3k
    ps_op->s_ivd_op.e4_fld_type = IV_NA_FLD;
332
333
94.3k
    ps_view_ctxt->u4_fmt_conv_cur_row = 0;
334
94.3k
    ps_view_ctxt->u4_output_present = 0;
335
94.3k
    ps_view_ctxt->u4_fmt_conv_num_rows = FMT_CONV_NUM_ROWS;
336
94.3k
    ps_view_ctxt->u4_ts = ps_ip->s_ivd_ip.u4_ts;
337
94.3k
    ps_view_ctxt->i4_frametype = IV_NA_FRAME;
338
94.3k
    ps_view_ctxt->i4_content_type = IV_CONTENTTYPE_NA;
339
340
    /* Mimicking the hack in lines '2005' in 'ih264d_api.c' and '1323' in
341
     * 'ih264d_parse_headers.c */
342
94.3k
    ps_view_ctxt->u4_sps_cnt_in_process = 0;
343
344
94.3k
    memset(ps_mvcd_ctxt->as_nalu_mvc_ext, 0, sizeof(ps_mvcd_ctxt->as_nalu_mvc_ext));
345
94.3k
}
346
347
void imvcd_view_init(mvc_dec_ctxt_t *ps_mvcd_ctxt)
348
96.0k
{
349
96.0k
    dec_struct_t *ps_view_ctxt = &ps_mvcd_ctxt->s_view_dec_ctxt;
350
351
96.0k
    ps_view_ctxt->u4_num_fld_in_frm = 0;
352
96.0k
    ps_view_ctxt->u4_slice_start_code_found = 0;
353
96.0k
    ps_view_ctxt->u4_cur_mb_addr = 0;
354
96.0k
    ps_view_ctxt->u4_total_mbs_coded = 0;
355
96.0k
    ps_view_ctxt->u2_cur_slice_num = 0;
356
96.0k
    ps_view_ctxt->cur_dec_mb_num = 0;
357
96.0k
    ps_view_ctxt->cur_recon_mb_num = 0;
358
96.0k
    ps_view_ctxt->u4_first_slice_in_pic = 1;
359
96.0k
    ps_view_ctxt->u1_slice_header_done = 0;
360
96.0k
    ps_view_ctxt->u1_dangling_field = 0;
361
96.0k
    ps_view_ctxt->u4_dec_thread_created = 0;
362
96.0k
    ps_view_ctxt->u4_bs_deblk_thread_created = 0;
363
96.0k
    ps_view_ctxt->u4_cur_bs_mb_num = 0;
364
96.0k
    ps_view_ctxt->u4_start_recon_deblk = 0;
365
96.0k
    ps_view_ctxt->u4_pic_buf_got = 0;
366
96.0k
    ps_view_ctxt->pu1_inv_scan = (UWORD8 *) gau1_ih264d_inv_scan;
367
96.0k
    ps_view_ctxt->u1_pic_decode_done = 0;
368
369
96.0k
    ps_view_ctxt->pu1_init_dpb_base = NULL;
370
96.0k
    ps_view_ctxt->ps_dpb_mgr = NULL;
371
96.0k
}
372
373
IV_API_CALL_STATUS_T imvcd_bitstream_buf_alloc(dec_struct_t *ps_view_ctxt, UWORD16 u2_num_views)
374
3.64k
{
375
3.64k
    UWORD32 u4_size;
376
377
3.64k
    u4_size = MAX(MIN_BITSTREAMS_BUF_SIZE,
378
3.64k
                  ((ps_view_ctxt->u2_pic_wd * ps_view_ctxt->u2_pic_ht * 3 / 2) + EXTRA_BS_OFFSET) *
379
3.64k
                      u2_num_views * sizeof(ps_view_ctxt->pu1_bits_buf_dynamic[0]));
380
3.64k
    ps_view_ctxt->pu1_bits_buf_dynamic =
381
3.64k
        ps_view_ctxt->pf_aligned_alloc(ps_view_ctxt->pv_mem_ctxt, 128, u4_size);
382
3.64k
    RETURN_IF((NULL == ps_view_ctxt->pu1_bits_buf_dynamic), IV_FAIL);
383
384
3.64k
    memset(ps_view_ctxt->pu1_bits_buf_dynamic, 0, u4_size);
385
3.64k
    ps_view_ctxt->u4_dynamic_bits_buf_size = u4_size;
386
387
3.64k
    return IV_SUCCESS;
388
3.64k
}
389
390
void imvcd_bitsteam_buf_free(dec_struct_t *ps_view_ctxt)
391
3.77k
{
392
3.77k
    PS_DEC_ALIGNED_FREE(ps_view_ctxt, ps_view_ctxt->pu1_bits_buf_dynamic);
393
3.77k
}
394
395
IV_API_CALL_STATUS_T imvcd_bitstream_buf_realloc(dec_struct_t *ps_view_ctxt, UWORD32 u4_size)
396
36
{
397
36
    imvcd_bitsteam_buf_free(ps_view_ctxt);
398
399
36
    u4_size = MAX(MIN_BITSTREAMS_BUF_SIZE, u4_size);
400
401
36
    ps_view_ctxt->pu1_bits_buf_dynamic =
402
36
        ps_view_ctxt->pf_aligned_alloc(ps_view_ctxt->pv_mem_ctxt, 128, u4_size);
403
36
    RETURN_IF((NULL == ps_view_ctxt->pu1_bits_buf_dynamic), IV_FAIL);
404
405
36
    memset(ps_view_ctxt->pu1_bits_buf_dynamic, 0, u4_size);
406
36
    ps_view_ctxt->u4_dynamic_bits_buf_size = u4_size;
407
408
36
    return IV_SUCCESS;
409
36
}