Coverage Report

Created: 2026-12-01 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/decoder/ih264d_api.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 Name         : ih264d_api.c                                         */
24
/*                                                                           */
25
/*  Description       : Has all  API related functions                       */
26
/*                                                                           */
27
/*                                                                           */
28
/*  List of Functions : api_check_struct_sanity                              */
29
/*          ih264d_set_processor                                             */
30
/*          ih264d_create                                                    */
31
/*          ih264d_delete                                                    */
32
/*          ih264d_init                                                      */
33
/*          ih264d_map_error                                                 */
34
/*          ih264d_video_decode                                              */
35
/*          ih264d_get_version                                               */
36
/*          ih264d_get_display_frame                                         */
37
/*          ih264d_set_display_frame                                         */
38
/*          ih264d_set_flush_mode                                            */
39
/*          ih264d_get_status                                                */
40
/*          ih264d_get_buf_info                                              */
41
/*          ih264d_set_params                                                */
42
/*          ih264d_set_default_params                                        */
43
/*          ih264d_reset                                                     */
44
/*          ih264d_ctl                                                       */
45
/*          ih264d_rel_display_frame                                         */
46
/*          ih264d_set_degrade                                               */
47
/*          ih264d_get_frame_dimensions                                      */
48
/*          ih264d_set_num_cores                                             */
49
/*          ih264d_fill_output_struct_from_context                           */
50
/*          ih264d_api_function                                              */
51
/*                                                                           */
52
/*  Issues / Problems : None                                                 */
53
/*                                                                           */
54
/*  Revision History  :                                                      */
55
/*                                                                           */
56
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
57
/*         14 10 2008   100356(SKV)     Draft                                */
58
/*                                                                           */
59
/*****************************************************************************/
60
#include "ih264_typedefs.h"
61
#include "ih264_macros.h"
62
#include "ih264_platform_macros.h"
63
#include "ih264d_tables.h"
64
#include "iv.h"
65
#include "ivd.h"
66
#include "ih264d.h"
67
#include "ih264d_defs.h"
68
69
#include <string.h>
70
#include <limits.h>
71
#include <stddef.h>
72
73
#include "ih264d_inter_pred.h"
74
75
#include "ih264d_structs.h"
76
#include "ih264d_nal.h"
77
#include "ih264d_error_handler.h"
78
79
#include "ih264d_defs.h"
80
81
#include "ithread.h"
82
#include "ih264d_parse_slice.h"
83
#include "ih264d_function_selector.h"
84
#include "ih264_error.h"
85
#include "ih264_disp_mgr.h"
86
#include "ih264_buf_mgr.h"
87
#include "ih264d_deblocking.h"
88
#include "ih264d_parse_cavlc.h"
89
#include "ih264d_parse_cabac.h"
90
#include "ih264d_utils.h"
91
#include "ih264d_format_conv.h"
92
#include "ih264d_parse_headers.h"
93
#include "ih264d_thread_compute_bs.h"
94
#include <assert.h>
95
96
97
/*********************/
98
/* Codec Versioning  */
99
/*********************/
100
//Move this to where it is used
101
#define CODEC_NAME              "H264VDEC"
102
#define CODEC_RELEASE_TYPE      "production"
103
#define CODEC_RELEASE_VER       "05.00"
104
#define CODEC_VENDOR            "ITTIAM"
105
0
#define MAXVERSION_STRLEN       511
106
#ifdef ANDROID
107
#define VERSION(version_string, codec_name, codec_release_type, codec_release_ver, codec_vendor)    \
108
    snprintf(version_string, MAXVERSION_STRLEN,                                                     \
109
             "@(#)Id:%s_%s Ver:%s Released by %s",                                                  \
110
             codec_name, codec_release_type, codec_release_ver, codec_vendor)
111
#else
112
#define VERSION(version_string, codec_name, codec_release_type, codec_release_ver, codec_vendor)    \
113
0
    snprintf(version_string, MAXVERSION_STRLEN,                                                     \
114
0
             "@(#)Id:%s_%s Ver:%s Released by %s Build: %s @ %s",                                   \
115
0
             codec_name, codec_release_type, codec_release_ver, codec_vendor, __DATE__, __TIME__)
116
#endif
117
118
119
0
#define MIN_IN_BUFS             1
120
71.2k
#define MIN_OUT_BUFS_420        3
121
0
#define MIN_OUT_BUFS_422ILE     1
122
0
#define MIN_OUT_BUFS_RGB565     1
123
79.1k
#define MIN_OUT_BUFS_420SP      2
124
125
#define NUM_FRAMES_LIMIT_ENABLED 0
126
127
#if NUM_FRAMES_LIMIT_ENABLED
128
#define NUM_FRAMES_LIMIT 10000
129
#else
130
0
#define NUM_FRAMES_LIMIT 0x7FFFFFFF
131
#endif
132
133
134
UWORD32 ih264d_get_extra_mem_external(UWORD32 width, UWORD32 height);
135
WORD32 ih264d_get_frame_dimensions(iv_obj_t *dec_hdl,
136
                                   void *pv_api_ip,
137
                                   void *pv_api_op);
138
WORD32 ih264d_get_vui_params(iv_obj_t *dec_hdl,
139
                             void *pv_api_ip,
140
                             void *pv_api_op);
141
142
WORD32 ih264d_get_sei_mdcv_params(iv_obj_t *dec_hdl,
143
                                  void *pv_api_ip,
144
                                  void *pv_api_op);
145
146
WORD32 ih264d_get_sei_cll_params(iv_obj_t *dec_hdl,
147
                                 void *pv_api_ip,
148
                                 void *pv_api_op);
149
150
WORD32 ih264d_get_sei_ave_params(iv_obj_t *dec_hdl,
151
                                 void *pv_api_ip,
152
                                 void *pv_api_op);
153
154
WORD32 ih264d_get_sei_ccv_params(iv_obj_t *dec_hdl,
155
                                 void *pv_api_ip,
156
                                 void *pv_api_op);
157
158
WORD32 ih264d_get_sei_sii_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
159
160
WORD32 ih264d_get_sei_fgc_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
161
162
WORD32 ih264d_set_num_cores(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
163
164
WORD32 ih264d_deblock_display(dec_struct_t *ps_dec);
165
166
void ih264d_signal_decode_thread(dec_struct_t *ps_dec);
167
168
void ih264d_signal_bs_deblk_thread(dec_struct_t *ps_dec);
169
void ih264d_decode_picture_thread(dec_struct_t *ps_dec);
170
171
WORD32 ih264d_set_degrade(iv_obj_t *ps_codec_obj,
172
                          void *pv_api_ip,
173
                          void *pv_api_op);
174
175
void ih264d_fill_output_struct_from_context(dec_struct_t *ps_dec,
176
                                            ivd_video_decode_op_t *ps_dec_op);
177
178
/*!
179
 **************************************************************************
180
 * \if Function name : ih264d_export_sei_params \endif
181
 *
182
 * \brief
183
 *    Exports sei params from decoder to application.
184
 *
185
 * \return
186
 *    0 on Success and error code otherwise
187
 **************************************************************************
188
 */
189
190
void ih264d_export_sei_params(ivd_sei_decode_op_t *ps_sei_decode_op, dec_struct_t *ps_dec)
191
216k
{
192
216k
    WORD32 i4_status = IV_SUCCESS;
193
216k
    sei *ps_sei = (sei *)ps_dec->pv_disp_sei_params;
194
195
216k
    i4_status = ih264d_export_sei_mdcv_params(ps_sei_decode_op, ps_sei, &ps_dec->s_sei_export);
196
216k
    i4_status = ih264d_export_sei_cll_params(ps_sei_decode_op, ps_sei, &ps_dec->s_sei_export);
197
216k
    i4_status = ih264d_export_sei_ave_params(ps_sei_decode_op, ps_sei, &ps_dec->s_sei_export);
198
216k
    i4_status = ih264d_export_sei_ccv_params(ps_sei_decode_op, ps_sei, &ps_dec->s_sei_export);
199
216k
    i4_status = ih264d_export_sei_sii_params(ps_sei_decode_op, ps_sei, &ps_dec->s_sei_export);
200
216k
    i4_status = ih264d_export_sei_fgc_params(ps_sei_decode_op, ps_sei, &ps_dec->s_sei_export);
201
202
216k
    UNUSED(i4_status);
203
216k
}
204
205
static IV_API_CALL_STATUS_T api_check_struct_sanity(iv_obj_t *ps_handle,
206
                                                    void *pv_api_ip,
207
                                                    void *pv_api_op)
208
0
{
209
0
    IVD_API_COMMAND_TYPE_T e_cmd;
210
0
    UWORD32 *pu4_api_ip;
211
0
    UWORD32 *pu4_api_op;
212
0
    UWORD32 i, j;
213
214
0
    if(NULL == pv_api_op)
215
0
        return (IV_FAIL);
216
217
0
    if(NULL == pv_api_ip)
218
0
        return (IV_FAIL);
219
220
0
    pu4_api_ip = (UWORD32 *)pv_api_ip;
221
0
    pu4_api_op = (UWORD32 *)pv_api_op;
222
0
    e_cmd = *(pu4_api_ip + 1);
223
224
    /* error checks on handle */
225
0
    switch((WORD32)e_cmd)
226
0
    {
227
0
        case IVD_CMD_CREATE:
228
0
            break;
229
230
0
        case IVD_CMD_REL_DISPLAY_FRAME:
231
0
        case IVD_CMD_SET_DISPLAY_FRAME:
232
0
        case IVD_CMD_GET_DISPLAY_FRAME:
233
0
        case IVD_CMD_VIDEO_DECODE:
234
0
        case IVD_CMD_DELETE:
235
0
        case IVD_CMD_VIDEO_CTL:
236
0
            if(ps_handle == NULL)
237
0
            {
238
0
                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
239
0
                *(pu4_api_op + 1) |= IVD_HANDLE_NULL;
240
0
                return IV_FAIL;
241
0
            }
242
243
0
            if(ps_handle->u4_size != sizeof(iv_obj_t))
244
0
            {
245
0
                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
246
0
                *(pu4_api_op + 1) |= IVD_HANDLE_STRUCT_SIZE_INCORRECT;
247
0
                return IV_FAIL;
248
0
            }
249
250
0
            if(ps_handle->pv_fxns != ih264d_api_function)
251
0
            {
252
0
                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
253
0
                *(pu4_api_op + 1) |= IVD_INVALID_HANDLE_NULL;
254
0
                return IV_FAIL;
255
0
            }
256
257
0
            if(ps_handle->pv_codec_handle == NULL)
258
0
            {
259
0
                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
260
0
                *(pu4_api_op + 1) |= IVD_INVALID_HANDLE_NULL;
261
0
                return IV_FAIL;
262
0
            }
263
0
            break;
264
0
        default:
265
0
            *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
266
0
            *(pu4_api_op + 1) |= IVD_INVALID_API_CMD;
267
0
            return IV_FAIL;
268
0
    }
269
270
0
    switch((WORD32)e_cmd)
271
0
    {
272
0
        case IVD_CMD_CREATE:
273
0
        {
274
0
            ih264d_create_ip_t *ps_ip = (ih264d_create_ip_t *)pv_api_ip;
275
0
            ih264d_create_op_t *ps_op = (ih264d_create_op_t *)pv_api_op;
276
277
278
0
            ps_op->s_ivd_create_op_t.u4_error_code = 0;
279
280
0
            if((ps_ip->s_ivd_create_ip_t.u4_size > sizeof(ih264d_create_ip_t))
281
0
                            || (ps_ip->s_ivd_create_ip_t.u4_size
282
0
                                            < sizeof(ivd_create_ip_t)))
283
0
            {
284
0
                ps_op->s_ivd_create_op_t.u4_error_code |= 1
285
0
                                << IVD_UNSUPPORTEDPARAM;
286
0
                ps_op->s_ivd_create_op_t.u4_error_code |=
287
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
288
0
                H264_DEC_DEBUG_PRINT("\n");
289
0
                return (IV_FAIL);
290
0
            }
291
292
0
            if((ps_op->s_ivd_create_op_t.u4_size != sizeof(ih264d_create_op_t))
293
0
                            && (ps_op->s_ivd_create_op_t.u4_size
294
0
                                            != sizeof(ivd_create_op_t)))
295
0
            {
296
0
                ps_op->s_ivd_create_op_t.u4_error_code |= 1
297
0
                                << IVD_UNSUPPORTEDPARAM;
298
0
                ps_op->s_ivd_create_op_t.u4_error_code |=
299
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
300
0
                H264_DEC_DEBUG_PRINT("\n");
301
0
                return (IV_FAIL);
302
0
            }
303
304
305
0
            if((ps_ip->s_ivd_create_ip_t.e_output_format != IV_YUV_420P)
306
0
                            && (ps_ip->s_ivd_create_ip_t.e_output_format
307
0
                                            != IV_YUV_422ILE)
308
0
                            && (ps_ip->s_ivd_create_ip_t.e_output_format
309
0
                                            != IV_RGB_565)
310
0
                            && (ps_ip->s_ivd_create_ip_t.e_output_format
311
0
                                            != IV_YUV_420SP_UV)
312
0
                            && (ps_ip->s_ivd_create_ip_t.e_output_format
313
0
                                            != IV_YUV_420SP_VU))
314
0
            {
315
0
                ps_op->s_ivd_create_op_t.u4_error_code |= 1
316
0
                                << IVD_UNSUPPORTEDPARAM;
317
0
                ps_op->s_ivd_create_op_t.u4_error_code |=
318
0
                                IVD_INIT_DEC_COL_FMT_NOT_SUPPORTED;
319
0
                H264_DEC_DEBUG_PRINT("\n");
320
0
                return (IV_FAIL);
321
0
            }
322
323
0
        }
324
0
            break;
325
326
0
        case IVD_CMD_GET_DISPLAY_FRAME:
327
0
        {
328
0
            ih264d_get_display_frame_ip_t *ps_ip =
329
0
                            (ih264d_get_display_frame_ip_t *)pv_api_ip;
330
0
            ih264d_get_display_frame_op_t *ps_op =
331
0
                            (ih264d_get_display_frame_op_t *)pv_api_op;
332
333
0
            ps_op->s_ivd_get_display_frame_op_t.u4_error_code = 0;
334
335
0
            if((ps_ip->s_ivd_get_display_frame_ip_t.u4_size
336
0
                            != sizeof(ih264d_get_display_frame_ip_t))
337
0
                            && (ps_ip->s_ivd_get_display_frame_ip_t.u4_size
338
0
                                            != sizeof(ivd_get_display_frame_ip_t)))
339
0
            {
340
0
                ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1
341
0
                                << IVD_UNSUPPORTEDPARAM;
342
0
                ps_op->s_ivd_get_display_frame_op_t.u4_error_code |=
343
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
344
0
                return (IV_FAIL);
345
0
            }
346
347
0
            if((ps_op->s_ivd_get_display_frame_op_t.u4_size
348
0
                            != sizeof(ih264d_get_display_frame_op_t))
349
0
                            && (ps_op->s_ivd_get_display_frame_op_t.u4_size
350
0
                                            != sizeof(ivd_get_display_frame_op_t)))
351
0
            {
352
0
                ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1
353
0
                                << IVD_UNSUPPORTEDPARAM;
354
0
                ps_op->s_ivd_get_display_frame_op_t.u4_error_code |=
355
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
356
0
                return (IV_FAIL);
357
0
            }
358
0
        }
359
0
            break;
360
361
0
        case IVD_CMD_REL_DISPLAY_FRAME:
362
0
        {
363
0
            ih264d_rel_display_frame_ip_t *ps_ip =
364
0
                            (ih264d_rel_display_frame_ip_t *)pv_api_ip;
365
0
            ih264d_rel_display_frame_op_t *ps_op =
366
0
                            (ih264d_rel_display_frame_op_t *)pv_api_op;
367
368
0
            ps_op->s_ivd_rel_display_frame_op_t.u4_error_code = 0;
369
370
0
            if((ps_ip->s_ivd_rel_display_frame_ip_t.u4_size
371
0
                            != sizeof(ih264d_rel_display_frame_ip_t))
372
0
                            && (ps_ip->s_ivd_rel_display_frame_ip_t.u4_size
373
0
                                            != sizeof(ivd_rel_display_frame_ip_t)))
374
0
            {
375
0
                ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |= 1
376
0
                                << IVD_UNSUPPORTEDPARAM;
377
0
                ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |=
378
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
379
0
                return (IV_FAIL);
380
0
            }
381
382
0
            if((ps_op->s_ivd_rel_display_frame_op_t.u4_size
383
0
                            != sizeof(ih264d_rel_display_frame_op_t))
384
0
                            && (ps_op->s_ivd_rel_display_frame_op_t.u4_size
385
0
                                            != sizeof(ivd_rel_display_frame_op_t)))
386
0
            {
387
0
                ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |= 1
388
0
                                << IVD_UNSUPPORTEDPARAM;
389
0
                ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |=
390
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
391
0
                return (IV_FAIL);
392
0
            }
393
394
            /* u4_disp_buf_id indexes u4_disp_buf_mapping[] and              */
395
            /* u4_disp_buf_to_be_freed[], both MAX_DISP_BUFS_NEW entries     */
396
0
            if(ps_ip->s_ivd_rel_display_frame_ip_t.u4_disp_buf_id
397
0
                            >= MAX_DISP_BUFS_NEW)
398
0
            {
399
0
                ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |= 1
400
0
                                << IVD_UNSUPPORTEDPARAM;
401
0
                return (IV_FAIL);
402
0
            }
403
404
0
        }
405
0
            break;
406
407
0
        case IVD_CMD_SET_DISPLAY_FRAME:
408
0
        {
409
0
            ih264d_set_display_frame_ip_t *ps_ip =
410
0
                            (ih264d_set_display_frame_ip_t *)pv_api_ip;
411
0
            ih264d_set_display_frame_op_t *ps_op =
412
0
                            (ih264d_set_display_frame_op_t *)pv_api_op;
413
0
            UWORD32 j;
414
415
0
            ps_op->s_ivd_set_display_frame_op_t.u4_error_code = 0;
416
417
0
            if((ps_ip->s_ivd_set_display_frame_ip_t.u4_size
418
0
                            != sizeof(ih264d_set_display_frame_ip_t))
419
0
                            && (ps_ip->s_ivd_set_display_frame_ip_t.u4_size
420
0
                                            != sizeof(ivd_set_display_frame_ip_t)))
421
0
            {
422
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
423
0
                                << IVD_UNSUPPORTEDPARAM;
424
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
425
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
426
0
                return (IV_FAIL);
427
0
            }
428
429
0
            if((ps_op->s_ivd_set_display_frame_op_t.u4_size
430
0
                            != sizeof(ih264d_set_display_frame_op_t))
431
0
                            && (ps_op->s_ivd_set_display_frame_op_t.u4_size
432
0
                                            != sizeof(ivd_set_display_frame_op_t)))
433
0
            {
434
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
435
0
                                << IVD_UNSUPPORTEDPARAM;
436
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
437
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
438
0
                return (IV_FAIL);
439
0
            }
440
441
0
            if(ps_ip->s_ivd_set_display_frame_ip_t.num_disp_bufs == 0)
442
0
            {
443
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
444
0
                                << IVD_UNSUPPORTEDPARAM;
445
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
446
0
                                IVD_DISP_FRM_ZERO_OP_BUFS;
447
0
                return IV_FAIL;
448
0
            }
449
450
0
            for(j = 0; j < ps_ip->s_ivd_set_display_frame_ip_t.num_disp_bufs;
451
0
                            j++)
452
0
            {
453
0
                if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].u4_num_bufs
454
0
                                == 0)
455
0
                {
456
0
                    ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
457
0
                                    << IVD_UNSUPPORTEDPARAM;
458
0
                    ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
459
0
                                    IVD_DISP_FRM_ZERO_OP_BUFS;
460
0
                    return IV_FAIL;
461
0
                }
462
463
0
                for(i = 0;
464
0
                                i
465
0
                                                < ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].u4_num_bufs;
466
0
                                i++)
467
0
                {
468
0
                    if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].pu1_bufs[i]
469
0
                                    == NULL)
470
0
                    {
471
0
                        ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
472
0
                                        << IVD_UNSUPPORTEDPARAM;
473
0
                        ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
474
0
                                        IVD_DISP_FRM_OP_BUF_NULL;
475
0
                        return IV_FAIL;
476
0
                    }
477
478
0
                    if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].u4_min_out_buf_size[i]
479
0
                                    == 0)
480
0
                    {
481
0
                        ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
482
0
                                        << IVD_UNSUPPORTEDPARAM;
483
0
                        ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
484
0
                                        IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
485
0
                        return IV_FAIL;
486
0
                    }
487
0
                }
488
0
            }
489
0
        }
490
0
            break;
491
492
0
        case IVD_CMD_VIDEO_DECODE:
493
0
        {
494
0
            ih264d_video_decode_ip_t *ps_ip =
495
0
                            (ih264d_video_decode_ip_t *)pv_api_ip;
496
0
            ih264d_video_decode_op_t *ps_op =
497
0
                            (ih264d_video_decode_op_t *)pv_api_op;
498
499
0
            H264_DEC_DEBUG_PRINT("The input bytes is: %d",
500
0
                                 ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes);
501
0
            ps_op->s_ivd_video_decode_op_t.u4_error_code = 0;
502
503
0
            if(ps_ip->s_ivd_video_decode_ip_t.u4_size != sizeof(ih264d_video_decode_ip_t) &&
504
0
               ps_ip->s_ivd_video_decode_ip_t.u4_size != sizeof(ivd_video_decode_ip_t) &&
505
0
               ps_ip->s_ivd_video_decode_ip_t.u4_size !=
506
0
                   offsetof(ivd_video_decode_ip_t, s_out_buffer))
507
0
            {
508
0
                ps_op->s_ivd_video_decode_op_t.u4_error_code |= 1
509
0
                                << IVD_UNSUPPORTEDPARAM;
510
0
                ps_op->s_ivd_video_decode_op_t.u4_error_code |=
511
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
512
0
                return (IV_FAIL);
513
0
            }
514
515
0
            if(ps_op->s_ivd_video_decode_op_t.u4_size != sizeof(ih264d_video_decode_op_t) &&
516
0
               ps_op->s_ivd_video_decode_op_t.u4_size != sizeof(ivd_video_decode_op_t) &&
517
0
               ps_op->s_ivd_video_decode_op_t.u4_size !=
518
0
                   offsetof(ivd_video_decode_op_t, u4_output_present))
519
0
            {
520
0
                ps_op->s_ivd_video_decode_op_t.u4_error_code |= 1
521
0
                                << IVD_UNSUPPORTEDPARAM;
522
0
                ps_op->s_ivd_video_decode_op_t.u4_error_code |=
523
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
524
0
                return (IV_FAIL);
525
0
            }
526
527
0
            {
528
0
                dec_struct_t *ps_dec = (dec_struct_t *)(ps_handle->pv_codec_handle);
529
0
                if(ps_dec->u1_enable_mb_info)
530
0
                {
531
0
                    if(!ps_ip->pu1_8x8_blk_qp_map && !ps_ip->pu1_8x8_blk_type_map)
532
0
                    {
533
0
                        ps_op->s_ivd_video_decode_op_t.u4_error_code |= 1
534
0
                                        << IVD_UNSUPPORTEDPARAM;
535
0
                        ps_op->s_ivd_video_decode_op_t.u4_error_code |=
536
0
                                        IH264D_FRAME_INFO_OP_BUF_NULL;
537
0
                        return IV_FAIL;
538
0
                    }
539
0
                }
540
0
            }
541
0
        }
542
0
            break;
543
544
0
        case IVD_CMD_DELETE:
545
0
        {
546
0
            ih264d_delete_ip_t *ps_ip =
547
0
                            (ih264d_delete_ip_t *)pv_api_ip;
548
0
            ih264d_delete_op_t *ps_op =
549
0
                            (ih264d_delete_op_t *)pv_api_op;
550
551
0
            ps_op->s_ivd_delete_op_t.u4_error_code = 0;
552
553
0
            if(ps_ip->s_ivd_delete_ip_t.u4_size
554
0
                            != sizeof(ih264d_delete_ip_t))
555
0
            {
556
0
                ps_op->s_ivd_delete_op_t.u4_error_code |= 1
557
0
                                << IVD_UNSUPPORTEDPARAM;
558
0
                ps_op->s_ivd_delete_op_t.u4_error_code |=
559
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
560
0
                return (IV_FAIL);
561
0
            }
562
563
0
            if(ps_op->s_ivd_delete_op_t.u4_size
564
0
                            != sizeof(ih264d_delete_op_t))
565
0
            {
566
0
                ps_op->s_ivd_delete_op_t.u4_error_code |= 1
567
0
                                << IVD_UNSUPPORTEDPARAM;
568
0
                ps_op->s_ivd_delete_op_t.u4_error_code |=
569
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
570
0
                return (IV_FAIL);
571
0
            }
572
573
0
        }
574
0
            break;
575
576
0
        case IVD_CMD_VIDEO_CTL:
