comparison h264.c @ 5780:bd3d1e4f937a libavcodec

Support function and changes to reference picture reordering for PAFF. patch by Jeff Downs, heydowns a borg d com original thread: Subject: [FFmpeg-devel] [PATCH] Implement PAFF in H.264 Date: 18/09/07 20:30
author andoma
date Fri, 05 Oct 2007 13:54:11 +0000
parents ad3168a70fbe
children 0b3aa6f4c313
comparison
equal deleted inserted replaced
5779:ad3168a70fbe 5780:bd3d1e4f937a
3017 } 3017 }
3018 3018
3019 static void print_short_term(H264Context *h); 3019 static void print_short_term(H264Context *h);
3020 static void print_long_term(H264Context *h); 3020 static void print_long_term(H264Context *h);
3021 3021
3022 /**
3023 * Extract structure information about the picture described by pic_num in
3024 * the current decoding context (frame or field). Note that pic_num is
3025 * picture number without wrapping (so, 0<=pic_num<max_pic_num).
3026 * @param pic_num picture number for which to extract structure information
3027 * @param structure one of PICT_XXX describing structure of picture
3028 * with pic_num
3029 * @return frame number (short term) or long term index of picture
3030 * described by pic_num
3031 */
3032 static int pic_num_extract(H264Context *h, int pic_num, int *structure){
3033 MpegEncContext * const s = &h->s;
3034
3035 *structure = s->picture_structure;
3036 if(FIELD_PICTURE){
3037 if (!(pic_num & 1))
3038 /* opposite field */
3039 *structure ^= PICT_FRAME;
3040 pic_num >>= 1;
3041 }
3042
3043 return pic_num;
3044 }
3045
3022 static int decode_ref_pic_list_reordering(H264Context *h){ 3046 static int decode_ref_pic_list_reordering(H264Context *h){
3023 MpegEncContext * const s = &h->s; 3047 MpegEncContext * const s = &h->s;
3024 int list, index; 3048 int list, index, pic_structure;
3025 3049
3026 print_short_term(h); 3050 print_short_term(h);
3027 print_long_term(h); 3051 print_long_term(h);
3028 if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move before func 3052 if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move before func
3029 3053
3048 } 3072 }
3049 3073
3050 if(reordering_of_pic_nums_idc<3){ 3074 if(reordering_of_pic_nums_idc<3){
3051 if(reordering_of_pic_nums_idc<2){ 3075 if(reordering_of_pic_nums_idc<2){
3052 const unsigned int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1; 3076 const unsigned int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1;
3077 int frame_num;
3053 3078
3054 if(abs_diff_pic_num >= h->max_pic_num){ 3079 if(abs_diff_pic_num >= h->max_pic_num){
3055 av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); 3080 av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n");
3056 return -1; 3081 return -1;
3057 } 3082 }
3058 3083
3059 if(reordering_of_pic_nums_idc == 0) pred-= abs_diff_pic_num; 3084 if(reordering_of_pic_nums_idc == 0) pred-= abs_diff_pic_num;
3060 else pred+= abs_diff_pic_num; 3085 else pred+= abs_diff_pic_num;
3061 pred &= h->max_pic_num - 1; 3086 pred &= h->max_pic_num - 1;
3062 3087
3088 frame_num = pic_num_extract(h, pred, &pic_structure);
3089
3063 for(i= h->short_ref_count-1; i>=0; i--){ 3090 for(i= h->short_ref_count-1; i>=0; i--){
3064 ref = h->short_ref[i]; 3091 ref = h->short_ref[i];
3065 assert(ref->reference == 3); 3092 assert(ref->reference);
3066 assert(!ref->long_ref); 3093 assert(!ref->long_ref);
3067 if(ref->data[0] != NULL && ref->frame_num == pred && ref->long_ref == 0) // ignore non existing pictures by testing data[0] pointer 3094 if(ref->data[0] != NULL &&
3095 ref->frame_num == frame_num &&
3096 (ref->reference & pic_structure) &&
3097 ref->long_ref == 0) // ignore non existing pictures by testing data[0] pointer
3068 break; 3098 break;
3069 } 3099 }
3070 if(i>=0) 3100 if(i>=0)
3071 ref->pic_id= ref->frame_num; 3101 ref->pic_id= pred;
3072 }else{ 3102 }else{
3103 int long_idx;
3073 pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx 3104 pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx
3074 if(pic_id>31){ 3105
3106 long_idx= pic_num_extract(h, pic_id, &pic_structure);
3107
3108 if(long_idx>31){
3075 av_log(h->s.avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n"); 3109 av_log(h->s.avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n");
3076 return -1; 3110 return -1;
3077 } 3111 }
3078 ref = h->long_ref[pic_id]; 3112 ref = h->long_ref[long_idx];
3079 if(ref){ 3113 assert(!(ref && !ref->reference));
3114 if(ref && (ref->reference & pic_structure)){
3080 ref->pic_id= pic_id; 3115 ref->pic_id= pic_id;
3081 assert(ref->reference == 3);
3082 assert(ref->long_ref); 3116 assert(ref->long_ref);
3083 i=0; 3117 i=0;
3084 }else{ 3118 }else{
3085 i=-1; 3119 i=-1;
3086 } 3120 }
3096 } 3130 }
3097 for(; i > index; i--){ 3131 for(; i > index; i--){
3098 h->ref_list[list][i]= h->ref_list[list][i-1]; 3132 h->ref_list[list][i]= h->ref_list[list][i-1];
3099 } 3133 }
3100 h->ref_list[list][index]= *ref; 3134 h->ref_list[list][index]= *ref;
3135 if (FIELD_PICTURE){
3136 int bot = pic_structure == PICT_BOTTOM_FIELD;
3137 pic_as_field(&h->ref_list[list][index], bot);
3138 }
3101 } 3139 }
3102 }else{ 3140 }else{
3103 av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); 3141 av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n");
3104 return -1; 3142 return -1;
3105 } 3143 }