Coverage Report

Created: 2026-09-01 07:15

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