577
0
        {
578
0
            UWORD32 *pu4_ptr_cmd;
579
0
            UWORD32 sub_command;
580
581
0
            pu4_ptr_cmd = (UWORD32 *)pv_api_ip;
582
0
            pu4_ptr_cmd += 2;
583
0
            sub_command = *pu4_ptr_cmd;
584
585
0
            switch(sub_command)
586
0
            {
587
0
                case IVD_CMD_CTL_SETPARAMS:
588
0
                {
589
0
                    ih264d_ctl_set_config_ip_t *ps_ip;
590
0
                    ih264d_ctl_set_config_op_t *ps_op;
591
0
                    ps_ip = (ih264d_ctl_set_config_ip_t *)pv_api_ip;
592
0
                    ps_op = (ih264d_ctl_set_config_op_t *)pv_api_op;
593
594
0
                    if(ps_ip->s_ivd_ctl_set_config_ip_t.u4_size
595
0
                                    != sizeof(ih264d_ctl_set_config_ip_t))
596
0
                    {
597
0
                        ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |= 1
598
0
                                        << IVD_UNSUPPORTEDPARAM;
599
0
                        ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |=
600
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
601
0
                        return IV_FAIL;
602
0
                    }
603
0
                }
604
                    //no break; is needed here
605
0
                case IVD_CMD_CTL_SETDEFAULT:
606
0
                {
607
0
                    ih264d_ctl_set_config_op_t *ps_op;
608
0
                    ps_op = (ih264d_ctl_set_config_op_t *)pv_api_op;
609
0
                    if(ps_op->s_ivd_ctl_set_config_op_t.u4_size
610
0
                                    != sizeof(ih264d_ctl_set_config_op_t))
611
0
                    {
612
0
                        ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |= 1
613
0
                                        << IVD_UNSUPPORTEDPARAM;
614
0
                        ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |=
615
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
616
0
                        return IV_FAIL;
617
0
                    }
618
0
                }
619
0
                    break;
620
621
0
                case IVD_CMD_CTL_GETPARAMS:
622
0
                {
623
0
                    ih264d_ctl_getstatus_ip_t *ps_ip;
624
0
                    ih264d_ctl_getstatus_op_t *ps_op;
625
626
0
                    ps_ip = (ih264d_ctl_getstatus_ip_t *)pv_api_ip;
627
0
                    ps_op = (ih264d_ctl_getstatus_op_t *)pv_api_op;
628
0
                    if(ps_ip->s_ivd_ctl_getstatus_ip_t.u4_size
629
0
                                    != sizeof(ih264d_ctl_getstatus_ip_t))
630
0
                    {
631
0
                        ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |= 1
632
0
                                        << IVD_UNSUPPORTEDPARAM;
633
0
                        ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |=
634
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
635
0
                        return IV_FAIL;
636
0
                    }
637
0
                    if(ps_op->s_ivd_ctl_getstatus_op_t.u4_size
638
0
                                    != sizeof(ih264d_ctl_getstatus_op_t))
639
0
                    {
640
0
                        ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |= 1
641
0
                                        << IVD_UNSUPPORTEDPARAM;
642
0
                        ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |=
643
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
644
0
                        return IV_FAIL;
645
0
                    }
646
0
                }
647
0
                    break;
648
649
0
                case IVD_CMD_CTL_GETBUFINFO:
650
0
                {
651
0
                    ih264d_ctl_getbufinfo_ip_t *ps_ip;
652
0
                    ih264d_ctl_getbufinfo_op_t *ps_op;
653
0
                    ps_ip = (ih264d_ctl_getbufinfo_ip_t *)pv_api_ip;
654
0
                    ps_op = (ih264d_ctl_getbufinfo_op_t *)pv_api_op;
655
656
0
                    if(ps_ip->s_ivd_ctl_getbufinfo_ip_t.u4_size
657
0
                                    != sizeof(ih264d_ctl_getbufinfo_ip_t))
658
0
                    {
659
0
                        ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |= 1
660
0
                                        << IVD_UNSUPPORTEDPARAM;
661
0
                        ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |=
662
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
663
0
                        return IV_FAIL;
664
0
                    }
665
0
                    if(ps_op->s_ivd_ctl_getbufinfo_op_t.u4_size
666
0
                                    != sizeof(ih264d_ctl_getbufinfo_op_t))
667
0
                    {
668
0
                        ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |= 1
669
0
                                        << IVD_UNSUPPORTEDPARAM;
670
0
                        ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |=
671
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
672
0
                        return IV_FAIL;
673
0
                    }
674
0
                }
675
0
                    break;
676
677
0
                case IVD_CMD_CTL_GETVERSION:
678
0
                {
679
0
                    ih264d_ctl_getversioninfo_ip_t *ps_ip;
680
0
                    ih264d_ctl_getversioninfo_op_t *ps_op;
681
0
                    ps_ip = (ih264d_ctl_getversioninfo_ip_t *)pv_api_ip;
682
0
                    ps_op = (ih264d_ctl_getversioninfo_op_t *)pv_api_op;
683
0
                    if(ps_ip->s_ivd_ctl_getversioninfo_ip_t.u4_size
684
0
                                    != sizeof(ih264d_ctl_getversioninfo_ip_t))
685
0
                    {
686
0
                        ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |= 1
687
0
                                        << IVD_UNSUPPORTEDPARAM;
688
0
                        ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |=
689
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
690
0
                        return IV_FAIL;
691
0
                    }
692
0
                    if(ps_op->s_ivd_ctl_getversioninfo_op_t.u4_size
693
0
                                    != sizeof(ih264d_ctl_getversioninfo_op_t))
694
0
                    {
695
0
                        ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |= 1
696
0
                                        << IVD_UNSUPPORTEDPARAM;
697
0
                        ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |=
698
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
699
0
                        return IV_FAIL;
700
0
                    }
701
0
                }
702
0
                    break;
703
704
0
                case IVD_CMD_CTL_FLUSH:
705
0
                {
706
0
                    ih264d_ctl_flush_ip_t *ps_ip;
707
0
                    ih264d_ctl_flush_op_t *ps_op;
708
0
                    ps_ip = (ih264d_ctl_flush_ip_t *)pv_api_ip;
709
0
                    ps_op = (ih264d_ctl_flush_op_t *)pv_api_op;
710
0
                    if(ps_ip->s_ivd_ctl_flush_ip_t.u4_size
711
0
                                    != sizeof(ih264d_ctl_flush_ip_t))
712
0
                    {
713
0
                        ps_op->s_ivd_ctl_flush_op_t.u4_error_code |= 1
714
0
                                        << IVD_UNSUPPORTEDPARAM;
715
0
                        ps_op->s_ivd_ctl_flush_op_t.u4_error_code |=
716
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
717
0
                        return IV_FAIL;
718
0
                    }
719
0
                    if(ps_op->s_ivd_ctl_flush_op_t.u4_size
720
0
                                    != sizeof(ih264d_ctl_flush_op_t))
721
0
                    {
722
0
                        ps_op->s_ivd_ctl_flush_op_t.u4_error_code |= 1
723
0
                                        << IVD_UNSUPPORTEDPARAM;
724
0
                        ps_op->s_ivd_ctl_flush_op_t.u4_error_code |=
725
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
726
0
                        return IV_FAIL;
727
0
                    }
728
0
                }
729
0
                    break;
730
731
0
                case IVD_CMD_CTL_RESET:
732
0
                {
733
0
                    ih264d_ctl_reset_ip_t *ps_ip;
734
0
                    ih264d_ctl_reset_op_t *ps_op;
735
0
                    ps_ip = (ih264d_ctl_reset_ip_t *)pv_api_ip;
736
0
                    ps_op = (ih264d_ctl_reset_op_t *)pv_api_op;
737
0
                    if(ps_ip->s_ivd_ctl_reset_ip_t.u4_size
738
0
                                    != sizeof(ih264d_ctl_reset_ip_t))
739
0
                    {
740
0
                        ps_op->s_ivd_ctl_reset_op_t.u4_error_code |= 1
741
0
                                        << IVD_UNSUPPORTEDPARAM;
742
0
                        ps_op->s_ivd_ctl_reset_op_t.u4_error_code |=
743
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
744
0
                        return IV_FAIL;
745
0
                    }
746
0
                    if(ps_op->s_ivd_ctl_reset_op_t.u4_size
747
0
                                    != sizeof(ih264d_ctl_reset_op_t))
748
0
                    {
749
0
                        ps_op->s_ivd_ctl_reset_op_t.u4_error_code |= 1
750
0
                                        << IVD_UNSUPPORTEDPARAM;
751
0
                        ps_op->s_ivd_ctl_reset_op_t.u4_error_code |=
752
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
753
0
                        return IV_FAIL;
754
0
                    }
755
0
                }
756
0
                    break;
757
758
0
                case IH264D_CMD_CTL_DEGRADE:
759
0
                {
760
0
                    ih264d_ctl_degrade_ip_t *ps_ip;
761
0
                    ih264d_ctl_degrade_op_t *ps_op;
762
763
0
                    ps_ip = (ih264d_ctl_degrade_ip_t *)pv_api_ip;
764
0
                    ps_op = (ih264d_ctl_degrade_op_t *)pv_api_op;
765
766
0
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_degrade_ip_t))
767
0
                    {
768
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
769
0
                        ps_op->u4_error_code |=
770
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
771
0
                        return IV_FAIL;
772
0
                    }
773
774
0
                    if(ps_op->u4_size != sizeof(ih264d_ctl_degrade_op_t))
775
0
                    {
776
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
777
0
                        ps_op->u4_error_code |=
778
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
779
0
                        return IV_FAIL;
780
0
                    }
781
782
0
                    if((ps_ip->i4_degrade_pics < 0)
783
0
                                    || (ps_ip->i4_degrade_pics > 4)
784
0
                                    || (ps_ip->i4_nondegrade_interval < 0)
785
0
                                    || (ps_ip->i4_degrade_type < 0)
786
0
                                    || (ps_ip->i4_degrade_type > 15))
787
0
                    {
788
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
789
0
                        return IV_FAIL;
790
0
                    }
791
792
0
                    break;
793
0
                }
794
795
0
                case IH264D_CMD_CTL_GET_BUFFER_DIMENSIONS:
796
0
                {
797
0
                    ih264d_ctl_get_frame_dimensions_ip_t *ps_ip;
798
0
                    ih264d_ctl_get_frame_dimensions_op_t *ps_op;
799
800
0
                    ps_ip = (ih264d_ctl_get_frame_dimensions_ip_t *)pv_api_ip;
801
0
                    ps_op = (ih264d_ctl_get_frame_dimensions_op_t *)pv_api_op;
802
803
0
                    if(ps_ip->u4_size
804
0
                                    != sizeof(ih264d_ctl_get_frame_dimensions_ip_t))
805
0
                    {
806
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
807
0
                        ps_op->u4_error_code |=
808
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
809
0
                        return IV_FAIL;
810
0
                    }
811
812
0
                    if(ps_op->u4_size
813
0
                                    != sizeof(ih264d_ctl_get_frame_dimensions_op_t))
814
0
                    {
815
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
816
0
                        ps_op->u4_error_code |=
817
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
818
0
                        return IV_FAIL;
819
0
                    }
820
821
0
                    break;
822
0
                }
823
0
                case IH264D_CMD_CTL_GET_VUI_PARAMS:
824
0
                {
825
0
                    ih264d_ctl_get_vui_params_ip_t *ps_ip;
826
0
                    ih264d_ctl_get_vui_params_op_t *ps_op;
827
828
0
                    ps_ip =
829
0
                                    (ih264d_ctl_get_vui_params_ip_t *)pv_api_ip;
830
0
                    ps_op =
831
0
                                    (ih264d_ctl_get_vui_params_op_t *)pv_api_op;
832
833
0
                    if(ps_ip->u4_size
834
0
                                    != sizeof(ih264d_ctl_get_vui_params_ip_t))
835
0
                    {
836
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
837
0
                        ps_op->u4_error_code |=
838
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
839
0
                        return IV_FAIL;
840
0
                    }
841
842
0
                    if(ps_op->u4_size
843
0
                                    != sizeof(ih264d_ctl_get_vui_params_op_t))
844
0
                    {
845
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
846
0
                        ps_op->u4_error_code |=
847
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
848
0
                        return IV_FAIL;
849
0
                    }
850
851
0
                    break;
852
0
                }
853
0
                case IH264D_CMD_CTL_GET_SEI_MDCV_PARAMS:
854
0
                {
855
0
                    ih264d_ctl_get_sei_mdcv_params_ip_t *ps_ip;
856
0
                    ih264d_ctl_get_sei_mdcv_params_op_t *ps_op;
857
858
0
                    ps_ip = (ih264d_ctl_get_sei_mdcv_params_ip_t *)pv_api_ip;
859
0
                    ps_op = (ih264d_ctl_get_sei_mdcv_params_op_t *)pv_api_op;
860
861
0
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_get_sei_mdcv_params_ip_t))
862
0
                    {
863
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
864
0
                        ps_op->u4_error_code |=
865
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
866
0
                        return IV_FAIL;
867
0
                    }
868
869
0
                    if(ps_op->u4_size != sizeof(ih264d_ctl_get_sei_mdcv_params_op_t))
870
0
                    {
871
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
872
0
                        ps_op->u4_error_code |=
873
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
874
0
                        return IV_FAIL;
875
0
                    }
876
877
0
                    break;
878
0
                }
879
880
0
                case IH264D_CMD_CTL_GET_SEI_CLL_PARAMS:
881
0
                {
882
0
                    ih264d_ctl_get_sei_cll_params_ip_t *ps_ip;
883
0
                    ih264d_ctl_get_sei_cll_params_op_t *ps_op;
884
885
0
                    ps_ip = (ih264d_ctl_get_sei_cll_params_ip_t *)pv_api_ip;
886
0
                    ps_op = (ih264d_ctl_get_sei_cll_params_op_t *)pv_api_op;
887
888
0
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_get_sei_cll_params_ip_t))
889
0
                    {
890
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
891
0
                        ps_op->u4_error_code |=
892
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
893
0
                        return IV_FAIL;
894
0
                    }
895
896
0
                    if(ps_op->u4_size != sizeof(ih264d_ctl_get_sei_cll_params_op_t))
897
0
                    {
898
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
899
0
                        ps_op->u4_error_code |=
900
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
901
0
                        return IV_FAIL;
902
0
                    }
903
904
0
                    break;
905
0
                }
906
907
0
                case IH264D_CMD_CTL_GET_SEI_AVE_PARAMS:
908
0
                {
909
0
                    ih264d_ctl_get_sei_ave_params_ip_t *ps_ip;
910
0
                    ih264d_ctl_get_sei_ave_params_op_t *ps_op;
911
912
0
                    ps_ip = (ih264d_ctl_get_sei_ave_params_ip_t *)pv_api_ip;
913
0
                    ps_op = (ih264d_ctl_get_sei_ave_params_op_t *)pv_api_op;
914
915
0
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_get_sei_ave_params_ip_t))
916
0
                    {
917
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
918
0
                        ps_op->u4_error_code |=
919
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
920
0
                        return IV_FAIL;
921
0
                    }
922
923
0
                    if(ps_op->u4_size != sizeof(ih264d_ctl_get_sei_ave_params_op_t))
924
0
                    {
925
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
926
0
                        ps_op->u4_error_code |=
927
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
928
0
                        return IV_FAIL;
929
0
                    }
930
931
0
                    break;
932
0
                }
933
934
0
                case IH264D_CMD_CTL_GET_SEI_CCV_PARAMS:
935
0
                {
936
0
                    ih264d_ctl_get_sei_ccv_params_ip_t *ps_ip;
937
0
                    ih264d_ctl_get_sei_ccv_params_op_t *ps_op;
938
939
0
                    ps_ip = (ih264d_ctl_get_sei_ccv_params_ip_t *)pv_api_ip;
940
0
                    ps_op = (ih264d_ctl_get_sei_ccv_params_op_t *)pv_api_op;
941
942
0
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_get_sei_ccv_params_ip_t))
943
0
                    {
944
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
945
0
                        ps_op->u4_error_code |=
946
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
947
0
                        return IV_FAIL;
948
0
                    }
949
950
0
                    if(ps_op->u4_size != sizeof(ih264d_ctl_get_sei_ccv_params_op_t))
951
0
                    {
952
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
953
0
                        ps_op->u4_error_code |=
954
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
955
0
                        return IV_FAIL;
956
0
                    }
957
958
0
                    break;
959
0
                }
960
961
0
                case IH264D_CMD_CTL_GET_SEI_SII_PARAMS:
962
0
                {
963
0
                    ih264d_ctl_get_sei_sii_params_ip_t *ps_ip;
964
0
                    ih264d_ctl_get_sei_sii_params_op_t *ps_op;
965
966
0
                    ps_ip = (ih264d_ctl_get_sei_sii_params_ip_t *) pv_api_ip;
967
0
                    ps_op = (ih264d_ctl_get_sei_sii_params_op_t *) pv_api_op;
968
969
0
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_get_sei_sii_params_ip_t))
970
0
                    {
971
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
972
0
                        ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
973
0
                        return IV_FAIL;
974
0
                    }
975
976
0
                    if(ps_op->u4_size != sizeof(ih264d_ctl_get_sei_sii_params_op_t))
977
0
                    {
978
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
979
0
                        ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
980
0
                        return IV_FAIL;
981
0
                    }
982
983
0
                    break;
984
0
                }
985
986
0
                case IH264D_CMD_CTL_GET_SEI_FGC_PARAMS:
987
0
                {
988
0
                    ih264d_ctl_get_sei_fgc_params_ip_t *ps_ip;
989
0
                    ih264d_ctl_get_sei_fgc_params_op_t *ps_op;
990
991
0
                    ps_ip = (ih264d_ctl_get_sei_fgc_params_ip_t *) pv_api_ip;
992
0
                    ps_op = (ih264d_ctl_get_sei_fgc_params_op_t *) pv_api_op;
993
994
0
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_get_sei_fgc_params_ip_t))
995
0
                    {
996
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
997
0
                        ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
998
0
                        return IV_FAIL;
999
0
                    }
1000
1001
0
                    if(ps_op->u4_size != sizeof(ih264d_ctl_get_sei_fgc_params_op_t))
1002
0
                    {
1003
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
1004
0
                        ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
1005
0
                        return IV_FAIL;
1006
0
                    }
1007
1008
0
                    break;
1009
0
                }
1010
1011
0
                case IH264D_CMD_CTL_SET_NUM_CORES:
1012
0
                {
1013
0
                    ih264d_ctl_set_num_cores_ip_t *ps_ip;
1014
0
                    ih264d_ctl_set_num_cores_op_t *ps_op;
1015
1016
0
                    ps_ip = (ih264d_ctl_set_num_cores_ip_t *)pv_api_ip;
1017
0
                    ps_op = (ih264d_ctl_set_num_cores_op_t *)pv_api_op;
1018
1019
0
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_set_num_cores_ip_t))
1020
0
                    {
1021
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
1022
0
                        ps_op->u4_error_code |=
1023
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
1024
0
                        return IV_FAIL;
1025
0
                    }
1026
1027
0
                    if(ps_op->u4_size != sizeof(ih264d_ctl_set_num_cores_op_t))
1028
0
                    {
1029
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
1030
0
                        ps_op->u4_error_code |=
1031
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
1032
0
                        return IV_FAIL;
1033
0
                    }
1034
1035
0
                    if((ps_ip->u4_num_cores != 1) && (ps_ip->u4_num_cores != 2)
1036
0
                                    && (ps_ip->u4_num_cores != 3)
1037
0
                                    && (ps_ip->u4_num_cores != 4))
1038
0
                    {
1039
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
1040
0
                        return IV_FAIL;
1041
0
                    }
1042
0
                    break;
1043
0
                }
1044
0
                case IH264D_CMD_CTL_SET_PROCESSOR:
1045
0
                {
1046
0
                    ih264d_ctl_set_processor_ip_t *ps_ip;
1047
0
                    ih264d_ctl_set_processor_op_t *ps_op;
1048
1049
0
                    ps_ip = (ih264d_ctl_set_processor_ip_t *)pv_api_ip;
1050
0
                    ps_op = (ih264d_ctl_set_processor_op_t *)pv_api_op;
1051
1052
0
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_set_processor_ip_t))
1053
0
                    {
1054
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
1055
0
                        ps_op->u4_error_code |=
1056
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
1057
0
                        return IV_FAIL;
1058
0
                    }
1059
1060
0
                    if(ps_op->u4_size != sizeof(ih264d_ctl_set_processor_op_t))
1061
0
                    {
1062
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
1063
0
                        ps_op->u4_error_code |=
1064
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
1065
0
                        return IV_FAIL;
1066
0
                    }
1067
1068
0
                    break;
1069
0
                }
1070
0
                default:
1071
0
                    *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
1072
0
                    *(pu4_api_op + 1) |= IVD_UNSUPPORTED_API_CMD;
1073
0
                    return IV_FAIL;
1074
0
                    break;
1075
0
            }
1076
0
        }
1077
0
            break;
1078
0
    }
1079
1080
0
    return IV_SUCCESS;
1081
0
}
1082
1083
1084
/**
1085
 *******************************************************************************
1086
 *
1087
 * @brief
1088
 *  Sets Processor type
1089
 *
1090
 * @par Description:
1091
 *  Sets Processor type
1092
 *
1093
 * @param[in] ps_codec_obj
1094
 *  Pointer to codec object at API level
1095
 *
1096
 * @param[in] pv_api_ip
1097
 *  Pointer to input argument structure
1098
 *
1099
 * @param[out] pv_api_op
1100
 *  Pointer to output argument structure
1101
 *
1102
 * @returns  Status
1103
 *
1104
 * @remarks
1105
 *
1106
 *
1107
 *******************************************************************************
1108
 */
