Coverage Report

Created: 2026-06-10 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/decoder/svc/isvcd_nal_parse.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2022 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
 */
20
/*!
21
 **************************************************************************
22
 * \file isvcd_nal_parse.c
23
 *
24
 * \brief
25
 *    Contains routines that resample for SVC resampling
26
 *
27
 * Detailed_description
28
 *
29
 * \date
30
 *
31
 *
32
 * \author : Kishore
33
 **************************************************************************
34
 */
35
36
/*****************************************************************************/
37
/* File Includes                                                             */
38
/*****************************************************************************/
39
40
/* System include files */
41
#include <stdio.h>
42
#include <stdlib.h>
43
#include <string.h>
44
#include <limits.h>
45
#include <stddef.h>
46
#include <assert.h>
47
48
/* standard interface include files */
49
#include "ih264_typedefs.h"
50
#include "ih264_macros.h"
51
#include "ih264_platform_macros.h"
52
#include "ih264d_tables.h"
53
#include "iv.h"
54
#include "ivd.h"
55
#include "ih264d_defs.h"
56
#include "ih264d_debug.h"
57
#include "ih264_debug.h"
58
#include "ih264d_inter_pred.h"
59
#include "isvcd_structs.h"
60
#include "ih264d_nal.h"
61
#include "ih264d_error_handler.h"
62
63
/*****************************************************************************/
64
/*Extern Variable Declarations                                               */
65
/*****************************************************************************/
66
67
/*****************************************************************************/
68
/* Global Variable Definitions                                               */
69
/*****************************************************************************/
70
71
/*****************************************************************************/
72
/* Static Global Variable Definitions                                        */
73
/*****************************************************************************/
74
75
/*****************************************************************************/
76
/* Static function Definitions                                               */
77
/*****************************************************************************/
78
79
/*****************************************************************************/
80
/*                                                                           */
81
/*  Function Name : isvcd_get_nal_buf                                         */
82
/*                                                                           */
83
/*  Description   : This routine returns the NAL buffer structure to use for */
84
/*                  current NAL unit. This will also perform the initializa -*/
85
/*                  tion of the structure                                    */
86
/*  Inputs        : 1. NAL parse structure                                   */
87
/*                  2. Place holder for nal buffer structure                 */
88
/*  Globals       : None                                                     */
89
/*  Processing    : If current NAL unit prefix NAL unit then                 */
90
/*                      - Resets the prefix nal buffer structure             */
91
/*                      - Assigns the buffer pointer                         */
92
/*                  Otherwise                                                */
93
/*                      - Assigns the buffer pointer                         */
94
/*  Outputs       :  - Updated NAL buffer strcuture                          */
95
/*                   - Updates the place holder with correct NAL buffer      */
96
/*                  structure                                                */
97
/*  Returns       : None                                                     */
98
/*                                                                           */
99
/*  Issues        : None                                                     */
100
/*                                                                           */
101
/*  Revision History:                                                        */
102
/*                                                                           */
103
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
104
/*         06 09 2021   Vijay      Draft                                     */
105
/*                                                                           */
106
/*****************************************************************************/
107
void isvcd_get_nal_buf(nal_parse_ctxt_t *ps_nal_parse_ctxt, nal_buf_t **pps_nal_buf)
108
1.48M
{
109
1.48M
    nal_prms_t *ps_nal_prms;
110
1.48M
    nal_buf_t *ps_nal_buf;
111
112
1.48M
    ps_nal_prms = &ps_nal_parse_ctxt->s_nal_prms;
113
114
    /* Get the NAL buffer structure */
115
1.48M
    if(PREFIX_UNIT_NAL == ps_nal_prms->i4_nal_unit_type)
116
3.22k
    {
117
3.22k
        ps_nal_buf = &ps_nal_parse_ctxt->s_prefix_nal_buf;
118
119
        /* Note: This reset will cause a prefix NAL unit */
120
        /* which is followed by another prefix NAL unit  */
121
        /* to be ignored by the module. This is indeed   */
122
        /* a desired behaviour                           */
123
3.22k
        isvcd_nal_buf_reset(ps_nal_buf);
124
3.22k
    }
125
1.48M
    else
126
1.48M
    {
127
1.48M
        ps_nal_buf = &ps_nal_parse_ctxt->s_nal_buf;
128
1.48M
    }
129
130
    /* Initialize the buffer structure */
131
1.48M
    ps_nal_buf->i4_valid_flag = SVCD_TRUE;
132
1.48M
    if(VCL_NAL == ps_nal_prms->i4_derived_nal_type)
133
238k
    {
134
238k
        ps_nal_buf->pu1_buf = ps_nal_parse_ctxt->pu1_vcl_nal_buf;
135
238k
    }
136
1.24M
    else if(NON_VCL_NAL == ps_nal_prms->i4_derived_nal_type)
137
1.23M
    {
138
1.23M
        ps_nal_buf->pu1_buf = ps_nal_parse_ctxt->pu1_non_vcl_nal_buf;
139
1.23M
    }
140
12.9k
    else
141
12.9k
    {
142
12.9k
        ps_nal_buf->pu1_buf = NULL;
143
12.9k
        return;
144
12.9k
    }
145
146
1.47M
    *pps_nal_buf = ps_nal_buf;
147
1.47M
}
148
149
/*****************************************************************************/
150
/*                                                                           */
151
/*  Function Name : isvcd_dqid_ctxt_reset                                     */
152
/*                                                                           */
153
/*  Description   : This routine resets the DQID context. This routine shall */
154
/*                  be invoked once in a picture                             */
155
/*                                                                           */
156
/*  Inputs        : DQID context structure                                   */
157
/*  Globals       : None                                                     */
158
/*  Processing    : Invalidates all the DQID nodes                           */
159
/*                                                                           */
160
/*  Outputs       : Updated DQID context                                     */
161
/*  Returns       : status                                                   */
162
/*                                                                           */
163
/*  Issues        : None                                                     */
164
/*                                                                           */
165
/*  Revision History:                                                        */
166
/*                                                                           */
167
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
168
/*         06 09 2021   Vijay      Draft                                     */
169
/*                                                                           */
170
/*****************************************************************************/
171
WORD32 isvcd_dqid_ctxt_reset(dqid_ctxt_t *ps_dqid_ctxt)
172
263k
{
173
263k
    WORD32 i4_lyr_idx;
174
263k
    WORD32 i4_max_num_lyrs;
175
263k
    dqid_node_t *ps_dqid_node;
176
177
    /* sanity checks */
178
263k
    if(NULL == ps_dqid_ctxt)
179
0
    {
180
0
        return NOT_OK;
181
0
    }
182
183
263k
    i4_max_num_lyrs = ps_dqid_ctxt->i4_max_num_lyrs;
184
263k
    ps_dqid_node = ps_dqid_ctxt->ps_dqid_node;
185
186
    /* Loop over all the layers */
187
1.05M
    for(i4_lyr_idx = 0; i4_lyr_idx < i4_max_num_lyrs; i4_lyr_idx++)
188
791k
    {
189
        /* Reset the valid flag */
190
791k
        ps_dqid_node->u1_valid_flag = SVCD_FALSE;
191
192
        /* Loop updates */
193
791k
        ps_dqid_node += 1;
194
791k
    } /* loop over all the layers */
195
196
263k
    return (OK);
197
263k
}
198
199
/*****************************************************************************/
200
/*                                                                           */
201
/*  Function Name : isvcd_get_dqid_node                                       */
202
/*                                                                           */
203
/*  Description   : This routine gets a DQID node corresponding to a DQID    */
204
/*                                                                           */
205
/*  Inputs        : 1. DQID context                                          */
206
/*                  2. DQID                                                  */
207
/*                  3. Place holder for DQID node (output)                   */
208
/*  Globals       : None                                                     */
209
/*  Processing    : It performs the following                                */
210
/*                  - Searches for all elements untill it gets element having*/
211
/*                    DQID equal to input DQID.                              */
212
/*                  - If not found it finds a free (un-occupied) node        */
213
/*                                                                           */
214
/*  Outputs       : 1. Updated DQID node                                     */
215
/*  Returns       : status                                                   */
216
/*                                                                           */
217
/*  Issues        : None                                                     */
218
/*                                                                           */
219
/*  Revision History:                                                        */
220
/*                                                                           */
221
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
222
/*         06 09 2021   Vijay      Draft                                     */
223
/*                                                                           */
224
/*****************************************************************************/
225
WORD32 isvcd_get_dqid_node(dqid_ctxt_t *ps_dqid_ctxt, UWORD8 u1_dqid, dqid_node_t **pps_dqid_node)
226
844k
{
227
844k
    WORD32 i4_lyr_idx;
228
844k
    WORD32 i4_max_num_lyrs;
229
844k
    dqid_node_t *ps_dqid_node;
230
844k
    dqid_node_t *ps_rqrd_dqid_node;
231
232
    /* sanity checks */
233
844k
    if((NULL == ps_dqid_ctxt) || (NULL == pps_dqid_node))
234
0
    {
235
0
        return NOT_OK;
236
0
    }
237
238
844k
    i4_max_num_lyrs = ps_dqid_ctxt->i4_max_num_lyrs;
239
844k
    ps_dqid_node = ps_dqid_ctxt->ps_dqid_node;
240
241
    /*Initialization */
242
844k
    ps_rqrd_dqid_node = NULL;
243
244
    /* Loop over all the buffer nodes */
245
1.95M
    for(i4_lyr_idx = 0; i4_lyr_idx < i4_max_num_lyrs; i4_lyr_idx++)
246
1.60M
    {
247
1.60M
        if((SVCD_TRUE == ps_dqid_node->u1_valid_flag) && (u1_dqid == ps_dqid_node->u1_dqid))
248
495k
        {
249
495k
            ps_rqrd_dqid_node = ps_dqid_node;
250
495k
            break;
251
495k
        }
252
        /* Loop updates */
253
1.11M
        ps_dqid_node += 1;
254
1.11M
    } /* Loop over all the buffer nodes */
255
256
844k
    if(NULL == ps_rqrd_dqid_node)
257
349k
    {
258
        /* If vcl node is not allocated for the requested DQID then allocate buffer */
259
349k
        ps_dqid_node = ps_dqid_ctxt->ps_dqid_node;
260
414k
        for(i4_lyr_idx = 0; i4_lyr_idx < i4_max_num_lyrs; i4_lyr_idx++)
261
414k
        {
262
414k
            if(SVCD_FALSE == ps_dqid_node->u1_valid_flag)
263
349k
            {
264
349k
                break;
265
349k
            }
266
            /* Loop updates */
267
65.1k
            ps_dqid_node += 1;
268
65.1k
        } /* Loop over all the nodes */
269
        /* Update the node structure */
270
349k
        ps_rqrd_dqid_node = ps_dqid_node;
271
349k
    }
272
273
    /* sanity checks */
274
844k
    if(NULL == ps_rqrd_dqid_node)
275
0
    {
276
0
        return NOT_OK;
277
0
    }
278
844k
    *pps_dqid_node = ps_rqrd_dqid_node;
279
280
844k
    return (OK);
281
844k
}
282
283
/*****************************************************************************/
284
/*                                                                           */
285
/*  Function Name : isvcd_nal_reset_ctxt                                     */
286
/*                                                                           */
287
/*  Description   : This routine performs NAL unit level initialization      */
288
/*                  This routine shall be called before parsing a NAL unit   */
289
/*                                                                           */
290
/*  Inputs        : 1. NAL parse context structure                           */
291
/*  Globals       : None                                                     */
292
/*  Processing    : This does initializaiton of NAL unit level tracking      */
293
/*                  varaibles                                                */
294
/*                                                                           */
295
/*  Outputs       : Updated context structure                                */
296
/*  Returns       : status                                                   */
297
/*                                                                           */
298
/*  Issues        : None                                                     */
299
/*                                                                           */
300
/*  Revision History:                                                        */
301
/*                                                                           */
302
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
303
/*         06 09 2021   Vijay      Draft                                     */
304
/*                                                                           */
305
/*****************************************************************************/
306
WORD32 isvcd_nal_reset_ctxt(nal_parse_ctxt_t *ps_nal_parse_ctxt)
307
1.77M
{
308
1.77M
    nal_unit_t *ps_nal_unit;
309
310
1.77M
    if(NULL == ps_nal_parse_ctxt)
311
0
    {
312
0
        return NOT_OK;
313
0
    }
314
315
    /* Reset the NAL boundary detetction */
316
1.77M
    ps_nal_parse_ctxt->i4_find_nal_state = NAL_START;
317
1.77M
    ps_nal_parse_ctxt->i4_zero_byte_cnt = 0;
318
1.77M
    ps_nal_unit = ps_nal_parse_ctxt->pv_nal_unit;
319
1.77M
    ps_nal_unit->i4_num_bufs = 0;
320
321
    /*Reset emulation prevention */
322
1.77M
    isvcd_reset_emulation_ctxt(&ps_nal_parse_ctxt->s_emulation_ctxt);
323
324
    /*Reset the NAL header prms */
325
1.77M
    isvcd_set_default_nal_prms(&ps_nal_parse_ctxt->s_nal_prms);
326
327
    /* Reset other NAL level tracking variables */
328
1.77M
    ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_FALSE;
329
330
    /*Reset NAL buffer structure*/
331
1.77M
    isvcd_nal_buf_reset(&ps_nal_parse_ctxt->s_nal_buf);
332
333
1.77M
    return (OK);
334
1.77M
}
335
336
/*****************************************************************************/
337
/*                                                                           */
338
/*  Function Name : isvcd_pic_reset_ctxt                                      */
339
/*                                                                           */
340
/*  Description   : This routine performs the picture level initialization.  */
341
/*                  This routine shall be called before parsing a access unit*/
342
/*                                                                           */
343
/*  Inputs        : pv_nal_parse_ctxt - Pointer to context structure         */
344
/*                                                                           */
345
/*  Globals       : None                                                     */
346
/*                                                                           */
347
/*  Processing    : 1. Resets the varaibles                                  */
348
/*                                                                           */
349
/*  Outputs       : Updated context structure                                */
350
/*                                                                           */
351
/*  Returns       : none                                                     */
352
/*                                                                           */
353
/*  Issues        : None                                                     */
354
/*                                                                           */
355
/*  Revision History:                                                        */
356
/*          DD MM YYYY   Author(s)       Changes                             */
357
/*          06 09 2021   Vijay           Draft                               */
358
/*                                                                           */
359
/*****************************************************************************/
360
void isvcd_pic_reset_ctxt(nal_parse_ctxt_t *ps_nal_parse_ctxt)
361
263k
{
362
263k
    WORD32 i4_status;
363
364
    /*-----------------------------------------------------------------------*/
365
    /*! Reset NAL boundary detetction logic                                  */
366
    /*-----------------------------------------------------------------------*/
367
263k
    i4_status = isvcd_nal_reset_ctxt(ps_nal_parse_ctxt);
368
369
263k
    UNUSED(i4_status);
370
371
    /*-----------------------------------------------------------------------*/
372
    /*! Reset picture boundary detctetion logic                              */
373
    /*-----------------------------------------------------------------------*/
374
263k
    ps_nal_parse_ctxt->i4_is_frst_vcl_nal_in_au = SVCD_TRUE;
375
376
    /*-----------------------------------------------------------------------*/
377
    /*! Reset VCL and non VCL NAL buffer tracking variables                  */
378
    /*-----------------------------------------------------------------------*/
379
263k
    ps_nal_parse_ctxt->pu1_non_vcl_nal_buf = ps_nal_parse_ctxt->pv_non_vcl_nal_buf;
380
263k
    ps_nal_parse_ctxt->pu1_vcl_nal_buf = ps_nal_parse_ctxt->pv_vcl_nal_buf;
381
382
    /* reset the bytes left to buffer size */
383
263k
    ps_nal_parse_ctxt->u4_bytes_left_vcl = MAX_VCL_NAL_BUFF_SIZE;
384
385
263k
    ps_nal_parse_ctxt->u4_bytes_left_non_vcl = MAX_NON_VCL_NAL_BUFF_SIZE;
386
387
    /* Offset the buffer to start of vcl data */
388
263k
    UPDATE_NAL_BUF_PTR(&ps_nal_parse_ctxt->pu1_non_vcl_nal_buf, NON_VCL_NAL,
389
263k
                       &ps_nal_parse_ctxt->u4_bytes_left_non_vcl);
390
391
263k
    UPDATE_NAL_BUF_PTR(&ps_nal_parse_ctxt->pu1_vcl_nal_buf, VCL_NAL,
392
263k
                       &ps_nal_parse_ctxt->u4_bytes_left_vcl);
393
394
    /* Reset previous field */
395
263k
    ps_nal_parse_ctxt->ps_prev_non_vcl_buf = NULL;
396
263k
    ps_nal_parse_ctxt->i4_idr_pic_err_flag = 0;
397
398
    /*-----------------------------------------------------------------------*/
399
    /*! Reset other NAL related tracking variables                           */
400
    /*-----------------------------------------------------------------------*/
401
263k
    ps_nal_parse_ctxt->i4_num_non_vcl_nals = 0;
402
403
    /* Reset the vcl nal node buffer context */
404
263k
    i4_status = isvcd_dqid_ctxt_reset(&ps_nal_parse_ctxt->s_dqid_ctxt);
405
406
    /* Reset target layer update flag */
407
263k
    ps_nal_parse_ctxt->i4_tgt_lyr_update = SVCD_TRUE;
408
263k
}
409
410
/*****************************************************************************/
411
/*                                                                           */
412
/*  Function Name : isvcd_get_nal_prms                                        */
413
/*                                                                           */
414
/*  Description   : This routine will update the nal prms                    */
415
/*  Inputs        : 1. Start of bitstream buffer containing NAL header       */
416
/*                  2. Size of the buffer                                    */
417
/*                  3. NAL prms structure                                    */
418
/*                  4. Place holder for error code                           */
419
/*                  5. Place holder for nal discard flag                     */
420
/*                  6. NAL parse context structure                           */
421
/*  Globals       : None                                                     */
422
/*  Processing    : 1. Parses the NAL header                                 */
423
/*                  2. Sets the discard flag                                 */
424
/*                  3. If NAL is not discarded and nal is VCL NAL unit then  */
425
/*                     decodes the slice prms (prefix nal units are excluded)*/
426
/*  Outputs       : Updated NAL prms structure                               */
427
/*                  Updated NAL discrd flag                                  */
428
/*                  Updates the error code if encountered with error         */
429
/*  Returns       : status                                                   */
430
/*                                                                           */
431
/*  Issues        : None                                                     */
432
/*                                                                           */
433
/*  Revision History:                                                        */
434
/*                                                                           */
435
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
436
/*         06 09 2021   Vijay           Draft                                */
437
/*                                                                           */
438
/*****************************************************************************/
439
WORD32 isvcd_get_nal_prms(UWORD8 *pu1_buf, WORD32 i4_buf_size, nal_prms_t *ps_nal_prms,
440
                          nal_prms_t *ps_prefix_nal_prms, nal_buf_t *ps_prefix_nal_buf,
441
                          UWORD32 *pu4_err_code, WORD32 *pi4_sps_pps_status,
442
                          WORD32 *pi4_nal_discard_flag, nal_parse_ctxt_t *ps_nal_parse_ctxt)
