Revision d31dbec3

View differences:

libavcodec/dnxhdenc.c
55 55
    int i, j, level, run;
56 56
    int max_level = 1<<(ctx->cid_table->bit_depth+2);
57 57

  
58
    CHECKED_ALLOCZ(ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes));
59
    CHECKED_ALLOCZ(ctx->vlc_bits,  max_level*4*sizeof(*ctx->vlc_bits));
60
    CHECKED_ALLOCZ(ctx->run_codes, 63*2);
61
    CHECKED_ALLOCZ(ctx->run_bits,    63);
58
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes), fail);
59
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits , max_level*4*sizeof(*ctx->vlc_bits ), fail);
60
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes, 63*2                               , fail);
61
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits , 63                                 , fail);
62 62

  
63 63
    ctx->vlc_codes += max_level*2;
64 64
    ctx->vlc_bits  += max_level*2;
......
111 111
    uint16_t weight_matrix[64] = {1,}; // convert_matrix needs uint16_t*
112 112
    int qscale, i;
113 113

  
114
    CHECKED_ALLOCZ(ctx->qmatrix_l,   (ctx->m.avctx->qmax+1) * 64 * sizeof(int));
115
    CHECKED_ALLOCZ(ctx->qmatrix_c,   (ctx->m.avctx->qmax+1) * 64 * sizeof(int));
116
    CHECKED_ALLOCZ(ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t));
117
    CHECKED_ALLOCZ(ctx->qmatrix_c16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t));
114
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l,   (ctx->m.avctx->qmax+1) * 64 *     sizeof(int)     , fail);
115
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c,   (ctx->m.avctx->qmax+1) * 64 *     sizeof(int)     , fail);
116
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t), fail);
117
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t), fail);
118 118

  
119 119
    for (i = 1; i < 64; i++) {
120 120
        int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]];
......
142 142

  
143 143
static int dnxhd_init_rc(DNXHDEncContext *ctx)
144 144
{
145
    CHECKED_ALLOCZ(ctx->mb_rc, 8160*ctx->m.avctx->qmax*sizeof(RCEntry));
145
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_rc, 8160*ctx->m.avctx->qmax*sizeof(RCEntry), fail);
146 146
    if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD)
147
        CHECKED_ALLOCZ(ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry));
147
        FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry), fail);
148 148

  
149 149
    ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8;
150 150
    ctx->qscale = 1;
......
203 203
    if (dnxhd_init_rc(ctx) < 0)
204 204
        return -1;
205 205

  
206
    CHECKED_ALLOCZ(ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t));
207
    CHECKED_ALLOCZ(ctx->mb_bits,    ctx->m.mb_num   *sizeof(uint16_t));
208
    CHECKED_ALLOCZ(ctx->mb_qscale,  ctx->m.mb_num   *sizeof(uint8_t));
206
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t), fail);
207
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_bits,    ctx->m.mb_num   *sizeof(uint16_t), fail);
208
    FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_qscale,  ctx->m.mb_num   *sizeof(uint8_t) , fail);
209 209

  
210 210
    ctx->frame.key_frame = 1;
211 211
    ctx->frame.pict_type = FF_I_TYPE;
......
228 228
    }
229 229

  
230 230
    return 0;
231
 fail: //for CHECKED_ALLOCZ
231
 fail: //for FF_ALLOCZ_OR_GOTO
232 232
    return -1;
233 233
}
234 234

  
libavcodec/h264.c
2077 2077
    const int big_mb_num= s->mb_stride * (s->mb_height+1);
2078 2078
    int x,y;
2079 2079

  
2080
    CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8  * sizeof(uint8_t))
2080
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->intra4x4_pred_mode, big_mb_num * 8  * sizeof(uint8_t), fail)
2081 2081

  
2082
    CHECKED_ALLOCZ(h->non_zero_count    , big_mb_num * 16 * sizeof(uint8_t))
2083
    CHECKED_ALLOCZ(h->slice_table_base  , (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base))
2084
    CHECKED_ALLOCZ(h->cbp_table, big_mb_num * sizeof(uint16_t))
