static int fill_default_ref_list(H264Context *h){
    MpegEncContext * const s = &h->s;
    int i;
    int smallest_poc_greater_than_current = -1;
    int structure_sel;
    Picture sorted_short_ref[32];
    Picture field_entry_list[2][32];
    Picture *frame_list[2];
    if (FIELD_PICTURE) {
        structure_sel = PICT_FRAME;
        frame_list[0] = field_entry_list[0];
        frame_list[1] = field_entry_list[1];
    } else {
        structure_sel = 0;
        frame_list[0] = h->default_ref_list[0];
        frame_list[1] = h->default_ref_list[1];
    }
    if(h->slice_type==FF_B_TYPE){
        int list;
        int len[2];
        int short_len[2];
        int out_i;
        int limit= INT_MIN;
        for(out_i=0; out_i<h->short_ref_count; out_i++){
            int best_i=INT_MIN;
            int best_poc=INT_MAX;
            for(i=0; i<h->short_ref_count; i++){
                const int poc= h->short_ref[i]->poc;
                if(poc > limit && poc < best_poc){
                    best_poc= poc;
                    best_i= i;
                }
            }
            assert(best_i != INT_MIN);
            limit= best_poc;
            sorted_short_ref[out_i]= *h->short_ref[best_i];
            tprintf(h->s.avctx, "sorted poc: %d->%d poc:%d fn:%d\n", best_i, out_i, sorted_short_ref[out_i].poc, sorted_short_ref[out_i].frame_num);
            if (-1 == smallest_poc_greater_than_current) {
                if (h->short_ref[best_i]->poc >= s->current_picture_ptr->poc) {
                    smallest_poc_greater_than_current = out_i;
                }
            }
        }
        tprintf(h->s.avctx, "current poc: %d, smallest_poc_greater_than_current: %d\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current);
        for(list=0; list<2; list++){
            int index = 0;
            int j= -99;
            int step= list ? -1 : 1;
            for(i=0; i<h->short_ref_count && index < h->ref_count[list]; i++, j+=step) {
                int sel;
                while(j<0 || j>= h->short_ref_count){
                    if(j != -99 && step == (list ? -1 : 1))
                        return -1;
                    step = -step;
                    j= smallest_poc_greater_than_current + (step>>1);
                }
                sel = sorted_short_ref[j].reference | structure_sel;
                if(sel != PICT_FRAME) continue;
                frame_list[list][index  ]= sorted_short_ref[j];
                frame_list[list][index++].pic_id= sorted_short_ref[j].frame_num;
            }
            short_len[list] = index;
            for(i = 0; i < 16 && index < h->ref_count[ list ]; i++){
                int sel;
                if(h->long_ref[i] == NULL) continue;
                sel = h->long_ref[i]->reference | structure_sel;
                if(sel != PICT_FRAME) continue;
                frame_list[ list ][index  ]= *h->long_ref[i];
                frame_list[ list ][index++].pic_id= i;
            }
            len[list] = index;
        }
        for(list=0; list<2; list++){
            if (FIELD_PICTURE)
                len[list] = split_field_ref_list(h->default_ref_list[list],
                                                 h->ref_count[list],
                                                 frame_list[list],
                                                 len[list],
                                                 s->picture_structure,
                                                 short_len[list]);
            if(list && len[0] > 1 && len[0] == len[1])
                for(i=0; h->default_ref_list[0][i].data[0] == h->default_ref_list[1][i].data[0]; i++)
                    if(i == len[0]){
                        FFSWAP(Picture, h->default_ref_list[1][0], h->default_ref_list[1][1]);
                        break;
                    }
            if(len[list] < h->ref_count[ list ])
                memset(&h->default_ref_list[list][len[list]], 0, sizeof(Picture)*(h->ref_count[ list ] - len[list]));
        }
    }else{
        int index=0;
        int short_len;
        for(i=0; i<h->short_ref_count; i++){
            int sel;
            sel = h->short_ref[i]->reference | structure_sel;
            if(sel != PICT_FRAME) continue;
            frame_list[0][index  ]= *h->short_ref[i];
            frame_list[0][index++].pic_id= h->short_ref[i]->frame_num;
        }
        short_len = index;
        for(i = 0; i < 16; i++){
            int sel;
            if(h->long_ref[i] == NULL) continue;
            sel = h->long_ref[i]->reference | structure_sel;
            if(sel != PICT_FRAME) continue;
            frame_list[0][index  ]= *h->long_ref[i];
            frame_list[0][index++].pic_id= i;
        }
        if (FIELD_PICTURE)
            index = split_field_ref_list(h->default_ref_list[0],
                                         h->ref_count[0], frame_list[0],
                                         index, s->picture_structure,
                                         short_len);
        if(index < h->ref_count[0])
            memset(&h->default_ref_list[0][index], 0, sizeof(Picture)*(h->ref_count[0] - index));
    }
#ifdef TRACE
    for (i=0; i<h->ref_count[0]; i++) {
        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]);
    }
    if(h->slice_type==FF_B_TYPE){
        for (i=0; i<h->ref_count[1]; i++) {
            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]);
        }
    }