1109
1110
WORD32 ih264d_set_processor(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
1111
0
{
1112
0
    ih264d_ctl_set_processor_ip_t *ps_ip;
1113
0
    ih264d_ctl_set_processor_op_t *ps_op;
1114
0
    dec_struct_t *ps_codec = (dec_struct_t *)dec_hdl->pv_codec_handle;
1115
1116
0
    ps_ip = (ih264d_ctl_set_processor_ip_t *)pv_api_ip;
1117
0
    ps_op = (ih264d_ctl_set_processor_op_t *)pv_api_op;
1118
1119
0
    ps_codec->e_processor_arch = (IVD_ARCH_T)ps_ip->u4_arch;
1120
0
    ps_codec->e_processor_soc = (IVD_SOC_T)ps_ip->u4_soc;
1121
1122
0
    ih264d_init_function_ptr(ps_codec);
1123
1124
0
    ps_op->u4_error_code = 0;
1125
0
    return IV_SUCCESS;
1126
0
}
1127
1128
1129
/**************************************************************************
1130
 * \if Function name : ih264d_init_decoder \endif
1131
 *
1132
 *
1133
 * \brief
1134
 *    Initializes the decoder
1135
 *
1136
 * \param apiVersion               : Version of the api being used.
1137
 * \param errorHandlingMechanism   : Mechanism to be used for errror handling.
1138
 * \param postFilteringType: Type of post filtering operation to be used.
1139
 * \param uc_outputFormat: Format of the decoded picture [default 4:2:0].
1140
 * \param uc_dispBufs: Number of Display Buffers.
1141
 * \param p_NALBufAPI: Pointer to NAL Buffer API.
1142
 * \param p_DispBufAPI: Pointer to Display Buffer API.
1143
 * \param ih264d_dec_mem_manager  :Pointer to the function that will be called by decoder
1144
 *                        for memory allocation and freeing.
1145
 *
1146
 * \return
1147
 *    0 on Success and -1 on error
1148
 *
1149
 **************************************************************************
1150
 */
1151
void ih264d_init_decoder(void * ps_dec_params)
1152
0
{
1153
0
    dec_struct_t * ps_dec = (dec_struct_t *)ps_dec_params;
1154
0
    dec_slice_params_t *ps_cur_slice;
1155
0
    pocstruct_t *ps_prev_poc, *ps_cur_poc;
1156
0
    WORD32 size;
1157
1158
    /* Free any dynamic buffers that are allocated. This has to happen before
1159
     * the buffer managers are cleared below, so that their mutexes can be
1160
     * destroyed. */
1161
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_bits_buf_dynamic);
1162
0
    ih264d_free_dynamic_bufs(ps_dec);
1163
1164
0
    size = sizeof(pred_info_t) * 2 * 32;
1165
0
    memset(ps_dec->ps_pred, 0 , size);
1166
1167
0
    size = sizeof(disp_mgr_t);
1168
0
    memset(ps_dec->pv_disp_buf_mgr, 0 , size);
1169
1170
0
    size = sizeof(buf_mgr_t) + ithread_get_mutex_lock_size();
1171
0
    memset(ps_dec->pv_pic_buf_mgr, 0, size);
1172
1173
0
    size = sizeof(dec_err_status_t);
1174
0
    memset(ps_dec->ps_dec_err_status, 0, size);
1175
1176
0
    size = sizeof(sei);
1177
0
    memset(ps_dec->ps_sei, 0, size);
1178
1179
0
    size = sizeof(sei);
1180
0
    memset(ps_dec->ps_sei_parse, 0, size);
1181
1182
0
    size = sizeof(dpb_commands_t);
1183
0
    memset(ps_dec->ps_dpb_cmds, 0, size);
1184
1185
0
    size = sizeof(dec_bit_stream_t);
1186
0
    memset(ps_dec->ps_bitstrm, 0, size);
1187
1188
0
    size = sizeof(dec_slice_params_t);
1189
0
    memset(ps_dec->ps_cur_slice, 0, size);
1190
1191
0
    size = MAX(sizeof(dec_seq_params_t), sizeof(dec_pic_params_t));
1192
0
    memset(ps_dec->pv_scratch_sps_pps, 0, size);
1193
1194
0
    size = sizeof(ctxt_inc_mb_info_t);
1195
0
    memset(ps_dec->ps_left_mb_ctxt_info, 0, size);
1196
1197
0
    size = (sizeof(neighbouradd_t) << 2);
1198
0
    memset(ps_dec->ps_left_mvpred_addr, 0 ,size);
1199
1200
0
    size = sizeof(buf_mgr_t) + ithread_get_mutex_lock_size();
1201
0
    memset(ps_dec->pv_mv_buf_mgr, 0, size);
1202
1203
0
    {
1204
0
        UWORD8 i;
1205
0
        struct pic_buffer_t *ps_init_dpb;
1206
0
        ps_init_dpb = ps_dec->ps_dpb_mgr->ps_init_dpb[0][0];
1207
0
        for(i = 0; i < 2 * MAX_REF_BUFS; i++)
1208
0
        {
1209
0
            ps_init_dpb->pu1_buf1 = NULL;
1210
0
            ps_init_dpb->u1_long_term_frm_idx = MAX_REF_BUFS + 1;
1211
0
            ps_dec->ps_dpb_mgr->ps_init_dpb[0][i] = ps_init_dpb;
1212
0
            ps_dec->ps_dpb_mgr->ps_mod_dpb[0][i] = ps_init_dpb;
1213
0
            ps_init_dpb++;
1214
0
        }
1215
1216
0
        ps_init_dpb = ps_dec->ps_dpb_mgr->ps_init_dpb[1][0];
1217
0
        for(i = 0; i < 2 * MAX_REF_BUFS; i++)
1218
0
        {
1219
0
            ps_init_dpb->pu1_buf1 = NULL;
1220
0
            ps_init_dpb->u1_long_term_frm_idx = MAX_REF_BUFS + 1;
1221
0
            ps_dec->ps_dpb_mgr->ps_init_dpb[1][i] = ps_init_dpb;
1222
0
            ps_dec->ps_dpb_mgr->ps_mod_dpb[1][i] = ps_init_dpb;
1223
0
            ps_init_dpb++;
1224
0
        }
1225
0
    }
1226
1227
0
    ps_cur_slice = ps_dec->ps_cur_slice;
1228
0
    ps_dec->init_done = 0;
1229
1230
0
    ps_dec->u4_num_cores = 1;
1231
1232
0
    ps_dec->u2_pic_ht = ps_dec->u2_pic_wd = 0;
1233
1234
0
    ps_dec->u1_separate_parse = DEFAULT_SEPARATE_PARSE;
1235
0
    ps_dec->u4_app_disable_deblk_frm = 0;
1236
0
    ps_dec->i4_degrade_type = 0;
1237
0
    ps_dec->i4_degrade_pics = 0;
1238
1239
0
    memset(ps_dec->ps_pps, 0,
1240
0
           ((sizeof(dec_pic_params_t)) * MAX_NUM_PIC_PARAMS));
1241
0
    memset(ps_dec->ps_sps, 0,
1242
0
           ((sizeof(dec_seq_params_t)) * MAX_NUM_SEQ_PARAMS));
1243
1244
    /* Initialization of function pointers ih264d_deblock_picture function*/
1245
1246
0
    ps_dec->p_DeblockPicture[0] = ih264d_deblock_picture_non_mbaff;
1247
0
    ps_dec->p_DeblockPicture[1] = ih264d_deblock_picture_mbaff;
1248
1249
0
    ps_dec->s_cab_dec_env.pv_codec_handle = ps_dec;
1250
1251
0
    ps_dec->u4_num_fld_in_frm = 0;
1252
1253
0
    ps_dec->ps_dpb_mgr->pv_codec_handle = ps_dec;
1254
1255
    /* Initialize the sei validity u4_flag with zero indiacting sei is not valid*/
1256
0
    ps_dec->ps_sei->u1_is_valid = 0;
1257
1258
    /* decParams Initializations */
1259
0
    ps_dec->ps_cur_pps = NULL;
1260
0
    ps_dec->ps_cur_sps = NULL;
1261
0
    ps_dec->u1_init_dec_flag = 0;
1262
0
    ps_dec->u1_first_slice_in_stream = 1;
1263
0
    ps_dec->u1_last_pic_not_decoded = 0;
1264
0
    ps_dec->u4_app_disp_width = 0;
1265
0
    ps_dec->i4_header_decoded = 0;
1266
0
    ps_dec->u4_total_frames_decoded = 0;
1267
1268
0
    ps_dec->i4_error_code = 0;
1269
0
    ps_dec->i4_content_type = IV_CONTENTTYPE_NA;
1270
0
    ps_dec->ps_cur_slice->u1_mbaff_frame_flag = 0;
1271
1272
0
    ps_dec->ps_dec_err_status->u1_err_flag = ACCEPT_ALL_PICS; //REJECT_PB_PICS;
1273
0
    ps_dec->ps_dec_err_status->u1_cur_pic_type = PIC_TYPE_UNKNOWN;
1274
0
    ps_dec->ps_dec_err_status->u4_frm_sei_sync = SYNC_FRM_DEFAULT;
1275
0
    ps_dec->ps_dec_err_status->u4_cur_frm = INIT_FRAME;
1276
0
    ps_dec->ps_dec_err_status->u1_pic_aud_i = PIC_TYPE_UNKNOWN;
1277
1278
0
    ps_dec->u1_pr_sl_type = 0xFF;
1279
0
    ps_dec->u2_mbx = 0xffff;
1280
0
    ps_dec->u2_mby = 0;
1281
0
    ps_dec->u4_total_mbs_coded = 0;
1282
1283
    /* POC initializations */
1284
0
    ps_prev_poc = &ps_dec->s_prev_pic_poc;
1285
0
    ps_cur_poc = &ps_dec->s_cur_pic_poc;
1286
0
    ps_prev_poc->i4_pic_order_cnt_lsb = ps_cur_poc->i4_pic_order_cnt_lsb = 0;
1287
0
    ps_prev_poc->i4_pic_order_cnt_msb = ps_cur_poc->i4_pic_order_cnt_msb = 0;
1288
0
    ps_prev_poc->i4_delta_pic_order_cnt_bottom =
1289
0
                    ps_cur_poc->i4_delta_pic_order_cnt_bottom = 0;
1290
0
    ps_prev_poc->i4_delta_pic_order_cnt[0] =
1291
0
                    ps_cur_poc->i4_delta_pic_order_cnt[0] = 0;
1292
0
    ps_prev_poc->i4_delta_pic_order_cnt[1] =
1293
0
                    ps_cur_poc->i4_delta_pic_order_cnt[1] = 0;
1294
0
    ps_prev_poc->u1_mmco_equalto5 = ps_cur_poc->u1_mmco_equalto5 = 0;
1295
0
    ps_prev_poc->i4_top_field_order_count = ps_cur_poc->i4_top_field_order_count =
1296
0
                    0;
1297
0
    ps_prev_poc->i4_bottom_field_order_count =
1298
0
                    ps_cur_poc->i4_bottom_field_order_count = 0;
1299
0
    ps_prev_poc->u1_bot_field = ps_cur_poc->u1_bot_field = 0;
1300
0
    ps_prev_poc->u1_mmco_equalto5 = ps_cur_poc->u1_mmco_equalto5 = 0;
1301
0
    ps_prev_poc->i4_prev_frame_num_ofst = ps_cur_poc->i4_prev_frame_num_ofst = 0;
1302
0
    ps_cur_slice->u1_mmco_equalto5 = 0;
1303
0
    ps_cur_slice->u2_frame_num = 0;
1304
1305
0
    ps_dec->i4_max_poc = 0;
1306
0
    ps_dec->i4_prev_max_display_seq = 0;
1307
0
    ps_dec->u4_recon_mb_grp = 4;
1308
0
    ps_dec->i4_reorder_depth = -1;
1309
1310
    /* Field PIC initializations */
1311
0
    ps_dec->u1_second_field = 0;
1312
0
    ps_dec->s_prev_seq_params.u1_eoseq_pending = 0;
1313
1314
    /* Set the cropping parameters as zero */
1315
0
    ps_dec->u2_crop_offset_y = 0;
1316
0
    ps_dec->u2_crop_offset_uv = 0;
1317
1318
    /* The Initial Frame Rate Info is not Present */
1319
0
    ps_dec->i4_vui_frame_rate = -1;
1320
0
    ps_dec->i4_pic_type = NA_SLICE;
1321
0
    ps_dec->i4_frametype = IV_NA_FRAME;
1322
0
    ps_dec->i4_content_type = IV_CONTENTTYPE_NA;
1323
1324
0
    ps_dec->u1_res_changed = 0;
1325
1326
1327
0
    ps_dec->u1_frame_decoded_flag = 0;
1328
1329
    /* Set the default frame seek mask mode */
1330
0
    ps_dec->u4_skip_frm_mask = SKIP_NONE;
1331
1332
    /********************************************************/
1333
    /* Initialize CAVLC residual decoding function pointers */
1334
    /********************************************************/
1335
0
    ps_dec->pf_cavlc_4x4res_block[0] = ih264d_cavlc_4x4res_block_totalcoeff_1;
1336
0
    ps_dec->pf_cavlc_4x4res_block[1] =
1337
0
                    ih264d_cavlc_4x4res_block_totalcoeff_2to10;
1338
0
    ps_dec->pf_cavlc_4x4res_block[2] =
1339
0
                    ih264d_cavlc_4x4res_block_totalcoeff_11to16;
1340
1341
0
    ps_dec->pf_cavlc_parse4x4coeff[0] = ih264d_cavlc_parse4x4coeff_n0to7;
1342
0
    ps_dec->pf_cavlc_parse4x4coeff[1] = ih264d_cavlc_parse4x4coeff_n8;
1343
1344
0
    ps_dec->pf_cavlc_parse_8x8block[0] =
1345
0
                    ih264d_cavlc_parse_8x8block_none_available;
1346
0
    ps_dec->pf_cavlc_parse_8x8block[1] =
1347
0
                    ih264d_cavlc_parse_8x8block_left_available;
1348
0
    ps_dec->pf_cavlc_parse_8x8block[2] =
1349
0
                    ih264d_cavlc_parse_8x8block_top_available;
1350
0
    ps_dec->pf_cavlc_parse_8x8block[3] =
1351
0
                    ih264d_cavlc_parse_8x8block_both_available;
1352
1353
    /***************************************************************************/
1354
    /* Initialize Bs calculation function pointers for P and B, 16x16/non16x16 */
1355
    /***************************************************************************/
1356
0
    ps_dec->pf_fill_bs1[0][0] = ih264d_fill_bs1_16x16mb_pslice;
1357
0
    ps_dec->pf_fill_bs1[0][1] = ih264d_fill_bs1_non16x16mb_pslice;
1358
1359
0
    ps_dec->pf_fill_bs1[1][0] = ih264d_fill_bs1_16x16mb_bslice;
1360
0
    ps_dec->pf_fill_bs1[1][1] = ih264d_fill_bs1_non16x16mb_bslice;
1361
1362
0
    ps_dec->pf_fill_bs_xtra_left_edge[0] =
1363
0
                    ih264d_fill_bs_xtra_left_edge_cur_frm;
1364
0
    ps_dec->pf_fill_bs_xtra_left_edge[1] =
1365
0
                    ih264d_fill_bs_xtra_left_edge_cur_fld;
1366
1367
    /* Initialize Reference Pic Buffers */
1368
0
    ih264d_init_ref_bufs(ps_dec->ps_dpb_mgr);
1369
1370
0
    ps_dec->u2_prv_frame_num = 0;
1371
0
    ps_dec->u1_top_bottom_decoded = 0;
1372
0
    ps_dec->u1_dangling_field = 0;
1373
1374
0
    ps_dec->s_cab_dec_env.cabac_table = gau4_ih264d_cabac_table;
1375
1376
0
    ps_dec->pu1_left_mv_ctxt_inc = ps_dec->u1_left_mv_ctxt_inc_arr[0];
1377
0
    ps_dec->pi1_left_ref_idx_ctxt_inc =
1378
0
                    &ps_dec->i1_left_ref_idx_ctx_inc_arr[0][0];
1379
0
    ps_dec->pu1_left_yuv_dc_csbp = &ps_dec->u1_yuv_dc_csbp_topmb;
1380
1381
    /* ! */
1382
    /* Initializing flush frame u4_flag */
1383
0
    ps_dec->u1_flushfrm = 0;
1384
1385
0
    {
1386
0
        ps_dec->s_cab_dec_env.pv_codec_handle = (void*)ps_dec;
1387
0
        ps_dec->ps_bitstrm->pv_codec_handle = (void*)ps_dec;
1388
0
        ps_dec->ps_cur_slice->pv_codec_handle = (void*)ps_dec;
1389
0
        ps_dec->ps_dpb_mgr->pv_codec_handle = (void*)ps_dec;
1390
0
    }
1391
1392
0
    memset(ps_dec->disp_bufs, 0, (MAX_DISP_BUFS_NEW) * sizeof(disp_buf_t));
1393
0
    memset(ps_dec->u4_disp_buf_mapping, 0,
1394
0
           (MAX_DISP_BUFS_NEW) * sizeof(UWORD32));
1395
0
    memset(ps_dec->u4_disp_buf_to_be_freed, 0,
1396
0
           (MAX_DISP_BUFS_NEW) * sizeof(UWORD32));
1397
0
    memset(ps_dec->ps_cur_slice, 0, sizeof(dec_slice_params_t));
1398
1399
0
    ih264d_init_arch(ps_dec);
1400
0
    ih264d_init_function_ptr(ps_dec);
1401
0
    ps_dec->e_frm_out_mode = ps_dec->u4_disable_ref_retention ? IVD_DECODE_FRAME_OUT
1402
0
                                                              : IVD_DISPLAY_FRAME_OUT;
1403
0
    ps_dec->init_done = 1;
1404
1405
0
}
1406
1407
WORD32 ih264d_join_threads(dec_struct_t *ps_dec)
1408
0
{
1409
0
    if(ps_dec->i4_threads_active)
1410
0
    {
1411
        /* Wait for threads */
1412
0
        ps_dec->i4_break_threads = 1;
1413
0
        if(ps_dec->u4_dec_thread_created)
1414
0
        {
1415
0
            ithread_mutex_lock(ps_dec->apv_proc_start_mutex[0]);
1416
1417
0
            ps_dec->ai4_process_start[0] = PROC_START;
1418
1419
0
            ithread_cond_signal(ps_dec->apv_proc_start_condition[0]);
1420
1421
0
            ithread_mutex_unlock(ps_dec->apv_proc_start_mutex[0]);
1422
1423
0
            ithread_join(ps_dec->pv_dec_thread_handle, NULL);
1424
1425
0
            ps_dec->u4_dec_thread_created = 0;
1426
0
        }
1427
1428
0
        if(ps_dec->u4_bs_deblk_thread_created)
1429
0
        {
1430
0
            ithread_mutex_lock(ps_dec->apv_proc_start_mutex[1]);
1431
1432
0
            ps_dec->ai4_process_start[1] = PROC_START;
1433
1434
0
            ithread_cond_signal(ps_dec->apv_proc_start_condition[1]);
1435
1436
0
            ithread_mutex_unlock(ps_dec->apv_proc_start_mutex[1]);
1437
1438
0
            ithread_join(ps_dec->pv_bs_deblk_thread_handle, NULL);
1439
1440
0
            ps_dec->u4_bs_deblk_thread_created = 0;
1441
0
        }
1442
0
    }
1443
0
    return IV_SUCCESS;
1444
0
}
1445
1446
WORD32 ih264d_free_static_bufs(iv_obj_t *dec_hdl)
1447
0
{
1448
0
    dec_struct_t *ps_dec;
1449
1450
0
    void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1451
0
    void *pv_mem_ctxt;
1452
1453
0
    ps_dec = (dec_struct_t *)dec_hdl->pv_codec_handle;
1454
0
    pf_aligned_free = ps_dec->pf_aligned_free;
1455
0
    pv_mem_ctxt = ps_dec->pv_mem_ctxt;
1456
1457
0
    if(ps_dec->i4_threads_active)
1458
0
    {
1459
1460
0
        ih264d_join_threads(ps_dec);
1461
1462
        // destroy mutex and condition variable for both the threads
1463
        // 1. ih264d_decode_picture_thread
1464
        // 2. ih264d_recon_deblk_thread
1465
0
        {
1466
0
            UWORD32 i;
1467
0
            for(i = 0; i < 2; i++)
1468
0
            {
1469
0
                ithread_cond_destroy(ps_dec->apv_proc_start_condition[i]);
1470
0
                ithread_cond_destroy(ps_dec->apv_proc_done_condition[i]);
1471
1472
0
                ithread_mutex_destroy(ps_dec->apv_proc_start_mutex[i]);
1473
0
                ithread_mutex_destroy(ps_dec->apv_proc_done_mutex[i]);
1474
0
            }
1475
0
        }
1476
0
        PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->apv_proc_start_mutex[0]);
1477
0
        PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->apv_proc_start_condition[0]);
1478
0
    }
1479
1480
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_sps);
1481
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pps);
1482
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_dec_thread_handle);
1483
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_bs_deblk_thread_handle);
1484
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dpb_mgr);
1485
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pred);
1486
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_disp_buf_mgr);
1487
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_pic_buf_mgr);
1488
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pic_buf_base);
1489
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dec_err_status);
1490
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_sei);
1491
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_sei_parse);
1492
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dpb_cmds);
1493
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_bitstrm);
1494
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_cur_slice);
1495
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_scratch_sps_pps);
1496
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_bits_buf_static);
1497
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ppv_map_ref_idx_to_poc_base);
1498
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->p_cabac_ctxt_table_t);
1499
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_left_mb_ctxt_info);
1500
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_ref_buff_base);
1501
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pi2_pred1);
1502
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_temp_mc_buffer);
1503
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_init_dpb_base);
1504
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu4_mbaff_wt_mat);
1505
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu4_wts_ofsts_mat);
1506
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_left_mvpred_addr);
1507
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_mv_buf_mgr);
1508
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_col_mv_base);
1509
0
    PS_DEC_ALIGNED_FREE(ps_dec, dec_hdl->pv_codec_handle);
1510
1511
0
    if(dec_hdl)
1512
0
    {
1513
0
        pf_aligned_free(pv_mem_ctxt, dec_hdl);
1514
0
    }
1515
0
    return IV_SUCCESS;
1516
0
}
1517
/*****************************************************************************/
1518
/*                                                                           */
1519
/*  Function Name : ih264d_create                                              */
1520
/*                                                                           */
1521
/*  Description   : creates decoder                                          */
1522
/*                                                                           */
1523
/*  Inputs        :iv_obj_t decoder handle                                   */
1524
/*                :pv_api_ip pointer to input structure                      */
1525
/*                :pv_api_op pointer to output structure                     */
1526
/*  Outputs       :                                                          */
1527
/*  Returns       : void                                                     */
1528
/*                                                                           */
1529
/*  Issues        : none                                                     */
1530
/*                                                                           */
1531
/*  Revision History:                                                        */
1532
/*                                                                           */
1533
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1534
/*         22 10 2008    100356         Draft                                */
1535
/*                                                                           */
1536
/*****************************************************************************/
1537
WORD32 ih264d_allocate_static_bufs(iv_obj_t **dec_hdl, void *pv_api_ip, void *pv_api_op)
1538
0
{
1539
0
    ih264d_create_ip_t *ps_create_ip;
1540
0
    ih264d_create_op_t *ps_create_op;
1541
0
    void *pv_buf;
1542
0
    UWORD8 *pu1_buf;
1543
0
    dec_struct_t *ps_dec;
1544
0
    void *(*pf_aligned_alloc)(void *pv_mem_ctxt, WORD32 alignment, WORD32 size);
1545
0
    void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1546
0
    void *pv_mem_ctxt;
1547
0
    WORD32 size;
1548
1549
0
    ps_create_ip = (ih264d_create_ip_t *)pv_api_ip;
1550
0
    ps_create_op = (ih264d_create_op_t *)pv_api_op;
1551
1552
0
    ps_create_op->s_ivd_create_op_t.u4_error_code = 0;
1553
1554
0
    pf_aligned_alloc = ps_create_ip->s_ivd_create_ip_t.pf_aligned_alloc;
1555
0
    pf_aligned_free = ps_create_ip->s_ivd_create_ip_t.pf_aligned_free;
1556
0
    pv_mem_ctxt  = ps_create_ip->s_ivd_create_ip_t.pv_mem_ctxt;
1557
1558
    /* Initialize return handle to NULL */
1559
0
    ps_create_op->s_ivd_create_op_t.pv_handle = NULL;
1560
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, sizeof(iv_obj_t));
1561
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1562
0
    memset(pv_buf, 0, sizeof(iv_obj_t));
1563
0
    *dec_hdl = (iv_obj_t *)pv_buf;
1564
0
    ps_create_op->s_ivd_create_op_t.pv_handle = *dec_hdl;
1565
1566
0
    (*dec_hdl)->pv_codec_handle = NULL;
1567
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, sizeof(dec_struct_t));
1568
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1569
0
    (*dec_hdl)->pv_codec_handle = (dec_struct_t *)pv_buf;
1570
0
    ps_dec = (dec_struct_t *)pv_buf;
1571
1572
0
    memset(ps_dec, 0, sizeof(dec_struct_t));
1573
1574
0
#ifndef LOGO_EN
1575
0
    ps_dec->u4_share_disp_buf = ps_create_ip->s_ivd_create_ip_t.u4_share_disp_buf;
1576
#else
1577
    ps_dec->u4_share_disp_buf = 0;
1578
#endif
1579
1580
0
    ps_dec->u1_chroma_format =
1581
0
                    (UWORD8)(ps_create_ip->s_ivd_create_ip_t.e_output_format);
1582
1583
0
    if((ps_dec->u1_chroma_format != IV_YUV_420P)
1584
0
                    && (ps_dec->u1_chroma_format
1585
0
                                    != IV_YUV_420SP_UV)
1586
0
                    && (ps_dec->u1_chroma_format
1587
0
                                    != IV_YUV_420SP_VU))
1588
0
    {
1589
0
        ps_dec->u4_share_disp_buf = 0;
1590
0
    }
1591
1592
0
    ps_dec->u1_enable_mb_info = ps_create_ip->u4_enable_frame_info;
1593
0
    ps_dec->pf_aligned_alloc = pf_aligned_alloc;
1594
0
    ps_dec->pf_aligned_free = pf_aligned_free;
1595
0
    ps_dec->pv_mem_ctxt = pv_mem_ctxt;
1596
0
    ps_dec->i4_threads_active = ps_create_ip->u4_keep_threads_active;
1597
0
    ps_dec->u4_disable_ref_retention = ps_create_ip->u4_disable_ref_retention;
1598
1599
1600
0
    size = ((sizeof(dec_seq_params_t)) * MAX_NUM_SEQ_PARAMS);
1601
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1602
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1603
0
    memset(pv_buf, 0, size);
1604
0
    ps_dec->ps_sps = pv_buf;
1605
1606
0
    size = (sizeof(dec_pic_params_t)) * MAX_NUM_PIC_PARAMS;
1607
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1608
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1609
0
    memset(pv_buf, 0, size);
1610
0
    ps_dec->ps_pps = pv_buf;
1611
1612
0
    size = ithread_get_handle_size();
1613
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1614
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1615
0
    memset(pv_buf, 0, size);
1616
0
    ps_dec->pv_dec_thread_handle = pv_buf;
1617
1618
0
    size = ithread_get_handle_size();
1619
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1620
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1621
0
    memset(pv_buf, 0, size);
1622
0
    ps_dec->pv_bs_deblk_thread_handle = pv_buf;
1623
1624
0
    if(ps_dec->i4_threads_active)
1625
0
    {
1626
0
        UWORD32 i;
1627
        /* Request memory to hold mutex (start/done) for both threads */
1628
0
        size = ithread_get_mutex_lock_size() << 2;
1629
0
        pv_buf = pf_aligned_alloc(pv_mem_ctxt, 8, size);
1630
0
        RETURN_IF((NULL == pv_buf), IV_FAIL);
1631
0
        memset(pv_buf, 0, size);
1632
1633
        // init mutex variable for both the threads
1634
        // 1. ih264d_decode_picture_thread
1635
        // 2. ih264d_recon_deblk_thread
1636
0
        for(i = 0; i < 2; i++)
1637
0
        {
1638
0
            WORD32 ret;
1639
0
            WORD32 mutex_size = ithread_get_mutex_lock_size();
1640
1641
0
            ps_dec->apv_proc_start_mutex[i] =
1642
0
                            (UWORD8 *)pv_buf + (2 * i * mutex_size);
1643
0
            ps_dec->apv_proc_done_mutex[i] =
1644
0
                            (UWORD8 *)pv_buf + ((2 * i + 1) * mutex_size);
1645
1646
0
            ret = ithread_mutex_init(ps_dec->apv_proc_start_mutex[i]);
1647
0
            RETURN_IF((ret != IV_SUCCESS), ret);
1648
1649
0
            ret = ithread_mutex_init(ps_dec->apv_proc_done_mutex[i]);
1650
0
            RETURN_IF((ret != IV_SUCCESS), ret);
1651
0
        }
1652
1653
0
        size = ithread_get_cond_struct_size() << 2;
1654
0
        pv_buf = pf_aligned_alloc(pv_mem_ctxt, 8, size);
1655
0
        RETURN_IF((NULL == pv_buf), IV_FAIL);
1656
0
        memset(pv_buf, 0, size);
1657
1658
        // init condition variable for both the threads
1659
0
        for(i = 0; i < 2; i++)
1660
0
        {
1661
0
            WORD32 ret;
1662
0
            WORD32 cond_size = ithread_get_cond_struct_size();
1663
0
            ps_dec->apv_proc_start_condition[i] =
1664
0
                            (UWORD8 *)pv_buf + (2 * i * cond_size);
1665
0
            ps_dec->apv_proc_done_condition[i] =
1666
0
                            (UWORD8 *)pv_buf + ((2 * i + 1) * cond_size);
1667
1668
0
            ret = ithread_cond_init(ps_dec->apv_proc_start_condition[i]);
1669
0
            RETURN_IF((ret != IV_SUCCESS), ret);
1670
1671
0
            ret = ithread_cond_init(ps_dec->apv_proc_done_condition[i]);
1672
0
            RETURN_IF((ret != IV_SUCCESS), ret);
1673
0
        }
1674
0
    }
1675
1676
0
    size = sizeof(dpb_manager_t);
1677
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1678
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1679
0
    memset(pv_buf, 0, size);
1680
0
    ps_dec->ps_dpb_mgr = pv_buf;
1681
1682
0
    size = sizeof(pred_info_t) * 2 * 32;
1683
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1684
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1685
0
    memset(pv_buf, 0, size);
1686
0
    ps_dec->ps_pred = pv_buf;
1687
1688
0
    size = sizeof(disp_mgr_t);
1689
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1690
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1691
0
    memset(pv_buf, 0, size);
1692
0
    ps_dec->pv_disp_buf_mgr = pv_buf;
1693
1694
0
    size = sizeof(buf_mgr_t) + ithread_get_mutex_lock_size();
1695
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1696
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1697
0
    memset(pv_buf, 0, size);
1698
0
    ps_dec->pv_pic_buf_mgr = pv_buf;
1699
1700
0
    size = sizeof(struct pic_buffer_t) * (H264_MAX_REF_PICS * 2);
1701
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1702
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1703
0
    memset(pv_buf, 0, size);
1704
0
    ps_dec->ps_pic_buf_base = pv_buf;
1705
1706
0
    size = sizeof(dec_err_status_t);
1707
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1708
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1709
0
    memset(pv_buf, 0, size);
1710
0
    ps_dec->ps_dec_err_status = (dec_err_status_t *)pv_buf;
1711
1712
0
    size = sizeof(sei);
1713
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1714
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1715
0
    memset(pv_buf, 0, size);
1716
0
    ps_dec->ps_sei = (sei *)pv_buf;
1717
1718
0
    size = sizeof(sei);
1719
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1720
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1721
0
    memset(pv_buf, 0, size);
1722
0
    ps_dec->ps_sei_parse = (sei *)pv_buf;
1723
1724
0
    size = sizeof(dpb_commands_t);
1725
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1726
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1727
0
    memset(pv_buf, 0, size);
1728
0
    ps_dec->ps_dpb_cmds = (dpb_commands_t *)pv_buf;
1729
1730
0
    size = sizeof(dec_bit_stream_t);
1731
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1732
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1733
0
    memset(pv_buf, 0, size);
1734
0
    ps_dec->ps_bitstrm = (dec_bit_stream_t *)pv_buf;
1735
1736
0
    size = sizeof(dec_slice_params_t);
1737
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1738
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1739
0
    memset(pv_buf, 0, size);
1740
0
    ps_dec->ps_cur_slice = (dec_slice_params_t *)pv_buf;
1741
1742
0
    size = MAX(sizeof(dec_seq_params_t), sizeof(dec_pic_params_t));
1743
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1744
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1745
0
    memset(pv_buf, 0, size);
1746
0
    ps_dec->pv_scratch_sps_pps = pv_buf;
1747
1748
1749
0
    ps_dec->u4_static_bits_buf_size = 256000;
1750
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, ps_dec->u4_static_bits_buf_size);
1751
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1752
0
    memset(pv_buf, 0, ps_dec->u4_static_bits_buf_size);
1753
0
    ps_dec->pu1_bits_buf_static = pv_buf;
1754
1755
1756
0
    size = ((TOTAL_LIST_ENTRIES + PAD_MAP_IDX_POC)
1757
0
                        * sizeof(void *));
1758
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1759
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1760
0
    ps_dec->ppv_map_ref_idx_to_poc_base = pv_buf;
1761
0
    memset(ps_dec->ppv_map_ref_idx_to_poc_base, 0, size);
1762
1763
0
    ps_dec->ppv_map_ref_idx_to_poc = ps_dec->ppv_map_ref_idx_to_poc_base + OFFSET_MAP_IDX_POC;
1764
1765
1766
0
    size = (sizeof(bin_ctxt_model_t) * NUM_CABAC_CTXTS);
1767
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1768
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1769
0
    memset(pv_buf, 0, size);
1770
0
    ps_dec->p_cabac_ctxt_table_t = pv_buf;
1771
1772
1773
1774
0
    size = sizeof(ctxt_inc_mb_info_t);
1775
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1776
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1777
0
    memset(pv_buf, 0, size);
1778
0
    ps_dec->ps_left_mb_ctxt_info = pv_buf;
1779
1780
1781
1782
0
    size = MAX_REF_BUF_SIZE * 2;
1783
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1784
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1785
0
    memset(pv_buf, 0, size);
1786
0
    ps_dec->pu1_ref_buff_base = pv_buf;
1787
0
    ps_dec->pu1_ref_buff = ps_dec->pu1_ref_buff_base + MAX_REF_BUF_SIZE;
1788
1789
1790
0
    size = ((sizeof(WORD16)) * PRED_BUFFER_WIDTH
1791
0
                        * PRED_BUFFER_HEIGHT * 2);
1792
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1793
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1794
0
    memset(pv_buf, 0, size);
1795
0
    ps_dec->pi2_pred1 = pv_buf;
1796
1797
1798
0
    size = sizeof(UWORD8) * (MB_LUM_SIZE);
1799
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1800
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1801
0
    memset(pv_buf, 0, size);
1802
0
    ps_dec->pu1_temp_mc_buffer = pv_buf;
1803
1804
1805
1806
1807
0
    size = 8 * MAX_REF_BUFS * sizeof(struct pic_buffer_t);
1808
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1809
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1810
0
    memset(pv_buf, 0, size);
1811
1812
0
    ps_dec->pu1_init_dpb_base = pv_buf;
1813
0
    pu1_buf = pv_buf;
1814
0
    ps_dec->ps_dpb_mgr->ps_init_dpb[0][0] = (struct pic_buffer_t *)pu1_buf;
1815
1816
0
    pu1_buf += size / 2;
1817
0
    ps_dec->ps_dpb_mgr->ps_init_dpb[1][0] = (struct pic_buffer_t *)pu1_buf;
1818
1819
0
    size = (sizeof(UWORD32) * 2 * 3
1820
0
                        * ((MAX_FRAMES << 1) * (MAX_FRAMES << 1)) * 2);
1821
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1822
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1823
0
    memset(pv_buf, 0, size);
1824
0
    ps_dec->pu4_mbaff_wt_mat = pv_buf;
1825
1826
0
    size = sizeof(UWORD32) * 2 * 3
1827
0
                        * ((MAX_FRAMES << 1) * (MAX_FRAMES << 1));
1828
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1829
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1830
0
    memset(pv_buf, 0, size);
1831
0
    ps_dec->pu4_wts_ofsts_mat = pv_buf;
1832
1833
1834
0
    size = (sizeof(neighbouradd_t) << 2);
1835
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1836
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1837
0
    memset(pv_buf, 0, size);
1838
0
    ps_dec->ps_left_mvpred_addr = pv_buf;
1839
1840
1841
0
    size = sizeof(buf_mgr_t) + ithread_get_mutex_lock_size();