2082
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->non_zero_count    , big_mb_num * 16 * sizeof(uint8_t), fail)
2083
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->slice_table_base  , (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base), fail)
2084
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->cbp_table, big_mb_num * sizeof(uint16_t), fail)
2085 2085

  
2086
    CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t))
2087
    CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t));
2088
    CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t));
2089
    CHECKED_ALLOCZ(h->direct_table, 32*big_mb_num * sizeof(uint8_t));
2086
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t), fail)
2087
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t), fail);
2088
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t), fail);
2089
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->direct_table, 32*big_mb_num * sizeof(uint8_t) , fail);
2090 2090

  
2091 2091
    memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride)  * sizeof(*h->slice_table_base));
2092 2092
    h->slice_table= h->slice_table_base + s->mb_stride*2 + 1;
2093 2093

  
2094
    CHECKED_ALLOCZ(h->mb2b_xy  , big_mb_num * sizeof(uint32_t));
2095
    CHECKED_ALLOCZ(h->mb2b8_xy , big_mb_num * sizeof(uint32_t));
2094
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2b_xy  , big_mb_num * sizeof(uint32_t), fail);
2095
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2b8_xy , big_mb_num * sizeof(uint32_t), fail);
2096 2096
    for(y=0; y<s->mb_height; y++){
2097 2097
        for(x=0; x<s->mb_width; x++){
2098 2098
            const int mb_xy= x + y*s->mb_stride;
......
2139 2139
 * Allocate buffers which are not shared amongst multiple threads.
2140 2140
 */
2141 2141
static int context_init(H264Context *h){
2142
    CHECKED_ALLOCZ(h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t))
2143
    CHECKED_ALLOCZ(h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t))
2142
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail)
2143
    FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail)
2144 2144

  
2145 2145
    return 0;
2146 2146
fail:
libavcodec/mpegvideo.c
243 243

  
244 244
    if(pic->qscale_table==NULL){
245 245
        if (s->encoding) {
246
            CHECKED_ALLOCZ(pic->mb_var   , mb_array_size * sizeof(int16_t))
247
            CHECKED_ALLOCZ(pic->mc_mb_var, mb_array_size * sizeof(int16_t))
248
            CHECKED_ALLOCZ(pic->mb_mean  , mb_array_size * sizeof(int8_t))
246
            FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_var   , mb_array_size * sizeof(int16_t)  , fail)
247
            FF_ALLOCZ_OR_GOTO(s->avctx, pic->mc_mb_var, mb_array_size * sizeof(int16_t)  , fail)
248
            FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_mean  , mb_array_size * sizeof(int8_t )  , fail)
249 249
        }
250 250

  
251
        CHECKED_ALLOCZ(pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2) //the +2 is for the slice end check
252
        CHECKED_ALLOCZ(pic->qscale_table , mb_array_size * sizeof(uint8_t))
253
        CHECKED_ALLOCZ(pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t))
251
        FF_ALLOCZ_OR_GOTO(s->avctx, pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2, fail) //the +2 is for the slice end check
252
        FF_ALLOCZ_OR_GOTO(s->avctx, pic->qscale_table , mb_array_size * sizeof(uint8_t)  , fail)
253
        FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t), fail)
254 254
        pic->mb_type= pic->mb_type_base + 2*s->mb_stride+1;
255 255
        if(s->out_format == FMT_H264){
256 256
            for(i=0; i<2; i++){
257
                CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b4_array_size+4)  * sizeof(int16_t))
257
                FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b4_array_size+4)  * sizeof(int16_t), fail)
258 258
                pic->motion_val[i]= pic->motion_val_base[i]+4;
259
                CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t))
259
                FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], b8_array_size * sizeof(uint8_t), fail)
260 260
            }
261 261
            pic->motion_subsample_log2= 2;
262 262
        }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){
263 263
            for(i=0; i<2; i++){
264
                CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+4) * sizeof(int16_t))
264
                FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b8_array_size+4) * sizeof(int16_t), fail)
265 265
                pic->motion_val[i]= pic->motion_val_base[i]+4;
266
                CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t))
266
                FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], b8_array_size * sizeof(uint8_t), fail)
267 267
            }
268 268
            pic->motion_subsample_log2= 3;
269 269
        }
