| | 209 | void KeyframeSequencer::decode_Header(GetBitContext * gb) |
| | 210 | { |
| | 211 | uint first_mb_in_slice; |
| | 212 | uint slice_type; |
| | 213 | uint pic_parameter_set_id; |
| | 214 | bool field_pic_flag; |
| | 215 | bool bottom_field_flag; |
| | 216 | |
| | 217 | if (log2_max_frame_num < 1) |
| | 218 | { |
| | 219 | std::cerr |
| | 220 | << "KeyframeSequencer::decode_Header: SPS has not been parsed!\n"; |
| | 221 | return; |
| | 222 | } |
| | 223 | |
| | 224 | new_VLC_NAL = false; |
| | 225 | |
| | 226 | prev_frame_num = frame_num; |
| | 227 | |
| | 228 | first_mb_in_slice = get_ue_golomb(gb); |
| | 229 | slice_type = get_ue_golomb(gb); |
| | 230 | |
| | 231 | pic_parameter_set_id = get_ue_golomb(gb); |
| | 232 | if (pic_parameter_set_id != prev_pic_parameter_set_id) { |
| | 233 | new_VLC_NAL = true; |
| | 234 | prev_pic_parameter_set_id = pic_parameter_set_id; |
| | 235 | } |
| | 236 | |
| | 237 | if (separate_colour_plane_flag) |
| | 238 | get_bits(gb, 2); // colour_plane_id |
| | 239 | |
| | 240 | frame_num = get_bits(gb, log2_max_frame_num); |
| | 241 | |
| | 242 | if (frame_mbs_only_flag) |
| | 243 | new_VLC_NAL = true; |
| | 244 | else |
| | 245 | { |
| | 246 | /* From section 7.3.3 Slice header syntax |
| | 247 | if (!frame_mbs_only_flag) { |
| | 248 | field_pic_flag = get_bits1(gb); |
| | 249 | if (field_pic_flag) |
| | 250 | bottom_field_flag = get_bits1(gb); |
| | 251 | } |
| | 252 | */ |
| | 253 | |
| | 254 | #if 0 |
| | 255 | new_VLC_NAL = get_bits1(gb) ? !get_bits1(gb) : true; |
| | 256 | #else |
| | 257 | field_pic_flag = get_bits1(gb); |
| | 258 | if (field_pic_flag != prev_field_pic_flag) { |
| | 259 | new_VLC_NAL = true; |
| | 260 | prev_field_pic_flag = field_pic_flag; |
| | 261 | } |
| | 262 | |
| | 263 | if (field_pic_flag) { |
| | 264 | bottom_field_flag = get_bits1(gb); |
| | 265 | if (bottom_field_flag != prev_bottom_field_flag) { |
| | 266 | new_VLC_NAL = !bottom_field_flag; |
| | 267 | prev_bottom_field_flag = bottom_field_flag; |
| | 268 | } |
| | 269 | } |
| | 270 | #endif |
| | 271 | } |
| | 272 | } |
| | 273 | |
| | 274 | /* |
| | 275 | * libavcodec used for example |
| | 276 | */ |
| | 277 | void KeyframeSequencer::decode_SPS(GetBitContext * gb) |
| | 278 | { |
| | 279 | int profile_idc, chroma_format_idc; |
| | 280 | |
| | 281 | profile_idc = get_bits(gb, 8); // profile_idc |
| | 282 | get_bits1(gb); // constraint_set0_flag |
| | 283 | get_bits1(gb); // constraint_set1_flag |
| | 284 | get_bits1(gb); // constraint_set2_flag |
| | 285 | get_bits1(gb); // constraint_set3_flag |
| | 286 | get_bits(gb, 4); // reserved |
| | 287 | get_bits(gb, 8); // level_idc |
| | 288 | get_ue_golomb(gb); // sps_id |
| | 289 | |
| | 290 | if(profile_idc >= 100){ // high profile |
| | 291 | if((chroma_format_idc = get_ue_golomb(gb)) == 3) // chroma_format_idc |
| | 292 | separate_colour_plane_flag = (get_bits1(gb) == 1); |
| | 293 | get_ue_golomb(gb); // bit_depth_luma_minus8 |
| | 294 | get_ue_golomb(gb); // bit_depth_chroma_minus8 |
| | 295 | get_bits1(gb); // qpprime_y_zero_transform_bypass_flag |
| | 296 | |
| | 297 | if (get_bits1(gb)) // seq_scaling_matrix_present_flag |
| | 298 | { |
| | 299 | for (int idx = 0; idx < ((chroma_format_idc != 3) ? 8 : 12); ++idx) |
| | 300 | { |
| | 301 | get_bits1(gb); // scaling_list |
| | 302 | } |
| | 303 | } |
| | 304 | } |
| | 305 | |
| | 306 | log2_max_frame_num = get_ue_golomb(gb) + 4; |
| | 307 | |
| | 308 | uint pic_order_cnt_type; |
| | 309 | uint log2_max_pic_order_cnt_lsb; |
| | 310 | bool delta_pic_order_always_zero_flag; |
| | 311 | int offset_for_non_ref_pic; |
| | 312 | int offset_for_top_to_bottom_field; |
| | 313 | uint tmp; |
| | 314 | uint num_ref_frames; |
| | 315 | bool gaps_in_frame_num_allowed_flag; |
| | 316 | uint pic_width_in_mbs; |
| | 317 | uint pic_height_in_map_units; |
| | 318 | |
| | 319 | pic_order_cnt_type = get_ue_golomb(gb); |
| | 320 | if (pic_order_cnt_type == 0) |
| | 321 | log2_max_pic_order_cnt_lsb = get_ue_golomb(gb) + 4; |
| | 322 | else if (pic_order_cnt_type == 1) |
| | 323 | { |
| | 324 | delta_pic_order_always_zero_flag = get_bits1(gb); |
| | 325 | offset_for_non_ref_pic = get_se_golomb(gb); |
| | 326 | offset_for_top_to_bottom_field = get_se_golomb(gb); |
| | 327 | tmp = get_ue_golomb(gb); |
| | 328 | for (uint idx = 0; idx < tmp; ++idx) |
| | 329 | get_se_golomb(gb); // offset_for_ref_frame[i] |
| | 330 | } |
| | 331 | |
| | 332 | num_ref_frames = get_ue_golomb(gb); |
| | 333 | gaps_in_frame_num_allowed_flag = get_bits1(gb); |
| | 334 | pic_width_in_mbs = get_ue_golomb(gb) + 1; |
| | 335 | pic_height_in_map_units = get_ue_golomb(gb) + 1; |
| | 336 | frame_mbs_only_flag = get_bits1(gb); |
| | 337 | |
| | 338 | } |
| | 339 | |