1842
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1843
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1844
0
    memset(pv_buf, 0, size);
1845
0
    ps_dec->pv_mv_buf_mgr = pv_buf;
1846
1847
1848
0
    size =  sizeof(col_mv_buf_t) * (H264_MAX_REF_PICS * 2);
1849
0
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1850
0
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1851
0
    ps_dec->ps_col_mv_base = pv_buf;
1852
0
    memset(ps_dec->ps_col_mv_base, 0, size);
1853
1854
0
    ih264d_init_decoder(ps_dec);
1855
1856
0
    return IV_SUCCESS;
1857
0
}
1858
1859
1860
/*****************************************************************************/
1861
/*                                                                           */
1862
/*  Function Name : ih264d_create                                              */
1863
/*                                                                           */
1864
/*  Description   : creates decoder                                          */
1865
/*                                                                           */
1866
/*  Inputs        :iv_obj_t decoder handle                                   */
1867
/*                :pv_api_ip pointer to input structure                      */
1868
/*                :pv_api_op pointer to output structure                     */
1869
/*  Outputs       :                                                          */
1870
/*  Returns       : void                                                     */
1871
/*                                                                           */
1872
/*  Issues        : none                                                     */
1873
/*                                                                           */
1874
/*  Revision History:                                                        */
1875
/*                                                                           */
1876
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1877
/*         22 10 2008    100356         Draft                                */
1878
/*                                                                           */
1879
/*****************************************************************************/
1880
WORD32 ih264d_create(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
1881
0
{
1882
0
    ih264d_create_ip_t *ps_create_ip;
1883
0
    ih264d_create_op_t *ps_create_op;
1884
1885
0
    WORD32 ret;
1886
1887
0
    ps_create_ip = (ih264d_create_ip_t *)pv_api_ip;
1888
0
    ps_create_op = (ih264d_create_op_t *)pv_api_op;
1889
1890
0
    ps_create_op->s_ivd_create_op_t.u4_error_code = 0;
1891
0
    dec_hdl = NULL;
1892
0
    ret = ih264d_allocate_static_bufs(&dec_hdl, pv_api_ip, pv_api_op);
1893
1894
    /* If allocation of some buffer fails, then free buffers allocated till then */
1895
0
    if(IV_FAIL == ret)
1896
0
    {
1897
0
        if(dec_hdl)
1898
0
        {
1899
0
            if(dec_hdl->pv_codec_handle)
1900
0
            {
1901
0
                ih264d_free_static_bufs(dec_hdl);
1902
0
            }
1903
0
            else
1904
0
            {
1905
0
                void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1906
0
                void *pv_mem_ctxt;
1907
1908
0
                pf_aligned_free = ps_create_ip->s_ivd_create_ip_t.pf_aligned_free;
1909
0
                pv_mem_ctxt  = ps_create_ip->s_ivd_create_ip_t.pv_mem_ctxt;
1910
0
                pf_aligned_free(pv_mem_ctxt, dec_hdl);
1911
0
            }
1912
0
        }
1913
0
        ps_create_op->s_ivd_create_op_t.u4_error_code = IVD_MEM_ALLOC_FAILED;
1914
0
        ps_create_op->s_ivd_create_op_t.u4_error_code |= 1 << IVD_FATALERROR;
1915
1916
0
        return IV_FAIL;
1917
0
    }
1918
1919
0
    return IV_SUCCESS;
1920
0
}
1921
1922
/*****************************************************************************/
1923
/*                                                                           */
1924
/*  Function Name :  ih264d_map_error                                        */
1925
/*                                                                           */
1926
/*  Description   :  Maps error codes to IVD error groups                    */
1927
/*                                                                           */
1928
/*  Inputs        :                                                          */
1929
/*  Globals       : <Does it use any global variables?>                      */
1930
/*  Outputs       :                                                          */
1931
/*  Returns       : void                                                     */
1932
/*                                                                           */
1933
/*  Issues        : none                                                     */
1934
/*                                                                           */
1935
/*  Revision History:                                                        */
1936
/*                                                                           */
1937
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1938
/*         22 10 2008    100356         Draft                                */
1939
/*                                                                           */
1940
/*****************************************************************************/
1941
UWORD32 ih264d_map_error(UWORD32 i4_err_status)
1942
95.2k
{
1943
95.2k
    UWORD32 temp = 0;
1944
1945
95.2k
    switch(i4_err_status)
1946
95.2k
    {
1947
0
        case ERROR_MEM_ALLOC_ISRAM_T:
1948
0
        case ERROR_MEM_ALLOC_SDRAM_T:
1949
0
        case ERROR_BUF_MGR:
1950
0
        case ERROR_MB_GROUP_ASSGN_T:
1951
0
        case ERROR_FRAME_LIMIT_OVER:
1952
0
        case ERROR_ACTUAL_RESOLUTION_GREATER_THAN_INIT:
1953
0
        case ERROR_PROFILE_NOT_SUPPORTED:
1954
0
        case ERROR_INIT_NOT_DONE:
1955
0
        case IVD_MEM_ALLOC_FAILED:
1956
657
        case ERROR_FEATURE_UNAVAIL:
1957
981
        case IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED:
1958
981
            temp = 1 << IVD_FATALERROR;
1959
981
            H264_DEC_DEBUG_PRINT("\nFatal Error\n");
1960
981
            break;
1961
1962
0
        case ERROR_DBP_MANAGER_T:
1963
0
        case ERROR_GAPS_IN_FRM_NUM:
1964
0
        case ERROR_UNKNOWN_NAL:
1965
0
        case ERROR_INV_MB_SLC_GRP_T:
1966
0
        case ERROR_MULTIPLE_SLC_GRP_T:
1967
0
        case ERROR_UNKNOWN_LEVEL:
1968
0
        case ERROR_UNAVAIL_PICBUF_T:
1969
0
        case ERROR_UNAVAIL_MVBUF_T:
1970
0
        case ERROR_UNAVAIL_DISPBUF_T:
1971
15
        case ERROR_NUM_REF:
1972
15
        case ERROR_REFIDX_ORDER_T:
1973
15
        case ERROR_PIC0_NOT_FOUND_T:
1974
15
        case ERROR_MB_TYPE:
1975
15
        case ERROR_SUB_MB_TYPE:
1976
15
        case ERROR_CBP:
1977
303
        case ERROR_REF_IDX:
1978
303
        case ERROR_NUM_MV:
1979
303
        case ERROR_CHROMA_PRED_MODE:
1980
303
        case ERROR_INTRAPRED:
1981
303
        case ERROR_NEXT_MB_ADDRESS_T:
1982
303
        case ERROR_MB_ADDRESS_T:
1983
303
        case ERROR_PIC1_NOT_FOUND_T:
1984
303
        case ERROR_CAVLC_NUM_COEFF_T:
1985
303
        case ERROR_CAVLC_SCAN_POS_T:
1986
303
        case ERROR_PRED_WEIGHT_TABLE_T:
1987
303
        case ERROR_CORRUPTED_SLICE:
1988
303
            temp = 1 << IVD_CORRUPTEDDATA;
1989
303
            break;
1990
1991
0
        case ERROR_NOT_SUPP_RESOLUTION:
1992
0
        case ERROR_ACTUAL_LEVEL_GREATER_THAN_INIT:
1993
0
            temp = 1 << IVD_UNSUPPORTEDINPUT;
1994
0
            break;
1995
1996
0
        case ERROR_INVALID_PIC_PARAM:
1997
5
        case ERROR_INVALID_SEQ_PARAM:
1998
5
        case ERROR_EGC_EXCEED_32_1_T:
1999
5
        case ERROR_EGC_EXCEED_32_2_T:
2000
5
        case ERROR_INV_RANGE_TEV_T:
2001
5
        case ERROR_INV_SLC_TYPE_T:
2002
22
        case ERROR_INV_POC_TYPE_T:
2003
255
        case ERROR_INV_RANGE_QP_T:
2004
1.05k
        case ERROR_INV_SPS_PPS_T:
2005
1.05k
        case ERROR_INV_SLICE_HDR_T:
2006
1.05k
        case ERROR_INV_SEI_MDCV_PARAMS:
2007
1.05k
        case ERROR_INV_SEI_CLL_PARAMS:
2008
1.05k
        case ERROR_INV_SEI_AVE_PARAMS:
2009
1.10k
        case ERROR_INV_SEI_CCV_PARAMS:
2010
1.10k
        case ERROR_INV_SEI_SII_PARAMS:
2011
2012
1.10k
            temp = 1 << IVD_CORRUPTEDHEADER;
2013
1.10k
            break;
2014
2015
0
        case ERROR_EOB_FLUSHBITS_T:
2016
380
        case ERROR_EOB_GETBITS_T:
2017
380
        case ERROR_EOB_GETBIT_T:
2018
380
        case ERROR_EOB_BYPASS_T:
2019
380
        case ERROR_EOB_DECISION_T:
2020
380
        case ERROR_EOB_TERMINATE_T:
2021
380
        case ERROR_EOB_READCOEFF4X4CAB_T:
2022
380
            temp = 1 << IVD_INSUFFICIENTDATA;
2023
380
            break;
2024
0
        case ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED:
2025
0
        case ERROR_DISP_WIDTH_RESET_TO_PIC_WIDTH:
2026
0
            temp = 1 << IVD_UNSUPPORTEDPARAM | 1 << IVD_FATALERROR;
2027
0
            break;
2028
2029
0
        case ERROR_DANGLING_FIELD_IN_PIC:
2030
0
            temp = 1 << IVD_APPLIEDCONCEALMENT;
2031
0
            break;
2032
2033
0
        case IVD_DEC_FRM_SKIPPED:
2034
0
            break;
2035
2036
95.2k
    }
2037
2038
95.2k
    return temp;
2039
2040
95.2k
}
2041
2042
UWORD32 ih264d_get_outbuf_size(WORD32 pic_wd,
2043
                               UWORD32 pic_ht,
2044
                               UWORD8 u1_chroma_format,
2045
                               UWORD32 *p_buf_size)
2046
150k
{
2047
150k
    UWORD32 u4_min_num_out_bufs = 0;
2048
2049
150k
    if(u1_chroma_format == IV_YUV_420P)
2050
71.2k
        u4_min_num_out_bufs = MIN_OUT_BUFS_420;
2051
79.1k
    else if(u1_chroma_format == IV_YUV_422ILE)
2052
0
        u4_min_num_out_bufs = MIN_OUT_BUFS_422ILE;
2053
79.1k
    else if(u1_chroma_format == IV_RGB_565)
2054
0
        u4_min_num_out_bufs = MIN_OUT_BUFS_RGB565;
2055
79.1k
    else if((u1_chroma_format == IV_YUV_420SP_UV)
2056
28.9k
                    || (u1_chroma_format == IV_YUV_420SP_VU))
2057
79.1k
        u4_min_num_out_bufs = MIN_OUT_BUFS_420SP;
2058
2059
150k
    if(u1_chroma_format == IV_YUV_420P)
2060
71.2k
    {
2061
71.2k
        p_buf_size[0] = (pic_wd * pic_ht);
2062
71.2k
        p_buf_size[1] = (pic_wd * pic_ht) >> 2;
2063
71.2k
        p_buf_size[2] = (pic_wd * pic_ht) >> 2;
2064
71.2k
    }
2065
79.1k
    else if(u1_chroma_format == IV_YUV_422ILE)
2066
0
    {
2067
0
        p_buf_size[0] = (pic_wd * pic_ht) * 2;
2068
0
        p_buf_size[1] = p_buf_size[2] = 0;
2069
0
    }
2070
79.1k
    else if(u1_chroma_format == IV_RGB_565)
2071
0
    {
2072
0
        p_buf_size[0] = (pic_wd * pic_ht) * 2;
2073
0
        p_buf_size[1] = p_buf_size[2] = 0;
2074
0
    }
2075
79.1k
    else if((u1_chroma_format == IV_YUV_420SP_UV)
2076
28.9k
                    || (u1_chroma_format == IV_YUV_420SP_VU))
2077
79.1k
    {
2078
79.1k
        p_buf_size[0] = (pic_wd * pic_ht);
2079
79.1k
        p_buf_size[1] = (pic_wd * pic_ht) >> 1;
2080
79.1k
        p_buf_size[2] = 0;
2081
79.1k
    }
2082
2083
150k
    return u4_min_num_out_bufs;
2084
150k
}
2085
2086
WORD32 check_app_out_buf_size(dec_struct_t *ps_dec)
2087
150k
{
2088
150k
    UWORD32 au4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
2089
150k
    UWORD32 u4_min_num_out_bufs, i;
2090
150k
    UWORD32 pic_wd, pic_ht;
2091
2092
150k
    if(0 == ps_dec->u4_share_disp_buf)
2093
150k
    {
2094
150k
        pic_wd = ps_dec->u2_disp_width;
2095
150k
        pic_ht = ps_dec->u2_disp_height;
2096
2097
150k
    }
2098
0
    else
2099
0
    {
2100
0
        pic_wd = ps_dec->u2_frm_wd_y;
2101
0
        pic_ht = ps_dec->u2_frm_ht_y;
2102
0
    }
2103
2104
150k
    if(ps_dec->u4_app_disp_width > pic_wd)
2105
0
        pic_wd = ps_dec->u4_app_disp_width;
2106
2107
150k
    u4_min_num_out_bufs = ih264d_get_outbuf_size(pic_wd, pic_ht,
2108
150k
                                                 ps_dec->u1_chroma_format,
2109
150k
                                                 &au4_min_out_buf_size[0]);
2110
2111
2112
150k
    if(0 == ps_dec->u4_share_disp_buf)
2113
150k
    {
2114
150k
        if(ps_dec->ps_out_buffer->u4_num_bufs < u4_min_num_out_bufs)
2115
0
            return IV_FAIL;
2116
2117
517k
        for(i = 0; i < u4_min_num_out_bufs; i++)
2118
368k
        {
2119
368k
            if(ps_dec->ps_out_buffer->u4_min_out_buf_size[i]
2120
368k
                            < au4_min_out_buf_size[i])
2121
1.85k
                return (IV_FAIL);
2122
368k
        }
2123
150k
    }
2124
0
    else
2125
0
    {
2126
0
        if(ps_dec->disp_bufs[0].u4_num_bufs < u4_min_num_out_bufs)
2127
0
            return IV_FAIL;
2128
2129
0
        for(i = 0; i < u4_min_num_out_bufs; i++)
2130
0
        {
2131
            /* We need to check only with the disp_buffer[0], because we have
2132
             * already ensured that all the buffers are of the same size in
2133
             * ih264d_set_display_frame.
2134
             */
2135
0
            if(ps_dec->disp_bufs[0].u4_bufsize[i] < au4_min_out_buf_size[i])
2136
0
                return (IV_FAIL);
2137
0
        }
2138
2139
0
    }
2140
2141
148k
    return (IV_SUCCESS);
2142
150k
}
2143
2144
2145
/*****************************************************************************/
2146
/*                                                                           */
2147
/*  Function Name :  ih264d_video_decode                                     */
2148
/*                                                                           */
2149
/*  Description   :  handle video decode API command                         */
2150
/*                                                                           */
2151
/*  Inputs        :iv_obj_t decoder handle                                   */
2152
/*                :pv_api_ip pointer to input structure                      */
2153
/*                :pv_api_op pointer to output structure                     */
2154
/*  Outputs       :                                                          */
2155
/*  Returns       : void                                                     */
2156
/*                                                                           */
2157
/*  Issues        : none                                                     */
2158
/*                                                                           */
2159
/*  Revision History:                                                        */
2160
/*                                                                           */
2161
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2162
/*         22 10 2008    100356         Draft                                */
2163
/*                                                                           */
2164
/*****************************************************************************/
2165
2166
WORD32 ih264d_video_decode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
2167
0
{
2168
    /* ! */
2169
2170
0
    dec_struct_t * ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
2171
2172
0
    WORD32 i4_err_status = 0;
2173
0
    UWORD8 *pu1_buf = NULL;
2174
0
    WORD32 buflen;
2175
0
    UWORD32 u4_max_ofst, u4_length_of_start_code = 0;
2176
2177
0
    UWORD32 bytes_consumed = 0;
2178
0
    UWORD32 cur_slice_is_nonref = 0;
2179
0
    UWORD32 u4_next_is_aud;
2180
0
    UWORD32 u4_first_start_code_found = 0;
2181
0
    WORD32 ret = 0,api_ret_value = IV_SUCCESS;
2182
0
    WORD32 frm_skipped = 0;
2183
0
    WORD32 header_data_left = 0,frame_data_left = 0;
2184
0
    UWORD8 *pu1_bitstrm_buf;
2185
0
    ih264d_video_decode_ip_t *ps_h264d_dec_ip;
2186
0
    ih264d_video_decode_op_t *ps_h264d_dec_op;
2187
0
    ivd_video_decode_ip_t *ps_dec_ip;
2188
0
    ivd_video_decode_op_t *ps_dec_op;
2189
2190
0
    ithread_set_name((void*)"Parse_thread");
2191
2192
0
    ps_h264d_dec_ip = (ih264d_video_decode_ip_t *)pv_api_ip;
2193
0
    ps_h264d_dec_op = (ih264d_video_decode_op_t *)pv_api_op;
2194
0
    ps_dec_ip = &ps_h264d_dec_ip->s_ivd_video_decode_ip_t;
2195
0
    ps_dec_op = &ps_h264d_dec_op->s_ivd_video_decode_op_t;
2196
2197
0
    {
2198
0
        UWORD32 u4_size;
2199
0
        u4_size = ps_dec_op->u4_size;
2200
0
        memset(ps_h264d_dec_op, 0, ps_dec_op->u4_size);
2201
0
        ps_dec_op->u4_size = u4_size;
2202
0
    }
2203
2204
0
    ps_dec->pv_dec_out = ps_dec_op;
2205
0
    if(ps_dec->init_done != 1)
2206
0
    {
2207
0
        return IV_FAIL;
2208
0
    }
2209
2210
    /*Data memory barries instruction,so that bitstream write by the application is complete*/
2211
0
    DATA_SYNC();
2212
2213
0
    if(0 == ps_dec->u1_flushfrm)
2214
0
    {
2215
0
        if(ps_dec_ip->pv_stream_buffer == NULL)
2216
0
        {
2217
0
            ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
2218
0
            ps_dec_op->u4_error_code |= IVD_DEC_FRM_BS_BUF_NULL;
2219
0
            return IV_FAIL;
2220
0
        }
2221
0
        if(ps_dec_ip->u4_num_Bytes <= 0)
2222
0
        {
2223
0
            ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
2224
0
            ps_dec_op->u4_error_code |= IVD_DEC_NUMBYTES_INV;
2225
0
            return IV_FAIL;
2226
2227
0
        }
2228
0
    }
2229
0
    ps_dec->u1_pic_decode_done = 0;
2230
2231
0
    if(ps_dec->i4_threads_active)
2232
0
    {
2233
0
        UWORD32 i;
2234
0
        ps_dec->i4_break_threads = 0;
2235
0
        for (i = 0; i < 2; i++)
2236
0
        {
2237
0
            ret = ithread_mutex_lock(ps_dec->apv_proc_start_mutex[i]);
2238
0
            RETURN_IF((ret != IV_SUCCESS), ret);
2239
2240
0
            ps_dec->ai4_process_start[i] = PROC_INIT;
2241
2242
0
            ret = ithread_mutex_unlock(ps_dec->apv_proc_start_mutex[i]);
2243
0
            RETURN_IF((ret != IV_SUCCESS), ret);
2244
0
        }
2245
0
    }
2246
0
    else {
2247
0
        ps_dec->u4_dec_thread_created = 0;
2248
0
        ps_dec->u4_bs_deblk_thread_created = 0;
2249
0
    }
2250
2251
0
    ps_dec_op->u4_num_bytes_consumed = 0;
2252
0
    ps_dec_op->i4_reorder_depth = -1;
2253
0
    ps_dec_op->i4_display_index = DEFAULT_POC;
2254
0
    ps_dec->ps_out_buffer = NULL;
2255
2256
0
    if(ps_dec_ip->u4_size
2257
0
                    >= offsetof(ivd_video_decode_ip_t, s_out_buffer))
2258
0
        ps_dec->ps_out_buffer = &ps_dec_ip->s_out_buffer;
2259
2260
0
    ps_dec->u4_fmt_conv_cur_row = 0;
2261
2262
0
    ps_dec->u4_output_present = 0;
2263
0
    ps_dec->s_disp_op.u4_error_code = 1;
2264
0
    ps_dec->u4_fmt_conv_num_rows = FMT_CONV_NUM_ROWS;
2265
0
    if(0 == ps_dec->u4_share_disp_buf
2266
0
                    && ps_dec->i4_decode_header == 0)
2267
0
    {
2268
0
        UWORD32 i;
2269
0
        if((ps_dec->ps_out_buffer->u4_num_bufs == 0) ||
2270
0
           (ps_dec->ps_out_buffer->u4_num_bufs > IVD_VIDDEC_MAX_IO_BUFFERS))
2271
0
        {
2272
0
            ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
2273
0
            ps_dec_op->u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUFS;
2274
0
            return IV_FAIL;
2275
0
        }
2276
2277
0
        for(i = 0; i < ps_dec->ps_out_buffer->u4_num_bufs; i++)
2278
0
        {
2279
0
            if(ps_dec->ps_out_buffer->pu1_bufs[i] == NULL)
2280
0
            {
2281
0
                ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
2282
0
                ps_dec_op->u4_error_code |= IVD_DISP_FRM_OP_BUF_NULL;
2283
0
                return IV_FAIL;
2284
0
            }
2285
2286
0
            if(ps_dec->ps_out_buffer->u4_min_out_buf_size[i] == 0)
2287
0
            {
2288
0
                ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
2289
0
                ps_dec_op->u4_error_code |=
2290
0
                                IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
2291
0
                return IV_FAIL;
2292
0
            }
2293
0
        }
2294
0
    }
2295
2296
0
    if(ps_dec->u4_total_frames_decoded >= NUM_FRAMES_LIMIT)
2297
0
    {
2298
0
        ps_dec_op->u4_error_code = ERROR_FRAME_LIMIT_OVER;
2299
0
        return IV_FAIL;
2300
0
    }
2301
2302
    /* ! */
2303
0
    ps_dec->u4_ts = ps_dec_ip->u4_ts;
2304
0
    ps_dec->i4_error_code = 0;
2305
2306
0
    ps_dec_op->u4_error_code = 0;
2307
0
    ps_dec_op->e_pic_type = IV_NA_FRAME;
2308
0
    ps_dec_op->u4_output_present = 0;
2309
0
    ps_dec_op->u4_frame_decoded_flag = 0;
2310
2311
0
    ps_dec->i4_frametype = IV_NA_FRAME;
2312
0
    ps_dec->i4_content_type = IV_CONTENTTYPE_NA;
2313
2314
0
    ps_dec->u4_slice_start_code_found = 0;
2315
2316
    /* In case the decoder is not in flush mode(in shared mode),
2317
     then decoder has to pick up a buffer to write current frame.
2318
     Check if a frame is available in such cases */
2319
2320
0
    if(ps_dec->u1_init_dec_flag == 1 && ps_dec->u4_share_disp_buf == 1
2321
0
                    && ps_dec->u1_flushfrm == 0)
2322
0
    {
2323
0
        UWORD32 i;
2324
2325
0
        WORD32 disp_avail = 0, free_id;
2326
2327
        /* Check if at least one buffer is available with the codec */
2328
        /* If not then return to application with error */
2329
0
        for(i = 0; i < ps_dec->u1_pic_bufs; i++)
2330
0
        {
2331
0
            if(0 == ps_dec->u4_disp_buf_mapping[i]
2332
0
                            || 1 == ps_dec->u4_disp_buf_to_be_freed[i])
2333
0
            {
2334
0
                disp_avail = 1;
2335
0
                break;
2336
0
            }
2337
2338
0
        }
2339
2340
0
        if(0 == disp_avail)
2341
0
        {
2342
            /* If something is queued for display wait for that buffer to be returned */
2343
2344
0
            ps_dec_op->u4_error_code = IVD_DEC_REF_BUF_NULL;
2345
0
            ps_dec_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
2346
0
            return (IV_FAIL);
2347
0
        }
2348
2349
0
        while(1)
2350
0
        {
2351
0
            pic_buffer_t *ps_pic_buf;
2352
0
            ps_pic_buf = (pic_buffer_t *)ih264_buf_mgr_get_next_free(
2353
0
                            (buf_mgr_t *)ps_dec->pv_pic_buf_mgr, &free_id);
2354
2355
0
            if(ps_pic_buf == NULL)
2356
0
            {
2357
0
                UWORD32 display_queued = 0;
2358
2359
                /* check if any buffer was given for display which is not returned yet */
2360
0
                for(i = 0; i < (MAX_DISP_BUFS_NEW); i++)
2361
0
                {
2362
0
                    if(0 != ps_dec->u4_disp_buf_mapping[i])
2363
0
                    {
2364
0
                        display_queued = 1;
2365
0
                        break;
2366
0
                    }
2367
0
                }
2368
                /* If some buffer is queued for display, then codec has to singal an error and wait
2369
                 for that buffer to be returned.
2370
                 If nothing is queued for display then codec has ownership of all display buffers
2371
                 and it can reuse any of the existing buffers and continue decoding */
2372
2373
0
                if(1 == display_queued)
2374
0
                {
2375
                    /* If something is queued for display wait for that buffer to be returned */
2376
0
                    ps_dec_op->u4_error_code = IVD_DEC_REF_BUF_NULL;
2377
0
                    ps_dec_op->u4_error_code |= (1
2378
0
                                    << IVD_UNSUPPORTEDPARAM);
2379
0
                    return (IV_FAIL);
2380
0
                }
2381
0
            }
2382
0
            else
2383
0
            {
2384
                /* If the buffer is with display, then mark it as in use and then look for a buffer again */
2385
0
                if(1 == ps_dec->u4_disp_buf_mapping[free_id])
2386
0
                {
2387
0
                    ih264_buf_mgr_set_status(
2388
0
                                    (buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
2389
0
                                    free_id,
2390
0
                                    BUF_MGR_IO);
2391
0
                }
2392
0
                else
2393
0
                {
2394
                    /**
2395
                     *  Found a free buffer for present call. Release it now.
2396
                     *  Will be again obtained later.
2397
                     */
2398
0
                    ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
2399
0
                                          free_id,
2400
0
                                          BUF_MGR_IO);
2401
0
                    break;
2402
0
                }
2403
0
            }
2404
0
        }
2405
2406
0
    }
2407
2408
0
    if(ps_dec->u1_enable_mb_info && (ps_dec->i4_header_decoded & DECODED_SPS_MASK))
2409
0
    {
2410
0
        UWORD32 blk_qp_map_size = ps_h264d_dec_ip->u4_8x8_blk_qp_map_size;
2411
0
        UWORD32 blk_type_map_size = ps_h264d_dec_ip->u4_8x8_blk_type_map_size;
2412
0
        UWORD32 blk_8x8_map_size = ps_dec->u4_total_mbs << 2;
2413
0
        if ((ps_h264d_dec_ip->pu1_8x8_blk_qp_map && blk_qp_map_size < blk_8x8_map_size) ||
2414
0
            (ps_h264d_dec_ip->pu1_8x8_blk_type_map && blk_type_map_size < blk_8x8_map_size))
2415
0
        {
2416
0
            ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
2417
0
            ps_dec_op->u4_error_code |= IH264D_INSUFFICIENT_METADATA_BUFFER;
2418
0
            return IV_FAIL;
2419
0
        }
2420
0
    }
2421
2422
0
    if(ps_dec->u1_flushfrm)
2423
0
    {
2424
0
        if(ps_dec->u1_init_dec_flag == 0)
2425
0
        {
2426
            /*Come out of flush mode and return*/
2427
0
            ps_dec->u1_flushfrm = 0;
2428
0
            return (IV_FAIL);
2429
0
        }
2430
2431
2432
2433
0
        ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer,
2434
0
                                      &(ps_dec->s_disp_op));
2435
0
        if(0 == ps_dec->s_disp_op.u4_error_code)
2436
0
        {
2437
            /* check output buffer size given by the application */
2438
0
            if(check_app_out_buf_size(ps_dec) != IV_SUCCESS)
2439
0
            {
2440
0
                ps_dec_op->u4_error_code= IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
2441
0
                return (IV_FAIL);
2442
0
            }
2443
2444
0
            ps_dec->u4_fmt_conv_cur_row = 0;
2445
0
            ps_dec->u4_fmt_conv_num_rows = ps_dec->s_disp_frame_info.u4_y_ht;
2446
0
            ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op),
2447
0
                                  ps_dec->u4_fmt_conv_cur_row,
2448
0
                                  ps_dec->u4_fmt_conv_num_rows);
2449
0
            ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
2450
0
            ps_dec->u4_output_present = 1;
2451
2452
0
            if(ps_dec->u1_enable_mb_info)
2453
0
            {
2454
0
                UWORD32 disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
2455
0
                if(ps_h264d_dec_ip->pu1_8x8_blk_qp_map)
2456
0
                {
2457
0
                    ps_h264d_dec_op->pu1_8x8_blk_qp_map = ps_h264d_dec_ip->pu1_8x8_blk_qp_map;
2458
0
                    ps_h264d_dec_op->u4_8x8_blk_qp_map_size = ps_dec->u4_total_mbs << 2;
2459
0
                    memcpy(ps_h264d_dec_op->pu1_8x8_blk_qp_map,
2460
0
                        ps_dec->as_buf_id_info_map[disp_buf_id].pu1_qp_map,
2461
0
                        ps_dec->u4_total_mbs << 2);
2462
0
                }
2463
0
                if(ps_h264d_dec_ip->pu1_8x8_blk_type_map)
2464
0
                {
2465
0
                    ps_h264d_dec_op->pu1_8x8_blk_type_map = ps_h264d_dec_ip->pu1_8x8_blk_type_map;
2466
0
                    ps_h264d_dec_op->u4_8x8_blk_type_map_size = ps_dec->u4_total_mbs << 2;
2467
0
                    memcpy(ps_h264d_dec_op->pu1_8x8_blk_type_map,
2468
0
                        ps_dec->as_buf_id_info_map[disp_buf_id].pu1_mb_type_map,
2469
0
                        ps_dec->u4_total_mbs << 2);
2470
0
                }
2471
0
            }
2472
0
        }