443
1.93M
{
444
1.93M
    UWORD8 *pu1_input_buf;
445
1.93M
    WORD32 i4_status;
446
1.93M
    dec_seq_params_t *ps_sps;
447
1.93M
    dec_pic_params_t *ps_pps;
448
449
1.93M
    ps_sps = ps_nal_parse_ctxt->pv_seq_prms;
450
1.93M
    ps_pps = ps_nal_parse_ctxt->pv_pic_prms;
451
452
1.93M
    *pu4_err_code = 0;
453
1.93M
    *pi4_sps_pps_status = NAL_CORRUPT_DATA;
454
455
    /* Decode the NAL header */
456
1.93M
    isvcd_dec_nal_hdr(pu1_buf, i4_buf_size, ps_nal_parse_ctxt->pv_nal_header_buf, ps_nal_prms,
457
1.93M
                      ps_prefix_nal_buf, ps_prefix_nal_prms, pu4_err_code);
458
459
    /* If encountered with error return fail */
460
1.93M
    if(0 != *pu4_err_code)
461
47.4k
    {
462
47.4k
        return (NOT_OK);
463
47.4k
    }
464
465
1.88M
    if(ACCESS_UNIT_DELIMITER_RBSP == ps_nal_prms->i4_nal_unit_type)
466
9.37k
    {
467
9.37k
        *pi4_nal_discard_flag = 1;
468
9.37k
        return OK;
469
9.37k
    }
470
471
    /* Set the discard flag */
472
1.87M
    *pi4_nal_discard_flag = isvcd_discard_nal(
473
1.87M
        (void *) ps_nal_prms, (void *) &ps_nal_parse_ctxt->s_app_attr,
474
1.87M
        (void *) &ps_nal_parse_ctxt->s_int_attr, ps_nal_parse_ctxt->i4_tgt_lyr_update);
475
476
    /* Parse the slice header if all the following */
477
    /* conditions are true                         */
478
    /* 1. NAL is a VCL NAL unit                    */
479
    /* 2. NAL is not a prefix NAL unit             */
480
    /* 3. NAL is not discarded                     */
481
1.87M
    if((NON_VCL_NAL == ps_nal_prms->i4_derived_nal_type) ||
482
616k
       (PREFIX_UNIT_NAL == ps_nal_prms->i4_nal_unit_type) || (SVCD_TRUE == *pi4_nal_discard_flag))
483
1.35M
    {
484
1.35M
        return (OK);
485
1.35M
    }
486
487
519k
    pu1_input_buf = pu1_buf;
488
519k
    pu1_input_buf += ps_nal_prms->i4_nal_header_len;
489
519k
    i4_buf_size -= ps_nal_prms->i4_nal_header_len;
490
491
519k
    i4_status =
492
519k
        isvcd_parse_part_slice_hdr(pu1_input_buf, i4_buf_size, ps_nal_parse_ctxt->pv_nal_header_buf,
493
519k
                                   ps_sps, ps_pps, ps_nal_prms, pu4_err_code, pi4_sps_pps_status);
494
495
519k
    return (i4_status);
496
1.87M
}
497
498
/*****************************************************************************/
499
/*                                                                           */
500
/*  Function Name : isvcd_compare_nal_prms                                    */
501
/*                                                                           */
502
/*  Description   : Detects the picture boundary for annex B based input     */
503
/*                  bitstream                                                */
504
/*                                                                           */
505
/*  Inputs        : 1. Pointer to NAL prms                                   */
506
/*                  2. Pass (first pass or second pass (verification)        */
507
/*                  3. Place holder for picture boundary type                */
508
/*                  4. Place holder for picture boundary status              */
509
/*                  4. pointer to bitstream extract context structure        */
510
/*  Globals       :                                                          */
511
/*  Processing    : Detects the picture bounadry as described in G.7.4.1.2.4 */
512
/*                                                                           */
513
/*  Outputs       : Detects the picture boundary                             */
514
/*                  Updates the first NAL in AU field                        */
515
/*                  Updates the picture boundary type if picture boundary is */
516
/*                      detetcetd otherwise it's value shall be ignored      */
517
/*                  Updates the picture boundary status with either          */
518
/*                  PIC_BOUNDARY_TRUE if picture boundary is detetcted or    */
519
/*                  PIC_BOUNDARY_FALSE otherwise                             */
520
/*                  Updates the error code                                   */
521
/*  Returns       : status                                                   */
522
/*                                                                           */
523
/*  Issues        : None                                                     */
524
/*                                                                           */
525
/*  Revision History:                                                        */
526
/*                                                                           */
527
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
528
/*         06 09 2021   Vijay           Draft                                */
529
/*                                                                           */
530
/*****************************************************************************/
531
WORD32 isvcd_compare_nal_prms(nal_prms_t *ps_nal_prms, WORD32 i4_pass, WORD32 i4_prev_dqid,
532
                              WORD32 *pi4_pic_bound_type, WORD32 *pi4_pic_bound_status,
533
                              nal_parse_ctxt_t *ps_nal_parse_ctxt)
534
447k
{
535
447k
    dqid_node_t *ps_dqid_node;
536
447k
    vcl_node_t *ps_vcl_node;
537
447k
    WORD32 i4_status;
538
539
    /* If DQID is lesser than the DQID of the previous */
540
    /* NAL then declare the picture boundary           */
541
447k
    *pi4_pic_bound_type = PIC_BOUND_DQID;
542
447k
    if(i4_prev_dqid > ps_nal_prms->i4_dqid)
543
43.5k
    {
544
43.5k
        *pi4_pic_bound_status = PIC_BOUNDARY_TRUE;
545
43.5k
        return (OK);
546
43.5k
    }
547
548
    /* Perform the picture boundary detection only for */
549
    /* the layers with quality id equal to 0           */
550
404k
    if((FIRST_PASS == i4_pass) && (0 != (ps_nal_prms->i4_dqid & 0x0F)))
551
0
    {
552
0
        *pi4_pic_bound_status = PIC_BOUNDARY_FALSE;
553
0
        return (OK);
554
0
    }
555
556
    /* Get the DQID node */
557
404k
    i4_status =
558
404k
        isvcd_get_dqid_node(&ps_nal_parse_ctxt->s_dqid_ctxt, (UWORD8) i4_prev_dqid, &ps_dqid_node);
559
404k
    if((OK != i4_status) || (NULL == ps_dqid_node))
560
0
    {
561
0
        return NOT_OK;
562
0
    }
563
    /* If the current slice is first slice in the layer */
564
    /* then do not compare                              */
565
404k
    if(SVCD_FALSE == ps_dqid_node->u1_valid_flag)
566
140k
    {
567
140k
        *pi4_pic_bound_status = PIC_BOUNDARY_FALSE;
568
140k
        return (OK);
569
140k
    }
570
571
263k
    *pi4_pic_bound_type = PIC_BOUND_SLICE_PRMS;
572
263k
    *pi4_pic_bound_status = PIC_BOUNDARY_TRUE;
573
263k
    ps_vcl_node = ps_dqid_node->ps_vcl_node;
574
575
    /* Compare NAL ref idc */
576
263k
    {
577
263k
        WORD32 i4_prev_ref_pic_flag;
578
263k
        WORD32 i4_cur_ref_pic_flag;
579
580
263k
        i4_prev_ref_pic_flag = (0 != ps_vcl_node->i4_nal_ref_idc);
581
263k
        i4_cur_ref_pic_flag = (0 != ps_nal_prms->i4_nal_ref_idc);
582
583
263k
        if(i4_prev_ref_pic_flag != i4_cur_ref_pic_flag)
584
37.7k
        {
585
37.7k
            return (OK);
586
37.7k
        }
587
263k
    }
588
589
    /* Compare IDR picture flag */
590
225k
    if(ps_vcl_node->i4_idr_pic_flag != ps_nal_prms->i4_idr_pic_flag)
591
22.3k
    {
592
22.3k
        return (OK);
593
22.3k
    }
594
595
    /* Compare PPS id */
596
203k
    if(ps_vcl_node->u1_pps_id != ps_nal_prms->u1_pps_id)
597
44.8k
    {
598
44.8k
        return (OK);
599
44.8k
    }
600
601
    /* Compare idr pic num */
602
158k
    if((SVCD_TRUE == ps_nal_prms->i4_idr_pic_flag) &&
603
124k
       (ps_vcl_node->i4_idr_pic_num != ps_nal_prms->i4_idr_pic_num))
604
30.2k
    {
605
30.2k
        return (OK);
606
30.2k
    }
607
608
    /* Compare frame number */
609
128k
    if(ps_vcl_node->u2_frm_num != ps_nal_prms->u2_frm_num)
610
63.7k
    {
611
63.7k
        return (OK);
612
63.7k
    }
613
614
    /* Compare poc lsb */
615
64.8k
    if(ps_dqid_node->i4_poc_lsb != ps_nal_prms->i4_poc_lsb)
616
3.43k
    {
617
3.43k
        return (OK);
618
3.43k
    }
619
620
    /* Compare delta poc bottom */
621
61.3k
    if(ps_dqid_node->i4_delta_poc_bot != ps_nal_prms->i4_delta_poc_bot)
622
3.89k
    {
623
3.89k
        return (OK);
624
3.89k
    }
625
626
    /* Compare delta poc [0] */
627
57.5k
    if(ps_dqid_node->ai4_delta_poc[0] != ps_nal_prms->ai4_delta_poc[0])
628
2.61k
    {
629
2.61k
        return (OK);
630
2.61k
    }
631
632
    /* Compare delta poc [0] */
633
54.8k
    if(ps_dqid_node->ai4_delta_poc[1] != ps_nal_prms->ai4_delta_poc[1])
634
772
    {
635
772
        return (OK);
636
772
    }
637
638
54.1k
    *pi4_pic_bound_status = PIC_BOUNDARY_FALSE;
639
54.1k
    return (OK);
640
54.8k
}
641
642
/*****************************************************************************/
643
/*                                                                           */
644
/*  Function Name : isvcd_detetct_pic_boundary_annex_b                        */
645
/*                                                                           */
646
/*  Description   : Detects the picture boundary for annex B based input     */
647
/*                  bitstream                                                */
648
/*                                                                           */
649
/*                                                                           */
650
/*  Inputs        : 1. Pointer to NAL prms                                   */
651
/*                  2. Input bitstream structure                             */
652
/*                  3. Current position of the bitstream pointer             */
653
/*                  4. Place holder for picture boundary status              */
654
/*                  5. pointer to bitstream extract context structure        */
655
/*  Globals       :                                                          */
656
/*  Processing    : It does the following                                    */
657
/*                  1. Look for next NAL.                                    */
658
/*                      If not found then declare picture boundary           */
659
/*                      Otherwsie goto next step                             */
660
/*                  2. Parse the NAL header                                  */
661
/*                      If encountered with error then declare picture       */
662
/*                      boundary                                             */
663
/*                      Otherwise goto next step                             */
664
/*                  3. If picture boundary type is                           */
665
/*                      DQID change and DQID is not equal previous DQID then */
666
/*                      declare picture boundary. Otherwise, the comapre the */
667
/*                      rest of parameters. If during comparison, if there is*/
668
/*                  4. If picture boundary type is                           */
669
/*                      SLICE PRMS CHANGE and Dependency id is not equal then*/
670
/*                      declare picture boundary. Otherwise compre rest of   */
671
/*                      parameters and goto step 5                           */
672
/*                  5. If during comparison, if there is                     */
673
/*                       * an error - then declare picture boundary          */
674
/*                       * Otherwsie if picture  boundary is not detetcted   */
675
/*                         then discard the second slice and proceed.        */
676
/*                                                                           */
677
/*  Outputs       : Detects the picture boundary                             */
678
/*                  Updates the first NAL in AU field                        */
679
/*                  Updates the picture boundary type if picture boundary is */
680
/*                      detetcetd otherwise it's value shall be ignored      */
681
/*                  Updates the error code                                   */
682
/*  Returns       : status                                                   */
683
/*                                                                           */
684
/*  Issues        : None                                                     */
685
/*                                                                           */
686
/*  Revision History:                                                        */
687
/*                                                                           */
688
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
689
/*         06 09 2021   Vijay           Draft                                */
690
/*                                                                           */
691
/*****************************************************************************/
692
WORD32 isvcd_detect_pic_boundary_annex_b(nal_prms_t *ps_nal_prms, UWORD8 *pu1_stream_buffer,
693
                                         WORD32 i4_cur_pos, WORD32 *pi4_pic_bound_status,
694
                                         nal_parse_ctxt_t *ps_nal_parse_ctxt,
695
                                         UWORD32 *pu4_num_bytes)
