Coverage Report

Created: 2026-12-01 06:42

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
3.38M
{
109
3.38M
    nal_prms_t *ps_nal_prms;
110
3.38M
    nal_buf_t *ps_nal_buf;
111
112
3.38M
    ps_nal_prms = &ps_nal_parse_ctxt->s_nal_prms;
113
114
    /* Get the NAL buffer structure */
115
3.38M
    if(PREFIX_UNIT_NAL == ps_nal_prms->i4_nal_unit_type)
116
3.73k
    {
117
3.73k
        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.73k
        isvcd_nal_buf_reset(ps_nal_buf);
124
3.73k
    }
125
3.38M
    else
126
3.38M
    {
127
3.38M
        ps_nal_buf = &ps_nal_parse_ctxt->s_nal_buf;
128
3.38M
    }
129
130
    /* Initialize the buffer structure */
131
3.38M
    ps_nal_buf->i4_valid_flag = SVCD_TRUE;
132
3.38M
    if(VCL_NAL == ps_nal_prms->i4_derived_nal_type)
133
276k
    {
134
276k
        ps_nal_buf->pu1_buf = ps_nal_parse_ctxt->pu1_vcl_nal_buf;
135
276k
    }
136
3.11M
    else if(NON_VCL_NAL == ps_nal_prms->i4_derived_nal_type)
137
3.08M
    {
138
3.08M
        ps_nal_buf->pu1_buf = ps_nal_parse_ctxt->pu1_non_vcl_nal_buf;
139
3.08M
    }
140
22.8k
    else
141
22.8k
    {
142
22.8k
        ps_nal_buf->pu1_buf = NULL;
143
22.8k
        return;
144
22.8k
    }
145
146
3.36M
    *pps_nal_buf = ps_nal_buf;
147
3.36M
}
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
323k
{
173
323k
    WORD32 i4_lyr_idx;
174
323k
    WORD32 i4_max_num_lyrs;
175
323k
    dqid_node_t *ps_dqid_node;
176
177
    /* sanity checks */
178
323k
    if(NULL == ps_dqid_ctxt)
179
0
    {
180
0
        return NOT_OK;
181
0
    }
182
183
323k
    i4_max_num_lyrs = ps_dqid_ctxt->i4_max_num_lyrs;
184
323k
    ps_dqid_node = ps_dqid_ctxt->ps_dqid_node;
185
186
    /* Loop over all the layers */
187
1.29M
    for(i4_lyr_idx = 0; i4_lyr_idx < i4_max_num_lyrs; i4_lyr_idx++)
188
971k
    {
189
        /* Reset the valid flag */
190
971k
        ps_dqid_node->u1_valid_flag = SVCD_FALSE;
191
192
        /* Loop updates */
193
971k
        ps_dqid_node += 1;
194
971k
    } /* loop over all the layers */
195
196
323k
    return (OK);
197
323k
}
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
990k
{
227
990k
    WORD32 i4_lyr_idx;
228
990k
    WORD32 i4_max_num_lyrs;
229
990k
    dqid_node_t *ps_dqid_node;
230
990k
    dqid_node_t *ps_rqrd_dqid_node;
231
232
    /* sanity checks */
233
990k
    if((NULL == ps_dqid_ctxt) || (NULL == pps_dqid_node))
234
0
    {
235
0
        return NOT_OK;
236
0
    }
237
238
990k
    i4_max_num_lyrs = ps_dqid_ctxt->i4_max_num_lyrs;
239
990k
    ps_dqid_node = ps_dqid_ctxt->ps_dqid_node;
240
241
    /*Initialization */
242
990k
    ps_rqrd_dqid_node = NULL;
243
244
    /* Loop over all the buffer nodes */
245
2.35M
    for(i4_lyr_idx = 0; i4_lyr_idx < i4_max_num_lyrs; i4_lyr_idx++)
246
1.92M
    {
247
1.92M
        if((SVCD_TRUE == ps_dqid_node->u1_valid_flag) && (u1_dqid == ps_dqid_node->u1_dqid))
248
563k
        {
249
563k
            ps_rqrd_dqid_node = ps_dqid_node;
250
563k
            break;
251
563k
        }
252
        /* Loop updates */
253
1.36M
        ps_dqid_node += 1;
254
1.36M
    } /* Loop over all the buffer nodes */
255
256
990k
    if(NULL == ps_rqrd_dqid_node)
257
426k
    {
258
        /* If vcl node is not allocated for the requested DQID then allocate buffer */
259
426k
        ps_dqid_node = ps_dqid_ctxt->ps_dqid_node;
260
506k
        for(i4_lyr_idx = 0; i4_lyr_idx < i4_max_num_lyrs; i4_lyr_idx++)
261
506k
        {
262
506k
            if(SVCD_FALSE == ps_dqid_node->u1_valid_flag)
263
426k
            {
264
426k
                break;
265
426k
            }
266
            /* Loop updates */
267
79.7k
            ps_dqid_node += 1;
268
79.7k
        } /* Loop over all the nodes */
269
        /* Update the node structure */
270
426k
        ps_rqrd_dqid_node = ps_dqid_node;
271
426k
    }
272
273
    /* sanity checks */
274
990k
    if(NULL == ps_rqrd_dqid_node)
275
0
    {
276
0
        return NOT_OK;
277
0
    }
278
990k
    *pps_dqid_node = ps_rqrd_dqid_node;
279
280
990k
    return (OK);
281
990k
}
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
3.75M
{
308
3.75M
    nal_unit_t *ps_nal_unit;
309
310
3.75M
    if(NULL == ps_nal_parse_ctxt)
311
0
    {
312
0
        return NOT_OK;
313
0
    }
314
315
    /* Reset the NAL boundary detetction */
316
3.75M
    ps_nal_parse_ctxt->i4_find_nal_state = NAL_START;
317
3.75M
    ps_nal_parse_ctxt->i4_zero_byte_cnt = 0;
318
3.75M
    ps_nal_unit = ps_nal_parse_ctxt->pv_nal_unit;
319
3.75M
    ps_nal_unit->i4_num_bufs = 0;
320
321
    /*Reset emulation prevention */
322
3.75M
    isvcd_reset_emulation_ctxt(&ps_nal_parse_ctxt->s_emulation_ctxt);
323
324
    /*Reset the NAL header prms */
325
3.75M
    isvcd_set_default_nal_prms(&ps_nal_parse_ctxt->s_nal_prms);
326
327
    /* Reset other NAL level tracking variables */
328
3.75M
    ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_FALSE;
329
330
    /*Reset NAL buffer structure*/
331
3.75M
    isvcd_nal_buf_reset(&ps_nal_parse_ctxt->s_nal_buf);
332
333
3.75M
    return (OK);
334
3.75M
}
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
323k
{
362
323k
    WORD32 i4_status;
363
364
    /*-----------------------------------------------------------------------*/
365
    /*! Reset NAL boundary detetction logic                                  */
366
    /*-----------------------------------------------------------------------*/
367
323k
    i4_status = isvcd_nal_reset_ctxt(ps_nal_parse_ctxt);
368
369
323k
    UNUSED(i4_status);
370
371
    /*-----------------------------------------------------------------------*/
372
    /*! Reset picture boundary detctetion logic                              */
373
    /*-----------------------------------------------------------------------*/
374
323k
    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
323k
    ps_nal_parse_ctxt->pu1_non_vcl_nal_buf = ps_nal_parse_ctxt->pv_non_vcl_nal_buf;
380
323k
    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
323k
    ps_nal_parse_ctxt->u4_bytes_left_vcl = MAX_VCL_NAL_BUFF_SIZE;
384
385
323k
    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
323k
    UPDATE_NAL_BUF_PTR(&ps_nal_parse_ctxt->pu1_non_vcl_nal_buf, NON_VCL_NAL,
389
323k
                       &ps_nal_parse_ctxt->u4_bytes_left_non_vcl);
390
391
323k
    UPDATE_NAL_BUF_PTR(&ps_nal_parse_ctxt->pu1_vcl_nal_buf, VCL_NAL,
392
323k
                       &ps_nal_parse_ctxt->u4_bytes_left_vcl);
393
394
    /* Reset previous field */
395
323k
    ps_nal_parse_ctxt->ps_prev_non_vcl_buf = NULL;
396
323k
    ps_nal_parse_ctxt->i4_idr_pic_err_flag = 0;
397
398
    /*-----------------------------------------------------------------------*/
399
    /*! Reset other NAL related tracking variables                           */
400
    /*-----------------------------------------------------------------------*/
401
323k
    ps_nal_parse_ctxt->i4_num_non_vcl_nals = 0;
402
403
    /* Reset the vcl nal node buffer context */
404
323k
    i4_status = isvcd_dqid_ctxt_reset(&ps_nal_parse_ctxt->s_dqid_ctxt);
405
406
    /* Reset target layer update flag */
407
323k
    ps_nal_parse_ctxt->i4_tgt_lyr_update = SVCD_TRUE;
408
323k
}
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
3.93M
{
444
3.93M
    UWORD8 *pu1_input_buf;
445
3.93M
    WORD32 i4_status;
446
3.93M
    dec_seq_params_t *ps_sps;
447
3.93M
    dec_pic_params_t *ps_pps;
448
449
3.93M
    ps_sps = ps_nal_parse_ctxt->pv_seq_prms;
450
3.93M
    ps_pps = ps_nal_parse_ctxt->pv_pic_prms;
451
452
3.93M
    *pu4_err_code = 0;
453
3.93M
    *pi4_sps_pps_status = NAL_CORRUPT_DATA;
454
455
    /* Decode the NAL header */
456
3.93M
    isvcd_dec_nal_hdr(pu1_buf, i4_buf_size, ps_nal_parse_ctxt->pv_nal_header_buf, ps_nal_prms,
457
3.93M
                      ps_prefix_nal_buf, ps_prefix_nal_prms, pu4_err_code);
458
459
    /* If encountered with error return fail */
460
3.93M
    if(0 != *pu4_err_code)
461
76.2k
    {
462
76.2k
        return (NOT_OK);
463
76.2k
    }
464
465
3.85M
    if(ACCESS_UNIT_DELIMITER_RBSP == ps_nal_prms->i4_nal_unit_type)
466
13.6k
    {
467
13.6k
        *pi4_nal_discard_flag = 1;
468
13.6k
        return OK;
469
13.6k
    }
470
471
    /* Set the discard flag */
472
3.84M
    *pi4_nal_discard_flag = isvcd_discard_nal(
473
3.84M
        (void *) ps_nal_prms, (void *) &ps_nal_parse_ctxt->s_app_attr,
474
3.84M
        (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
3.84M
    if((NON_VCL_NAL == ps_nal_prms->i4_derived_nal_type) ||
482
731k
       (PREFIX_UNIT_NAL == ps_nal_prms->i4_nal_unit_type) || (SVCD_TRUE == *pi4_nal_discard_flag))
483
3.23M
    {
484
3.23M
        return (OK);
485
3.23M
    }
486
487
612k
    pu1_input_buf = pu1_buf;
488
612k
    pu1_input_buf += ps_nal_prms->i4_nal_header_len;
489
612k
    i4_buf_size -= ps_nal_prms->i4_nal_header_len;
490
491
612k
    i4_status =
492
612k
        isvcd_parse_part_slice_hdr(pu1_input_buf, i4_buf_size, ps_nal_parse_ctxt->pv_nal_header_buf,
493
612k
                                   ps_sps, ps_pps, ps_nal_prms, pu4_err_code, pi4_sps_pps_status);
494
495
612k
    return (i4_status);
496
3.84M
}
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
524k
{
535
524k
    dqid_node_t *ps_dqid_node;
536
524k
    vcl_node_t *ps_vcl_node;
537
524k
    WORD32 i4_status;
538
539
    /* If DQID is lesser than the DQID of the previous */
540
    /* NAL then declare the picture boundary           */
541
524k
    *pi4_pic_bound_type = PIC_BOUND_DQID;
542
524k
    if(i4_prev_dqid > ps_nal_prms->i4_dqid)
543
55.7k
    {
544
55.7k
        *pi4_pic_bound_status = PIC_BOUNDARY_TRUE;
545
55.7k
        return (OK);
546
55.7k
    }
547
548
    /* Perform the picture boundary detection only for */
549
    /* the layers with quality id equal to 0           */
550
468k
    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
468k
    i4_status =
558
468k
        isvcd_get_dqid_node(&ps_nal_parse_ctxt->s_dqid_ctxt, (UWORD8) i4_prev_dqid, &ps_dqid_node);
559
468k
    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
468k
    if(SVCD_FALSE == ps_dqid_node->u1_valid_flag)
566
171k
    {
567
171k
        *pi4_pic_bound_status = PIC_BOUNDARY_FALSE;
568
171k
        return (OK);
569
171k
    }
570
571
296k
    *pi4_pic_bound_type = PIC_BOUND_SLICE_PRMS;
572
296k
    *pi4_pic_bound_status = PIC_BOUNDARY_TRUE;
573
296k
    ps_vcl_node = ps_dqid_node->ps_vcl_node;
574
575
    /* Compare NAL ref idc */
576
296k
    {
577
296k
        WORD32 i4_prev_ref_pic_flag;
578
296k
        WORD32 i4_cur_ref_pic_flag;
579
580
296k
        i4_prev_ref_pic_flag = (0 != ps_vcl_node->i4_nal_ref_idc);
581
296k
        i4_cur_ref_pic_flag = (0 != ps_nal_prms->i4_nal_ref_idc);
582
583
296k
        if(i4_prev_ref_pic_flag != i4_cur_ref_pic_flag)
584
46.7k
        {
585
46.7k
            return (OK);
586
46.7k
        }
587
296k
    }
588
589
    /* Compare IDR picture flag */
590
249k
    if(ps_vcl_node->i4_idr_pic_flag != ps_nal_prms->i4_idr_pic_flag)
591
26.2k
    {
592
26.2k
        return (OK);
593
26.2k
    }
594
595
    /* Compare PPS id */
596
223k
    if(ps_vcl_node->u1_pps_id != ps_nal_prms->u1_pps_id)
597
49.6k
    {
598
49.6k
        return (OK);
599
49.6k
    }
600
601
    /* Compare idr pic num */
602
174k
    if((SVCD_TRUE == ps_nal_prms->i4_idr_pic_flag) &&
603
126k
       (ps_vcl_node->i4_idr_pic_num != ps_nal_prms->i4_idr_pic_num))
604
31.7k
    {
605
31.7k
        return (OK);
606
31.7k
    }
607
608
    /* Compare frame number */
609
142k
    if(ps_vcl_node->u2_frm_num != ps_nal_prms->u2_frm_num)
610
82.6k
    {
611
82.6k
        return (OK);
612
82.6k
    }
613
614
    /* Compare poc lsb */
615
59.6k
    if(ps_dqid_node->i4_poc_lsb != ps_nal_prms->i4_poc_lsb)
616
5.05k
    {
617
5.05k
        return (OK);
618
5.05k
    }
619
620
    /* Compare delta poc bottom */
621
54.5k
    if(ps_dqid_node->i4_delta_poc_bot != ps_nal_prms->i4_delta_poc_bot)
622
1.30k
    {
623
1.30k
        return (OK);
624
1.30k
    }
625
626
    /* Compare delta poc [0] */
627
53.2k
    if(ps_dqid_node->ai4_delta_poc[0] != ps_nal_prms->ai4_delta_poc[0])
628
3.24k
    {
629
3.24k
        return (OK);
630
3.24k
    }
631
632
    /* Compare delta poc [0] */
633
50.0k
    if(ps_dqid_node->ai4_delta_poc[1] != ps_nal_prms->ai4_delta_poc[1])
634
868
    {
635
868
        return (OK);
636
868
    }
637
638
49.1k
    *pi4_pic_bound_status = PIC_BOUNDARY_FALSE;
639
49.1k
    return (OK);
640
50.0k
}
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
437k
{
697
437k
    UWORD32 u4_err_code;
698
437k
    WORD32 i4_zero_cnt;
699
437k
    WORD32 i4_status;
700
437k
    nal_prms_t s_nal_prms = {0};
701
437k
    nal_prms_t s_prefix_nal_prms = {0};
702
437k
    nal_buf_t s_prefix_nal_buf = {0};
703
437k
    WORD32 i4_pic_bound_type;
704
437k
    WORD32 i4_pic_bound_status;
705
437k
    UWORD8 *pu1_buf;
706
437k
    WORD32 i4_buf_size;
707
437k
    WORD32 i4_more_data_flag;
708
437k
    WORD32 i4_new_lyr_flag;
709
437k
    WORD32 i4_prev_dqid;
710
437k
    WORD32 i4_nal_discard_flag;
711
712
    /* Initializations */
713
437k
    i4_zero_cnt = 0;
714
437k
    s_prefix_nal_buf.i4_valid_flag = SVCD_FALSE;
715
437k
    *pi4_pic_bound_status = PIC_BOUNDARY_FALSE;
716
437k
    i4_new_lyr_flag = SVCD_TRUE;
717
718
    /* Get the previous layer's DQID                    */
719
437k
    if(SVCD_TRUE == ps_nal_parse_ctxt->i4_is_frst_vcl_nal_in_au)
720
171k
    {
721
171k
        ps_nal_parse_ctxt->i4_prev_dq_id = ps_nal_prms->i4_dqid;
722
171k
        ps_nal_parse_ctxt->i4_is_frst_vcl_nal_in_au = SVCD_FALSE;
723
171k
    }
724
437k
    i4_prev_dqid = ps_nal_parse_ctxt->i4_prev_dq_id;
725
437k
    ps_nal_parse_ctxt->i4_prev_dq_id = ps_nal_prms->i4_dqid;
726
727
    /* Detect the picture boundary */
728
437k
    if(ps_nal_prms->i4_dqid <= i4_prev_dqid)
729
383k
    {
730
383k
        i4_status =
731
383k
            isvcd_compare_nal_prms(ps_nal_prms, FIRST_PASS, i4_prev_dqid, &i4_pic_bound_type,
732
383k
                                   &i4_pic_bound_status, ps_nal_parse_ctxt);
733
383k
        if(OK != i4_status)
734
0
        {
735
0
            return NOT_OK;
736
0
        }
737
383k
        i4_new_lyr_flag = SVCD_FALSE;
738
739
        /* Check whether the picture boundary is detected */
740
        /* or not */
741
383k
        if(PIC_BOUNDARY_FALSE == i4_pic_bound_status)
742
212k
        {
743
212k
            return (OK);
744
212k
        }
745
746
        /* Otherwise look for next nal and compare again */
747
170k
        *pi4_pic_bound_status = PIC_BOUNDARY_TRUE;
748
170k
    }
749
750
224k
    do
751
226k
    {
752
226k
        WORD32 i4_sps_pps_corrupt_status;
753
226k
        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
226k
        if((NAL_END != ps_nal_parse_ctxt->i4_find_nal_state) ||
758
211k
           ((WORD64) i4_cur_pos >= (WORD64) *pu4_num_bytes))
759
15.5k
        {
760
15.5k
            return (OK);
761
15.5k
        }
762
763
        /* Otherwise fill the parameters */
764
210k
        pu1_buf = pu1_stream_buffer;
765
210k
        pu1_buf += i4_cur_pos;
766
210k
        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
210k
        isvcd_set_default_nal_prms(&s_nal_prms);
773
774
        /* take a back up of tgt lyr update flag */
775
210k
        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
210k
        ps_nal_parse_ctxt->i4_tgt_lyr_update = SVCD_FALSE;
779
780
210k
        i4_status = isvcd_get_nal_prms(pu1_buf, i4_buf_size, &s_nal_prms, &s_prefix_nal_prms,
781
210k
                                       &s_prefix_nal_buf, &u4_err_code, &i4_sps_pps_corrupt_status,
782
210k
                                       &i4_nal_discard_flag, ps_nal_parse_ctxt);
783
        /* restore back the tgt lyr update flag */
784
210k
        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
210k
        if(0 != u4_err_code)
788
11.7k
        {
789
11.7k
            return (OK);
790
11.7k
        }
791
792
199k
        i4_more_data_flag = SVCD_FALSE;
793
794
        /* If prefix NAL unit comes then save the nal prms*/
795
199k
        if(PREFIX_UNIT_NAL == s_nal_prms.i4_nal_unit_type)
796
1.85k
        {
797
1.85k
            UWORD32 u4_bytes_consumed;
798
1.85k
            WORD32 i4_status;
799
800
            /* If prefix NAL is not discarded then set the varaibles */
801
            /* appropriatly */
802
1.85k
            if(SVCD_FALSE == i4_nal_discard_flag)
803
905
            {
804
905
                s_prefix_nal_buf.i4_valid_flag = SVCD_TRUE;
805
905
                memcpy(&s_prefix_nal_prms, &s_nal_prms, sizeof(nal_prms_t));
806
905
            }
807
808
            /* Go to next start code */
809
1.85k
            i4_zero_cnt = 0;
810
1.85k
            u4_bytes_consumed = 0;
811
1.85k
            i4_status = isvcd_nal_find_start_code(pu1_stream_buffer, i4_cur_pos, *pu4_num_bytes,
812
1.85k
                                                  &i4_zero_cnt, &u4_bytes_consumed);
813
            /* If associated NAL unit is  not present then */
814
1.85k
            if(SC_FOUND != i4_status)
815
187
            {
816
187
                return (OK);
817
187
            }
818
1.67k
            i4_cur_pos += u4_bytes_consumed;
819
1.67k
            i4_more_data_flag = SVCD_TRUE;
820
1.67k
        }
821
199k
    } 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
197k
    if((NON_VCL_NAL == s_nal_prms.i4_derived_nal_type) ||
826
167k
       (PREFIX_UNIT_NAL == s_nal_prms.i4_nal_unit_type) || (SVCD_TRUE == i4_nal_discard_flag))
827
34.4k
    {
828
34.4k
        return (OK);
829
34.4k
    }
830
831
162k
    if(SVCD_FALSE == i4_new_lyr_flag)
832
120k
    {
833
120k
        if(PIC_BOUND_DQID == i4_pic_bound_type)
834
38.4k
        {
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
38.4k
            if(i4_prev_dqid != s_nal_prms.i4_dqid)
838
19.4k
            {
839
19.4k
                return (OK);
840
19.4k
            }
841
38.4k
        }
842
81.9k
        else
843
81.9k
        {
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
81.9k
            if(PIC_BOUND_SLICE_PRMS != i4_pic_bound_type)
847
0
            {
848
0
                return NOT_OK;
849
0
            }
850
851
81.9k
            if((i4_prev_dqid & 0xF) != (s_nal_prms.i4_dqid & 0xF))
852
0
            {
853
0
                return (OK);
854
0
            }
855
81.9k
        }
856
857
100k
        isvcd_compare_nal_prms(&s_nal_prms, SECOND_PASS, i4_prev_dqid, &i4_pic_bound_type,
858
100k
                               &i4_pic_bound_status, ps_nal_parse_ctxt);
859
100k
        *pi4_pic_bound_status = i4_pic_bound_status;
860
861
100k
        if(PIC_BOUNDARY_FALSE == i4_pic_bound_status)
862
6.88k
        {
863
6.88k
            ps_nal_parse_ctxt->i4_prev_dq_id = i4_prev_dqid;
864
6.88k
        }
865
100k
    }
866
42.3k
    else
867
42.3k
    {
868
42.3k
        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
42.3k
        if(i4_prev_dqid == s_nal_prms.i4_dqid)
876
39.4k
        {
877
39.4k
            isvcd_compare_nal_prms(&s_nal_prms, SECOND_PASS, i4_prev_dqid, &i4_pic_bound_type,
878
39.4k
                                   &i4_pic_bound_status, ps_nal_parse_ctxt);
879
            /* NAL header is corrupted and hence correct it  */
880
39.4k
            if(PIC_BOUNDARY_FALSE == i4_pic_bound_status)
881
1.12k
            {
882
1.12k
                ps_nal_prms->i4_dqid = s_nal_prms.i4_dqid;
883
1.12k
                ps_nal_prms->i4_dependency_id = s_nal_prms.i4_dependency_id;
884
1.12k
                ps_nal_prms->i4_quality_id = s_nal_prms.i4_quality_id;
885
1.12k
                ps_nal_parse_ctxt->i4_prev_dq_id = ps_nal_prms->i4_dqid;
886
1.12k
            }
887
39.4k
        }
888
42.3k
        *pi4_pic_bound_status = PIC_BOUNDARY_FALSE;
889
42.3k
    }
890
143k
    return (OK);
891
162k
}
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
254k
{
918
254k
    vcl_node_t *ps_bot_node;
919
254k
    vcl_node_t *ps_top_node;
920
254k
    vcl_node_t *ps_node;
921
254k
    WORD32 i4_rqrd_dqid;
922
923
    /* sanity checks */
924
254k
    if((NULL == ps_vcl_nal) || (NULL == ps_vcl_node))
925
0
    {
926
0
        return NOT_OK;
927
0
    }
928
929
254k
    i4_rqrd_dqid = (ps_vcl_node->i4_dependency_id << 4);
930
254k
    i4_rqrd_dqid += ps_vcl_node->i4_quality_id;
931
254k
    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
331k
    while(NULL != ps_node)
936
79.5k
    {
937
79.5k
        WORD32 i4_dqid;
938
939
79.5k
        i4_dqid = (ps_node->i4_dependency_id << 4);
940
79.5k
        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
79.5k
        if(i4_dqid > i4_rqrd_dqid)
946
2.62k
        {
947
2.62k
            ps_bot_node = ps_node->ps_bot_node;
948
2.62k
            break;
949
2.62k
        }
950
951
76.9k
        ps_node = ps_node->ps_top_node;
952
76.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
254k
    if(NULL == ps_node)
958
252k
    {
959
252k
        ps_bot_node = ps_vcl_nal->ps_top_node;
960
252k
    }
961
962
    /* Insert the node into DQID list */
963
254k
    if(NULL != ps_bot_node)
964
76.9k
    {
965
76.9k
        ps_top_node = ps_bot_node->ps_top_node;
966
76.9k
    }
967
178k
    else
968
178k
    {
969
178k
        ps_top_node = ps_vcl_nal->ps_bot_node;
970
178k
    }
971
972
    /* Join previous node and specified node */
973
254k
    if(NULL != ps_bot_node)
974
76.9k
    {
975
76.9k
        ps_bot_node->ps_top_node = ps_vcl_node;
976
76.9k
    }
977
178k
    else
978
178k
    {
979
178k
        ps_vcl_nal->ps_bot_node = ps_vcl_node;
980
178k
    }
981
254k
    ps_vcl_node->ps_bot_node = ps_bot_node;
982
983
    /* Join next node and specified node */
984
254k
    if(NULL != ps_top_node)
985
2.62k
    {
986
2.62k
        ps_top_node->ps_bot_node = ps_vcl_node;
987
2.62k
    }
988
252k
    else
989
252k
    {
990
252k
        ps_vcl_nal->ps_top_node = ps_vcl_node;
991
252k
    }
992
254k
    ps_vcl_node->ps_top_node = ps_top_node;
993
994
254k
    return (OK);
995
254k
}
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
3.35M
{
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
3.35M
    nal_prms_t *ps_nal_prms;
1031
3.35M
    nal_buf_t *ps_nal_buf, *ps_prefix_nal_buf;
1032
1033
3.35M
    ps_nal_prms = &ps_nal_parse_ctxt->s_nal_prms;
1034
3.35M
    ps_nal_prms = &ps_nal_parse_ctxt->s_nal_prms;
1035
3.35M
    ps_nal_buf = &ps_nal_parse_ctxt->s_nal_buf;
1036
3.35M
    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
3.35M
    if(PREFIX_UNIT_NAL == ps_nal_prms->i4_nal_unit_type)
1041
2.93k
    {
1042
        /* Since we consume the zeroes in start code also */
1043
        /* size has to reduced                            */
1044
2.93k
        if(NAL_END == ps_nal_parse_ctxt->i4_find_nal_state)
1045
2.93k
        {
1046
2.93k
            ps_prefix_nal_buf->i4_buf_size -= 2;
1047
2.93k
        }
1048
1049
2.93k
        ps_prefix_nal_buf->u4_max_bits =
1050
2.93k
            isvcd_nal_rbsp_to_sodb(ps_prefix_nal_buf->pu1_buf, ps_prefix_nal_buf->i4_buf_size, 0);
1051
2.93k
        memcpy(&ps_nal_parse_ctxt->s_prefix_nal_prms, &ps_nal_parse_ctxt->s_nal_prms,
1052
2.93k
               sizeof(nal_prms_t));
1053
2.93k
        return;
1054
2.93k
    }
1055
1056
3.35M
    if(ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode)
1057
3.35M
    {
1058
        /* Since we consume the zeroes in start code also */
1059
        /* size has to reduced                            */
1060
3.35M
        if(NAL_END == ps_nal_parse_ctxt->i4_find_nal_state)
1061
3.35M
        {
1062
3.35M
            ps_nal_buf->i4_buf_size -= 2;
1063
3.35M
        }
1064
3.35M
    }
1065
1066
3.35M
    if(VCL_NAL == ps_nal_prms->i4_derived_nal_type)
1067
272k
    {
1068
272k
        dqid_node_t *ps_dqid_node;
1069
272k
        vcl_node_t *ps_node;
1070
272k
        WORD32 i4_status;
1071
272k
        dec_pic_params_t *ps_pps;
1072
272k
        dec_seq_params_t *ps_sps;
1073
272k
        vcl_buf_hdr_t *ps_vcl_hdr;
1074
272k
        vcl_buf_hdr_t *ps_prev_vcl_hdr;
1075
272k
        WORD32 i4_slice_offset;
1076
1077
272k
        ps_sps = ps_nal_parse_ctxt->pv_seq_prms;
1078
272k
        ps_sps += ps_nal_prms->u1_sps_id;
1079
272k
        ps_pps = ps_nal_parse_ctxt->pv_pic_prms;
1080
272k
        ps_pps += ps_nal_prms->u1_pps_id;
1081
1082
        /* Get the VCL NAL node */
1083
272k
        i4_status = isvcd_get_dqid_node(&ps_nal_parse_ctxt->s_dqid_ctxt,
1084
272k
                                        (UWORD8) ps_nal_parse_ctxt->i4_prev_dq_id, &ps_dqid_node);
1085
1086
272k
        ps_node = ps_dqid_node->ps_vcl_node;
1087
1088
272k
        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
272k
        if(SVCD_FALSE == ps_dqid_node->u1_valid_flag)
1100
223k
        {
1101
            /* Update the DQID node */
1102
223k
            ps_dqid_node->u1_valid_flag = SVCD_TRUE;
1103
223k
            ps_dqid_node->u1_dqid = (ps_nal_prms->i4_dependency_id << 4);
1104
223k
            ps_dqid_node->u1_dqid += ps_nal_prms->i4_quality_id;
1105
223k
            ps_dqid_node->i4_poc_lsb = ps_nal_prms->i4_poc_lsb;
1106
223k
            ps_dqid_node->i4_delta_poc_bot = ps_nal_prms->i4_delta_poc_bot;
1107
223k
            ps_dqid_node->ai4_delta_poc[0] = ps_nal_prms->ai4_delta_poc[0];
1108
223k
            ps_dqid_node->ai4_delta_poc[1] = ps_nal_prms->ai4_delta_poc[1];
1109
1110
            /* Update the VCL node */
1111
223k
            ps_node->i4_quality_id = ps_nal_prms->i4_quality_id;
1112
223k
            ps_node->i4_dependency_id = ps_nal_prms->i4_dependency_id;
1113
223k
            ps_node->i4_temporal_id = ps_nal_prms->i4_temporal_id;
1114
223k
            ps_node->i4_priority_id = ps_nal_prms->i4_priority_id;
1115
223k
            ps_node->i4_idr_pic_flag = ps_nal_prms->i4_idr_pic_flag;
1116
223k
            ps_node->i4_nal_ref_idc = ps_nal_prms->i4_nal_ref_idc;
1117
223k
            ps_node->i4_nal_unit_type = ps_nal_prms->i4_nal_unit_type;
1118
223k
            ps_node->i4_use_ref_base = ps_nal_prms->i4_use_ref_base_pic_flag;
1119
223k
            ps_node->i4_nal_ref_idc = ps_nal_prms->i4_nal_ref_idc;
1120
223k
            ps_node->u1_sps_id = ps_nal_prms->u1_sps_id;
1121
223k
            ps_node->u1_pps_id = ps_nal_prms->u1_pps_id;
1122
223k
            ps_node->u2_frm_num = ps_nal_prms->u2_frm_num;
1123
223k
            ps_node->i4_idr_pic_num = ps_nal_prms->i4_idr_pic_num;
1124
223k
            ps_node->i4_num_slices = 0;
1125
223k
            ps_node->u1_acc_no_int_pred = 1;
1126
223k
            if(0 == ps_sps->u1_pic_order_cnt_type)
1127
181k
            {
1128
181k
                ps_node->i4_poc_syntax = ps_nal_prms->i4_poc_lsb;
1129
181k
            }
1130
41.6k
            else
1131
41.6k
            {
1132
41.6k
                ps_node->i4_poc_syntax = ps_nal_prms->ai4_delta_poc[0];
1133
41.6k
            }
1134
1135
            /* Insert the node into DQID list */
1136
223k
            i4_status = isvcd_insert_vcl_node(ps_vcl_nal, ps_node);
1137
223k
            if(OK != i4_status)
1138
0
            {
1139
0
                return;
1140
0
            }
1141
1142
            /* Reset the previous field */
1143
223k
            ps_nal_parse_ctxt->ps_prev_vcl_buf = NULL;
1144
223k
            ps_node->ps_first_vcl_nal = NULL;
1145
223k
        }
1146
1147
        /* Update accumulated no inter layer prediction */
1148
272k
        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
272k
        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
272k
        else
1167
272k
        {
1168
272k
            ps_vcl_hdr = (vcl_buf_hdr_t *) (ps_nal_buf->pu1_buf - GET_NAL_BUF_INC(VCL_NAL));
1169
272k
        }
1170
1171
272k
        i4_slice_offset = 0;
1172
272k
        if(SVCD_TRUE == ps_prefix_nal_buf->i4_valid_flag)
1173
613
        {
1174
613
            ps_vcl_hdr = (vcl_buf_hdr_t *) (ps_prefix_nal_buf->pu1_buf - GET_NAL_BUF_INC(VCL_NAL));
1175
613
            i4_slice_offset = ps_nal_buf->pu1_buf - ps_prefix_nal_buf->pu1_buf;
1176
613
        }
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
272k
        ps_prev_vcl_hdr = ps_nal_parse_ctxt->ps_prev_vcl_buf;
1182
272k
        if(NULL != ps_prev_vcl_hdr)
1183
49.0k
        {
1184
49.0k
            ps_prev_vcl_hdr->ps_next = ps_vcl_hdr;
1185
49.0k
        }
1186
223k
        else
1187
223k
        {
1188
223k
            ps_node->ps_first_vcl_nal = ps_vcl_hdr;
1189
223k
        }
1190
1191
        /* Fill the VCL buffer header */
1192
272k
        ps_vcl_hdr->ps_next = NULL;
1193
272k
        ps_vcl_hdr->i4_no_int_lyr_pred = ps_nal_prms->i4_no_int_lyr_pred;
1194
272k
        ps_vcl_hdr->i4_first_mb_addr = ps_nal_prms->u4_first_mb_addr;
1195
272k
        ps_vcl_hdr->u4_prefix_nal_bits = ps_prefix_nal_buf->u4_max_bits;
1196
272k
        ps_vcl_hdr->i4_slice_offset = 0;
1197
272k
        ps_vcl_hdr->i4_buf_offset = GET_NAL_BUF_INC(VCL_NAL);
1198
272k
        ps_vcl_hdr->i4_slice_offset = i4_slice_offset;
1199
1200
        /* Determine max num bits */
1201
272k
        ps_nal_buf->u4_max_bits = isvcd_nal_rbsp_to_sodb(
1202
272k
            ps_nal_buf->pu1_buf, ps_nal_buf->i4_buf_size, ps_pps->u1_entropy_coding_mode);
1203
272k
        ps_vcl_hdr->u4_max_bits = ps_nal_buf->u4_max_bits;
1204
1205
        /* Updates */
1206
272k
        ps_nal_parse_ctxt->ps_prev_vcl_buf = ps_vcl_hdr;
1207
272k
        ps_node->i4_num_slices += 1;
1208
272k
    }
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
3.07M
    else
1214
3.07M
    {
1215
3.07M
        non_vcl_buf_hdr_t *ps_non_vcl_buf_hdr;
1216
3.07M
        non_vcl_buf_hdr_t *ps_prev_non_vcl_buf_hdr;
1217
1218
3.07M
        ps_non_vcl_buf_hdr =
1219
3.07M
            (non_vcl_buf_hdr_t *) (ps_nal_buf->pu1_buf - GET_NAL_BUF_INC(NON_VCL_NAL));
1220
1221
        /* Update NON VCL structure */
1222
3.07M
        ps_non_vcl_buf_hdr->i4_nal_unit_type = ps_nal_prms->i4_nal_unit_type;
1223
3.07M
        ps_non_vcl_buf_hdr->ps_next = NULL;
1224
3.07M
        ps_non_vcl_buf_hdr->i4_buf_offset = GET_NAL_BUF_INC(NON_VCL_NAL);
1225
3.07M
        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
3.07M
        ps_prev_non_vcl_buf_hdr = ps_nal_parse_ctxt->ps_prev_non_vcl_buf;
1231
3.07M
        if(NULL != ps_prev_non_vcl_buf_hdr)
1232
2.98M
        {
1233
2.98M
            ps_prev_non_vcl_buf_hdr->ps_next = ps_non_vcl_buf_hdr;
1234
2.98M
        }
1235
98.6k
        else
1236
98.6k
        {
1237
98.6k
            ps_non_vcl_nal->ps_first_non_vcl_nal = ps_non_vcl_buf_hdr;
1238
98.6k
        }
1239
1240
        /* Updates */
1241
3.07M
        ps_nal_parse_ctxt->i4_num_non_vcl_nals += 1;
1242
3.07M
        ps_non_vcl_nal->i4_num_non_vcl_nals = ps_nal_parse_ctxt->i4_num_non_vcl_nals;
1243
3.07M
        ps_nal_parse_ctxt->ps_prev_non_vcl_buf = ps_non_vcl_buf_hdr;
1244
3.07M
    }
1245
3.35M
}
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
171k
{
1341
171k
    vcl_node_t *ps_node;
1342
171k
    target_lyr_attr_t *ps_int_attr;
1343
171k
    dqid_ctxt_t *ps_dqid_ctxt;
1344
171k
    UWORD8 u1_dep_id;
1345
171k
    WORD32 i4_status;
1346
171k
    WORD32 i4_dep_id;
1347
1348
171k
    ps_int_attr = &ps_nal_parse_ctxt->s_int_attr;
1349
171k
    ps_dqid_ctxt = &ps_nal_parse_ctxt->s_dqid_ctxt;
1350
171k
    i4_dep_id = -1;
1351
1352
421k
    for(u1_dep_id = 0; u1_dep_id <= ps_int_attr->i4_dependency_id; u1_dep_id++)
1353
250k
    {
1354
250k
        dqid_node_t *ps_dqid_node;
1355
1356
        /* Get a DQID node */
1357
250k
        i4_status = isvcd_get_dqid_node(ps_dqid_ctxt, (UWORD8) (u1_dep_id << 4), &ps_dqid_node);
1358
250k
        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
250k
        if(SVCD_FALSE == ps_dqid_node->u1_valid_flag)
1365
31.9k
        {
1366
31.9k
            if(1 == ps_nal_parse_ctxt->i4_idr_pic_err_flag)
1367
260
            {
1368
260
                ps_int_attr->i4_dependency_id = i4_dep_id;
1369
260
                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
339
                while(NULL != ps_vcl_nal->ps_top_node)
1375
169
                {
1376
                    /* if higher dependency */
1377
169
                    if(ps_vcl_nal->ps_top_node->i4_dependency_id > i4_dep_id)
1378
79
                    {
1379
79
                        ps_vcl_nal->ps_top_node = ps_vcl_nal->ps_top_node->ps_bot_node;
1380
79
                    }
1381
90
                    else
1382
90
                    {
1383
90
                        break;
1384
90
                    }
1385
169
                }
1386
1387
                /* if no node exists in the dependency list */
1388
260
                if(NULL == ps_vcl_nal->ps_top_node)
1389
170
                {
1390
170
                    ps_vcl_nal->ps_bot_node = NULL;
1391
170
                }
1392
90
                else if(ps_vcl_nal->ps_top_node == ps_vcl_nal->ps_bot_node)
1393
90
                {
1394
                    /* if a single node exists */
1395
90
                    ps_vcl_nal->ps_top_node->ps_bot_node = NULL;
1396
90
                    ps_vcl_nal->ps_bot_node->ps_top_node = NULL;
1397
90
                }
1398
1399
260
                return (NOT_OK);
1400
260
            }
1401
31.6k
            else
1402
31.6k
            {
1403
31.6k
                ps_dqid_node->u1_valid_flag = SVCD_TRUE;
1404
31.6k
                ps_dqid_node->u1_dqid = (u1_dep_id << 4);
1405
1406
                /* Fill VCL node information */
1407
31.6k
                ps_node = ps_dqid_node->ps_vcl_node;
1408
31.6k
                ps_node->i4_dependency_id = u1_dep_id;
1409
31.6k
                ps_node->i4_quality_id = 0;
1410
31.6k
                ps_node->ps_first_vcl_nal = NULL;
1411
31.6k
            }
1412
1413
            /* Insert node into DQID list */
1414
31.6k
            i4_status = isvcd_insert_vcl_node(ps_vcl_nal, ps_node);
1415
31.6k
            if(OK != i4_status)
1416
0
            {
1417
0
                return (NOT_OK);
1418
0
            }
1419
31.6k
        }
1420
1421
249k
        i4_dep_id++;
1422
249k
    } /* End of loop over all the dependency id */
1423
171k
    return (OK);
1424
171k
}
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
26.5k
{
1458
26.5k
    nal_parse_ctxt_t *ps_nal_parse_ctxt;
1459
26.5k
    target_lyr_attr_t *ps_app_attr;
1460
1461
26.5k
    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
26.5k
    ps_nal_parse_ctxt = (nal_parse_ctxt_t *) pv_nal_parse_ctxt;
1467
26.5k
    ps_app_attr = &ps_nal_parse_ctxt->s_app_attr;
1468
1469
    /*-----------------------------------------------------------------------*/
1470
    /*! Register the target information into context structure               */
1471
    /*-----------------------------------------------------------------------*/
1472
26.5k
    ps_app_attr->i4_quality_id = i4_target_quality_id;
1473
26.5k
    ps_app_attr->i4_dependency_id = i4_target_dependency_id;
1474
26.5k
    ps_app_attr->i4_temporal_id = i4_target_temporal_id;
1475
26.5k
    ps_app_attr->i4_priority_id = i4_target_priority_id;
1476
26.5k
    return IV_SUCCESS;
1477
26.5k
}
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
26.5k
{
1511
26.5k
    nal_parse_ctxt_t *ps_nal_parse_ctxt = (nal_parse_ctxt_t *) pv_nal_parse_ctxt;
1512
26.5k
    UNUSED(i4_input_mode);
1513
1514
    /*-----------------------------------------------------------------------*/
1515
    /*! Set the input bitstream mode of context structure                    */
1516
    /*-----------------------------------------------------------------------*/
1517
26.5k
    switch(i4_input_bitstream_mode)
1518
26.5k
    {
1519
26.5k
        case ANNEX_B:
1520
26.5k
        case NON_ANNEX_B:
1521
26.5k
            break;
1522
0
        default:
1523
0
            break;
1524
26.5k
    }
1525
1526
26.5k
    ps_nal_parse_ctxt->i4_input_bitstream_mode = i4_input_bitstream_mode;
1527
1528
    /*-----------------------------------------------------------------------*/
1529
    /*! Perform the picture level initialization                             */
1530
    /*-----------------------------------------------------------------------*/
1531
26.5k
    isvcd_pic_reset_ctxt(pv_nal_parse_ctxt);
1532
1533
    /* Reset the prefix nal unit buffer structure */
1534
26.5k
    isvcd_nal_buf_reset(&ps_nal_parse_ctxt->s_prefix_nal_buf);
1535
1536
    /*-----------------------------------------------------------------------*/
1537
    /*! Reset other varaibles                                                */
1538
    /*-----------------------------------------------------------------------*/
1539
26.5k
    ps_nal_parse_ctxt->i4_dec_frst_sc_flag = SVCD_TRUE;
1540
26.5k
    ps_nal_parse_ctxt->i4_eos_flag = SVCD_FALSE;
1541
26.5k
    ps_nal_parse_ctxt->u1_pic_boundary_aud_flag = 0;
1542
26.5k
    ps_nal_parse_ctxt->u4_bytes_left = 0;
1543
1544
    /* Reset target layer attributes */
1545
26.5k
    {
1546
26.5k
        target_lyr_attr_t *ps_app_attr;
1547
26.5k
        target_lyr_attr_t *ps_int_attr;
1548
1549
26.5k
        ps_app_attr = &ps_nal_parse_ctxt->s_app_attr;
1550
26.5k
        ps_int_attr = &ps_nal_parse_ctxt->s_int_attr;
1551
1552
26.5k
        ps_app_attr->i4_dependency_id = MAX_DEPENDENCY_ID;
1553
26.5k
        ps_app_attr->i4_quality_id = MAX_QUALITY_ID;
1554
26.5k
        ps_app_attr->i4_temporal_id = MAX_TEMPORAL_ID;
1555
26.5k
        ps_app_attr->i4_priority_id = MAX_PRIORITY_ID;
1556
1557
26.5k
        ps_int_attr->i4_dependency_id = -1;
1558
26.5k
        ps_int_attr->i4_quality_id = MAX_QUALITY_ID;
1559
26.5k
        ps_int_attr->i4_temporal_id = 0;
1560
26.5k
        ps_int_attr->i4_priority_id = MAX_PRIORITY_ID;
1561
26.5k
    }
1562
26.5k
}
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
171k
{
1678
171k
    WORD32 i4_status;
1679
1680
171k
    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
171k
    if(NOT_OK == i4_status)
1688
260
    {
1689
260
        ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_TRUE;
1690
260
        ps_vcl_nal->i1_nal_ref_id_next = -1;
1691
260
    }
1692
171k
    else
1693
171k
    {
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
171k
        ps_vcl_nal->i1_nal_ref_id_next = ps_nal_prms->i4_nal_ref_idc;
1699
1700
171k
        ps_vcl_nal->u2_frm_num_next = ps_nal_prms->u2_frm_num;
1701
171k
    }
1702
1703
    /* -------- reset few variables in context structure ----*/
1704
171k
    isvcd_pic_reset_ctxt(ps_nal_parse_ctxt);
1705
171k
}
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
177k
{
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
177k
    nal_parse_ctxt_t *ps_nal_parse_ctxt;
1755
177k
    vcl_nal_t *ps_vcl_nal;
1756
177k
    non_vcl_nal_t *ps_non_vcl_nal;
1757
177k
    nal_unit_t *ps_nal_unit;
1758
177k
    WORD32 i4_nal_start_flag, i4_cur_pos, i4_status;
1759
177k
    WORD32 i4_nal_header_len, i4_more_data_flag;
1760
177k
    UWORD32 u4_bytes_consumed_temp = 0;
1761
177k
    UWORD8 **ppu1_out_buf;
1762
177k
    nal_prms_t *ps_nal_prms;
1763
177k
    WORD32 i4_pic_bound_status;
1764
1765
177k
    ps_nal_parse_ctxt = (nal_parse_ctxt_t *) pv_nal_parse_ctxt;
1766
177k
    ps_vcl_nal = (vcl_nal_t *) pv_out_vcl_nal;
1767
177k
    ps_non_vcl_nal = (non_vcl_nal_t *) pv_out_non_vcl_nal;
1768
177k
    ps_nal_unit = (nal_unit_t *) ps_nal_parse_ctxt->pv_nal_unit;
1769
177k
    ps_nal_prms = &ps_nal_parse_ctxt->s_nal_prms;
1770
1771
    /* Initialization */
1772
177k
    i4_cur_pos = 0;
1773
177k
    *pu4_bytes_consumed = 0;
1774
177k
    i4_nal_header_len = 0;
1775
177k
    i4_nal_start_flag = SVCD_FALSE;
1776
177k
    i4_more_data_flag = SVCD_TRUE;
1777
177k
    i4_pic_bound_status = PIC_BOUNDARY_FALSE;
1778
1779
177k
    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
177k
    if(SVCD_TRUE == ps_nal_parse_ctxt->i4_is_frst_vcl_nal_in_au)
1786
177k
    {
1787
177k
        nal_buf_t *ps_prefix_nal_buf;
1788
1789
177k
        ps_prefix_nal_buf = &ps_nal_parse_ctxt->s_prefix_nal_buf;
1790
177k
        if(SVCD_TRUE == ps_prefix_nal_buf->i4_valid_flag)
1791
609
        {
1792
609
            WORD32 i4_buf_size;
1793
609
            UWORD8 *pu1_vcl_nal;
1794
1795
609
            if(ps_prefix_nal_buf->i4_buf_size > 0)
1796
167
            {
1797
167
                i4_buf_size = ps_prefix_nal_buf->i4_buf_size;
1798
167
                i4_buf_size = UP_ALIGN_8(i4_buf_size + BUFFER_ALIGN_4);
1799
167
            }
1800
442
            else
1801
442
            {
1802
442
                i4_buf_size = 0;
1803
442
            }
1804
1805
609
            pu1_vcl_nal = ps_nal_parse_ctxt->pu1_vcl_nal_buf + i4_buf_size;
1806
1807
609
            memmove(ps_nal_parse_ctxt->pu1_vcl_nal_buf, ps_prefix_nal_buf->pu1_buf, i4_buf_size);
1808
609
            ps_prefix_nal_buf->pu1_buf = ps_nal_parse_ctxt->pu1_vcl_nal_buf;
1809
609
            ps_nal_parse_ctxt->pu1_vcl_nal_buf = pu1_vcl_nal;
1810
1811
            /* subtract the buffer size left */
1812
609
            ps_nal_parse_ctxt->u4_bytes_left_vcl -= i4_buf_size;
1813
609
        }
1814
        /* Reset the top and bottom node */
1815
177k
        ps_vcl_nal->ps_top_node = NULL;
1816
177k
        ps_vcl_nal->ps_bot_node = NULL;
1817
177k
        ps_vcl_nal->i1_nal_ref_id_next = -1;
1818
177k
        ps_vcl_nal->u2_frm_num_next = 0;
1819
177k
    }
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
177k
    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
177k
    ps_nal_parse_ctxt->u4_bytes_left = 0;
1840
1841
    /*************************************************************************/
1842
    /*                      LOOP OVER NALs                                   */
1843
    /*************************************************************************/
1844
177k
    do
1845
1.59M
    {
1846
1.59M
        nal_buf_t *ps_nal_buf;
1847
1.59M
        UWORD32 *pu4_bytes_left;
1848
1849
        /* Find NAL boundary                */
1850
1.59M
        if(ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode)
1851
1.59M
        {
1852
1.59M
            i4_nal_start_flag = isvcd_get_annex_b_nal_unit(
1853
1.59M
                pu1_stream_buffer, i4_cur_pos, *pu4_num_bytes,
1854
1.59M
                &ps_nal_parse_ctxt->i4_find_nal_state, &ps_nal_parse_ctxt->i4_zero_byte_cnt,
1855
1.59M
                &u4_bytes_consumed_temp, ps_nal_parse_ctxt->pv_nal_unit, &i4_more_data_flag);
1856
1857
1.59M
            i4_cur_pos += u4_bytes_consumed_temp;
1858
1.59M
        }
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.59M
        if(SVCD_TRUE == i4_nal_start_flag)
1869
1.59M
        {
1870
1.59M
            UWORD32 u4_err_code;
1871
1.59M
            WORD32 i4_sps_pps_corrupt_status;
1872
1.59M
            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.59M
            i4_internal_dep_id_prev = ps_nal_parse_ctxt->s_int_attr.i4_dependency_id;
1882
1883
1.59M
            i4_status = isvcd_get_nal_prms(
1884
1.59M
                ps_nal_unit->pu1_bufs, ps_nal_unit->i4_buf_sizes, ps_nal_prms,
1885
1.59M
                &ps_nal_parse_ctxt->s_prefix_nal_prms, &ps_nal_parse_ctxt->s_prefix_nal_buf,
1886
1.59M
                &u4_err_code, &i4_sps_pps_corrupt_status, &ps_nal_parse_ctxt->i4_discard_nal_flag,
1887
1.59M
                ps_nal_parse_ctxt);
1888
1889
1.59M
            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.59M
            if((NAL_INSUFFICIENT_DATA == (WORD32) u4_err_code) &&
1900
4.82k
               (NAL_END != ps_nal_parse_ctxt->i4_find_nal_state))
1901
3.51k
            {
1902
3.51k
                ps_nal_parse_ctxt->u4_bytes_left = *pu4_num_bytes - *pu4_bytes_consumed;
1903
1904
                /* Reset the NAL level tracking variables */
1905
3.51k
                isvcd_nal_reset_ctxt(ps_nal_parse_ctxt);
1906
3.51k
                break;
1907
3.51k
            }
1908
1.59M
            else if(0 != u4_err_code)
1909
31.4k
            {
1910
31.4k
                ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_TRUE;
1911
1912
31.4k
                if(SVCD_TRUE == ps_nal_prms->i4_idr_pic_flag)
1913
1.20k
                {
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.20k
                    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.20k
                }
1960
31.4k
            }
1961
1962
            /* Populate the derived nal type into bitstream extract*/
1963
            /* context structure                                   */
1964
1.59M
            i4_nal_header_len = ps_nal_prms->i4_nal_header_len;
1965
1.59M
            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.59M
            ps_nal_parse_ctxt->i4_idr_pic_err_flag |=
1969
1.59M
                ((SVCD_TRUE == ps_nal_prms->i4_idr_pic_flag) &&
1970
340k
                 (SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag) &&
1971
336k
                 (i4_internal_dep_id_prev != ps_nal_parse_ctxt->s_int_attr.i4_dependency_id));
1972
1973
1.59M
            if(ACCESS_UNIT_DELIMITER_RBSP == ps_nal_prms->i4_nal_unit_type)
1974
7.67k
            {
1975
7.67k
                i4_pic_bound_status = PIC_BOUNDARY_TRUE;
1976
7.67k
                ps_nal_parse_ctxt->u1_pic_boundary_aud_flag = 1;
1977
                /* If picture boundary is detected then come out of  */
1978
                /* the loop                                          */
1979
7.67k
                if(PIC_BOUNDARY_TRUE == i4_pic_bound_status)
1980
7.67k
                {
1981
7.67k
                    isvcd_nal_parse_pic_bound_proc(ps_nal_parse_ctxt, ps_vcl_nal, ps_nal_prms);
1982
7.67k
                    break;
1983
7.67k
                }
1984
7.67k
            }
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.58M
            if((VCL_NAL == ps_nal_prms->i4_derived_nal_type) &&
1991
446k
               (PREFIX_UNIT_NAL != ps_nal_prms->i4_nal_unit_type) &&
1992
443k
               (SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag))
1993
437k
            {
1994
437k
                if(ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode)
1995
437k
                {
1996
437k
                    ps_nal_parse_ctxt->u1_pic_boundary_aud_flag = 0;
1997
1998
437k
                    i4_status = isvcd_detect_pic_boundary_annex_b(ps_nal_prms, pu1_stream_buffer,
1999
437k
                                                                  i4_cur_pos, &i4_pic_bound_status,
2000
437k
                                                                  ps_nal_parse_ctxt, pu4_num_bytes);
2001
437k
                }
2002
2003
                /* If picture boundary is detected then come out of  */
2004
                /* the loop                                          */
2005
437k
                if(PIC_BOUNDARY_TRUE == i4_pic_bound_status)
2006
164k
                {
2007
164k
                    isvcd_nal_parse_pic_bound_proc(ps_nal_parse_ctxt, ps_vcl_nal, ps_nal_prms);
2008
164k
                    break;
2009
164k
                }
2010
437k
            }
2011
2012
1.42M
            if(SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag)
2013
1.38M
            {
2014
                /* Set the active NAL buffer structure and initialize */
2015
                /* the nal buffer structure                           */
2016
1.38M
                isvcd_get_nal_buf(ps_nal_parse_ctxt, &ps_nal_buf);
2017
1.38M
                ps_nal_parse_ctxt->ps_nal_buf = ps_nal_buf;
2018
1.38M
            }
2019
39.0k
            else
2020
39.0k
            {
2021
39.0k
                ps_nal_parse_ctxt->ps_nal_buf = NULL;
2022
39.0k
            }
2023
1.42M
        }
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
1.42M
        *pu4_bytes_consumed += u4_bytes_consumed_temp;
2031
2032
        /*********************************************************************/
2033
        /*          EMULATION PREVENTION AND BYTE SWAPPING                   */
2034
        /*********************************************************************/
2035
2036
        /* Determine output buffer */
2037
1.42M
        ps_nal_buf = ps_nal_parse_ctxt->ps_nal_buf;
2038
2039
1.42M
        if(VCL_NAL == ps_nal_parse_ctxt->i4_nal_type)
2040
282k
        {
2041
282k
            ppu1_out_buf = &ps_nal_parse_ctxt->pu1_vcl_nal_buf;
2042
282k
            pu4_bytes_left = &ps_nal_parse_ctxt->u4_bytes_left_vcl;
2043
282k
            if(*pu4_bytes_left < (MAX_VCL_NAL_BUFF_SIZE * 0.05))
2044
0
            {
2045
0
                return (VCL_NAL_FOUND_FALSE);
2046
0
            }
2047
282k
        }
2048
1.14M
        else
2049
1.14M
        {
2050
1.14M
            ppu1_out_buf = &ps_nal_parse_ctxt->pu1_non_vcl_nal_buf;
2051
1.14M
            pu4_bytes_left = &ps_nal_parse_ctxt->u4_bytes_left_non_vcl;
2052
1.14M
            if(*pu4_bytes_left < (MAX_NON_VCL_NAL_BUFF_SIZE * 0.05))
2053
120
            {
2054
120
                return (VCL_NAL_FOUND_FALSE);
2055
120
            }
2056
1.14M
        }
2057
2058
        /* if 0 bytes left then discard the current NAL */
2059
1.42M
        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
1.42M
        if(SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag)
2066
1.38M
        {
2067
1.38M
            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
1.38M
            {
2072
1.38M
                UWORD32 u4_buf_size;
2073
2074
                /* clip the size before emulation prevention */
2075
1.38M
                u4_buf_size = (UWORD32) CLIP3(0, (WORD32) *pu4_bytes_left - 8,
2076
1.38M
                                              (ps_nal_unit->i4_buf_sizes - i4_nal_header_len));
2077
2078
1.38M
                u4_buf_inc = isvcd_nal_byte_swap_emulation(
2079
1.38M
                    (UWORD32 *) *ppu1_out_buf, &u4_output_bytes,
2080
1.38M
                    ps_nal_unit->pu1_bufs + i4_nal_header_len, u4_buf_size,
2081
1.38M
                    NUM_OF_ZERO_BYTES_BEFORE_START_CODE, &ps_nal_parse_ctxt->s_emulation_ctxt);
2082
2083
1.38M
                i4_nal_header_len = 0;
2084
1.38M
                u4_buf_inc = UP_ALIGN_8(u4_buf_inc);
2085
1.38M
                *ppu1_out_buf += u4_buf_inc;
2086
1.38M
                *pu4_bytes_left -= u4_buf_inc;
2087
1.38M
                ps_nal_buf->i4_buf_size += u4_output_bytes;
2088
1.38M
            }
2089
1.38M
        }
2090
2091
        /*********************************************************************/
2092
        /*                UPDATE VARIABLES                                   */
2093
        /*********************************************************************/
2094
1.42M
        if(NAL_END == ps_nal_parse_ctxt->i4_find_nal_state)
2095
1.42M
        {
2096
1.42M
            if(SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag)
2097
1.38M
            {
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
1.38M
                isvcd_update_nal_ctxt(ps_nal_parse_ctxt, ps_vcl_nal, ps_non_vcl_nal);
2104
2105
1.38M
                UPDATE_NAL_BUF_PTR(ppu1_out_buf, ps_nal_prms->i4_derived_nal_type, pu4_bytes_left);
2106
1.38M
            }
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
1.42M
            if((PREFIX_UNIT_NAL != ps_nal_prms->i4_nal_unit_type) ||
2115
3.93k
               (SVCD_TRUE == ps_nal_parse_ctxt->i4_discard_nal_flag))
2116
1.41M
            {
2117
1.41M
                isvcd_nal_buf_reset(&ps_nal_parse_ctxt->s_prefix_nal_buf);
2118
1.41M
            }
2119
2120
            /* Reset the nal level tracking variables */
2121
1.42M
            isvcd_nal_reset_ctxt(ps_nal_parse_ctxt);
2122
1.42M
        }
2123
2124
        /*------------- while loop ends here --------------------------------*/
2125
1.42M
    } while(SVCD_TRUE == i4_more_data_flag);
2126
2127
177k
    return (i4_pic_bound_status);
2128
177k
}
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
125k
{
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
125k
    nal_parse_ctxt_t *ps_nal_parse_ctxt;
2178
125k
    non_vcl_nal_t *ps_non_vcl_nal;
2179
125k
    nal_unit_t *ps_nal_unit;
2180
125k
    WORD32 i4_nal_start_flag, i4_cur_pos, i4_status;
2181
125k
    WORD32 i4_nal_header_len, i4_more_data_flag;
2182
125k
    UWORD32 u4_bytes_consumed_temp = 0;
2183
125k
    UWORD8 **ppu1_out_buf;
2184
125k
    nal_prms_t *ps_nal_prms;
2185
2186
125k
    ps_nal_parse_ctxt = (nal_parse_ctxt_t *) pv_nal_parse_ctxt;
2187
125k
    ps_non_vcl_nal = (non_vcl_nal_t *) pv_out_non_vcl_nal;
2188
125k
    ps_nal_unit = (nal_unit_t *) ps_nal_parse_ctxt->pv_nal_unit;
2189
125k
    ps_nal_prms = &ps_nal_parse_ctxt->s_nal_prms;
2190
2191
    /* Initialization */
2192
125k
    i4_cur_pos = 0;
2193
125k
    *pu4_bytes_consumed = 0;
2194
125k
    i4_nal_header_len = 0;
2195
125k
    i4_nal_start_flag = SVCD_FALSE;
2196
125k
    i4_more_data_flag = SVCD_TRUE;
2197
125k
    i4_status = PIC_BOUNDARY_FALSE;
2198
2199
    /* reset the target layer update flag */
2200
125k
    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
125k
    if(ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode &&
2212
125k
       SVCD_TRUE == ps_nal_parse_ctxt->i4_dec_frst_sc_flag)
2213
26.5k
    {
2214
26.5k
        WORD32 i4_status;
2215
2216
26.5k
        i4_status =
2217
26.5k
            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
26.5k
        if(i4_status == SC_NOT_FOUND)
2224
24
        {
2225
24
            return (VCL_NAL_FOUND_FALSE);
2226
24
        }
2227
2228
26.4k
        i4_cur_pos = *pu4_bytes_consumed;
2229
26.4k
        ps_nal_parse_ctxt->i4_dec_frst_sc_flag = SVCD_FALSE;
2230
26.4k
    }
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
125k
    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
125k
    do
2247
2.12M
    {
2248
2.12M
        nal_buf_t *ps_nal_buf;
2249
2.12M
        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
2.12M
        if(ANNEX_B == ps_nal_parse_ctxt->i4_input_bitstream_mode)
2263
2.12M
        {
2264
2.12M
            i4_nal_start_flag = isvcd_get_annex_b_nal_unit(
2265
2.12M
                pu1_stream_buffer, i4_cur_pos, *pu4_num_bytes,
2266
2.12M
                &ps_nal_parse_ctxt->i4_find_nal_state, &ps_nal_parse_ctxt->i4_zero_byte_cnt,
2267
2.12M
                &u4_bytes_consumed_temp, ps_nal_parse_ctxt->pv_nal_unit, &i4_more_data_flag);
2268
2269
2.12M
            i4_cur_pos += u4_bytes_consumed_temp;
2270
2.12M
        }
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
2.12M
        if(SVCD_TRUE == i4_nal_start_flag)
2278
2.12M
        {
2279
2.12M
            UWORD32 u4_err_code;
2280
2.12M
            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
2.12M
            isvcd_get_nal_prms(ps_nal_unit->pu1_bufs, ps_nal_unit->i4_buf_sizes, ps_nal_prms,
2287
2.12M
                               &ps_nal_parse_ctxt->s_prefix_nal_prms,
2288
2.12M
                               &ps_nal_parse_ctxt->s_prefix_nal_buf, &u4_err_code,
2289
2.12M
                               &i4_sps_pps_corrupt_status, &ps_nal_parse_ctxt->i4_discard_nal_flag,
2290
2.12M
                               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
2.12M
            if((NAL_INSUFFICIENT_DATA == (WORD32) u4_err_code) &&
2297
8.57k
               (NAL_END != ps_nal_parse_ctxt->i4_find_nal_state))
2298
6.78k
            {
2299
6.78k
                ps_nal_parse_ctxt->u4_bytes_left = *pu4_num_bytes - *pu4_bytes_consumed;
2300
2301
                /* Reset the NAL level tracking variables */
2302
6.78k
                isvcd_nal_reset_ctxt(ps_nal_parse_ctxt);
2303
6.78k
                break;
2304
6.78k
            }
2305
2.11M
            else if(0 != u4_err_code)
2306
22.8k
            {
2307
22.8k
                ps_nal_parse_ctxt->i4_discard_nal_flag = SVCD_TRUE;
2308
22.8k
            }
2309
2310
            /* Populate other paramters based on the nal prms */
2311
2.11M
            ps_nal_parse_ctxt->i4_nal_type = ps_nal_prms->i4_derived_nal_type;
2312
2.11M
            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
2.11M
            if(VCL_NAL == ps_nal_prms->i4_derived_nal_type &&
2316
115k
               PREFIX_UNIT_NAL != ps_nal_prms->i4_nal_unit_type)
2317
113k
            {
2318
113k
                isvcd_pic_reset_ctxt(ps_nal_parse_ctxt);
2319
2320
113k
                return (VCL_NAL_FOUND_TRUE);
2321
113k
            }
2322
2323
            /* Set the active NAL buffer structure and initialize */
2324
            /* the nal buffer structure                           */
2325
2.00M
            isvcd_get_nal_buf(ps_nal_parse_ctxt, &ps_nal_buf);
2326
2327
2.00M
            ps_nal_parse_ctxt->ps_nal_buf = ps_nal_buf;
2328
2.00M
        }
2329
2330
        /* Update the bytes consumed variable */
2331
2332
2.00M
        *pu4_bytes_consumed += u4_bytes_consumed_temp;
2333
2334
2.00M
        ps_nal_buf = ps_nal_parse_ctxt->ps_nal_buf;
2335
2.00M
        if(VCL_NAL == ps_nal_parse_ctxt->i4_nal_type)
2336
1.33k
        {
2337
1.33k
            ppu1_out_buf = &ps_nal_parse_ctxt->pu1_vcl_nal_buf;
2338
1.33k
            pu4_bytes_left = &ps_nal_parse_ctxt->u4_bytes_left_vcl;
2339
1.33k
            if(*pu4_bytes_left < (MAX_VCL_NAL_BUFF_SIZE * 0.05))
2340
0
            {
2341
0
                return (VCL_NAL_FOUND_FALSE);
2342
0
            }
2343
1.33k
        }
2344
2.00M
        else
2345
2.00M
        {
2346
2.00M
            ppu1_out_buf = &ps_nal_parse_ctxt->pu1_non_vcl_nal_buf;
2347
2.00M
            pu4_bytes_left = &ps_nal_parse_ctxt->u4_bytes_left_non_vcl;
2348
2.00M
            if(*pu4_bytes_left < (MAX_NON_VCL_NAL_BUFF_SIZE * 0.05))
2349
341
            {
2350
341
                return (VCL_NAL_FOUND_FALSE);
2351
341
            }
2352
2.00M
        }
2353
2354
        /* if 0 bytes left then discard the current NAL */
2355
2.00M
        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
2.00M
        if(SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag)
2367
1.97M
        {
2368
1.97M
            UWORD32 u4_output_bytes, u4_buf_inc;
2369
2370
1.97M
            {
2371
1.97M
                UWORD32 u4_buf_size;
2372
2373
                /* clip the size before emulation prevention */
2374
1.97M
                u4_buf_size = (UWORD32) CLIP3(0, (WORD32) *pu4_bytes_left - 8,
2375
1.97M
                                              (ps_nal_unit->i4_buf_sizes - i4_nal_header_len));
2376
2377
1.97M
                u4_buf_inc = isvcd_nal_byte_swap_emulation(
2378
1.97M
                    (UWORD32 *) *ppu1_out_buf, &u4_output_bytes,
2379
1.97M
                    ps_nal_unit->pu1_bufs + i4_nal_header_len, u4_buf_size,
2380
1.97M
                    NUM_OF_ZERO_BYTES_BEFORE_START_CODE, &ps_nal_parse_ctxt->s_emulation_ctxt);
2381
1.97M
                i4_nal_header_len = 0;
2382
2383
1.97M
                u4_buf_inc = UP_ALIGN_8(u4_buf_inc);
2384
1.97M
                *ppu1_out_buf += u4_buf_inc;
2385
1.97M
                *pu4_bytes_left -= u4_buf_inc;
2386
1.97M
                ps_nal_buf->i4_buf_size += u4_output_bytes;
2387
1.97M
            }
2388
1.97M
        }
2389
2390
        /*********************************************************************/
2391
        /*                UPDATE VARIABLES                                   */
2392
        /*********************************************************************/
2393
2394
2.00M
        if(NAL_END == ps_nal_parse_ctxt->i4_find_nal_state)
2395
1.99M
        {
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
1.99M
            if(SVCD_FALSE == ps_nal_parse_ctxt->i4_discard_nal_flag)
2401
1.97M
            {
2402
1.97M
                isvcd_update_nal_ctxt(ps_nal_parse_ctxt, NULL, ps_non_vcl_nal);
2403
2404
1.97M
                UPDATE_NAL_BUF_PTR(ppu1_out_buf, ps_nal_prms->i4_derived_nal_type, pu4_bytes_left);
2405
1.97M
            }
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
1.99M
            if((PREFIX_UNIT_NAL != ps_nal_prms->i4_nal_unit_type) ||
2414
1.95k
               (SVCD_TRUE == ps_nal_parse_ctxt->i4_discard_nal_flag))
2415
1.99M
            {
2416
1.99M
                isvcd_nal_buf_reset(&ps_nal_parse_ctxt->s_prefix_nal_buf);
2417
1.99M
            }
2418
2419
            /* Reset NAL level tracking variables */
2420
1.99M
            isvcd_nal_reset_ctxt(ps_nal_parse_ctxt);
2421
1.99M
        }
2422
2423
2.00M
        i4_nal_header_len = 0;
2424
        /*------------- while loop ends here --------------------------------*/
2425
2.00M
    } while(SVCD_TRUE == i4_more_data_flag);
2426
2427
11.5k
    if(i4_more_data_flag == 0)
2428
11.5k
    {
2429
11.5k
        isvcd_pic_reset_ctxt(ps_nal_parse_ctxt);
2430
11.5k
        return (VCL_NAL_FOUND_TRUE);
2431
11.5k
    }
2432
2433
0
    return (VCL_NAL_FOUND_FALSE);
2434
11.5k
}