xref: /aosp_15_r20/external/libavc/decoder/svc/isvcd_nal_parse_structs.h (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
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_structs.h
23  *
24  * \brief
25  *    Contains the definitions of structures used in the
26  *      bitstream extraction module
27  * Detailed_description
28  *
29  * \date
30  *
31  *
32  * \author : Kishore
33  **************************************************************************
34  */
35 
36 #ifndef _SVCD_NAL_PARSE_STRUCTS_H_
37 #define _SVCD_NAL_PARSE_STRUCTS_H_
38 
39 /*****************************************************************************/
40 /* File Includes                                                             */
41 /*****************************************************************************/
42 
43 /*****************************************************************************/
44 /* Constant Macros                                                           */
45 /*****************************************************************************/
46 
47 #define HEADER_BUFFER_LEN_BEFORE_EP 32
48 
49 #define MAX_NAL_HEADER_SIZE 4
50 
51 #define UP_ALIGN_8(x) (((((UWORD64) x) + 7) >> 3) << 3)
52 #define ALIGN_4(x) (((x) + 3) & (~3))
53 
54 /*--------------------------------------------------------------------------*/
55 /* The start address of any VCL or NON VCL internal buffers (input to        */
56 /* emulation prevention should be aligned to 4 byte boundary                */
57 /*--------------------------------------------------------------------------*/
58 
59 #define BUFFER_ALIGN_4 4
60 
61 #define FIRST_PASS 0
62 #define SECOND_PASS 1
63 /*****************************************************************************/
64 /* Function Macros                                                           */
65 /*****************************************************************************/
66 
GET_NAL_BUF_INC(WORD32 i4_derived_nal_type)67 static __inline UWORD32 GET_NAL_BUF_INC(WORD32 i4_derived_nal_type)
68 {
69     UWORD32 u4_buf_inc;
70 
71     if(VCL_NAL == i4_derived_nal_type)
72     {
73         u4_buf_inc = sizeof(vcl_buf_hdr_t);
74     }
75     else
76     {
77         u4_buf_inc = sizeof(non_vcl_buf_hdr_t);
78     }
79 
80     u4_buf_inc = UP_ALIGN_8(u4_buf_inc);
81     return (u4_buf_inc);
82 }
83 
UPDATE_NAL_BUF_PTR(UWORD8 ** ppu1_buf,WORD32 i4_derived_nal_type,UWORD32 * pu4_bytes_left)84 static __inline void UPDATE_NAL_BUF_PTR(UWORD8 **ppu1_buf, WORD32 i4_derived_nal_type,
85                                         UWORD32 *pu4_bytes_left)
86 {
87     UWORD8 *pu1_buf_ptr;
88     UWORD64 u4_inc;
89 
90     /* Align the start of the structure */
91 
92     pu1_buf_ptr = *ppu1_buf;
93 
94     /* Account for the vcl or non-vcl header */
95     u4_inc = GET_NAL_BUF_INC(i4_derived_nal_type);
96     u4_inc = UP_ALIGN_8(u4_inc);
97     pu1_buf_ptr += u4_inc;
98 
99     /* Update the pointers */
100     if(*pu4_bytes_left >= u4_inc)
101     {
102         *pu4_bytes_left -= u4_inc;
103     }
104     *ppu1_buf = pu1_buf_ptr;
105 }
106 
107 /*****************************************************************************/
108 /* Typedefs                                                                  */
109 /*****************************************************************************/
110 
111 /*****************************************************************************/
112 /* Enums                                                                     */
113 /*****************************************************************************/
114 
115 typedef enum
116 {
117     NAL_PARSE_HANDLE = 0,
118     NAL_PARSE_DQID_LIST_MEM,
119     NAL_PARSE_CMN_MEM,
120     NAL_PARSE_NAL_UNIT_MEM,
121     NAL_PARSE_NUM_MEM_TABS
122 } BITSTREAM_EXTRACT_MEMTABS_T;
123 
124 typedef enum
125 {
126     PIC_BOUND_DQID = 0,      /* Second slice has lower DQID than the first slice */
127     PIC_BOUND_SLICE_PRMS = 1 /* Second slice has different slice prms as */
128                              /* as compared to first slice               */
129 } PIC_BOUNDARY_TYPES_T;
130 
131 /*****************************************************************************/
132 /* Structure                                                                 */
133 /*****************************************************************************/
134 
135 typedef struct
136 {
137     vcl_node_t *ps_vcl_node; /*!< The pointer to VCL NAL node buffer.
138                               */
139     UWORD8 u1_valid_flag;    /*!< This flag shall indicate that the occupancy of
140                              vcl node buffer. SVCD_TRUE shall indicate that the vcl
141                              node buffer is occupied. @sa SVCD_BOOL_T
142                              */
143 
144     UWORD8 u1_dqid;          /*!< The value of DQID assigned for this structure.
145                              The range is [0,127] and is computed as
146                              (Dependency id * 16 + Quality id )
147                              */
148     WORD32 i4_poc_lsb;       /*!< It shall have the value of "picture order cnt lsb"
149                              when picture order count type is 0 for the layer. When not
150                              present in the bitstream, it shall be set to 0*/
151 
152     WORD32
153     i4_delta_poc_bot; /*!< It shall have the value of "delta picture order cnt
154                  bottom" when picture order count type is 0 for VCL NAL unit.
155                  When not present in the bitstream, it shall be set to 0*/
156 
157     WORD32
158     ai4_delta_poc[2]; /*!< It shall have the value of "delta picture order cnt
159                    bottom" when picture order count type is 1 for VCL NAL
160                    unit.
161                    When not present in the bitstream, itshall be set to 0 */
162 } dqid_node_t;
163 
164 typedef struct
165 {
166     WORD32 i4_max_num_lyrs;    /*!< Maximum number of layers that will be
167                        present in a access unit. This will determine the
168                        length of the VCL NAL node buffer. This parameter
169                        is configurable during instance creation time
170                        */
171 
172     dqid_node_t *ps_dqid_node; /*!< Pointer to start of VCL NAL node buffer.
173                                 */
174 
175 } dqid_ctxt_t;
176 
177 typedef struct
178 {
179     WORD32 i4_valid_flag; /*!< It shall indicate the validity of contents of
180                           this buffer structure. SVCD_TRUE shall indicate
181                           that the contents of this structure is valid.
182                           @sa SVCD_BOOL_T
183                           */
184 
185     UWORD8 *pu1_buf;      /*!< It shall point to start of SODB data of the NAL.
186                           It should be 8 byte aligned.
187                           */
188 
189     UWORD32 u4_max_bits;  /*!< The length of SODB data of NAL in bits. This
190                           should be set properly by taking care of whether NAL
191                           is coded in CAVLC or CABAC or NAL is a NON VCL NAL
192                           */
193 
194     WORD32 i4_buf_size;   /*!< The size of SODB data of NAL in bytes
195                            */
196 } nal_buf_t;
197 
198 typedef struct
199 {
200     /*----------------------------------------------------*/
201     /*---------- Mode of operation -----------------------*/
202     /*----------------------------------------------------*/
203 
204     WORD32 i4_input_bitstream_mode; /*!< RFC or Annex B   */
205 
206     /*----------------------------------------------------*/
207     /*---------- NAL boundary detection ------------------*/
208     /*----------------------------------------------------*/
209 
210     WORD32 i4_find_nal_state;   /*!< state of NAL boundary
211                        detection logic */
212 
213     WORD32 i4_zero_byte_cnt;    /*< Number of zero bytes consumed */
214 
215     WORD32 i4_dec_frst_sc_flag; /*!< A flag to decode
216                     the start code only. A value of SVCD_TRUE
217                     shall indicate that start code shall be
218                     decoded.@sa SVCD_BOOL_T */
219 
220     /*----------------------------------------------------*/
221     /*--------- Emulation prevention info ----------------*/
222     /*----------------------------------------------------*/
223 
224     emulation_prevent_ctxt_t s_emulation_ctxt;
225 
226     /*----------------------------------------------------*/
227     /*--------- Picture boundary detetction info ---------*/
228     /*----------------------------------------------------*/
229 
230     WORD32 i4_is_frst_vcl_nal_in_au; /*!< Indicates whether
231                      current NAL is first NAL in the current
232                      Access unit. This is needed for detecting
233                      picture boundary in partial input mode of
234                      operation */
235 
236     UWORD32 u4_time_stamp_lsb;       /*!< Holds the LSB of time stamp of the
237                          first NAL unit in the  access unit.
238                          Used for RFC based bitstreams */
239 
240     WORD32 i4_time_stamp_msb;        /*!< Holds the MSB of time stamp of the
241                          first NAL unit in the  access unit.
242                          Used for RFC based bitstreams */
243 
244     WORD32 i4_prev_dq_id;            /*!< Holds the value of DQID of
245                                last NAL unit parsed. this is used for
246                                detetecting the picture boundary.
247                                in Annex B mode of input bitstream */
248     WORD32 i4_idr_pic_err_flag;      /*!< place to hold the
249                           IDR status of current AU
250                           */
251 
252     /*----------------------------------------------------*/
253     /*-------- DQID node context -------------------------*/
254     /*----------------------------------------------------*/
255 
256     dqid_ctxt_t s_dqid_ctxt;
257 
258     /*----------------------------------------------------*/
259     /*-------- VCL and NON VCL buf info ------------------*/
260     /*----------------------------------------------------*/
261 
262     void *pv_non_vcl_nal_buf;               /*!< Start address of NON VCL
263                                   NAL buffer */
264 
265     void *pv_vcl_nal_buf;                   /*!< Start address of VCL NAL
266                                     buffer */
267 
268     UWORD32 u4_bytes_left_vcl;              /*!< number of bytes left in the
269                                             VCL buffer
270                                             */
271     UWORD32 u4_bytes_left_non_vcl;          /*!< number of bytes left in the
272                                         NON VCL buffer
273                                         */
274 
275     UWORD8 *pu1_non_vcl_nal_buf;            /*!< Current position of
276                                non VCL NAL buffer pointer */
277 
278     UWORD8 *pu1_vcl_nal_buf;                /*!< Current position of VCL NAL
279                                    buffer pointer */
280 
281     WORD32 i4_num_non_vcl_nals;             /*!< Number of non vcl nals */
282 
283     nal_buf_t s_prefix_nal_buf;             /*!< NAL buffer structure
284                             of prefix NAL unit */
285 
286     nal_buf_t s_nal_buf;                    /*!< NAL buffer structure of .
287                                      active NAL unit ( which is not a prefix
288                                      NAL unit) */
289 
290     nal_buf_t *ps_nal_buf;                  /*!< It shall point to active
291                                   NAL buffer structure. It shall point to
292                                   either "s_prefix_nal_buf" or "s_nal_buf"*/
293 
294     vcl_buf_hdr_t *ps_prev_vcl_buf;         /*!< It shall point
295                           to vcl buffer header of the previous
296                           slice of a layer */
297     non_vcl_buf_hdr_t *ps_prev_non_vcl_buf; /*!< It shall
298                       point to buffer header of the previous
299                       non vcl nal present in the bitstream */
300 
301     /*----------------------------------------------------*/
302     /*-------- NAL structure and NAL buffer --------------*/
303     /*----------------------------------------------------*/
304 
305     void *pv_nal_unit;
306     void *pv_nal_header_buf;
307     nal_prms_t s_nal_prms;
308     nal_prms_t s_prefix_nal_prms;
309 
310     /*----------------------------------------------------*/
311     /*-------------- Target layer info -------------------*/
312     /*----------------------------------------------------*/
313 
314     target_lyr_attr_t s_app_attr; /*!< This structure shall have
315                                   the target layer attributes set
316                                   by the application */
317 
318     target_lyr_attr_t s_int_attr; /*!< This structure shall have
319                                   the target layer attributes set
320                                   by the module. At any state, the
321                                   module tries to attain the values
322                                   of application attributes at
323                                   the IDR pictures */
324 
325     WORD32 i4_tgt_lyr_update;     /*!< It is a flag which
326                                   indicates whether the internal target layer
327                                   attributes has to be updated or not. A value
328                                   of SVCD_TRUE shall indicate that the target
329                                   layer attributes shall be updated.
330                                   @sa SVCD_BOOL_T */
331 
332     /*----------------------------------------------------*/
333     /*-------- other NAL info ----------------------------*/
334     /*----------------------------------------------------*/
335 
336     WORD32 i4_discard_nal_flag;
337     WORD32 i4_nal_type;
338 
339     /*----------------------------------------------------*/
340     /*---------- Seq, pic prms buffers -------------------*/
341     /*----------------------------------------------------*/
342 
343     void *pv_seq_prms;
344     void *pv_pic_prms;
345 
346     /*----------------------------------------------------*/
347     /*----------        Others          ------------------*/
348     /*----------------------------------------------------*/
349 
350     WORD32 i4_eos_flag;    /*!< Flush mode related parameter.
351                    This is used by the module during the
352                    flush call. SVCD_TRUE shall indicate that
353                    current  end of bitstream has occurred.
354                    @sa SVCD_BOOL_T; */
355 
356     UWORD32 u4_bytes_left; /*!< This field has number of bytes not
357                     consumed by the NAL parse module in the
358                     previous call because of insufficient bitstream
359                     to decode the slice and NAL header. */
360     UWORD8 u1_pic_boundary_aud_flag;
361 } nal_parse_ctxt_t;
362 
363 /*****************************************************************************/
364 /* Extern Variable Declarations                                              */
365 /*****************************************************************************/
366 
367 /*****************************************************************************/
368 /* Extern Function Declarations                                              */
369 /*****************************************************************************/
370 
371 #endif /* _SVCD_NAL_PARSE_STRUCTS_H_ */
372