int cur_poc, list;
int lens[2];
- if(FIELD_PICTURE)
- cur_poc= h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD];
+ if (FIELD_PICTURE)
+ cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD];
else
- cur_poc= h->cur_pic_ptr->poc;
-
- for(list= 0; list<2; list++){
- len= add_sorted(sorted , h->short_ref, h->short_ref_count, cur_poc, 1^list);
- len+=add_sorted(sorted+len, h->short_ref, h->short_ref_count, cur_poc, 0^list);
- av_assert0(len<=32);
- len= build_def_list(h->default_ref_list[list] , sorted , len, 0, h->picture_structure);
- len+=build_def_list(h->default_ref_list[list]+len, h->long_ref, 16 , 1, h->picture_structure);
- av_assert0(len<=32);
-
- if(len < h->ref_count[list])
- memset(&h->default_ref_list[list][len], 0, sizeof(Picture)*(h->ref_count[list] - len));
- lens[list]= len;
+ cur_poc = h->cur_pic_ptr->poc;
+
+ for (list = 0; list < 2; list++) {
+ len = add_sorted(sorted, h->short_ref, h->short_ref_count, cur_poc, 1 ^ list);
+ len += add_sorted(sorted + len, h->short_ref, h->short_ref_count, cur_poc, 0 ^ list);
- assert(len <= 32);
++ av_assert0(len <= 32);
+ len = build_def_list(h->default_ref_list[list], sorted, len, 0, h->picture_structure);
+ len += build_def_list(h->default_ref_list[list] + len, h->long_ref, 16, 1, h->picture_structure);
- assert(len <= 32);
++ av_assert0(len <= 32);
+
+ if (len < h->ref_count[list])
+ memset(&h->default_ref_list[list][len], 0, sizeof(Picture) * (h->ref_count[list] - len));
+ lens[list] = len;
}
- if(lens[0] == lens[1] && lens[1] > 1){
+ if (lens[0] == lens[1] && lens[1] > 1) {
for (i = 0; h->default_ref_list[0][i].f.data[0] == h->default_ref_list[1][i].f.data[0] && i < lens[0]; i++);
if (i == lens[0]) {
Picture tmp;
COPY_PICTURE(&h->default_ref_list[1][1], &tmp);
}
}
- }else{
- len = build_def_list(h->default_ref_list[0] , h->short_ref, h->short_ref_count, 0, h->picture_structure);
- len+= build_def_list(h->default_ref_list[0]+len, h-> long_ref, 16 , 1, h->picture_structure);
- av_assert0(len<=32);
- if(len < h->ref_count[0])
- memset(&h->default_ref_list[0][len], 0, sizeof(Picture)*(h->ref_count[0] - len));
+ } else {
+ len = build_def_list(h->default_ref_list[0], h->short_ref, h->short_ref_count, 0, h->picture_structure);
+ len += build_def_list(h->default_ref_list[0] + len, h-> long_ref, 16, 1, h->picture_structure);
- assert(len <= 32);
++ av_assert0(len <= 32);
+ if (len < h->ref_count[0])
+ memset(&h->default_ref_list[0][len], 0, sizeof(Picture) * (h->ref_count[0] - len));
}
#ifdef TRACE
- for (i=0; i<h->ref_count[0]; i++) {
- tprintf(h->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].f.data[0]);
+ for (i = 0; i < h->ref_count[0]; i++) {
+ tprintf(h->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].f.data[0]);
}
- if(h->slice_type_nos==AV_PICTURE_TYPE_B){
- for (i=0; i<h->ref_count[1]; i++) {
- tprintf(h->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].f.data[0]);
+ if (h->slice_type_nos == AV_PICTURE_TYPE_B) {
+ for (i = 0; i < h->ref_count[1]; i++) {
+ tprintf(h->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].f.data[0]);
}
}
#endif
}
}
}
- for(list=0; list<h->list_count; list++){
- for(index= 0; index < h->ref_count[list]; index++){
+ for (list = 0; list < h->list_count; list++) {
+ for (index = 0; index < h->ref_count[list]; index++) {
- if (!h->ref_list[list][index].f.data[0]) {
- av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture\n");
- if (h->default_ref_list[list][0].f.data[0])
+ if ( !h->ref_list[list][index].f.data[0]
+ || (!FIELD_PICTURE && (h->ref_list[list][index].reference&3) != 3)) {
+ int i;
+ av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture, default is %d\n", h->default_ref_list[list][0].poc);
- for (i=0; i<FF_ARRAY_ELEMS(h->last_pocs); i++)
++ for (i = 0; i < FF_ARRAY_ELEMS(h->last_pocs); i++)
+ h->last_pocs[i] = INT_MIN;
+ if (h->default_ref_list[list][0].f.data[0]
+ && !(!FIELD_PICTURE && (h->default_ref_list[list][index].reference&3) != 3))
COPY_PICTURE(&h->ref_list[list][index], &h->default_ref_list[list][0]);
else
return -1;
return 0;
}
- void ff_h264_fill_mbaff_ref_list(H264Context *h){
+ void ff_h264_fill_mbaff_ref_list(H264Context *h)
+ {
int list, i, j;
- for(list=0; list<h->list_count; list++){
- for(i=0; i<h->ref_count[list]; i++){
- for (list = 0; list < 2; list++) { //FIXME try list_count
++ for (list = 0; list < h->list_count; list++) {
+ for (i = 0; i < h->ref_count[list]; i++) {
Picture *frame = &h->ref_list[list][i];
- Picture *field = &h->ref_list[list][16+2*i];
+ Picture *field = &h->ref_list[list][16 + 2 * i];
COPY_PICTURE(field, frame);
- for(j=0; j<3; j++)
+ for (j = 0; j < 3; j++)
field[0].f.linesize[j] <<= 1;
field[0].reference = PICT_TOP_FIELD;
- field[0].poc= field[0].field_poc[0];
+ field[0].poc = field[0].field_poc[0];
COPY_PICTURE(field + 1, field);
- for(j=0; j<3; j++)
+ for (j = 0; j < 3; j++)
field[1].f.data[j] += frame->f.linesize[j];
field[1].reference = PICT_BOTTOM_FIELD;
- field[1].poc= field[1].field_poc[1];
+ field[1].poc = field[1].field_poc[1];
- h->luma_weight[16+2*i][list][0] = h->luma_weight[16+2*i+1][list][0] = h->luma_weight[i][list][0];
- h->luma_weight[16+2*i][list][1] = h->luma_weight[16+2*i+1][list][1] = h->luma_weight[i][list][1];
- for(j=0; j<2; j++){
- h->chroma_weight[16+2*i][list][j][0] = h->chroma_weight[16+2*i+1][list][j][0] = h->chroma_weight[i][list][j][0];
- h->chroma_weight[16+2*i][list][j][1] = h->chroma_weight[16+2*i+1][list][j][1] = h->chroma_weight[i][list][j][1];
+ h->luma_weight[16 + 2 * i][list][0] = h->luma_weight[16 + 2 * i + 1][list][0] = h->luma_weight[i][list][0];
+ h->luma_weight[16 + 2 * i][list][1] = h->luma_weight[16 + 2 * i + 1][list][1] = h->luma_weight[i][list][1];
+ for (j = 0; j < 2; j++) {
+ h->chroma_weight[16 + 2 * i][list][j][0] = h->chroma_weight[16 + 2 * i + 1][list][j][0] = h->chroma_weight[i][list][j][0];
+ h->chroma_weight[16 + 2 * i][list][j][1] = h->chroma_weight[16 + 2 * i + 1][list][j][1] = h->chroma_weight[i][list][j][1];
}
}
}
return pic;
}
- void ff_h264_remove_all_refs(H264Context *h){
+ void ff_h264_remove_all_refs(H264Context *h)
+ {
int i;
- for(i=0; i<16; i++){
+ for (i = 0; i < 16; i++) {
remove_long(h, i, 0);
}
- assert(h->long_ref_count==0);
+ assert(h->long_ref_count == 0);
- for(i=0; i<h->short_ref_count; i++){
+ for (i = 0; i < h->short_ref_count; i++) {
unreference_pic(h, h->short_ref[i], 0);
- h->short_ref[i]= NULL;
+ h->short_ref[i] = NULL;
}
- h->short_ref_count=0;
+ h->short_ref_count = 0;
+
+ memset(h->default_ref_list, 0, sizeof(h->default_ref_list));
+ memset(h->ref_list, 0, sizeof(h->ref_list));
}
/**
MMCO mmco_temp[MAX_MMCO_COUNT], *mmco = first_slice ? h->mmco : mmco_temp;
int mmco_index = 0, i;
- assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count);
-
if (h->short_ref_count &&
- h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count &&
+ h->long_ref_count + h->short_ref_count >= h->sps.ref_frame_count &&
!(FIELD_PICTURE && !h->first_field && h->cur_pic_ptr->reference)) {
- mmco[0].opcode = MMCO_SHORT2UNUSED;
+ mmco[0].opcode = MMCO_SHORT2UNUSED;
mmco[0].short_pic_num = h->short_ref[h->short_ref_count - 1]->frame_num;
- mmco_index = 1;
+ mmco_index = 1;
if (FIELD_PICTURE) {
mmco[0].short_pic_num *= 2;
- mmco[1].opcode = MMCO_SHORT2UNUSED;
- mmco[1].short_pic_num = mmco[0].short_pic_num + 1;
- mmco_index = 2;
+ mmco[1].opcode = MMCO_SHORT2UNUSED;
+ mmco[1].short_pic_num = mmco[0].short_pic_num + 1;
+ mmco_index = 2;
}
}
}
break;
case MMCO_RESET:
- while(h->short_ref_count){
+ while (h->short_ref_count) {
remove_short(h, h->short_ref[0]->frame_num, 0);
}
- for(j = 0; j < 16; j++) {
+ for (j = 0; j < 16; j++) {
remove_long(h, j, 0);
}
- h->frame_num=
- h->cur_pic_ptr->frame_num= 0;
+ h->frame_num = h->cur_pic_ptr->frame_num = 0;
h->mmco_reset = 1;
- h->cur_pic_ptr->mmco_reset=1;
+ h->cur_pic_ptr->mmco_reset = 1;
+ for (j = 0; j < MAX_DELAYED_PIC_COUNT; j++)
+ h->last_pocs[j] = INT_MIN;
break;
default: assert(0);
}
}
}
- if (h->long_ref_count + h->short_ref_count > FFMAX(h->sps.ref_frame_count, 1)){
- if (h->long_ref_count + h->short_ref_count -
- (h->short_ref[0] == h->cur_pic_ptr) > h->sps.ref_frame_count) {
++ if (h->long_ref_count + h->short_ref_count > FFMAX(h->sps.ref_frame_count, 1)) {
/* We have too many reference frames, probably due to corrupted
* stream. Need to discard one frame. Prevents overrun of the