Coverage Report

Created: 2026-04-29 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmpeg2/decoder/impeg2d_dec_hdr.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
#include <string.h>
21
#ifdef __ANDROID__
22
#include <android/log.h>
23
#endif
24
#include "iv_datatypedef.h"
25
#include "iv.h"
26
#include "ivd.h"
27
#include "impeg2_macros.h"
28
#include "impeg2_buf_mgr.h"
29
#include "impeg2_disp_mgr.h"
30
#include "impeg2_defs.h"
31
#include "impeg2_inter_pred.h"
32
#include "impeg2_idct.h"
33
#include "impeg2_format_conv.h"
34
#include "impeg2_mem_func.h"
35
#include "impeg2_platform_macros.h"
36
#include "ithread.h"
37
#include "impeg2_job_queue.h"
38
39
#include "impeg2d.h"
40
#include "impeg2d_bitstream.h"
41
#include "impeg2d_api.h"
42
#include "impeg2d_structs.h"
43
#include "impeg2_globals.h"
44
#include "impeg2d_pic_proc.h"
45
#include "impeg2d_deinterlace.h"
46
47
#ifdef __ANDROID__
48
#ifndef ALOGE
49
#define ALOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, NULL, __VA_ARGS__))
50
#endif
51
inline int android_errorWriteLog(int tag, const char* subTag) {
52
    ALOGE("android_errorWriteLog(%x, %s)", tag, subTag);
53
    return 0;
54
}
55
#endif
56
57
/*****************************************************************************
58
* MPEG2 Constants for Parse Check
59
******************************************************************************/
60
225k
#define MPEG2_MAX_FRAME_RATE_CODE   8
61
62
/******************************************************************************
63
*  Function Name   : impeg2d_next_start_code
64
*
65
*  Description     : Peek for next_start_code from the stream_t.
66
*
67
*  Arguments       :
68
*  dec             : Decoder Context
69
*
70
*  Values Returned : None
71
******************************************************************************/
72
void impeg2d_next_start_code(dec_state_t *ps_dec)
73
4.45M
{
74
4.45M
    stream_t *ps_stream;
75
4.45M
    ps_stream = &ps_dec->s_bit_stream;
76
4.45M
    impeg2d_bit_stream_flush_to_byte_boundary(ps_stream);
77
78
165M
    while ((impeg2d_bit_stream_nxt(ps_stream,START_CODE_PREFIX_LEN) != START_CODE_PREFIX)
79
160M
        && (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
80
160M
    {
81
160M
        impeg2d_bit_stream_get(ps_stream,8);
82
160M
    }
83
4.45M
    return;
84
4.45M
}
85
/******************************************************************************
86
*  Function Name   : impeg2d_next_code
87
*
88
*  Description     : Peek for next_start_code from the stream_t.
89
*
90
*  Arguments       :
91
*  dec             : Decoder Context
92
*
93
*  Values Returned : None
94
******************************************************************************/
95
void impeg2d_next_code(dec_state_t *ps_dec, UWORD32 u4_start_code_val)
96
31.4k
{
97
31.4k
    stream_t *ps_stream;
98
31.4k
    ps_stream = &ps_dec->s_bit_stream;
99
31.4k
    impeg2d_bit_stream_flush_to_byte_boundary(ps_stream);
100
101
142M
    while ((impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) != u4_start_code_val) &&
102
142M
            (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
103
142M
    {
104
105
142M
        if (impeg2d_bit_stream_get(ps_stream,8) != 0)
106
112M
        {
107
            /* Ignore stuffing bit errors. */
108
112M
        }
109
110
142M
    }
111
31.4k
    return;
112
31.4k
}
113
/******************************************************************************
114
*  Function Name   : impeg2d_peek_next_start_code
115
*
116
*  Description     : Peek for next_start_code from the stream_t.
117
*
118
*  Arguments       :
119
*  dec             : Decoder Context
120
*
121
*  Values Returned : None
122
******************************************************************************/
123
void impeg2d_peek_next_start_code(dec_state_t *ps_dec)
124
21.3k
{
125
21.3k
    stream_t *ps_stream;
126
21.3k
    ps_stream = &ps_dec->s_bit_stream;
127
21.3k
    impeg2d_bit_stream_flush_to_byte_boundary(ps_stream);
128
129
7.91M
    while ((impeg2d_bit_stream_nxt(ps_stream,START_CODE_PREFIX_LEN) != START_CODE_PREFIX)
130
7.88M
        && (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
131
7.88M
    {
132
7.88M
        impeg2d_bit_stream_get(ps_stream,8);
133
7.88M
    }
134
21.3k
    return;
135
21.3k
}
136
/******************************************************************************
137
*
138
*  Function Name   : impeg2d_dec_seq_hdr
139
*
140
*  Description     : Decodes Sequence header information
141
*
142
*  Arguments       :
143
*  dec             : Decoder Context
144
*
145
*  Values Returned : None
146
******************************************************************************/
147
IMPEG2D_ERROR_CODES_T impeg2d_dec_seq_hdr(dec_state_t *ps_dec)
148
238k
{
149
238k
    stream_t *ps_stream;
150
238k
    ps_stream = &ps_dec->s_bit_stream;
151
238k
    UWORD16 u2_height;
152
238k
    UWORD16 u2_width;
153
154
238k
    if (impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) != SEQUENCE_HEADER_CODE)
155
0
    {
156
0
        impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
157
0
        return IMPEG2D_FRM_HDR_START_CODE_NOT_FOUND;
158
159
0
    }
160
238k
    impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
161
162
238k
    u2_width    = impeg2d_bit_stream_get(ps_stream,12);
163
238k
    u2_height   = impeg2d_bit_stream_get(ps_stream,12);
164
165
238k
    if (0 == u2_width || 0 == u2_height)
166
1.11k
    {
167
1.11k
        IMPEG2D_ERROR_CODES_T e_error = IMPEG2D_FRM_HDR_DECODE_ERR;
168
1.11k
        return e_error;
169
1.11k
    }
170
171
237k
    if ((u2_width != ps_dec->u2_horizontal_size)
172
226k
                    || (u2_height != ps_dec->u2_vertical_size))
173
12.1k
    {
174
12.1k
        if (0 == ps_dec->u2_header_done)
175
7.27k
        {
176
            /* This is the first time we are reading the resolution */
177
7.27k
            ps_dec->u2_horizontal_size = u2_width;
178
7.27k
            ps_dec->u2_vertical_size = u2_height;
179
7.27k
        }
180
4.84k
        else
181
4.84k
        {
182
4.84k
            if (0 == ps_dec->i4_pic_count)
183
774
            {
184
                /* Decoder has not decoded a single frame since the last
185
                 * reset/init. This implies that we have two headers in the
186
                 * input stream. So, do not indicate a resolution change, since
187
                 * this can take the decoder into an infinite loop.
188
                 */
189
774
                return (IMPEG2D_ERROR_CODES_T) IMPEG2D_FRM_HDR_DECODE_ERR;
190
774
            }
191
4.07k
            else if((u2_width > ps_dec->u2_create_max_width)
192
2.58k
                            || (u2_height > ps_dec->u2_create_max_height))
193
2.35k
            {
194
2.35k
                IMPEG2D_ERROR_CODES_T e_error = IMPEG2D_UNSUPPORTED_DIMENSIONS;
195
196
2.35k
                ps_dec->u2_reinit_max_height   = u2_height;
197
2.35k
                ps_dec->u2_reinit_max_width    = u2_width;
198
199
2.35k
                return e_error;
200
2.35k
            }
201
1.71k
            else if((ps_dec->u2_horizontal_size < MIN_WIDTH)
202
1.71k
                            || (ps_dec->u2_vertical_size < MIN_HEIGHT))
203
0
            {
204
0
                return IMPEG2D_UNSUPPORTED_DIMENSIONS;
205
0
            }
206
1.71k
            else
207
1.71k
            {
208
                /* The resolution has changed */
209
1.71k
                return (IMPEG2D_ERROR_CODES_T)IVD_RES_CHANGED;
210
1.71k
            }
211
4.84k
        }
212
12.1k
    }
213
214
232k
    if((ps_dec->u2_horizontal_size > ps_dec->u2_create_max_width)
215
230k
                    || (ps_dec->u2_vertical_size > ps_dec->u2_create_max_height))
216
2.44k
    {
217
2.44k
        IMPEG2D_ERROR_CODES_T e_error = IMPEG2D_UNSUPPORTED_DIMENSIONS;
218
2.44k
        ps_dec->u2_reinit_max_height   = ps_dec->u2_vertical_size;
219
2.44k
        ps_dec->u2_reinit_max_width    = ps_dec->u2_horizontal_size;
220
2.44k
        return e_error;
221
2.44k
    }
222
223
229k
    if((ps_dec->u2_horizontal_size < MIN_WIDTH)
224
228k
                    || (ps_dec->u2_vertical_size < MIN_HEIGHT))
225
4.50k
    {
226
4.50k
        return IMPEG2D_UNSUPPORTED_DIMENSIONS;
227
4.50k
    }
228
229
    /*------------------------------------------------------------------------*/
230
    /* Flush the following as they are not being used                         */
231
    /* aspect_ratio_info (4 bits)                                             */
232
    /*------------------------------------------------------------------------*/
233
225k
    ps_dec->u2_aspect_ratio_info = impeg2d_bit_stream_get(ps_stream,4);
234
235
    /*------------------------------------------------------------------------*/
236
    /* Frame rate code(4 bits)                                                */
237
    /*------------------------------------------------------------------------*/
238
225k
    ps_dec->u2_frame_rate_code = impeg2d_bit_stream_get(ps_stream,4);
239
225k
    if (ps_dec->u2_frame_rate_code > MPEG2_MAX_FRAME_RATE_CODE)
240
667
    {
241
667
        return IMPEG2D_FRM_HDR_DECODE_ERR;
242
667
    }
243
    /*------------------------------------------------------------------------*/
244
    /* Flush the following as they are not being used                         */
245
    /* bit_rate_value (18 bits)                                               */
246
    /*------------------------------------------------------------------------*/
247
224k
    impeg2d_bit_stream_flush(ps_stream,18);
248
224k
    GET_MARKER_BIT(ps_dec,ps_stream);
249
    /*------------------------------------------------------------------------*/
250
    /* Flush the following as they are not being used                         */
251
    /* vbv_buffer_size_value(10 bits), constrained_parameter_flag (1 bit)     */
252
    /*------------------------------------------------------------------------*/
253
224k
    impeg2d_bit_stream_flush(ps_stream,11);
254
255
    /*------------------------------------------------------------------------*/
256
    /* Quantization matrix for the intra blocks                               */
257
    /*------------------------------------------------------------------------*/
258
224k
    if(impeg2d_bit_stream_get_bit(ps_stream) == 1)
259
3.00k
    {
260
3.00k
        UWORD16 i;
261
195k
        for(i = 0; i < NUM_PELS_IN_BLOCK; i++)
262
192k
        {
263
192k
            ps_dec->au1_intra_quant_matrix[gau1_impeg2_inv_scan_zig_zag[i]] =  (UWORD8)impeg2d_bit_stream_get(ps_stream,8);
264
192k
        }
265
266
3.00k
    }
267
221k
    else
268
221k
    {
269
221k
        memcpy(ps_dec->au1_intra_quant_matrix,gau1_impeg2_intra_quant_matrix_default,
270
221k
                NUM_PELS_IN_BLOCK);
271
221k
    }
272
273
    /*------------------------------------------------------------------------*/
274
    /* Quantization matrix for the inter blocks                               */
275
    /*------------------------------------------------------------------------*/
276
224k
    if(impeg2d_bit_stream_get_bit(ps_stream) == 1)
277
2.05k
    {
278
2.05k
        UWORD16 i;
279
133k
        for(i = 0; i < NUM_PELS_IN_BLOCK; i++)
280
131k
        {
281
131k
            ps_dec->au1_inter_quant_matrix[gau1_impeg2_inv_scan_zig_zag[i]] =   (UWORD8)impeg2d_bit_stream_get(ps_stream,8);
282
131k
        }
283
2.05k
    }
284
222k
    else
285
222k
    {
286
222k
        memcpy(ps_dec->au1_inter_quant_matrix,gau1_impeg2_inter_quant_matrix_default,
287
222k
            NUM_PELS_IN_BLOCK);
288
222k
    }
289
224k
    impeg2d_next_start_code(ps_dec);
290
291
224k
    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
292
225k
}
293
294
/******************************************************************************
295
*
296
*  Function Name   : impeg2d_dec_seq_ext
297
*
298
*  Description     : Gets additional sequence data.
299
*
300
*  Arguments       :
301
*  dec             : Decoder Context
302
*
303
*  Values Returned : None
304
******************************************************************************/
305
IMPEG2D_ERROR_CODES_T impeg2d_dec_seq_ext(dec_state_t *ps_dec)
306
18.4k
{
307
18.4k
    stream_t *ps_stream;
308
18.4k
    UWORD16 horizontal_value;
309
18.4k
    UWORD16 vertical_value;
310
311
18.4k
    ps_stream = &ps_dec->s_bit_stream;
312
313
18.4k
    if (impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) != EXTENSION_START_CODE)
314
825
    {
315
825
        impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
316
825
        return IMPEG2D_FRM_HDR_START_CODE_NOT_FOUND;
317
318
825
    }
319
    /* Flush the extension start code */
320
17.6k
    impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
321
322
    /* Flush extension start code identifier */
323
17.6k
    impeg2d_bit_stream_flush(ps_stream,4);
324
325
    /*----------------------------------------------------------------------*/
326
    /* Profile and Level information                                        */
327
    /*----------------------------------------------------------------------*/
328
17.6k
    {
329
17.6k
        UWORD32   u4_esc_bit, u4_profile, u4_level;
330
331
        /* Read the profile and level information */
332
        /* check_profile_and_level: Table 8-1     */
333
        /* [7:7] 1 Escape bit                     */
334
        /* [6:4] 3 Profile identification         */
335
        /* [3:0] 4 Level identification           */
336
337
17.6k
        u4_esc_bit   = impeg2d_bit_stream_get_bit(ps_stream);
338
17.6k
        u4_profile   = impeg2d_bit_stream_get(ps_stream,3);
339
17.6k
        u4_level     = impeg2d_bit_stream_get(ps_stream,4);
340
17.6k
        UNUSED(u4_profile);
341
17.6k
        UNUSED(u4_level);
342
        /*
343
        if( escBit == 1                   ||
344
            profile < MPEG2_MAIN_PROFILE  ||
345
            level < MPEG2_MAIN_LEVEL)
346
            */
347
17.6k
        if (1 == u4_esc_bit)
348
584
        {
349
584
            return IMPEG2D_PROF_LEVEL_NOT_SUPPORTED;
350
584
        }
351
17.6k
    }
352
353
17.0k
    ps_dec->u2_progressive_sequence = impeg2d_bit_stream_get_bit(ps_stream);
354
355
    /* Read the chrominance format */
356
17.0k
    if(impeg2d_bit_stream_get(ps_stream,2) != 0x1)
357
308
        return IMPEG2D_CHROMA_FMT_NOT_SUP;
358
359
    /* Error resilience: store the 2 most significant bit in horizontal and vertical   */
360
    /* variables.Use it only if adding them to the vertical and horizontal sizes       */
361
    /* respectively, doesn't exceed the MAX_WD and MAX_HT supported by the application.*/
362
363
364
    /* Read the 2 most significant bits from horizontal_size */
365
16.7k
    horizontal_value               = (impeg2d_bit_stream_get(ps_stream,2) << 12);
366
367
    /* Read the 2 most significant bits from vertical_size */
368
16.7k
    vertical_value                 = (impeg2d_bit_stream_get(ps_stream,2) << 12);
369
370
    /* Error resilience: The height and width should not be more than the*/
371
    /*max height and width the application can support*/
372
16.7k
    if(ps_dec->u2_create_max_height < (ps_dec->u2_vertical_size + vertical_value))
373
440
    {
374
440
        return (IMPEG2D_ERROR_CODES_T) IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
375
440
    }
376
377
16.2k
    if(ps_dec->u2_create_max_width < (ps_dec->u2_horizontal_size + horizontal_value))
378
255
    {
379
255
        return (IMPEG2D_ERROR_CODES_T) IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
380
255
    }
381
16.0k
    ps_dec->u2_vertical_size       += vertical_value;
382
16.0k
    ps_dec->u2_horizontal_size     += horizontal_value;
383
384
    /*-----------------------------------------------------------------------*/
385
    /* Flush the following as they are not used now                          */
386
    /* bit_rate_extension          12                                        */
387
    /* marker_bit                   1                                        */
388
    /* vbv_buffer_size_extension    8                                        */
389
    /* low_delay                    1                                        */
390
    /*-----------------------------------------------------------------------*/
391
16.0k
    impeg2d_bit_stream_flush(ps_stream,12);
392
16.0k
    GET_MARKER_BIT(ps_dec,ps_stream);
393
16.0k
    impeg2d_bit_stream_flush(ps_stream,9);
394
    /*-----------------------------------------------------------------------*/
395
    /* frame_rate_extension_n       2                                        */
396
    /* frame_rate_extension_d       5                                        */
397
    /*-----------------------------------------------------------------------*/
398
16.0k
    ps_dec->u2_frame_rate_extension_n = impeg2d_bit_stream_get(ps_stream,2);
399
16.0k
    ps_dec->u2_frame_rate_extension_d = impeg2d_bit_stream_get(ps_stream,5);
400
401
16.0k
    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
402
16.2k
}
403
404
/*******************************************************************************
405
*
406
*  Function Name   : impeg2d_dec_seq_disp_ext
407
*
408
*  Description     : This function is eqvt to sequence_display_extension() of
409
*                    standard. It flushes data present as it is not being used
410
*
411
*  Arguments       :
412
*  dec             : Decoder Context
413
*
414
*  Values Returned : None
415
******************************************************************************/
416
void impeg2d_dec_seq_disp_ext(dec_state_t *ps_dec)
417
99.8k
{
418
99.8k
    stream_t *ps_stream;
419
99.8k
    ps_stream = &ps_dec->s_bit_stream;
420
421
    /*
422
    sequence_display_extension()
423
    {
424
        extension_start_code_identifier 4
425
        video_format                    3
426
        colour_description              1
427
        if (colour_description)
428
        {
429
            colour_primaries            8
430
            transfer_characteristics    8
431
            matrix_coefficients         8
432
        }
433
        display_horizontal_size         14
434
        marker_bit                      1
435
        display_vertical_size           14
436
        next_start_code()
437
    }
438
    */
439
440
99.8k
    impeg2d_bit_stream_get(ps_stream, 4);
441
99.8k
    ps_dec->u1_video_format = impeg2d_bit_stream_get(ps_stream, 3);
442
99.8k
    ps_dec->u1_colour_description = impeg2d_bit_stream_get(ps_stream, 1);
443
99.8k
    ps_dec->u1_colour_primaries = 2;
444
99.8k
    ps_dec->u1_transfer_characteristics = 2;
445
99.8k
    ps_dec->u1_matrix_coefficients = 2;
446
99.8k
    if(ps_dec->u1_colour_description)
447
17.5k
    {
448
17.5k
        ps_dec->u1_colour_primaries = impeg2d_bit_stream_get(ps_stream, 8);
449
17.5k
        ps_dec->u1_transfer_characteristics = impeg2d_bit_stream_get(ps_stream, 8);
450
17.5k
        ps_dec->u1_matrix_coefficients = impeg2d_bit_stream_get(ps_stream, 8);
451
17.5k
    }
452
453
    /* display_horizontal_size and display_vertical_size */
454
99.8k
    ps_dec->u2_display_horizontal_size = impeg2d_bit_stream_get(ps_stream,14);;
455
99.8k
    GET_MARKER_BIT(ps_dec,ps_stream);
456
99.8k
    ps_dec->u2_display_vertical_size   = impeg2d_bit_stream_get(ps_stream,14);
457
458
99.8k
    ps_dec->u1_seq_disp_extn_present = 1;
459
99.8k
    impeg2d_next_start_code(ps_dec);
460
99.8k
}
461
462
463
/*******************************************************************************
464
*
465
*  Function Name   : impeg2d_dec_seq_scale_ext
466
*
467
*  Description     : This function is eqvt to sequence_scalable_extension() of
468
*                    standard.
469
*
470
*  Arguments       : Decoder context
471
*
472
*  Values Returned : None
473
*******************************************************************************/
474
IMPEG2D_ERROR_CODES_T impeg2d_dec_seq_scale_ext(dec_state_t *ps_dec)
475
0
{
476
0
    UNUSED(ps_dec);
477
0
    return IMPEG2D_SCALABILITIY_NOT_SUPPORTED;
478
0
}
479
480
/*******************************************************************************
481
*
482
*  Function Name   : impeg2d_dec_quant_matrix_ext
483
*
484
*  Description     : Gets Intra and NonIntra quantizer matrix from the stream.
485
*
486
*  Arguments       : Decoder context
487
*
488
*  Values Returned : None
489
*******************************************************************************/
490
void impeg2d_dec_quant_matrix_ext(dec_state_t *ps_dec)
491
27.5k
{
492
27.5k
    stream_t *ps_stream;
493
494
27.5k
    ps_stream = &ps_dec->s_bit_stream;
495
    /* Flush extension_start_code_identifier */
496
27.5k
    impeg2d_bit_stream_flush(ps_stream,4);
497
498
    /*------------------------------------------------------------------------*/
499
    /* Quantization matrix for the intra blocks                               */
500
    /*------------------------------------------------------------------------*/
501
27.5k
    if(impeg2d_bit_stream_get(ps_stream,1) == 1)
502
898
    {
503
898
        UWORD16 i;
504
58.3k
        for(i = 0; i < NUM_PELS_IN_BLOCK; i++)
505
57.4k
        {
506
57.4k
            ps_dec->au1_intra_quant_matrix[gau1_impeg2_inv_scan_zig_zag[i]] =  (UWORD8)impeg2d_bit_stream_get(ps_stream,8);
507
57.4k
        }
508
509
898
    }
510
511
512
    /*------------------------------------------------------------------------*/
513
    /* Quantization matrix for the inter blocks                               */
514
    /*------------------------------------------------------------------------*/
515
27.5k
    if(impeg2d_bit_stream_get(ps_stream,1) == 1)
516
734
    {
517
734
        UWORD16 i;
518
47.7k
        for(i = 0; i < NUM_PELS_IN_BLOCK; i++)
519
46.9k
        {
520
46.9k
            ps_dec->au1_inter_quant_matrix[gau1_impeg2_inv_scan_zig_zag[i]] =   (UWORD8)impeg2d_bit_stream_get(ps_stream,8);
521
46.9k
        }
522
734
    }
523
524
    /* Note : chroma intra quantizer matrix and chroma non
525
    intra quantizer matrix are not needed for 4:2:0 format */
526
27.5k
    impeg2d_next_start_code(ps_dec);
527
27.5k
}
528
/*******************************************************************************
529
*
530
*  Function Name   : impeg2d_dec_pic_disp_ext
531
*
532
*  Description     : This function is eqvt to picture_display_extension() of
533
*                    standard.The parameters are not used by decoder
534
*
535
*  Arguments       : Pointer to dec_state_t
536
*
537
*  Values Returned : Decoder context
538
*
539
*  Values Returned : None
540
*******************************************************************************/
541
void impeg2d_dec_pic_disp_ext(dec_state_t *ps_dec)
542
4.68k
{
543
4.68k
    WORD16 i2_number_of_frame_centre_offsets ;
544
4.68k
    stream_t *ps_stream;
545
546
4.68k
    ps_stream = &ps_dec->s_bit_stream;
547
4.68k
    impeg2d_bit_stream_flush(ps_stream,4);
548
549
4.68k
    if (ps_dec->u2_progressive_sequence)
550
1.09k
    {
551
1.09k
        i2_number_of_frame_centre_offsets = (ps_dec->u2_repeat_first_field) ?
552
736
            2 + ps_dec->u2_top_field_first : 1;
553
1.09k
    }
554
3.59k
    else
555
3.59k
    {
556
3.59k
        i2_number_of_frame_centre_offsets =
557
3.59k
            (ps_dec->u2_picture_structure != FRAME_PICTURE) ?
558
3.24k
            1 : 2 + ps_dec->u2_repeat_first_field;
559
3.59k
    }
560
13.2k
    while(i2_number_of_frame_centre_offsets--)
561
8.56k
    {
562
        /* frame_centre_horizontal_offset */
563
8.56k
        impeg2d_bit_stream_get(ps_stream,16);
564
8.56k
        GET_MARKER_BIT(ps_dec,ps_stream);
565
        /* frame_centre_vertical_offset */
566
8.56k
        impeg2d_bit_stream_get(ps_stream,16);
567
8.56k
        GET_MARKER_BIT(ps_dec,ps_stream);
568
8.56k
    }
569
4.68k
    impeg2d_next_start_code(ps_dec);
570
4.68k
}
571
572
/*******************************************************************************
573
*
574
*  Function Name   : impeg2d_dec_itu_t_ext
575
*
576
*  Description     : This function is eqvt to ITU-T_extension() of
577
*                    standard.The parameters are not used by decoder
578
*
579
*  Arguments       : Decoder context
580
*
581
*  Values Returned : None
582
*******************************************************************************/
583
void impeg2d_dec_itu_t_ext(dec_state_t *ps_dec)
584
51.6k
{
585
51.6k
  impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,EXT_ID_LEN);
586
51.6k
  impeg2d_next_start_code(ps_dec);
587
51.6k
}
588
589
/*******************************************************************************
590
*  Function Name   : impeg2d_dec_copyright_ext
591
*
592
*  Description     : This function is eqvt to copyright_extension() of
593
*                    standard. The parameters are not used by decoder
594
*
595
*  Arguments       : Decoder context
596
*
597
*  Values Returned : None
598
*******************************************************************************/
599
600
601
void impeg2d_dec_copyright_ext(dec_state_t *ps_dec)
602
1.64k
{
603
1.64k
    UWORD32 u4_bits_to_flush;
604
605
1.64k
    u4_bits_to_flush = COPYRIGHT_EXTENSION_LEN;
606
607
4.94k
    while(u4_bits_to_flush >= 32 )
608
3.29k
    {
609
3.29k
        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,32);
610
3.29k
        u4_bits_to_flush = u4_bits_to_flush - 32;
611
3.29k
    }
612
613
1.64k
    if(u4_bits_to_flush > 0)
614
1.64k
    {
615
1.64k
        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,u4_bits_to_flush);
616
1.64k
    }
617
618
619
1.64k
  impeg2d_next_start_code(ps_dec);
620
1.64k
}
621
/*******************************************************************************
622
*  Function Name   : impeg2d_dec_cam_param_ext
623
*
624
*  Description     : This function is eqvt to camera_parameters_extension() of
625
*                    standard. The parameters are not used by decoder
626
*
627
*  Arguments       : Decoder context
628
*
629
*  Values Returned : None
630
*******************************************************************************/
631
632
633
void impeg2d_dec_cam_param_ext(dec_state_t *ps_dec)
634
2.37k
{
635
636
2.37k
    UWORD32 u4_bits_to_flush;
637
638
2.37k
    u4_bits_to_flush = CAMERA_PARAMETER_EXTENSION_LEN;
639
640
28.5k
    while(u4_bits_to_flush >= 32 )
641
26.1k
    {
642
26.1k
        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,32);
643
26.1k
        u4_bits_to_flush = u4_bits_to_flush - 32;
644
26.1k
    }