270 270
        if(s->avctx->debug&FF_DEBUG_DCT_COEFF) {
271
            CHECKED_ALLOCZ(pic->dct_coeff, 64 * mb_array_size * sizeof(DCTELEM)*6)
271
            FF_ALLOCZ_OR_GOTO(s->avctx, pic->dct_coeff, 64 * mb_array_size * sizeof(DCTELEM)*6, fail)
272 272
        }
273 273
        pic->qstride= s->mb_stride;
274
        CHECKED_ALLOCZ(pic->pan_scan , 1 * sizeof(AVPanScan))
274
        FF_ALLOCZ_OR_GOTO(s->avctx, pic->pan_scan , 1 * sizeof(AVPanScan), fail)
275 275
    }
276 276

  
277 277
    /* It might be nicer if the application would keep track of these
......
282 282
        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.
283 283

  
284 284
    return 0;
285
fail: //for the CHECKED_ALLOCZ macro
285
fail: //for the FF_ALLOCZ_OR_GOTO macro
286 286
    if(r>=0)
287 287
        free_frame_buffer(s, pic);
288 288
    return -1;
......
325 325
    int i;
326 326

  
327 327
    // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264)
328
    CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*21*2); //(width + edge + align)*interlaced*MBsize*tolerance
328
    FF_ALLOCZ_OR_GOTO(s->avctx, s->allocated_edge_emu_buffer, (s->width+64)*2*21*2, fail); //(width + edge + align)*interlaced*MBsize*tolerance
329 329
    s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21;
330 330

  
331 331
     //FIXME should be linesize instead of s->width*2 but that is not known before get_buffer()
332
    CHECKED_ALLOCZ(s->me.scratchpad,  (s->width+64)*4*16*2*sizeof(uint8_t))
332
    FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad,  (s->width+64)*4*16*2*sizeof(uint8_t), fail)
333 333
    s->me.temp=         s->me.scratchpad;
334 334
    s->rd_scratchpad=   s->me.scratchpad;
335 335
    s->b_scratchpad=    s->me.scratchpad;
336 336
    s->obmc_scratchpad= s->me.scratchpad + 16;
337 337
    if (s->encoding) {
338
        CHECKED_ALLOCZ(s->me.map      , ME_MAP_SIZE*sizeof(uint32_t))
339
        CHECKED_ALLOCZ(s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t))
338
        FF_ALLOCZ_OR_GOTO(s->avctx, s->me.map      , ME_MAP_SIZE*sizeof(uint32_t), fail)
339
        FF_ALLOCZ_OR_GOTO(s->avctx, s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t), fail)
340 340
        if(s->avctx->noise_reduction){
341
            CHECKED_ALLOCZ(s->dct_error_sum, 2 * 64 * sizeof(int))
341
            FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_error_sum, 2 * 64 * sizeof(int), fail)
342 342
        }
343 343
    }
344
    CHECKED_ALLOCZ(s->blocks, 64*12*2 * sizeof(DCTELEM))
344
    FF_ALLOCZ_OR_GOTO(s->avctx, s->blocks, 64*12*2 * sizeof(DCTELEM), fail)
345 345
    s->block= s->blocks[0];
346 346

  
347 347
    for(i=0;i<12;i++){
......
509 509

  
510 510
    s->avctx->coded_frame= (AVFrame*)&s->current_picture;
511 511

  
512
    CHECKED_ALLOCZ(s->mb_index2xy, (s->mb_num+1)*sizeof(int)) //error ressilience code looks cleaner with this
512
    FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num+1)*sizeof(int), fail) //error ressilience code looks cleaner with this
513 513
    for(y=0; y<s->mb_height; y++){
514 514
        for(x=0; x<s->mb_width; x++){
515 515
            s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride;
......
519 519

  
520 520
    if (s->encoding) {
521 521
        /* Allocate MV tables */
522
        CHECKED_ALLOCZ(s->p_mv_table_base            , mv_table_size * 2 * sizeof(int16_t))
523
        CHECKED_ALLOCZ(s->b_forw_mv_table_base       , mv_table_size * 2 * sizeof(int16_t))
524
        CHECKED_ALLOCZ(s->b_back_mv_table_base       , mv_table_size * 2 * sizeof(int16_t))
