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.h 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 #ifndef _SVCD_NAL_H_ 37 #define _SVCD_NAL_H_ 38 39 /*****************************************************************************/ 40 /* File Includes */ 41 /*****************************************************************************/ 42 43 /*****************************************************************************/ 44 /* Constant Macros */ 45 /*****************************************************************************/ 46 47 #define START_CODE_NOT_FOUND -1 48 #define END_OF_STREAM_BUFFER -2 49 #define END_OF_STREAM -1 50 51 #define SC_NOT_FOUND (-1) 52 #define SC_FOUND 1 53 54 #define NUM_OF_ZERO_BYTES_BEFORE_START_CODE (2) 55 #define START_CODE_BYTE (0x01) 56 57 #define EMULATION_PREVENTION_BYTE (0x03) 58 59 /*****************************************************************************/ 60 /* Function Macros */ 61 /*****************************************************************************/ 62 63 /*****************************************************************************/ 64 /* Typedefs */ 65 /*****************************************************************************/ 66 67 /*****************************************************************************/ 68 /* Enums */ 69 /*****************************************************************************/ 70 71 typedef enum 72 { 73 NON_VCL_NAL, 74 VCL_NAL 75 } DERIVED_NAL_UNIT_TYPE_T; 76 77 typedef enum 78 { 79 NAL_START = 0, 80 FIND_NAL_END, 81 NAL_END 82 } NAL_BOUND_DETECT_STATE_T; 83 84 typedef enum 85 { 86 STUFFED_BYTE = 0, 87 /* Should be used for reset purposes */ 88 NOT_STUFFED_BYTE 89 } EMULATION_STATE_T; 90 91 typedef enum 92 { 93 NAL_INSUFFICIENT_DATA = (WORD32) 0x80000000, 94 NAL_CORRUPT_DATA = (WORD32) 0x80000001 95 } NAL_PARSE_ERR_CODES_T; 96 97 /*****************************************************************************/ 98 /* Structure */ 99 /*****************************************************************************/ 100 typedef struct 101 { 102 WORD32 i4_nal_ref_idc; /*!< NAL ref idc - decoded prm from the bitstream */ 103 104 WORD32 i4_nal_unit_type; /*!< NAL unit type - decoded prm from the 105 bitstream */ 106 107 WORD32 i4_priority_id; /*!< Priority id of NAL - decoded prm from the 108 bitstream. If not present then set to 0 */ 109 110 WORD32 i4_dependency_id; /*!< dependency id of NAL - decoded prm from the 111 bitstream. If not present then set to 0 */ 112 113 WORD32 i4_quality_id; /*!< Quality id of NAL - decoded prm from the 114 bitstream. If not present then set to 0 */ 115 116 WORD32 i4_temporal_id; /*!< Temporal id of NAL - decoded prm from the 117 bitstream. If not present then set to 0 */ 118 119 WORD32 i4_no_int_lyr_pred; /*!< No inter layer predictiion flag of NAL - 120 decoded prm from the bitstream. if not present then it is set to 0 */ 121 122 WORD32 i4_use_ref_base_pic_flag; /*!<Use ref_base_pic flag - decoded from 123 the bitstream. If not present then it is set to 0 */ 124 125 WORD32 i4_discard_flag; /*!<Discard_flag - decoded from the bitstream. 126 If not present then it is set to 0 */ 127 128 WORD32 i4_derived_nal_type; /*! Derived NAL type - Place holder for enum 129 which indicates whether the current NAL is VCL NAL or NON_VCL_NAL */ 130 131 WORD32 i4_idr_pic_flag; /*! Derived prm - Indicates whether current NAL 132 is idr VCL NAL or not. SVCD_TRUE means IDR PIC NAL otherwsie not */ 133 134 WORD32 i4_nal_header_len; /*! lenght of NAL header in bytes */ 135 136 WORD32 i4_dqid; /*! Derived parameter. It has same meaning as DQID in the 137 SVC standard */ 138 139 UWORD32 u4_first_mb_addr; /*!< It shall hold the value of first MB address 140 of the VCL NAL unit (excluding the prefix NAL 141 unit) */ 142 143 UWORD8 u1_sps_id; /*!< It shall have the value of SPS id for the VCL NAL 144 unit (excluding the prefix NAL unit)*/ 145 146 UWORD8 u1_pps_id; /*!< It shall have the value of PPS id for the VCL NAL 147 unit (excluding the prefix NAL unit)*/ 148 149 UWORD16 u2_frm_num; /*!< It shall have the value of frame number for the VCL 150 NAL unit (excluding the prefix NAL unit)*/ 151 152 UWORD32 i4_idr_pic_num; /*!< It shall have the value of IDR picture number when 153 "i4_idr_pic_flag" is SVCD_TRUE for VCL NAL unit. 154 (excluding prefix NAL unit) */ 155 156 WORD32 i4_poc_lsb; /*!< It shall have the value of "picture order cnt lsb" 157 when picture order count type is 0 for VCL NAL unit 158 (excluding the prefix NAL unit). When not present in the 159 bitstream, it shall be set to 0 */ 160 161 WORD32 i4_delta_poc_bot; /*!< It shall have the value of "delta picture order 162 cnt bottom" when picture order count type is 0 for VCL NAL 163 unit (excluding the prefix NAL unit). When not present in 164 the bitstream, it shall be set to 0 */ 165 166 WORD32 ai4_delta_poc[2]; /*!< It shall have the value of "delta picture order 167 cnt bottom" when picture order count type is 1 for VCL NAL 168 unit (excluding the prefix NAL unit). When not present in 169 the bitstream, it shall be set to 0 */ 170 171 } nal_prms_t; 172 173 /*****************************************************************************/ 174 /* Extern Variable Declarations */ 175 /*****************************************************************************/ 176 177 /*****************************************************************************/ 178 /* Extern Function Declarations */ 179 /*****************************************************************************/ 180 181 void isvcd_nal_buf_reset(void *ps_nal_buf); 182 183 UWORD32 isvcd_nal_rbsp_to_sodb(UWORD8 *pu1_buf, WORD32 i4_nal_len_in_bytes, UWORD8 u1_ecd_mode); 184 185 WORD32 isvcd_get_first_start_code(UWORD8 *pu1_stream_buffer, UWORD32 *pu4_bytes_consumed, 186 UWORD32 *pu4_num_bytes); 187 188 WORD32 isvcd_nal_find_start_code(UWORD8 *pu1_buf_start, WORD32 i4_cur_pos, WORD32 i4_max_num_bytes, 189 WORD32 *pi4_zero_cnt, UWORD32 *pu4_bytes_consumed); 190 191 WORD32 isvcd_get_annex_b_nal_unit(UWORD8 *pu1_buf_start, WORD32 i4_cur_pos, WORD32 i4_max_num_bytes, 192 WORD32 *pi4_state, WORD32 *pi4_zero_byte_cnt, 193 UWORD32 *pu4_bytes_consumed, void *pv_nal_unit, 194 WORD32 *pi4_more_data_flag); 195 196 void isvcd_reset_emulation_ctxt(void *pv_emulation_ctxt); 197 198 UWORD32 isvcd_nal_byte_swap_emulation(UWORD32 *pu4_out_stream, UWORD32 *pu4_out_len, 199 UWORD8 *pu1_in_stream, UWORD32 u4_in_len, WORD32 i4_0s_bfr_sc, 200 void *pv_emulation_ctxt); 201 202 void isvcd_dec_nal_hdr(void *pv_buf_ptr, WORD32 i4_buf_size, void *pv_nal_header_buf, 203 void *pv_nal_prms, void *pv_prefix_nal_buf, void *pv_prefix_nal_prms, 204 UWORD32 *pu4_err_code); 205 206 void isvcd_set_default_nal_prms(void *pv_nal_prms); 207 208 WORD32 isvcd_parse_part_slice_hdr(UWORD8 *pu1_input_buf, WORD32 i4_input_buf_size, 209 UWORD8 *pu1_temp_buf, void *ps_sps, void *ps_pps, 210 nal_prms_t *ps_nal_prms, UWORD32 *pu4_err_code, 211 WORD32 *pi4_sps_pps_status); 212 213 WORD32 isvcd_discard_nal(void *pv_nal_prms, void *pv_app_attr, void *pv_int_attr, 214 WORD32 i4_update_flag); 215 216 #endif /* _SVCD_NAL_H_ */ 217