696
370k
{
697
370k
    UWORD32 u4_err_code;
698
370k
    WORD32 i4_zero_cnt;
699
370k
    WORD32 i4_status;
700
370k
    nal_prms_t s_nal_prms = {0};
701
370k
    nal_prms_t s_prefix_nal_prms = {0};
702
370k
    nal_buf_t s_prefix_nal_buf = {0};
703
370k
    WORD32 i4_pic_bound_type;
704
370k
    WORD32 i4_pic_bound_status;
705
370k
    UWORD8 *pu1_buf;
706
370k
    WORD32 i4_buf_size;
707
370k
    WORD32 i4_more_data_flag;
708
370k
    WORD32 i4_new_lyr_flag;
709
370k
    WORD32 i4_prev_dqid;
710
370k
    WORD32 i4_nal_discard_flag;
711
712
    /* Initializations */
713
370k
    i4_zero_cnt = 0;
714
370k
    s_prefix_nal_buf.i4_valid_flag = SVCD_FALSE;
715
370k
    *pi4_pic_bound_status = PIC_BOUNDARY_FALSE;
716
370k
    i4_new_lyr_flag = SVCD_TRUE;
717
718
    /* Get the previous layer's DQID                    */
719
370k
    if(SVCD_TRUE == ps_nal_parse_ctxt->i4_is_frst_vcl_nal_in_au)
720
140k
    {
721
140k
        ps_nal_parse_ctxt->i4_prev_dq_id = ps_nal_prms->i4_dqid;
722
140k
        ps_nal_parse_ctxt->i4_is_frst_vcl_nal_in_au = SVCD_FALSE;
723
140k
    }
724
370k
    i4_prev_dqid = ps_nal_parse_ctxt->i4_prev_dq_id;
725
370k
    ps_nal_parse_ctxt->i4_prev_dq_id = ps_nal_prms->i4_dqid;
726
727
    /* Detect the picture boundary */
728
370k
    if(ps_nal_prms->i4_dqid <= i4_prev_dqid)
729
328k
    {
730
328k
        i4_status =
731
328k
            isvcd_compare_nal_prms(ps_nal_prms, FIRST_PASS, i4_prev_dqid, &i4_pic_bound_type,
732
328k
                                   &i4_pic_bound_status, ps_nal_parse_ctxt);
733
328k
        if(OK != i4_status)
734
0
        {
735
0
            return NOT_OK;
736
0
        }
737
328k
        i4_new_lyr_flag = SVCD_FALSE;
738
739
        /* Check whether the picture boundary is detected */
740
        /* or not */
741
328k
        if(PIC_BOUNDARY_FALSE == i4_pic_bound_status)
742
184k
        {
743
184k
            return (OK);
744
184k
        }
745
746
        /* Otherwise look for next nal and compare again */
747
144k
        *pi4_pic_bound_status = PIC_BOUNDARY_TRUE;
748
144k
    }
749
750
186k
    do
751
189k
    {
752
189k
        WORD32 i4_sps_pps_corrupt_status;
753
189k
        WORD32 i4_tgt_lyr_bckup;
754
        /* If following conditions are true then there */
755
        /* is no data left to decode next NAL and hence*/
756
        /* no further processing is required           */
757
189k
        if((NAL_END != ps_nal_parse_ctxt->i4_find_nal_state) ||
758
177k
           ((WORD64) i4_cur_pos >= (WORD64) *pu4_num_bytes))
759
12.4k
        {
760
12.4k
            return (OK);
761
12.4k
        }
762
763
        /* Otherwise fill the parameters */
764
176k
        pu1_buf = pu1_stream_buffer;
765
176k
        pu1_buf += i4_cur_pos;
766
176k
        i4_buf_size = *pu4_num_bytes - i4_cur_pos;
767
768
        /* Get the NAL prms. This involves the following things*/
769
        /* 1. Decode the NAL header                            */
770
        /* 2. Set the discard flag                             */
771
        /* 3. Decode the slice header if needed                */
772
176k
        isvcd_set_default_nal_prms(&s_nal_prms);
773
774
        /* take a back up of tgt lyr update flag */
775
176k
        i4_tgt_lyr_bckup = ps_nal_parse_ctxt->i4_tgt_lyr_update;
776
777
        /* the tgt attributes should not be  updaetd while pic boundary det*/
778
176k
        ps_nal_parse_ctxt->i4_tgt_lyr_update = SVCD_FALSE;
779
780
176k
        i4_status = isvcd_get_nal_prms(pu1_buf, i4_buf_size, &s_nal_prms, &s_prefix_nal_prms,
781
176k
                                       &s_prefix_nal_buf, &u4_err_code, &i4_sps_pps_corrupt_status,
782
176k
                                       &i4_nal_discard_flag, ps_nal_parse_ctxt);
783
        /* restore back the tgt lyr update flag */
784
176k
        ps_nal_parse_ctxt->i4_tgt_lyr_update = i4_tgt_lyr_bckup;
785
        /* If the error code by the nal prms decoder then declare*/
786
        /* picture boundary                                     */
787
176k
        if(0 != u4_err_code)
788
6.50k
        {
789
6.50k
            return (OK);
790
6.50k
        }
791
792
170k
        i4_more_data_flag = SVCD_FALSE;
793
794
        /* If prefix NAL unit comes then save the nal prms*/
795
170k
        if(PREFIX_UNIT_NAL == s_nal_prms.i4_nal_unit_type)
796
2.75k
        {
797
2.75k
            UWORD32 u4_bytes_consumed;
798
2.75k
            WORD32 i4_status;
799
800
            /* If prefix NAL is not discarded then set the varaibles */
801
            /* appropriatly */
802
2.75k
            if(SVCD_FALSE == i4_nal_discard_flag)
803
1.27k
            {
804
1.27k
                s_prefix_nal_buf.i4_valid_flag = SVCD_TRUE;
805
1.27k
                memcpy(&s_prefix_nal_prms, &s_nal_prms, sizeof(nal_prms_t));
806
1.27k
            }
807
808
            /* Go to next start code */
809
2.75k
            i4_zero_cnt = 0;
810
2.75k
            u4_bytes_consumed = 0;
811
2.75k
            i4_status = isvcd_nal_find_start_code(pu1_stream_buffer, i4_cur_pos, *pu4_num_bytes,
812
2.75k
                                                  &i4_zero_cnt, &u4_bytes_consumed);
813
            /* If associated NAL unit is  not present then */
814
2.75k
            if(SC_FOUND != i4_status)
815
129
            {
816
129
                return (OK);
817
129
            }
818
2.62k
            i4_cur_pos += u4_bytes_consumed;
819
2.62k
            i4_more_data_flag = SVCD_TRUE;
820
2.62k
        }
821
170k
    } while(SVCD_TRUE == i4_more_data_flag);
822
823
    /* Do further picture boundary detection only for */
824
    /* VCL NAL unit (excliding prefix NAL unit)       */
825
167k
    if((NON_VCL_NAL == s_nal_prms.i4_derived_nal_type) ||
826
141k
       (PREFIX_UNIT_NAL == s_nal_prms.i4_nal_unit_type) || (SVCD_TRUE == i4_nal_discard_flag))
827
29.2k
    {
828
29.2k
        return (OK);
829
29.2k
    }
830
831
138k
    if(SVCD_FALSE == i4_new_lyr_flag)
832
104k
    {
833
104k
        if(PIC_BOUND_DQID == i4_pic_bound_type)
834
30.3k
        {
835
            /* If picture boundary was detetcted based on change*/
836
            /* in DQID then declare picture boundary if DQID of the third slice is different */
837
30.3k
            if(i4_prev_dqid != s_nal_prms.i4_dqid)
838
15.8k
            {
839
15.8k
                return (OK);
840
15.8k
            }
841
30.3k
        }
842
74.0k
        else
843
74.0k
        {
844
            /* If picture boundary was detetcted based on change in DQID */
845
            /* then declare picture boundary if dependency id of third slice is different */
846
74.0k
            if(PIC_BOUND_SLICE_PRMS != i4_pic_bound_type)
847
0
            {
848
0
                return NOT_OK;
849
0
            }
850
851
74.0k
            if((i4_prev_dqid & 0xF) != (s_nal_prms.i4_dqid & 0xF))
852
0
            {
853
0
                return (OK);
854
0
            }
855
74.0k
        }
856
857
88.5k
        isvcd_compare_nal_prms(&s_nal_prms, SECOND_PASS, i4_prev_dqid, &i4_pic_bound_type,
858
88.5k
                               &i4_pic_bound_status, ps_nal_parse_ctxt);
859
88.5k
        *pi4_pic_bound_status = i4_pic_bound_status;
860
861
88.5k
        if(PIC_BOUNDARY_FALSE == i4_pic_bound_status)
862
9.49k
        {
863
9.49k
            ps_nal_parse_ctxt->i4_prev_dq_id = i4_prev_dqid;
864
9.49k
        }
865
88.5k
    }
866
34.0k
    else
867
34.0k
    {
868
34.0k
        if(SVCD_TRUE != i4_new_lyr_flag)
869
0
        {
870
0
            return NOT_OK;
871
0
        }
872
        /* The NAL header is not corrupted only if any of the following conditions are true */
873
        /* 1. The DQID of the first slice differs with DQID of the third slice */
874
        /* 2. Picture boundary is detected between first slice and third slice */
875
34.0k
        if(i4_prev_dqid == s_nal_prms.i4_dqid)
876
30.7k
        {
877
30.7k
            isvcd_compare_nal_prms(&s_nal_prms, SECOND_PASS, i4_prev_dqid, &i4_pic_bound_type,
878
30.7k
                                   &i4_pic_bound_status, ps_nal_parse_ctxt);
879
            /* NAL header is corrupted and hence correct it  */
880
30.7k
            if(PIC_BOUNDARY_FALSE == i4_pic_bound_status)
881
1.10k
            {
882
1.10k
                ps_nal_prms->i4_dqid = s_nal_prms.i4_dqid;
883
1.10k
                ps_nal_prms->i4_dependency_id = s_nal_prms.i4_dependency_id;
884
1.10k
                ps_nal_prms->i4_quality_id = s_nal_prms.i4_quality_id;
885
1.10k
                ps_nal_parse_ctxt->i4_prev_dq_id = ps_nal_prms->i4_dqid;
886
1.10k
            }
887
30.7k
        }
888
34.0k
        *pi4_pic_bound_status = PIC_BOUNDARY_FALSE;
889
34.0k
    }
890
122k
    return (OK);
891
138k
}
892
893
/*****************************************************************************/
894
/*                                                                           */
895
/*  Function Name : isvcd_insert_vcl_node                                    */
896
/*                                                                           */
897
/*  Description   : This routine inserts a DQID layer into DQID list         */
898
/*                  (this will add a VCL NAL node into VCL NAL structure     */
899
/*                                                                           */
900
/*  Inputs        : 1. vcl nal structure                                     */
901
/*                  2. VCL node to be inserted                               */
902
/*  Globals       : None                                                     */
903
/*  Processing    :                                                          */
904
/*                                                                           */
905
/*  Outputs       : Updated vcl nal structure                                */
906
/*  Returns       : status                                                   */
907
/*                                                                           */
908
/*  Issues        : None                                                     */
909
/*                                                                           */
910
/*  Revision History:                                                        */
911
/*                                                                           */
912
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
913
/*         06 09 2021   Vijay      Draft                                     */
914
/*                                                                           */
915
/*****************************************************************************/
916
WORD32 isvcd_insert_vcl_node(vcl_nal_t *ps_vcl_nal, vcl_node_t *ps_vcl_node)
917
208k
{
918
208k
    vcl_node_t *ps_bot_node;
919
208k
    vcl_node_t *ps_top_node;
920
208k
    vcl_node_t *ps_node;
921
208k
    WORD32 i4_rqrd_dqid;
922
923
    /* sanity checks */
924
208k
    if((NULL == ps_vcl_nal) || (NULL == ps_vcl_node))
925
0
    {
926
0
        return NOT_OK;
927
0
    }
928
929
208k
    i4_rqrd_dqid = (ps_vcl_node->i4_dependency_id << 4);
930
208k
    i4_rqrd_dqid += ps_vcl_node->i4_quality_id;
931
208k
    ps_node = ps_vcl_nal->ps_bot_node;
932
933
    /* Search for node which has a DQID which is */
934
    /* lesser than taht of the node to inserted  */
935
270k
    while(NULL != ps_node)
936
64.9k
    {
937
64.9k
        WORD32 i4_dqid;
938
939
64.9k
        i4_dqid = (ps_node->i4_dependency_id << 4);
940
64.9k
        i4_dqid += ps_node->i4_quality_id;
941
942
        /* If we get a DQID which is greater than*/
943
        /* the DQID of the  node to be inserted  */
944
        /* then break out of the loop and update */
945
64.9k
        if(i4_dqid > i4_rqrd_dqid)
946
2.99k
        {
947
2.99k
            ps_bot_node = ps_node->ps_bot_node;
948
2.99k
            break;
949
2.99k
        }
950
951
61.9k
        ps_node = ps_node->ps_top_node;
952
61.9k
    }
953
954
    /* If none of the nodes in the list have DQId */
955
    /* greater than the node to be inserted then  */
956
    /* bottom node will be top most node          */
957
208k
    if(NULL == ps_node)
958
205k
    {
959
205k
        ps_bot_node = ps_vcl_nal->ps_top_node;
960
205k
    }
961
962
    /* Insert the node into DQID list */
963
208k
    if(NULL != ps_bot_node)
964
61.9k
    {
965
61.9k
        ps_top_node = ps_bot_node->ps_top_node;
966
61.9k
    }
967
146k
    else
968
146k
    {
969
146k
        ps_top_node = ps_vcl_nal->ps_bot_node;
970
146k
    }
971
972
    /* Join previous node and specified node */
973
208k
    if(NULL != ps_bot_node)
974
61.9k
    {
975
61.9k
        ps_bot_node->ps_top_node = ps_vcl_node;
976
61.9k
    }
977
146k
    else
978
146k
    {
979
146k
        ps_vcl_nal->ps_bot_node = ps_vcl_node;
980
146k
    }
981
208k
    ps_vcl_node->ps_bot_node = ps_bot_node;
982
983
    /* Join next node and specified node */
984
208k
    if(NULL != ps_top_node)
985
2.99k
    {
986
2.99k
        ps_top_node->ps_bot_node = ps_vcl_node;
987
2.99k
    }
988
205k
    else
989
205k
    {
990
205k
        ps_vcl_nal->ps_top_node = ps_vcl_node;
991
205k
    }
992
208k
    ps_vcl_node->ps_top_node = ps_top_node;
993
994
208k
    return (OK);
995
208k
}
996
/*****************************************************************************/
997
/*                                                                           */
998
/*  Function Name : isvcd_update_nal_ctxt                                     */
999
/*                                                                           */
1000
/*  Description   : Updates the vcl nal or non vcl structures.               */
1001
/*                                                                           */
1002
/*  Inputs        : ps_nal_parse_ctxt - Bitstream extract context structure  */
1003
/*                  vcl nal structure pointer                                */
1004
/*                  NON vcl nal structure                                    */
1005
/*                                                                           */
1006
/*  Globals       : None                                                     */
1007
/*                                                                           */
1008
/*  Processing    : If VCL NAL then adds a node to DQID list                 */
1009
/*                  otherwise adds information to non vcl structure          */
1010
/*                                                                           */
1011
/*  Outputs       : None                                                     */
1012
/*                                                                           */
1013
/*  Returns       : None                                                     */
1014
/*                                                                           */
1015
/*  Issues        : None                                                     */
1016
/*                                                                           */
1017
/*  Revision History:                                                        */
1018
/*          DD MM YYYY   Author(s)       Changes                             */
1019
/*          06 09 2021   Vijay           Draft                               */
1020
/*                                                                           */
1021
/*****************************************************************************/
1022
void isvcd_update_nal_ctxt(nal_parse_ctxt_t *ps_nal_parse_ctxt, vcl_nal_t *ps_vcl_nal,
1023
                           non_vcl_nal_t *ps_non_vcl_nal)