645
646
2.37k
    if(u4_bits_to_flush > 0)
647
2.37k
    {
648
2.37k
        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,u4_bits_to_flush);
649
2.37k
    }
650
651
2.37k
  impeg2d_next_start_code(ps_dec);
652
2.37k
}
653
654
/*******************************************************************************
655
*
656
*  Function Name   : impeg2d_dec_grp_of_pic_hdr
657
*
658
*  Description     : Gets information at the GOP level.
659
*
660
*  Arguments       : Decoder context
661
*
662
*  Values Returned : None
663
*******************************************************************************/
664
665
666
void impeg2d_dec_grp_of_pic_hdr(dec_state_t *ps_dec)
667
775k
{
668
669
775k
    UWORD32 u4_bits_to_flush;
670
671
775k
    u4_bits_to_flush = GROUP_OF_PICTURE_LEN;
672
673
1.55M
    while(u4_bits_to_flush >= 32 )
674
775k
    {
675
775k
        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,32);
676
775k
        u4_bits_to_flush = u4_bits_to_flush - 32;
677
775k
    }
678
679
775k
    if(u4_bits_to_flush > 0)
680
775k
    {
681
775k
        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,u4_bits_to_flush);
682
775k
    }
683
684
775k
}
685
686
687
/*******************************************************************************
688
*
689
*  Function Name   : impeg2d_dec_pic_hdr
690
*
691
*  Description     : Gets the picture header information.
692
*
693
*  Arguments       : Decoder context
694
*
695
*  Values Returned : None
696
*******************************************************************************/
697
IMPEG2D_ERROR_CODES_T impeg2d_dec_pic_hdr(dec_state_t *ps_dec)
698
36.5k
{
699
36.5k
    stream_t *ps_stream;
700
36.5k
    ps_stream = &ps_dec->s_bit_stream;
701
702
36.5k
    impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
703
    /* Flush temporal reference */
704
36.5k
    impeg2d_bit_stream_get(ps_stream,10);
705
706
    /* Picture type */
707
36.5k
    ps_dec->e_pic_type = (e_pic_type_t)impeg2d_bit_stream_get(ps_stream,3);
708
36.5k
    if((ps_dec->e_pic_type < I_PIC) || (ps_dec->e_pic_type > D_PIC))
709
3.21k
    {
710
3.21k
        impeg2d_next_code(ps_dec, PICTURE_START_CODE);
711
3.21k
        return IMPEG2D_INVALID_PIC_TYPE;
712
3.21k
    }
713
714
    /* Flush vbv_delay */
715
33.3k
    impeg2d_bit_stream_get(ps_stream,16);
716
717
33.3k
    if(ps_dec->e_pic_type == P_PIC || ps_dec->e_pic_type == B_PIC)
718
14.2k
    {
719
14.2k
        ps_dec->u2_full_pel_forw_vector = impeg2d_bit_stream_get_bit(ps_stream);
720
14.2k
        ps_dec->u2_forw_f_code          = impeg2d_bit_stream_get(ps_stream,3);
721
14.2k
    }
722
33.3k
    if(ps_dec->e_pic_type == B_PIC)
723
7.71k
    {
724
7.71k
        ps_dec->u2_full_pel_back_vector = impeg2d_bit_stream_get_bit(ps_stream);
725
7.71k
        ps_dec->u2_back_f_code          = impeg2d_bit_stream_get(ps_stream,3);
726
7.71k
    }
727
728
33.3k
    if(ps_dec->u2_is_mpeg2 == 0)
729
17.7k
    {
730
17.7k
        if (ps_dec->u2_forw_f_code < 1 || ps_dec->u2_forw_f_code > 7 ||
731
16.9k
                        ps_dec->u2_back_f_code < 1 || ps_dec->u2_back_f_code > 7)
732
1.38k
        {
733
1.38k
            return IMPEG2D_UNKNOWN_ERROR;
734
1.38k
        }
735
16.3k
        ps_dec->au2_f_code[0][0] = ps_dec->au2_f_code[0][1] = ps_dec->u2_forw_f_code;
736
16.3k
        ps_dec->au2_f_code[1][0] = ps_dec->au2_f_code[1][1] = ps_dec->u2_back_f_code;
737
16.3k
    }
738
739
    /*-----------------------------------------------------------------------*/
740
    /*  Flush the extra bit value                                            */
741
    /*                                                                       */
742
    /*  while(impeg2d_bit_stream_nxt() == '1')                                  */
743
    /*  {                                                                    */
744
    /*      extra_bit_picture         1                                      */
745
    /*      extra_information_picture 8                                      */
746
    /*  }                                                                    */
747
    /*  extra_bit_picture             1                                      */
748
    /*-----------------------------------------------------------------------*/
749
40.4k
    while (impeg2d_bit_stream_nxt(ps_stream,1) == 1 &&
750
8.72k
           ps_stream->u4_offset < ps_stream->u4_max_offset)
751
8.46k
    {
752
8.46k
        impeg2d_bit_stream_get(ps_stream,9);
753
8.46k
    }
754
31.9k
    impeg2d_bit_stream_get_bit(ps_stream);
755
31.9k
    impeg2d_next_start_code(ps_dec);
756
757
31.9k
    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
758
33.3k
}
759
760
761
/*******************************************************************************
762
*
763
*  Function Name   : impeg2d_dec_pic_coding_ext
764
*
765
*  Description     : Reads more picture level parameters
766
*
767
*  Arguments       :
768
*  dec             : Decoder context
769
*
770
*  Values Returned : Error
771
*******************************************************************************/
772
IMPEG2D_ERROR_CODES_T impeg2d_dec_pic_coding_ext(dec_state_t *ps_dec)
773
15.6k
{
774
775
15.6k
    UWORD32 u4_val;
776
15.6k
    stream_t *ps_stream;
777
15.6k
    IMPEG2D_ERROR_CODES_T e_error = (IMPEG2D_ERROR_CODES_T) IV_SUCCESS;
778
779
15.6k
    ps_stream = &ps_dec->s_bit_stream;
780
15.6k
    impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
781
    /* extension code identifier */
782
15.6k
    impeg2d_bit_stream_get(ps_stream,4);
783
784
15.6k
    u4_val = impeg2d_bit_stream_get(ps_stream,4);
785
15.6k
    if(u4_val == 0)
786
1.45k
        return IMPEG2D_UNKNOWN_ERROR;
787
14.1k
    ps_dec->au2_f_code[0][0]             = u4_val;
788
789
14.1k
    u4_val = impeg2d_bit_stream_get(ps_stream,4);
790
14.1k
    if(u4_val == 0)
791
814
        return IMPEG2D_UNKNOWN_ERROR;
792
13.3k
    ps_dec->au2_f_code[0][1]             = u4_val;
793
794
13.3k
    u4_val = impeg2d_bit_stream_get(ps_stream,4);
795
13.3k
    if(u4_val == 0)
796
293
        return IMPEG2D_UNKNOWN_ERROR;
797
13.0k
    ps_dec->au2_f_code[1][0]             = u4_val;
798
799
13.0k
    u4_val = impeg2d_bit_stream_get(ps_stream,4);
800
13.0k
    if(u4_val == 0)
801
482
        return IMPEG2D_UNKNOWN_ERROR;
802
12.5k
    ps_dec->au2_f_code[1][1]             = u4_val;
803
804
12.5k
    ps_dec->u2_intra_dc_precision        = impeg2d_bit_stream_get(ps_stream,2);
805
12.5k
    ps_dec->u2_picture_structure            = impeg2d_bit_stream_get(ps_stream,2);
806
12.5k
    if (ps_dec->u2_picture_structure < TOP_FIELD ||
807
12.2k
                    ps_dec->u2_picture_structure > FRAME_PICTURE)
808
334
    {
809
334
        return IMPEG2D_FRM_HDR_DECODE_ERR;
810
334
    }
811
12.2k
    ps_dec->u2_top_field_first              = impeg2d_bit_stream_get_bit(ps_stream);
812
12.2k
    ps_dec->u2_frame_pred_frame_dct         = impeg2d_bit_stream_get_bit(ps_stream);
813
12.2k
    ps_dec->u2_concealment_motion_vectors   = impeg2d_bit_stream_get_bit(ps_stream);
814
12.2k
    ps_dec->u2_q_scale_type                 = impeg2d_bit_stream_get_bit(ps_stream);
815
12.2k
    ps_dec->u2_intra_vlc_format             = impeg2d_bit_stream_get_bit(ps_stream);
816
12.2k
    ps_dec->u2_alternate_scan               = impeg2d_bit_stream_get_bit(ps_stream);
817
12.2k
    ps_dec->u2_repeat_first_field           = impeg2d_bit_stream_get_bit(ps_stream);
818
    /* Flush chroma_420_type */
819
12.2k
    impeg2d_bit_stream_get_bit(ps_stream);
820
821
12.2k
    ps_dec->u2_progressive_frame            = impeg2d_bit_stream_get_bit(ps_stream);
822
12.2k
    if (impeg2d_bit_stream_get_bit(ps_stream))
823
794
    {
824
        /* Flush v_axis, field_sequence, burst_amplitude, sub_carrier_phase */
825
794
        impeg2d_bit_stream_flush(ps_stream,20);
826
794
    }
827
12.2k
    impeg2d_next_start_code(ps_dec);
828
829
830
12.2k
    if(VERTICAL_SCAN == ps_dec->u2_alternate_scan)
831
6.89k
    {
832
6.89k
        ps_dec->pu1_inv_scan_matrix = (UWORD8 *)gau1_impeg2_inv_scan_vertical;
833
6.89k
    }
834
5.35k
    else
835
5.35k
    {
836
5.35k
        ps_dec->pu1_inv_scan_matrix = (UWORD8 *)gau1_impeg2_inv_scan_zig_zag;
837
5.35k
    }
838
12.2k
    return e_error;
839
12.5k
}
840
841
/*******************************************************************************
842
*
843
*  Function Name   : impeg2d_dec_slice
844
*
845
*  Description     : Reads Slice level parameters and calls functions that
846
*                    decode individual MBs of slice
847
*
848
*  Arguments       :
849
*  dec             : Decoder context
850
*
851
*  Values Returned : None
852
*******************************************************************************/
853
IMPEG2D_ERROR_CODES_T impeg2d_dec_slice(dec_state_t *ps_dec)
854
1.95M
{
855
1.95M
    stream_t *ps_stream;
856
1.95M
    UWORD32 u4_slice_vertical_position;
857
1.95M
    UWORD32 u4_slice_vertical_position_extension;
858
1.95M
    IMPEG2D_ERROR_CODES_T e_error;
859
860
1.95M
    ps_stream = &ps_dec->s_bit_stream;
861
862
    /*------------------------------------------------------------------------*/
863
    /* All the profiles supported require restricted slice structure. Hence   */
864
    /* there is no need to store slice_vertical_position. Note that max       */
865
    /* height supported does not exceed 2800 and scalablity is not supported  */
866
    /*------------------------------------------------------------------------*/
867
868
    /* Remove the slice start code */
869
1.95M
    impeg2d_bit_stream_flush(ps_stream,START_CODE_PREFIX_LEN);
870
1.95M
    u4_slice_vertical_position = impeg2d_bit_stream_get(ps_stream, 8);
871
1.95M
    if(u4_slice_vertical_position > 2800)
872
0
    {
873
0
        u4_slice_vertical_position_extension = impeg2d_bit_stream_get(ps_stream, 3);
874
0
        u4_slice_vertical_position += (u4_slice_vertical_position_extension << 7);
875
0
    }
876
877
1.95M
    if((u4_slice_vertical_position > ps_dec->u2_num_vert_mb) ||
878
1.95M
       (u4_slice_vertical_position == 0))
879
7.90k
    {
880
7.90k
        return IMPEG2D_INVALID_VERT_SIZE;
881
7.90k
    }
882
883
    // change the mb_y to point to slice_vertical_position
884
1.95M
    u4_slice_vertical_position--;
885
1.95M
    if (ps_dec->u2_mb_y != u4_slice_vertical_position)
886
260k
    {
887
260k
        ps_dec->u2_mb_y    = u4_slice_vertical_position;
888
260k
        ps_dec->u2_mb_x    = 0;
889
890
        /* Update the number of MBs left, since we have probably missed a slice
891
         * (that's why we see a mismatch between u2_mb_y and current position).
892
         */
893
260k
        ps_dec->u2_num_mbs_left = (ps_dec->u2_num_vert_mb - ps_dec->u2_mb_y)
894
260k
                        * ps_dec->u2_num_horiz_mb;
895
260k
    }
896
1.95M
    ps_dec->u2_first_mb = 1;
897
898
    /*------------------------------------------------------------------------*/
899
    /* Quant scale code decoding                                              */
900
    /*------------------------------------------------------------------------*/
901
1.95M
    {
902
1.95M
        UWORD16 u2_quant_scale_code;
903
1.95M
        u2_quant_scale_code = impeg2d_bit_stream_get(ps_stream,5);
904
1.95M
        ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ?
905
1.94M
            gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1);
906
1.95M
    }
