Revision 7e2eb4ba

View differences:

libavcodec/h264.c
715 715
    copy_fields(h, h1, short_ref, cabac_init_idc);
716 716

  
717 717
    copy_picture_range(h->short_ref,   h1->short_ref,   32, s, s1);
718
    copy_picture_range(h->long_ref,    h1->long_ref,    32,  s, s1);
718
    copy_picture_range(h->long_ref,    h1->long_ref,    32, s, s1);
719 719
    copy_picture_range(h->delayed_pic, h1->delayed_pic, MAX_DELAYED_PIC_COUNT+2, s, s1);
720 720

  
721 721
    h->last_slice_type = h1->last_slice_type;
......
930 930

  
931 931
    if(out_of_order || pics > s->avctx->has_b_frames){
932 932
        out->reference &= ~DELAYED_PIC_REF;
933
        out->owner2 = s; // for frame threading, the owner must be the second field's thread
934
                         // or else the first thread can release the picture and reuse it unsafely
933 935
        for(i=out_idx; h->delayed_pic[i]; i++)
934 936
            h->delayed_pic[i] = h->delayed_pic[i+1];
935 937
    }
......
2049 2051
            s0->first_field = FIELD_PICTURE;
2050 2052
        }
2051 2053

  
2052
        if((!FIELD_PICTURE || s0->first_field) && ff_h264_frame_start(h) < 0) {
2053
            s0->first_field = 0;
2054
            return -1;
2054
        if(!FIELD_PICTURE || s0->first_field) {
2055
            if (ff_h264_frame_start(h) < 0) {
2056
                s0->first_field = 0;
2057
                return -1;
2058
            }
2059
        } else {
2060
            ff_release_unused_pictures(s, 0);
2055 2061
        }
2056 2062
    }
2057 2063
    if(h != h0)
libavcodec/mpegvideo.c
316 316
    s->prev_pict_types[0]= s->dropable ? FF_B_TYPE : s->pict_type;
317 317
    if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == FF_B_TYPE)
318 318
        pic->age= INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2 and it is a bit tricky to skip them anyway.
319
    pic->owner2 = s;
319 320

  
320 321
    return 0;
321 322
fail: //for the FF_ALLOCZ_OR_GOTO macro
......
946 947
    }
947 948
}
948 949

  
950
void ff_release_unused_pictures(MpegEncContext *s, int remove_current)
951
{
952
    int i;
953

  
954
    /* release non reference frames */
955
    for(i=0; i<s->picture_count; i++){
956
        if(s->picture[i].data[0] && !s->picture[i].reference
957
           && s->picture[i].owner2 == s
958
           && (remove_current || &s->picture[i] != s->current_picture_ptr)
959
           /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
960
            free_frame_buffer(s, &s->picture[i]);
961
        }
962
    }
963
}
964

  
949 965
int ff_find_unused_picture(MpegEncContext *s, int shared){
950 966
    int i;
951 967

  
......
1025 1041
    }
1026 1042

  
1027 1043
    if(!s->encoding){
1028
        /* release non reference frames */
1029
        for(i=0; i<s->picture_count; i++){
1030
            if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
1031
                free_frame_buffer(s, &s->picture[i]);
1032
            }
1033
        }
1044
        ff_release_unused_pictures(s, 1);
1034 1045

  
1035 1046
        if(s->current_picture_ptr && s->current_picture_ptr->data[0]==NULL)
1036 1047
            pic= s->current_picture_ptr; //we already have a unused image (maybe it was set before reading the header)
libavcodec/mpegvideo.h
76 76
#define EXT_START_CODE          0x000001b5
77 77
#define USER_START_CODE         0x000001b2
78 78

  
79
struct MpegEncContext;
80

  
79 81
/**
80 82
 * Picture.
81 83
 */
......
132 134
    uint8_t *mb_mean;           ///< Table for MB luminance
133 135
    int32_t *mb_cmp_score;      ///< Table for MB cmp scores, for mb decision FIXME remove
134 136
    int b_frame_score;          /* */
137
    struct MpegEncContext *owner2; ///< pointer to the MpegEncContext that allocated this picture
135 138
} Picture;
136 139

  
137
struct MpegEncContext;
138

  
139 140
/**
140 141
 * Motion estimation context.
141 142
 */
......
712 713
void ff_mpeg_flush(AVCodecContext *avctx);
713 714
void ff_print_debug_info(MpegEncContext *s, AVFrame *pict);
714 715
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
716
void ff_release_unused_pictures(MpegEncContext *s, int remove_current);
715 717
int ff_find_unused_picture(MpegEncContext *s, int shared);
716 718
void ff_denoise_dct(MpegEncContext *s, DCTELEM *block);
717 719
void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);

Also available in: Unified diff