2473
0
        ih264d_export_sei_params(&ps_dec_op->s_sei_decode_op, ps_dec);
2474
2475
0
        ih264d_release_display_field(ps_dec, &(ps_dec->s_disp_op));
2476
2477
0
        ps_dec_op->u4_pic_wd = (UWORD32)ps_dec->u2_disp_width;
2478
0
        ps_dec_op->u4_pic_ht = (UWORD32)ps_dec->u2_disp_height;
2479
0
        ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
2480
0
        ps_dec_op->i4_display_index = ps_dec->i4_display_index;
2481
2482
0
        ps_dec_op->u4_new_seq = 0;
2483
2484
0
        ps_dec_op->u4_output_present = ps_dec->u4_output_present;
2485
0
        ps_dec_op->u4_progressive_frame_flag =
2486
0
                        ps_dec->s_disp_op.u4_progressive_frame_flag;
2487
0
        ps_dec_op->e_output_format =
2488
0
                        ps_dec->s_disp_op.e_output_format;
2489
0
        ps_dec_op->s_disp_frm_buf = ps_dec->s_disp_op.s_disp_frm_buf;
2490
0
        ps_dec_op->e4_fld_type = ps_dec->s_disp_op.e4_fld_type;
2491
0
        ps_dec_op->u4_ts = ps_dec->s_disp_op.u4_ts;
2492
0
        ps_dec_op->u4_disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
2493
2494
        /*In the case of flush ,since no frame is decoded set pic type as invalid*/
2495
0
        ps_dec_op->u4_is_ref_flag = -1;
2496
0
        ps_dec_op->e_pic_type = IV_NA_FRAME;
2497
0
        ps_dec_op->u4_frame_decoded_flag = 0;
2498
2499
0
        if(0 == ps_dec->s_disp_op.u4_error_code)
2500
0
        {
2501
0
            return (IV_SUCCESS);
2502
0
        }
2503
0
        else
2504
0
            return (IV_FAIL);
2505
2506
0
    }
2507
0
    if(ps_dec->u1_res_changed == 1)
2508
0
    {
2509
        /*if resolution has changed and all buffers have been flushed, reset decoder*/
2510
0
        ih264d_init_decoder(ps_dec);
2511
0
    }
2512
2513
0
    ps_dec->u4_cur_mb_addr = 0;
2514
0
    ps_dec->u4_total_mbs_coded = 0;
2515
0
    ps_dec->u2_cur_slice_num = 0;
2516
0
    ps_dec->cur_dec_mb_num = 0;
2517
0
    ps_dec->cur_recon_mb_num = 0;
2518
0
    ps_dec->u4_first_slice_in_pic = 1;
2519
0
    ps_dec->u1_slice_header_done = 0;
2520
0
    ps_dec->u1_dangling_field = 0;
2521
0
    ps_dec->u4_cur_bs_mb_num = 0;
2522
0
    ps_dec->u4_start_recon_deblk  = 0;
2523
0
    ps_dec->u4_sps_cnt_in_process = 0;
2524
2525
0
    DEBUG_THREADS_PRINTF(" Starting process call\n");
2526
2527
2528
0
    ps_dec->u4_pic_buf_got = 0;
2529
2530
0
    do
2531
0
    {
2532
0
        WORD32 buf_size;
2533
2534
0
        pu1_buf = (UWORD8*)ps_dec_ip->pv_stream_buffer
2535
0
                        + ps_dec_op->u4_num_bytes_consumed;
2536
2537
0
        u4_max_ofst = ps_dec_ip->u4_num_Bytes
2538
0
                        - ps_dec_op->u4_num_bytes_consumed;
2539
2540
        /* If dynamic bitstream buffer is not allocated and
2541
         * header decode is done, then allocate dynamic bitstream buffer
2542
         */
2543
0
        if((NULL == ps_dec->pu1_bits_buf_dynamic) &&
2544
0
           (ps_dec->i4_header_decoded & 1))
2545
0
        {
2546
0
            WORD32 size;
2547
2548
0
            void *pv_buf;
2549
0
            void *pv_mem_ctxt = ps_dec->pv_mem_ctxt;
2550
0
            size = MAX(256000, ps_dec->u2_pic_wd * ps_dec->u2_pic_ht * 3 / 2);
2551
0
            pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128,
2552
0
                                              size + EXTRA_BS_OFFSET);
2553
0
            RETURN_IF((NULL == pv_buf), IV_FAIL);
2554
0
            memset(pv_buf, 0, size + EXTRA_BS_OFFSET);
2555
0
            ps_dec->pu1_bits_buf_dynamic = pv_buf;
2556
0
            ps_dec->u4_dynamic_bits_buf_size = size;
2557
0
        }
2558
2559
0
        if(ps_dec->pu1_bits_buf_dynamic)
2560
0
        {
2561
0
            pu1_bitstrm_buf = ps_dec->pu1_bits_buf_dynamic;
2562
0
            buf_size = ps_dec->u4_dynamic_bits_buf_size;
2563
0
        }
2564
0
        else
2565
0
        {
2566
0
            pu1_bitstrm_buf = ps_dec->pu1_bits_buf_static;
2567
0
            buf_size = ps_dec->u4_static_bits_buf_size;
2568
0
        }
2569
2570
0
        u4_next_is_aud = 0;
2571
2572
0
        buflen = ih264d_find_start_code(pu1_buf, 0, u4_max_ofst,
2573
0
                                               &u4_length_of_start_code,
2574
0
                                               &u4_next_is_aud);
2575
2576
0
        if(buflen == -1)
2577
0
            buflen = 0;
2578
        /* Ignore bytes beyond the allocated size of intermediate buffer */
2579
        /* Since 8 bytes are read ahead, ensure 8 bytes are free at the
2580
        end of the buffer, which will be memset to 0 after emulation prevention */
2581
0
        buflen = MIN(buflen, buf_size - 8);
2582
2583
0
        bytes_consumed = buflen + u4_length_of_start_code;
2584
0
        ps_dec_op->u4_num_bytes_consumed += bytes_consumed;
2585
2586
0
        if(buflen)
2587
0
        {
2588
0
            memcpy(pu1_bitstrm_buf, pu1_buf + u4_length_of_start_code,
2589
0
                   buflen);
2590
            /* Decoder may read extra 8 bytes near end of the frame */
2591
0
            if((buflen + 8) < buf_size)
2592
0
            {
2593
0
                memset(pu1_bitstrm_buf + buflen, 0, 8);
2594
0
            }
2595
0
            u4_first_start_code_found = 1;
2596
2597
0
        }
2598
0
        else
2599
0
        {
2600
            /*start code not found*/
2601
2602
0
            if(u4_first_start_code_found == 0)
2603
0
            {
2604
                /*no start codes found in current process call*/
2605
2606
0
                ps_dec->i4_error_code = ERROR_START_CODE_NOT_FOUND;
2607
0
                ps_dec_op->u4_error_code |= 1 << IVD_INSUFFICIENTDATA;
2608
2609
0
                if(ps_dec->u4_pic_buf_got == 0)
2610
0
                {
2611
2612
0
                    ih264d_fill_output_struct_from_context(ps_dec,
2613
0
                                                           ps_dec_op);
2614
2615
0
                    ps_dec_op->u4_error_code = ps_dec->i4_error_code;
2616
0
                    ps_dec_op->u4_frame_decoded_flag = 0;
2617
2618
0
                    return (IV_FAIL);
2619
0
                }
2620
0
                else
2621
0
                {
2622
0
                    ps_dec->u1_pic_decode_done = 1;
2623
0
                    continue;
2624
0
                }
2625
0
            }
2626
0
            else
2627
0
            {
2628
                /* a start code has already been found earlier in the same process call*/
2629
0
                frame_data_left = 0;
2630
0
                header_data_left = 0;
2631
0
                continue;
2632
0
            }
2633
2634
0
        }
2635
2636
0
        ret = ih264d_parse_nal_unit(dec_hdl, ps_dec_op,
2637
0
                              pu1_bitstrm_buf, buflen);
2638
0
        if(ret == IVD_DEC_FRM_SKIPPED)
2639
0
        {
2640
0
            frm_skipped = 1;
2641
0
            ret = OK;
2642
0
        }
2643
0
        else if(ret != OK)
2644
0
        {
2645
0
            UWORD32 error =  ih264d_map_error(ret);
2646
0
            ps_dec_op->u4_error_code = error | ret;
2647
0
            api_ret_value = IV_FAIL;
2648
2649
0
            if((ret == IVD_RES_CHANGED)
2650
0
                            || (ret == IVD_MEM_ALLOC_FAILED)
2651
0
                            || (ret == ERROR_UNAVAIL_PICBUF_T)
2652
0
                            || (ret == ERROR_UNAVAIL_MVBUF_T)
2653
0
                            || (ret == ERROR_INV_SPS_PPS_T)
2654
0
                            || (ret == ERROR_FEATURE_UNAVAIL)
2655
0
                            || (ret == IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED)
2656
0
                            || (ret == IVD_DISP_FRM_ZERO_OP_BUF_SIZE))
2657
0
            {
2658
0
                ps_dec->u4_slice_start_code_found = 0;
2659
0
                break;
2660
0
            }
2661
2662
0
            if((ret == ERROR_INCOMPLETE_FRAME) || (ret == ERROR_DANGLING_FIELD_IN_PIC))
2663
0
            {
2664
0
                ps_dec_op->u4_num_bytes_consumed -= bytes_consumed;
2665
0
                api_ret_value = IV_FAIL;
2666
0
                break;
2667
0
            }
2668
2669
0
            if(ret == ERROR_IN_LAST_SLICE_OF_PIC)
2670
0
            {
2671
0
                api_ret_value = IV_FAIL;
2672
0
                break;
2673
0
            }
2674
2675
0
        }
2676
2677
0
        header_data_left = ((ps_dec->i4_decode_header == 1)
2678
0
                        && (ps_dec->i4_header_decoded != 3)
2679
0
                        && (ps_dec_op->u4_num_bytes_consumed
2680
0
                                        < ps_dec_ip->u4_num_Bytes));
2681
0
        frame_data_left = (((ps_dec->i4_decode_header == 0)
2682
0
                        && ((ps_dec->u1_pic_decode_done == 0)
2683
0
                                        || (u4_next_is_aud == 1)))
2684
0
                        && (ps_dec_op->u4_num_bytes_consumed
2685
0
                                        < ps_dec_ip->u4_num_Bytes));
2686
0
    }
2687
0
    while(( header_data_left == 1)||(frame_data_left == 1));
2688
2689
0
    if((ps_dec->u4_pic_buf_got == 1)
2690
0
            && (ret != IVD_MEM_ALLOC_FAILED)
2691
0
            && ps_dec->u4_total_mbs_coded < ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
2692
0
    {
2693
        // last slice - missing/corruption
2694
0
        WORD32 num_mb_skipped;
2695
0
        WORD32 prev_slice_err;
2696
0
        pocstruct_t temp_poc;
2697
0
        WORD32 ret1;
2698
0
        WORD32 ht_in_mbs;
2699
0
        ht_in_mbs = ps_dec->u2_pic_ht >> (4 + ps_dec->ps_cur_slice->u1_field_pic_flag);
2700
0
        num_mb_skipped = (ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
2701
0
                            - ps_dec->u4_total_mbs_coded;
2702
2703
0
        if(ps_dec->u4_first_slice_in_pic && (ps_dec->u4_pic_buf_got == 0))
2704
0
            prev_slice_err = 1;
2705
0
        else
2706
0
            prev_slice_err = 2;
2707
2708
0
        if(ps_dec->u4_first_slice_in_pic && (ps_dec->u4_total_mbs_coded == 0))
2709
0
            prev_slice_err = 1;
2710
2711
0
        ret1 = ih264d_mark_err_slice_skip(ps_dec, num_mb_skipped, ps_dec->u1_nal_unit_type == IDR_SLICE_NAL, ps_dec->ps_cur_slice->u2_frame_num,
2712
0
                                   &temp_poc, prev_slice_err);
2713
2714
0
        if((ret1 == ERROR_UNAVAIL_PICBUF_T) || (ret1 == ERROR_UNAVAIL_MVBUF_T) ||
2715
0
                       (ret1 == ERROR_INV_SPS_PPS_T))
2716
0
        {
2717
0
            ret = ret1;
2718
0
        }
2719
0
    }
2720
2721
0
    if((ret == IVD_RES_CHANGED)
2722
0
                    || (ret == IVD_MEM_ALLOC_FAILED)
2723
0
                    || (ret == ERROR_UNAVAIL_PICBUF_T)
2724
0
                    || (ret == ERROR_UNAVAIL_MVBUF_T)
2725
0
                    || (ret == ERROR_INV_SPS_PPS_T))
2726
0
    {
2727
2728
        /* signal the decode thread */
2729
0
        ih264d_signal_decode_thread(ps_dec);
2730
        /* close deblock thread if it is not closed yet */
2731
0
        if(ps_dec->u4_num_cores == 3)
2732
0
        {
2733
0
            ih264d_signal_bs_deblk_thread(ps_dec);
2734
0
        }
2735
        /* dont consume bitstream for change in resolution case */
2736
0
        if(ret == IVD_RES_CHANGED)
2737
0
        {
2738
0
            ps_dec_op->u4_num_bytes_consumed -= bytes_consumed;
2739
0
        }
2740
0
        return IV_FAIL;
2741
0
    }
2742
2743
2744
0
    if(ps_dec->u1_separate_parse)
2745
0
    {
2746
        /* If Format conversion is not complete,
2747
         complete it here */
2748
0
        if(ps_dec->u4_num_cores == 2)
2749
0
        {
2750
2751
            /*do deblocking of all mbs*/
2752
0
            if((ps_dec->u4_nmb_deblk == 0) &&(ps_dec->u4_start_recon_deblk == 1) && (ps_dec->ps_cur_sps->u1_mb_aff_flag == 0))
2753
0
            {
2754
0
                UWORD32 u4_num_mbs,u4_max_addr;
2755
0
                tfr_ctxt_t s_tfr_ctxt;
2756
0
                tfr_ctxt_t *ps_tfr_cxt = &s_tfr_ctxt;
2757
0
                pad_mgr_t *ps_pad_mgr = &ps_dec->s_pad_mgr;
2758
2759
                /*BS is done for all mbs while parsing*/
2760
0
                u4_max_addr = (ps_dec->u2_frm_wd_in_mbs * ps_dec->u2_frm_ht_in_mbs) - 1;
2761
0
                ps_dec->u4_cur_bs_mb_num = u4_max_addr + 1;
2762
2763
2764
0
                ih264d_init_deblk_tfr_ctxt(ps_dec, ps_pad_mgr, ps_tfr_cxt,
2765
0
                                           ps_dec->u2_frm_wd_in_mbs, 0);
2766
2767
2768
0
                u4_num_mbs = u4_max_addr
2769
0
                                - ps_dec->u4_cur_deblk_mb_num + 1;
2770
2771
0
                DEBUG_PERF_PRINTF("mbs left for deblocking= %d \n",u4_num_mbs);
2772
2773
0
                if(u4_num_mbs != 0)
2774
0
                    ih264d_check_mb_map_deblk(ps_dec, u4_num_mbs,
2775
0
                                                   ps_tfr_cxt,1);
2776
2777
0
                ps_dec->u4_start_recon_deblk  = 0;
2778
2779
0
            }
2780
2781
0
        }
2782
2783
        /*signal the decode thread*/
2784
0
        ih264d_signal_decode_thread(ps_dec);
2785
        /* close deblock thread if it is not closed yet*/
2786
0
        if(ps_dec->u4_num_cores == 3)
2787
0
        {
2788
0
            ih264d_signal_bs_deblk_thread(ps_dec);
2789
0
        }
2790
0
    }
2791
2792
2793
0
    DATA_SYNC();
2794
2795
2796
0
    if((ps_dec_op->u4_error_code & 0xff)
2797
0
                    != ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED)
2798
0
    {
2799
0
        ps_dec_op->u4_pic_wd = (UWORD32)ps_dec->u2_disp_width;
2800
0
        ps_dec_op->u4_pic_ht = (UWORD32)ps_dec->u2_disp_height;
2801
0
        ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
2802
0
    }
2803
2804
//Report if header (sps and pps) has not been decoded yet
2805
0
    if(ps_dec->i4_decode_header == 1 && ps_dec->i4_header_decoded != 3)
2806
0
    {
2807
0
        ps_dec_op->u4_error_code |= (1 << IVD_INSUFFICIENTDATA);
2808
0
        api_ret_value = IV_FAIL;
2809
0
    }
2810
2811
0
    if((ps_dec->u4_pic_buf_got == 1)
2812
0
                    && (ERROR_DANGLING_FIELD_IN_PIC != i4_err_status))
2813
0
    {
2814
        /*
2815
         * For field pictures, set the bottom and top picture decoded u4_flag correctly.
2816
         */
2817
2818
0
        if(ps_dec->ps_cur_slice->u1_field_pic_flag)
2819
0
        {
2820
0
            if(1 == ps_dec->ps_cur_slice->u1_bottom_field_flag)
2821
0
            {
2822
0
                ps_dec->u1_top_bottom_decoded |= BOT_FIELD_ONLY;
2823
0
            }
2824
0
            else
2825
0
            {
2826
0
                ps_dec->u1_top_bottom_decoded |= TOP_FIELD_ONLY;
2827
0
            }
2828
0
        }
2829
0
        else
2830
0
        {
2831
0
                ps_dec->u1_top_bottom_decoded = TOP_FIELD_ONLY | BOT_FIELD_ONLY;
2832
0
        }
2833
2834
        /* if new frame in not found (if we are still getting slices from previous frame)
2835
         * ih264d_deblock_display is not called. Such frames will not be added to reference /display
2836
         */
2837
0
        if ((ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC) == 0)
2838
0
        {
2839
            /* Calling Function to deblock Picture and Display */
2840
0
            ret = ih264d_deblock_display(ps_dec);
2841
0
        }
2842
2843
2844
        /*set to complete ,as we dont support partial frame decode*/
2845
0
        if(ps_dec->i4_header_decoded == 3)
2846
0
        {
2847
0
            ps_dec->u4_total_mbs_coded = ps_dec->ps_cur_sps->u4_max_mb_addr + 1;
2848
0
        }
2849
2850
        /*Update the i4_frametype at the end of picture*/
2851
0
        if(ps_dec->ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL)
2852
0
        {
2853
0
            ps_dec->i4_frametype = IV_IDR_FRAME;
2854
0
        }
2855
0
        else if(ps_dec->i4_pic_type == B_SLICE)
2856
0
        {
2857
0
            ps_dec->i4_frametype = IV_B_FRAME;
2858
0
        }
2859
0
        else if(ps_dec->i4_pic_type == P_SLICE)
2860
0
        {
2861
0
            ps_dec->i4_frametype = IV_P_FRAME;
2862
0
        }
2863
0
        else if(ps_dec->i4_pic_type == I_SLICE)
2864
0
        {
2865
0
            ps_dec->i4_frametype = IV_I_FRAME;
2866
0
        }
2867
0
        else
2868
0
        {
2869
0
            H264_DEC_DEBUG_PRINT("Shouldn't come here\n");
2870
0
        }
2871
2872
        //Update the content type
2873
0
        ps_dec->i4_content_type = ps_dec->ps_cur_slice->u1_field_pic_flag;
2874
2875
0
        ps_dec->u4_total_frames_decoded = ps_dec->u4_total_frames_decoded + 2;
2876
0
        ps_dec->u4_total_frames_decoded = ps_dec->u4_total_frames_decoded
2877
0
                        - ps_dec->ps_cur_slice->u1_field_pic_flag;
2878
2879
0
    }
2880
2881
    /* close deblock thread if it is not closed yet*/
2882
0
    if(!ps_dec->i4_threads_active)
2883
0
    {
2884
0
        if(ps_dec->u4_num_cores == 3)
2885
0
        {
2886
0
            ih264d_signal_bs_deblk_thread(ps_dec);
2887
0
        }
2888
0
    }
2889
2890
2891
0
    {
2892
        /* In case the decoder is configured to run in low delay mode,
2893
         * then get display buffer and then format convert.
2894
         * Note in this mode, format conversion does not run paralelly in a thread and adds to the codec cycles
2895
         */
2896
2897
0
        if((IVD_DECODE_FRAME_OUT == ps_dec->e_frm_out_mode)
2898
0
                        && ps_dec->u1_init_dec_flag)
2899
0
        {
2900
2901
0
            ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer,
2902
0
                                          &(ps_dec->s_disp_op));
2903
0
            if(0 == ps_dec->s_disp_op.u4_error_code)
2904
0
            {
2905
0
                ps_dec->u4_fmt_conv_cur_row = 0;
2906
0
                ps_dec->u4_output_present = 1;
2907
0
            }
2908
0
        }
2909
2910
0
        ih264d_fill_output_struct_from_context(ps_dec, ps_dec_op);
2911
2912
        /* If Format conversion is not complete,
2913
         complete it here */
2914
0
        if(ps_dec->u4_output_present &&
2915
0
          (ps_dec->u4_fmt_conv_cur_row < ps_dec->s_disp_frame_info.u4_y_ht))
2916
0
        {
2917
0
            ps_dec->u4_fmt_conv_num_rows = ps_dec->s_disp_frame_info.u4_y_ht
2918
0
                            - ps_dec->u4_fmt_conv_cur_row;
2919
0
            ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op),
2920
0
                                  ps_dec->u4_fmt_conv_cur_row,
2921
0
                                  ps_dec->u4_fmt_conv_num_rows);
2922
0
            ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
2923
0
        }
2924
2925
0
        ih264d_release_display_field(ps_dec, &(ps_dec->s_disp_op));
2926
0
    }
2927
2928
0
    if(ps_dec->i4_decode_header == 1 && (ps_dec->i4_header_decoded & 1) == 1)
2929
0
    {
2930
0
        ps_dec_op->u4_progressive_frame_flag = 1;
2931
0
        if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
2932
0
        {
2933
0
            if((0 == ps_dec->ps_sps->u1_frame_mbs_only_flag)
2934
0
                            && (0 == ps_dec->ps_sps->u1_mb_aff_flag))
2935
0
                ps_dec_op->u4_progressive_frame_flag = 0;
2936
2937
0
        }
2938
0
    }
2939
2940
0
    if((TOP_FIELD_ONLY | BOT_FIELD_ONLY) == ps_dec->u1_top_bottom_decoded)
2941
0
    {
2942
0
        ps_dec->u1_top_bottom_decoded = 0;
2943
0
    }
2944
    /*--------------------------------------------------------------------*/
2945
    /* Do End of Pic processing.                                          */
2946
    /* Should be called only if frame was decoded in previous process call*/
2947
    /*--------------------------------------------------------------------*/
2948
0
    if(ps_dec->u4_pic_buf_got == 1)
2949
0
    {
2950
0
        if(1 == ps_dec->u1_last_pic_not_decoded)
2951
0
        {
2952
0
            ret = ih264d_end_of_pic_dispbuf_mgr(ps_dec);
2953
2954
0
            if(ret != OK)
2955
0
                return ret;
2956
2957
0
            ret = ih264d_end_of_pic(ps_dec);
2958
0
            if(ret != OK)
2959
0
                return ret;
2960
0
        }
2961
0
        else
2962
0
        {
2963
0
            ret = ih264d_end_of_pic(ps_dec);
2964
0
            if(ret != OK)
2965
0
                return ret;
2966
0
        }
2967
2968
0
    }
2969
2970
0
    if(ps_dec->u1_enable_mb_info && ps_dec->u4_output_present)
2971
0
    {
2972
0
        UWORD32 disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
2973
0
        if(ps_h264d_dec_ip->pu1_8x8_blk_qp_map)
2974
0
        {
2975
0
            ps_h264d_dec_op->pu1_8x8_blk_qp_map = ps_h264d_dec_ip->pu1_8x8_blk_qp_map;
2976
0
            ps_h264d_dec_op->u4_8x8_blk_qp_map_size = ps_dec->u4_total_mbs << 2;
2977
0
            memcpy(ps_h264d_dec_op->pu1_8x8_blk_qp_map,
2978
0
                ps_dec->as_buf_id_info_map[disp_buf_id].pu1_qp_map,
2979
0
                ps_dec->u4_total_mbs << 2);
2980
0
        }
2981
0
        if(ps_h264d_dec_ip->pu1_8x8_blk_type_map)
2982
0
        {
2983
0
            ps_h264d_dec_op->pu1_8x8_blk_type_map = ps_h264d_dec_ip->pu1_8x8_blk_type_map;
2984
0
            ps_h264d_dec_op->u4_8x8_blk_type_map_size = ps_dec->u4_total_mbs << 2;
2985
0
            memcpy(ps_h264d_dec_op->pu1_8x8_blk_type_map,
2986
0
                ps_dec->as_buf_id_info_map[disp_buf_id].pu1_mb_type_map,
2987
0
                ps_dec->u4_total_mbs << 2);
2988
0
        }
2989
0
    }
2990
2991
    /* Report IVD_DEC_FRM_SKIPPED only when disable_ref_retention skipped
2992
     * slice(s) without producing a picture or encountering another error,
2993
     * so preceding skipped slices do not fail a decoded I-frame or mask
2994
     * header/slice errors (e.g., IVD_RES_CHANGED). Mapped without
2995
     * IVD_FATALERROR in ih264d_map_error(). */
2996
0
    if((0 == ps_dec->u4_pic_buf_got) && (0 == ps_dec->i4_error_code) &&
2997
0
       (0 == ps_dec_op->u4_error_code) && (IV_SUCCESS == api_ret_value) &&
2998
0
       (OK == ret) && frm_skipped)