907
908
1.95M
    if (impeg2d_bit_stream_nxt(ps_stream,1) == 1)
909
1.59M
    {
910
1.59M
        impeg2d_bit_stream_flush(ps_stream,9);
911
        /* Flush extra bit information */
912
3.40M
        while (impeg2d_bit_stream_nxt(ps_stream,1) == 1 &&
913
1.80M
               ps_stream->u4_offset < ps_stream->u4_max_offset)
914
1.80M
        {
915
1.80M
            impeg2d_bit_stream_flush(ps_stream,9);
916
1.80M
        }
917
1.59M
    }
918
1.95M
    impeg2d_bit_stream_get_bit(ps_stream);
919
920
    /* Reset the DC predictors to reset values given in Table 7.2 at the start*/
921
    /* of slice data */
922
1.95M
    ps_dec->u2_def_dc_pred[Y_LUMA]   = 128 << ps_dec->u2_intra_dc_precision;
923
1.95M
    ps_dec->u2_def_dc_pred[U_CHROMA]   = 128 << ps_dec->u2_intra_dc_precision;
924
1.95M
    ps_dec->u2_def_dc_pred[V_CHROMA]   = 128 << ps_dec->u2_intra_dc_precision;
925
    /*------------------------------------------------------------------------*/
926
    /* dec->DecMBsinSlice() implements the following psuedo code from standard*/
