Coverage Report

Created: 2024-07-27 06:35

/src/libavc/decoder/mvc/imvcd_api_utils.c
Line
Count
Source (jump to first uncovered line)
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
322k
{
42
322k
    if(ps_handle == NULL)
43
0
    {
44
0
        return IV_FAIL;
45
0
    }
46
47
322k
    if(ps_handle->pv_codec_handle == NULL)
48
0
    {
49
0
        return IV_FAIL;
50
0
    }
51
52
322k
    return IV_SUCCESS;
53
322k
}
54
55
IV_API_CALL_STATUS_T imvcd_check_create_structs(imvcd_create_ip_t *ps_ip, imvcd_create_op_t *ps_op)
56
17.9k
{
57
17.9k
    if(NULL == ps_ip)
58
0
    {
59
0
        return IV_FAIL;
60
0
    }
61
62
17.9k
    if(NULL == ps_op)
63
0
    {
64
0
        return IV_FAIL;
65
0
    }
66
67
17.9k
    if(ps_ip->s_ivd_ip.e_output_format != IV_YUV_420P)
68
0
    {
69
0
        return IV_FAIL;
70
0
    }
71
72
17.9k
    if(NULL == ps_ip->s_ivd_ip.pf_aligned_alloc)
73
0
    {
74
0
        return IV_FAIL;
75
0
    }
76
77
17.9k
    if(NULL == ps_ip->s_ivd_ip.pf_aligned_free)
78
0
    {
79
0
        return IV_FAIL;
80
0
    }
81
82
17.9k
    if(0 != ps_ip->s_ivd_ip.u4_share_disp_buf)
83
0
    {
84
0
        return IV_FAIL;
85
0
    }
86
87
17.9k
    return IV_SUCCESS;
88
17.9k
}
89
90
IV_API_CALL_STATUS_T imvcd_check_ctl_structs(void *pv_ip, void *pv_op)
91
177k
{
92
177k
    ivd_ctl_set_config_ip_t *ps_ip = (ivd_ctl_set_config_ip_t *) pv_ip;
93
177k
    ivd_ctl_set_config_op_t *ps_op = (ivd_ctl_set_config_op_t *) pv_op;
94
95
177k
    WORD32 i4_sub_cmd = ps_ip->e_sub_cmd;
96
97
177k
    if(NULL == ps_ip)
98
0
    {
99
0
        return IV_FAIL;
100
0
    }
101
102
177k
    if(NULL == ps_op)
103
0
    {
104
0
        return IV_FAIL;
105
0
    }
106
107
177k
    switch(i4_sub_cmd)
108
177k
    {
109
126k
        case IVD_CMD_CTL_SETPARAMS:
110
126k
        {
111
126k
            if((ps_ip->u4_size != sizeof(ivd_ctl_set_config_ip_t)) ||
112
126k
               (ps_op->u4_size != sizeof(ivd_ctl_set_config_op_t)))
113
0
            {
114
0
                return IV_FAIL;
115
0
            }
116
126k
            else
117
126k
            {
118
126k
                return IV_SUCCESS;
119
126k
            }
120
126k
        }
121
17.9k
        case IMVCD_CTL_SET_NUM_CORES:
122
17.9k
        {
123
17.9k
            if((ps_ip->u4_size != sizeof(imvcd_set_num_cores_ip_t)) ||
124
17.9k
               (ps_op->u4_size != sizeof(imvcd_set_num_cores_op_t)))
125
0
            {
126
0
                return IV_FAIL;
127
0
            }
128
17.9k
            else
129
17.9k
            {
130
17.9k
                return IV_SUCCESS;
131
17.9k
            }
132
17.9k
        }
133
17.9k
        case IMVCD_CTL_SET_PROCESSOR:
134
17.9k
        {
135
17.9k
            if((ps_ip->u4_size != sizeof(imvcd_set_arch_ip_t)) ||
136
17.9k
               (ps_op->u4_size != sizeof(imvcd_set_arch_op_t)))
137
0
            {
138
0
                return IV_FAIL;
139
0
            }
140
17.9k
            else
141
17.9k
            {
142
17.9k
                return IV_SUCCESS;
143
17.9k
            }
144
17.9k
        }
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
15.2k
        case IVD_CMD_CTL_GETBUFINFO:
170
15.2k
        {
171
15.2k
            if((ps_ip->u4_size != sizeof(ivd_ctl_getbufinfo_ip_t)) ||
172
15.2k
               (ps_op->u4_size != sizeof(ivd_ctl_getbufinfo_op_t)))
173
0
            {
174
0
                return IV_FAIL;
175
0
            }
176
15.2k
            else
177
15.2k
            {
178
15.2k
                return IV_SUCCESS;
179
15.2k
            }
180
15.2k
        }
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
177k
    }
198
177k
}
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
126k
{
204
126k
    WORD32 i, j;
205
206
126k
    mvc_dec_ctxt_t *ps_mvcd_ctxt = (mvc_dec_ctxt_t *) ps_dec_hdl->pv_codec_handle;
207
208
126k
    UWORD16 u2_num_views = 1;
209
210
126k
    if(NULL == ps_ip)
211
0
    {
212
0
        return IV_FAIL;
213
0
    }
214
215
126k
    if(NULL == ps_op)
216
0
    {
217
0
        return IV_FAIL;
218
0
    }
219
220
126k
    if(!ps_mvcd_ctxt->b_flush_enabled && !ps_mvcd_ctxt->b_header_only_decode)
221
108k
    {
222
108k
        if(NULL == ps_ip->s_ivd_ip.pv_stream_buffer)
223
0
        {
224
0
            return IV_FAIL;
225
0
        }
226
227
217k
        for(i = 0; i < u2_num_views; i++)
228
108k
        {
229
435k
            for(j = 0; j < NUM_COMPONENTS; j++)
230
326k
            {
231
326k
                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
326k
            }
236
108k
        }
237
238
108k
        if(0 == ps_ip->s_ivd_ip.u4_num_Bytes)
239
0
        {
240
0
            return IV_FAIL;
241
0
        }
242
108k
    }
243
244
126k
    return IV_SUCCESS;
245
126k
}
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
125k
{
250
125k
    if(!ps_mvcd_ctxt->b_header_only_decode)
251
107k
    {
252
107k
        WORD32 i, j;
253
254
107k
        subset_sps_t *ps_subset_sps = imvcd_get_valid_subset_sps(ps_mvcd_ctxt);
255
107k
        dec_struct_t *ps_view_ctxt = &ps_mvcd_ctxt->s_view_dec_ctxt;
256
257
107k
        UWORD16 u2_num_views =
258
107k
            (NULL == ps_subset_sps) ? 1 : ps_subset_sps->s_sps_mvc_ext.u2_num_views;
259
260
218k
        for(i = 0; i < u2_num_views; i++)
261
110k
        {
262
110k
            yuv_buf_props_t *ps_view_buf = &ps_mvcd_ctxt->s_out_buffer.as_view_buf_props[i];
263
264
110k
            ps_view_buf->u1_bit_depth = 8;
265
110k
            ps_view_buf->u2_height = ps_view_ctxt->u2_disp_height;
266
110k
            ps_view_buf->u2_width = ps_view_ctxt->u2_disp_width;
267
268
442k
            for(j = 0; j < NUM_COMPONENTS; j++)
269
332k
            {
270
332k
                buffer_container_t *ps_component_buf = &ps_view_buf->as_component_bufs[j];
271
332k
                bool b_is_chroma = (((COMPONENT_TYPES_T) j) != Y);
272
273
332k
                ps_component_buf->pv_data = ps_app_buffer->pu1_bufs[i * NUM_COMPONENTS + j];
274
332k
                ps_component_buf->i4_data_stride = ps_view_buf->u2_width >> b_is_chroma;
275
332k
            }
276
110k
        }
277
107k
    }
278
125k
}
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
80.1k
{
282
80.1k
    WORD32 i;
283
284
80.1k
    UWORD16 u2_num_views = ps_mvcd_ctxt->u2_num_views;
285
286
163k
    for(i = 0; i < u2_num_views; i++)
287
82.9k
    {
288
82.9k
        yuv_buf_props_t *ps_view_buf = &ps_mvcd_ctxt->s_out_buffer.as_view_buf_props[i];
289
290
82.9k
        ps_view_disp_bufs[i].u4_size = sizeof(ps_view_disp_bufs[i]);
291
292
82.9k
        ps_view_disp_bufs[i].pv_y_buf = ps_view_buf->as_component_bufs[Y].pv_data;
293
82.9k
        ps_view_disp_bufs[i].u4_y_strd = ps_view_buf->as_component_bufs[Y].i4_data_stride;
294
82.9k
        ps_view_disp_bufs[i].u4_y_wd = ps_view_buf->u2_width;
295
82.9k
        ps_view_disp_bufs[i].u4_y_ht = ps_view_buf->u2_height;
296
297
82.9k
        ps_view_disp_bufs[i].pv_u_buf = ps_view_buf->as_component_bufs[U].pv_data;
298
82.9k
        ps_view_disp_bufs[i].u4_u_strd = ps_view_buf->as_component_bufs[U].i4_data_stride;
299
82.9k
        ps_view_disp_bufs[i].u4_u_wd = ps_view_buf->u2_width / 2;
300
82.9k
        ps_view_disp_bufs[i].u4_u_ht = ps_view_buf->u2_height / 2;
301
302
82.9k
        ps_view_disp_bufs[i].pv_v_buf = ps_view_buf->as_component_bufs[V].pv_data;
303
82.9k
        ps_view_disp_bufs[i].u4_v_strd = ps_view_buf->as_component_bufs[V].i4_data_stride;
304
82.9k
        ps_view_disp_bufs[i].u4_v_wd = ps_view_buf->u2_width / 2;
305
82.9k
        ps_view_disp_bufs[i].u4_v_ht = ps_view_buf->u2_height / 2;
306
82.9k
    }
307
80.1k
}
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
125k
{
312
125k
    subset_sps_t *ps_subset_sps;
313
314
125k
    mvc_dec_ctxt_t *ps_mvcd_ctxt = (mvc_dec_ctxt_t *) ps_dec_hdl->pv_codec_handle;
315
125k
    dec_struct_t *ps_view_ctxt = &ps_mvcd_ctxt->s_view_dec_ctxt;
316
317
125k
    ps_mvcd_ctxt->u2_num_views_decoded = 0;
318
125k
    ps_subset_sps = imvcd_get_valid_subset_sps(ps_mvcd_ctxt);
319
125k
    ps_mvcd_ctxt->u2_num_views =
320
125k
        (NULL == ps_subset_sps) ? 1 : ps_subset_sps->s_sps_mvc_ext.u2_num_views;
321
125k
    imvcd_convert_app_out_buf(ps_mvcd_ctxt, &ps_ip->s_ivd_ip.s_out_buffer);
322
323
125k
    ps_op->s_ivd_op.u4_num_bytes_consumed = 0;
324
125k
    ps_op->s_ivd_op.u4_output_present = 0;
325
125k
    ps_op->s_ivd_op.u4_error_code = 0;
326
125k
    ps_op->s_ivd_op.e_pic_type = IV_FRAMETYPE_DEFAULT;
327
125k
    ps_op->s_ivd_op.u4_frame_decoded_flag = 0;
328
125k
    ps_op->s_ivd_op.u4_new_seq = 0;
329
125k
    ps_op->s_ivd_op.u4_progressive_frame_flag = 1;
330
125k
    ps_op->s_ivd_op.u4_is_ref_flag = 1;
331
125k
    ps_op->s_ivd_op.e4_fld_type = IV_NA_FLD;
332
333
125k
    ps_view_ctxt->u4_fmt_conv_cur_row = 0;
334
125k
    ps_view_ctxt->u4_output_present = 0;
335
125k
    ps_view_ctxt->u4_fmt_conv_num_rows = FMT_CONV_NUM_ROWS;
336
125k
    ps_view_ctxt->u4_ts = ps_ip->s_ivd_ip.u4_ts;
337
125k
    ps_view_ctxt->i4_frametype = IV_NA_FRAME;
338
125k
    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
125k
    ps_view_ctxt->u4_sps_cnt_in_process = 0;
343
344
125k
    memset(ps_mvcd_ctxt->as_nalu_mvc_ext, 0, sizeof(ps_mvcd_ctxt->as_nalu_mvc_ext));
345
125k
}
346
347
void imvcd_view_init(mvc_dec_ctxt_t *ps_mvcd_ctxt)
348
128k
{
349
128k
    dec_struct_t *ps_view_ctxt = &ps_mvcd_ctxt->s_view_dec_ctxt;
350
351
128k
    ps_view_ctxt->u4_num_fld_in_frm = 0;
352
128k
    ps_view_ctxt->u4_slice_start_code_found = 0;
353
128k
    ps_view_ctxt->u2_cur_mb_addr = 0;
354
128k
    ps_view_ctxt->u2_total_mbs_coded = 0;
355
128k
    ps_view_ctxt->u2_cur_slice_num = 0;
356
128k
    ps_view_ctxt->cur_dec_mb_num = 0;
357
128k
    ps_view_ctxt->cur_recon_mb_num = 0;
358
128k
    ps_view_ctxt->u4_first_slice_in_pic = 1;
359
128k
    ps_view_ctxt->u1_slice_header_done = 0;
360
128k
    ps_view_ctxt->u1_dangling_field = 0;
361
128k
    ps_view_ctxt->u4_dec_thread_created = 0;
362
128k
    ps_view_ctxt->u4_bs_deblk_thread_created = 0;
363
128k
    ps_view_ctxt->u4_cur_bs_mb_num = 0;
364
128k
    ps_view_ctxt->u4_start_recon_deblk = 0;
365
128k
    ps_view_ctxt->u4_pic_buf_got = 0;
366
128k
    ps_view_ctxt->pu1_inv_scan = (UWORD8 *) gau1_ih264d_inv_scan;
367
128k
    ps_view_ctxt->u1_pic_decode_done = 0;
368
369
128k
    ps_view_ctxt->pu1_init_dpb_base = NULL;
370
128k
    ps_view_ctxt->ps_dpb_mgr = NULL;
371
128k
}
372
373
IV_API_CALL_STATUS_T imvcd_bitstream_buf_alloc(dec_struct_t *ps_view_ctxt, UWORD16 u2_num_views)
374
15.0k
{
375
15.0k
    UWORD32 u4_size;
376
377
15.0k
    u4_size = MAX(MIN_BITSTREAMS_BUF_SIZE,
378
15.0k
                  ((ps_view_ctxt->u2_pic_wd * ps_view_ctxt->u2_pic_ht * 3 / 2) + EXTRA_BS_OFFSET) *
379
15.0k
                      u2_num_views * sizeof(ps_view_ctxt->pu1_bits_buf_dynamic[0]));
380
15.0k
    ps_view_ctxt->pu1_bits_buf_dynamic =
381
15.0k
        ps_view_ctxt->pf_aligned_alloc(ps_view_ctxt->pv_mem_ctxt, 128, u4_size);
382
15.0k
    RETURN_IF((NULL == ps_view_ctxt->pu1_bits_buf_dynamic), IV_FAIL);
383
384
15.0k
    memset(ps_view_ctxt->pu1_bits_buf_dynamic, 0, u4_size);
385
15.0k
    ps_view_ctxt->u4_dynamic_bits_buf_size = u4_size;
386
387
15.0k
    return IV_SUCCESS;
388
15.0k
}
389
390
void imvcd_bitsteam_buf_free(dec_struct_t *ps_view_ctxt)
391
17.9k
{
392
17.9k
    PS_DEC_ALIGNED_FREE(ps_view_ctxt, ps_view_ctxt->pu1_bits_buf_dynamic);
393
17.9k
}
394
395
IV_API_CALL_STATUS_T imvcd_bitstream_buf_realloc(dec_struct_t *ps_view_ctxt, UWORD32 u4_size)
396
60
{
397
60
    imvcd_bitsteam_buf_free(ps_view_ctxt);
398
399
60
    u4_size = MAX(MIN_BITSTREAMS_BUF_SIZE, u4_size);
400
401
60
    ps_view_ctxt->pu1_bits_buf_dynamic =
402
60
        ps_view_ctxt->pf_aligned_alloc(ps_view_ctxt->pv_mem_ctxt, 128, u4_size);
403
60
    RETURN_IF((NULL == ps_view_ctxt->pu1_bits_buf_dynamic), IV_FAIL);
404
405
60
    memset(ps_view_ctxt->pu1_bits_buf_dynamic, 0, u4_size);
406
60
    ps_view_ctxt->u4_dynamic_bits_buf_size = u4_size;
407
408
60
    return IV_SUCCESS;
409
60
}