comparison h264.c @ 2815:636133fccbdc libavcodec

workaround 'colocated mv if colocated block is L1 predicted' bug in x264
author michael
date Mon, 01 Aug 2005 14:47:07 +0000
parents 75400dfbe117
children fd5d7c732c6b
comparison
equal deleted inserted replaced
2814:48fb350b0ec9 2815:636133fccbdc
346 346
347 uint8_t zigzag_scan[16]; 347 uint8_t zigzag_scan[16];
348 uint8_t field_scan[16]; 348 uint8_t field_scan[16];
349 const uint8_t *zigzag_scan_q0; 349 const uint8_t *zigzag_scan_q0;
350 const uint8_t *field_scan_q0; 350 const uint8_t *field_scan_q0;
351
352 int x264_build;
351 }H264Context; 353 }H264Context;
352 354
353 static VLC coeff_token_vlc[4]; 355 static VLC coeff_token_vlc[4];
354 static VLC chroma_dc_coeff_token_vlc; 356 static VLC chroma_dc_coeff_token_vlc;
355 357
1274 if(IS_16X16(*mb_type)){ 1276 if(IS_16X16(*mb_type)){
1275 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref[0], 1); 1277 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref[0], 1);
1276 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, ref[1], 1); 1278 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, ref[1], 1);
1277 if(!IS_INTRA(mb_type_col) 1279 if(!IS_INTRA(mb_type_col)
1278 && ( l1ref0[0] == 0 && ABS(l1mv0[0][0]) <= 1 && ABS(l1mv0[0][1]) <= 1 1280 && ( l1ref0[0] == 0 && ABS(l1mv0[0][0]) <= 1 && ABS(l1mv0[0][1]) <= 1
1279 || l1ref0[0] < 0 && l1ref1[0] == 0 && ABS(l1mv1[0][0]) <= 1 && ABS(l1mv1[0][1]) <= 1)){ 1281 || l1ref0[0] < 0 && l1ref1[0] == 0 && ABS(l1mv1[0][0]) <= 1 && ABS(l1mv1[0][1]) <= 1
1282 && (h->x264_build>33 || !h->x264_build))){
1280 if(ref[0] > 0) 1283 if(ref[0] > 0)
1281 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv[0][0],mv[0][1]), 4); 1284 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv[0][0],mv[0][1]), 4);
1282 else 1285 else
1283 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); 1286 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
1284 if(ref[1] > 0) 1287 if(ref[1] > 0)
1303 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref[0], 1); 1306 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref[0], 1);
1304 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, ref[1], 1); 1307 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, ref[1], 1);
1305 1308
1306 /* col_zero_flag */ 1309 /* col_zero_flag */
1307 if(!IS_INTRA(mb_type_col) && ( l1ref0[x8 + y8*h->b8_stride] == 0 1310 if(!IS_INTRA(mb_type_col) && ( l1ref0[x8 + y8*h->b8_stride] == 0
1308 || l1ref0[x8 + y8*h->b8_stride] < 0 && l1ref1[x8 + y8*h->b8_stride] == 0)){ 1311 || l1ref0[x8 + y8*h->b8_stride] < 0 && l1ref1[x8 + y8*h->b8_stride] == 0
1312 && (h->x264_build>33 || !h->x264_build))){
1309 const int16_t (*l1mv)[2]= l1ref0[x8 + y8*h->b8_stride] == 0 ? l1mv0 : l1mv1; 1313 const int16_t (*l1mv)[2]= l1ref0[x8 + y8*h->b8_stride] == 0 ? l1mv0 : l1mv1;
1310 for(i4=0; i4<4; i4++){ 1314 for(i4=0; i4<4; i4++){
1311 const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*h->b_stride]; 1315 const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*h->b_stride];
1312 if(ABS(mv_col[0]) <= 1 && ABS(mv_col[1]) <= 1){ 1316 if(ABS(mv_col[0]) <= 1 && ABS(mv_col[1]) <= 1){
1313 if(ref[0] == 0) 1317 if(ref[0] == 0)
6828 } 6832 }
6829 #endif 6833 #endif
6830 return -1; //not reached 6834 return -1; //not reached
6831 } 6835 }
6832 6836
6837 static int decode_unregistered_user_data(H264Context *h, int size){
6838 MpegEncContext * const s = &h->s;
6839 uint8_t user_data[16+256];
6840 int e, build, i;
6841
6842 if(size<16)
6843 return -1;
6844
6845 for(i=0; i<sizeof(user_data)-1 && i<size; i++){
6846 user_data[i]= get_bits(&s->gb, 8);
6847 }
6848
6849 user_data[i]= 0;
6850 e= sscanf(user_data+16, "x264 - core %d"/*%s - H.264/MPEG-4 AVC codec - Copyleft 2005 - http://www.videolan.org/x264.html*/, &build);
6851 if(e==1 && build>=0)
6852 h->x264_build= build;
6853
6854 if(s->avctx->debug & FF_DEBUG_BUGS)
6855 av_log(s->avctx, AV_LOG_DEBUG, "user data:\"%s\"\n", user_data+16);
6856
6857 for(; i<size; i++)
6858 skip_bits(&s->gb, 8);
6859
6860 return 0;
6861 }
6862
6863 static int decode_sei(H264Context *h){
6864 MpegEncContext * const s = &h->s;
6865
6866 while(get_bits_count(&s->gb) + 16 < s->gb.size_in_bits){
6867 int size, type;
6868
6869 type=0;
6870 do{
6871 type+= show_bits(&s->gb, 8);
6872 }while(get_bits(&s->gb, 8) == 255);
6873
6874 size=0;
6875 do{
6876 size+= show_bits(&s->gb, 8);
6877 }while(get_bits(&s->gb, 8) == 255);
6878
6879 switch(type){
6880 case 5:
6881 if(decode_unregistered_user_data(h, size) < 0);
6882 return -1;
6883 break;
6884 default:
6885 skip_bits(&s->gb, 8*size);
6886 }
6887
6888 //FIXME check bits here
6889 align_get_bits(&s->gb);
6890 }
6891
6892 return 0;
6893 }
6894
6833 static inline void decode_hrd_parameters(H264Context *h, SPS *sps){ 6895 static inline void decode_hrd_parameters(H264Context *h, SPS *sps){
6834 MpegEncContext * const s = &h->s; 6896 MpegEncContext * const s = &h->s;
6835 int cpb_count, i; 6897 int cpb_count, i;
6836 cpb_count = get_ue_golomb(&s->gb) + 1; 6898 cpb_count = get_ue_golomb(&s->gb) + 1;
6837 get_bits(&s->gb, 4); /* bit_rate_scale */ 6899 get_bits(&s->gb, 4); /* bit_rate_scale */
7255 if (h->is_avc && (nalsize != consumed)) 7317 if (h->is_avc && (nalsize != consumed))
7256 av_log(h->s.avctx, AV_LOG_ERROR, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize); 7318 av_log(h->s.avctx, AV_LOG_ERROR, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize);
7257 7319
7258 buf_index += consumed; 7320 buf_index += consumed;
7259 7321
7260 if( (s->hurry_up == 1 && h->nal_ref_idc == 0) 7322 if( (s->hurry_up == 1 && h->nal_ref_idc == 0) //FIXME dont discard SEI id
7261 ||(avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) 7323 ||(avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0))
7262 continue; 7324 continue;
7263 7325
7264 switch(h->nal_unit_type){ 7326 switch(h->nal_unit_type){
7265 case NAL_IDR_SLICE: 7327 case NAL_IDR_SLICE:
7306 && (avctx->skip_frame < AVDISCARD_NONKEY || h->slice_type==I_TYPE) 7368 && (avctx->skip_frame < AVDISCARD_NONKEY || h->slice_type==I_TYPE)
7307 && avctx->skip_frame < AVDISCARD_ALL) 7369 && avctx->skip_frame < AVDISCARD_ALL)
7308 decode_slice(h); 7370 decode_slice(h);
7309 break; 7371 break;
7310 case NAL_SEI: 7372 case NAL_SEI:
7373 init_get_bits(&s->gb, ptr, bit_length);
7374 decode_sei(h);
7311 break; 7375 break;
7312 case NAL_SPS: 7376 case NAL_SPS:
7313 init_get_bits(&s->gb, ptr, bit_length); 7377 init_get_bits(&s->gb, ptr, bit_length);
7314 decode_seq_parameter_set(h); 7378 decode_seq_parameter_set(h);
7315 7379