1024
1.46M
{
1025
    /*! If current NAL is VCL NAL then
1026
          - Insert a VCL node into DQID list if neccessery
1027
          - update the information part of NAL unit */
1028
    /*! Otherwise, populate the buffer parameters into non vcl output
1029
    structure */
1030
1.46M
    nal_prms_t *ps_nal_prms;
1031
1.46M
    nal_buf_t *ps_nal_buf, *ps_prefix_nal_buf;
1032
1033
1.46M
    ps_nal_prms = &ps_nal_parse_ctxt->s_nal_prms;
1034
1.46M
    ps_nal_prms = &ps_nal_parse_ctxt->s_nal_prms;
1035
1.46M
    ps_nal_buf = &ps_nal_parse_ctxt->s_nal_buf;
1036
1.46M
    ps_prefix_nal_buf = &ps_nal_parse_ctxt->s_prefix_nal_buf;
1037
1038
    /* If prefix NAL unit then          */
1039
    /* - calculate the SODB length      */
1040
1.46M
    if(PREFIX_UNIT_NAL == ps_nal_prms->i4_nal_unit_type)
1041
2.35k
    {
1042
        /* Since we consume the zeroes in start code also */
1043
        /* size has to reduced                            */
1044
2.35k
        if(NAL_END == ps_nal_parse_ctxt->i4_find_nal_state)
1045
2.35k
        {
1046
2.35k
            ps_prefix_nal_buf->i4_buf_size -= 2;
1047
2.35k
        }
1048
1049
2.35k
        ps_prefix_nal_buf->u4_max_bits =
1050
2.35k
            isvcd_nal_rbsp_to_sodb(ps_prefix_nal_buf->pu1_buf, ps_prefix_nal_buf->i4_buf_size, 0);
1051
2.35k
        memcpy(&ps_nal_parse_ctxt->s_prefix_nal_prms, &ps_nal_parse_ctxt->s_nal_prms,
1052
2.35k
               sizeof(nal_prms_t));
1053
2.35k
        return;
1054
2.35k
    }
1055
1056
1.46M
    if(ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode)
1057
1.46M
    {
1058
        /* Since we consume the zeroes in start code also */
1059
        /* size has to reduced                            */
1060
1.46M
        if(NAL_END == ps_nal_parse_ctxt->i4_find_nal_state)
1061
1.46M
        {
1062
1.46M
            ps_nal_buf->i4_buf_size -= 2;
1063
1.46M
        }
1064
1.46M
    }
1065
1066
1.46M
    if(VCL_NAL == ps_nal_prms->i4_derived_nal_type)
1067
235k
    {
1068
235k
        dqid_node_t *ps_dqid_node;
1069
235k
        vcl_node_t *ps_node;
1070
235k
        WORD32 i4_status;
1071
235k
        dec_pic_params_t *ps_pps;
1072
235k
        dec_seq_params_t *ps_sps;
1073
235k
        vcl_buf_hdr_t *ps_vcl_hdr;
1074
235k
        vcl_buf_hdr_t *ps_prev_vcl_hdr;
1075
235k
        WORD32 i4_slice_offset;
1076
1077
235k
        ps_sps = ps_nal_parse_ctxt->pv_seq_prms;
1078
235k
        ps_sps += ps_nal_prms->u1_sps_id;
1079
235k
        ps_pps = ps_nal_parse_ctxt->pv_pic_prms;
1080
235k
        ps_pps += ps_nal_prms->u1_pps_id;
1081
1082
        /* Get the VCL NAL node */
1083
235k
        i4_status = isvcd_get_dqid_node(&ps_nal_parse_ctxt->s_dqid_ctxt,
1084
235k
                                        (UWORD8) ps_nal_parse_ctxt->i4_prev_dq_id, &ps_dqid_node);
1085
1086
235k
        ps_node = ps_dqid_node->ps_vcl_node;
1087
1088
235k
        if(NULL == ps_node)
1089
0
        {
1090
            /* no active node has been acquired */
1091
0
            return;
1092
0
        }
1093
1094
        /*-------------------------------------------------------------------*/
1095
        /* The DQID list updation should happen only once in a               */
1096
        /* layer. Hence a flag used to determine whether the                 */
1097
        /* layer is already initialized or not.                              */
1098
        /*-------------------------------------------------------------------*/
1099
235k
        if(SVCD_FALSE == ps_dqid_node->u1_valid_flag)
1100
181k
        {
1101
            /* Update the DQID node */
1102
181k
            ps_dqid_node->u1_valid_flag = SVCD_TRUE;
1103
181k
            ps_dqid_node->u1_dqid = (ps_nal_prms->i4_dependency_id << 4);
1104
181k
            ps_dqid_node->u1_dqid += ps_nal_prms->i4_quality_id;
1105
181k
            ps_dqid_node->i4_poc_lsb = ps_nal_prms->i4_poc_lsb;
1106
181k
            ps_dqid_node->i4_delta_poc_bot = ps_nal_prms->i4_delta_poc_bot;
1107
181k
            ps_dqid_node->ai4_delta_poc[0] = ps_nal_prms->ai4_delta_poc[0];
1108
181k
            ps_dqid_node->ai4_delta_poc[1] = ps_nal_prms->ai4_delta_poc[1];
1109
1110
            /* Update the VCL node */
1111
181k
            ps_node->i4_quality_id = ps_nal_prms->i4_quality_id;
1112
181k
            ps_node->i4_dependency_id = ps_nal_prms->i4_dependency_id;
1113
181k
            ps_node->i4_temporal_id = ps_nal_prms->i4_temporal_id;
1114
181k
            ps_node->i4_priority_id = ps_nal_prms->i4_priority_id;
1115
181k
            ps_node->i4_idr_pic_flag = ps_nal_prms->i4_idr_pic_flag;
1116
181k
            ps_node->i4_nal_ref_idc = ps_nal_prms->i4_nal_ref_idc;
1117
181k
            ps_node->i4_nal_unit_type = ps_nal_prms->i4_nal_unit_type;
1118
181k
            ps_node->i4_use_ref_base = ps_nal_prms->i4_use_ref_base_pic_flag;
1119
181k
            ps_node->i4_nal_ref_idc = ps_nal_prms->i4_nal_ref_idc;
1120
181k
            ps_node->u1_sps_id = ps_nal_prms->u1_sps_id;
1121
181k
            ps_node->u1_pps_id = ps_nal_prms->u1_pps_id;
1122
181k
            ps_node->u2_frm_num = ps_nal_prms->u2_frm_num;
1123
181k
            ps_node->i4_idr_pic_num = ps_nal_prms->i4_idr_pic_num;
1124
181k
            ps_node->i4_num_slices = 0;
1125
181k
            ps_node->u1_acc_no_int_pred = 1;
1126
181k
            if(0 == ps_sps->u1_pic_order_cnt_type)
1127
146k
            {
1128
146k
                ps_node->i4_poc_syntax = ps_nal_prms->i4_poc_lsb;
1129
146k
            }
1130
34.7k
            else
1131
34.7k
            {
1132
34.7k
                ps_node->i4_poc_syntax = ps_nal_prms->ai4_delta_poc[0];
1133
34.7k
            }
1134
1135
            /* Insert the node into DQID list */
1136
181k
            i4_status = isvcd_insert_vcl_node(ps_vcl_nal, ps_node);
1137
181k
            if(OK != i4_status)
1138
0
            {
1139
0
                return;
1140
0
            }
1141
1142
            /* Reset the previous field */
1143
181k
            ps_nal_parse_ctxt->ps_prev_vcl_buf = NULL;
1144
181k
            ps_node->ps_first_vcl_nal = NULL;
1145
181k
        }
1146
1147
        /* Update accumulated no inter layer prediction */
1148
235k
        ps_node->u1_acc_no_int_pred &= (UWORD8) ps_nal_prms->i4_no_int_lyr_pred;
1149
1150
        /****************** Fill VCL BUF header ************/
1151
1152
        /* If prefix NAL unit is present then update  */
1153
        /* the following                              */
1154
        /* - Start of buffer header will be present in*/
1155
        /*   before the start of prefix NAL unit's SODB*/
1156
        /*   data.                                    */
1157
        /*   Note: If memeory left for buffer header  */
1158
        /*   of the prefix NAL unit will have junk    */
1159
        /*   values                                   */
1160
1161
235k
        if(NULL == ps_nal_buf->pu1_buf)
1162
0
        {
1163
            /* no nal needs to be added into the list hence return */
1164
0
            return;
1165
0
        }
1166
235k
        else
1167
235k
        {
1168
235k
            ps_vcl_hdr = (vcl_buf_hdr_t *) (ps_nal_buf->pu1_buf - GET_NAL_BUF_INC(VCL_NAL));
1169
235k
        }
1170
1171
235k
        i4_slice_offset = 0;
1172
235k
        if(SVCD_TRUE == ps_prefix_nal_buf->i4_valid_flag)
1173
638
        {
1174
638
            ps_vcl_hdr = (vcl_buf_hdr_t *) (ps_prefix_nal_buf->pu1_buf - GET_NAL_BUF_INC(VCL_NAL));
1175
638
            i4_slice_offset = ps_nal_buf->pu1_buf - ps_prefix_nal_buf->pu1_buf;
1176
638
        }
1177
1178
        /* Update the next field of the previous nal  */
1179
        /* unit or if it is the first NAL then update */
1180
        /* VCL node information                       */
1181
235k
        ps_prev_vcl_hdr = ps_nal_parse_ctxt->ps_prev_vcl_buf;
1182
235k
        if(NULL != ps_prev_vcl_hdr)
1183
53.9k
        {
1184
53.9k
            ps_prev_vcl_hdr->ps_next = ps_vcl_hdr;
1185
53.9k
        }
1186
181k
        else
1187
181k
        {
1188
181k
            ps_node->ps_first_vcl_nal = ps_vcl_hdr;
1189
181k
        }
1190
1191
        /* Fill the VCL buffer header */
1192
235k
        ps_vcl_hdr->ps_next = NULL;
1193
235k
        ps_vcl_hdr->i4_no_int_lyr_pred = ps_nal_prms->i4_no_int_lyr_pred;
1194
235k
        ps_vcl_hdr->i4_first_mb_addr = ps_nal_prms->u4_first_mb_addr;
1195
235k
        ps_vcl_hdr->u4_prefix_nal_bits = ps_prefix_nal_buf->u4_max_bits;
1196
235k
        ps_vcl_hdr->i4_slice_offset = 0;
1197
235k
        ps_vcl_hdr->i4_buf_offset = GET_NAL_BUF_INC(VCL_NAL);
1198
235k
        ps_vcl_hdr->i4_slice_offset = i4_slice_offset;
1199
1200
        /* Determine max num bits */
1201
235k
        ps_nal_buf->u4_max_bits = isvcd_nal_rbsp_to_sodb(
1202
235k
            ps_nal_buf->pu1_buf, ps_nal_buf->i4_buf_size, ps_pps->u1_entropy_coding_mode);
1203
235k
        ps_vcl_hdr->u4_max_bits = ps_nal_buf->u4_max_bits;
1204
1205
        /* Updates */
1206
235k
        ps_nal_parse_ctxt->ps_prev_vcl_buf = ps_vcl_hdr;
1207
235k
        ps_node->i4_num_slices += 1;
1208
235k
    }
1209
    /*-----------------------------------------------------------------------*/
1210
    /* If start of NAL and if its a NON VCL NAL then update the              */
1211
    /* start address of the NON VCL NAL                                      */
1212
    /*-----------------------------------------------------------------------*/
1213
1.22M
    else
1214
1.22M
    {
1215
1.22M
        non_vcl_buf_hdr_t *ps_non_vcl_buf_hdr;
1216
1.22M
        non_vcl_buf_hdr_t *ps_prev_non_vcl_buf_hdr;
1217
1218
1.22M
        ps_non_vcl_buf_hdr =
1219
1.22M
            (non_vcl_buf_hdr_t *) (ps_nal_buf->pu1_buf - GET_NAL_BUF_INC(NON_VCL_NAL));
1220
1221
        /* Update NON VCL structure */
1222
1.22M
        ps_non_vcl_buf_hdr->i4_nal_unit_type = ps_nal_prms->i4_nal_unit_type;
1223
1.22M
        ps_non_vcl_buf_hdr->ps_next = NULL;
1224
1.22M
        ps_non_vcl_buf_hdr->i4_buf_offset = GET_NAL_BUF_INC(NON_VCL_NAL);
1225
1.22M
        ps_non_vcl_buf_hdr->i4_buf_size = ps_nal_buf->i4_buf_size;
1226
1227
        /* Update the next field and first non vcl fields of */
1228
        /* non vcl buffer header structure and non vcl       */
1229
        /* structure respectively                            */
1230
1.22M
        ps_prev_non_vcl_buf_hdr = ps_nal_parse_ctxt->ps_prev_non_vcl_buf;
1231
1.22M
        if(NULL != ps_prev_non_vcl_buf_hdr)
1232
1.14M
        {
1233
1.14M
            ps_prev_non_vcl_buf_hdr->ps_next = ps_non_vcl_buf_hdr;
1234
1.14M
        }
1235
80.4k
        else
1236
80.4k
        {
1237
80.4k
            ps_non_vcl_nal->ps_first_non_vcl_nal = ps_non_vcl_buf_hdr;
1238
80.4k
        }
1239
1240
        /* Updates */
1241
1.22M
        ps_nal_parse_ctxt->i4_num_non_vcl_nals += 1;
1242
1.22M
        ps_non_vcl_nal->i4_num_non_vcl_nals = ps_nal_parse_ctxt->i4_num_non_vcl_nals;
1243
1.22M
        ps_nal_parse_ctxt->ps_prev_non_vcl_buf = ps_non_vcl_buf_hdr;
1244
1.22M
    }
1245
1.46M
}
1246
1247
/*****************************************************************************/
1248
/*                                                                           */
1249
/*  Function Name : isvcd_idr_err_hdlr                                        */
1250
/*                                                                           */
1251
/*  Description   : This routine shall be invoked to handle a case when a    */
1252
/*                  slice is an IDR picture and it is referring to corrupted */
1253
/*                  SPS or PPS                                               */
1254
/*                                                                           */
1255
/*  Inputs        : 1. VCL NAL structure                                     */
1256
/*                  2. NAL paramters                                         */
1257
/*                  3. NAL parse context structure                           */
1258
/*  Globals       : None                                                     */
1259
/*  Processing    : It will set the highest available dependency id below the*/
1260
/*                  current dependency id as the target layer. Also sets the */
1261
/*                  update target layer flag to FALSE as target layer need not*/
1262
/*                  adopt to the application's target layer in the current   */
1263
/*                  picture                                                  */
1264
/*                                                                           */
1265
/*  Outputs       : Updated vcl nal structure                                */
1266
/*                  Updated internal target layer attributes                 */
1267
/*                  Updated target layer update flag                         */
1268
/*  Returns       : status                                                   */
1269
/*                                                                           */
1270
/*  Issues        : None                                                     */
1271
/*                                                                           */
1272
/*  Revision History:                                                        */
1273
/*                                                                           */
1274
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1275
/*         06 09 2021   Vijay           Draft                                */
1276
/*                                                                           */
1277
/*****************************************************************************/
1278
WORD32 isvcd_idr_err_hdlr(vcl_nal_t *ps_vcl_nal, nal_prms_t *ps_nal_prms,
1279
                          nal_parse_ctxt_t *ps_nal_parse_ctxt)