525
        CHECKED_ALLOCZ(s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t))
526
        CHECKED_ALLOCZ(s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t))
527
        CHECKED_ALLOCZ(s->b_direct_mv_table_base     , mv_table_size * 2 * sizeof(int16_t))
522
        FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base            , mv_table_size * 2 * sizeof(int16_t), fail)
523
        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base       , mv_table_size * 2 * sizeof(int16_t), fail)
524
        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base       , mv_table_size * 2 * sizeof(int16_t), fail)
525
        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
526
        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
527
        FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base     , mv_table_size * 2 * sizeof(int16_t), fail)
528 528
        s->p_mv_table           = s->p_mv_table_base            + s->mb_stride + 1;
529 529
        s->b_forw_mv_table      = s->b_forw_mv_table_base       + s->mb_stride + 1;
530 530
        s->b_back_mv_table      = s->b_back_mv_table_base       + s->mb_stride + 1;
......
533 533
        s->b_direct_mv_table    = s->b_direct_mv_table_base     + s->mb_stride + 1;
534 534

  
535 535
        if(s->msmpeg4_version){
536
            CHECKED_ALLOCZ(s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int));
536
            FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int), fail);
537 537
        }
538
        CHECKED_ALLOCZ(s->avctx->stats_out, 256);
538
        FF_ALLOCZ_OR_GOTO(s->avctx, s->avctx->stats_out, 256, fail);
539 539

  
540 540
        /* Allocate MB type table */
541
        CHECKED_ALLOCZ(s->mb_type  , mb_array_size * sizeof(uint16_t)) //needed for encoding
541
        FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type  , mb_array_size * sizeof(uint16_t), fail) //needed for encoding
542 542

  
543
        CHECKED_ALLOCZ(s->lambda_table, mb_array_size * sizeof(int))
543
        FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size * sizeof(int), fail)
544 544

  
545
        CHECKED_ALLOCZ(s->q_intra_matrix, 64*32 * sizeof(int))
546
        CHECKED_ALLOCZ(s->q_inter_matrix, 64*32 * sizeof(int))
547
        CHECKED_ALLOCZ(s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t))
548
        CHECKED_ALLOCZ(s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t))
549
        CHECKED_ALLOCZ(s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*))
550
        CHECKED_ALLOCZ(s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*))
545
        FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix  , 64*32   * sizeof(int), fail)
546
        FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix  , 64*32   * sizeof(int), fail)
547
        FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t), fail)
548
        FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t), fail)
549
        FF_ALLOCZ_OR_GOTO(s->avctx, s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail)
550
        FF_ALLOCZ_OR_GOTO(s->avctx, s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail)
551 551

  
552 552
        if(s->avctx->noise_reduction){
553
            CHECKED_ALLOCZ(s->dct_offset, 2 * 64 * sizeof(uint16_t))
553
            FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail)
554 554
        }
555 555
    }
556
    CHECKED_ALLOCZ(s->picture, MAX_PICTURE_COUNT * sizeof(Picture))
556
    FF_ALLOCZ_OR_GOTO(s->avctx, s->picture, MAX_PICTURE_COUNT * sizeof(Picture), fail)
557 557
    for(i = 0; i < MAX_PICTURE_COUNT; i++) {
558 558
        avcodec_get_frame_defaults((AVFrame *)&s->picture[i]);
559 559
    }
560 560

  
561
    CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t))
561
    FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, mb_array_size*sizeof(uint8_t), fail)
562 562

  
563 563
    if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){
564 564
        /* interlaced direct mode decoding tables */
......
566 566
                int j, k;
567 567
                for(j=0; j<2; j++){
568 568
                    for(k=0; k<2; k++){
569
                        CHECKED_ALLOCZ(s->b_field_mv_table_base[i][j][k]     , mv_table_size * 2 * sizeof(int16_t))
570
                        s->b_field_mv_table[i][j][k]    = s->b_field_mv_table_base[i][j][k]     + s->mb_stride + 1;
569
                        FF_ALLOCZ_OR_GOTO(s->avctx,    s->b_field_mv_table_base[i][j][k], mv_table_size * 2 * sizeof(int16_t), fail)
570
                        s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] + s->mb_stride + 1;
571 571
                    }
572
                    CHECKED_ALLOCZ(s->b_field_select_table[i][j]     , mb_array_size * 2 * sizeof(uint8_t))
573
                    CHECKED_ALLOCZ(s->p_field_mv_table_base[i][j]     , mv_table_size * 2 * sizeof(int16_t))
574
                    s->p_field_mv_table[i][j]    = s->p_field_mv_table_base[i][j]     + s->mb_stride + 1;
572
                    FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_select_table [i][j], mb_array_size * 2 * sizeof(uint8_t), fail)