927
    /* do                                                                     */
928
    /* {                                                                      */
929
    /*      macroblock()                                                      */
930
    /* } while (impeg2d_bit_stream_nxt() != '000 0000 0000 0000 0000 0000')      */
931
    /*------------------------------------------------------------------------*/
932
933
1.95M
    e_error = ps_dec->pf_decode_slice(ps_dec);
934
1.95M
    if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
935
23.7k
    {
936
23.7k
        return e_error;
937
23.7k
    }
938
939
    /* Check for the MBy index instead of number of MBs left, because the
940
     * number of MBs left in case of multi-thread decode is the number of MBs
941
     * in that row only
942
     */
943
1.92M
    if(ps_dec->u2_mb_y < ps_dec->u2_num_vert_mb)
944
1.92M
        impeg2d_next_start_code(ps_dec);
945
946
1.92M
    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
947
1.95M
}
948
949
void impeg2d_dec_pic_data_thread(dec_state_t *ps_dec)
950
39.4k
{
951
39.4k
    WORD32 i4_continue_decode;
952
953
39.4k
    WORD32 i4_cur_row, temp;
954
39.4k
    UWORD32 u4_bits_read;
955
39.4k
    WORD32 i4_dequeue_job;
956
39.4k
    IMPEG2D_ERROR_CODES_T e_error;
957
958
39.4k
    UWORD32 id = ps_dec->currThreadId;
959
39.4k
    dec_state_multi_core_t *ps_dec_state_multi_core = ps_dec->ps_dec_state_multi_core;
960
961
96.6k
    while (1)
962
96.6k
    {
963
96.6k
        if(ps_dec->i4_threads_active)
964
96.6k
        {
965
96.6k
            if(id != 0)
966
69.2k
            {
967
69.2k
                e_error = ithread_mutex_lock(ps_dec->pv_proc_start_mutex);
968
69.2k
                if((IMPEG2D_ERROR_CODES_T)IV_SUCCESS != e_error)
969
0
                    break;
970
971
126k
                while(!ps_dec->ai4_process_start)
972
57.1k
                {
973
57.1k
                    ithread_cond_wait(ps_dec->pv_proc_start_condition,
974
57.1k
                                      ps_dec->pv_proc_start_mutex);
975
57.1k
                }
976
69.2k
                ps_dec->ai4_process_start = 0;
977
69.2k
                e_error = ithread_mutex_unlock(ps_dec->pv_proc_start_mutex);
978
69.2k
                if((IMPEG2D_ERROR_CODES_T)IV_SUCCESS != e_error)
979
0
                    break;
980
                // break off at the end of decoding all the frames
981
69.2k
                if(ps_dec_state_multi_core->i4_break_threads)
982
12.0k
                    break;
983
69.2k
            }
984
96.6k
        }
985
84.5k
        i4_cur_row = ps_dec->u2_mb_y + 1;
986
987
84.5k
        i4_continue_decode = 1;
988
989
84.5k
        i4_dequeue_job = 1;
990
84.5k
        do
991
2.00M
        {
992
2.00M
            if(i4_cur_row > ps_dec->u2_num_vert_mb)
993
0
            {
994
0
                i4_continue_decode = 0;
995
0
                break;
996
0
            }
997
998
2.00M
            if((ps_dec->i4_num_cores> 1) && (i4_dequeue_job))
999
87.2k
            {
1000
87.2k
                job_t s_job;
1001
87.2k
                IV_API_CALL_STATUS_T e_ret;
1002
87.2k
                UWORD8 *pu1_buf;
1003
1004
87.2k
                e_ret = impeg2_jobq_dequeue(ps_dec->pv_jobq, &s_job, sizeof(s_job), 1, 1);
1005
87.2k
                if(e_ret != IV_SUCCESS)
1006
23.6k
                    break;
1007
1008
63.6k
                if(CMD_PROCESS == s_job.i4_cmd)
1009
38.5k
                {
1010
38.5k
                    pu1_buf = ps_dec->pu1_inp_bits_buf + s_job.i4_bistream_ofst;
1011
38.5k
                    impeg2d_bit_stream_init(&(ps_dec->s_bit_stream), pu1_buf,
1012
38.5k
                            (ps_dec->u4_num_inp_bytes - s_job.i4_bistream_ofst));
1013
38.5k
                    i4_cur_row      = s_job.i2_start_mb_y;
1014
38.5k
                    ps_dec->i4_start_mb_y = s_job.i2_start_mb_y;
1015
38.5k
                    ps_dec->i4_end_mb_y = s_job.i2_end_mb_y;
1016
38.5k
                    ps_dec->u2_mb_x = 0;
1017
38.5k
                    ps_dec->u2_mb_y = ps_dec->i4_start_mb_y;
1018
38.5k
                    ps_dec->u2_num_mbs_left = (ps_dec->i4_end_mb_y - ps_dec->i4_start_mb_y) * ps_dec->u2_num_horiz_mb;
1019
1020
38.5k
                }
1021
25.1k
                else
1022
25.1k
                {
1023
25.1k
                    WORD32 start_row;
1024
25.1k
                    WORD32 num_rows;
1025
25.1k
                    start_row = s_job.i2_start_mb_y << 4;
1026
25.1k
                    num_rows = MIN((s_job.i2_end_mb_y << 4), ps_dec->u2_vertical_size);
1027
25.1k
                    num_rows -= start_row;
1028
1029
25.1k
                    if(ps_dec->u4_deinterlace && (0 == ps_dec->u2_progressive_frame))
1030
7.50k
                    {
1031
7.50k
                        impeg2d_deinterlace(ps_dec,
1032
7.50k
                                            ps_dec->ps_disp_pic,
1033
7.50k
                                            ps_dec->ps_disp_frm_buf,
1034
7.50k
                                            start_row,
1035
7.50k
                                            num_rows);
1036
1037
7.50k
                    }
1038
17.6k
                    else
1039
17.6k
                    {
1040
17.6k
                        impeg2d_format_convert(ps_dec, ps_dec->ps_disp_pic,
1041
17.6k
                                               ps_dec->ps_disp_frm_buf,
1042
17.6k
                                               start_row, num_rows);
1043
17.6k
                    }
1044
25.1k
                    break;
1045
1046
25.1k
                }
1047
1048
63.6k
            }
1049
1.95M
            e_error = impeg2d_dec_slice(ps_dec);
1050
1051
1.95M
            if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
1052
31.6k
            {
1053
31.6k
                ps_dec->u2_num_mbs_left = 0;
1054
31.6k
                break;
1055
31.6k
            }
1056
1057
            /* Detecting next slice start code */
1058
1.92M
            while(1)
1059
1.92M
            {
1060
                // skip (dec->u4_num_cores-1) rows
1061
1.92M
                u4_bits_read = impeg2d_bit_stream_nxt(&ps_dec->s_bit_stream,START_CODE_LEN);
1062
1.92M
                temp = u4_bits_read & 0xFF;
1063
1.92M
                i4_continue_decode = (((u4_bits_read >> 8) == 0x01) && (temp) && (temp <= 0xAF));
1064
1065
1.92M
                if (1 == ps_dec->i4_num_cores && 0 == ps_dec->u2_num_mbs_left)
1066
175
                {
1067
175
                    i4_continue_decode = 0;
1068
#ifdef __ANDROID__
1069
                    android_errorWriteLog(0x534e4554, "26070014");
1070
#endif
1071
175
                }
1072
1073
1.92M
                if(i4_continue_decode)
1074
1.92M
                {
1075
1.92M
                    if (0 != ps_dec->u2_num_mbs_left)
1076
1.92M
                    {
1077
                        /* If the slice is from the same row, then continue decoding without dequeue */
1078
1.92M
                        if((temp - 1) == i4_cur_row)
1079
1.88M
                        {
1080
1.88M
                            i4_dequeue_job = 0;
1081
1.88M
                        }
1082
36.7k
                        else
1083
36.7k
                        {
1084
36.7k
                            if(temp < ps_dec->i4_end_mb_y)
1085
35.4k
                            {
1086
35.4k
                                i4_cur_row = ps_dec->u2_mb_y;
1087
35.4k
                            }
1088
1.37k
                            else
1089
1.37k
                            {
1090
1.37k
                                i4_dequeue_job = 1;
1091
1.37k
                            }
1092
36.7k
                        }
1093
1.92M
                    }
1094
1.89k
                    else
1095
1.89k
                    {
1096
1.89k
                        i4_dequeue_job = 1;
1097
1.89k
                    }
1098
1.92M
                    break;
1099
1.92M
                }
1100
4.21k
                else
1101
4.21k
                    break;
1102
1.92M
            }
1103
1104
1.92M
        }while(i4_continue_decode);
1105
84.5k
        if(ps_dec->i4_num_cores > 1)
1106
83.3k
        {
1107
358k
            while(1)
1108
358k
            {
1109
358k
                job_t s_job;
1110
358k
                IV_API_CALL_STATUS_T e_ret;
1111
1112
358k
                e_ret = impeg2_jobq_dequeue(ps_dec->pv_jobq, &s_job, sizeof(s_job), 1, 1);
1113
358k
                if(e_ret != IV_SUCCESS)
1114
83.3k
                    break;
1115
275k
                if(CMD_FMTCONV == s_job.i4_cmd)
1116
273k
                {
1117
273k
                    WORD32 start_row;
1118
273k
                    WORD32 num_rows;
1119
273k
                    start_row = s_job.i2_start_mb_y << 4;
1120
273k
                    num_rows = MIN((s_job.i2_end_mb_y << 4), ps_dec->u2_vertical_size);
1121
273k
                    num_rows -= start_row;
1122
273k
                    if(ps_dec->u4_deinterlace && (0 == ps_dec->u2_progressive_frame))
1123
104k
                    {
1124
104k
                        impeg2d_deinterlace(ps_dec,
1125
104k
                                            ps_dec->ps_disp_pic,
1126
104k
                                            ps_dec->ps_disp_frm_buf,
1127
104k
                                            start_row,
1128
104k
                                            num_rows);
1129
1130
104k
                    }
1131
169k
                    else
1132
169k
                    {
1133
169k
                        impeg2d_format_convert(ps_dec,
1134
169k
                                               ps_dec->ps_disp_pic,
1135
169k
                                               ps_dec->ps_disp_frm_buf,
1136
169k
                                               start_row,
1137
169k
                                               num_rows);
1138
169k
                    }
1139
273k
                }
1140
275k
            }
1141
83.3k
        }
1142
1.25k
        else
1143
1.25k
        {
1144
1.25k
            if((NULL != ps_dec->ps_disp_pic) && ((0 == ps_dec->u4_share_disp_buf) || (IV_YUV_420P != ps_dec->i4_chromaFormat)))
1145
578
            {
1146
578
                if(ps_dec->u4_deinterlace && (0 == ps_dec->u2_progressive_frame))
1147
209
                {
1148
209
                    impeg2d_deinterlace(ps_dec,
1149
209
                                        ps_dec->ps_disp_pic,
1150
209
                                        ps_dec->ps_disp_frm_buf,
1151
209
                                        0,
1152
209
                                        ps_dec->u2_vertical_size);
1153
1154
209
                }
1155
369
                else
1156
369
                {
1157
369
                    impeg2d_format_convert(ps_dec, ps_dec->ps_disp_pic,
1158
369
                                            ps_dec->ps_disp_frm_buf,
1159
369
                                            0, ps_dec->u2_vertical_size);
1160
369
                }
1161
578
            }
1162
1.25k
        }
1163
84.5k
        if(ps_dec->i4_threads_active)
1164
84.6k
        {
1165
84.6k
            if(id != 0)
1166
57.1k
            {
1167
57.1k
                e_error = ithread_mutex_lock(ps_dec->pv_proc_done_mutex);
1168
57.1k
                if((IMPEG2D_ERROR_CODES_T)IV_SUCCESS != e_error)
1169
0
                    break;
1170
1171
57.1k
                ps_dec->ai4_process_done = 1;
1172
57.1k
                ithread_cond_signal(ps_dec->pv_proc_done_condition);
1173
1174
57.1k
                e_error = ithread_mutex_unlock(ps_dec->pv_proc_done_mutex);
1175
57.1k
                if((IMPEG2D_ERROR_CODES_T)IV_SUCCESS != e_error)
1176
0
                    break;
1177
57.1k
            }
1178
27.4k
            else
1179
27.4k
            {
1180
27.4k
                break;
1181
27.4k
            }
1182
84.6k
        }
1183
18.4E
        else
1184
18.4E
        {
1185
18.4E
            break;
1186
18.4E
        }
1187
84.5k
    }
1188
39.4k
}
1189
1190
static WORD32 impeg2d_init_thread_dec_ctxt(dec_state_t *ps_dec,
1191
                                           dec_state_t *ps_dec_thd,
1192
                                           WORD32 i4_min_mb_y)