1280
0
{
1281
0
    vcl_node_t *ps_vcl_node;
1282
0
    target_lyr_attr_t *ps_int_attr;
1283
1284
    /* sanity checks */
1285
0
    if((NULL == ps_vcl_nal) || (NULL == ps_nal_prms) || (NULL == ps_nal_parse_ctxt))
1286
0
    {
1287
0
        return NOT_OK;
1288
0
    }
1289
0
    UNUSED(ps_nal_prms);
1290
1291
    /* Initializations */
1292
0
    ps_vcl_node = ps_vcl_nal->ps_top_node;
1293
0
    ps_int_attr = &ps_nal_parse_ctxt->s_int_attr;
1294
1295
    /* the highest node present in the depedency list will be         */
1296
    /* considered as targte layer and appropriate params will be used */
1297
1298
    /* If not found then delete all the layers in the AU */
1299
0
    if(NULL == ps_vcl_node)
1300
0
    {
1301
0
        ps_int_attr->i4_dependency_id = -1;
1302
0
        ps_int_attr->i4_quality_id = MAX_QUALITY_ID;
1303
0
    }
1304
0
    else
1305
0
    {
1306
        /* Set the target layer */
1307
0
        ps_int_attr->i4_dependency_id = ps_vcl_node->i4_dependency_id;
1308
0
        ps_int_attr->i4_quality_id = ps_vcl_node->i4_quality_id;
1309
0
    }
1310
1311
0
    return (OK);
1312
0
}
1313
/*****************************************************************************/
1314
/*                                                                           */
1315
/*  Function Name :svcd_refine_dqid_list                                     */
1316
/*                                                                           */
1317
/*  Description   : Inserts the dummy nodes for each dependency id which     */
1318
/*                  have not come in the bitstream                           */
1319
/*                                                                           */
1320
/*  Inputs        :VCL NAL structure                                         */
1321
/*                  NAL parse context structure                              */
1322
/*  Globals       : None                                                     */
1323
/*  Processing    : For each dependency id till the target dependency id     */
1324
/*                  - If layer already exists (came in the bitstream) then   */
1325
/*                    do nothing                                             */
1326
/*                  - Otherwsie insert a dummy node                          */
1327
/*                                                                           */
1328
/*  Outputs       : Updated VCL NAL structure                                */
1329
/*  Returns       : None                                                     */
1330
/*                                                                           */
1331
/*  Issues        : None                                                     */
1332
/*                                                                           */
1333
/*  Revision History:                                                        */
1334
/*                                                                           */
1335
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1336
/*         06 09 2021   Vijay           Draft                                */
1337
/*                                                                           */
1338
/*****************************************************************************/
1339
WORD32 isvcd_refine_dqid_list(vcl_nal_t *ps_vcl_nal, nal_parse_ctxt_t *ps_nal_parse_ctxt)
1340
141k
{
1341
141k
    vcl_node_t *ps_node;
1342
141k
    target_lyr_attr_t *ps_int_attr;
1343
141k
    dqid_ctxt_t *ps_dqid_ctxt;
1344
141k
    UWORD8 u1_dep_id;
1345
141k
    WORD32 i4_status;
1346
141k
    WORD32 i4_dep_id;
1347
1348
141k
    ps_int_attr = &ps_nal_parse_ctxt->s_int_attr;
1349
141k
    ps_dqid_ctxt = &ps_nal_parse_ctxt->s_dqid_ctxt;
1350
141k
    i4_dep_id = -1;
1351
1352
346k
    for(u1_dep_id = 0; u1_dep_id <= ps_int_attr->i4_dependency_id; u1_dep_id++)
1353
205k
    {
1354
205k
        dqid_node_t *ps_dqid_node;
1355
1356
        /* Get a DQID node */
1357
205k
        i4_status = isvcd_get_dqid_node(ps_dqid_ctxt, (UWORD8) (u1_dep_id << 4), &ps_dqid_node);
1358
205k
        if(OK != i4_status)
1359
0
        {
1360
0
            return NOT_OK;
1361
0
        }
1362
1363
        /* If node does not exist already then insert a dummy node */
1364
205k
        if(SVCD_FALSE == ps_dqid_node->u1_valid_flag)
1365
27.8k
        {
1366
27.8k
            if(1 == ps_nal_parse_ctxt->i4_idr_pic_err_flag)
1367
316
            {
1368
316
                ps_int_attr->i4_dependency_id = i4_dep_id;
1369
316
                ps_int_attr->i4_quality_id = MAX_QUALITY_ID;
1370
1371
                /* remove all the nodes from dependency list */
1372
                /* which are at higher dependency than the   */
1373
                /* value set in init attributes              */
1374
457
                while(NULL != ps_vcl_nal->ps_top_node)
1375
221
                {
1376
                    /* if higher dependency */
1377
221
                    if(ps_vcl_nal->ps_top_node->i4_dependency_id > i4_dep_id)
1378
141
                    {
1379
141
                        ps_vcl_nal->ps_top_node = ps_vcl_nal->ps_top_node->ps_bot_node;
1380
141
                    }
1381
80
                    else
1382
80
                    {
1383
80
                        break;
1384
80
                    }
1385
221
                }
1386
1387
                /* if no node exists in the dependency list */
1388
316
                if(NULL == ps_vcl_nal->ps_top_node)
1389
236
                {
1390
236
                    ps_vcl_nal->ps_bot_node = NULL;
1391
236
                }
1392
80
                else if(ps_vcl_nal->ps_top_node == ps_vcl_nal->ps_bot_node)
1393
80
                {
1394
                    /* if a single node exists */
1395
80
                    ps_vcl_nal->ps_top_node->ps_bot_node = NULL;
1396
80
                    ps_vcl_nal->ps_bot_node->ps_top_node = NULL;
1397
80
                }
1398
1399
316
                return (NOT_OK);
1400
316
            }
1401
27.4k
            else
1402
27.4k
            {
1403
27.4k
                ps_dqid_node->u1_valid_flag = SVCD_TRUE;
1404
27.4k
                ps_dqid_node->u1_dqid = (u1_dep_id << 4);
1405
1406
                /* Fill VCL node information */
1407
27.4k
                ps_node = ps_dqid_node->ps_vcl_node;
1408
27.4k
                ps_node->i4_dependency_id = u1_dep_id;
1409
27.4k
                ps_node->i4_quality_id = 0;
1410
27.4k
                ps_node->ps_first_vcl_nal = NULL;
1411
27.4k
            }
1412
1413
            /* Insert node into DQID list */
1414
27.4k
            i4_status = isvcd_insert_vcl_node(ps_vcl_nal, ps_node);
1415
27.4k
            if(OK != i4_status)
1416
0
            {
1417
0
                return (NOT_OK);
1418
0
            }
1419
27.4k
        }
1420
1421
204k
        i4_dep_id++;
1422
204k
    } /* End of loop over all the dependency id */
1423
141k
    return (OK);
1424
141k
}
1425
1426
/*****************************************************************************/
1427
/*                                                                           */
1428
/*  Function Name : isvcd_nal_parse_set_target_attr                          */
1429
/*                                                                           */
1430
/*  Description   : Sets the target layer attributes                         */
1431
/*                                                                           */
1432
/*  Inputs        : i4_target_quality_id - Target layer quality id           */
1433
/*                  i4_target_dependency_id - Target layer dependency id     */
1434
/*                  i4_target_temporal_id - Target layer temporal id         */
1435
/*                  i4_target_priority_id - Target layer priority id         */
1436
/*                  pv_nal_parse_ctxt - Pointer module handle                */
1437
/*                                                                           */
1438
/*  Globals       : None                                                     */
1439
/*                                                                           */
1440
/*  Processing    : None                                                     */
1441
/*                                                                           */
1442
/*  Outputs       : None                                                     */
1443
/*                                                                           */
1444
/*  Returns       : None                                                     */
1445
/*                                                                           */
1446
/*  Issues        : None                                                     */
1447
/*                                                                           */
1448
/*  Revision History:                                                        */
1449
/*          DD MM YYYY   Author(s)       Changes                             */
1450
/*          06 09 2021   Vijay           Draft                               */
1451
/*                                                                           */
1452
/*****************************************************************************/
1453
1454
WORD32 isvcd_nal_parse_set_target_attr(WORD32 i4_target_quality_id, WORD32 i4_target_dependency_id,
1455
                                       WORD32 i4_target_temporal_id, WORD32 i4_target_priority_id,
1456
                                       void *pv_nal_parse_ctxt)
1457
20.4k
{
1458
20.4k
    nal_parse_ctxt_t *ps_nal_parse_ctxt;
1459
20.4k
    target_lyr_attr_t *ps_app_attr;
1460
1461
20.4k
    if((i4_target_quality_id > MAX_QUALITY_ID) || (i4_target_dependency_id > MAX_DEPENDENCY_ID))
1462
0
    {
1463
0
        return IV_FAIL;
1464
0
    }
1465
1466
20.4k
    ps_nal_parse_ctxt = (nal_parse_ctxt_t *) pv_nal_parse_ctxt;
1467
20.4k
    ps_app_attr = &ps_nal_parse_ctxt->s_app_attr;
1468
1469
    /*-----------------------------------------------------------------------*/
1470
    /*! Register the target information into context structure               */
1471
    /*-----------------------------------------------------------------------*/
1472
20.4k
    ps_app_attr->i4_quality_id = i4_target_quality_id;
1473
20.4k
    ps_app_attr->i4_dependency_id = i4_target_dependency_id;
1474
20.4k
    ps_app_attr->i4_temporal_id = i4_target_temporal_id;
1475
20.4k
    ps_app_attr->i4_priority_id = i4_target_priority_id;
1476
20.4k
    return IV_SUCCESS;
1477
20.4k
}
1478
1479
/*****************************************************************************/
1480
/*                                                                           */
1481
/*  Function Name : isvcd_nal_parse_reset_ctxt                               */
1482
/*                                                                           */
1483
/*  Description   : Initializes the bitstream extraction module. Should be   */
1484
/*                  called once in a sequence                                */
1485
/*                                                                           */
1486
/*  Inputs        : i4_input_bitstream_mode - Input bitstream mode RFC or    */
1487
/*                      Annex B                                              */
1488
/*                  i4_input_mode - Input mode - Full input mode or partial  */
1489
/*                      input mode                                           */
1490
/*                  pv_nal_parse_ctxt - Module handle                        */
1491
/*                                                                           */
1492
/*  Globals       : None                                                     */
1493
/*                                                                           */
1494
/*  Processing    : None                                                     */
1495
/*                                                                           */
1496
/*  Outputs       : None                                                     */
1497
/*                                                                           */
1498
/*  Returns       : None                                                     */
1499
/*                                                                           */
1500
/*  Issues        : None                                                     */
1501
/*                                                                           */
1502
/*  Revision History:                                                        */
1503
/*          DD MM YYYY   Author(s)       Changes                             */
1504
/*          06 09 2021   Vijay           Draft                               */
1505
/*                                                                           */
1506
/*****************************************************************************/
1507
1508
void isvcd_nal_parse_reset_ctxt(WORD32 i4_input_bitstream_mode, WORD32 i4_input_mode,
1509
                                void *pv_nal_parse_ctxt)
1510
20.4k
{
1511
20.4k
    nal_parse_ctxt_t *ps_nal_parse_ctxt = (nal_parse_ctxt_t *) pv_nal_parse_ctxt;
1512
20.4k
    UNUSED(i4_input_mode);
1513
1514
    /*-----------------------------------------------------------------------*/
1515
    /*! Set the input bitstream mode of context structure                    */
1516
    /*-----------------------------------------------------------------------*/
1517
20.4k
    switch(i4_input_bitstream_mode)
1518
20.4k
    {
1519
20.4k
        case ANNEX_B:
1520
20.4k
        case NON_ANNEX_B:
1521
20.4k
            break;
1522
0
        default:
1523
0
            break;
1524
20.4k
    }
1525
1526
20.4k
    ps_nal_parse_ctxt->i4_input_bitstream_mode = i4_input_bitstream_mode;
1527
1528
    /*-----------------------------------------------------------------------*/
1529
    /*! Perform the picture level initialization                             */
1530
    /*-----------------------------------------------------------------------*/
1531
20.4k
    isvcd_pic_reset_ctxt(pv_nal_parse_ctxt);
1532
1533
    /* Reset the prefix nal unit buffer structure */
1534
20.4k
    isvcd_nal_buf_reset(&ps_nal_parse_ctxt->s_prefix_nal_buf);
1535
1536
    /*-----------------------------------------------------------------------*/
1537
    /*! Reset other varaibles                                                */
1538
    /*-----------------------------------------------------------------------*/
1539
20.4k
    ps_nal_parse_ctxt->i4_dec_frst_sc_flag = SVCD_TRUE;
1540
20.4k
    ps_nal_parse_ctxt->i4_eos_flag = SVCD_FALSE;
1541
20.4k
    ps_nal_parse_ctxt->u1_pic_boundary_aud_flag = 0;
1542
20.4k
    ps_nal_parse_ctxt->u4_bytes_left = 0;
1543
1544
    /* Reset target layer attributes */
1545
20.4k
    {
1546
20.4k
        target_lyr_attr_t *ps_app_attr;
1547
20.4k
        target_lyr_attr_t *ps_int_attr;
1548
1549
20.4k
        ps_app_attr = &ps_nal_parse_ctxt->s_app_attr;
1550
20.4k
        ps_int_attr = &ps_nal_parse_ctxt->s_int_attr;
1551
1552
20.4k
        ps_app_attr->i4_dependency_id = MAX_DEPENDENCY_ID;
1553
20.4k
        ps_app_attr->i4_quality_id = MAX_QUALITY_ID;
1554
20.4k
        ps_app_attr->i4_temporal_id = MAX_TEMPORAL_ID;
1555
20.4k
        ps_app_attr->i4_priority_id = MAX_PRIORITY_ID;
1556
1557
20.4k
        ps_int_attr->i4_dependency_id = -1;
1558
20.4k
        ps_int_attr->i4_quality_id = MAX_QUALITY_ID;
1559
20.4k
        ps_int_attr->i4_temporal_id = 0;
1560
20.4k
        ps_int_attr->i4_priority_id = MAX_PRIORITY_ID;
1561
20.4k
    }
1562
20.4k
}
1563
1564
/*****************************************************************************/
1565
/*                                                                           */
1566
/*  Function Name : isvcd_nal_parse_partial_signal_eos                       */
1567
/*                                                                           */
1568
/*  Description   : Does processing when end of stream occurs for partial    */
1569
/*                  input mode of operation.                                 */
1570
/*                                                                           */
1571
/*  Inputs        : pv_nal_parse_ctxt - bitstream extract context structure  */
1572
/*                  pv_out_vcl_nal - vcl nal structure                       */
1573
/*                  pv_out_non_vcl_nal - non vcl nal structure               */
1574
/*                                                                           */
1575
/*  Globals       : None                                                     */
1576
/*                                                                           */
1577
/*  Processing    : None                                                     */
1578
/*                                                                           */
1579
/*  Outputs       : None                                                     */
1580
/*                                                                           */
1581
/*  Returns       : Picture boundary detetcted or not                        */
1582
/*                                                                           */
1583
/*  Issues        : None                                                     */
1584
/*                                                                           */
1585
/*  Revision History:                                                        */
1586
/*          DD MM YYYY   Author(s)       Changes                             */
1587
/*          06 09 2021   Vijay           Draft                               */
1588
/*                                                                           */
1589
/*****************************************************************************/
1590
1591
WORD32 isvcd_nal_parse_partial_signal_eos(void *pv_nal_parse_ctxt, void *pv_out_vcl_nal,
1592
                                          void *pv_out_non_vcl_nal)