573
                    FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_mv_table_base[i][j], mv_table_size * 2 * sizeof(int16_t), fail)
574
                    s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j]+ s->mb_stride + 1;
575 575
                }
576
                CHECKED_ALLOCZ(s->p_field_select_table[i]      , mb_array_size * 2 * sizeof(uint8_t))
576
                FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_select_table[i], mb_array_size * 2 * sizeof(uint8_t), fail)
577 577
            }
578 578
    }
579 579
    if (s->out_format == FMT_H263) {
580 580
        /* ac values */
581
        CHECKED_ALLOCZ(s->ac_val_base, yc_size * sizeof(int16_t) * 16);
581
        FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, yc_size * sizeof(int16_t) * 16, fail);
582 582
        s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;
583 583
        s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;
584 584
        s->ac_val[2] = s->ac_val[1] + c_size;
585 585

  
586 586
        /* cbp values */
587
        CHECKED_ALLOCZ(s->coded_block_base, y_size);
587
        FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail);
588 588
        s->coded_block= s->coded_block_base + s->b8_stride + 1;
589 589

  
590 590
        /* cbp, ac_pred, pred_dir */
591
        CHECKED_ALLOCZ(s->cbp_table  , mb_array_size * sizeof(uint8_t))
592
        CHECKED_ALLOCZ(s->pred_dir_table, mb_array_size * sizeof(uint8_t))
591
        FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table     , mb_array_size * sizeof(uint8_t), fail)
592
        FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table, mb_array_size * sizeof(uint8_t), fail)
593 593
    }
594 594

  
595 595
    if (s->h263_pred || s->h263_plus || !s->encoding) {
596 596
        /* dc values */
597 597
        //MN: we need these for error resilience of intra-frames
598
        CHECKED_ALLOCZ(s->dc_val_base, yc_size * sizeof(int16_t));
598
        FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base, yc_size * sizeof(int16_t), fail);
599 599
        s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
600 600
        s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
601 601
        s->dc_val[2] = s->dc_val[1] + c_size;
......
604 604
    }
605 605

  
606 606
    /* which mb is a intra block */
607
    CHECKED_ALLOCZ(s->mbintra_table, mb_array_size);
607
    FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail);
608 608
    memset(s->mbintra_table, 1, mb_array_size);
609 609

  
610 610
    /* init macroblock skip table */
611
    CHECKED_ALLOCZ(s->mbskip_table, mb_array_size+2);
611
    FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size+2, fail);
612 612
    //Note the +1 is for a quicker mpeg4 slice_end detection
613
    CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE);
613
    FF_ALLOCZ_OR_GOTO(s->avctx, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE, fail);
614 614

  
615 615
    s->parse_context.state= -1;
616 616
    if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){
libavutil/internal.h
249 249
#define perror please_use_av_log_instead_of_perror
250 250
#endif
251 251

  
252
#define CHECKED_ALLOC(p, size)\
252
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
253 253
{\
254 254
    p = av_malloc(size);\
255 255
    if (p == NULL && (size) != 0) {\
256
        av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.\n");\
257
        goto fail;\
256
        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
257
        goto label;\
258 258
    }\
259 259
}
260 260

  
261
#define CHECKED_ALLOCZ(p, size)\
261
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
262 262
{\
263 263
    p = av_mallocz(size);\
264 264
    if (p == NULL && (size) != 0) {\
265
        av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.\n");\
266
        goto fail;\
265
        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
266
        goto label;\
267 267
    }\
268 268
}
269 269

  

Also available in: Unified diff