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