| | 170 | if (NAL_type == NALUnitType::SPS || |
| | 171 | NAL_type == NALUnitType::SLICE || |
| | 172 | NAL_type == NALUnitType::SLICE_DPA) { |
| | 173 | /* |
| | 174 | bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE |
| | 175 | bytes larger then the actual read bits |
| | 176 | */ |
| | 177 | if (local_bytes + 20 + FF_INPUT_BUFFER_PADDING_SIZE < |
| | 178 | local_bytes_end) { |
| | 179 | init_get_bits(&gb, local_bytes, |
| | 180 | 8 * (local_bytes_end - local_bytes)); |
| | 181 | |
| | 182 | if (NAL_type == NALUnitType::SPS) |
| | 183 | decode_SPS(&gb); |
| | 184 | else |
| | 185 | decode_Header(&gb); |
| | 186 | } |
| | 187 | |
| | 188 | } |
| | 189 | else if (NAL_type == NALUnitType::SLICE_IDR) |
| | 190 | frame_num = 0; |
| | 191 | |
| | 207 | void KeyframeSequencer::decode_Header(GetBitContext * gb) |
| | 208 | { |
| | 209 | uint first_mb_in_slice; |
| | 210 | uint slice_type; |
| | 211 | uint pic_parameter_set_id; |
| | 212 | |
| | 213 | if (log2_max_frame_num < 1) |
| | 214 | { |
| | 215 | std::cerr |
| | 216 | << "KeyframeSequencer::decode_Header: SPS has not been parsed!\n"; |
| | 217 | return; |
| | 218 | } |
| | 219 | |
| | 220 | prev_frame_num = frame_num; |
| | 221 | |
| | 222 | first_mb_in_slice = get_ue_golomb(gb); |
| | 223 | slice_type = get_ue_golomb(gb); |
| | 224 | pic_parameter_set_id = get_ue_golomb(gb); |
| | 225 | |
| | 226 | if (separate_colour_plane_flag) |
| | 227 | get_bits(gb, 2); // colour_plane_id |
| | 228 | |
| | 229 | frame_num = get_bits(gb, log2_max_frame_num); |
| | 230 | } |
| | 231 | |
| | 232 | /* |
| | 233 | * Just the parts we need -- libavcodec used for example |
| | 234 | */ |
| | 235 | void KeyframeSequencer::decode_SPS(GetBitContext * gb) |
| | 236 | { |
| | 237 | int profile_idc, chroma_format_idc; |
| | 238 | int idx; |
| | 239 | |
| | 240 | profile_idc = get_bits(gb, 8); // profile_idc |
| | 241 | get_bits1(gb); // constraint_set0_flag |
| | 242 | get_bits1(gb); // constraint_set1_flag |
| | 243 | get_bits1(gb); // constraint_set2_flag |
| | 244 | get_bits1(gb); // constraint_set3_flag |
| | 245 | get_bits(gb, 4); // reserved |
| | 246 | get_bits(gb, 8); // level_idc |
| | 247 | get_ue_golomb(gb); // sps_id |
| | 248 | |
| | 249 | if(profile_idc >= 100){ // high profile |
| | 250 | if((chroma_format_idc = get_ue_golomb(gb)) == 3) // chroma_format_idc |
| | 251 | separate_colour_plane_flag = (get_bits1(gb) == 1); |
| | 252 | get_ue_golomb(gb); // bit_depth_luma_minus8 |
| | 253 | get_ue_golomb(gb); // bit_depth_chroma_minus8 |
| | 254 | get_bits1(gb); // qpprime_y_zero_transform_bypass_flag |
| | 255 | |
| | 256 | if (get_bits1(gb)) // seq_scaling_matrix_present_flag |
| | 257 | { |
| | 258 | for (idx = 0; idx < ((chroma_format_idc != 3) ? 8 : 12); ++idx) |
| | 259 | { |
| | 260 | get_bits1(gb); // scaling_list |
| | 261 | } |
| | 262 | } |
| | 263 | } |
| | 264 | |
| | 265 | log2_max_frame_num = get_ue_golomb(gb) + 4; |
| | 266 | } |
| | 267 | |