Commit d31dbec3 authored by Ramiro Polla's avatar Ramiro Polla

Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label

parameters.

Originally committed as revision 19776 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 9cf484d0
...@@ -55,10 +55,10 @@ static int dnxhd_init_vlc(DNXHDEncContext *ctx) ...@@ -55,10 +55,10 @@ static int dnxhd_init_vlc(DNXHDEncContext *ctx)
int i, j, level, run; int i, j, level, run;
int max_level = 1<<(ctx->cid_table->bit_depth+2); int max_level = 1<<(ctx->cid_table->bit_depth+2);
CHECKED_ALLOCZ(ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes)); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes), fail);
CHECKED_ALLOCZ(ctx->vlc_bits, max_level*4*sizeof(*ctx->vlc_bits)); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits , max_level*4*sizeof(*ctx->vlc_bits ), fail);
CHECKED_ALLOCZ(ctx->run_codes, 63*2); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes, 63*2 , fail);
CHECKED_ALLOCZ(ctx->run_bits, 63); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits , 63 , fail);
ctx->vlc_codes += max_level*2; ctx->vlc_codes += max_level*2;
ctx->vlc_bits += max_level*2; ctx->vlc_bits += max_level*2;
...@@ -111,10 +111,10 @@ static int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias) ...@@ -111,10 +111,10 @@ static int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias)
uint16_t weight_matrix[64] = {1,}; // convert_matrix needs uint16_t* uint16_t weight_matrix[64] = {1,}; // convert_matrix needs uint16_t*
int qscale, i; int qscale, i;
CHECKED_ALLOCZ(ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int)); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int) , fail);
CHECKED_ALLOCZ(ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int)); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int) , fail);
CHECKED_ALLOCZ(ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t)); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t), fail);
CHECKED_ALLOCZ(ctx->qmatrix_c16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t)); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t), fail);
for (i = 1; i < 64; i++) { for (i = 1; i < 64; i++) {
int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]]; int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]];
...@@ -142,9 +142,9 @@ static int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias) ...@@ -142,9 +142,9 @@ static int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias)
static int dnxhd_init_rc(DNXHDEncContext *ctx) static int dnxhd_init_rc(DNXHDEncContext *ctx)
{ {
CHECKED_ALLOCZ(ctx->mb_rc, 8160*ctx->m.avctx->qmax*sizeof(RCEntry)); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_rc, 8160*ctx->m.avctx->qmax*sizeof(RCEntry), fail);
if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD)
CHECKED_ALLOCZ(ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry)); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry), fail);
ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8; ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8;
ctx->qscale = 1; ctx->qscale = 1;
...@@ -203,9 +203,9 @@ static int dnxhd_encode_init(AVCodecContext *avctx) ...@@ -203,9 +203,9 @@ static int dnxhd_encode_init(AVCodecContext *avctx)
if (dnxhd_init_rc(ctx) < 0) if (dnxhd_init_rc(ctx) < 0)
return -1; return -1;
CHECKED_ALLOCZ(ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t)); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t), fail);
CHECKED_ALLOCZ(ctx->mb_bits, ctx->m.mb_num *sizeof(uint16_t)); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_bits, ctx->m.mb_num *sizeof(uint16_t), fail);
CHECKED_ALLOCZ(ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t)); FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t) , fail);
ctx->frame.key_frame = 1; ctx->frame.key_frame = 1;
ctx->frame.pict_type = FF_I_TYPE; ctx->frame.pict_type = FF_I_TYPE;
...@@ -228,7 +228,7 @@ static int dnxhd_encode_init(AVCodecContext *avctx) ...@@ -228,7 +228,7 @@ static int dnxhd_encode_init(AVCodecContext *avctx)
} }
return 0; return 0;
fail: //for CHECKED_ALLOCZ fail: //for FF_ALLOCZ_OR_GOTO
return -1; return -1;
} }
......
...@@ -2077,22 +2077,22 @@ static int alloc_tables(H264Context *h){ ...@@ -2077,22 +2077,22 @@ static int alloc_tables(H264Context *h){
const int big_mb_num= s->mb_stride * (s->mb_height+1); const int big_mb_num= s->mb_stride * (s->mb_height+1);
int x,y; int x,y;
CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(h->s.avctx, h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t), fail)
CHECKED_ALLOCZ(h->non_zero_count , big_mb_num * 16 * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(h->s.avctx, h->non_zero_count , big_mb_num * 16 * sizeof(uint8_t), fail)
CHECKED_ALLOCZ(h->slice_table_base , (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base)) FF_ALLOCZ_OR_GOTO(h->s.avctx, h->slice_table_base , (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base), fail)
CHECKED_ALLOCZ(h->cbp_table, big_mb_num * sizeof(uint16_t)) FF_ALLOCZ_OR_GOTO(h->s.avctx, h->cbp_table, big_mb_num * sizeof(uint16_t), fail)
CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(h->s.avctx, h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t), fail)
CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t)); FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t), fail);
CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t)); FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t), fail);
CHECKED_ALLOCZ(h->direct_table, 32*big_mb_num * sizeof(uint8_t)); FF_ALLOCZ_OR_GOTO(h->s.avctx, h->direct_table, 32*big_mb_num * sizeof(uint8_t) , fail);
memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base)); memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base));
h->slice_table= h->slice_table_base + s->mb_stride*2 + 1; h->slice_table= h->slice_table_base + s->mb_stride*2 + 1;
CHECKED_ALLOCZ(h->mb2b_xy , big_mb_num * sizeof(uint32_t)); FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2b_xy , big_mb_num * sizeof(uint32_t), fail);
CHECKED_ALLOCZ(h->mb2b8_xy , big_mb_num * sizeof(uint32_t)); FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2b8_xy , big_mb_num * sizeof(uint32_t), fail);
for(y=0; y<s->mb_height; y++){ for(y=0; y<s->mb_height; y++){
for(x=0; x<s->mb_width; x++){ for(x=0; x<s->mb_width; x++){
const int mb_xy= x + y*s->mb_stride; const int mb_xy= x + y*s->mb_stride;
...@@ -2139,8 +2139,8 @@ static void clone_tables(H264Context *dst, H264Context *src){ ...@@ -2139,8 +2139,8 @@ static void clone_tables(H264Context *dst, H264Context *src){
* Allocate buffers which are not shared amongst multiple threads. * Allocate buffers which are not shared amongst multiple threads.
*/ */
static int context_init(H264Context *h){ static int context_init(H264Context *h){
CHECKED_ALLOCZ(h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail)
CHECKED_ALLOCZ(h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail)
return 0; return 0;
fail: fail:
......
...@@ -243,35 +243,35 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){ ...@@ -243,35 +243,35 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){
if(pic->qscale_table==NULL){ if(pic->qscale_table==NULL){
if (s->encoding) { if (s->encoding) {
CHECKED_ALLOCZ(pic->mb_var , mb_array_size * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_var , mb_array_size * sizeof(int16_t) , fail)
CHECKED_ALLOCZ(pic->mc_mb_var, mb_array_size * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, pic->mc_mb_var, mb_array_size * sizeof(int16_t) , fail)
CHECKED_ALLOCZ(pic->mb_mean , mb_array_size * sizeof(int8_t)) FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_mean , mb_array_size * sizeof(int8_t ) , fail)
} }
CHECKED_ALLOCZ(pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2) //the +2 is for the slice end check 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
CHECKED_ALLOCZ(pic->qscale_table , mb_array_size * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(s->avctx, pic->qscale_table , mb_array_size * sizeof(uint8_t) , fail)
CHECKED_ALLOCZ(pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t)) FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t), fail)
pic->mb_type= pic->mb_type_base + 2*s->mb_stride+1; pic->mb_type= pic->mb_type_base + 2*s->mb_stride+1;
if(s->out_format == FMT_H264){ if(s->out_format == FMT_H264){
for(i=0; i<2; i++){ for(i=0; i<2; i++){
CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b4_array_size+4) * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b4_array_size+4) * sizeof(int16_t), fail)
pic->motion_val[i]= pic->motion_val_base[i]+4; pic->motion_val[i]= pic->motion_val_base[i]+4;
CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], b8_array_size * sizeof(uint8_t), fail)
} }
pic->motion_subsample_log2= 2; pic->motion_subsample_log2= 2;
}else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){ }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){
for(i=0; i<2; i++){ for(i=0; i<2; i++){
CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+4) * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b8_array_size+4) * sizeof(int16_t), fail)
pic->motion_val[i]= pic->motion_val_base[i]+4; pic->motion_val[i]= pic->motion_val_base[i]+4;
CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], b8_array_size * sizeof(uint8_t), fail)
} }
pic->motion_subsample_log2= 3; pic->motion_subsample_log2= 3;
} }
if(s->avctx->debug&FF_DEBUG_DCT_COEFF) { if(s->avctx->debug&FF_DEBUG_DCT_COEFF) {
CHECKED_ALLOCZ(pic->dct_coeff, 64 * mb_array_size * sizeof(DCTELEM)*6) FF_ALLOCZ_OR_GOTO(s->avctx, pic->dct_coeff, 64 * mb_array_size * sizeof(DCTELEM)*6, fail)
} }
pic->qstride= s->mb_stride; pic->qstride= s->mb_stride;
CHECKED_ALLOCZ(pic->pan_scan , 1 * sizeof(AVPanScan)) FF_ALLOCZ_OR_GOTO(s->avctx, pic->pan_scan , 1 * sizeof(AVPanScan), fail)
} }
/* It might be nicer if the application would keep track of these /* It might be nicer if the application would keep track of these
...@@ -282,7 +282,7 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){ ...@@ -282,7 +282,7 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){
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. 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.
return 0; return 0;
fail: //for the CHECKED_ALLOCZ macro fail: //for the FF_ALLOCZ_OR_GOTO macro
if(r>=0) if(r>=0)
free_frame_buffer(s, pic); free_frame_buffer(s, pic);
return -1; return -1;
...@@ -325,23 +325,23 @@ static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){ ...@@ -325,23 +325,23 @@ static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){
int i; int i;
// edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264) // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264)
CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*21*2); //(width + edge + align)*interlaced*MBsize*tolerance FF_ALLOCZ_OR_GOTO(s->avctx, s->allocated_edge_emu_buffer, (s->width+64)*2*21*2, fail); //(width + edge + align)*interlaced*MBsize*tolerance
s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21; s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21;
//FIXME should be linesize instead of s->width*2 but that is not known before get_buffer() //FIXME should be linesize instead of s->width*2 but that is not known before get_buffer()
CHECKED_ALLOCZ(s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t), fail)
s->me.temp= s->me.scratchpad; s->me.temp= s->me.scratchpad;
s->rd_scratchpad= s->me.scratchpad; s->rd_scratchpad= s->me.scratchpad;
s->b_scratchpad= s->me.scratchpad; s->b_scratchpad= s->me.scratchpad;
s->obmc_scratchpad= s->me.scratchpad + 16; s->obmc_scratchpad= s->me.scratchpad + 16;
if (s->encoding) { if (s->encoding) {
CHECKED_ALLOCZ(s->me.map , ME_MAP_SIZE*sizeof(uint32_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->me.map , ME_MAP_SIZE*sizeof(uint32_t), fail)
CHECKED_ALLOCZ(s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t), fail)
if(s->avctx->noise_reduction){ if(s->avctx->noise_reduction){
CHECKED_ALLOCZ(s->dct_error_sum, 2 * 64 * sizeof(int)) FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_error_sum, 2 * 64 * sizeof(int), fail)
} }
} }
CHECKED_ALLOCZ(s->blocks, 64*12*2 * sizeof(DCTELEM)) FF_ALLOCZ_OR_GOTO(s->avctx, s->blocks, 64*12*2 * sizeof(DCTELEM), fail)
s->block= s->blocks[0]; s->block= s->blocks[0];
for(i=0;i<12;i++){ for(i=0;i<12;i++){
...@@ -509,7 +509,7 @@ av_cold int MPV_common_init(MpegEncContext *s) ...@@ -509,7 +509,7 @@ av_cold int MPV_common_init(MpegEncContext *s)
s->avctx->coded_frame= (AVFrame*)&s->current_picture; s->avctx->coded_frame= (AVFrame*)&s->current_picture;
CHECKED_ALLOCZ(s->mb_index2xy, (s->mb_num+1)*sizeof(int)) //error ressilience code looks cleaner with this FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num+1)*sizeof(int), fail) //error ressilience code looks cleaner with this
for(y=0; y<s->mb_height; y++){ for(y=0; y<s->mb_height; y++){
for(x=0; x<s->mb_width; x++){ for(x=0; x<s->mb_width; x++){
s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride; s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride;
...@@ -519,12 +519,12 @@ av_cold int MPV_common_init(MpegEncContext *s) ...@@ -519,12 +519,12 @@ av_cold int MPV_common_init(MpegEncContext *s)
if (s->encoding) { if (s->encoding) {
/* Allocate MV tables */ /* Allocate MV tables */
CHECKED_ALLOCZ(s->p_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
CHECKED_ALLOCZ(s->b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
CHECKED_ALLOCZ(s->b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
CHECKED_ALLOCZ(s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
CHECKED_ALLOCZ(s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
CHECKED_ALLOCZ(s->b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1; s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1;
s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1; s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1;
s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1; s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1;
...@@ -533,32 +533,32 @@ av_cold int MPV_common_init(MpegEncContext *s) ...@@ -533,32 +533,32 @@ av_cold int MPV_common_init(MpegEncContext *s)
s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1;
if(s->msmpeg4_version){ if(s->msmpeg4_version){
CHECKED_ALLOCZ(s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int)); FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int), fail);
} }
CHECKED_ALLOCZ(s->avctx->stats_out, 256); FF_ALLOCZ_OR_GOTO(s->avctx, s->avctx->stats_out, 256, fail);
/* Allocate MB type table */ /* Allocate MB type table */
CHECKED_ALLOCZ(s->mb_type , mb_array_size * sizeof(uint16_t)) //needed for encoding FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type , mb_array_size * sizeof(uint16_t), fail) //needed for encoding
CHECKED_ALLOCZ(s->lambda_table, mb_array_size * sizeof(int)) FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size * sizeof(int), fail)
CHECKED_ALLOCZ(s->q_intra_matrix, 64*32 * sizeof(int)) FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix , 64*32 * sizeof(int), fail)
CHECKED_ALLOCZ(s->q_inter_matrix, 64*32 * sizeof(int)) FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix , 64*32 * sizeof(int), fail)
CHECKED_ALLOCZ(s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t), fail)
CHECKED_ALLOCZ(s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t), fail)
CHECKED_ALLOCZ(s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*)) FF_ALLOCZ_OR_GOTO(s->avctx, s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail)
CHECKED_ALLOCZ(s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*)) FF_ALLOCZ_OR_GOTO(s->avctx, s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail)
if(s->avctx->noise_reduction){ if(s->avctx->noise_reduction){
CHECKED_ALLOCZ(s->dct_offset, 2 * 64 * sizeof(uint16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail)
} }
} }
CHECKED_ALLOCZ(s->picture, MAX_PICTURE_COUNT * sizeof(Picture)) FF_ALLOCZ_OR_GOTO(s->avctx, s->picture, MAX_PICTURE_COUNT * sizeof(Picture), fail)
for(i = 0; i < MAX_PICTURE_COUNT; i++) { for(i = 0; i < MAX_PICTURE_COUNT; i++) {
avcodec_get_frame_defaults((AVFrame *)&s->picture[i]); avcodec_get_frame_defaults((AVFrame *)&s->picture[i]);
} }
CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, mb_array_size*sizeof(uint8_t), fail)
if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){ if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){
/* interlaced direct mode decoding tables */ /* interlaced direct mode decoding tables */
...@@ -566,36 +566,36 @@ av_cold int MPV_common_init(MpegEncContext *s) ...@@ -566,36 +566,36 @@ av_cold int MPV_common_init(MpegEncContext *s)
int j, k; int j, k;
for(j=0; j<2; j++){ for(j=0; j<2; j++){
for(k=0; k<2; k++){ for(k=0; k<2; k++){
CHECKED_ALLOCZ(s->b_field_mv_table_base[i][j][k] , mv_table_size * 2 * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_mv_table_base[i][j][k], mv_table_size * 2 * sizeof(int16_t), fail)
s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] + s->mb_stride + 1; s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] + s->mb_stride + 1;
} }
CHECKED_ALLOCZ(s->b_field_select_table[i][j] , mb_array_size * 2 * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_select_table [i][j], mb_array_size * 2 * sizeof(uint8_t), fail)
CHECKED_ALLOCZ(s->p_field_mv_table_base[i][j] , mv_table_size * 2 * sizeof(int16_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_mv_table_base[i][j], mv_table_size * 2 * sizeof(int16_t), fail)
s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j] + s->mb_stride + 1; s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j]+ s->mb_stride + 1;
} }
CHECKED_ALLOCZ(s->p_field_select_table[i] , mb_array_size * 2 * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_select_table[i], mb_array_size * 2 * sizeof(uint8_t), fail)
} }
} }
if (s->out_format == FMT_H263) { if (s->out_format == FMT_H263) {
/* ac values */ /* ac values */
CHECKED_ALLOCZ(s->ac_val_base, yc_size * sizeof(int16_t) * 16); FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, yc_size * sizeof(int16_t) * 16, fail);
s->ac_val[0] = s->ac_val_base + s->b8_stride + 1; s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;
s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1; s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;
s->ac_val[2] = s->ac_val[1] + c_size; s->ac_val[2] = s->ac_val[1] + c_size;
/* cbp values */ /* cbp values */
CHECKED_ALLOCZ(s->coded_block_base, y_size); FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail);
s->coded_block= s->coded_block_base + s->b8_stride + 1; s->coded_block= s->coded_block_base + s->b8_stride + 1;
/* cbp, ac_pred, pred_dir */ /* cbp, ac_pred, pred_dir */
CHECKED_ALLOCZ(s->cbp_table , mb_array_size * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table , mb_array_size * sizeof(uint8_t), fail)
CHECKED_ALLOCZ(s->pred_dir_table, mb_array_size * sizeof(uint8_t)) FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table, mb_array_size * sizeof(uint8_t), fail)
} }
if (s->h263_pred || s->h263_plus || !s->encoding) { if (s->h263_pred || s->h263_plus || !s->encoding) {
/* dc values */ /* dc values */
//MN: we need these for error resilience of intra-frames //MN: we need these for error resilience of intra-frames
CHECKED_ALLOCZ(s->dc_val_base, yc_size * sizeof(int16_t)); FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base, yc_size * sizeof(int16_t), fail);
s->dc_val[0] = s->dc_val_base + s->b8_stride + 1; s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1; s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
s->dc_val[2] = s->dc_val[1] + c_size; s->dc_val[2] = s->dc_val[1] + c_size;
...@@ -604,13 +604,13 @@ av_cold int MPV_common_init(MpegEncContext *s) ...@@ -604,13 +604,13 @@ av_cold int MPV_common_init(MpegEncContext *s)
} }
/* which mb is a intra block */ /* which mb is a intra block */
CHECKED_ALLOCZ(s->mbintra_table, mb_array_size); FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail);
memset(s->mbintra_table, 1, mb_array_size); memset(s->mbintra_table, 1, mb_array_size);
/* init macroblock skip table */ /* init macroblock skip table */
CHECKED_ALLOCZ(s->mbskip_table, mb_array_size+2); FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size+2, fail);
//Note the +1 is for a quicker mpeg4 slice_end detection //Note the +1 is for a quicker mpeg4 slice_end detection
CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE); FF_ALLOCZ_OR_GOTO(s->avctx, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE, fail);
s->parse_context.state= -1; s->parse_context.state= -1;
if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){
......
...@@ -249,21 +249,21 @@ if ((y) < (x)) {\ ...@@ -249,21 +249,21 @@ if ((y) < (x)) {\
#define perror please_use_av_log_instead_of_perror #define perror please_use_av_log_instead_of_perror
#endif #endif
#define CHECKED_ALLOC(p, size)\ #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
{\ {\
p = av_malloc(size);\ p = av_malloc(size);\
if (p == NULL && (size) != 0) {\ if (p == NULL && (size) != 0) {\
av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.\n");\ av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
goto fail;\ goto label;\
}\ }\
} }
#define CHECKED_ALLOCZ(p, size)\ #define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
{\ {\
p = av_mallocz(size);\ p = av_mallocz(size);\
if (p == NULL && (size) != 0) {\ if (p == NULL && (size) != 0) {\
av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.\n");\ av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
goto fail;\ goto label;\
}\ }\
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment