Mercurial > libavcodec.hg
changeset 1169:4e891257d3e2 libavcodec
multiple reference frames support
author | michaelni |
---|---|
date | Fri, 04 Apr 2003 20:59:50 +0000 |
parents | 5af9aeadbdc3 |
children | 4710976004a5 |
files | golomb.h h264.c |
diffstat | 2 files changed, 66 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/golomb.h Fri Apr 04 14:42:28 2003 +0000 +++ b/golomb.h Fri Apr 04 20:59:50 2003 +0000 @@ -66,7 +66,7 @@ assert(range >= 1); if(range==1) return 0; - else if(range==2) return get_bits1(gb); + else if(range==2) return get_bits1(gb)^1; else return get_ue_golomb(gb); } @@ -76,7 +76,7 @@ static inline int get_te_golomb(GetBitContext *gb, int range){ assert(range >= 1); - if(range==2) return get_bits1(gb); + if(range==2) return get_bits1(gb)^1; else return get_ue_golomb(gb); } @@ -193,7 +193,7 @@ assert(range >= 1); assert(i<=range); - if(range==2) put_bits(pb, 1, i); + if(range==2) put_bits(pb, 1, i^1); else set_ue_golomb(pb, i); }
--- a/h264.c Fri Apr 04 14:42:28 2003 +0000 +++ b/h264.c Fri Apr 04 20:59:50 2003 +0000 @@ -733,6 +733,21 @@ return i&31; } +static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){ + const int topright_ref= h->ref_cache[list][ i - 8 + part_width ]; + + if(topright_ref != PART_NOT_AVAILABLE){ + *C= h->mv_cache[list][ i - 8 + part_width ]; + return topright_ref; + }else{ +#ifdef TRACE + printf("topright MV not available\n"); +#endif + *C= h->mv_cache[list][ i - 8 - 1 ]; + return h->ref_cache[list][ i - 8 - 1 ]; + } +} + /** * gets the predicted MV. * @param n the block index @@ -744,14 +759,14 @@ MpegEncContext * const s = &h->s; const int index8= scan8[n]; const int top_ref= h->ref_cache[list][ index8 - 8 ]; - const int topright_ref= h->ref_cache[list][ index8 - 8 + part_width ]; const int left_ref= h->ref_cache[list][ index8 - 1 ]; const int16_t * const A= h->mv_cache[list][ index8 - 1 ]; const int16_t * const B= h->mv_cache[list][ index8 - 8 ]; - const int16_t * const C= h->mv_cache[list][ index8 - 8 + part_width ]; - + const int16_t * C; + int diagonal_ref, match_count; + assert(part_width==1 || part_width==2 || part_width==4); - + /* mv_cache B . . A T T T T U . . L . . , . @@ -759,36 +774,36 @@ U . . L . . , . . . . L . . . . */ - if(topright_ref != PART_NOT_AVAILABLE){ - if((topright_ref==ref) + (top_ref==ref) + (left_ref==ref) == 1){ - *mx= A[0] + B[0] + C[0]; - *my= A[1] + B[1] + C[1]; + + diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width); + match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref); + + if(match_count > 1){ //most common + *mx= mid_pred(A[0], B[0], C[0]); + *my= mid_pred(A[1], B[1], C[1]); + }else if(match_count==1){ + if(left_ref==ref){ + *mx= A[0]; + *my= A[1]; + }else if(top_ref==ref){ + *mx= B[0]; + *my= B[1]; + }else{ + *mx= C[0]; + *my= C[1]; + } + }else{ + if(top_ref == PART_NOT_AVAILABLE && diagonal_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){ + *mx= A[0]; + *my= A[1]; }else{ *mx= mid_pred(A[0], B[0], C[0]); *my= mid_pred(A[1], B[1], C[1]); } - }else{ - const int topleft_ref= h->ref_cache[list][ index8 - 9 ]; - const int16_t * const D= h->mv_cache[list][ index8 - 9 ]; - if(top_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){ //FIXME check rare FMO case where std isnt clear - *mx= A[0]; - *my= A[1]; - }else{ - if((topleft_ref==ref) + (top_ref==ref) + (left_ref==ref) == 1){ - *mx= A[0] + B[0] + D[0]; - *my= A[1] + B[1] + D[1]; - }else{ - *mx= mid_pred(A[0], B[0], D[0]); - *my= mid_pred(A[1], B[1], D[1]); - } - } + } #ifdef TRACE -printf("topleft: %2d %2d %2d ", topleft_ref, D[0], D[1]); -#endif - } -#ifdef TRACE -printf("pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], topright_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, s->mb_x, s->mb_y, n, list); +printf("pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, s->mb_x, s->mb_y, n, list); #endif } @@ -854,32 +869,20 @@ return; } }else{ - const int topright_ref= h->ref_cache[list][ scan8[4] - 8 + 2 ]; - const int16_t * const C= h->mv_cache[list][ scan8[4] - 8 + 2 ]; + const int16_t * C; + int diagonal_ref; + + diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2); #ifdef TRACE -printf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d", topright_ref, C[0], C[1], s->mb_x, s->mb_y, n, list); +printf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d", diagonal_ref, C[0], C[1], s->mb_x, s->mb_y, n, list); #endif - if(topright_ref == ref){ + if(diagonal_ref == ref){ *mx= C[0]; *my= C[1]; return; } - - if(topright_ref == PART_NOT_AVAILABLE){ //insanity ... - const int topleft_ref= h->ref_cache[list][ scan8[4] - 9 ]; - const int16_t * const D= h->mv_cache[list][ scan8[4] - 9 ]; - -#ifdef TRACE -printf("pred_8x16: insanity (%2d %2d %2d) at %2d %2d %d list %d", topleft_ref, D[0], D[1], s->mb_x, s->mb_y, n, list); -#endif - if(topleft_ref == ref){ - *mx= D[0]; - *my= D[1]; - return; - } - } } //RARE @@ -1947,7 +1950,7 @@ y_offset += 8*s->mb_y; if(list0){ - Picture *ref= &h->ref_list[0][ h->ref_cache[0][ scan8[0] ] ]; + Picture *ref= &h->ref_list[0][ h->ref_cache[0][ scan8[n] ] ]; mc_dir_part(h, ref, n, square, chroma_height, delta, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset, qpix_op, chroma_op); @@ -1957,7 +1960,7 @@ } if(list1){ - Picture *ref= &h->ref_list[1][ h->ref_cache[1][ scan8[0] ] ]; + Picture *ref= &h->ref_list[1][ h->ref_cache[1][ scan8[n] ] ]; mc_dir_part(h, ref, n, square, chroma_height, delta, 1, dest_y, dest_cb, dest_cr, x_offset, y_offset, qpix_op, chroma_op); @@ -2539,16 +2542,21 @@ h->short_ref_count=0; } -//static void /** * * @return the removed picture or NULL if an error occures */ static Picture * remove_short(H264Context *h, int frame_num){ + MpegEncContext * const s = &h->s; int i; + if(s->avctx->debug&FF_DEBUG_MMCO) + printf("remove short %d count %d\n", frame_num, h->short_ref_count); + for(i=0; i<h->short_ref_count; i++){ Picture *pic= h->short_ref[i]; + if(s->avctx->debug&FF_DEBUG_MMCO) + printf("%d %d %X\n", i, pic->frame_num, (int)pic); if(pic->frame_num == frame_num){ h->short_ref[i]= NULL; memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i - 1)*sizeof(Picture*)); @@ -2653,8 +2661,9 @@ } if(h->short_ref_count) - memmove(&h->short_ref[1], &h->short_ref[0], (h->short_ref_count - 1)*sizeof(Picture*)); - h->short_ref[0]= s->current_picture_ptr; + memmove(&h->short_ref[1], &h->short_ref[0], h->short_ref_count*sizeof(Picture*)); + + h->short_ref[0]= s->current_picture_ptr; h->short_ref[0]->long_ref=0; h->short_ref_count++; } @@ -2884,6 +2893,7 @@ frame_start(h); } + s->current_picture_ptr->frame_num= //FIXME frame_num cleanup h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); if(h->sps.frame_mbs_only_flag){ @@ -3176,7 +3186,7 @@ static int decode_mb(H264Context *h){ MpegEncContext * const s = &h->s; const int mb_xy= s->mb_x + s->mb_y*h->mb_stride; - int mb_type, /*ref0,*/ partition_count, cbp; + int mb_type, partition_count, cbp; memset(h->mb, 0, sizeof(int16_t)*24*16); //FIXME avoid if allready clear (move after skip handlong? @@ -4096,7 +4106,7 @@ if(s->current_picture_ptr->reference) execute_ref_pic_marking(h, h->mmco, h->mmco_index); else - assert(h->mmco_index=0); + assert(h->mmco_index==0); ff_er_frame_end(s); MPV_frame_end(s);