2999
0
    {
3000
0
        ps_dec->i4_error_code = IVD_DEC_FRM_SKIPPED;
3001
0
        ps_dec_op->u4_error_code = ih264d_map_error(IVD_DEC_FRM_SKIPPED) | IVD_DEC_FRM_SKIPPED;
3002
0
        api_ret_value = IV_FAIL;
3003
0
    }
3004
3005
    /*Data memory barrier instruction,so that yuv write by the library is complete*/
3006
0
    DATA_SYNC();
3007
3008
0
    H264_DEC_DEBUG_PRINT("The num bytes consumed: %d\n",
3009
0
                         ps_dec_op->u4_num_bytes_consumed);
3010
0
    return api_ret_value;
3011
0
}
3012
3013
WORD32 ih264d_get_version(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3014
0
{
3015
0
    char version_string[MAXVERSION_STRLEN + 1];
3016
0
    UWORD32 version_string_len;
3017
3018
0
    ivd_ctl_getversioninfo_ip_t *ps_ip;
3019
0
    ivd_ctl_getversioninfo_op_t *ps_op;
3020
3021
0
    ps_ip = (ivd_ctl_getversioninfo_ip_t *)pv_api_ip;
3022
0
    ps_op = (ivd_ctl_getversioninfo_op_t *)pv_api_op;
3023
0
    UNUSED(dec_hdl);
3024
0
    ps_op->u4_error_code = IV_SUCCESS;
3025
3026
0
    VERSION(version_string, CODEC_NAME, CODEC_RELEASE_TYPE, CODEC_RELEASE_VER,
3027
0
            CODEC_VENDOR);
3028
3029
0
    if((WORD32)ps_ip->u4_version_buffer_size <= 0)
3030
0
    {
3031
0
        ps_op->u4_error_code = IH264D_VERS_BUF_INSUFFICIENT;
3032
0
        return (IV_FAIL);
3033
0
    }
3034
3035
0
    version_string_len = strnlen(version_string, MAXVERSION_STRLEN) + 1;
3036
3037
0
    if(ps_ip->u4_version_buffer_size >= version_string_len) //(WORD32)sizeof(sizeof(version_string)))
3038
0
    {
3039
0
        memcpy(ps_ip->pv_version_buffer, version_string, version_string_len);
3040
0
        ps_op->u4_error_code = IV_SUCCESS;
3041
0
    }
3042
0
    else
3043
0
    {
3044
0
        ps_op->u4_error_code = IH264D_VERS_BUF_INSUFFICIENT;
3045
0
        return IV_FAIL;
3046
0
    }
3047
0
    return (IV_SUCCESS);
3048
0
}
3049
3050
/*****************************************************************************/
3051
/*                                                                           */
3052
/*  Function Name :   ih264d_get_display_frame                               */
3053
/*                                                                           */
3054
/*  Description   :                                                          */
3055
/*  Inputs        :iv_obj_t decoder handle                                   */
3056
/*                :pv_api_ip pointer to input structure                      */
3057
/*                :pv_api_op pointer to output structure                     */
3058
/*  Outputs       :                                                          */
3059
/*  Returns       : void                                                     */
3060
/*                                                                           */
3061
/*  Issues        : none                                                     */
3062
/*                                                                           */
3063
/*  Revision History:                                                        */
3064
/*                                                                           */
3065
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3066
/*         22 10 2008    100356         Draft                                */
3067
/*                                                                           */
3068
/*****************************************************************************/
3069
WORD32 ih264d_get_display_frame(iv_obj_t *dec_hdl,
3070
                                void *pv_api_ip,
3071
                                void *pv_api_op)
3072
0
{
3073
3074
0
    UNUSED(dec_hdl);
3075
0
    UNUSED(pv_api_ip);
3076
0
    UNUSED(pv_api_op);
3077
    // This function is no longer needed, output is returned in the process()
3078
0
    return IV_FAIL;
3079
0
}
3080
3081
/*****************************************************************************/
3082
/*                                                                           */
3083
/*  Function Name :  ih264d_set_display_frame                                */
3084
/*                                                                           */
3085
/*  Description   :                                                          */
3086
/*                                                                           */
3087
/*  Inputs        :iv_obj_t decoder handle                                   */
3088
/*                :pv_api_ip pointer to input structure                      */
3089
/*                :pv_api_op pointer to output structure                     */
3090
/*  Outputs       :                                                          */
3091
/*  Returns       : void                                                     */
3092
/*                                                                           */
3093
/*  Issues        : none                                                     */
3094
/*                                                                           */
3095
/*  Revision History:                                                        */
3096
/*                                                                           */
3097
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3098
/*         22 10 2008    100356         Draft                                */
3099
/*                                                                           */
3100
/*****************************************************************************/
3101
WORD32 ih264d_set_display_frame(iv_obj_t *dec_hdl,
3102
                                void *pv_api_ip,
3103
                                void *pv_api_op)
3104
0
{
3105
3106
0
    UWORD32 u4_disp_buf_size[3], u4_num_disp_bufs;
3107
0
    ivd_set_display_frame_ip_t *dec_disp_ip;
3108
0
    ivd_set_display_frame_op_t *dec_disp_op;
3109
3110
0
    UWORD32 i;
3111
0
    dec_struct_t * ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3112
3113
0
    dec_disp_ip = (ivd_set_display_frame_ip_t *)pv_api_ip;
3114
0
    dec_disp_op = (ivd_set_display_frame_op_t *)pv_api_op;
3115
0
    dec_disp_op->u4_error_code = 0;
3116
3117
3118
0
    ps_dec->u4_num_disp_bufs = 0;
3119
0
    if(ps_dec->u4_share_disp_buf)
3120
0
    {
3121
0
        UWORD32 u4_num_bufs = dec_disp_ip->num_disp_bufs;
3122
3123
0
        u4_num_bufs = MIN(u4_num_bufs, MAX_DISP_BUFS_NEW);
3124
3125
0
        ps_dec->u4_num_disp_bufs = u4_num_bufs;
3126
3127
        /* Get the number and sizes of the first buffer. Compare this with the
3128
         * rest to make sure all the buffers are of the same size.
3129
         */
3130
0
        u4_num_disp_bufs = dec_disp_ip->s_disp_buffer[0].u4_num_bufs;
3131
3132
0
        u4_disp_buf_size[0] =
3133
0
          dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[0];
3134
0
        u4_disp_buf_size[1] =
3135
0
          dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[1];
3136
0
        u4_disp_buf_size[2] =
3137
0
          dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[2];
3138
3139
0
        for(i = 0; i < u4_num_bufs; i++)
3140
0
        {
3141
0
            if(dec_disp_ip->s_disp_buffer[i].u4_num_bufs != u4_num_disp_bufs)
3142
0
            {
3143
0
                return IV_FAIL;
3144
0
            }
3145
3146
0
            if((dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[0]
3147
0
                != u4_disp_buf_size[0])
3148
0
                || (dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[1]
3149
0
                    != u4_disp_buf_size[1])
3150
0
                || (dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[2]
3151
0
                    != u4_disp_buf_size[2]))
3152
0
            {
3153
0
                return IV_FAIL;
3154
0
            }
3155
3156
0
            ps_dec->disp_bufs[i].u4_num_bufs =
3157
0
                            dec_disp_ip->s_disp_buffer[i].u4_num_bufs;
3158
3159
0
            ps_dec->disp_bufs[i].buf[0] =
3160
0
                            dec_disp_ip->s_disp_buffer[i].pu1_bufs[0];
3161
0
            ps_dec->disp_bufs[i].buf[1] =
3162
0
                            dec_disp_ip->s_disp_buffer[i].pu1_bufs[1];
3163
0
            ps_dec->disp_bufs[i].buf[2] =
3164
0
                            dec_disp_ip->s_disp_buffer[i].pu1_bufs[2];
3165
3166
0
            ps_dec->disp_bufs[i].u4_bufsize[0] =
3167
0
                            dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[0];
3168
0
            ps_dec->disp_bufs[i].u4_bufsize[1] =
3169
0
                            dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[1];
3170
0
            ps_dec->disp_bufs[i].u4_bufsize[2] =
3171
0
                            dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[2];
3172
3173
0
        }
3174
0
    }
3175
0
    return IV_SUCCESS;
3176
3177
0
}
3178
3179
/*****************************************************************************/
3180
/*                                                                           */
3181
/*  Function Name : ih264d_set_flush_mode                                    */
3182
/*                                                                           */
3183
/*  Description   :                                                          */
3184
/*                                                                           */
3185
/*  Inputs        :iv_obj_t decoder handle                                   */
3186
/*                :pv_api_ip pointer to input structure                      */
3187
/*                :pv_api_op pointer to output structure                     */
3188
/*  Globals       : <Does it use any global variables?>                      */
3189
/*  Outputs       :                                                          */
3190
/*  Returns       : void                                                     */
3191
/*                                                                           */
3192
/*  Issues        : none                                                     */
3193
/*                                                                           */
3194
/*  Revision History:                                                        */
3195
/*                                                                           */
3196
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3197
/*         22 10 2008    100356         Draft                                */
3198
/*                                                                           */
3199
/*****************************************************************************/
3200
WORD32 ih264d_set_flush_mode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3201
0
{
3202
0
    dec_struct_t * ps_dec;
3203
0
    ivd_ctl_flush_op_t *ps_ctl_op = (ivd_ctl_flush_op_t*)pv_api_op;
3204
0
    ps_ctl_op->u4_error_code = 0;
3205
3206
0
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3207
0
    ih264d_join_threads(ps_dec);
3208
0
    UNUSED(pv_api_ip);
3209
    /* ! */
3210
    /* Signal flush frame control call */
3211
0
    ps_dec->u1_flushfrm = 1;
3212
3213
0
    if(ps_dec->u1_init_dec_flag == 1)
3214
0
    {
3215
0
        ih264d_release_pics_in_dpb((void *)ps_dec, ps_dec->u1_pic_bufs);
3216
0
        ih264d_release_display_bufs(ps_dec);
3217
0
    }
3218
3219
0
    ps_ctl_op->u4_error_code = 0;
3220
3221
    /* Ignore dangling fields during flush */
3222
0
    ps_dec->u1_top_bottom_decoded = 0;
3223
3224
0
    return IV_SUCCESS;
3225
0
}
3226
3227
/*****************************************************************************/
3228
/*                                                                           */
3229
/*  Function Name : ih264d_get_status                                        */
3230
/*                                                                           */
3231
/*  Description   :                                                          */
3232
/*                                                                           */
3233
/*  Inputs        :iv_obj_t decoder handle                                   */
3234
/*                :pv_api_ip pointer to input structure                      */
3235
/*                :pv_api_op pointer to output structure                     */
3236
/*  Globals       : <Does it use any global variables?>                      */
3237
/*  Outputs       :                                                          */
3238
/*  Returns       : void                                                     */
3239
/*                                                                           */
3240
/*  Issues        : none                                                     */
3241
/*                                                                           */
3242
/*  Revision History:                                                        */
3243
/*                                                                           */
3244
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3245
/*         22 10 2008    100356         Draft                                */
3246
/*                                                                           */
3247
/*****************************************************************************/
3248
3249
WORD32 ih264d_get_status(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3250
0
{
3251
3252
0
    UWORD32 i;
3253
0
    dec_struct_t * ps_dec;
3254
0
    UWORD32 pic_wd, pic_ht;
3255
0
    ivd_ctl_getstatus_op_t *ps_ctl_op = (ivd_ctl_getstatus_op_t*)pv_api_op;
3256
0
    UNUSED(pv_api_ip);
3257
0
    ps_ctl_op->u4_error_code = 0;
3258
3259
0
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3260
3261
3262
0
    if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
3263
0
    {
3264
0
        ps_ctl_op->u4_pic_ht = ps_dec->u2_disp_height;
3265
0
        ps_ctl_op->u4_pic_wd = ps_dec->u2_disp_width;
3266
3267
0
        if(0 == ps_dec->u4_share_disp_buf)
3268
0
        {
3269
0
            pic_wd = ps_dec->u2_disp_width;
3270
0
            pic_ht = ps_dec->u2_disp_height;
3271
3272
0
        }
3273
0
        else
3274
0
        {
3275
0
            pic_wd = ps_dec->u2_frm_wd_y;
3276
0
            pic_ht = ps_dec->u2_frm_ht_y;
3277
0
        }
3278
0
    }
3279
0
    else
3280
0
    {
3281
0
        pic_wd = 0;
3282
0
        pic_ht = 0;
3283
3284
0
        ps_ctl_op->u4_pic_ht = pic_wd;
3285
0
        ps_ctl_op->u4_pic_wd = pic_ht;
3286
3287
0
        if(1 == ps_dec->u4_share_disp_buf)
3288
0
        {
3289
0
            pic_wd += (PAD_LEN_Y_H << 1);
3290
0
            pic_ht += (PAD_LEN_Y_V << 2);
3291
3292
0
        }
3293
3294
0
    }
3295
3296
0
    if(ps_dec->u4_app_disp_width > pic_wd)
3297
0
        pic_wd = ps_dec->u4_app_disp_width;
3298
0
    if(0 == ps_dec->u4_share_disp_buf)
3299
0
        ps_ctl_op->u4_num_disp_bufs = 1;
3300
0
    else
3301
0
    {
3302
0
        if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
3303
0
        {
3304
0
            if((ps_dec->ps_cur_sps->u1_vui_parameters_present_flag == 1) &&
3305
0
               (1 == ps_dec->ps_cur_sps->s_vui.u1_bitstream_restriction_flag))
3306
0
            {
3307
0
                ps_ctl_op->u4_num_disp_bufs =
3308
0
                                ps_dec->ps_cur_sps->s_vui.u4_num_reorder_frames + 1;
3309
0
            }
3310
0
            else
3311
0
            {
3312
                /*if VUI is not present assume maximum possible refrence frames for the level,
3313
                 * as max reorder frames*/
3314
0
                ps_ctl_op->u4_num_disp_bufs = ih264d_get_dpb_size(ps_dec->ps_cur_sps);
3315
0
            }
3316
3317
0
            ps_ctl_op->u4_num_disp_bufs +=
3318
0
                            ps_dec->ps_cur_sps->u1_num_ref_frames + 1;
3319
0
        }
3320
0
        else
3321
0
        {
3322
0
            ps_ctl_op->u4_num_disp_bufs = 32;
3323
0
        }
3324
0
        ps_ctl_op->u4_num_disp_bufs = MAX(
3325
0
                        ps_ctl_op->u4_num_disp_bufs, 6);
3326
0
        ps_ctl_op->u4_num_disp_bufs = MIN(
3327
0
                        ps_ctl_op->u4_num_disp_bufs, 32);
3328
0
    }
3329
3330
0
    ps_ctl_op->u4_error_code = ps_dec->i4_error_code;
3331
3332
0
    ps_ctl_op->u4_frame_rate = 0; //make it proper
3333
0
    ps_ctl_op->u4_bit_rate = 0; //make it proper
3334
0
    ps_ctl_op->e_content_type = ps_dec->i4_content_type;
3335
0
    ps_ctl_op->e_output_chroma_format = ps_dec->u1_chroma_format;
3336
0
    ps_ctl_op->u4_min_num_in_bufs = MIN_IN_BUFS;
3337
3338
0
    if(ps_dec->u1_chroma_format == IV_YUV_420P)
3339
0
    {
3340
0
        ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_420;
3341
0
    }
3342
0
    else if(ps_dec->u1_chroma_format == IV_YUV_422ILE)
3343
0
    {
3344
0
        ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_422ILE;
3345
0
    }
3346
0
    else if(ps_dec->u1_chroma_format == IV_RGB_565)
3347
0
    {
3348
0
        ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_RGB565;
3349
0
    }
3350
0
    else if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
3351
0
                    || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
3352
0
    {
3353
0
        ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_420SP;
3354
0
    }
3355
3356
0
    else
3357
0
    {
3358
        //Invalid chroma format; Error code may be updated, verify in testing if needed
3359
0
        ps_ctl_op->u4_error_code = ERROR_FEATURE_UNAVAIL;
3360
0
        return IV_FAIL;
3361
0
    }
3362
3363
0
    for(i = 0; i < ps_ctl_op->u4_min_num_in_bufs; i++)
3364
0
    {
3365
0
        ps_ctl_op->u4_min_in_buf_size[i] = MAX(256000, pic_wd * pic_ht * 3 / 2);
3366
0
    }
3367
3368
    /*!*/
3369
0
    if(ps_dec->u1_chroma_format == IV_YUV_420P)
3370
0
    {
3371
0
        ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht);
3372
0
        ps_ctl_op->u4_min_out_buf_size[1] = (pic_wd * pic_ht)
3373
0
                        >> 2;
3374
0
        ps_ctl_op->u4_min_out_buf_size[2] = (pic_wd * pic_ht)
3375
0
                        >> 2;
3376
0
    }
3377
0
    else if(ps_dec->u1_chroma_format == IV_YUV_422ILE)
3378
0
    {
3379
0
        ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht)
3380
0
                        * 2;
3381
0
        ps_ctl_op->u4_min_out_buf_size[1] =
3382
0
                        ps_ctl_op->u4_min_out_buf_size[2] = 0;
3383
0
    }
3384
0
    else if(ps_dec->u1_chroma_format == IV_RGB_565)
3385
0
    {
3386
0
        ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht)
3387
0
                        * 2;
3388
0
        ps_ctl_op->u4_min_out_buf_size[1] =
3389
0
                        ps_ctl_op->u4_min_out_buf_size[2] = 0;
3390
0
    }
3391
0
    else if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
3392
0
                    || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
3393
0
    {
3394
0
        ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht);
3395
0
        ps_ctl_op->u4_min_out_buf_size[1] = (pic_wd * pic_ht)
3396
0
                        >> 1;
3397
0
        ps_ctl_op->u4_min_out_buf_size[2] = 0;
3398
0
    }
3399
3400
0
    ps_dec->u4_num_disp_bufs_requested = ps_ctl_op->u4_num_disp_bufs;
3401
0
    return IV_SUCCESS;