1593
20
{
1594
20
    nal_parse_ctxt_t *ps_nal_parse_ctxt;
1595
20
    vcl_nal_t *ps_vcl_nal;
1596
1597
20
    ps_nal_parse_ctxt = (nal_parse_ctxt_t *) pv_nal_parse_ctxt;
1598
20
    ps_vcl_nal = (vcl_nal_t *) pv_out_vcl_nal;
1599
1600
    /* for RFC mode */
1601
20
    if(NON_ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode)
1602
0
    {
1603
        /* Reset the end of stream flag so that in    */
1604
0
        ps_nal_parse_ctxt->i4_eos_flag = SVCD_TRUE;
1605
0
    }
1606
1607
20
    if(1 == ps_nal_parse_ctxt->u1_pic_boundary_aud_flag)
1608
13
    {
1609
13
        ps_nal_parse_ctxt->i4_eos_flag = SVCD_TRUE;
1610
13
    }
1611
    /* Update VCL node if it is first call in the */
1612
    /* flush mode                                 */
1613
20
    if(SVCD_FALSE == ps_nal_parse_ctxt->i4_eos_flag)
1614
7
    {
1615
7
        WORD32 i4_status;
1616
1617
        /* Update the unfinished NAL into VCL node if */
1618
        /* all the following conditions are true      */
1619
        /* 1. We have not found the start code and    */
1620
        /*    NAL boundary is not detected yet        */
1621
        /* 2. NAL is not discarded                    */
1622
7
        if((FIND_NAL_END == ps_nal_parse_ctxt->i4_find_nal_state) &&
1623
0
           (SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag))
1624
0
        {
1625
0
            isvcd_update_nal_ctxt(ps_nal_parse_ctxt, pv_out_vcl_nal, pv_out_non_vcl_nal);
1626
0
        }
1627
1628
7
        ps_nal_parse_ctxt->i4_idr_pic_err_flag = 0;
1629
        /* Refine based on the no inter layer pred flag*/
1630
7
        i4_status = isvcd_refine_dqid_list(ps_vcl_nal, ps_nal_parse_ctxt);
1631
1632
7
        if(!(OK == i4_status))
1633
0
        {
1634
0
            return i4_status;
1635
0
        }
1636
7
        UNUSED(i4_status);
1637
1638
        /* Reset the context structure variables */
1639
7
        isvcd_nal_reset_ctxt(ps_nal_parse_ctxt);
1640
1641
        /* Reset the end of stream flag so that in    */
1642
        /* the next flush call the above steps need   */
1643
        /* not be performed                           */
1644
7
        ps_nal_parse_ctxt->i4_eos_flag = SVCD_TRUE;
1645
1646
7
        return (PIC_BOUNDARY_TRUE);
1647
7
    }
1648
13
    else
1649
13
    {
1650
13
        return (FLUSH_DECODED_PICTURE);
1651
13
    }
1652
20
}
1653
/*****************************************************************************/
1654
/*                                                                           */
1655
/*  Function Name : isvcd_nal_parse_pic_bound_proc                           */
1656
/*                                                                           */
1657
/*  Description   : Function does the picture end processign and resets      */
1658
/*                                                                           */
1659
/*                                                                           */
1660
/*  Inputs        : ps_nal_parse_ctxt, ps_vcl_nal                            */
1661
/*  Globals       : none                                                     */
1662
/*  Processing    : DQid list refiniment and resets                          */
1663
/*                                                                           */
1664
/*  Outputs       : none                                                     */
1665
/*  Returns       : none                                                     */
1666
/*                                                                           */
1667
/*  Issues        : none                                                     */
1668
/*                                                                           */
1669
/*  Revision History:                                                        */
1670
/*                                                                           */
1671
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1672
/*         06 09 2021   vijayakumar          creation                        */
1673
/*                                                                           */
1674
/*****************************************************************************/
1675
void isvcd_nal_parse_pic_bound_proc(nal_parse_ctxt_t *ps_nal_parse_ctxt, vcl_nal_t *ps_vcl_nal,
1676
                                    nal_prms_t *ps_nal_prms)
1677
141k
{
1678
141k
    WORD32 i4_status;
1679
1680
141k
    i4_status = isvcd_refine_dqid_list(ps_vcl_nal, ps_nal_parse_ctxt);
1681
1682
    /* in case of IDR pictures if the node     */
1683
    /* which has to be added into dependency   */
1684
    /* list is not valied then the layer below */
1685
    /* that node is set as target layer        */
1686
1687
141k
    if(NOT_OK == i4_status)
1688
316
    {
1689
316
        ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_TRUE;
1690
316
        ps_vcl_nal->i1_nal_ref_id_next = -1;
1691
316
    }
1692
141k
    else
1693
141k
    {
1694
        /* update the next access unit params */
1695
        /* will be used by lower level decoder*/
1696
        /* for concealment of frame number    */
1697
        /* applicable for single layer cases  */
1698
141k
        ps_vcl_nal->i1_nal_ref_id_next = ps_nal_prms->i4_nal_ref_idc;
1699
1700
141k
        ps_vcl_nal->u2_frm_num_next = ps_nal_prms->u2_frm_num;
1701
141k
    }
1702
1703
    /* -------- reset few variables in context structure ----*/
1704
141k
    isvcd_pic_reset_ctxt(ps_nal_parse_ctxt);
1705
141k
}
1706
/*****************************************************************************/
1707
/*                                                                           */
1708
/*  Function Name : isvcd_nal_parse_vcl_nal_partial                          */
1709
/*                                                                           */
1710
/*  Description   : None                                                     */
1711
/*                                                                           */
1712
/*  Inputs        : pv_nal_parse_ctxt - bitstream extract ctxt               */
1713
/*                      structure                                            */
1714
/*                  pv_input_bitstream_ctxt - bitstream context              */
1715
/*                  pv_out_non_vcl_nal - non vcl nal structure (output)      */
1716
/*                  pv_out_vcl_nal - vcl nal structure (output)              */
1717
/*                  pu4_bytes_consumed - bytes consumed variable(output)     */
1718
/*                  pi4_num_packets_consumed - packets consumed (output/RFC) */
1719
/*                                                                           */
1720
/*  Globals       : None                                                     */
1721
/*                                                                           */
1722
/*  Processing    : None                                                     */
1723
/*                                                                           */
1724
/*  Outputs       : Updates bytes consumed variable, packets consumed,       */
1725
/*                  output structures (vcl nal , non vcl nal)                */
1726
/*                                                                           */
1727
/*  Returns       : If picture bounadry is detetcted then PIC_BOUNDARY_TRUE  */
1728
/*                  otherwise PIC_BOUNDARY_FALSE                             */
1729
/*                                                                           */
1730
/*  Issues        : None                                                     */
1731
/*                                                                           */
1732
/*  Revision History:                                                        */
1733
/*          DD MM YYYY   Author(s)       Changes                             */
1734
/*          06 09 2021   Vijay           Draft                               */
1735
/*                                                                           */
1736
/*****************************************************************************/
1737
1738
WORD32 isvcd_nal_parse_vcl_nal_partial(void *pv_nal_parse_ctxt, UWORD8 *pu1_stream_buffer,
1739
                                       void *pv_out_non_vcl_nal, void *pv_out_vcl_nal,
1740
                                       UWORD32 *pu4_bytes_consumed, UWORD32 *pu4_num_bytes)
