Coverage Report

Created: 2024-06-24 06:30

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