#endif
    return 0;
}
['static int decode_slice_header(H264Context *h, H264Context *h0){\n    MpegEncContext * const s = &h->s;\n    MpegEncContext * const s0 = &h0->s;\n    unsigned int first_mb_in_slice;\n    unsigned int pps_id;\n    int num_ref_idx_active_override_flag;\n    static const uint8_t slice_type_map[5]= {FF_P_TYPE, FF_B_TYPE, FF_I_TYPE, FF_SP_TYPE, FF_SI_TYPE};\n    unsigned int slice_type, tmp, i;\n    int default_ref_list_done = 0;\n    int last_pic_structure;\n    s->dropable= h->nal_ref_idc == 0;\n    if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc){\n        s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;\n        s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;\n    }else{\n        s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab;\n        s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab;\n    }\n    first_mb_in_slice= get_ue_golomb(&s->gb);\n    if((s->flags2 & CODEC_FLAG2_CHUNKS) && first_mb_in_slice == 0){\n        h0->current_slice = 0;\n        if (!s0->first_field)\n            s->current_picture_ptr= NULL;\n    }\n    slice_type= get_ue_golomb(&s->gb);\n    if(slice_type > 9){\n        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);\n        return -1;\n    }\n    if(slice_type > 4){\n        slice_type -= 5;\n        h->slice_type_fixed=1;\n    }else\n        h->slice_type_fixed=0;\n    slice_type= slice_type_map[ slice_type ];\n    if (slice_type == FF_I_TYPE\n        || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) {\n        default_ref_list_done = 1;\n    }\n    h->slice_type= slice_type;\n    s->pict_type= h->slice_type;\n    if (s->pict_type == FF_B_TYPE && s0->last_picture_ptr == NULL) {\n        av_log(h->s.avctx, AV_LOG_ERROR,\n               "B picture before any references, skipping\\n");\n        return -1;\n    }\n    pps_id= get_ue_golomb(&s->gb);\n    if(pps_id>=MAX_PPS_COUNT){\n        av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\\n");\n        return -1;\n    }\n    if(!h0->pps_buffers[pps_id]) {\n        av_log(h->s.avctx, AV_LOG_ERROR, "non existing PPS referenced\\n");\n        return -1;\n    }\n    h->pps= *h0->pps_buffers[pps_id];\n    if(!h0->sps_buffers[h->pps.sps_id]) {\n        av_log(h->s.avctx, AV_LOG_ERROR, "non existing SPS referenced\\n");\n        return -1;\n    }\n    h->sps = *h0->sps_buffers[h->pps.sps_id];\n    if(h == h0 && h->dequant_coeff_pps != pps_id){\n        h->dequant_coeff_pps = pps_id;\n        init_dequant_tables(h);\n    }\n    s->mb_width= h->sps.mb_width;\n    s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);\n    h->b_stride=  s->mb_width*4;\n    h->b8_stride= s->mb_width*2;\n    s->width = 16*s->mb_width - 2*(h->sps.crop_left + h->sps.crop_right );\n    if(h->sps.frame_mbs_only_flag)\n        s->height= 16*s->mb_height - 2*(h->sps.crop_top  + h->sps.crop_bottom);\n    else\n        s->height= 16*s->mb_height - 4*(h->sps.crop_top  + h->sps.crop_bottom);\n    if (s->context_initialized\n        && (   s->width != s->avctx->width || s->height != s->avctx->height)) {\n        if(h != h0)\n            return -1;\n        free_tables(h);\n        MPV_common_end(s);\n    }\n    if (!s->context_initialized) {\n        if(h != h0)\n            return -1;\n        if (MPV_common_init(s) < 0)\n            return -1;\n        s->first_field = 0;\n        init_scan_tables(h);\n        alloc_tables(h);\n        for(i = 1; i < s->avctx->thread_count; i++) {\n            H264Context *c;\n            c = h->thread_context[i] = av_malloc(sizeof(H264Context));\n            memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));\n            memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext));\n            c->sps = h->sps;\n            c->pps = h->pps;\n            init_scan_tables(c);\n            clone_tables(c, h);\n        }\n        for(i = 0; i < s->avctx->thread_count; i++)\n            if(context_init(h->thread_context[i]) < 0)\n                return -1;\n        s->avctx->width = s->width;\n        s->avctx->height = s->height;\n        s->avctx->sample_aspect_ratio= h->sps.sar;\n        if(!s->avctx->sample_aspect_ratio.den)\n            s->avctx->sample_aspect_ratio.den = 1;\n        if(h->sps.timing_info_present_flag){\n            s->avctx->time_base= (AVRational){h->sps.num_units_in_tick * 2, h->sps.time_scale};\n            if(h->x264_build > 0 && h->x264_build < 44)\n                s->avctx->time_base.den *= 2;\n            av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,\n                      s->avctx->time_base.num, s->avctx->time_base.den, 1<<30);\n        }\n    }\n    h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num);\n    h->mb_mbaff = 0;\n    h->mb_aff_frame = 0;\n    last_pic_structure = s0->picture_structure;\n    if(h->sps.frame_mbs_only_flag){\n        s->picture_structure= PICT_FRAME;\n    }else{\n        if(get_bits1(&s->gb)) {\n            s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb);\n        } else {\n            s->picture_structure= PICT_FRAME;\n            h->mb_aff_frame = h->sps.mb_aff;\n        }\n    }\n    if(h0->current_slice == 0){\n        if (s0->first_field) {\n            assert(s0->current_picture_ptr);\n            assert(s0->current_picture_ptr->data[0]);\n            assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF);\n            if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {\n                s0->current_picture_ptr = NULL;\n                s0->first_field = FIELD_PICTURE;\n            } else {\n                if (h->nal_ref_idc &&\n                        s0->current_picture_ptr->reference &&\n                        s0->current_picture_ptr->frame_num != h->frame_num) {\n                    s0->first_field = 1;\n                    s0->current_picture_ptr = NULL;\n                } else {\n                    s0->first_field = 0;\n                }\n            }\n        } else {\n            assert(!s0->current_picture_ptr);\n            s0->first_field = FIELD_PICTURE;\n        }\n        if((!FIELD_PICTURE || s0->first_field) && frame_start(h) < 0) {\n            s0->first_field = 0;\n            return -1;\n        }\n    }\n    if(h != h0)\n        clone_slice(h, h0);\n    s->current_picture_ptr->frame_num= h->frame_num;\n    assert(s->mb_num == s->mb_width * s->mb_height);\n    if(first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num ||\n       first_mb_in_slice                    >= s->mb_num){\n        av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\\n");\n        return -1;\n    }\n    s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;\n    s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE;\n    if (s->picture_structure == PICT_BOTTOM_FIELD)\n        s->resync_mb_y = s->mb_y = s->mb_y + 1;\n    assert(s->mb_y < s->mb_height);\n    if(s->picture_structure==PICT_FRAME){\n        h->curr_pic_num=   h->frame_num;\n        h->max_pic_num= 1<< h->sps.log2_max_frame_num;\n    }else{\n        h->curr_pic_num= 2*h->frame_num + 1;\n        h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1);\n    }\n    if(h->nal_unit_type == NAL_IDR_SLICE){\n        get_ue_golomb(&s->gb);\n    }\n    if(h->sps.poc_type==0){\n        h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb);\n        if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){\n            h->delta_poc_bottom= get_se_golomb(&s->gb);\n        }\n    }\n    if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){\n        h->delta_poc[0]= get_se_golomb(&s->gb);\n        if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME)\n            h->delta_poc[1]= get_se_golomb(&s->gb);\n    }\n    init_poc(h);\n    if(h->pps.redundant_pic_cnt_present){\n        h->redundant_pic_count= get_ue_golomb(&s->gb);\n    }\n    h->ref_count[0]= h->pps.ref_count[0];\n    h->ref_count[1]= h->pps.ref_count[1];\n    if(h->slice_type == FF_P_TYPE || h->slice_type == FF_SP_TYPE || h->slice_type == FF_B_TYPE){\n        if(h->slice_type == FF_B_TYPE){\n            h->direct_spatial_mv_pred= get_bits1(&s->gb);\n        }\n        num_ref_idx_active_override_flag= get_bits1(&s->gb);\n        if(num_ref_idx_active_override_flag){\n            h->ref_count[0]= get_ue_golomb(&s->gb) + 1;\n            if(h->slice_type==FF_B_TYPE)\n                h->ref_count[1]= get_ue_golomb(&s->gb) + 1;\n            if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){\n                av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\\n");\n                h->ref_count[0]= h->ref_count[1]= 1;\n                return -1;\n            }\n        }\n        if(h->slice_type == FF_B_TYPE)\n            h->list_count= 2;\n        else\n            h->list_count= 1;\n    }else\n        h->list_count= 0;\n    if(!default_ref_list_done){\n        fill_default_ref_list(h);\n    }\n    if(decode_ref_pic_list_reordering(h) < 0)\n        return -1;\n    if(   (h->pps.weighted_pred          && (h->slice_type == FF_P_TYPE || h->slice_type == FF_SP_TYPE ))\n       || (h->pps.weighted_bipred_idc==1 && h->slice_type==FF_B_TYPE ) )\n        pred_weight_table(h);\n    else if(h->pps.weighted_bipred_idc==2 && h->slice_type==FF_B_TYPE)\n        implicit_weight_table(h);\n    else\n        h->use_weight = 0;\n    if(h->nal_ref_idc)\n        decode_ref_pic_marking(h0, &s->gb);\n    if(FRAME_MBAFF)\n        fill_mbaff_ref_list(h);\n    if( h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE && h->pps.cabac ){\n        tmp = get_ue_golomb(&s->gb);\n        if(tmp > 2){\n            av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\\n");\n            return -1;\n        }\n        h->cabac_init_idc= tmp;\n    }\n    h->last_qscale_diff = 0;\n    tmp = h->pps.init_qp + get_se_golomb(&s->gb);\n    if(tmp>51){\n        av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n        return -1;\n    }\n    s->qscale= tmp;\n    h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n    h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n    if(h->slice_type == FF_SP_TYPE){\n        get_bits1(&s->gb);\n    }\n    if(h->slice_type==FF_SP_TYPE || h->slice_type == FF_SI_TYPE){\n        get_se_golomb(&s->gb);\n    }\n    h->deblocking_filter = 1;\n    h->slice_alpha_c0_offset = 0;\n    h->slice_beta_offset = 0;\n    if( h->pps.deblocking_filter_parameters_present ) {\n        tmp= get_ue_golomb(&s->gb);\n        if(tmp > 2){\n            av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\\n", tmp);\n            return -1;\n        }\n        h->deblocking_filter= tmp;\n        if(h->deblocking_filter < 2)\n            h->deblocking_filter^= 1;\n        if( h->deblocking_filter ) {\n            h->slice_alpha_c0_offset = get_se_golomb(&s->gb) << 1;\n            h->slice_beta_offset = get_se_golomb(&s->gb) << 1;\n        }\n    }\n    if(   s->avctx->skip_loop_filter >= AVDISCARD_ALL\n       ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type != FF_I_TYPE)\n       ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR  && h->slice_type == FF_B_TYPE)\n       ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0))\n        h->deblocking_filter= 0;\n    if(h->deblocking_filter == 1 && h0->max_contexts > 1) {\n        if(s->avctx->flags2 & CODEC_FLAG2_FAST) {\n            h->deblocking_filter = 2;\n        } else {\n            h0->max_contexts = 1;\n            if(!h0->single_decode_warning) {\n                av_log(s->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\\n");\n                h0->single_decode_warning = 1;\n            }\n            if(h != h0)\n                return 1;\n        }\n    }\n#if 0\n    if( h->pps.num_slice_groups > 1  && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5)\n        slice_group_change_cycle= get_bits(&s->gb, ?);\n#endif\n    h0->last_slice_type = slice_type;\n    h->slice_num = ++h0->current_slice;\n    h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;\n    h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;\n    if(s->avctx->debug&FF_DEBUG_PICT_INFO){\n        av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s\\n",\n               h->slice_num,\n               (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"),\n               first_mb_in_slice,\n               av_get_pict_type_char(h->slice_type),\n               pps_id, h->frame_num,\n               s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1],\n               h->ref_count[0], h->ref_count[1],\n               s->qscale,\n               h->deblocking_filter, h->slice_alpha_c0_offset/2, h->slice_beta_offset/2,\n               h->use_weight,\n               h->use_weight==1 && h->use_weight_chroma ? "c" : ""\n               );\n    }\n    return 0;\n}', 'static int fill_default_ref_list(H264Context *h){\n    MpegEncContext * const s = &h->s;\n    int i;\n    int smallest_poc_greater_than_current = -1;\n    int structure_sel;\n    Picture sorted_short_ref[32];\n    Picture field_entry_list[2][32];\n    Picture *frame_list[2];\n    if (FIELD_PICTURE) {\n        structure_sel = PICT_FRAME;\n        frame_list[0] = field_entry_list[0];\n        frame_list[1] = field_entry_list[1];\n    } else {\n        structure_sel = 0;\n        frame_list[0] = h->default_ref_list[0];\n        frame_list[1] = h->default_ref_list[1];\n    }\n    if(h->slice_type==FF_B_TYPE){\n        int list;\n        int len[2];\n        int short_len[2];\n        int out_i;\n        int limit= INT_MIN;\n        for(out_i=0; out_i<h->short_ref_count; out_i++){\n            int best_i=INT_MIN;\n            int best_poc=INT_MAX;\n            for(i=0; i<h->short_ref_count; i++){\n                const int poc= h->short_ref[i]->poc;\n                if(poc > limit && poc < best_poc){\n                    best_poc= poc;\n                    best_i= i;\n                }\n            }\n            assert(best_i != INT_MIN);\n            limit= best_poc;\n            sorted_short_ref[out_i]= *h->short_ref[best_i];\n            tprintf(h->s.avctx, "sorted poc: %d->%d poc:%d fn:%d\\n", best_i, out_i, sorted_short_ref[out_i].poc, sorted_short_ref[out_i].frame_num);\n            if (-1 == smallest_poc_greater_than_current) {\n                if (h->short_ref[best_i]->poc >= s->current_picture_ptr->poc) {\n                    smallest_poc_greater_than_current = out_i;\n                }\n            }\n        }\n        tprintf(h->s.avctx, "current poc: %d, smallest_poc_greater_than_current: %d\\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current);\n        for(list=0; list<2; list++){\n            int index = 0;\n            int j= -99;\n            int step= list ? -1 : 1;\n            for(i=0; i<h->short_ref_count && index < h->ref_count[list]; i++, j+=step) {\n                int sel;\n                while(j<0 || j>= h->short_ref_count){\n                    if(j != -99 && step == (list ? -1 : 1))\n                        return -1;\n                    step = -step;\n                    j= smallest_poc_greater_than_current + (step>>1);\n                }\n                sel = sorted_short_ref[j].reference | structure_sel;\n                if(sel != PICT_FRAME) continue;\n                frame_list[list][index  ]= sorted_short_ref[j];\n                frame_list[list][index++].pic_id= sorted_short_ref[j].frame_num;\n            }\n            short_len[list] = index;\n            for(i = 0; i < 16 && index < h->ref_count[ list ]; i++){\n                int sel;\n                if(h->long_ref[i] == NULL) continue;\n                sel = h->long_ref[i]->reference | structure_sel;\n                if(sel != PICT_FRAME) continue;\n                frame_list[ list ][index  ]= *h->long_ref[i];\n                frame_list[ list ][index++].pic_id= i;\n            }\n            len[list] = index;\n        }\n        for(list=0; list<2; list++){\n            if (FIELD_PICTURE)\n                len[list] = split_field_ref_list(h->default_ref_list[list],\n                                                 h->ref_count[list],\n                                                 frame_list[list],\n                                                 len[list],\n                                                 s->picture_structure,\n                                                 short_len[list]);\n            if(list && len[0] > 1 && len[0] == len[1])\n                for(i=0; h->default_ref_list[0][i].data[0] == h->default_ref_list[1][i].data[0]; i++)\n                    if(i == len[0]){\n                        FFSWAP(Picture, h->default_ref_list[1][0], h->default_ref_list[1][1]);\n                        break;\n                    }\n            if(len[list] < h->ref_count[ list ])\n                memset(&h->default_ref_list[list][len[list]], 0, sizeof(Picture)*(h->ref_count[ list ] - len[list]));\n        }\n    }else{\n        int index=0;\n        int short_len;\n        for(i=0; i<h->short_ref_count; i++){\n            int sel;\n            sel = h->short_ref[i]->reference | structure_sel;\n            if(sel != PICT_FRAME) continue;\n            frame_list[0][index  ]= *h->short_ref[i];\n            frame_list[0][index++].pic_id= h->short_ref[i]->frame_num;\n        }\n        short_len = index;\n        for(i = 0; i < 16; i++){\n            int sel;\n            if(h->long_ref[i] == NULL) continue;\n            sel = h->long_ref[i]->reference | structure_sel;\n            if(sel != PICT_FRAME) continue;\n            frame_list[0][index  ]= *h->long_ref[i];\n            frame_list[0][index++].pic_id= i;\n        }\n        if (FIELD_PICTURE)\n            index = split_field_ref_list(h->default_ref_list[0],\n                                         h->ref_count[0], frame_list[0],\n                                         index, s->picture_structure,\n                                         short_len);\n        if(index < h->ref_count[0])\n            memset(&h->default_ref_list[0][index], 0, sizeof(Picture)*(h->ref_count[0] - index));\n    }\n#ifdef TRACE\n    for (i=0; i<h->ref_count[0]; i++) {\n        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]);\n    }\n    if(h->slice_type==FF_B_TYPE){\n        for (i=0; i<h->ref_count[1]; i++) {\n            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]);\n        }\n    }\n#endif\n    return 0;\n}']