1741
145k
{
1742
    /*! - Search for the NAL boundary
1743
        - If NAL boundary is not found and bytes consumed is lesser than
1744
          minimum buffer size then break out of the loop
1745
        - if it is start of NAL then read the NAL header
1746
        - If it is a VCL NAL then invoke picture boundary detection logic and
1747
          picture boundary is detected then break out of the loop without
1748
          updating the bytes consumed variable
1749
        - NAL discard logic determines whther the current NAL has to be
1750
          discarded or not
1751
        - If NAL is not discarded then populate the vcl or non vcl output
1752
          structures
1753
    */
1754
145k
    nal_parse_ctxt_t *ps_nal_parse_ctxt;
1755
145k
    vcl_nal_t *ps_vcl_nal;
1756
145k
    non_vcl_nal_t *ps_non_vcl_nal;
1757
145k
    nal_unit_t *ps_nal_unit;
1758
145k
    WORD32 i4_nal_start_flag, i4_cur_pos, i4_status;
1759
145k
    WORD32 i4_nal_header_len, i4_more_data_flag;
1760
145k
    UWORD32 u4_bytes_consumed_temp = 0;
1761
145k
    UWORD8 **ppu1_out_buf;
1762
145k
    nal_prms_t *ps_nal_prms;
1763
145k
    WORD32 i4_pic_bound_status;
1764
1765
145k
    ps_nal_parse_ctxt = (nal_parse_ctxt_t *) pv_nal_parse_ctxt;
1766
145k
    ps_vcl_nal = (vcl_nal_t *) pv_out_vcl_nal;
1767
145k
    ps_non_vcl_nal = (non_vcl_nal_t *) pv_out_non_vcl_nal;
1768
145k
    ps_nal_unit = (nal_unit_t *) ps_nal_parse_ctxt->pv_nal_unit;
1769
145k
    ps_nal_prms = &ps_nal_parse_ctxt->s_nal_prms;
1770
1771
    /* Initialization */
1772
145k
    i4_cur_pos = 0;
1773
145k
    *pu4_bytes_consumed = 0;
1774
145k
    i4_nal_header_len = 0;
1775
145k
    i4_nal_start_flag = SVCD_FALSE;
1776
145k
    i4_more_data_flag = SVCD_TRUE;
1777
145k
    i4_pic_bound_status = PIC_BOUNDARY_FALSE;
1778
1779
145k
    ps_non_vcl_nal->i4_num_non_vcl_nals = ps_nal_parse_ctxt->i4_num_non_vcl_nals;
1780
1781
    /* Since we do not perform the picture boundary detection */
1782
    /* on the prefix NAL unit, the current picture's prefix   */
1783
    /* NAL unit will be at the bottom of the buffer. Hence    */
1784
    /* it should be copied to top of the buffer               */
1785
145k
    if(SVCD_TRUE == ps_nal_parse_ctxt->i4_is_frst_vcl_nal_in_au)
1786
145k
    {
1787
145k
        nal_buf_t *ps_prefix_nal_buf;
1788
1789
145k
        ps_prefix_nal_buf = &ps_nal_parse_ctxt->s_prefix_nal_buf;
1790
145k
        if(SVCD_TRUE == ps_prefix_nal_buf->i4_valid_flag)
1791
615
        {
1792
615
            WORD32 i4_buf_size;
1793
615
            UWORD8 *pu1_vcl_nal;
1794
1795
615
            if(ps_prefix_nal_buf->i4_buf_size > 0)
1796
90
            {
1797
90
                i4_buf_size = ps_prefix_nal_buf->i4_buf_size;
1798
90
                i4_buf_size = UP_ALIGN_8(i4_buf_size + BUFFER_ALIGN_4);
1799
90
            }
1800
525
            else
1801
525
            {
1802
525
                i4_buf_size = 0;
1803
525
            }
1804
1805
615
            pu1_vcl_nal = ps_nal_parse_ctxt->pu1_vcl_nal_buf + i4_buf_size;
1806
1807
615
            memmove(ps_nal_parse_ctxt->pu1_vcl_nal_buf, ps_prefix_nal_buf->pu1_buf, i4_buf_size);
1808
615
            ps_prefix_nal_buf->pu1_buf = ps_nal_parse_ctxt->pu1_vcl_nal_buf;
1809
615
            ps_nal_parse_ctxt->pu1_vcl_nal_buf = pu1_vcl_nal;
1810
1811
            /* subtract the buffer size left */
1812
615
            ps_nal_parse_ctxt->u4_bytes_left_vcl -= i4_buf_size;
1813
615
        }
1814
        /* Reset the top and bottom node */
1815
145k
        ps_vcl_nal->ps_top_node = NULL;
1816
145k
        ps_vcl_nal->ps_bot_node = NULL;
1817
145k
        ps_vcl_nal->i1_nal_ref_id_next = -1;
1818
145k
        ps_vcl_nal->u2_frm_num_next = 0;
1819
145k
    }
1820
1821
    /* If number of bytes left in the previous process call  */
1822
    /* is is greater or equal to number of bytes in input    */
1823
    /* buffer of the current process call then declare that  */
1824
    /* end of bitstream has occurred and consume the bytes   */
1825
    /* but do not decode                                     */
1826
145k
    if(ps_nal_parse_ctxt->u4_bytes_left >= (UWORD32) *pu4_num_bytes)
1827
20
    {
1828
20
        ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_TRUE;
1829
20
        *pu4_bytes_consumed = *pu4_num_bytes;
1830
1831
20
        i4_status =
1832
20
            isvcd_nal_parse_partial_signal_eos(ps_nal_parse_ctxt, ps_vcl_nal, ps_non_vcl_nal);
1833
        /* set the next AU params to default values */
1834
20
        ps_vcl_nal->i1_nal_ref_id_next = -1;
1835
20
        ps_vcl_nal->u2_frm_num_next = 0;
1836
1837
20
        return (i4_status);
1838
20
    }
1839
145k
    ps_nal_parse_ctxt->u4_bytes_left = 0;
1840
1841
    /*************************************************************************/
1842
    /*                      LOOP OVER NALs                                   */
1843
    /*************************************************************************/
1844
145k
    do
1845
1.06M
    {
1846
1.06M
        nal_buf_t *ps_nal_buf;
1847
1.06M
        UWORD32 *pu4_bytes_left;
1848
1849
        /* Find NAL boundary                */
1850
1.06M
        if(ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode)
1851
1.06M
        {
1852
1.06M
            i4_nal_start_flag = isvcd_get_annex_b_nal_unit(
1853
1.06M
                pu1_stream_buffer, i4_cur_pos, *pu4_num_bytes,
1854
1.06M
                &ps_nal_parse_ctxt->i4_find_nal_state, &ps_nal_parse_ctxt->i4_zero_byte_cnt,
1855
1.06M
                &u4_bytes_consumed_temp, ps_nal_parse_ctxt->pv_nal_unit, &i4_more_data_flag);
1856
1857
1.06M
            i4_cur_pos += u4_bytes_consumed_temp;
1858
1.06M
        }
1859
1860
        /*********************************************************************/
1861
        /*          READ NAL HEADER AND NAL DISCARD LOGIC                    */
1862
        /*********************************************************************/
1863
1864
        /* If it is the start of NAL header perform the following */
1865
        /* 1. Decode NAL header                                   */
1866
        /* 2. Determine whether the NAL has to be discarded or not*/
1867
        /* 3. Detect the picture boundary                         */
1868
1.06M
        if(SVCD_TRUE == i4_nal_start_flag)
1869
1.06M
        {
1870
1.06M
            UWORD32 u4_err_code;
1871
1.06M
            WORD32 i4_sps_pps_corrupt_status;
1872
1.06M
            WORD32 i4_internal_dep_id_prev;
1873
1874
            /* Get the NAL prms. This involves the following things*/
1875
            /* 1. Decode the NAL header                            */
1876
            /* 2. Set the discard flag                             */
1877
            /* 3. Decode the slice header if needed                */
1878
1879
            /* get the dependency id at which the NAl parse is currently */
1880
            /* present */
1881
1.06M
            i4_internal_dep_id_prev = ps_nal_parse_ctxt->s_int_attr.i4_dependency_id;
1882
1883
1.06M
            i4_status = isvcd_get_nal_prms(
1884
1.06M
                ps_nal_unit->pu1_bufs, ps_nal_unit->i4_buf_sizes, ps_nal_prms,
1885
1.06M
                &ps_nal_parse_ctxt->s_prefix_nal_prms, &ps_nal_parse_ctxt->s_prefix_nal_buf,
1886
1.06M
                &u4_err_code, &i4_sps_pps_corrupt_status, &ps_nal_parse_ctxt->i4_discard_nal_flag,
1887
1.06M
                ps_nal_parse_ctxt);
1888
1889
1.06M
            if(NON_ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode)
1890
0
            {
1891
0
                ps_nal_parse_ctxt->i4_prev_dq_id = ps_nal_prms->i4_dqid;
1892
0
            }
1893
1894
            /* If the error code returned by the "picture boundary" */
1895
            /* detetction is                                        */
1896
            /* 1. Insufficient bitstream size: then store the bytes */
1897
            /*    left and break out of the loop                    */
1898
            /* 2. Corrupted slice: then discard the slice           */
1899
1.06M
            if((NAL_INSUFFICIENT_DATA == (WORD32) u4_err_code) &&
1900
2.88k
               (NAL_END != ps_nal_parse_ctxt->i4_find_nal_state))
1901
2.16k
            {
1902
2.16k
                ps_nal_parse_ctxt->u4_bytes_left = *pu4_num_bytes - *pu4_bytes_consumed;
1903
1904
                /* Reset the NAL level tracking variables */
1905
2.16k
                isvcd_nal_reset_ctxt(ps_nal_parse_ctxt);
1906
2.16k
                break;
1907
2.16k
            }
1908
1.05M
            else if(0 != u4_err_code)
1909
20.8k
            {
1910
20.8k
                ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_TRUE;
1911
1912
20.8k
                if(SVCD_TRUE == ps_nal_prms->i4_idr_pic_flag)
1913
1.14k
                {
1914
                    /* IDR Error handler is called       */
1915
                    /* only if for a given layer the NAL */
1916
                    /* haeder and partial slice decode   */
1917
                    /* routine comes out as no SPS PPS   */
1918
                    /* error. But for Lowest layer in    */
1919
                    /* access unit it is doen always     */
1920
1.14k
                    if(i4_internal_dep_id_prev != ps_nal_parse_ctxt->s_int_attr.i4_dependency_id)
1921
0
                    {
1922
                        /* if the target depedency id has been */
1923
                        /* changed while decoding currnet NAL  */
1924
1925
0
                        if((0 != i4_sps_pps_corrupt_status) ||
1926
0
                           (-1 == ps_nal_parse_ctxt->i4_prev_dq_id))
1927
0
                        {
1928
0
                            i4_status =
1929
0
                                isvcd_idr_err_hdlr(ps_vcl_nal, ps_nal_prms, ps_nal_parse_ctxt);
1930
0
                            if(OK != i4_status)
1931
0
                            {
1932
0
                                return i4_status;
1933
0
                            }
1934
0
                            UNUSED(i4_status);
1935
1936
0
                            ps_nal_parse_ctxt->i4_tgt_lyr_update = SVCD_FALSE;
1937
0
                        }
1938
0
                        else
1939
0
                        {
1940
0
                            if(0 == ps_nal_prms->i4_quality_id)
1941
0
                            {
1942
                                /* over write the frame number */
1943
0
                                ps_nal_parse_ctxt->s_nal_prms.u2_frm_num = 0;
1944
1945
                                /* Get the previous layer's DQID */
1946
0
                                if(ps_nal_parse_ctxt->i4_prev_dq_id < ps_nal_prms->i4_dqid)
1947
0
                                {
1948
0
                                    ps_nal_parse_ctxt->i4_prev_dq_id = ps_nal_prms->i4_dqid;
1949
0
                                    ps_nal_parse_ctxt->i4_is_frst_vcl_nal_in_au = SVCD_FALSE;
1950
0
                                }
1951
1952
                                /* update the nal context with the nal */
1953
                                /* header params */
1954
0
                                isvcd_update_nal_ctxt(ps_nal_parse_ctxt, ps_vcl_nal,
1955
0
                                                      ps_non_vcl_nal);
1956
0
                            }
1957
0
                        }
1958
0
                    }
1959
1.14k
                }
1960
20.8k
            }
1961
1962
            /* Populate the derived nal type into bitstream extract*/
1963
            /* context structure                                   */
1964
1.05M
            i4_nal_header_len = ps_nal_prms->i4_nal_header_len;
1965
1.05M
            ps_nal_parse_ctxt->i4_nal_type = ps_nal_prms->i4_derived_nal_type;
1966
1967
            /* get the accumulated idr pic error flag */
1968
1.05M
            ps_nal_parse_ctxt->i4_idr_pic_err_flag |=
1969
1.05M
                ((SVCD_TRUE == ps_nal_prms->i4_idr_pic_flag) &&
1970
294k
                 (SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag) &&
1971
292k
                 (i4_internal_dep_id_prev != ps_nal_parse_ctxt->s_int_attr.i4_dependency_id));
1972
1973
1.05M
            if(ACCESS_UNIT_DELIMITER_RBSP == ps_nal_prms->i4_nal_unit_type)
1974
6.51k
            {
1975
6.51k
                i4_pic_bound_status = PIC_BOUNDARY_TRUE;
1976
6.51k
                ps_nal_parse_ctxt->u1_pic_boundary_aud_flag = 1;
1977
                /* If picture boundary is detected then come out of  */
1978
                /* the loop                                          */
1979
6.51k
                if(PIC_BOUNDARY_TRUE == i4_pic_bound_status)
1980
6.51k
                {
1981
6.51k
                    isvcd_nal_parse_pic_bound_proc(ps_nal_parse_ctxt, ps_vcl_nal, ps_nal_prms);
1982
6.51k
                    break;
1983
6.51k
                }
1984
6.51k
            }
1985
            /* Perform the picture boundary detetction if all the  */
1986
            /* following conditions are TRUE                       */
1987
            /*  1. VCL NAL                                         */
1988
            /*  2. Not a prefix NAL                                */
1989
            /*  3. Not a discardable NAL                           */
1990
1.05M
            if((VCL_NAL == ps_nal_prms->i4_derived_nal_type) &&
1991
377k
               (PREFIX_UNIT_NAL != ps_nal_prms->i4_nal_unit_type) &&
1992
375k
               (SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag))
1993
370k
            {
1994
370k
                if(ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode)
1995
370k
                {
1996
370k
                    ps_nal_parse_ctxt->u1_pic_boundary_aud_flag = 0;
1997
1998
370k
                    i4_status = isvcd_detect_pic_boundary_annex_b(ps_nal_prms, pu1_stream_buffer,
1999
370k
                                                                  i4_cur_pos, &i4_pic_bound_status,
2000
370k
                                                                  ps_nal_parse_ctxt, pu4_num_bytes);
2001
370k
                }
2002
2003
                /* If picture boundary is detected then come out of  */
2004
                /* the loop                                          */
2005
370k
                if(PIC_BOUNDARY_TRUE == i4_pic_bound_status)
2006
134k
                {
2007
134k
                    isvcd_nal_parse_pic_bound_proc(ps_nal_parse_ctxt, ps_vcl_nal, ps_nal_prms);
2008
134k
                    break;
2009
134k
                }
2010
370k
            }
2011
2012
917k
            if(SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag)
2013
891k
            {
2014
                /* Set the active NAL buffer structure and initialize */
2015
                /* the nal buffer structure                           */
2016
891k
                isvcd_get_nal_buf(ps_nal_parse_ctxt, &ps_nal_buf);
2017
891k
                ps_nal_parse_ctxt->ps_nal_buf = ps_nal_buf;
2018
891k
            }
2019
26.0k
            else
2020
26.0k
            {
2021
26.0k
                ps_nal_parse_ctxt->ps_nal_buf = NULL;
2022
26.0k
            }
2023
917k
        }
2024
2025
        /*-------------------------------------------------------------------*/
2026
        /* In RFC based bitstreams, this is a dummy update (in this mode, the*/
2027
        /* bytes consumed updation is done by picture boundary dectection    */
2028
        /* But for Annex B based streams this is valid update                */
2029
        /*-------------------------------------------------------------------*/
2030
918k
        *pu4_bytes_consumed += u4_bytes_consumed_temp;
2031
2032
        /*********************************************************************/
2033
        /*          EMULATION PREVENTION AND BYTE SWAPPING                   */
2034
        /*********************************************************************/
2035
2036
        /* Determine output buffer */
2037
918k
        ps_nal_buf = ps_nal_parse_ctxt->ps_nal_buf;
2038
2039
918k
        if(VCL_NAL == ps_nal_parse_ctxt->i4_nal_type)
2040
242k
        {
2041
242k
            ppu1_out_buf = &ps_nal_parse_ctxt->pu1_vcl_nal_buf;
2042
242k
            pu4_bytes_left = &ps_nal_parse_ctxt->u4_bytes_left_vcl;
2043
242k
            if(*pu4_bytes_left < (MAX_VCL_NAL_BUFF_SIZE * 0.05))
2044
0
            {
2045
0
                return (VCL_NAL_FOUND_FALSE);
2046
0
            }
2047
242k
        }
2048
675k
        else
2049
675k
        {
2050
675k
            ppu1_out_buf = &ps_nal_parse_ctxt->pu1_non_vcl_nal_buf;
2051
675k
            pu4_bytes_left = &ps_nal_parse_ctxt->u4_bytes_left_non_vcl;
2052
675k
            if(*pu4_bytes_left < (MAX_NON_VCL_NAL_BUFF_SIZE * 0.05))
2053
135
            {
2054
135
                return (VCL_NAL_FOUND_FALSE);
2055
135
            }
2056
675k
        }
2057
2058
        /* if 0 bytes left then discard the current NAL */
2059
917k
        if(0 >= (WORD32) *pu4_bytes_left)
2060
0
        {
2061
0
            ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_TRUE;
2062
0
        }
2063
2064
        /* Perform the emulation prevention and byte swap */
2065
917k
        if(SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag)
2066
891k
        {
2067
891k
            UWORD32 u4_output_bytes, u4_buf_inc;
2068
2069
            /* Do emulation prevention and byte swapping on all the packets  */
2070
            /* of RFC or current partial or full Annex B NAL unit            */
2071
891k
            {
2072
891k
                UWORD32 u4_buf_size;
2073
2074
                /* clip the size before emulation prevention */
2075
891k
                u4_buf_size = (UWORD32) CLIP3(0, (WORD32) *pu4_bytes_left,
2076
891k
                                              (ps_nal_unit->i4_buf_sizes - i4_nal_header_len));
2077
2078
891k
                u4_buf_inc = isvcd_nal_byte_swap_emulation(
2079
891k
                    (UWORD32 *) *ppu1_out_buf, &u4_output_bytes,
2080
891k
                    ps_nal_unit->pu1_bufs + i4_nal_header_len, u4_buf_size,
2081
891k
                    NUM_OF_ZERO_BYTES_BEFORE_START_CODE, &ps_nal_parse_ctxt->s_emulation_ctxt);
2082
2083
891k
                i4_nal_header_len = 0;
2084
891k
                u4_buf_inc = UP_ALIGN_8(u4_buf_inc);
2085
891k
                *ppu1_out_buf += u4_buf_inc;
2086
891k
                *pu4_bytes_left -= u4_buf_inc;
2087
891k
                ps_nal_buf->i4_buf_size += u4_output_bytes;
2088
891k
            }
2089
891k
        }
2090
2091
        /*********************************************************************/
2092
        /*                UPDATE VARIABLES                                   */
2093
        /*********************************************************************/
2094
917k
        if(NAL_END == ps_nal_parse_ctxt->i4_find_nal_state)
2095
916k
        {
2096
916k
            if(SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag)
2097
890k
            {
2098
                /* This fucntions updates output nal ctxt - vcl nal structure*/
2099
                /* and non vcl nal structure depending upon the current NAL  */
2100
                /* type.                                                     */
2101
                /* This will only update parameters which are available at   */
2102
                /* end of NAL unit like nal unit's total size                */
2103
890k
                isvcd_update_nal_ctxt(ps_nal_parse_ctxt, ps_vcl_nal, ps_non_vcl_nal);
2104
2105
890k
                UPDATE_NAL_BUF_PTR(ppu1_out_buf, ps_nal_prms->i4_derived_nal_type, pu4_bytes_left);
2106
890k
            }
2107
2108
            /* If the prefix NAL unit is not immediatly followed by */
2109
            /* a AVC NAL unit it shall be discarded and hence reset */
2110
            /* is done                                              */
2111
            /* Also if prefix NAL unit is discarded then we should  */
2112
            /* not associate the prefix NAL unit with AVC NAL unit  */
2113
            /* and hence a reset is required                        */
2114
916k
            if((PREFIX_UNIT_NAL != ps_nal_prms->i4_nal_unit_type) ||
2115
2.10k
               (SVCD_TRUE == ps_nal_parse_ctxt->i4_discard_nal_flag))
2116
914k
            {
2117
914k
                isvcd_nal_buf_reset(&ps_nal_parse_ctxt->s_prefix_nal_buf);
2118
914k
            }
2119
2120
            /* Reset the nal level tracking variables */
2121
916k
            isvcd_nal_reset_ctxt(ps_nal_parse_ctxt);
2122
916k
        }
2123
2124
        /*------------- while loop ends here --------------------------------*/
2125
917k
    } while(SVCD_TRUE == i4_more_data_flag);
2126
2127
145k
    return (i4_pic_bound_status);
2128
145k
}
2129
2130
/*****************************************************************************/
2131
/*                                                                           */
2132
/*  Function Name : isvcd_nal_parse_non_vcl_nal                              */
2133
/*                                                                           */
2134
/*  Description   : None                                                     */
2135
/*                                                                           */
2136
/*  Inputs        : pv_nal_parse_ctxt - bitstream extract ctxt               */
2137
/*                      structure                                            */
2138
/*                  pv_input_bitstream_ctxt - bitstream context              */
2139
/*                  pv_out_non_vcl_nal - non vcl nal structure (output)      */
2140
/*                  pu4_bytes_consumed - bytes consumed variable(output)     */
2141
/*                  pi4_num_packets_consumed - packets consumed (output/RFC) */
2142
/*                                                                           */
2143
/*  Globals       : None                                                     */
2144
/*                                                                           */
2145
/*  Processing    : None                                                     */
2146
/*                                                                           */
2147
/*  Outputs       : Updates bytes consumed variable, packets consumed,       */
2148
/*                  output structures (non vcl nal)                          */
2149
/*                                                                           */
2150
/*  Returns       : If vcl nal is found then VCL_NAL_FOUND_TRUE otherwise    */
2151
/*                  VCL_NAL_FOUND_FALSE                                      */
2152
/*                                                                           */
2153
/*  Issues        : None                                                     */
2154
/*                                                                           */
2155
/*  Revision History:                                                        */
2156
/*          DD MM YYYY   Author(s)       Changes                             */
2157
/*          06 09 2021   Vijay      Draft                                    */
2158
/*                                                                           */
2159
/*****************************************************************************/
2160
2161
WORD32 isvcd_nal_parse_non_vcl_nal(void *pv_nal_parse_ctxt, UWORD8 *pu1_stream_buffer,
2162
                                   void *pv_out_non_vcl_nal, UWORD32 *pu4_bytes_consumed,
2163
                                   UWORD32 *pu4_num_bytes)
