comparison h264.c @ 6481:493dc59d469a libavcodec

add FF_ prefix to all (frame)_TYPE usage
author aurel
date Sun, 09 Mar 2008 23:31:02 +0000
parents 3c67363d6fa0
children ecbe9565dcae
comparison
equal deleted inserted replaced
6480:6f01a499e785 6481:493dc59d469a
475 *(uint32_t*)h->mvd_cache [list][scan8[7 ]+1]= 475 *(uint32_t*)h->mvd_cache [list][scan8[7 ]+1]=
476 *(uint32_t*)h->mvd_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewhere else) 476 *(uint32_t*)h->mvd_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewhere else)
477 *(uint32_t*)h->mvd_cache [list][scan8[4 ]]= 477 *(uint32_t*)h->mvd_cache [list][scan8[4 ]]=
478 *(uint32_t*)h->mvd_cache [list][scan8[12]]= 0; 478 *(uint32_t*)h->mvd_cache [list][scan8[12]]= 0;
479 479
480 if(h->slice_type == B_TYPE){ 480 if(h->slice_type == FF_B_TYPE){
481 fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, 0, 1); 481 fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, 0, 1);
482 482
483 if(IS_DIRECT(top_type)){ 483 if(IS_DIRECT(top_type)){
484 *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0x01010101; 484 *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0x01010101;
485 }else if(IS_8X8(top_type)){ 485 }else if(IS_8X8(top_type)){
916 static inline void direct_ref_list_init(H264Context * const h){ 916 static inline void direct_ref_list_init(H264Context * const h){
917 MpegEncContext * const s = &h->s; 917 MpegEncContext * const s = &h->s;
918 Picture * const ref1 = &h->ref_list[1][0]; 918 Picture * const ref1 = &h->ref_list[1][0];
919 Picture * const cur = s->current_picture_ptr; 919 Picture * const cur = s->current_picture_ptr;
920 int list, i, j; 920 int list, i, j;
921 if(cur->pict_type == I_TYPE) 921 if(cur->pict_type == FF_I_TYPE)
922 cur->ref_count[0] = 0; 922 cur->ref_count[0] = 0;
923 if(cur->pict_type != B_TYPE) 923 if(cur->pict_type != FF_B_TYPE)
924 cur->ref_count[1] = 0; 924 cur->ref_count[1] = 0;
925 for(list=0; list<2; list++){ 925 for(list=0; list<2; list++){
926 cur->ref_count[list] = h->ref_count[list]; 926 cur->ref_count[list] = h->ref_count[list];
927 for(j=0; j<h->ref_count[list]; j++) 927 for(j=0; j<h->ref_count[list]; j++)
928 cur->ref_poc[list][j] = h->ref_list[list][j].poc; 928 cur->ref_poc[list][j] = h->ref_list[list][j].poc;
929 } 929 }
930 if(cur->pict_type != B_TYPE || h->direct_spatial_mv_pred) 930 if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred)
931 return; 931 return;
932 for(list=0; list<2; list++){ 932 for(list=0; list<2; list++){
933 for(i=0; i<ref1->ref_count[list]; i++){ 933 for(i=0; i<ref1->ref_count[list]; i++){
934 const int poc = ref1->ref_poc[list][i]; 934 const int poc = ref1->ref_poc[list][i];
935 h->map_col_to_list0[list][i] = 0; /* bogus; fills in for missing frames */ 935 h->map_col_to_list0[list][i] = 0; /* bogus; fills in for missing frames */
1356 ref_index[0+1*h->b8_stride]= h->ref_cache[list][scan8[8]]; 1356 ref_index[0+1*h->b8_stride]= h->ref_cache[list][scan8[8]];
1357 ref_index[1+1*h->b8_stride]= h->ref_cache[list][scan8[12]]; 1357 ref_index[1+1*h->b8_stride]= h->ref_cache[list][scan8[12]];
1358 } 1358 }
1359 } 1359 }
1360 1360
1361 if(h->slice_type == B_TYPE && h->pps.cabac){ 1361 if(h->slice_type == FF_B_TYPE && h->pps.cabac){
1362 if(IS_8X8(mb_type)){ 1362 if(IS_8X8(mb_type)){
1363 uint8_t *direct_table = &h->direct_table[b8_xy]; 1363 uint8_t *direct_table = &h->direct_table[b8_xy];
1364 direct_table[1+0*h->b8_stride] = IS_DIRECT(h->sub_mb_type[1]) ? 1 : 0; 1364 direct_table[1+0*h->b8_stride] = IS_DIRECT(h->sub_mb_type[1]) ? 1 : 0;
1365 direct_table[0+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[2]) ? 1 : 0; 1365 direct_table[0+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[2]) ? 1 : 0;
1366 direct_table[1+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[3]) ? 1 : 0; 1366 direct_table[1+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[3]) ? 1 : 0;
2855 structure_sel = 0; 2855 structure_sel = 0;
2856 frame_list[0] = h->default_ref_list[0]; 2856 frame_list[0] = h->default_ref_list[0];
2857 frame_list[1] = h->default_ref_list[1]; 2857 frame_list[1] = h->default_ref_list[1];
2858 } 2858 }
2859 2859
2860 if(h->slice_type==B_TYPE){ 2860 if(h->slice_type==FF_B_TYPE){
2861 int list; 2861 int list;
2862 int len[2]; 2862 int len[2];
2863 int short_len[2]; 2863 int short_len[2];
2864 int out_i; 2864 int out_i;
2865 int limit= INT_MIN; 2865 int limit= INT_MIN;
2977 } 2977 }
2978 #ifdef TRACE 2978 #ifdef TRACE
2979 for (i=0; i<h->ref_count[0]; i++) { 2979 for (i=0; i<h->ref_count[0]; i++) {
2980 tprintf(h->s.avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].data[0]); 2980 tprintf(h->s.avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].data[0]);
2981 } 2981 }
2982 if(h->slice_type==B_TYPE){ 2982 if(h->slice_type==FF_B_TYPE){
2983 for (i=0; i<h->ref_count[1]; i++) { 2983 for (i=0; i<h->ref_count[1]; i++) {
2984 tprintf(h->s.avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].data[0]); 2984 tprintf(h->s.avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].data[0]);
2985 } 2985 }
2986 } 2986 }
2987 #endif 2987 #endif
3019 MpegEncContext * const s = &h->s; 3019 MpegEncContext * const s = &h->s;
3020 int list, index, pic_structure; 3020 int list, index, pic_structure;
3021 3021
3022 print_short_term(h); 3022 print_short_term(h);
3023 print_long_term(h); 3023 print_long_term(h);
3024 if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move before func 3024 if(h->slice_type==FF_I_TYPE || h->slice_type==FF_SI_TYPE) return 0; //FIXME move before func
3025 3025
3026 for(list=0; list<h->list_count; list++){ 3026 for(list=0; list<h->list_count; list++){
3027 memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); 3027 memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]);
3028 3028
3029 if(get_bits1(&s->gb)){ 3029 if(get_bits1(&s->gb)){
3120 if(!h->ref_list[list][index].data[0]) 3120 if(!h->ref_list[list][index].data[0])
3121 h->ref_list[list][index]= s->current_picture; 3121 h->ref_list[list][index]= s->current_picture;
3122 } 3122 }
3123 } 3123 }
3124 3124
3125 if(h->slice_type==B_TYPE && !h->direct_spatial_mv_pred) 3125 if(h->slice_type==FF_B_TYPE && !h->direct_spatial_mv_pred)
3126 direct_dist_scale_factor(h); 3126 direct_dist_scale_factor(h);
3127 direct_ref_list_init(h); 3127 direct_ref_list_init(h);
3128 return 0; 3128 return 0;
3129 } 3129 }
3130 3130
3203 h->chroma_weight[list][i][j]= chroma_def; 3203 h->chroma_weight[list][i][j]= chroma_def;
3204 h->chroma_offset[list][i][j]= 0; 3204 h->chroma_offset[list][i][j]= 0;
3205 } 3205 }
3206 } 3206 }
3207 } 3207 }
3208 if(h->slice_type != B_TYPE) break; 3208 if(h->slice_type != FF_B_TYPE) break;
3209 } 3209 }
3210 h->use_weight= h->use_weight || h->use_weight_chroma; 3210 h->use_weight= h->use_weight || h->use_weight_chroma;
3211 return 0; 3211 return 0;
3212 } 3212 }
3213 3213
3862 MpegEncContext * const s = &h->s; 3862 MpegEncContext * const s = &h->s;
3863 MpegEncContext * const s0 = &h0->s; 3863 MpegEncContext * const s0 = &h0->s;
3864 unsigned int first_mb_in_slice; 3864 unsigned int first_mb_in_slice;
3865 unsigned int pps_id; 3865 unsigned int pps_id;
3866 int num_ref_idx_active_override_flag; 3866 int num_ref_idx_active_override_flag;
3867 static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE}; 3867 static const uint8_t slice_type_map[5]= {FF_P_TYPE, FF_B_TYPE, FF_I_TYPE, FF_SP_TYPE, FF_SI_TYPE};
3868 unsigned int slice_type, tmp, i; 3868 unsigned int slice_type, tmp, i;
3869 int default_ref_list_done = 0; 3869 int default_ref_list_done = 0;
3870 int last_pic_structure; 3870 int last_pic_structure;
3871 3871
3872 s->dropable= h->nal_ref_idc == 0; 3872 s->dropable= h->nal_ref_idc == 0;
3897 h->slice_type_fixed=1; 3897 h->slice_type_fixed=1;
3898 }else 3898 }else
3899 h->slice_type_fixed=0; 3899 h->slice_type_fixed=0;
3900 3900
3901 slice_type= slice_type_map[ slice_type ]; 3901 slice_type= slice_type_map[ slice_type ];
3902 if (slice_type == I_TYPE 3902 if (slice_type == FF_I_TYPE
3903 || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) { 3903 || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) {
3904 default_ref_list_done = 1; 3904 default_ref_list_done = 1;
3905 } 3905 }
3906 h->slice_type= slice_type; 3906 h->slice_type= slice_type;
3907 3907
3908 s->pict_type= h->slice_type; // to make a few old func happy, it's wrong though 3908 s->pict_type= h->slice_type; // to make a few old func happy, it's wrong though
3909 if (s->pict_type == B_TYPE && s0->last_picture_ptr == NULL) { 3909 if (s->pict_type == FF_B_TYPE && s0->last_picture_ptr == NULL) {
3910 av_log(h->s.avctx, AV_LOG_ERROR, 3910 av_log(h->s.avctx, AV_LOG_ERROR,
3911 "B picture before any references, skipping\n"); 3911 "B picture before any references, skipping\n");
3912 return -1; 3912 return -1;
3913 } 3913 }
3914 3914
4107 4107
4108 //set defaults, might be overriden a few line later 4108 //set defaults, might be overriden a few line later
4109 h->ref_count[0]= h->pps.ref_count[0]; 4109 h->ref_count[0]= h->pps.ref_count[0];
4110 h->ref_count[1]= h->pps.ref_count[1]; 4110 h->ref_count[1]= h->pps.ref_count[1];
4111 4111
4112 if(h->slice_type == P_TYPE || h->slice_type == SP_TYPE || h->slice_type == B_TYPE){ 4112 if(h->slice_type == FF_P_TYPE || h->slice_type == FF_SP_TYPE || h->slice_type == FF_B_TYPE){
4113 if(h->slice_type == B_TYPE){ 4113 if(h->slice_type == FF_B_TYPE){
4114 h->direct_spatial_mv_pred= get_bits1(&s->gb); 4114 h->direct_spatial_mv_pred= get_bits1(&s->gb);
4115 } 4115 }
4116 num_ref_idx_active_override_flag= get_bits1(&s->gb); 4116 num_ref_idx_active_override_flag= get_bits1(&s->gb);
4117 4117
4118 if(num_ref_idx_active_override_flag){ 4118 if(num_ref_idx_active_override_flag){
4119 h->ref_count[0]= get_ue_golomb(&s->gb) + 1; 4119 h->ref_count[0]= get_ue_golomb(&s->gb) + 1;
4120 if(h->slice_type==B_TYPE) 4120 if(h->slice_type==FF_B_TYPE)
4121 h->ref_count[1]= get_ue_golomb(&s->gb) + 1; 4121 h->ref_count[1]= get_ue_golomb(&s->gb) + 1;
4122 4122
4123 if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){ 4123 if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){
4124 av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n"); 4124 av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n");
4125 h->ref_count[0]= h->ref_count[1]= 1; 4125 h->ref_count[0]= h->ref_count[1]= 1;
4126 return -1; 4126 return -1;
4127 } 4127 }
4128 } 4128 }
4129 if(h->slice_type == B_TYPE) 4129 if(h->slice_type == FF_B_TYPE)
4130 h->list_count= 2; 4130 h->list_count= 2;
4131 else 4131 else
4132 h->list_count= 1; 4132 h->list_count= 1;
4133 }else 4133 }else
4134 h->list_count= 0; 4134 h->list_count= 0;
4138 } 4138 }
4139 4139
4140 if(decode_ref_pic_list_reordering(h) < 0) 4140 if(decode_ref_pic_list_reordering(h) < 0)
4141 return -1; 4141 return -1;
4142 4142
4143 if( (h->pps.weighted_pred && (h->slice_type == P_TYPE || h->slice_type == SP_TYPE )) 4143 if( (h->pps.weighted_pred && (h->slice_type == FF_P_TYPE || h->slice_type == FF_SP_TYPE ))
4144 || (h->pps.weighted_bipred_idc==1 && h->slice_type==B_TYPE ) ) 4144 || (h->pps.weighted_bipred_idc==1 && h->slice_type==FF_B_TYPE ) )
4145 pred_weight_table(h); 4145 pred_weight_table(h);
4146 else if(h->pps.weighted_bipred_idc==2 && h->slice_type==B_TYPE) 4146 else if(h->pps.weighted_bipred_idc==2 && h->slice_type==FF_B_TYPE)
4147 implicit_weight_table(h); 4147 implicit_weight_table(h);
4148 else 4148 else
4149 h->use_weight = 0; 4149 h->use_weight = 0;
4150 4150
4151 if(h->nal_ref_idc) 4151 if(h->nal_ref_idc)
4152 decode_ref_pic_marking(h0, &s->gb); 4152 decode_ref_pic_marking(h0, &s->gb);
4153 4153
4154 if(FRAME_MBAFF) 4154 if(FRAME_MBAFF)
4155 fill_mbaff_ref_list(h); 4155 fill_mbaff_ref_list(h);
4156 4156
4157 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE && h->pps.cabac ){ 4157 if( h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE && h->pps.cabac ){
4158 tmp = get_ue_golomb(&s->gb); 4158 tmp = get_ue_golomb(&s->gb);
4159 if(tmp > 2){ 4159 if(tmp > 2){
4160 av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n"); 4160 av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n");
4161 return -1; 4161 return -1;
4162 } 4162 }
4171 } 4171 }
4172 s->qscale= tmp; 4172 s->qscale= tmp;
4173 h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); 4173 h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);
4174 h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); 4174 h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);
4175 //FIXME qscale / qp ... stuff 4175 //FIXME qscale / qp ... stuff
4176 if(h->slice_type == SP_TYPE){ 4176 if(h->slice_type == FF_SP_TYPE){
4177 get_bits1(&s->gb); /* sp_for_switch_flag */ 4177 get_bits1(&s->gb); /* sp_for_switch_flag */
4178 } 4178 }
4179 if(h->slice_type==SP_TYPE || h->slice_type == SI_TYPE){ 4179 if(h->slice_type==FF_SP_TYPE || h->slice_type == FF_SI_TYPE){
4180 get_se_golomb(&s->gb); /* slice_qs_delta */ 4180 get_se_golomb(&s->gb); /* slice_qs_delta */
4181 } 4181 }
4182 4182
4183 h->deblocking_filter = 1; 4183 h->deblocking_filter = 1;
4184 h->slice_alpha_c0_offset = 0; 4184 h->slice_alpha_c0_offset = 0;
4198 h->slice_beta_offset = get_se_golomb(&s->gb) << 1; 4198 h->slice_beta_offset = get_se_golomb(&s->gb) << 1;
4199 } 4199 }
4200 } 4200 }
4201 4201
4202 if( s->avctx->skip_loop_filter >= AVDISCARD_ALL 4202 if( s->avctx->skip_loop_filter >= AVDISCARD_ALL
4203 ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type != I_TYPE) 4203 ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type != FF_I_TYPE)
4204 ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type == B_TYPE) 4204 ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type == FF_B_TYPE)
4205 ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) 4205 ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0))
4206 h->deblocking_filter= 0; 4206 h->deblocking_filter= 0;
4207 4207
4208 if(h->deblocking_filter == 1 && h0->max_contexts > 1) { 4208 if(h->deblocking_filter == 1 && h0->max_contexts > 1) {
4209 if(s->avctx->flags2 & CODEC_FLAG2_FAST) { 4209 if(s->avctx->flags2 & CODEC_FLAG2_FAST) {
4460 memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui 4460 memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui
4461 4461
4462 if(MB_FIELD) 4462 if(MB_FIELD)
4463 mb_type|= MB_TYPE_INTERLACED; 4463 mb_type|= MB_TYPE_INTERLACED;
4464 4464
4465 if( h->slice_type == B_TYPE ) 4465 if( h->slice_type == FF_B_TYPE )
4466 { 4466 {
4467 // just for fill_caches. pred_direct_motion will set the real mb_type 4467 // just for fill_caches. pred_direct_motion will set the real mb_type
4468 mb_type|= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP; 4468 mb_type|= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP;
4469 4469
4470 fill_caches(h, mb_type, 0); //FIXME check what is needed and what not ... 4470 fill_caches(h, mb_type, 0); //FIXME check what is needed and what not ...
4503 s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong? 4503 s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?
4504 4504
4505 tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); 4505 tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
4506 cbp = 0; /* avoid warning. FIXME: find a solution without slowing 4506 cbp = 0; /* avoid warning. FIXME: find a solution without slowing
4507 down the code */ 4507 down the code */
4508 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){ 4508 if(h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE){
4509 if(s->mb_skip_run==-1) 4509 if(s->mb_skip_run==-1)
4510 s->mb_skip_run= get_ue_golomb(&s->gb); 4510 s->mb_skip_run= get_ue_golomb(&s->gb);
4511 4511
4512 if (s->mb_skip_run--) { 4512 if (s->mb_skip_run--) {
4513 if(FRAME_MBAFF && (s->mb_y&1) == 0){ 4513 if(FRAME_MBAFF && (s->mb_y&1) == 0){
4527 h->mb_field_decoding_flag= (s->picture_structure!=PICT_FRAME); 4527 h->mb_field_decoding_flag= (s->picture_structure!=PICT_FRAME);
4528 4528
4529 h->prev_mb_skipped= 0; 4529 h->prev_mb_skipped= 0;
4530 4530
4531 mb_type= get_ue_golomb(&s->gb); 4531 mb_type= get_ue_golomb(&s->gb);
4532 if(h->slice_type == B_TYPE){ 4532 if(h->slice_type == FF_B_TYPE){
4533 if(mb_type < 23){ 4533 if(mb_type < 23){
4534 partition_count= b_mb_type_info[mb_type].partition_count; 4534 partition_count= b_mb_type_info[mb_type].partition_count;
4535 mb_type= b_mb_type_info[mb_type].type; 4535 mb_type= b_mb_type_info[mb_type].type;
4536 }else{ 4536 }else{
4537 mb_type -= 23; 4537 mb_type -= 23;
4538 goto decode_intra_mb; 4538 goto decode_intra_mb;
4539 } 4539 }
4540 }else if(h->slice_type == P_TYPE /*|| h->slice_type == SP_TYPE */){ 4540 }else if(h->slice_type == FF_P_TYPE /*|| h->slice_type == FF_SP_TYPE */){
4541 if(mb_type < 5){ 4541 if(mb_type < 5){
4542 partition_count= p_mb_type_info[mb_type].partition_count; 4542 partition_count= p_mb_type_info[mb_type].partition_count;
4543 mb_type= p_mb_type_info[mb_type].type; 4543 mb_type= p_mb_type_info[mb_type].type;
4544 }else{ 4544 }else{
4545 mb_type -= 5; 4545 mb_type -= 5;
4546 goto decode_intra_mb; 4546 goto decode_intra_mb;
4547 } 4547 }
4548 }else{ 4548 }else{
4549 assert(h->slice_type == I_TYPE); 4549 assert(h->slice_type == FF_I_TYPE);
4550 decode_intra_mb: 4550 decode_intra_mb:
4551 if(mb_type > 25){ 4551 if(mb_type > 25){
4552 av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y); 4552 av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y);
4553 return -1; 4553 return -1;
4554 } 4554 }
4650 return -1; 4650 return -1;
4651 h->chroma_pred_mode= pred_mode; 4651 h->chroma_pred_mode= pred_mode;
4652 }else if(partition_count==4){ 4652 }else if(partition_count==4){
4653 int i, j, sub_partition_count[4], list, ref[2][4]; 4653 int i, j, sub_partition_count[4], list, ref[2][4];
4654 4654
4655 if(h->slice_type == B_TYPE){ 4655 if(h->slice_type == FF_B_TYPE){
4656 for(i=0; i<4; i++){ 4656 for(i=0; i<4; i++){
4657 h->sub_mb_type[i]= get_ue_golomb(&s->gb); 4657 h->sub_mb_type[i]= get_ue_golomb(&s->gb);
4658 if(h->sub_mb_type[i] >=13){ 4658 if(h->sub_mb_type[i] >=13){
4659 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); 4659 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);
4660 return -1; 4660 return -1;
4669 h->ref_cache[1][scan8[4]] = 4669 h->ref_cache[1][scan8[4]] =
4670 h->ref_cache[0][scan8[12]] = 4670 h->ref_cache[0][scan8[12]] =
4671 h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE; 4671 h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
4672 } 4672 }
4673 }else{ 4673 }else{
4674 assert(h->slice_type == P_TYPE || h->slice_type == SP_TYPE); //FIXME SP correct ? 4674 assert(h->slice_type == FF_P_TYPE || h->slice_type == FF_SP_TYPE); //FIXME SP correct ?
4675 for(i=0; i<4; i++){ 4675 for(i=0; i<4; i++){
4676 h->sub_mb_type[i]= get_ue_golomb(&s->gb); 4676 h->sub_mb_type[i]= get_ue_golomb(&s->gb);
4677 if(h->sub_mb_type[i] >=4){ 4677 if(h->sub_mb_type[i] >=4){
4678 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); 4678 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);
4679 return -1; 4679 return -1;
5040 } 5040 }
5041 5041
5042 static int decode_cabac_mb_type( H264Context *h ) { 5042 static int decode_cabac_mb_type( H264Context *h ) {
5043 MpegEncContext * const s = &h->s; 5043 MpegEncContext * const s = &h->s;
5044 5044
5045 if( h->slice_type == I_TYPE ) { 5045 if( h->slice_type == FF_I_TYPE ) {
5046 return decode_cabac_intra_mb_type(h, 3, 1); 5046 return decode_cabac_intra_mb_type(h, 3, 1);
5047 } else if( h->slice_type == P_TYPE ) { 5047 } else if( h->slice_type == FF_P_TYPE ) {
5048 if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) { 5048 if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) {
5049 /* P-type */ 5049 /* P-type */
5050 if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) { 5050 if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) {
5051 /* P_L0_D16x16, P_8x8 */ 5051 /* P_L0_D16x16, P_8x8 */
5052 return 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] ); 5052 return 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] );
5055 return 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] ); 5055 return 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] );
5056 } 5056 }
5057 } else { 5057 } else {
5058 return decode_cabac_intra_mb_type(h, 17, 0) + 5; 5058 return decode_cabac_intra_mb_type(h, 17, 0) + 5;
5059 } 5059 }
5060 } else if( h->slice_type == B_TYPE ) { 5060 } else if( h->slice_type == FF_B_TYPE ) {
5061 const int mba_xy = h->left_mb_xy[0]; 5061 const int mba_xy = h->left_mb_xy[0];
5062 const int mbb_xy = h->top_mb_xy; 5062 const int mbb_xy = h->top_mb_xy;
5063 int ctx = 0; 5063 int ctx = 0;
5064 int bits; 5064 int bits;
5065 5065
5125 if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] )) 5125 if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] ))
5126 ctx++; 5126 ctx++;
5127 if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] )) 5127 if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] ))
5128 ctx++; 5128 ctx++;
5129 5129
5130 if( h->slice_type == B_TYPE ) 5130 if( h->slice_type == FF_B_TYPE )
5131 ctx += 13; 5131 ctx += 13;
5132 return get_cabac_noinline( &h->cabac, &h->cabac_state[11+ctx] ); 5132 return get_cabac_noinline( &h->cabac, &h->cabac_state[11+ctx] );
5133 } 5133 }
5134 5134
5135 static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) { 5135 static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) {
5262 int refa = h->ref_cache[list][scan8[n] - 1]; 5262 int refa = h->ref_cache[list][scan8[n] - 1];
5263 int refb = h->ref_cache[list][scan8[n] - 8]; 5263 int refb = h->ref_cache[list][scan8[n] - 8];
5264 int ref = 0; 5264 int ref = 0;
5265 int ctx = 0; 5265 int ctx = 0;
5266 5266
5267 if( h->slice_type == B_TYPE) { 5267 if( h->slice_type == FF_B_TYPE) {
5268 if( refa > 0 && !h->direct_cache[scan8[n] - 1] ) 5268 if( refa > 0 && !h->direct_cache[scan8[n] - 1] )
5269 ctx++; 5269 ctx++;
5270 if( refb > 0 && !h->direct_cache[scan8[n] - 8] ) 5270 if( refb > 0 && !h->direct_cache[scan8[n] - 8] )
5271 ctx += 2; 5271 ctx += 2;
5272 } else { 5272 } else {
5580 int dct8x8_allowed= h->pps.transform_8x8_mode; 5580 int dct8x8_allowed= h->pps.transform_8x8_mode;
5581 5581
5582 s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?) 5582 s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?)
5583 5583
5584 tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); 5584 tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
5585 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE ) { 5585 if( h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE ) {
5586 int skip; 5586 int skip;
5587 /* a skipped mb needs the aff flag from the following mb */ 5587 /* a skipped mb needs the aff flag from the following mb */
5588 if( FRAME_MBAFF && s->mb_x==0 && (s->mb_y&1)==0 ) 5588 if( FRAME_MBAFF && s->mb_x==0 && (s->mb_y&1)==0 )
5589 predict_field_decoding_flag(h); 5589 predict_field_decoding_flag(h);
5590 if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped ) 5590 if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped )
5625 if( ( mb_type = decode_cabac_mb_type( h ) ) < 0 ) { 5625 if( ( mb_type = decode_cabac_mb_type( h ) ) < 0 ) {
5626 av_log( h->s.avctx, AV_LOG_ERROR, "decode_cabac_mb_type failed\n" ); 5626 av_log( h->s.avctx, AV_LOG_ERROR, "decode_cabac_mb_type failed\n" );
5627 return -1; 5627 return -1;
5628 } 5628 }
5629 5629
5630 if( h->slice_type == B_TYPE ) { 5630 if( h->slice_type == FF_B_TYPE ) {
5631 if( mb_type < 23 ){ 5631 if( mb_type < 23 ){
5632 partition_count= b_mb_type_info[mb_type].partition_count; 5632 partition_count= b_mb_type_info[mb_type].partition_count;
5633 mb_type= b_mb_type_info[mb_type].type; 5633 mb_type= b_mb_type_info[mb_type].type;
5634 }else{ 5634 }else{
5635 mb_type -= 23; 5635 mb_type -= 23;
5636 goto decode_intra_mb; 5636 goto decode_intra_mb;
5637 } 5637 }
5638 } else if( h->slice_type == P_TYPE ) { 5638 } else if( h->slice_type == FF_P_TYPE ) {
5639 if( mb_type < 5) { 5639 if( mb_type < 5) {
5640 partition_count= p_mb_type_info[mb_type].partition_count; 5640 partition_count= p_mb_type_info[mb_type].partition_count;
5641 mb_type= p_mb_type_info[mb_type].type; 5641 mb_type= p_mb_type_info[mb_type].type;
5642 } else { 5642 } else {
5643 mb_type -= 5; 5643 mb_type -= 5;
5644 goto decode_intra_mb; 5644 goto decode_intra_mb;
5645 } 5645 }
5646 } else { 5646 } else {
5647 assert(h->slice_type == I_TYPE); 5647 assert(h->slice_type == FF_I_TYPE);
5648 decode_intra_mb: 5648 decode_intra_mb:
5649 partition_count = 0; 5649 partition_count = 0;
5650 cbp= i_mb_type_info[mb_type].cbp; 5650 cbp= i_mb_type_info[mb_type].cbp;
5651 h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode; 5651 h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;
5652 mb_type= i_mb_type_info[mb_type].type; 5652 mb_type= i_mb_type_info[mb_type].type;
5745 if( pred_mode < 0 ) return -1; 5745 if( pred_mode < 0 ) return -1;
5746 h->chroma_pred_mode= pred_mode; 5746 h->chroma_pred_mode= pred_mode;
5747 } else if( partition_count == 4 ) { 5747 } else if( partition_count == 4 ) {
5748 int i, j, sub_partition_count[4], list, ref[2][4]; 5748 int i, j, sub_partition_count[4], list, ref[2][4];
5749 5749
5750 if( h->slice_type == B_TYPE ) { 5750 if( h->slice_type == FF_B_TYPE ) {
5751 for( i = 0; i < 4; i++ ) { 5751 for( i = 0; i < 4; i++ ) {
5752 h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h ); 5752 h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h );
5753 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; 5753 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
5754 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; 5754 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type;
5755 } 5755 }
6443 && (s->current_picture.mb_type[mb_xy-1] & (MB_TYPE_16x16 | MB_TYPE_8x16)) 6443 && (s->current_picture.mb_type[mb_xy-1] & (MB_TYPE_16x16 | MB_TYPE_8x16))
6444 ? 3 : 0; 6444 ? 3 : 0;
6445 int step = IS_8x8DCT(mb_type) ? 2 : 1; 6445 int step = IS_8x8DCT(mb_type) ? 2 : 1;
6446 edges = (mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4; 6446 edges = (mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4;
6447 s->dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache, 6447 s->dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache,
6448 (h->slice_type == B_TYPE), edges, step, mask_edge0, mask_edge1 ); 6448 (h->slice_type == FF_B_TYPE), edges, step, mask_edge0, mask_edge1 );
6449 } 6449 }
6450 if( IS_INTRA(s->current_picture.mb_type[mb_xy-1]) ) 6450 if( IS_INTRA(s->current_picture.mb_type[mb_xy-1]) )
6451 bSv[0][0] = 0x0004000400040004ULL; 6451 bSv[0][0] = 0x0004000400040004ULL;
6452 if( IS_INTRA(s->current_picture.mb_type[h->top_mb_xy]) ) 6452 if( IS_INTRA(s->current_picture.mb_type[h->top_mb_xy]) )
6453 bSv[1][0] = FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL; 6453 bSv[1][0] = FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL;
6674 } 6674 }
6675 else if( mask_par0 && (edge || (mbn_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) { 6675 else if( mask_par0 && (edge || (mbn_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) {
6676 int b_idx= 8 + 4 + edge * (dir ? 8:1); 6676 int b_idx= 8 + 4 + edge * (dir ? 8:1);
6677 int bn_idx= b_idx - (dir ? 8:1); 6677 int bn_idx= b_idx - (dir ? 8:1);
6678 int v = 0; 6678 int v = 0;
6679 for( l = 0; !v && l < 1 + (h->slice_type == B_TYPE); l++ ) { 6679 for( l = 0; !v && l < 1 + (h->slice_type == FF_B_TYPE); l++ ) {
6680 v |= ref2frm[h->ref_cache[l][b_idx]+2] != ref2frm[h->ref_cache[l][bn_idx]+2] || 6680 v |= ref2frm[h->ref_cache[l][b_idx]+2] != ref2frm[h->ref_cache[l][bn_idx]+2] ||
6681 FFABS( h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] ) >= 4 || 6681 FFABS( h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] ) >= 4 ||
6682 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit; 6682 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit;
6683 } 6683 }
6684 bS[0] = bS[1] = bS[2] = bS[3] = v; 6684 bS[0] = bS[1] = bS[2] = bS[3] = v;
6698 bS[i] = 2; 6698 bS[i] = 2;
6699 } 6699 }
6700 else if(!mv_done) 6700 else if(!mv_done)
6701 { 6701 {
6702 bS[i] = 0; 6702 bS[i] = 0;
6703 for( l = 0; l < 1 + (h->slice_type == B_TYPE); l++ ) { 6703 for( l = 0; l < 1 + (h->slice_type == FF_B_TYPE); l++ ) {
6704 if( ref2frm[h->ref_cache[l][b_idx]+2] != ref2frm[h->ref_cache[l][bn_idx]+2] || 6704 if( ref2frm[h->ref_cache[l][b_idx]+2] != ref2frm[h->ref_cache[l][bn_idx]+2] ||
6705 FFABS( h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] ) >= 4 || 6705 FFABS( h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] ) >= 4 ||
6706 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit ) { 6706 FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit ) {
6707 bS[i] = 1; 6707 bS[i] = 1;
6708 break; 6708 break;
6761 s->gb.buffer + get_bits_count(&s->gb)/8, 6761 s->gb.buffer + get_bits_count(&s->gb)/8,
6762 ( s->gb.size_in_bits - get_bits_count(&s->gb) + 7)/8); 6762 ( s->gb.size_in_bits - get_bits_count(&s->gb) + 7)/8);
6763 /* calculate pre-state */ 6763 /* calculate pre-state */
6764 for( i= 0; i < 460; i++ ) { 6764 for( i= 0; i < 460; i++ ) {
6765 int pre; 6765 int pre;
6766 if( h->slice_type == I_TYPE ) 6766 if( h->slice_type == FF_I_TYPE )
6767 pre = av_clip( ((cabac_context_init_I[i][0] * s->qscale) >>4 ) + cabac_context_init_I[i][1], 1, 126 ); 6767 pre = av_clip( ((cabac_context_init_I[i][0] * s->qscale) >>4 ) + cabac_context_init_I[i][1], 1, 126 );
6768 else 6768 else
6769 pre = av_clip( ((cabac_context_init_PB[h->cabac_init_idc][i][0] * s->qscale) >>4 ) + cabac_context_init_PB[h->cabac_init_idc][i][1], 1, 126 ); 6769 pre = av_clip( ((cabac_context_init_PB[h->cabac_init_idc][i][0] * s->qscale) >>4 ) + cabac_context_init_PB[h->cabac_init_idc][i][1], 1, 126 );
6770 6770
6771 if( pre <= 63 ) 6771 if( pre <= 63 )
7522 break; 7522 break;
7523 7523
7524 s->current_picture_ptr->key_frame|= (hx->nal_unit_type == NAL_IDR_SLICE); 7524 s->current_picture_ptr->key_frame|= (hx->nal_unit_type == NAL_IDR_SLICE);
7525 if(hx->redundant_pic_count==0 && hx->s.hurry_up < 5 7525 if(hx->redundant_pic_count==0 && hx->s.hurry_up < 5
7526 && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) 7526 && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)
7527 && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type!=B_TYPE) 7527 && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type!=FF_B_TYPE)
7528 && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type==I_TYPE) 7528 && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type==FF_I_TYPE)
7529 && avctx->skip_frame < AVDISCARD_ALL) 7529 && avctx->skip_frame < AVDISCARD_ALL)
7530 context_count++; 7530 context_count++;
7531 break; 7531 break;
7532 case NAL_DPA: 7532 case NAL_DPA:
7533 init_get_bits(&hx->s.gb, ptr, bit_length); 7533 init_get_bits(&hx->s.gb, ptr, bit_length);
7547 7547
7548 if(hx->redundant_pic_count==0 && hx->intra_gb_ptr && hx->s.data_partitioning 7548 if(hx->redundant_pic_count==0 && hx->intra_gb_ptr && hx->s.data_partitioning
7549 && s->context_initialized 7549 && s->context_initialized
7550 && s->hurry_up < 5 7550 && s->hurry_up < 5
7551 && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) 7551 && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)
7552 && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type!=B_TYPE) 7552 && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type!=FF_B_TYPE)
7553 && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type==I_TYPE) 7553 && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type==FF_I_TYPE)
7554 && avctx->skip_frame < AVDISCARD_ALL) 7554 && avctx->skip_frame < AVDISCARD_ALL)
7555 context_count++; 7555 context_count++;
7556 break; 7556 break;
7557 case NAL_SEI: 7557 case NAL_SEI:
7558 init_get_bits(&s->gb, ptr, bit_length); 7558 init_get_bits(&s->gb, ptr, bit_length);
7812 else if(prev && pics <= s->avctx->has_b_frames) 7812 else if(prev && pics <= s->avctx->has_b_frames)
7813 out = prev; 7813 out = prev;
7814 else if((out_of_order && pics-1 == s->avctx->has_b_frames && pics < 15) 7814 else if((out_of_order && pics-1 == s->avctx->has_b_frames && pics < 15)
7815 || (s->low_delay && 7815 || (s->low_delay &&
7816 ((!cross_idr && prev && out->poc > prev->poc + 2) 7816 ((!cross_idr && prev && out->poc > prev->poc + 2)
7817 || cur->pict_type == B_TYPE))) 7817 || cur->pict_type == FF_B_TYPE)))
7818 { 7818 {
7819 s->low_delay = 0; 7819 s->low_delay = 0;
7820 s->avctx->has_b_frames++; 7820 s->avctx->has_b_frames++;
7821 out = prev; 7821 out = prev;
7822 } 7822 }