1193
57.1k
{
1194
57.1k
    UNUSED(i4_min_mb_y);
1195
57.1k
    ps_dec_thd->i4_start_mb_y = 0;
1196
57.1k
    ps_dec_thd->i4_end_mb_y = ps_dec->u2_num_vert_mb;
1197
57.1k
    ps_dec_thd->u2_mb_x = 0;
1198
57.1k
    ps_dec_thd->u2_mb_y = 0;
1199
57.1k
    ps_dec_thd->u2_is_mpeg2 = ps_dec->u2_is_mpeg2;
1200
57.1k
    ps_dec_thd->i4_pic_count = ps_dec->i4_pic_count;
1201
57.1k
    ps_dec_thd->u2_frame_width = ps_dec->u2_frame_width;
1202
57.1k
    ps_dec_thd->u2_frame_height = ps_dec->u2_frame_height;
1203
57.1k
    ps_dec_thd->u2_picture_width = ps_dec->u2_picture_width;
1204
57.1k
    ps_dec_thd->u2_horizontal_size = ps_dec->u2_horizontal_size;
1205
57.1k
    ps_dec_thd->u2_vertical_size = ps_dec->u2_vertical_size;
1206
57.1k
    ps_dec_thd->u2_create_max_width = ps_dec->u2_create_max_width;
1207
57.1k
    ps_dec_thd->u2_create_max_height = ps_dec->u2_create_max_height;
1208
57.1k
    ps_dec_thd->u2_header_done = ps_dec->u2_header_done;
1209
57.1k
    ps_dec_thd->u2_decode_header = ps_dec->u2_decode_header;
1210
1211
57.1k
    ps_dec_thd->u2_num_horiz_mb = ps_dec->u2_num_horiz_mb;
1212
57.1k
    ps_dec_thd->u2_num_vert_mb = ps_dec->u2_num_vert_mb;
1213
57.1k
    ps_dec_thd->u2_num_flds_decoded = ps_dec->u2_num_flds_decoded;
1214
1215
57.1k
    ps_dec_thd->u4_frm_buf_stride = ps_dec->u4_frm_buf_stride;
1216
1217
57.1k
    ps_dec_thd->u2_field_dct = ps_dec->u2_field_dct;
1218
57.1k
    ps_dec_thd->u2_read_dct_type = ps_dec->u2_read_dct_type;
1219
1220
57.1k
    ps_dec_thd->u2_read_motion_type = ps_dec->u2_read_motion_type;
1221
57.1k
    ps_dec_thd->u2_motion_type = ps_dec->u2_motion_type;
1222
1223
57.1k
    ps_dec_thd->pu2_mb_type = ps_dec->pu2_mb_type;
1224
57.1k
    ps_dec_thd->u2_fld_pic = ps_dec->u2_fld_pic;
1225
57.1k
    ps_dec_thd->u2_frm_pic = ps_dec->u2_frm_pic;
1226
1227
57.1k
    ps_dec_thd->u2_fld_parity = ps_dec->u2_fld_parity;
1228
1229
57.1k
    ps_dec_thd->au2_fcode_data[0] = ps_dec->au2_fcode_data[0];
1230
57.1k
    ps_dec_thd->au2_fcode_data[1] = ps_dec->au2_fcode_data[1];
1231
1232
57.1k
    ps_dec_thd->u1_quant_scale = ps_dec->u1_quant_scale;
1233
1234
57.1k
    ps_dec_thd->u2_num_mbs_left = ps_dec->u2_num_mbs_left;
1235
57.1k
    ps_dec_thd->u2_first_mb = ps_dec->u2_first_mb;
1236
57.1k
    ps_dec_thd->u2_num_skipped_mbs = ps_dec->u2_num_skipped_mbs;
1237
1238
57.1k
    memcpy(&ps_dec_thd->s_cur_frm_buf, &ps_dec->s_cur_frm_buf, sizeof(yuv_buf_t));
1239
57.1k
    memcpy(&ps_dec_thd->as_recent_fld[0][0], &ps_dec->as_recent_fld[0][0], sizeof(yuv_buf_t));
1240
57.1k
    memcpy(&ps_dec_thd->as_recent_fld[0][1], &ps_dec->as_recent_fld[0][1], sizeof(yuv_buf_t));
1241
57.1k
    memcpy(&ps_dec_thd->as_recent_fld[1][0], &ps_dec->as_recent_fld[1][0], sizeof(yuv_buf_t));
1242
57.1k
    memcpy(&ps_dec_thd->as_recent_fld[1][1], &ps_dec->as_recent_fld[1][1], sizeof(yuv_buf_t));
1243
57.1k
    memcpy(&ps_dec_thd->as_ref_buf, &ps_dec->as_ref_buf, sizeof(yuv_buf_t) * 2 * 2);
1244
1245
1246
57.1k
    ps_dec_thd->pf_decode_slice = ps_dec->pf_decode_slice;
1247
1248
57.1k
    ps_dec_thd->pf_vld_inv_quant = ps_dec->pf_vld_inv_quant;
1249
1250
57.1k
    memcpy(ps_dec_thd->pf_idct_recon, ps_dec->pf_idct_recon, sizeof(ps_dec->pf_idct_recon));
1251
1252
57.1k
    memcpy(ps_dec_thd->pf_mc, ps_dec->pf_mc, sizeof(ps_dec->pf_mc));
1253
57.1k
    ps_dec_thd->pf_interpolate = ps_dec->pf_interpolate;
1254
57.1k
    ps_dec_thd->pf_copy_mb = ps_dec->pf_copy_mb;
1255
57.1k
    ps_dec_thd->pf_fullx_halfy_8x8              =  ps_dec->pf_fullx_halfy_8x8;
1256
57.1k
    ps_dec_thd->pf_halfx_fully_8x8              =  ps_dec->pf_halfx_fully_8x8;
1257
57.1k
    ps_dec_thd->pf_halfx_halfy_8x8              =  ps_dec->pf_halfx_halfy_8x8;
1258
57.1k
    ps_dec_thd->pf_fullx_fully_8x8              =  ps_dec->pf_fullx_fully_8x8;
1259
1260
57.1k
    ps_dec_thd->pf_memset_8bit_8x8_block        =  ps_dec->pf_memset_8bit_8x8_block;
1261
57.1k
    ps_dec_thd->pf_memset_16bit_8x8_linear_block        =  ps_dec->pf_memset_16bit_8x8_linear_block;
1262
57.1k
    ps_dec_thd->pf_copy_yuv420p_buf             =   ps_dec->pf_copy_yuv420p_buf;
1263
57.1k
    ps_dec_thd->pf_fmt_conv_yuv420p_to_yuv422ile    =   ps_dec->pf_fmt_conv_yuv420p_to_yuv422ile;
1264
57.1k
    ps_dec_thd->pf_fmt_conv_yuv420p_to_yuv420sp_uv  =   ps_dec->pf_fmt_conv_yuv420p_to_yuv420sp_uv;
1265
57.1k
    ps_dec_thd->pf_fmt_conv_yuv420p_to_yuv420sp_vu  =   ps_dec->pf_fmt_conv_yuv420p_to_yuv420sp_vu;
1266
1267
1268
57.1k
    memcpy(ps_dec_thd->au1_intra_quant_matrix, ps_dec->au1_intra_quant_matrix, NUM_PELS_IN_BLOCK * sizeof(UWORD8));
1269
57.1k
    memcpy(ps_dec_thd->au1_inter_quant_matrix, ps_dec->au1_inter_quant_matrix, NUM_PELS_IN_BLOCK * sizeof(UWORD8));
1270
57.1k
    ps_dec_thd->pu1_inv_scan_matrix = ps_dec->pu1_inv_scan_matrix;
1271
1272
1273
57.1k
    ps_dec_thd->u2_progressive_sequence = ps_dec->u2_progressive_sequence;
1274
57.1k
    ps_dec_thd->e_pic_type =  ps_dec->e_pic_type;
1275
57.1k
    ps_dec_thd->u2_full_pel_forw_vector = ps_dec->u2_full_pel_forw_vector;
1276
57.1k
    ps_dec_thd->u2_forw_f_code =   ps_dec->u2_forw_f_code;
1277
57.1k
    ps_dec_thd->u2_full_pel_back_vector = ps_dec->u2_full_pel_back_vector;
1278
57.1k
    ps_dec_thd->u2_back_f_code = ps_dec->u2_back_f_code;
1279
1280
57.1k
    memcpy(ps_dec_thd->ai2_mv, ps_dec->ai2_mv, (2*2*2)*sizeof(WORD16));
1281
57.1k
    memcpy(ps_dec_thd->au2_f_code, ps_dec->au2_f_code, (2*2)*sizeof(UWORD16));
1282
57.1k
    ps_dec_thd->u2_intra_dc_precision = ps_dec->u2_intra_dc_precision;
1283
57.1k
    ps_dec_thd->u2_picture_structure = ps_dec->u2_picture_structure;
1284
57.1k
    ps_dec_thd->u2_top_field_first = ps_dec->u2_top_field_first;
1285
57.1k
    ps_dec_thd->u2_frame_pred_frame_dct = ps_dec->u2_frame_pred_frame_dct;
1286
57.1k
    ps_dec_thd->u2_concealment_motion_vectors = ps_dec->u2_concealment_motion_vectors;
1287
57.1k
    ps_dec_thd->u2_q_scale_type =  ps_dec->u2_q_scale_type;
1288
57.1k
    ps_dec_thd->u2_intra_vlc_format = ps_dec->u2_intra_vlc_format;
1289
57.1k
    ps_dec_thd->u2_alternate_scan = ps_dec->u2_alternate_scan;
1290
57.1k
    ps_dec_thd->u2_repeat_first_field = ps_dec->u2_repeat_first_field;
1291
57.1k
    ps_dec_thd->u2_progressive_frame = ps_dec->u2_progressive_frame;
1292
57.1k
    ps_dec_thd->pu1_inp_bits_buf = ps_dec->pu1_inp_bits_buf;
1293
57.1k
    ps_dec_thd->u4_num_inp_bytes = ps_dec->u4_num_inp_bytes;
1294
57.1k
    ps_dec_thd->pv_jobq = ps_dec->pv_jobq;
1295
57.1k
    ps_dec_thd->pv_jobq_buf = ps_dec->pv_jobq_buf;
1296
57.1k
    ps_dec_thd->i4_jobq_buf_size = ps_dec->i4_jobq_buf_size;
1297
1298
1299
57.1k
    ps_dec_thd->u2_frame_rate_code = ps_dec->u2_frame_rate_code;
1300
57.1k
    ps_dec_thd->u2_frame_rate_extension_n = ps_dec->u2_frame_rate_extension_n;
1301
57.1k
    ps_dec_thd->u2_frame_rate_extension_d = ps_dec->u2_frame_rate_extension_d;
1302
57.1k
    ps_dec_thd->u2_framePeriod =   ps_dec->u2_framePeriod;
1303
57.1k
    ps_dec_thd->u2_display_horizontal_size = ps_dec->u2_display_horizontal_size;
1304
57.1k
    ps_dec_thd->u2_display_vertical_size = ps_dec->u2_display_vertical_size;
1305
57.1k
    ps_dec_thd->u2_aspect_ratio_info = ps_dec->u2_aspect_ratio_info;
1306
1307
57.1k
    ps_dec_thd->ps_func_bi_direct = ps_dec->ps_func_bi_direct;
1308
57.1k
    ps_dec_thd->ps_func_forw_or_back = ps_dec->ps_func_forw_or_back;
1309
57.1k
    ps_dec_thd->pv_deinterlacer_ctxt = ps_dec->pv_deinterlacer_ctxt;
1310
57.1k
    ps_dec_thd->ps_deint_pic = ps_dec->ps_deint_pic;
1311
57.1k
    ps_dec_thd->pu1_deint_fmt_buf = ps_dec->pu1_deint_fmt_buf;
1312
1313
57.1k
    return 0;
1314
57.1k
}
1315
1316
1317
WORD32 impeg2d_get_slice_pos(dec_state_multi_core_t *ps_dec_state_multi_core)
1318
27.4k
{
1319
27.4k
    WORD32 u4_bits;
1320
27.4k
    WORD32 i4_row;
1321
1322
1323
27.4k
    dec_state_t *ps_dec = ps_dec_state_multi_core->ps_dec_state[0];
1324
27.4k
    WORD32 i4_prev_row;
1325
27.4k
    stream_t s_bitstrm;
1326
27.4k
    WORD32 i4_start_row;
1327
27.4k
    WORD32 i4_slice_bistream_ofst;
1328
27.4k
    WORD32 i;
1329
27.4k
    s_bitstrm = ps_dec->s_bit_stream;
1330
27.4k
    i4_prev_row = -1;
1331
1332
27.4k
    ps_dec_state_multi_core->ps_dec_state[0]->i4_start_mb_y = 0;
1333
27.4k
    ps_dec_state_multi_core->ps_dec_state[1]->i4_start_mb_y = -1;
1334
27.4k
    ps_dec_state_multi_core->ps_dec_state[2]->i4_start_mb_y = -1;
1335
27.4k
    ps_dec_state_multi_core->ps_dec_state[3]->i4_start_mb_y = -1;
1336
1337
27.4k
    ps_dec_state_multi_core->ps_dec_state[0]->i4_end_mb_y = ps_dec->u2_num_vert_mb;
1338
27.4k
    ps_dec_state_multi_core->ps_dec_state[1]->i4_end_mb_y = -1;
1339
27.4k
    ps_dec_state_multi_core->ps_dec_state[2]->i4_end_mb_y = -1;
1340
27.4k
    ps_dec_state_multi_core->ps_dec_state[3]->i4_end_mb_y = -1;
1341
1342
27.4k
    if(ps_dec->i4_num_cores == 1)
1343
1.23k
        return 0;
1344
    /* Reset the jobq to start of the jobq buffer */
1345
26.1k
    impeg2_jobq_reset((jobq_t *)ps_dec->pv_jobq);
1346
1347
26.1k
    i4_start_row = -1;
1348
26.1k
    i4_slice_bistream_ofst = 0;
1349
67.3k
    while(1)
1350
67.3k
    {
1351
67.3k
        WORD32 i4_is_slice;
1352
1353
67.3k
        if(s_bitstrm.u4_offset + START_CODE_LEN >= s_bitstrm.u4_max_offset)
1354
1.82k
        {
1355
1.82k
            break;
1356
1.82k
        }
1357
65.5k
        u4_bits = impeg2d_bit_stream_nxt(&s_bitstrm,START_CODE_LEN);
1358
1359
65.5k
        i4_row = u4_bits & 0xFF;
1360
1361
        /* Detect end of frame */
1362
65.5k
        i4_is_slice = (((u4_bits >> 8) == 0x01) && (i4_row) && (i4_row <= ps_dec->u2_num_vert_mb));
1363
65.5k
        if(!i4_is_slice)
1364
24.3k
            break;
1365
1366
41.2k
        i4_row -= 1;
1367
1368
1369
41.2k
        if(i4_prev_row < i4_row)
1370
32.0k
        {
1371
            /* Create a job for previous slice row */
1372
32.0k
            if(i4_start_row != -1)
1373
14.6k
            {
1374
14.6k
                job_t s_job;
1375
14.6k
                IV_API_CALL_STATUS_T ret;
1376
14.6k
                s_job.i2_start_mb_y = i4_start_row;
1377
14.6k
                s_job.i2_end_mb_y = i4_row;
1378
14.6k
                s_job.i4_cmd = CMD_PROCESS;
1379
14.6k
                s_job.i4_bistream_ofst = i4_slice_bistream_ofst;
1380
14.6k
                ret = impeg2_jobq_queue(ps_dec->pv_jobq, &s_job, sizeof(s_job), 1, 0);
1381
14.6k
                if(ret != IV_SUCCESS)
1382
0
                    return ret;
1383
1384
14.6k
            }
1385
            /* Store current slice's bitstream offset */
1386
32.0k
            i4_slice_bistream_ofst = s_bitstrm.u4_offset >> 3;
1387
32.0k
            i4_slice_bistream_ofst -= (size_t)s_bitstrm.pv_bs_buf & 3;
1388
32.0k
            i4_prev_row = i4_row;
1389
1390
            /* Store current slice's row position */
1391
32.0k
            i4_start_row = i4_row;
1392
1393
32.0k
        }
1394
#ifdef __ANDROID__
1395
        else if (i4_prev_row > i4_row)
1396
        {
1397
            android_errorWriteLog(0x534e4554, "26070014");
1398
        }
1399
#endif
1400
1401
41.2k
        impeg2d_bit_stream_flush(&s_bitstrm, START_CODE_LEN);
1402
1403
        // flush bytes till next start code
1404
        /* Flush the bytes till a  start code is encountered  */
1405
3.60M
        while(impeg2d_bit_stream_nxt(&s_bitstrm, 24) != START_CODE_PREFIX)
1406
3.56M
        {
1407
3.56M
            impeg2d_bit_stream_get(&s_bitstrm, 8);
1408
1409
3.56M
            if(s_bitstrm.u4_offset >= s_bitstrm.u4_max_offset)
1410
356
            {
1411
356
                break;
1412
356
            }
1413
3.56M
        }
1414
41.2k
    }
1415
1416
    /* Create job for the last slice row */
1417
26.1k
    {
1418
26.1k
        job_t s_job;
1419
26.1k
        IV_API_CALL_STATUS_T e_ret;
1420
26.1k
        s_job.i2_start_mb_y = i4_start_row;
1421
26.1k
        s_job.i2_end_mb_y = ps_dec->u2_num_vert_mb;
1422
26.1k
        s_job.i4_cmd = CMD_PROCESS;
1423
26.1k
        s_job.i4_bistream_ofst = i4_slice_bistream_ofst;
1424
26.1k
        e_ret = impeg2_jobq_queue(ps_dec->pv_jobq, &s_job, sizeof(s_job), 1, 0);
1425
26.1k
        if(e_ret != IV_SUCCESS)
1426
0
            return e_ret;
1427
1428
26.1k
    }
1429
26.1k
    if((NULL != ps_dec->ps_disp_pic) && ((0 == ps_dec->u4_share_disp_buf) || (IV_YUV_420P != ps_dec->i4_chromaFormat)))
1430
16.1k
    {
1431
314k
        for(i = 0; i < ps_dec->u2_vertical_size; i+=64)
1432
298k
        {
1433
298k
            job_t s_job;
1434
298k
            IV_API_CALL_STATUS_T ret;
1435
298k
            s_job.i2_start_mb_y = i;
1436
298k
            s_job.i2_start_mb_y >>= 4;
1437
298k
            s_job.i2_end_mb_y = (i + 64);
1438
298k
            s_job.i2_end_mb_y >>= 4;
1439
298k
            s_job.i4_cmd = CMD_FMTCONV;
1440
298k
            s_job.i4_bistream_ofst = 0;
1441
298k
            ret = impeg2_jobq_queue(ps_dec->pv_jobq, &s_job, sizeof(s_job), 1, 0);
1442
298k
            if(ret != IV_SUCCESS)
1443
0
                return ret;
1444
1445
298k
        }
1446
16.1k
    }
1447
1448
26.1k
    impeg2_jobq_terminate(ps_dec->pv_jobq);
1449
26.1k
    ps_dec->i4_bytes_consumed = s_bitstrm.u4_offset >> 3;
1450
26.1k
    ps_dec->i4_bytes_consumed -= ((size_t)s_bitstrm.pv_bs_buf & 3);
1451
1452
26.1k
    return 0;
1453
26.1k
}
1454
1455
/*******************************************************************************
1456
*
1457
*  Function Name   : impeg2d_dec_pic_data
1458
*
1459
*  Description     : It intializes several parameters and decodes a Picture
1460
*                    till any slice is left.
1461
*
1462
*  Arguments       :
1463
*  dec             : Decoder context
1464
*
1465
*  Values Returned : None
1466
*******************************************************************************/
1467
1468
void impeg2d_dec_pic_data(dec_state_t *ps_dec)
1469
27.4k
{
1470
1471
27.4k
    WORD32 i;
1472
27.4k
    dec_state_multi_core_t *ps_dec_state_multi_core;
1473
1474
27.4k
    dec_state_t *ps_dec_thd;
1475
27.4k
    WORD32 i4_status;
1476
27.4k
    WORD32 i4_min_mb_y;
1477
1478
1479
    /* Resetting the MB address and MB coordinates at the start of the Frame */
1480
27.4k
    ps_dec->u2_mb_x = ps_dec->u2_mb_y = 0;
1481
1482
27.4k
    ps_dec_state_multi_core = ps_dec->ps_dec_state_multi_core;
1483
27.4k
    impeg2d_get_slice_pos(ps_dec_state_multi_core);
1484
1485
27.4k
    if(ps_dec->i4_threads_active)
1486
27.4k
    {
1487
27.4k
        ps_dec->currThreadId = 0;
1488
27.4k
    }
1489
1490
27.4k
    i4_min_mb_y = 1;
1491
84.6k
    for(i=1; i < ps_dec->i4_num_cores; i++)
1492
57.1k
    {
1493
        // initialize decoder context for thread
1494
        // launch dec->u4_num_cores-1 threads
1495
1496
57.1k
        ps_dec_thd = ps_dec_state_multi_core->ps_dec_state[i];
1497
1498
57.1k
        ps_dec_thd->ps_disp_pic = ps_dec->ps_disp_pic;
1499
57.1k
        ps_dec_thd->ps_disp_frm_buf = ps_dec->ps_disp_frm_buf;
1500
1501
57.1k
        i4_status = impeg2d_init_thread_dec_ctxt(ps_dec, ps_dec_thd, i4_min_mb_y);
1502
        //impeg2d_dec_pic_data_thread(ps_dec_thd);
1503
1504
57.1k
        if(i4_status == 0 && !ps_dec_state_multi_core->au4_thread_launched[i])
1505
12.0k
        {
1506
12.0k
            if(ps_dec->i4_threads_active)
1507
12.0k
            {
1508
12.0k
                ps_dec_thd->currThreadId = i;
1509
12.0k
            }
1510
12.0k
            ithread_create(ps_dec_thd->pv_codec_thread_handle, NULL, (void *)impeg2d_dec_pic_data_thread, ps_dec_thd);
1511
12.0k
            ps_dec_state_multi_core->au4_thread_launched[i] = 1;
1512
12.0k
            i4_min_mb_y = ps_dec_thd->u2_mb_y + 1;
1513
12.0k
        }
1514
1515
45.1k
        else if (!ps_dec->i4_threads_active)
1516
0
        {
1517
0
            ps_dec_state_multi_core->au4_thread_launched[i] = 0;
1518
0
            break;
1519
0
        }
1520
1521
57.1k
        if(ps_dec->i4_threads_active)
1522
57.1k
        {
1523
57.1k
            i4_status = ithread_mutex_lock(ps_dec_thd->pv_proc_start_mutex);
1524
57.1k
            if((IMPEG2D_ERROR_CODES_T)IV_SUCCESS != i4_status) return;
1525
1526
57.1k
            ps_dec_thd->ai4_process_start = 1;
1527
57.1k
            ithread_cond_signal(ps_dec_thd->pv_proc_start_condition);
1528
1529
57.1k
            i4_status = ithread_mutex_unlock(ps_dec_thd->pv_proc_start_mutex);
1530
57.1k
            if((IMPEG2D_ERROR_CODES_T)IV_SUCCESS != i4_status) return;
1531
57.1k
        }
1532
57.1k
    }
1533
1534
27.4k
    impeg2d_dec_pic_data_thread(ps_dec);
1535
1536
    // wait for threads to complete
1537
84.6k
    for(i=1; i < ps_dec->i4_num_cores; i++)
1538
57.1k
    {
1539
57.1k
        if(ps_dec_state_multi_core->au4_thread_launched[i])
1540
57.1k
        {
1541
57.1k
            ps_dec_thd = ps_dec_state_multi_core->ps_dec_state[i];
1542
57.1k
            if (ps_dec->i4_threads_active)
1543
57.1k
            {
1544
57.1k
                i4_status = ithread_mutex_lock(ps_dec_thd->pv_proc_done_mutex);
1545
57.1k
                if((IMPEG2D_ERROR_CODES_T)IV_SUCCESS != i4_status) return;
1546
1547
78.1k
                while(!ps_dec_thd->ai4_process_done)
1548
20.9k
                {
1549
20.9k
                    ithread_cond_wait(ps_dec_thd->pv_proc_done_condition,
1550
20.9k
                                      ps_dec_thd->pv_proc_done_mutex);
1551
20.9k
                }
1552
57.1k
                ps_dec_thd->ai4_process_done = 0;
1553
57.1k
                i4_status = ithread_mutex_unlock(ps_dec_thd->pv_proc_done_mutex);
1554
57.1k
                if((IMPEG2D_ERROR_CODES_T)IV_SUCCESS != i4_status) return;
1555
57.1k
            }
1556
0
            else
1557
0
            {
1558
0
                ithread_join(ps_dec_thd->pv_codec_thread_handle, NULL);
1559
0
                ps_dec_state_multi_core->au4_thread_launched[i] = 0;
1560
0
            }
1561
57.1k
        }
1562
57.1k
    }
1563
1564
27.4k
}
1565
/*******************************************************************************
1566
*
1567
*  Function Name   : impeg2d_flush_ext_and_user_data
1568
*
1569
*  Description     : Flushes the extension and user data present in the
1570
*                    stream_t
1571
*
1572
*  Arguments       :
1573
*  dec             : Decoder context
1574
*
1575
*  Values Returned : None
1576
*******************************************************************************/
1577
void impeg2d_flush_ext_and_user_data(dec_state_t *ps_dec)
1578
902k
{
1579
902k
    UWORD32 u4_start_code;
1580
902k
    stream_t *ps_stream;
1581
1582
902k
    ps_stream    = &ps_dec->s_bit_stream;
1583
902k
    u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
1584
1585
1.14M
    while((u4_start_code == EXTENSION_START_CODE || u4_start_code == USER_DATA_START_CODE) &&
1586
239k
            (ps_stream->u4_offset < ps_stream->u4_max_offset))
1587
239k
    {
1588
239k
        impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
1589
5.86M
        while(impeg2d_bit_stream_nxt(ps_stream,START_CODE_PREFIX_LEN) != START_CODE_PREFIX &&
1590
5.62M
                (ps_stream->u4_offset < ps_stream->u4_max_offset))
1591
5.62M
        {
1592
5.62M
            impeg2d_bit_stream_flush(ps_stream,8);
1593
5.62M
        }
1594
239k
        u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
1595
239k
    }
1596
902k
}
1597
/*******************************************************************************
1598
*
1599
*  Function Name   : impeg2d_dec_user_data
1600
*
1601
*  Description     : Flushes the user data present in the stream_t
1602
*
1603
*  Arguments       :
1604
*  dec             : Decoder context
1605
*
1606
*  Values Returned : None
1607
*******************************************************************************/
1608
void impeg2d_dec_user_data(dec_state_t *ps_dec)
1609
66.6k
{
1610
66.6k
    UWORD32 u4_start_code;
1611
66.6k
    stream_t *ps_stream;
1612
1613
66.6k
    ps_stream    = &ps_dec->s_bit_stream;
1614
66.6k
    u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
1615
1616
92.1k
    while((u4_start_code == USER_DATA_START_CODE) &&
1617
25.4k
        (ps_stream->u4_offset <= ps_stream->u4_max_offset))
1618
25.4k
    {
1619
25.4k
        impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
1620
2.30M
        while((impeg2d_bit_stream_nxt(ps_stream,START_CODE_PREFIX_LEN) != START_CODE_PREFIX) &&
1621
2.27M
                (ps_stream->u4_offset < ps_stream->u4_max_offset))
1622
2.27M
        {
1623
2.27M
            impeg2d_bit_stream_flush(ps_stream,8);
1624
2.27M
        }
1625
25.4k
        u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
1626
25.4k
    }
1627
66.6k
}
1628
/*******************************************************************************
1629
*  Function Name   : impeg2d_dec_seq_ext_data
1630
*
1631
*  Description     : Decodes the extension data following Sequence
1632
*                    Extension. It flushes any user data if present
1633
*
1634
*  Arguments       :
1635
*  dec             : Decoder context
1636
*
1637
*  Values Returned : None
1638
*******************************************************************************/
1639
IMPEG2D_ERROR_CODES_T impeg2d_dec_seq_ext_data(dec_state_t *ps_dec)
1640
88.7k
{
1641
88.7k
    stream_t   *ps_stream;
1642
88.7k
    UWORD32     u4_start_code;
1643
88.7k
    IMPEG2D_ERROR_CODES_T e_error;
1644
1645
88.7k
    e_error = (IMPEG2D_ERROR_CODES_T) IVD_ERROR_NONE;
1646
1647
88.7k
    ps_stream      = &ps_dec->s_bit_stream;
1648
88.7k
    u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
1649
224k
    while( (u4_start_code == EXTENSION_START_CODE ||
1650
103k
            u4_start_code == USER_DATA_START_CODE) &&
1651
136k
            (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE == e_error &&
1652
136k
            (ps_stream->u4_offset < ps_stream->u4_max_offset))
1653
136k
    {
1654
136k
        if(u4_start_code == USER_DATA_START_CODE)
1655
14.2k
        {
1656
14.2k
            impeg2d_dec_user_data(ps_dec);
1657
14.2k
        }
1658
121k
        else
1659
121k
        {
1660
121k
            impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
1661
121k
            u4_start_code   = impeg2d_bit_stream_nxt(ps_stream,EXT_ID_LEN);
1662
121k
            switch(u4_start_code)
1663
121k
            {
1664
99.8k
            case SEQ_DISPLAY_EXT_ID:
1665
99.8k
                impeg2d_dec_seq_disp_ext(ps_dec);
1666
99.8k
                break;
1667
537
            case SEQ_SCALABLE_EXT_ID:
1668
537
                e_error = IMPEG2D_SCALABILITIY_NOT_SUPPORTED;
1669
537
                break;
1670
21.3k
            default:
1671
                /* In case its a reserved extension code */
1672
21.3k
                impeg2d_bit_stream_flush(ps_stream,EXT_ID_LEN);
1673
21.3k
                impeg2d_peek_next_start_code(ps_dec);
1674
21.3k
                break;
1675
121k
            }
1676
121k
        }
1677
136k
        u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
1678
136k
    }
1679
88.7k
    return e_error;
1680
88.7k
}
1681
/*******************************************************************************
1682
*  Function Name   : impeg2d_dec_pic_ext_data
1683
*
1684
*  Description     : Decodes the extension data following Picture Coding
1685
*                    Extension. It flushes any user data if present
1686
*
1687
*  Arguments       :
1688
*  dec             : Decoder context
1689
*
1690
*  Values Returned : None
1691
*******************************************************************************/
1692
IMPEG2D_ERROR_CODES_T impeg2d_dec_pic_ext_data(dec_state_t *ps_dec)
1693
12.2k
{
1694
12.2k
    stream_t   *ps_stream;
1695
12.2k
    UWORD32     u4_start_code;
1696
12.2k
    IMPEG2D_ERROR_CODES_T e_error;
1697
1698
12.2k
    e_error = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
1699
1700
12.2k
    ps_stream      = &ps_dec->s_bit_stream;
1701
12.2k
    u4_start_code   = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
1702
110k
    while ( (u4_start_code == EXTENSION_START_CODE ||
1703
12.5k
            u4_start_code == USER_DATA_START_CODE) &&
1704
98.0k
            (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE == e_error &&
1705
98.0k
            (ps_stream->u4_offset < ps_stream->u4_max_offset))
1706
98.0k
    {
1707
98.0k
        if(u4_start_code == USER_DATA_START_CODE)
1708
336
        {
1709
336
            impeg2d_dec_user_data(ps_dec);
1710
336
        }
1711
97.7k
        else
1712
97.7k
        {
1713
97.7k
            impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
1714
97.7k
            u4_start_code   = impeg2d_bit_stream_nxt(ps_stream,EXT_ID_LEN);
1715
97.7k
            switch(u4_start_code)
1716
97.7k
            {
1717
27.5k
            case QUANT_MATRIX_EXT_ID:
1718
27.5k
                impeg2d_dec_quant_matrix_ext(ps_dec);
1719
27.5k
                break;
1720
1.64k
            case COPYRIGHT_EXT_ID:
1721
1.64k
                impeg2d_dec_copyright_ext(ps_dec);
1722
1.64k
                break;
1723
4.68k
            case PIC_DISPLAY_EXT_ID:
1724
4.68k
                impeg2d_dec_pic_disp_ext(ps_dec);
1725
4.68k
                break;
1726
2.37k
            case CAMERA_PARAM_EXT_ID:
1727
2.37k
                impeg2d_dec_cam_param_ext(ps_dec);
1728
2.37k
                break;
1729
51.6k
            case ITU_T_EXT_ID:
1730
51.6k
                impeg2d_dec_itu_t_ext(ps_dec);
1731
51.6k
                break;
1732
228
            case PIC_SPATIAL_SCALABLE_EXT_ID:
1733
437
            case PIC_TEMPORAL_SCALABLE_EXT_ID:
1734
437
                e_error = IMPEG2D_SCALABLITY_NOT_SUP;
1735
437
                break;
1736
9.40k
            default:
1737
                /* In case its a reserved extension code */
1738
9.40k
                impeg2d_bit_stream_flush(ps_stream,EXT_ID_LEN);
1739
9.40k
                impeg2d_next_start_code(ps_dec);
1740
9.40k
                break;
1741
97.7k
            }
1742
97.7k
        }
1743
98.0k
        u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
1744
98.0k
    }
1745
12.2k
    return e_error;
1746
12.2k
}
1747
1748
/*******************************************************************************
1749
*
1750
*  Function Name   : impeg2d_process_video_header
1751
*
1752
*  Description     : Processes video sequence header information
1753
*
1754
*  Arguments       :
1755
*  dec             : Decoder context
1756
*
1757
*  Values Returned : None
1758
*******************************************************************************/
1759
IMPEG2D_ERROR_CODES_T impeg2d_process_video_header(dec_state_t *ps_dec)
1760
18.0k
{
1761
18.0k
    stream_t *ps_stream;
1762
18.0k
    ps_stream = &ps_dec->s_bit_stream;
1763
18.0k
    IMPEG2D_ERROR_CODES_T e_error;
1764
1765
18.0k
    impeg2d_next_code(ps_dec, SEQUENCE_HEADER_CODE);
1766
18.0k
    if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
1767
17.5k
    {
1768
17.5k
        e_error = impeg2d_dec_seq_hdr(ps_dec);
1769
17.5k
        if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
1770
8.19k
        {
1771
8.19k
            return e_error;
1772
8.19k
        }
1773
17.5k
    }
1774
472
    else
1775
472
    {
1776
472
      return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
1777
472
    }
1778
9.37k
    if (impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) == EXTENSION_START_CODE)
1779
4.58k
    {
1780
        /* MPEG2 Decoder */
1781
4.58k
        if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
1782
4.57k
        {
1783
4.57k
            e_error = impeg2d_dec_seq_ext(ps_dec);
1784
4.57k
            if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
1785
1.31k
            {
1786
1.31k
                return e_error;
1787
1.31k
            }
1788
4.57k
        }
1789
5
        else
1790
5
        {
1791
5
          return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
1792
5
        }
1793
3.26k
        if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
1794
2.86k
        {
1795
2.86k
            e_error = impeg2d_dec_seq_ext_data(ps_dec);
1796
2.86k
            if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
1797
213
            {
1798
213
                return e_error;
1799
213
            }
1800
2.86k
        }
1801
3.05k
        return impeg2d_init_video_state(ps_dec,MPEG_2_VIDEO);
1802
3.26k
    }
1803
4.79k
    else
1804
4.79k
    {
1805
         /* MPEG1 Decoder */
1806
4.79k
        if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
1807
2.99k
        {
1808
2.99k
            impeg2d_flush_ext_and_user_data(ps_dec);
1809
2.99k
        }
1810
4.79k
        return impeg2d_init_video_state(ps_dec,MPEG_1_VIDEO);
1811
4.79k
    }
1812
9.37k
}
1813
/*******************************************************************************
1814
*
1815
*  Function Name   : impeg2d_process_video_bit_stream
1816
*
1817
*  Description     : Processes video sequence header information
1818
*
1819
*  Arguments       :
1820
*  dec             : Decoder context
1821
*
1822
*  Values Returned : None
1823
*******************************************************************************/
1824
IMPEG2D_ERROR_CODES_T impeg2d_process_video_bit_stream(dec_state_t *ps_dec)
1825
43.9k
{
1826
43.9k
    stream_t *ps_stream;
1827
43.9k
    UWORD32 u4_next_bits, u4_start_code_found;
1828
43.9k
    IMPEG2D_ERROR_CODES_T e_error;
1829
1830
43.9k
    ps_stream = &ps_dec->s_bit_stream;
1831
43.9k
    impeg2d_next_start_code(ps_dec);
1832
    /* If the stream is MPEG-2 compliant stream */
1833
43.9k
    u4_start_code_found = 0;
1834
1835
43.9k
    if(ps_dec->u2_is_mpeg2)
1836
20.4k
    {
1837
        /* MPEG2 decoding starts */
1838
378k
        while((u4_start_code_found == 0) && (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
1839
366k
        {
1840
366k
            u4_next_bits = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
1841
1842
366k
            if(u4_next_bits == SEQUENCE_HEADER_CODE)
1843
15.4k
            {
1844
15.4k
                if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
1845
15.4k
                {
1846
15.4k
                    e_error = impeg2d_dec_seq_hdr(ps_dec);
1847
15.4k
                    if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
1848
1.53k
                    {
1849
1.53k
                        return e_error;
1850
1.53k
                    }
1851
1852
13.8k
                    u4_start_code_found = 0;
1853
1854
13.8k
                }
1855
0
                else
1856
0
                {
1857
0
                    return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
1858
0
                }
1859
1860
1861
13.8k
                if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
1862
13.8k
                {
1863
13.8k
                    IMPEG2D_ERROR_CODES_T e_error;
1864
13.8k
                    e_error = impeg2d_dec_seq_ext(ps_dec);
1865
13.8k
                    if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
1866
1.10k
                    {
1867
1.10k
                        return e_error;
1868
1.10k
                    }
1869
12.7k
                    u4_start_code_found = 0;
1870
1871
12.7k
                }
1872
13
                else
1873
13
                {
1874
13
                    return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
1875
13
                }
1876
13.8k
            }
1877
351k
            else if((u4_next_bits == USER_DATA_START_CODE) || (u4_next_bits == EXTENSION_START_CODE))
1878
85.8k
            {
1879
85.8k
                if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
1880
85.8k
                {
1881
85.8k
                    impeg2d_dec_seq_ext_data(ps_dec);
1882
85.8k
                    u4_start_code_found = 0;
1883
1884
85.8k
                }
1885
1886
85.8k
            }
1887
265k
            else if((ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
1888
265k
                    && (u4_next_bits == GOP_START_CODE))
1889
52.0k
            {
1890
52.0k
                impeg2d_dec_grp_of_pic_hdr(ps_dec);
1891
52.0k
                impeg2d_dec_user_data(ps_dec);
1892
52.0k
                u4_start_code_found = 0;
1893
1894
52.0k
            }
1895
213k
            else if((ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
1896
213k
                    && (u4_next_bits == PICTURE_START_CODE))
1897
17.3k
            {
1898
17.3k
                ps_dec->i4_pic_count++;
1899
1900
17.3k
                e_error = impeg2d_dec_pic_hdr(ps_dec);
1901
17.3k
                if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
1902
1.75k
                {
1903
1.75k
                    return e_error;
1904
1.75k
                }
1905
15.6k
                e_error = impeg2d_dec_pic_coding_ext(ps_dec);
1906
15.6k
                if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
1907
3.37k
                {
1908
3.37k
                    return e_error;
1909
3.37k
                }
1910
12.2k
                e_error = impeg2d_dec_pic_ext_data(ps_dec);
1911
12.2k
                if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
1912
437
                {
1913
437
                    return e_error;
1914
437
                }
1915
11.8k
                e_error = impeg2d_pre_pic_dec_proc(ps_dec);
1916
11.8k
                if ((IMPEG2D_ERROR_CODES_T) IVD_ERROR_NONE != e_error)
1917
770
                {
1918
770
                    return e_error;
1919
770
                }
1920
11.0k
                impeg2d_dec_pic_data(ps_dec);
1921
11.0k
                impeg2d_post_pic_dec_proc(ps_dec);
1922
11.0k
                u4_start_code_found = 1;
1923
11.0k
            }
1924
196k
            else
1925
1926
196k
            {
1927
196k
                FLUSH_BITS(ps_dec->s_bit_stream.u4_offset, ps_dec->s_bit_stream.u4_buf, ps_dec->s_bit_stream.u4_buf_nxt, 8, ps_dec->s_bit_stream.pu4_buf_aligned);
1928
1929
196k
            }
1930
357k
            if(u4_start_code_found == 0)
1931
346k
            {
1932
346k
                impeg2d_next_start_code(ps_dec);
1933
                /* In case a dec_pic_data call has not been made, the number of
1934
                 * bytes consumed in the previous header decode has to be
1935
                 * consumed. Not consuming it will result in zero bytes consumed
1936
                 * loops in case there are multiple headers and the second
1937
                 * or a future header has a resolution change/other error where
1938
                 * the bytes of the last header are not consumed.
1939
                 */
1940
346k
                ps_dec->i4_bytes_consumed = (ps_dec->s_bit_stream.u4_offset + 7) >> 3;
1941
346k
                ps_dec->i4_bytes_consumed -= ((size_t)ps_dec->s_bit_stream.pv_bs_buf & 3);
1942
346k
            }
1943
357k
        }
1944
11.4k
        if((u4_start_code_found == 0) && (ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset))
1945
95
        {
1946
95
            return IMPEG2D_FRM_HDR_START_CODE_NOT_FOUND;
1947
95
        }
1948
1949
11.4k
    }
1950
        /* If the stream is MPEG-1 compliant stream */
1951
23.5k
    else
1952
23.5k
    {
1953
1.68M
        while((u4_start_code_found == 0) && (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
1954
1.66M
        {
1955
1.66M
            u4_next_bits = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
1956
1957
1.66M
            if(impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) == SEQUENCE_HEADER_CODE)
1958
205k
            {
1959
205k
                if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
1960
205k
                {
1961
205k
                    e_error = impeg2d_dec_seq_hdr(ps_dec);
1962
205k
                    if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
1963
3.84k
                    {
1964
3.84k
                        return e_error;
1965
3.84k
                    }
1966
1967
201k
                    u4_start_code_found = 0;
1968
201k
                }
1969
0
                else
1970
0
                {
1971
0
                    return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
1972
0
                }
1973
205k
            }
1974
1.46M
            else if((ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset) && (u4_next_bits == EXTENSION_START_CODE || u4_next_bits == USER_DATA_START_CODE))
1975
159k
            {
1976
159k
                impeg2d_flush_ext_and_user_data(ps_dec);
1977
159k
                u4_start_code_found = 0;
1978
159k
            }
1979
1980
1981
1.30M
            else if ((impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) == GOP_START_CODE)
1982
723k
                    && (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
1983
723k
            {
1984
723k
                impeg2d_dec_grp_of_pic_hdr(ps_dec);
1985
723k
                impeg2d_flush_ext_and_user_data(ps_dec);
1986
723k
                u4_start_code_found = 0;
1987
723k
            }
1988
578k
            else if ((impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) == PICTURE_START_CODE)
1989
19.2k
                    && (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
1990
19.2k
            {
1991
19.2k
                ps_dec->i4_pic_count++;
1992
1993
19.2k
                e_error = impeg2d_dec_pic_hdr(ps_dec);
1994
19.2k
                if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
1995
2.83k
                {
1996
2.83k
                    return e_error;
1997
2.83k
                }
1998
16.3k
                impeg2d_flush_ext_and_user_data(ps_dec);
1999
16.3k
                e_error = impeg2d_pre_pic_dec_proc(ps_dec);
2000
16.3k
                if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
2001
0
                {
2002
0
                    return e_error;
2003
0
                }
2004
16.3k
                impeg2d_dec_pic_data(ps_dec);
2005
16.3k
                impeg2d_post_pic_dec_proc(ps_dec);
2006
16.3k
                u4_start_code_found = 1;
2007
16.3k
            }
2008
559k
            else
2009
559k
            {
2010
559k
                FLUSH_BITS(ps_dec->s_bit_stream.u4_offset, ps_dec->s_bit_stream.u4_buf, ps_dec->s_bit_stream.u4_buf_nxt, 8, ps_dec->s_bit_stream.pu4_buf_aligned);
2011
559k
            }
2012
1.66M
            impeg2d_next_start_code(ps_dec);
2013
1.66M
            if (0 == u4_start_code_found)
2014
1.64M
            {
2015
                /* In case a dec_pic_data call has not been made, the number of
2016
                 * bytes consumed in the previous header decode has to be
2017
                 * consumed. Not consuming it will result in zero bytes consumed
2018
                 * loops in case there are multiple headers and the second
2019
                 * or a future header has a resolution change/other error where
2020
                 * the bytes of the last header are not consumed.
2021
                 */
2022
1.64M
                ps_dec->i4_bytes_consumed = (ps_dec->s_bit_stream.u4_offset + 7) >> 3;
2023
1.64M
                ps_dec->i4_bytes_consumed -= ((size_t)ps_dec->s_bit_stream.pv_bs_buf & 3);
2024
1.64M
            }
2025
1.66M
        }
2026
16.8k
        if((u4_start_code_found == 0) && (ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset))
2027
311
        {
2028
311
           return IMPEG2D_FRM_HDR_START_CODE_NOT_FOUND;
2029
311
        }
2030
16.8k
    }
2031
2032
27.8k
    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
2033
43.9k
}