2164
102k
{
2165
    /*! - Search for the NAL boundary
2166
        - If NAL boundary is not found and bytes consumed is lesser than
2167
          minimum buffer size then break out of the loop
2168
        - if it is start of NAL then read the NAL header
2169
        - If it is a VCL NAL then return from this fucntion saying that
2170
          VCL NAL found
2171
        - NAL discard logic determines whther the current NAL has to be
2172
          discarded or not
2173
        - If NAL is not discarded then populate the vcl or non vcl output
2174
          structures
2175
    */
2176
2177
102k
    nal_parse_ctxt_t *ps_nal_parse_ctxt;
2178
102k
    non_vcl_nal_t *ps_non_vcl_nal;
2179
102k
    nal_unit_t *ps_nal_unit;
2180
102k
    WORD32 i4_nal_start_flag, i4_cur_pos, i4_status;
2181
102k
    WORD32 i4_nal_header_len, i4_more_data_flag;
2182
102k
    UWORD32 u4_bytes_consumed_temp = 0;
2183
102k
    UWORD8 **ppu1_out_buf;
2184
102k
    nal_prms_t *ps_nal_prms;
2185
2186
102k
    ps_nal_parse_ctxt = (nal_parse_ctxt_t *) pv_nal_parse_ctxt;
2187
102k
    ps_non_vcl_nal = (non_vcl_nal_t *) pv_out_non_vcl_nal;
2188
102k
    ps_nal_unit = (nal_unit_t *) ps_nal_parse_ctxt->pv_nal_unit;
2189
102k
    ps_nal_prms = &ps_nal_parse_ctxt->s_nal_prms;
2190
2191
    /* Initialization */
2192
102k
    i4_cur_pos = 0;
2193
102k
    *pu4_bytes_consumed = 0;
2194
102k
    i4_nal_header_len = 0;
2195
102k
    i4_nal_start_flag = SVCD_FALSE;
2196
102k
    i4_more_data_flag = SVCD_TRUE;
2197
102k
    i4_status = PIC_BOUNDARY_FALSE;
2198
2199
    /* reset the target layer update flag */
2200
102k
    ps_nal_parse_ctxt->i4_tgt_lyr_update = SVCD_FALSE;
2201
    /*************************************************************************/
2202
    /*              SEARCHING FOR THE START OF BITSTREAM                     */
2203
    /*************************************************************************/
2204
2205
    /*-----------------------------------------------------------------------*/
2206
    /* For Annex B based bitstreams the first start code has to decoded      */
2207
    /* The first start code can come after multiple process call also. This  */
2208
    /* has to be carefully handled                                           */
2209
    /*-----------------------------------------------------------------------*/
2210
2211
102k
    if(ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode &&
2212
102k
       SVCD_TRUE == ps_nal_parse_ctxt->i4_dec_frst_sc_flag)
2213
20.4k
    {
2214
20.4k
        WORD32 i4_status;
2215
2216
20.4k
        i4_status =
2217
20.4k
            isvcd_get_first_start_code(pu1_stream_buffer, pu4_bytes_consumed, pu4_num_bytes);
2218
2219
        /*-------------------------------------------------------------------*/
2220
        /* If start code found then proceed with bitstream extraction        */
2221
        /*-------------------------------------------------------------------*/
2222
2223
20.4k
        if(i4_status == SC_NOT_FOUND)
2224
20
        {
2225
20
            return (VCL_NAL_FOUND_FALSE);
2226
20
        }
2227
2228
20.3k
        i4_cur_pos = *pu4_bytes_consumed;
2229
20.3k
        ps_nal_parse_ctxt->i4_dec_frst_sc_flag = SVCD_FALSE;
2230
20.3k
    }
2231
2232
    /* If number of bytes left in the previous process call  */
2233
    /* is is greater or equal to number of bytes in input    */
2234
    /* buffer of the current process call then declare that  */
2235
    /* end of bitstream has occurred and consume the bytes   */
2236
    /* but do not decode                                     */
2237
102k
    if(ps_nal_parse_ctxt->u4_bytes_left >= (UWORD32) *pu4_num_bytes)
2238
0
    {
2239
0
        ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_TRUE;
2240
0
        *pu4_bytes_consumed = *pu4_num_bytes;
2241
2242
0
        i4_status = isvcd_nal_parse_partial_signal_eos(ps_nal_parse_ctxt, NULL, ps_non_vcl_nal);
2243
0
        return (i4_status);
2244
0
    }
2245
2246
102k
    do
2247
692k
    {
2248
692k
        nal_buf_t *ps_nal_buf;
2249
692k
        UWORD32 *pu4_bytes_left;
2250
2251
        /*********************************************************************/
2252
        /*                  NAL BOUNDARY DETECTION                           */
2253
        /*********************************************************************/
2254
        /*-------------------------------------------------------------------*/
2255
        /* Detect NAL boundary                                               */
2256
        /* After return,  this NAL boundary detetction logic might be in     */
2257
        /* one of following states:                                          */
2258
        /*  - NAL_START                                                      */
2259
        /*  - FIND_NAL_END                                                   */
2260
        /*  - NAL_END                                                        */
2261
        /*-------------------------------------------------------------------*/
2262
692k
        if(ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode)
2263
692k
        {
2264
692k
            i4_nal_start_flag = isvcd_get_annex_b_nal_unit(
2265
692k
                pu1_stream_buffer, i4_cur_pos, *pu4_num_bytes,
2266
692k
                &ps_nal_parse_ctxt->i4_find_nal_state, &ps_nal_parse_ctxt->i4_zero_byte_cnt,
2267
692k
                &u4_bytes_consumed_temp, ps_nal_parse_ctxt->pv_nal_unit, &i4_more_data_flag);
2268
2269
692k
            i4_cur_pos += u4_bytes_consumed_temp;
2270
692k
        }
2271
2272
        /* If current NAL unit is start of new NAL unit then parse the NAL
2273
            header. If the current NAL unit type is VCL NAL then return from
2274
            this function. otherwise apply NAL discard logic and discard the
2275
            NAL if discard NAL flag is true                                  */
2276
2277
692k
        if(SVCD_TRUE == i4_nal_start_flag)
2278
692k
        {
2279
692k
            UWORD32 u4_err_code;
2280
692k
            WORD32 i4_sps_pps_corrupt_status;
2281
2282
            /* Get the NAL prms. This involves the following things*/
2283
            /* 1. Decode the NAL header                            */
2284
            /* 2. Set the discard flag                             */
2285
            /* 3. Decode the slice header if needed                */
2286
692k
            isvcd_get_nal_prms(ps_nal_unit->pu1_bufs, ps_nal_unit->i4_buf_sizes, ps_nal_prms,
2287
692k
                               &ps_nal_parse_ctxt->s_prefix_nal_prms,
2288
692k
                               &ps_nal_parse_ctxt->s_prefix_nal_buf, &u4_err_code,
2289
692k
                               &i4_sps_pps_corrupt_status, &ps_nal_parse_ctxt->i4_discard_nal_flag,
2290
692k
                               ps_nal_parse_ctxt);
2291
            /* If the error code returned by the "picture boundary" */
2292
            /* detetction is                                        */
2293
            /* 1. Insufficient bitstream size: then store the bytes */
2294
            /*    left and break out of the loop                    */
2295
            /* 2. Corrupted slice: then discard the slice           */
2296
692k
            if((NAL_INSUFFICIENT_DATA == (WORD32) u4_err_code) &&
2297
6.68k
               (NAL_END != ps_nal_parse_ctxt->i4_find_nal_state))
2298
4.95k
            {
2299
4.95k
                ps_nal_parse_ctxt->u4_bytes_left = *pu4_num_bytes - *pu4_bytes_consumed;
2300
2301
                /* Reset the NAL level tracking variables */
2302
4.95k
                isvcd_nal_reset_ctxt(ps_nal_parse_ctxt);
2303
4.95k
                break;
2304
4.95k
            }
2305
687k
            else if(0 != u4_err_code)
2306
12.9k
            {
2307
12.9k
                ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_TRUE;
2308
12.9k
            }
2309
2310
            /* Populate other paramters based on the nal prms */
2311
687k
            ps_nal_parse_ctxt->i4_nal_type = ps_nal_prms->i4_derived_nal_type;
2312
687k
            i4_nal_header_len = ps_nal_prms->i4_nal_header_len;
2313
2314
            /* If derived NAL unit is VCL_NAL then return from this function */
2315
687k
            if(VCL_NAL == ps_nal_prms->i4_derived_nal_type &&
2316
94.7k
               PREFIX_UNIT_NAL != ps_nal_prms->i4_nal_unit_type)
2317
93.5k
            {
2318
93.5k
                isvcd_pic_reset_ctxt(ps_nal_parse_ctxt);
2319
2320
93.5k
                return (VCL_NAL_FOUND_TRUE);
2321
93.5k
            }
2322
2323
            /* Set the active NAL buffer structure and initialize */
2324
            /* the nal buffer structure                           */
2325
593k
            isvcd_get_nal_buf(ps_nal_parse_ctxt, &ps_nal_buf);
2326
2327
593k
            ps_nal_parse_ctxt->ps_nal_buf = ps_nal_buf;
2328
593k
        }
2329
2330
        /* Update the bytes consumed variable */
2331
2332
594k
        *pu4_bytes_consumed += u4_bytes_consumed_temp;
2333
2334
594k
        ps_nal_buf = ps_nal_parse_ctxt->ps_nal_buf;
2335
594k
        if(VCL_NAL == ps_nal_parse_ctxt->i4_nal_type)
2336
1.24k
        {
2337
1.24k
            ppu1_out_buf = &ps_nal_parse_ctxt->pu1_vcl_nal_buf;
2338
1.24k
            pu4_bytes_left = &ps_nal_parse_ctxt->u4_bytes_left_vcl;
2339
1.24k
            if(*pu4_bytes_left < (MAX_VCL_NAL_BUFF_SIZE * 0.05))
2340
0
            {
2341
0
                return (VCL_NAL_FOUND_FALSE);
2342
0
            }
2343
1.24k
        }
2344
592k
        else
2345
592k
        {
2346
592k
            ppu1_out_buf = &ps_nal_parse_ctxt->pu1_non_vcl_nal_buf;
2347
592k
            pu4_bytes_left = &ps_nal_parse_ctxt->u4_bytes_left_non_vcl;
2348
592k
            if(*pu4_bytes_left < (MAX_NON_VCL_NAL_BUFF_SIZE * 0.05))
2349
134
            {
2350
134
                return (VCL_NAL_FOUND_FALSE);
2351
134
            }
2352
592k
        }
2353
2354
        /* if 0 bytes left then discard the current NAL */
2355
593k
        if(0 >= (WORD32) *pu4_bytes_left)
2356
0
        {
2357
0
            ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_TRUE;
2358
0
        }
2359
2360
        /* If NAL is not discarded then :
2361
            1) Perform emulation prevention and byte swapping on the RBSP data
2362
            2) Update the NAL unit ctxt:
2363
                a) If VCL NAL then update DQID list
2364
                b) If NON VCL NAL then update the non vcl output structure   */
2365
2366
593k
        if(SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag)
2367
578k
        {
2368
578k
            UWORD32 u4_output_bytes, u4_buf_inc;
2369
2370
578k
            {
2371
578k
                UWORD32 u4_buf_size;
2372
2373
                /* clip the size before emulation prevention */
2374
578k
                u4_buf_size = (UWORD32) CLIP3(0, (WORD32) *pu4_bytes_left,
2375
578k
                                              (ps_nal_unit->i4_buf_sizes - i4_nal_header_len));
2376
2377
578k
                u4_buf_inc = isvcd_nal_byte_swap_emulation(
2378
578k
                    (UWORD32 *) *ppu1_out_buf, &u4_output_bytes,
2379
578k
                    ps_nal_unit->pu1_bufs + i4_nal_header_len, u4_buf_size,
2380
578k
                    NUM_OF_ZERO_BYTES_BEFORE_START_CODE, &ps_nal_parse_ctxt->s_emulation_ctxt);
2381
578k
                i4_nal_header_len = 0;
2382
2383
578k
                u4_buf_inc = UP_ALIGN_8(u4_buf_inc);
2384
578k
                *ppu1_out_buf += u4_buf_inc;
2385
578k
                *pu4_bytes_left -= u4_buf_inc;
2386
578k
                ps_nal_buf->i4_buf_size += u4_output_bytes;
2387
578k
            }
2388
578k
        }
2389
2390
        /*********************************************************************/
2391
        /*                UPDATE VARIABLES                                   */
2392
        /*********************************************************************/
2393
2394
593k
        if(NAL_END == ps_nal_parse_ctxt->i4_find_nal_state)
2395
590k
        {
2396
            /*---------------------------------------------------------------*/
2397
            /* - Update the total bits in the NAL. While doing so bits       */
2398
            /* calculated so far should be converted to SODB length          */
2399
            /*---------------------------------------------------------------*/
2400
590k
            if(SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag)
2401
575k
            {
2402
575k
                isvcd_update_nal_ctxt(ps_nal_parse_ctxt, NULL, ps_non_vcl_nal);
2403
2404
575k
                UPDATE_NAL_BUF_PTR(ppu1_out_buf, ps_nal_prms->i4_derived_nal_type, pu4_bytes_left);
2405
575k
            }
2406
2407
            /* If the prefix NAL unit is not immediatly followed by */
2408
            /* a AVC NAL unit it shall be discarded and hence reset */
2409
            /* is done                                              */
2410
            /* Also if prefix NAL unit is discarded then we should  */
2411
            /* not associate the prefix NAL unit with AVC NAL unit  */
2412
            /* and hence a reset is required                        */
2413
590k
            if((PREFIX_UNIT_NAL != ps_nal_prms->i4_nal_unit_type) ||
2414
2.01k
               (SVCD_TRUE == ps_nal_parse_ctxt->i4_discard_nal_flag))
2415
589k
            {
2416
589k
                isvcd_nal_buf_reset(&ps_nal_parse_ctxt->s_prefix_nal_buf);
2417
589k
            }
2418
2419
            /* Reset NAL level tracking variables */
2420
590k
            isvcd_nal_reset_ctxt(ps_nal_parse_ctxt);
2421
590k
        }
2422
2423
593k
        i4_nal_header_len = 0;
2424
        /*------------- while loop ends here --------------------------------*/
2425
593k
    } while(SVCD_TRUE == i4_more_data_flag);
2426
2427
8.42k
    if(i4_more_data_flag == 0)
2428
8.42k
    {
2429
8.42k
        isvcd_pic_reset_ctxt(ps_nal_parse_ctxt);
2430
8.42k
        return (VCL_NAL_FOUND_TRUE);
2431
8.42k
    }
2432
2433
0
    return (VCL_NAL_FOUND_FALSE);
2434
8.42k
}