3402
0
}
3403
3404
/*****************************************************************************/
3405
/*                                                                           */
3406
/*  Function Name :    ih264d_get_buf_info                                   */
3407
/*                                                                           */
3408
/*  Description   :                                                          */
3409
/*                                                                           */
3410
/*  Inputs        :iv_obj_t decoder handle                                   */
3411
/*                :pv_api_ip pointer to input structure                      */
3412
/*                :pv_api_op pointer to output structure                     */
3413
/*  Globals       : <Does it use any global variables?>                      */
3414
/*  Outputs       :                                                          */
3415
/*  Returns       : void                                                     */
3416
/*                                                                           */
3417
/*  Issues        : none                                                     */
3418
/*                                                                           */
3419
/*  Revision History:                                                        */
3420
/*                                                                           */
3421
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3422
/*         22 10 2008    100356         Draft                                */
3423
/*                                                                           */
3424
/*****************************************************************************/
3425
WORD32 ih264d_get_buf_info(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3426
0
{
3427
3428
0
    dec_struct_t * ps_dec;
3429
0
    UWORD8 i = 0; // Default for 420P format
3430
0
    UWORD16 pic_wd, pic_ht;
3431
0
    ivd_ctl_getbufinfo_op_t *ps_ctl_op =
3432
0
                    (ivd_ctl_getbufinfo_op_t*)pv_api_op;
3433
0
    UWORD32 au4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
3434
0
    UNUSED(pv_api_ip);
3435
3436
0
    ps_ctl_op->u4_error_code = 0;
3437
3438
0
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3439
3440
0
    ps_ctl_op->u4_min_num_in_bufs = MIN_IN_BUFS;
3441
3442
3443
0
    ps_ctl_op->u4_num_disp_bufs = 1;
3444
3445
3446
0
    pic_wd = 0;
3447
0
    pic_ht = 0;
3448
3449
0
    if(ps_dec->i4_header_decoded == 3)
3450
0
    {
3451
3452
0
        if(0 == ps_dec->u4_share_disp_buf)
3453
0
        {
3454
0
            pic_wd = ps_dec->u2_disp_width;
3455
0
            pic_ht = ps_dec->u2_disp_height;
3456
3457
0
        }
3458
0
        else
3459
0
        {
3460
0
            pic_wd = ps_dec->u2_frm_wd_y;
3461
0
            pic_ht = ps_dec->u2_frm_ht_y;
3462
0
        }
3463
3464
0
    }
3465
3466
0
    for(i = 0; i < ps_ctl_op->u4_min_num_in_bufs; i++)
3467
0
    {
3468
0
        ps_ctl_op->u4_min_in_buf_size[i] = MAX(256000, pic_wd * pic_ht * 3 / 2);
3469
0
    }
3470
0
    if((WORD32)ps_dec->u4_app_disp_width > pic_wd)
3471
0
        pic_wd = ps_dec->u4_app_disp_width;
3472
3473
0
    if(0 == ps_dec->u4_share_disp_buf)
3474
0
        ps_ctl_op->u4_num_disp_bufs = 1;
3475
0
    else
3476
0
    {
3477
0
        if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
3478
0
        {
3479
0
            if((ps_dec->ps_cur_sps->u1_vui_parameters_present_flag == 1) &&
3480
0
               (1 == ps_dec->ps_cur_sps->s_vui.u1_bitstream_restriction_flag))
3481
0
            {
3482
0
                ps_ctl_op->u4_num_disp_bufs =
3483
0
                                ps_dec->ps_cur_sps->s_vui.u4_num_reorder_frames + 1;
3484
0
            }
3485
0
            else
3486
0
            {
3487
                /*if VUI is not present assume maximum possible refrence frames for the level,
3488
                 * as max reorder frames*/
3489
0
                ps_ctl_op->u4_num_disp_bufs = ih264d_get_dpb_size(ps_dec->ps_cur_sps);
3490
0
            }
3491
3492
0
            ps_ctl_op->u4_num_disp_bufs +=
3493
0
                            ps_dec->ps_cur_sps->u1_num_ref_frames + 1;
3494
3495
0
        }
3496
0
        else
3497
0
        {
3498
0
            ps_ctl_op->u4_num_disp_bufs = 32;
3499
3500
0
        }
3501
3502
0
        ps_ctl_op->u4_num_disp_bufs = MAX(
3503
0
                        ps_ctl_op->u4_num_disp_bufs, 6);
3504
0
        ps_ctl_op->u4_num_disp_bufs = MIN(
3505
0
                        ps_ctl_op->u4_num_disp_bufs, 32);
3506
0
    }
3507
3508
0
    ps_ctl_op->u4_min_num_out_bufs = ih264d_get_outbuf_size(
3509
0
                    pic_wd, pic_ht, ps_dec->u1_chroma_format,
3510
0
                    &au4_min_out_buf_size[0]);
3511
3512
0
    for(i = 0; i < ps_ctl_op->u4_min_num_out_bufs; i++)
3513
0
    {
3514
0
        ps_ctl_op->u4_min_out_buf_size[i] = au4_min_out_buf_size[i];
3515
0
    }
3516
3517
0
    ps_dec->u4_num_disp_bufs_requested = ps_ctl_op->u4_num_disp_bufs;
3518
3519
0
    return IV_SUCCESS;
3520
0
}
3521
3522
/*****************************************************************************/
3523
/*                                                                           */
3524
/*  Function Name : ih264d_set_params                                        */
3525
/*                                                                           */
3526
/*  Description   :                                                          */
3527
/*                                                                           */
3528
/*  Inputs        :iv_obj_t decoder handle                                   */
3529
/*                :pv_api_ip pointer to input structure                      */
3530
/*                :pv_api_op pointer to output structure                     */
3531
/*  Outputs       :                                                          */
3532
/*  Returns       : void                                                     */
3533
/*                                                                           */
3534
/*  Issues        : none                                                     */
3535
/*                                                                           */
3536
/*  Revision History:                                                        */
3537
/*                                                                           */
3538
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3539
/*         22 10 2008    100356         Draft                                */
3540
/*                                                                           */
3541
/*****************************************************************************/
3542
WORD32 ih264d_set_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3543
0
{
3544
3545
0
    dec_struct_t * ps_dec;
3546
0
    WORD32 ret = IV_SUCCESS;
3547
3548
0
    ih264d_ctl_set_config_ip_t *ps_h264d_ctl_ip =
3549
0
                    (ih264d_ctl_set_config_ip_t *)pv_api_ip;
3550
0
    ih264d_ctl_set_config_op_t *ps_h264d_ctl_op =
3551
0
                    (ih264d_ctl_set_config_op_t *)pv_api_op;
3552
0
    ivd_ctl_set_config_ip_t *ps_ctl_ip =
3553
0
                    &ps_h264d_ctl_ip->s_ivd_ctl_set_config_ip_t;
3554
0
    ivd_ctl_set_config_op_t *ps_ctl_op =
3555
0
                    &ps_h264d_ctl_op->s_ivd_ctl_set_config_op_t;
3556
3557
0
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3558
3559
0
    ps_dec->u4_skip_frm_mask = 0;
3560
3561
0
    ps_ctl_op->u4_error_code = 0;
3562
3563
0
    if(ps_ctl_ip->e_frm_skip_mode != IVD_SKIP_NONE)
3564
0
    {
3565
0
        ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
3566
0
        ret = IV_FAIL;
3567
0
    }
3568
3569
0
    if(ps_ctl_ip->u4_disp_wd >= ps_dec->u2_disp_width)
3570
0
    {
3571
0
        ps_dec->u4_app_disp_width = ps_ctl_ip->u4_disp_wd;
3572
0
    }
3573
0
    else if(0 == ps_dec->i4_header_decoded)
3574
0
    {
3575
0
        ps_dec->u4_app_disp_width = ps_ctl_ip->u4_disp_wd;
3576
0
    }
3577
0
    else if(ps_ctl_ip->u4_disp_wd == 0)
3578
0
    {
3579
0
        ps_dec->u4_app_disp_width = 0;
3580
0
    }
3581
0
    else
3582
0
    {
3583
        /*
3584
         * Set the display width to zero. This will ensure that the wrong value we had stored (0xFFFFFFFF)
3585
         * does not propogate.
3586
         */
3587
0
        ps_dec->u4_app_disp_width = 0;
3588
0
        ps_ctl_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
3589
0
        ps_ctl_op->u4_error_code |= ERROR_DISP_WIDTH_INVALID;
3590
0
        ret = IV_FAIL;
3591
0
    }
3592
3593
0
    if(ps_ctl_ip->e_vid_dec_mode == IVD_DECODE_FRAME)
3594
0
        ps_dec->i4_decode_header = 0;
3595
0
    else if(ps_ctl_ip->e_vid_dec_mode == IVD_DECODE_HEADER)
3596
0
        ps_dec->i4_decode_header = 1;
3597
0
    else
3598
0
    {
3599
0
        ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
3600
0
        ps_dec->i4_decode_header = 1;
3601
0
        ret = IV_FAIL;
3602
0
    }
3603
0
    ps_dec->e_frm_out_mode = IVD_DISPLAY_FRAME_OUT;
3604
3605
0
    if((ps_ctl_ip->e_frm_out_mode != IVD_DECODE_FRAME_OUT) &&
3606
0
       (ps_ctl_ip->e_frm_out_mode != IVD_DISPLAY_FRAME_OUT))
3607
0
    {
3608
0
        ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
3609
0
        ret = IV_FAIL;
3610
0
    }
3611
0
    ps_dec->e_frm_out_mode = ps_ctl_ip->e_frm_out_mode;
3612
0
    if(ps_dec->u4_disable_ref_retention)
3613
0
    {
3614
0
        ps_dec->e_frm_out_mode = IVD_DECODE_FRAME_OUT;
3615
0
    }
3616
0
    return ret;
3617
3618
0
}
3619
3620
/*****************************************************************************/
3621
/*                                                                           */
3622
/*  Function Name : ih264d_set_default_params                                */
3623
/*                                                                           */
3624
/*  Description   :                                                          */
3625
/*                                                                           */
3626
/*  Inputs        :iv_obj_t decoder handle                                   */
3627
/*                :pv_api_ip pointer to input structure                      */
3628
/*                :pv_api_op pointer to output structure                     */
3629
/*  Outputs       :                                                          */
3630
/*  Returns       : void                                                     */
3631
/*                                                                           */
3632
/*  Issues        : none                                                     */
3633
/*                                                                           */
3634
/*  Revision History:                                                        */
3635
/*                                                                           */
3636
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3637
/*         08 08 2011   100421          Copied from set_params               */
3638
/*                                                                           */
3639
/*****************************************************************************/
3640
WORD32 ih264d_set_default_params(iv_obj_t *dec_hdl,
3641
                                 void *pv_api_ip,
3642
                                 void *pv_api_op)
3643
0
{
3644
3645
0
    dec_struct_t * ps_dec;
3646
0
    WORD32 ret = IV_SUCCESS;
3647
3648
0
    ivd_ctl_set_config_op_t *ps_ctl_op =
3649
0
                    (ivd_ctl_set_config_op_t *)pv_api_op;
3650
0
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3651
0
    UNUSED(pv_api_ip);
3652
3653
3654
0
    {
3655
0
        ps_dec->u4_app_disp_width = 0;
3656
0
        ps_dec->u4_skip_frm_mask = 0;
3657
0
        ps_dec->i4_decode_header = 1;
3658
0
        ps_dec->e_frm_out_mode = ps_dec->u4_disable_ref_retention ? IVD_DECODE_FRAME_OUT
3659
0
                                                                  : IVD_DISPLAY_FRAME_OUT;
3660
3661
0
        ps_ctl_op->u4_error_code = 0;
3662
0
    }
3663
3664
3665
0
    return ret;
3666
0
}
3667
/*****************************************************************************/
3668
/*                                                                           */
3669
/*  Function Name :  ih264d_reset                                            */
3670
/*                                                                           */
3671
/*  Description   :                                                          */
3672
/*                                                                           */
3673
/*  Inputs        :iv_obj_t decoder handle                                   */
3674
/*                :pv_api_ip pointer to input structure                      */
3675
/*                :pv_api_op pointer to output structure                     */
3676
/*  Globals       : <Does it use any global variables?>                      */
3677
/*  Outputs       :                                                          */
3678
/*  Returns       : void                                                     */
3679
/*                                                                           */
3680
/*  Issues        : none                                                     */
3681
/*                                                                           */
3682
/*  Revision History:                                                        */
3683
/*                                                                           */
3684
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3685
/*         22 10 2008    100356         Draft                                */
3686
/*                                                                           */
3687
/*****************************************************************************/
3688
WORD32 ih264d_delete(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3689
0
{
3690
0
    dec_struct_t *ps_dec;
3691
0
    ih264d_delete_ip_t *ps_ip = (ih264d_delete_ip_t *)pv_api_ip;
3692
0
    ih264d_delete_op_t *ps_op = (ih264d_delete_op_t *)pv_api_op;
3693
3694
0
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3695
0
    UNUSED(ps_ip);
3696
0
    ps_op->s_ivd_delete_op_t.u4_error_code = 0;
3697
0
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_bits_buf_dynamic);
3698
0
    ih264d_free_dynamic_bufs(ps_dec);
3699
0
    ih264d_free_static_bufs(dec_hdl);
3700
0
    return IV_SUCCESS;
3701
0
}
3702
/*****************************************************************************/
3703
/*                                                                           */
3704
/*  Function Name :  ih264d_reset                                            */
3705
/*                                                                           */
3706
/*  Description   :                                                          */
3707
/*                                                                           */
3708
/*  Inputs        :iv_obj_t decoder handle                                   */
3709
/*                :pv_api_ip pointer to input structure                      */
3710
/*                :pv_api_op pointer to output structure                     */
3711
/*  Globals       : <Does it use any global variables?>                      */
3712
/*  Outputs       :                                                          */
3713
/*  Returns       : void                                                     */
3714
/*                                                                           */
3715
/*  Issues        : none                                                     */
3716
/*                                                                           */
3717
/*  Revision History:                                                        */
3718
/*                                                                           */
3719
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3720
/*         22 10 2008    100356         Draft                                */
3721
/*                                                                           */
3722
/*****************************************************************************/
3723
WORD32 ih264d_reset(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3724
0
{
3725
0
    dec_struct_t * ps_dec;
3726
0
    ivd_ctl_reset_op_t *ps_ctl_op = (ivd_ctl_reset_op_t *)pv_api_op;
3727
0
    UNUSED(pv_api_ip);
3728
0
    ps_ctl_op->u4_error_code = 0;
3729
3730
0
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3731
3732
0
    if(ps_dec != NULL)
3733
0
    {
3734
0
        ih264d_join_threads(ps_dec);
3735
0
        ih264d_init_decoder(ps_dec);
3736
0
    }
3737
0
    else
3738
0
    {
3739
0
        H264_DEC_DEBUG_PRINT(
3740
0
                        "\nReset called without Initializing the decoder\n");
3741
0
        ps_ctl_op->u4_error_code = ERROR_INIT_NOT_DONE;
3742
0
    }
3743
3744
0
    return IV_SUCCESS;
3745
0
}
3746
3747
/*****************************************************************************/
3748
/*                                                                           */
3749
/*  Function Name :  ih264d_ctl                                              */
3750
/*                                                                           */
3751
/*  Description   :                                                          */
3752
/*                                                                           */
3753
/*  Inputs        :iv_obj_t decoder handle                                   */
3754
/*                :pv_api_ip pointer to input structure                      */
3755
/*                :pv_api_op pointer to output structure                     */
3756
/*  Outputs       :                                                          */
3757
/*  Returns       : void                                                     */
3758
/*                                                                           */
3759
/*  Issues        : none                                                     */
3760
/*                                                                           */
3761
/*  Revision History:                                                        */
3762
/*                                                                           */
3763
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3764
/*         22 10 2008    100356         Draft                                */
3765
/*                                                                           */
3766
/*****************************************************************************/
3767
WORD32 ih264d_ctl(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3768
0
{
3769
0
    ivd_ctl_set_config_ip_t *ps_ctl_ip;
3770
0
    ivd_ctl_set_config_op_t *ps_ctl_op;
3771
0
    WORD32 ret = IV_SUCCESS;
3772
0
    UWORD32 subcommand;
3773
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
3774
3775
0
    if(ps_dec->init_done != 1)
3776
0
    {
3777
        //Return proper Error Code
3778
0
        return IV_FAIL;
3779
0
    }
3780
0
    ps_ctl_ip = (ivd_ctl_set_config_ip_t*)pv_api_ip;
3781
0
    ps_ctl_op = (ivd_ctl_set_config_op_t*)pv_api_op;
3782
0
    ps_ctl_op->u4_error_code = 0;
3783
0
    subcommand = ps_ctl_ip->e_sub_cmd;
3784
3785
0
    switch(subcommand)
3786
0
    {
3787
0
        case IVD_CMD_CTL_GETPARAMS:
3788
0
            ret = ih264d_get_status(dec_hdl, (void *)pv_api_ip,
3789
0
                                    (void *)pv_api_op);
3790
0
            break;
3791
0
        case IVD_CMD_CTL_SETPARAMS:
3792
0
            ret = ih264d_set_params(dec_hdl, (void *)pv_api_ip,
3793
0
                                    (void *)pv_api_op);
3794
0
            break;
3795
0
        case IVD_CMD_CTL_RESET:
3796
0
            ret = ih264d_reset(dec_hdl, (void *)pv_api_ip, (void *)pv_api_op);
3797
0
            break;
3798
0
        case IVD_CMD_CTL_SETDEFAULT:
3799
0
            ret = ih264d_set_default_params(dec_hdl, (void *)pv_api_ip,
3800
0
                                            (void *)pv_api_op);
3801
0
            break;
3802
0
        case IVD_CMD_CTL_FLUSH:
3803
0
            ret = ih264d_set_flush_mode(dec_hdl, (void *)pv_api_ip,
3804
0
                                        (void *)pv_api_op);
3805
0
            break;
3806
0
        case IVD_CMD_CTL_GETBUFINFO:
3807
0
            ret = ih264d_get_buf_info(dec_hdl, (void *)pv_api_ip,
3808
0
                                      (void *)pv_api_op);
3809
0
            break;
3810
0
        case IVD_CMD_CTL_GETVERSION:
3811
0
            ret = ih264d_get_version(dec_hdl, (void *)pv_api_ip,
3812
0
                                     (void *)pv_api_op);
3813
0
            break;
3814
0
        case IH264D_CMD_CTL_DEGRADE:
3815
0
            ret = ih264d_set_degrade(dec_hdl, (void *)pv_api_ip,
3816
0
                                     (void *)pv_api_op);
3817
0
            break;
3818
3819
0
        case IH264D_CMD_CTL_SET_NUM_CORES:
3820
0
            ret = ih264d_set_num_cores(dec_hdl, (void *)pv_api_ip,
3821
0
                                       (void *)pv_api_op);
3822
0
            break;
3823
0
        case IH264D_CMD_CTL_GET_BUFFER_DIMENSIONS:
3824
0
            ret = ih264d_get_frame_dimensions(dec_hdl, (void *)pv_api_ip,
3825
0
                                              (void *)pv_api_op);
3826
0
            break;
3827
0
        case IH264D_CMD_CTL_GET_VUI_PARAMS:
3828
0
            ret = ih264d_get_vui_params(dec_hdl, (void *)pv_api_ip,
3829
0
                                        (void *)pv_api_op);
3830
0
            break;
3831
0
        case IH264D_CMD_CTL_GET_SEI_MDCV_PARAMS:
3832
0
            ret = ih264d_get_sei_mdcv_params(dec_hdl, (void *)pv_api_ip,
3833
0
                                             (void *)pv_api_op);
3834
0
            break;
3835
0
        case IH264D_CMD_CTL_GET_SEI_CLL_PARAMS:
3836
0
            ret = ih264d_get_sei_cll_params(dec_hdl, (void *)pv_api_ip,
3837
0
                                            (void *)pv_api_op);
3838
0
            break;
3839
0
        case IH264D_CMD_CTL_GET_SEI_AVE_PARAMS:
3840
0
            ret = ih264d_get_sei_ave_params(dec_hdl, (void *)pv_api_ip,
3841
0
                                            (void *)pv_api_op);
3842
0
            break;
3843
0
        case IH264D_CMD_CTL_GET_SEI_CCV_PARAMS:
3844
0
            ret = ih264d_get_sei_ccv_params(dec_hdl, (void *)pv_api_ip,
3845
0
                                            (void *)pv_api_op);
3846
0
            break;
3847
0
        case IH264D_CMD_CTL_GET_SEI_SII_PARAMS:
3848
0
            ret = ih264d_get_sei_sii_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
3849
0
            break;
3850
3851
0
        case IH264D_CMD_CTL_GET_SEI_FGC_PARAMS:
3852
0
            ret = ih264d_get_sei_fgc_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
3853
0
            break;
3854
3855
0
        case IH264D_CMD_CTL_SET_PROCESSOR:
3856
0
            ret = ih264d_set_processor(dec_hdl, (void *)pv_api_ip,
3857
0
                                       (void *)pv_api_op);
3858
0
            break;
3859
0
        default:
3860
0
            H264_DEC_DEBUG_PRINT("\ndo nothing\n")
3861
0
            ;
3862
0
            break;
3863
0
    }
3864
3865
0
    return ret;
3866
0
}
3867
/*****************************************************************************/
3868
/*                                                                           */
3869
/*  Function Name :   ih264d_rel_display_frame                               */
3870
/*                                                                           */
3871
/*  Description   :                                                          */
3872
/*                                                                           */
3873
/*  Inputs        :iv_obj_t decoder handle                                   */
3874
/*                :pv_api_ip pointer to input structure                      */
3875
/*                :pv_api_op pointer to output structure                     */
3876
/*  Outputs       :                                                          */
3877
/*  Returns       : void                                                     */
3878
/*                                                                           */
3879
/*  Issues        : none                                                     */
3880
/*                                                                           */
3881
/*  Revision History:                                                        */
3882
/*                                                                           */
3883
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3884
/*         22 10 2008    100356         Draft                                */
3885
/*                                                                           */
3886
/*****************************************************************************/
3887
WORD32 ih264d_rel_display_frame(iv_obj_t *dec_hdl,
3888
                                void *pv_api_ip,
3889
                                void *pv_api_op)
3890
0
{
3891
3892
0
    ivd_rel_display_frame_ip_t *ps_rel_ip;
3893
0
    ivd_rel_display_frame_op_t *ps_rel_op;
3894
0
    UWORD32 buf_released = 0;
3895
3896
0
    UWORD32 u4_ts = 0;
3897
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
3898
3899
0
    ps_rel_ip = (ivd_rel_display_frame_ip_t *)pv_api_ip;
3900
0
    ps_rel_op = (ivd_rel_display_frame_op_t *)pv_api_op;
3901
0
    ps_rel_op->u4_error_code = 0;
3902
0
    u4_ts = ps_rel_ip->u4_disp_buf_id;
3903
3904
0
    if(0 == ps_dec->u4_share_disp_buf)
3905
0
    {
3906
0
        ps_dec->u4_disp_buf_mapping[u4_ts] = 0;
3907
0
        ps_dec->u4_disp_buf_to_be_freed[u4_ts] = 0;
3908
0
        return IV_SUCCESS;
3909
0
    }
3910
3911
0
    if(ps_dec->pv_pic_buf_mgr != NULL)
3912
0
    {
3913
0
        if(1 == ps_dec->u4_disp_buf_mapping[u4_ts])
3914
0
        {
3915
0
            ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
3916
0
                                  ps_rel_ip->u4_disp_buf_id,
3917
0
                                  BUF_MGR_IO);
3918
0
            ps_dec->u4_disp_buf_mapping[u4_ts] = 0;
3919
0
            buf_released = 1;
3920
0
        }
3921
0
    }
3922
3923
0
    if((1 == ps_dec->u4_share_disp_buf) && (0 == buf_released))
3924
0
        ps_dec->u4_disp_buf_to_be_freed[u4_ts] = 1;
3925
3926
0
    return IV_SUCCESS;
3927
0
}
3928
3929
/**
3930
 *******************************************************************************
3931
 *
3932
 * @brief
3933
 *  Sets degrade params
3934
 *
3935
 * @par Description:
3936
 *  Sets degrade params.
3937
 *  Refer to ih264d_ctl_degrade_ip_t definition for details
3938
 *
3939
 * @param[in] ps_codec_obj
3940
 *  Pointer to codec object at API level
3941
 *
3942
 * @param[in] pv_api_ip
3943
 *  Pointer to input argument structure
3944
 *
3945
 * @param[out] pv_api_op
3946
 *  Pointer to output argument structure
3947
 *
3948
 * @returns  Status
3949
 *
3950
 * @remarks
3951
 *
3952
 *
3953
 *******************************************************************************
3954
 */
3955
3956
WORD32 ih264d_set_degrade(iv_obj_t *ps_codec_obj,
3957
                          void *pv_api_ip,
3958
                          void *pv_api_op)
3959
0
{
3960
0
    ih264d_ctl_degrade_ip_t *ps_ip;
3961
0
    ih264d_ctl_degrade_op_t *ps_op;
3962
0
    dec_struct_t *ps_codec = (dec_struct_t *)ps_codec_obj->pv_codec_handle;
3963
3964
0
    ps_ip = (ih264d_ctl_degrade_ip_t *)pv_api_ip;
3965
0
    ps_op = (ih264d_ctl_degrade_op_t *)pv_api_op;
3966
3967
0
    ps_codec->i4_degrade_type = ps_ip->i4_degrade_type;
3968
0
    ps_codec->i4_nondegrade_interval = ps_ip->i4_nondegrade_interval;
3969
0
    ps_codec->i4_degrade_pics = ps_ip->i4_degrade_pics;
3970
3971
0
    ps_op->u4_error_code = 0;
3972
0
    ps_codec->i4_degrade_pic_cnt = 0;
3973
3974
0
    return IV_SUCCESS;
3975
0
}
3976
3977
WORD32 ih264d_get_frame_dimensions(iv_obj_t *dec_hdl,
3978
                                   void *pv_api_ip,
3979
                                   void *pv_api_op)
3980
0
{
3981
0
    ih264d_ctl_get_frame_dimensions_ip_t *ps_ip;
3982
0
    ih264d_ctl_get_frame_dimensions_op_t *ps_op;
3983
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
3984
0
    UWORD32 disp_wd, disp_ht, buffer_wd, buffer_ht, x_offset, y_offset;
3985
3986
0
    ps_ip = (ih264d_ctl_get_frame_dimensions_ip_t *)pv_api_ip;
3987
3988
0
    ps_op = (ih264d_ctl_get_frame_dimensions_op_t *)pv_api_op;
3989
0
    UNUSED(ps_ip);
3990
0
    if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
3991
0
    {
3992
0
        disp_wd = ps_dec->u2_disp_width;
3993
0
        disp_ht = ps_dec->u2_disp_height;
3994
3995
0
        if(0 == ps_dec->u4_share_disp_buf)
3996
0
        {
3997
0
            buffer_wd = disp_wd;
3998
0
            buffer_ht = disp_ht;
3999
0
        }
4000
0
        else
4001
0
        {
4002
0
            buffer_wd = ps_dec->u2_frm_wd_y;
4003
0
            buffer_ht = ps_dec->u2_frm_ht_y;
4004
0
        }
4005
0
    }
4006
0
    else
4007
0
    {
4008
0
        disp_wd = 0;
4009
0
        disp_ht = 0;
4010
4011
0
        if(0 == ps_dec->u4_share_disp_buf)
4012
0
        {
4013
0
            buffer_wd = disp_wd;
4014
0
            buffer_ht = disp_ht;
4015
0
        }
4016
0
        else
4017
0
        {
4018
0
            buffer_wd = ALIGN16(disp_wd) + (PAD_LEN_Y_H << 1);
4019
0
            buffer_ht = ALIGN16(disp_ht) + (PAD_LEN_Y_V << 2);
4020
0
        }
4021
0
    }
4022
0
    if(ps_dec->u4_app_disp_width > buffer_wd)
4023
0
        buffer_wd = ps_dec->u4_app_disp_width;
4024
4025
0
    if(0 == ps_dec->u4_share_disp_buf)
4026
0
    {
4027
0
        x_offset = 0;
4028
0
        y_offset = 0;
4029
0
    }
4030
0
    else
4031
0
    {
4032
0
        y_offset = (PAD_LEN_Y_V << 1);
4033
0
        x_offset = PAD_LEN_Y_H;
4034
4035
0
        if((NULL != ps_dec->ps_sps) && (1 == (ps_dec->ps_sps->u1_is_valid))
4036
0
                        && (0 != ps_dec->u2_crop_offset_y))
4037
0
        {
4038
0
            y_offset += ps_dec->u2_crop_offset_y / ps_dec->u2_frm_wd_y;
4039
0
            x_offset += ps_dec->u2_crop_offset_y % ps_dec->u2_frm_wd_y;
4040
0
        }
4041
0
    }
4042
4043
0
    ps_op->u4_disp_wd[0] = disp_wd;
4044
0
    ps_op->u4_disp_ht[0] = disp_ht;
4045
0
    ps_op->u4_buffer_wd[0] = buffer_wd;
4046
0
    ps_op->u4_buffer_ht[0] = buffer_ht;
4047
0
    ps_op->u4_x_offset[0] = x_offset;
4048
0
    ps_op->u4_y_offset[0] = y_offset;
4049
4050
0
    ps_op->u4_disp_wd[1] = ps_op->u4_disp_wd[2] = ((ps_op->u4_disp_wd[0] + 1)
4051
0
                    >> 1);
4052
0
    ps_op->u4_disp_ht[1] = ps_op->u4_disp_ht[2] = ((ps_op->u4_disp_ht[0] + 1)
4053
0
                    >> 1);
4054
0
    ps_op->u4_buffer_wd[1] = ps_op->u4_buffer_wd[2] = (ps_op->u4_buffer_wd[0]
4055
0
                    >> 1);
4056
0
    ps_op->u4_buffer_ht[1] = ps_op->u4_buffer_ht[2] = (ps_op->u4_buffer_ht[0]
4057
0
                    >> 1);
4058
0
    ps_op->u4_x_offset[1] = ps_op->u4_x_offset[2] =
4059
0
                    (ps_op->u4_x_offset[0] >> 1);
4060
0
    ps_op->u4_y_offset[1] = ps_op->u4_y_offset[2] =
4061
0
                    (ps_op->u4_y_offset[0] >> 1);
4062
4063
0
    if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
4064
0
                    || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
4065
0
    {
4066
0
        ps_op->u4_disp_wd[2] = 0;
4067
0
        ps_op->u4_disp_ht[2] = 0;
4068
0
        ps_op->u4_buffer_wd[2] = 0;
4069
0
        ps_op->u4_buffer_ht[2] = 0;
4070
0
        ps_op->u4_x_offset[2] = 0;
4071
0
        ps_op->u4_y_offset[2] = 0;
4072
4073
0
        ps_op->u4_disp_wd[1] <<= 1;
4074
0
        ps_op->u4_buffer_wd[1] <<= 1;
4075
0
        ps_op->u4_x_offset[1] <<= 1;
4076
0
    }
4077
4078
0
    return IV_SUCCESS;
4079
4080
0
}
4081
4082
WORD32 ih264d_get_vui_params(iv_obj_t *dec_hdl,
4083
                             void *pv_api_ip,
4084
                             void *pv_api_op)
4085
0
{
4086
0
    ih264d_ctl_get_vui_params_ip_t *ps_ip;
4087
0
    ih264d_ctl_get_vui_params_op_t *ps_op;
4088
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
4089
0
    dec_seq_params_t *ps_sps;
4090
0
    vui_t *ps_vui;
4091
0
    WORD32 i;
4092
0
    UWORD32 u4_size;
4093
4094
0
    ps_ip = (ih264d_ctl_get_vui_params_ip_t *)pv_api_ip;
4095
0
    ps_op = (ih264d_ctl_get_vui_params_op_t *)pv_api_op;
4096
0
    UNUSED(ps_ip);
4097
4098
0
    u4_size = ps_op->u4_size;
4099
0
    memset(ps_op, 0, sizeof(ih264d_ctl_get_vui_params_op_t));
4100
0
    ps_op->u4_size = u4_size;
4101
4102
0
    if(NULL == ps_dec->ps_cur_sps)
4103
0
    {
4104
0
        ps_op->u4_error_code = ERROR_VUI_PARAMS_NOT_FOUND;
4105
0
        return IV_FAIL;
4106
0
    }
4107
4108
0
    ps_sps = ps_dec->ps_cur_sps;
4109
0
    if((0 == ps_sps->u1_is_valid)
4110
0
                    || (0 == ps_sps->u1_vui_parameters_present_flag))
4111
0
    {
4112
0
        ps_op->u4_error_code = ERROR_VUI_PARAMS_NOT_FOUND;
4113
0
        return IV_FAIL;
4114
0
    }
4115
4116
0
    ps_vui = &ps_sps->s_vui;
4117
4118
0
    ps_op->u1_aspect_ratio_idc              = ps_vui->u1_aspect_ratio_idc;
4119
0
    ps_op->u2_sar_width                     = ps_vui->u2_sar_width;
4120
0
    ps_op->u2_sar_height                    = ps_vui->u2_sar_height;
4121
0
    ps_op->u1_overscan_appropriate_flag     = ps_vui->u1_overscan_appropriate_flag;
4122
0
    ps_op->u1_video_format                  = ps_vui->u1_video_format;
4123
0
    ps_op->u1_video_full_range_flag         = ps_vui->u1_video_full_range_flag;
4124
0
    ps_op->u1_colour_primaries              = ps_vui->u1_colour_primaries;
4125
0
    ps_op->u1_tfr_chars                     = ps_vui->u1_tfr_chars;
4126
0
    ps_op->u1_matrix_coeffs                 = ps_vui->u1_matrix_coeffs;
4127
0
    ps_op->u1_cr_top_field                  = ps_vui->u1_cr_top_field;
4128
0
    ps_op->u1_cr_bottom_field               = ps_vui->u1_cr_bottom_field;
4129
0
    ps_op->u4_num_units_in_tick             = ps_vui->u4_num_units_in_tick;
4130
0
    ps_op->u4_time_scale                    = ps_vui->u4_time_scale;
4131
0
    ps_op->u1_fixed_frame_rate_flag         = ps_vui->u1_fixed_frame_rate_flag;
4132
0
    ps_op->u1_nal_hrd_params_present        = ps_vui->u1_nal_hrd_params_present;
4133
0
    ps_op->u1_vcl_hrd_params_present        = ps_vui->u1_vcl_hrd_params_present;
4134
0
    ps_op->u1_low_delay_hrd_flag            = ps_vui->u1_low_delay_hrd_flag;
4135
0
    ps_op->u1_pic_struct_present_flag       = ps_vui->u1_pic_struct_present_flag;
4136
0
    ps_op->u1_bitstream_restriction_flag    = ps_vui->u1_bitstream_restriction_flag;
4137
0
    ps_op->u1_mv_over_pic_boundaries_flag   = ps_vui->u1_mv_over_pic_boundaries_flag;
4138
0
    ps_op->u4_max_bytes_per_pic_denom       = ps_vui->u4_max_bytes_per_pic_denom;
4139
0
    ps_op->u4_max_bits_per_mb_denom         = ps_vui->u4_max_bits_per_mb_denom;
4140
0
    ps_op->u4_log2_max_mv_length_horz       = ps_vui->u4_log2_max_mv_length_horz;
4141
0
    ps_op->u4_log2_max_mv_length_vert       = ps_vui->u4_log2_max_mv_length_vert;
4142
0
    ps_op->u4_num_reorder_frames            = ps_vui->u4_num_reorder_frames;
4143
0
    ps_op->u4_max_dec_frame_buffering       = ps_vui->u4_max_dec_frame_buffering;
4144
4145
0
    return IV_SUCCESS;
4146
0
}
4147
/*****************************************************************************/
4148
/*                                                                           */
4149
/*  Function Name : ih264d_get_sei_mdcv_params                               */
4150
/*                                                                           */
4151
/*  Description   : This function populates SEI mdcv message in              */
4152
/*                     output structure                                      */
4153
/*  Inputs        : iv_obj_t decoder handle                                  */
4154
/*                : pv_api_ip pointer to input structure                     */
4155
/*                : pv_api_op pointer to output structure                    */
4156
/*  Outputs       :                                                          */
4157
/*  Returns       : returns 0; 1 with error code when MDCV is not present    */
4158
/*                                                                           */
4159
/*  Issues        : none                                                     */
4160
/*                                                                           */
4161
/*  Revision History:                                                        */
4162
/*                                                                           */
4163
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
4164
/*                                                                           */
4165
/*                                                                           */
4166
/*****************************************************************************/
4167
WORD32 ih264d_get_sei_mdcv_params(iv_obj_t *dec_hdl,
4168
                                  void *pv_api_ip,
4169
                                  void *pv_api_op)
4170
0
{
4171
0
    ih264d_ctl_get_sei_mdcv_params_ip_t *ps_ip;
4172
0
    ih264d_ctl_get_sei_mdcv_params_op_t *ps_op;
4173
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
4174
0
    sei_mdcv_params_t *ps_sei_mdcv;
4175
0
    WORD32 i4_count;
4176
4177
0
    ps_ip = (ih264d_ctl_get_sei_mdcv_params_ip_t *)pv_api_ip;
4178
0
    ps_op = (ih264d_ctl_get_sei_mdcv_params_op_t *)pv_api_op;
4179
0
    UNUSED(ps_ip);
4180
4181
0
    if(0 == ps_dec->s_sei_export.u1_sei_mdcv_params_present_flag)
4182
0
    {
4183
0
        ps_op->u4_error_code = ERROR_SEI_MDCV_PARAMS_NOT_FOUND;
4184
0
        return IV_FAIL;
4185
0
    }
4186
4187
0
    ps_sei_mdcv = &ps_dec->s_sei_export.s_sei_mdcv_params;
4188
4189
0
    for(i4_count = 0; i4_count < NUM_SEI_MDCV_PRIMARIES; i4_count++)
4190
0
    {
4191
0
        ps_op->au2_display_primaries_x[i4_count] = ps_sei_mdcv->au2_display_primaries_x[i4_count];
4192
0
        ps_op->au2_display_primaries_y[i4_count] = ps_sei_mdcv->au2_display_primaries_y[i4_count];
4193
0
    }
4194
4195
0
    ps_op->u2_white_point_x = ps_sei_mdcv->u2_white_point_x;
4196
0
    ps_op->u2_white_point_y = ps_sei_mdcv->u2_white_point_y;
4197
0
    ps_op->u4_max_display_mastering_luminance = ps_sei_mdcv->u4_max_display_mastering_luminance;
4198
0
    ps_op->u4_min_display_mastering_luminance = ps_sei_mdcv->u4_min_display_mastering_luminance;
4199
4200
0
    return IV_SUCCESS;
4201
0
}
4202
4203
/*****************************************************************************/
4204
/*                                                                           */
4205
/*  Function Name : ih264d_get_sei_cll_params                                */
4206
/*                                                                           */
4207
/*  Description   : This function populates SEI cll message in               */
4208
/*                     output structure                                      */
4209
/*  Inputs        : iv_obj_t decoder handle                                  */
4210
/*                : pv_api_ip pointer to input structure                     */
4211
/*                : pv_api_op pointer to output structure                    */
4212
/*  Outputs       :                                                          */
4213
/*  Returns       : returns 0; 1 with error code when CLL is not present     */
4214
/*                                                                           */
4215
/*  Issues        : none                                                     */
4216
/*                                                                           */
4217
/*  Revision History:                                                        */
4218
/*                                                                           */
4219
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
4220
/*                                                                           */
4221
/*                                                                           */
4222
/*****************************************************************************/
4223
WORD32 ih264d_get_sei_cll_params(iv_obj_t *dec_hdl,
4224
                                 void *pv_api_ip,
4225
                                 void *pv_api_op)
4226
0
{
4227
0
    ih264d_ctl_get_sei_cll_params_ip_t *ps_ip;
4228
0
    ih264d_ctl_get_sei_cll_params_op_t *ps_op;
4229
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
4230
0
    sei_cll_params_t *ps_sei_cll;
4231
4232
0
    ps_ip = (ih264d_ctl_get_sei_cll_params_ip_t *)pv_api_ip;
4233
0
    ps_op = (ih264d_ctl_get_sei_cll_params_op_t *)pv_api_op;
4234
0
    UNUSED(ps_ip);
4235
4236
0
    if(0 == ps_dec->s_sei_export.u1_sei_cll_params_present_flag)
4237
0
    {
4238
0
        ps_op->u4_error_code = ERROR_SEI_CLL_PARAMS_NOT_FOUND;
4239
0
        return IV_FAIL;
4240
0
    }
4241
4242
0
    ps_sei_cll = &ps_dec->s_sei_export.s_sei_cll_params;
4243
4244
0
    ps_op->u2_max_content_light_level = ps_sei_cll->u2_max_content_light_level;
4245
0
    ps_op->u2_max_pic_average_light_level = ps_sei_cll->u2_max_pic_average_light_level;
4246
4247
0
    return IV_SUCCESS;
4248
0
}
4249
4250
/*****************************************************************************/
4251
/*                                                                           */
4252
/*  Function Name : ih264d_get_sei_ave_params                                */
4253
/*                                                                           */
4254
/*  Description   : This function populates SEI ave message in               */
4255
/*                     output structure                                      */
4256
/*  Inputs        : iv_obj_t decoder handle                                  */
4257
/*                : pv_api_ip pointer to input structure                     */
4258
/*                : pv_api_op pointer to output structure                    */
4259
/*  Outputs       :                                                          */
4260
/*  Returns       : returns 0; 1 with error code when AVE is not present     */
4261
/*                                                                           */
4262
/*  Issues        : none                                                     */
4263
/*                                                                           */
4264
/*  Revision History:                                                        */
4265
/*                                                                           */
4266
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
4267
/*                                                                           */
4268
/*                                                                           */
4269
/*****************************************************************************/
4270
WORD32 ih264d_get_sei_ave_params(iv_obj_t *dec_hdl,
4271
                                 void *pv_api_ip,
4272
                                 void *pv_api_op)
4273
0
{
4274
0
    ih264d_ctl_get_sei_ave_params_ip_t *ps_ip;
4275
0
    ih264d_ctl_get_sei_ave_params_op_t *ps_op;
4276
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
4277
0
    sei_ave_params_t *ps_sei_ave;
4278
4279
0
    ps_ip = (ih264d_ctl_get_sei_ave_params_ip_t *)pv_api_ip;
4280
0
    ps_op = (ih264d_ctl_get_sei_ave_params_op_t *)pv_api_op;
4281
0
    UNUSED(ps_ip);
4282
4283
0
    if(0 == ps_dec->s_sei_export.u1_sei_ave_params_present_flag)
4284
0
    {
4285
0
        ps_op->u4_error_code = ERROR_SEI_AVE_PARAMS_NOT_FOUND;
4286
0
        return IV_FAIL;
4287
0
    }
4288
4289
0
    ps_sei_ave = &ps_dec->s_sei_export.s_sei_ave_params;
4290
4291
0
    ps_op->u4_ambient_illuminance = ps_sei_ave->u4_ambient_illuminance;
4292
0
    ps_op->u2_ambient_light_x = ps_sei_ave->u2_ambient_light_x;
4293
0
    ps_op->u2_ambient_light_y = ps_sei_ave->u2_ambient_light_y;
4294
4295
0
    return IV_SUCCESS;
4296
0
}
4297
4298
/*****************************************************************************/
4299
/*                                                                           */
4300
/*  Function Name : ih264d_get_sei_ccv_params                                */
4301
/*                                                                           */
4302
/*  Description   : This function populates SEI mdcv message in              */
4303
/*                     output structure                                      */
4304
/*  Inputs        : iv_obj_t decoder handle                                  */
4305
/*                : pv_api_ip pointer to input structure                     */
4306
/*                : pv_api_op pointer to output structure                    */
4307
/*  Outputs       :                                                          */
4308
/*  Returns       : returns 0; 1 with error code when CCV is not present    */
4309
/*                                                                           */
4310
/*  Issues        : none                                                     */
4311
/*                                                                           */
4312
/*  Revision History:                                                        */
4313
/*                                                                           */
4314
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
4315
/*                                                                           */
4316
/*                                                                           */
4317
/*****************************************************************************/
4318
WORD32 ih264d_get_sei_ccv_params(iv_obj_t *dec_hdl,
4319
                                 void *pv_api_ip,
4320
                                 void *pv_api_op)
4321
0
{
4322
0
    ih264d_ctl_get_sei_ccv_params_ip_t *ps_ip;
4323
0
    ih264d_ctl_get_sei_ccv_params_op_t *ps_op;
4324
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
4325
0
    sei_ccv_params_t *ps_sei_ccv;
4326
0
    WORD32 i4_count;
4327
4328
0
    ps_ip = (ih264d_ctl_get_sei_ccv_params_ip_t *)pv_api_ip;
4329
0
    ps_op = (ih264d_ctl_get_sei_ccv_params_op_t *)pv_api_op;
4330
0
    UNUSED(ps_ip);
4331
4332
0
    if(0 == ps_dec->s_sei_export.u1_sei_ccv_params_present_flag)
4333
0
    {
4334
0
        ps_op->u4_error_code = ERROR_SEI_CCV_PARAMS_NOT_FOUND;
4335
0
        return IV_FAIL;
4336
0
    }
4337
4338
0
    ps_sei_ccv = &ps_dec->s_sei_export.s_sei_ccv_params;
4339
4340
0
    ps_op->u1_ccv_cancel_flag = ps_sei_ccv->u1_ccv_cancel_flag;
4341
4342
0
    if(0 == ps_op->u1_ccv_cancel_flag)
4343
0
    {
4344
0
        ps_op->u1_ccv_persistence_flag = ps_sei_ccv->u1_ccv_persistence_flag;
4345
0
        ps_op->u1_ccv_primaries_present_flag = ps_sei_ccv->u1_ccv_primaries_present_flag;
4346
0
        ps_op->u1_ccv_min_luminance_value_present_flag =
4347
0
                    ps_sei_ccv->u1_ccv_min_luminance_value_present_flag;
4348
0
        ps_op->u1_ccv_max_luminance_value_present_flag =
4349
0
                    ps_sei_ccv->u1_ccv_max_luminance_value_present_flag;
4350
0
        ps_op->u1_ccv_avg_luminance_value_present_flag =
4351
0
                    ps_sei_ccv->u1_ccv_avg_luminance_value_present_flag;
4352
0
        ps_op->u1_ccv_reserved_zero_2bits = ps_sei_ccv->u1_ccv_reserved_zero_2bits;
4353
4354
0
        if(1 == ps_sei_ccv->u1_ccv_primaries_present_flag)
4355
0
        {
4356
0
            for(i4_count = 0; i4_count < NUM_SEI_CCV_PRIMARIES; i4_count++)
4357
0
            {
4358
0
                ps_op->ai4_ccv_primaries_x[i4_count] = ps_sei_ccv->ai4_ccv_primaries_x[i4_count];
4359
0
                ps_op->ai4_ccv_primaries_y[i4_count] = ps_sei_ccv->ai4_ccv_primaries_y[i4_count];
4360
0
            }
4361
0
        }
4362
4363
0
        if(1 == ps_sei_ccv->u1_ccv_min_luminance_value_present_flag)
4364
0
        {
4365
0
            ps_op->u4_ccv_min_luminance_value = ps_sei_ccv->u4_ccv_min_luminance_value;
4366
0
        }
4367
0
        if(1 == ps_sei_ccv->u1_ccv_max_luminance_value_present_flag)
4368
0
        {
4369
0
            ps_op->u4_ccv_max_luminance_value = ps_sei_ccv->u4_ccv_max_luminance_value;
4370
0
        }
4371
0
        if(1 == ps_sei_ccv->u1_ccv_avg_luminance_value_present_flag)
4372
0
        {
4373
0
            ps_op->u4_ccv_avg_luminance_value = ps_sei_ccv->u4_ccv_avg_luminance_value;
4374
0
        }
4375
0
    }
4376
4377
0
    return IV_SUCCESS;
4378
0
}
4379
4380
/*****************************************************************************/
4381
/*                                                                           */
4382
/*  Function Name : ih264d_get_sei_sii_params                                */
4383
/*                                                                           */
4384
/*  Description   : This function populates SEI sii message in               */
4385
/*                     output structure                                      */
4386
/*  Inputs        : iv_obj_t decoder handle                                  */
4387
/*                : pv_api_ip pointer to input structure                     */
4388
/*                : pv_api_op pointer to output structure                    */
4389
/*  Outputs       :                                                          */
4390
/*  Returns       : returns 0; 1 with error code when SII is not present     */
4391
/*                                                                           */
4392
/*  Issues        : none                                                     */
4393
/*                                                                           */
4394
/*  Revision History:                                                        */
4395
/*                                                                           */
4396
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
4397
/*                                                                           */
4398
/*                                                                           */
4399
/*****************************************************************************/
4400
WORD32 ih264d_get_sei_sii_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
4401
0
{
4402
0
    ih264d_ctl_get_sei_sii_params_ip_t *ps_ip;
4403
0
    ih264d_ctl_get_sei_sii_params_op_t *ps_op;
4404
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
4405
0
    sei_sii_params_t *ps_sei_sii;
4406
0
    int i;
4407
4408
0
    ps_ip = (ih264d_ctl_get_sei_sii_params_ip_t *) pv_api_ip;
4409
0
    ps_op = (ih264d_ctl_get_sei_sii_params_op_t *) pv_api_op;
4410
0
    UNUSED(ps_ip);
4411
4412
0
    if(0 == ps_dec->s_sei_export.u1_sei_sii_params_present_flag)
4413
0
    {
4414
0
        ps_op->u4_error_code = ERROR_SEI_SII_PARAMS_NOT_FOUND;
4415
0
        return IV_FAIL;
4416
0
    }
4417
4418
0
    ps_sei_sii = &ps_dec->s_sei_export.s_sei_sii_params;
4419
4420
0
    if((ps_sei_sii->u4_sii_sub_layer_idx > 0) &&
4421
0
       (ps_sei_sii->u1_fixed_shutter_interval_within_cvs_flag == 1))
4422
0
    {
4423
0
        ps_op->u4_error_code = ERROR_INV_SEI_SII_PARAMS;
4424
0
        return IV_FAIL;
4425
0
    }
4426
4427
0
    if((ps_sei_sii->u4_sii_sub_layer_idx > ps_sei_sii->u1_sii_max_sub_layers_minus1) &&
4428
0
       (ps_sei_sii->u1_fixed_shutter_interval_within_cvs_flag == 0))
4429
0
    {
4430
0
        ps_op->u4_error_code = ERROR_INV_SEI_SII_PARAMS;
4431
0
        return IV_FAIL;
4432
0
    }
4433
4434
0
    ps_op->u4_sii_sub_layer_idx = ps_sei_sii->u4_sii_sub_layer_idx;
4435
4436
0
    if(0 == ps_op->u4_sii_sub_layer_idx)
4437
0
    {
4438
0
        ps_op->u1_shutter_interval_info_present_flag =
4439
0
            ps_sei_sii->u1_shutter_interval_info_present_flag;
4440
4441
0
        if(1 == ps_sei_sii->u1_shutter_interval_info_present_flag)
4442
0
        {
4443
0
            ps_op->u4_sii_time_scale = ps_sei_sii->u4_sii_time_scale;
4444
0
            ps_op->u1_fixed_shutter_interval_within_cvs_flag =
4445
0
                ps_sei_sii->u1_fixed_shutter_interval_within_cvs_flag;
4446
4447
0
            if(1 == ps_sei_sii->u1_fixed_shutter_interval_within_cvs_flag)
4448
0
            {
4449
0
                ps_op->u4_sii_num_units_in_shutter_interval =
4450
0
                    ps_sei_sii->u4_sii_num_units_in_shutter_interval;
4451
0
            }
4452
0
            else
4453
0
            {
4454
0
                ps_op->u1_sii_max_sub_layers_minus1 = ps_sei_sii->u1_sii_max_sub_layers_minus1;
4455
0
                for(i = 0; i <= ps_sei_sii->u1_sii_max_sub_layers_minus1; i++)
4456
0
                {
4457
0
                    ps_op->au4_sub_layer_num_units_in_shutter_interval[i] =
4458
0
                        ps_sei_sii->au4_sub_layer_num_units_in_shutter_interval[i];
4459
0
                }
4460
0
            }
4461
0
        }
4462
0
    }
4463
4464
0
    return IV_SUCCESS;
4465
0
}
4466
4467
/*****************************************************************************/
4468
/*                                                                           */
4469
/*  Function Name : ih264d_get_sei_fgc_params                                */
4470
/*                                                                           */
4471
/*  Description   : This function populates SEI FGC message in               */
4472
/*                     output structure                                      */
4473
/*  Inputs        : iv_obj_t decoder handle                                  */
4474
/*                : pv_api_ip pointer to input structure                     */
4475
/*                : pv_api_op pointer to output structure                    */
4476
/*  Outputs       :                                                          */
4477
/*  Returns       : returns 0; 1 with error code when FGC is not present     */
4478
/*                                                                           */
4479
/*  Issues        : none                                                     */
4480
/*                                                                           */
4481
/*  Revision History:                                                        */
4482
/*                                                                           */
4483
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
4484
/*                                                                           */
4485
/*                                                                           */
4486
/*****************************************************************************/
4487
WORD32 ih264d_get_sei_fgc_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
4488
0
{
4489
0
    ih264d_ctl_get_sei_fgc_params_ip_t *ps_ip;
4490
0
    ih264d_ctl_get_sei_fgc_params_op_t *ps_op;
4491
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
4492
0
    sei_fgc_params_t *ps_sei_fgc;
4493
0
    WORD32 i4_count;
4494
0
    UWORD32 c, i, j;
4495
4496
0
    ps_ip = (ih264d_ctl_get_sei_fgc_params_ip_t *) pv_api_ip;
4497
0
    ps_op = (ih264d_ctl_get_sei_fgc_params_op_t *) pv_api_op;
4498
0
    UNUSED(ps_ip);
4499
4500
0
    if(0 == ps_dec->s_sei_export.u1_sei_fgc_params_present_flag)
4501
0
    {
4502
0
        ps_op->u4_error_code = ERROR_SEI_FGC_PARAMS_NOT_FOUND;
4503
0
        return IV_FAIL;
4504
0
    }
4505
4506
0
    ps_sei_fgc = &ps_dec->s_sei_export.s_sei_fgc_params;
4507
4508
0
    ps_op->u1_film_grain_characteristics_cancel_flag =
4509
0
        ps_sei_fgc->u1_film_grain_characteristics_cancel_flag;
4510
4511
0
    if(0 == ps_op->u1_film_grain_characteristics_cancel_flag)
4512
0
    {
4513
0
        ps_op->i4_poc = ps_sei_fgc->i4_poc;
4514
0
        ps_op->u4_idr_pic_id = ps_sei_fgc->u4_idr_pic_id;
4515
0
        ps_op->u1_film_grain_model_id = ps_sei_fgc->u1_film_grain_model_id;
4516
0
        ps_op->u1_separate_colour_description_present_flag =
4517
0
            ps_sei_fgc->u1_separate_colour_description_present_flag;
4518
4519
0
        if(ps_op->u1_separate_colour_description_present_flag)
4520
0
        {
4521
0
            ps_op->u1_film_grain_bit_depth_luma_minus8 =
4522
0
                ps_sei_fgc->u1_film_grain_bit_depth_luma_minus8;
4523
0
            ps_op->u1_film_grain_bit_depth_chroma_minus8 =
4524
0
                ps_sei_fgc->u1_film_grain_bit_depth_chroma_minus8;
4525
0
            ps_op->u1_film_grain_full_range_flag = ps_sei_fgc->u1_film_grain_full_range_flag;
4526
0
            ps_op->u1_film_grain_colour_primaries = ps_sei_fgc->u1_film_grain_colour_primaries;
4527
0
            ps_op->u1_film_grain_transfer_characteristics =
4528
0
                ps_sei_fgc->u1_film_grain_transfer_characteristics;
4529
0
            ps_op->u1_film_grain_matrix_coefficients =
4530
0
                ps_sei_fgc->u1_film_grain_matrix_coefficients;
4531
0
        }
4532
0
        ps_op->u1_blending_mode_id = ps_sei_fgc->u1_blending_mode_id;
4533
0
        ps_op->u1_log2_scale_factor = ps_sei_fgc->u1_log2_scale_factor;
4534
4535
0
        for(c = 0; c < SEI_FGC_NUM_COLOUR_COMPONENTS; c++)
4536
0
        {
4537
0
            ps_op->au1_comp_model_present_flag[c] = ps_sei_fgc->au1_comp_model_present_flag[c];
4538
0
        }
4539
4540
0
        for(c = 0; c < SEI_FGC_NUM_COLOUR_COMPONENTS; c++)
4541
0
        {
4542
0
            if(ps_op->au1_comp_model_present_flag[c])
4543
0
            {
4544
0
                ps_op->au1_num_intensity_intervals_minus1[c] =
4545
0
                    ps_sei_fgc->au1_num_intensity_intervals_minus1[c];
4546
4547
0
                ps_op->au1_num_model_values_minus1[c] = ps_sei_fgc->au1_num_model_values_minus1[c];
4548
4549
0
                for(i = 0; i <= ps_op->au1_num_intensity_intervals_minus1[c]; i++)
4550
0
                {
4551
0
                    ps_op->au1_intensity_interval_lower_bound[c][i] =
4552
0
                        ps_sei_fgc->au1_intensity_interval_lower_bound[c][i];
4553
0
                    ps_op->au1_intensity_interval_upper_bound[c][i] =
4554
0
                        ps_sei_fgc->au1_intensity_interval_upper_bound[c][i];
4555
4556
0
                    for(j = 0; j <= ps_op->au1_num_model_values_minus1[c]; j++)
4557
0
                    {
4558
0
                        ps_op->ai4_comp_model_value[c][i][j] =
4559
0
                            ps_sei_fgc->ai4_comp_model_value[c][i][j];
4560
0
                    }
4561
0
                }
4562
0
            }
4563
0
        }
4564
0
        ps_op->u4_film_grain_characteristics_repetition_period =
4565
0
            ps_sei_fgc->u4_film_grain_characteristics_repetition_period;
4566
0
    }
4567
0
    return IV_SUCCESS;
4568
0
}
4569
4570
WORD32 ih264d_set_num_cores(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
4571
0
{
4572
0
    ih264d_ctl_set_num_cores_ip_t *ps_ip;
4573
0
    ih264d_ctl_set_num_cores_op_t *ps_op;
4574
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
4575
4576
0
    ps_ip = (ih264d_ctl_set_num_cores_ip_t *)pv_api_ip;
4577
0
    ps_op = (ih264d_ctl_set_num_cores_op_t *)pv_api_op;
4578
0
    ps_op->u4_error_code = 0;
4579
0
    ps_dec->u4_num_cores = ps_ip->u4_num_cores;
4580
0
    if(ps_dec->u4_num_cores == 1)
4581
0
    {
4582
0
        ps_dec->u1_separate_parse = 0;
4583
0
    }
4584
0
    else
4585
0
    {
4586
0
        ps_dec->u1_separate_parse = 1;
4587
0
    }
4588
4589
    /*using only upto three threads currently*/
4590
0
    if(ps_dec->u4_num_cores > 3)
4591
0
        ps_dec->u4_num_cores = 3;
4592
4593
0
    return IV_SUCCESS;
4594
0
}
4595
4596
void ih264d_fill_output_struct_from_context(dec_struct_t *ps_dec,
4597
                                            ivd_video_decode_op_t *ps_dec_op)
4598
0
{
4599
0
    if((ps_dec_op->u4_error_code & 0xff)
4600
0
                    != ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED)
4601
0
    {
4602
0
        ps_dec_op->u4_pic_wd = (UWORD32)ps_dec->u2_disp_width;
4603
0
        ps_dec_op->u4_pic_ht = (UWORD32)ps_dec->u2_disp_height;
4604
0
    }
4605
0
    ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
4606
0
    ps_dec_op->i4_display_index = ps_dec->i4_display_index;
4607
0
    ps_dec_op->e_pic_type = ps_dec->i4_frametype;
4608
4609
0
    ps_dec_op->u4_new_seq = 0;
4610
0
    ps_dec_op->u4_output_present = ps_dec->u4_output_present;
4611
0
    ps_dec_op->u4_progressive_frame_flag =
4612
0
                    ps_dec->s_disp_op.u4_progressive_frame_flag;
4613
4614
0
    ps_dec_op->u4_is_ref_flag = 1;
4615
0
    if(ps_dec_op->u4_frame_decoded_flag)
4616
0
    {
4617
0
        if(ps_dec->ps_cur_slice->u1_nal_ref_idc == 0)
4618
0
            ps_dec_op->u4_is_ref_flag = 0;
4619
0
    }
4620
4621
0
    ps_dec_op->e_output_format = ps_dec->s_disp_op.e_output_format;
4622
0
    ps_dec_op->s_disp_frm_buf = ps_dec->s_disp_op.s_disp_frm_buf;
4623
0
    ps_dec_op->e4_fld_type = ps_dec->s_disp_op.e4_fld_type;
4624
0
    ps_dec_op->u4_ts = ps_dec->s_disp_op.u4_ts;
4625
0
    ps_dec_op->u4_disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
4626
4627
0
    ih264d_export_sei_params(&ps_dec_op->s_sei_decode_op, ps_dec);
4628
0
}
4629
4630
/*****************************************************************************/
4631
/*                                                                           */
4632
/*  Function Name : ih264d_api_function                                      */
4633
/*                                                                           */
4634
/*  Description   :                                                          */
4635
/*                                                                           */
4636
/*  Inputs        :iv_obj_t decoder handle                                   */
4637
/*                :pv_api_ip pointer to input structure                      */
4638
/*                :pv_api_op pointer to output structure                     */
4639
/*  Outputs       :                                                          */
4640
/*  Returns       : void                                                     */
4641
/*                                                                           */
4642
/*  Issues        : none                                                     */
4643
/*                                                                           */
4644
/*  Revision History:                                                        */
4645
/*                                                                           */
4646
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
4647
/*         22 10 2008    100356         Draft                                */
4648
/*                                                                           */
4649
/*****************************************************************************/
4650
IV_API_CALL_STATUS_T ih264d_api_function(iv_obj_t *dec_hdl,
4651
                                              void *pv_api_ip,
4652
                                              void *pv_api_op)
4653
0
{
4654
0
    UWORD32 command;
4655
0
    UWORD32 *pu2_ptr_cmd;
4656
0
    UWORD32 u4_api_ret;
4657
0
    IV_API_CALL_STATUS_T e_status;
4658
0
    e_status = api_check_struct_sanity(dec_hdl, pv_api_ip, pv_api_op);
4659
4660
0
    if(e_status != IV_SUCCESS)
4661
0
    {
4662
0
        UWORD32 *ptr_err;
4663
4664
0
        ptr_err = (UWORD32 *)pv_api_op;
4665
0
        UNUSED(ptr_err);
4666
0
        H264_DEC_DEBUG_PRINT("error code = %d\n", *(ptr_err + 1));
4667
0
        return IV_FAIL;
4668
0
    }
4669
4670
0
    pu2_ptr_cmd = (UWORD32 *)pv_api_ip;
4671
0
    pu2_ptr_cmd++;
4672
4673
0
    command = *pu2_ptr_cmd;
4674
//    H264_DEC_DEBUG_PRINT("inside lib = %d\n",command);
4675
0
    switch(command)
4676
0
    {
4677
4678
0
        case IVD_CMD_CREATE:
4679
0
            u4_api_ret = ih264d_create(dec_hdl, (void *)pv_api_ip,
4680
0
                                     (void *)pv_api_op);
4681
0
            break;
4682
0
        case IVD_CMD_DELETE:
4683
0
            u4_api_ret = ih264d_delete(dec_hdl, (void *)pv_api_ip,
4684
0
                                     (void *)pv_api_op);
4685
0
            break;
4686
4687
0
        case IVD_CMD_VIDEO_DECODE:
4688
0
            u4_api_ret = ih264d_video_decode(dec_hdl, (void *)pv_api_ip,
4689
0
                                             (void *)pv_api_op);
4690
0
            break;
4691
4692
0
        case IVD_CMD_GET_DISPLAY_FRAME:
4693
0
            u4_api_ret = ih264d_get_display_frame(dec_hdl, (void *)pv_api_ip,
4694
0
                                                  (void *)pv_api_op);
4695
4696
0
            break;
4697
4698
0
        case IVD_CMD_SET_DISPLAY_FRAME:
4699
0
            u4_api_ret = ih264d_set_display_frame(dec_hdl, (void *)pv_api_ip,
4700
0
                                                  (void *)pv_api_op);
4701
4702
0
            break;
4703
4704
0
        case IVD_CMD_REL_DISPLAY_FRAME:
4705
0
            u4_api_ret = ih264d_rel_display_frame(dec_hdl, (void *)pv_api_ip,
4706
0
                                                  (void *)pv_api_op);
4707
0
            break;
4708
4709
0
        case IVD_CMD_VIDEO_CTL:
4710
0
            u4_api_ret = ih264d_ctl(dec_hdl, (void *)pv_api_ip,
4711
0
                                    (void *)pv_api_op);
4712
0
            break;
4713
0
        default:
4714
0
            u4_api_ret = IV_FAIL;
4715
0
            break;
4716
0
    }
4717
4718
0
    return u4_api_ret;
4719
0
}