comparison h264.c @ 8451:384600e3fe5b libavcodec

Use get_ue_golomb_31() where possible, almost all are just in headers though.
author michael
date Tue, 23 Dec 2008 21:12:19 +0000
parents 2f25133ab807
children 06d4e91d7c24
comparison
equal deleted inserted replaced
8450:95dab8ec4cd7 8451:384600e3fe5b
2846 2846
2847 if(get_bits1(&s->gb)){ 2847 if(get_bits1(&s->gb)){
2848 int pred= h->curr_pic_num; 2848 int pred= h->curr_pic_num;
2849 2849
2850 for(index=0; ; index++){ 2850 for(index=0; ; index++){
2851 unsigned int reordering_of_pic_nums_idc= get_ue_golomb(&s->gb); 2851 unsigned int reordering_of_pic_nums_idc= get_ue_golomb_31(&s->gb);
2852 unsigned int pic_id; 2852 unsigned int pic_id;
2853 int i; 2853 int i;
2854 Picture *ref = NULL; 2854 Picture *ref = NULL;
2855 2855
2856 if(reordering_of_pic_nums_idc==3) 2856 if(reordering_of_pic_nums_idc==3)
3412 h->mmco_index= 1; 3412 h->mmco_index= 1;
3413 } 3413 }
3414 }else{ 3414 }else{
3415 if(get_bits1(gb)){ // adaptive_ref_pic_marking_mode_flag 3415 if(get_bits1(gb)){ // adaptive_ref_pic_marking_mode_flag
3416 for(i= 0; i<MAX_MMCO_COUNT; i++) { 3416 for(i= 0; i<MAX_MMCO_COUNT; i++) {
3417 MMCOOpcode opcode= get_ue_golomb(gb); 3417 MMCOOpcode opcode= get_ue_golomb_31(gb);
3418 3418
3419 h->mmco[i].opcode= opcode; 3419 h->mmco[i].opcode= opcode;
3420 if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){ 3420 if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){
3421 h->mmco[i].short_pic_num= (h->curr_pic_num - get_ue_golomb(gb) - 1) & (h->max_pic_num - 1); 3421 h->mmco[i].short_pic_num= (h->curr_pic_num - get_ue_golomb(gb) - 1) & (h->max_pic_num - 1);
3422 /* if(h->mmco[i].short_pic_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_pic_num ] == NULL){ 3422 /* if(h->mmco[i].short_pic_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_pic_num ] == NULL){
3423 av_log(s->avctx, AV_LOG_ERROR, "illegal short ref in memory management control operation %d\n", mmco); 3423 av_log(s->avctx, AV_LOG_ERROR, "illegal short ref in memory management control operation %d\n", mmco);
3424 return -1; 3424 return -1;
3425 }*/ 3425 }*/
3426 } 3426 }
3427 if(opcode==MMCO_SHORT2LONG || opcode==MMCO_LONG2UNUSED || opcode==MMCO_LONG || opcode==MMCO_SET_MAX_LONG){ 3427 if(opcode==MMCO_SHORT2LONG || opcode==MMCO_LONG2UNUSED || opcode==MMCO_LONG || opcode==MMCO_SET_MAX_LONG){
3428 unsigned int long_arg= get_ue_golomb(gb); 3428 unsigned int long_arg= get_ue_golomb_31(gb);
3429 if(long_arg >= 32 || (long_arg >= 16 && !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){ 3429 if(long_arg >= 32 || (long_arg >= 16 && !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){
3430 av_log(h->s.avctx, AV_LOG_ERROR, "illegal long ref in memory management control operation %d\n", opcode); 3430 av_log(h->s.avctx, AV_LOG_ERROR, "illegal long ref in memory management control operation %d\n", opcode);
3431 return -1; 3431 return -1;
3432 } 3432 }
3433 h->mmco[i].long_arg= long_arg; 3433 h->mmco[i].long_arg= long_arg;
3651 h0->current_slice = 0; 3651 h0->current_slice = 0;
3652 if (!s0->first_field) 3652 if (!s0->first_field)
3653 s->current_picture_ptr= NULL; 3653 s->current_picture_ptr= NULL;
3654 } 3654 }
3655 3655
3656 slice_type= get_ue_golomb(&s->gb); 3656 slice_type= get_ue_golomb_31(&s->gb);
3657 if(slice_type > 9){ 3657 if(slice_type > 9){
3658 av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y); 3658 av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y);
3659 return -1; 3659 return -1;
3660 } 3660 }
3661 if(slice_type > 4){ 3661 if(slice_type > 4){
3945 if(h->slice_type_nos==FF_B_TYPE && !h->direct_spatial_mv_pred) 3945 if(h->slice_type_nos==FF_B_TYPE && !h->direct_spatial_mv_pred)
3946 direct_dist_scale_factor(h); 3946 direct_dist_scale_factor(h);
3947 direct_ref_list_init(h); 3947 direct_ref_list_init(h);
3948 3948
3949 if( h->slice_type_nos != FF_I_TYPE && h->pps.cabac ){ 3949 if( h->slice_type_nos != FF_I_TYPE && h->pps.cabac ){
3950 tmp = get_ue_golomb(&s->gb); 3950 tmp = get_ue_golomb_31(&s->gb);
3951 if(tmp > 2){ 3951 if(tmp > 2){
3952 av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n"); 3952 av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n");
3953 return -1; 3953 return -1;
3954 } 3954 }
3955 h->cabac_init_idc= tmp; 3955 h->cabac_init_idc= tmp;
3974 3974
3975 h->deblocking_filter = 1; 3975 h->deblocking_filter = 1;
3976 h->slice_alpha_c0_offset = 0; 3976 h->slice_alpha_c0_offset = 0;
3977 h->slice_beta_offset = 0; 3977 h->slice_beta_offset = 0;
3978 if( h->pps.deblocking_filter_parameters_present ) { 3978 if( h->pps.deblocking_filter_parameters_present ) {
3979 tmp= get_ue_golomb(&s->gb); 3979 tmp= get_ue_golomb_31(&s->gb);
3980 if(tmp > 2){ 3980 if(tmp > 2){
3981 av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp); 3981 av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp);
3982 return -1; 3982 return -1;
3983 } 3983 }
3984 h->deblocking_filter= tmp; 3984 h->deblocking_filter= tmp;
4454 h->intra16x16_pred_mode= check_intra_pred_mode(h, h->intra16x16_pred_mode); 4454 h->intra16x16_pred_mode= check_intra_pred_mode(h, h->intra16x16_pred_mode);
4455 if(h->intra16x16_pred_mode < 0) 4455 if(h->intra16x16_pred_mode < 0)
4456 return -1; 4456 return -1;
4457 } 4457 }
4458 if(CHROMA){ 4458 if(CHROMA){
4459 pred_mode= check_intra_pred_mode(h, get_ue_golomb(&s->gb)); 4459 pred_mode= check_intra_pred_mode(h, get_ue_golomb_31(&s->gb));
4460 if(pred_mode < 0) 4460 if(pred_mode < 0)
4461 return -1; 4461 return -1;
4462 h->chroma_pred_mode= pred_mode; 4462 h->chroma_pred_mode= pred_mode;
4463 } 4463 }
4464 }else if(partition_count==4){ 4464 }else if(partition_count==4){
4465 int i, j, sub_partition_count[4], list, ref[2][4]; 4465 int i, j, sub_partition_count[4], list, ref[2][4];
4466 4466
4467 if(h->slice_type_nos == FF_B_TYPE){ 4467 if(h->slice_type_nos == FF_B_TYPE){
4468 for(i=0; i<4; i++){ 4468 for(i=0; i<4; i++){
4469 h->sub_mb_type[i]= get_ue_golomb(&s->gb); 4469 h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);
4470 if(h->sub_mb_type[i] >=13){ 4470 if(h->sub_mb_type[i] >=13){
4471 av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); 4471 av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y);
4472 return -1; 4472 return -1;
4473 } 4473 }
4474 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; 4474 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
4483 h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE; 4483 h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
4484 } 4484 }
4485 }else{ 4485 }else{
4486 assert(h->slice_type_nos == FF_P_TYPE); //FIXME SP correct ? 4486 assert(h->slice_type_nos == FF_P_TYPE); //FIXME SP correct ?
4487 for(i=0; i<4; i++){ 4487 for(i=0; i<4; i++){
4488 h->sub_mb_type[i]= get_ue_golomb(&s->gb); 4488 h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);
4489 if(h->sub_mb_type[i] >=4){ 4489 if(h->sub_mb_type[i] >=4){
4490 av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); 4490 av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y);
4491 return -1; 4491 return -1;
4492 } 4492 }
4493 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; 4493 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
6841 } 6841 }
6842 6842
6843 static inline int decode_hrd_parameters(H264Context *h, SPS *sps){ 6843 static inline int decode_hrd_parameters(H264Context *h, SPS *sps){
6844 MpegEncContext * const s = &h->s; 6844 MpegEncContext * const s = &h->s;
6845 int cpb_count, i; 6845 int cpb_count, i;
6846 cpb_count = get_ue_golomb(&s->gb) + 1; 6846 cpb_count = get_ue_golomb_31(&s->gb) + 1;
6847 6847
6848 if(cpb_count > 32U){ 6848 if(cpb_count > 32U){
6849 av_log(h->s.avctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count); 6849 av_log(h->s.avctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count);
6850 return -1; 6850 return -1;
6851 } 6851 }
7001 get_bits1(&s->gb); //constraint_set1_flag 7001 get_bits1(&s->gb); //constraint_set1_flag
7002 get_bits1(&s->gb); //constraint_set2_flag 7002 get_bits1(&s->gb); //constraint_set2_flag
7003 get_bits1(&s->gb); //constraint_set3_flag 7003 get_bits1(&s->gb); //constraint_set3_flag
7004 get_bits(&s->gb, 4); // reserved 7004 get_bits(&s->gb, 4); // reserved
7005 level_idc= get_bits(&s->gb, 8); 7005 level_idc= get_bits(&s->gb, 8);
7006 sps_id= get_ue_golomb(&s->gb); 7006 sps_id= get_ue_golomb_31(&s->gb);
7007 7007
7008 if(sps_id >= MAX_SPS_COUNT) { 7008 if(sps_id >= MAX_SPS_COUNT) {
7009 av_log(h->s.avctx, AV_LOG_ERROR, "sps_id (%d) out of range\n", sps_id); 7009 av_log(h->s.avctx, AV_LOG_ERROR, "sps_id (%d) out of range\n", sps_id);
7010 return -1; 7010 return -1;
7011 } 7011 }
7019 memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4)); 7019 memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4));
7020 memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8)); 7020 memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8));
7021 sps->scaling_matrix_present = 0; 7021 sps->scaling_matrix_present = 0;
7022 7022
7023 if(sps->profile_idc >= 100){ //high profile 7023 if(sps->profile_idc >= 100){ //high profile
7024 sps->chroma_format_idc= get_ue_golomb(&s->gb); 7024 sps->chroma_format_idc= get_ue_golomb_31(&s->gb);
7025 if(sps->chroma_format_idc == 3) 7025 if(sps->chroma_format_idc == 3)
7026 get_bits1(&s->gb); //residual_color_transform_flag 7026 get_bits1(&s->gb); //residual_color_transform_flag
7027 get_ue_golomb(&s->gb); //bit_depth_luma_minus8 7027 get_ue_golomb(&s->gb); //bit_depth_luma_minus8
7028 get_ue_golomb(&s->gb); //bit_depth_chroma_minus8 7028 get_ue_golomb(&s->gb); //bit_depth_chroma_minus8
7029 sps->transform_bypass = get_bits1(&s->gb); 7029 sps->transform_bypass = get_bits1(&s->gb);
7031 }else{ 7031 }else{
7032 sps->chroma_format_idc= 1; 7032 sps->chroma_format_idc= 1;
7033 } 7033 }
7034 7034
7035 sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4; 7035 sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4;
7036 sps->poc_type= get_ue_golomb(&s->gb); 7036 sps->poc_type= get_ue_golomb_31(&s->gb);
7037 7037
7038 if(sps->poc_type == 0){ //FIXME #define 7038 if(sps->poc_type == 0){ //FIXME #define
7039 sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4; 7039 sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4;
7040 } else if(sps->poc_type == 1){//FIXME #define 7040 } else if(sps->poc_type == 1){//FIXME #define
7041 sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb); 7041 sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb);
7053 }else if(sps->poc_type != 2){ 7053 }else if(sps->poc_type != 2){
7054 av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); 7054 av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type);
7055 goto fail; 7055 goto fail;
7056 } 7056 }
7057 7057
7058 sps->ref_frame_count= get_ue_golomb(&s->gb); 7058 sps->ref_frame_count= get_ue_golomb_31(&s->gb);
7059 if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count >= 32U){ 7059 if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count >= 32U){
7060 av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n"); 7060 av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n");
7061 goto fail; 7061 goto fail;
7062 } 7062 }
7063 sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb); 7063 sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb);
7145 } 7145 }
7146 7146
7147 pps= av_mallocz(sizeof(PPS)); 7147 pps= av_mallocz(sizeof(PPS));
7148 if(pps == NULL) 7148 if(pps == NULL)
7149 return -1; 7149 return -1;
7150 pps->sps_id= get_ue_golomb(&s->gb); 7150 pps->sps_id= get_ue_golomb_31(&s->gb);
7151 if((unsigned)pps->sps_id>=MAX_SPS_COUNT || h->sps_buffers[pps->sps_id] == NULL){ 7151 if((unsigned)pps->sps_id>=MAX_SPS_COUNT || h->sps_buffers[pps->sps_id] == NULL){
7152 av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n"); 7152 av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n");
7153 goto fail; 7153 goto fail;
7154 } 7154 }
7155 7155