Skip to content

Commit

Permalink
fix ossrs#471, h264 sps parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Bepartofyou committed Oct 8, 2021
1 parent 4f77ddb commit c1d7e67
Showing 1 changed file with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions trunk/src/kernel/srs_kernel_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,10 +1078,57 @@ srs_error_t SrsFormat::avc_demux_sps_rbsp(char* rbsp, int nb_rbsp)
if ((err = srs_avc_nalu_read_uev(&bs, pic_height_in_map_units_minus1)) != srs_success) {
return srs_error_wrap(err, "read pic_height_in_map_units_minus1");;
}

vcodec->width = (int)(pic_width_in_mbs_minus1 + 1) * 16;
vcodec->height = (int)(pic_height_in_map_units_minus1 + 1) * 16;


int8_t frame_mbs_only_flag = -1;
if ((err = srs_avc_nalu_read_bit(&bs, frame_mbs_only_flag)) != srs_success) {
return srs_error_wrap(err, "read frame_mbs_only_flag");;
}
if(!frame_mbs_only_flag) {
/* Skip mb_adaptive_frame_field_flag */
int8_t mb_adaptive_frame_field_flag = -1;
if ((err = srs_avc_nalu_read_bit(&bs, mb_adaptive_frame_field_flag)) != srs_success) {
return srs_error_wrap(err, "read mb_adaptive_frame_field_flag");;
}
}

/* Skip direct_8x8_inference_flag */
int8_t direct_8x8_inference_flag = -1;
if ((err = srs_avc_nalu_read_bit(&bs, direct_8x8_inference_flag)) != srs_success) {
return srs_error_wrap(err, "read direct_8x8_inference_flag");;
}

/* We need the following value to evaluate offsets, if any */
int8_t frame_cropping_flag = -1;
if ((err = srs_avc_nalu_read_bit(&bs, frame_cropping_flag)) != srs_success) {
return srs_error_wrap(err, "read frame_cropping_flag");;
}
int32_t frame_crop_left_offset = 0, frame_crop_right_offset = 0,
frame_crop_top_offset = 0, frame_crop_bottom_offset = 0;
if(frame_cropping_flag) {
if ((err = srs_avc_nalu_read_uev(&bs, frame_crop_left_offset)) != srs_success) {
return srs_error_wrap(err, "read frame_crop_left_offset");;
}
if ((err = srs_avc_nalu_read_uev(&bs, frame_crop_right_offset)) != srs_success) {
return srs_error_wrap(err, "read frame_crop_right_offset");;
}
if ((err = srs_avc_nalu_read_uev(&bs, frame_crop_top_offset)) != srs_success) {
return srs_error_wrap(err, "read frame_crop_top_offset");;
}
if ((err = srs_avc_nalu_read_uev(&bs, frame_crop_bottom_offset)) != srs_success) {
return srs_error_wrap(err, "read frame_crop_bottom_offset");;
}
}

/* Skip vui_parameters_present_flag */
int8_t vui_parameters_present_flag = -1;
if ((err = srs_avc_nalu_read_bit(&bs, vui_parameters_present_flag)) != srs_success) {
return srs_error_wrap(err, "read vui_parameters_present_flag");;
}

vcodec->width = ((pic_width_in_mbs_minus1 + 1) * 16) - frame_crop_left_offset * 2 - frame_crop_right_offset * 2;
vcodec->height = ((2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1) * 16) \
- (frame_crop_top_offset * 2) - (frame_crop_bottom_offset * 2);

return err;
}

Expand Down

0 comments on commit c1d7e67

Please sign in to comment.