Mercurial > libavcodec.hg
comparison dnxhdenc.c @ 10137:9a670cfd1941 libavcodec
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
parameters.
author | ramiro |
---|---|
date | Sun, 06 Sep 2009 00:08:19 +0000 |
parents | 85ad5d68ec98 |
children | 38cfe222e1a4 |
comparison
equal
deleted
inserted
replaced
10136:399b5d6b5439 | 10137:9a670cfd1941 |
---|---|
53 static int dnxhd_init_vlc(DNXHDEncContext *ctx) | 53 static int dnxhd_init_vlc(DNXHDEncContext *ctx) |
54 { | 54 { |
55 int i, j, level, run; | 55 int i, j, level, run; |
56 int max_level = 1<<(ctx->cid_table->bit_depth+2); | 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)); | 58 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes), fail); |
59 CHECKED_ALLOCZ(ctx->vlc_bits, max_level*4*sizeof(*ctx->vlc_bits)); | 59 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits , max_level*4*sizeof(*ctx->vlc_bits ), fail); |
60 CHECKED_ALLOCZ(ctx->run_codes, 63*2); | 60 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes, 63*2 , fail); |
61 CHECKED_ALLOCZ(ctx->run_bits, 63); | 61 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits , 63 , fail); |
62 | 62 |
63 ctx->vlc_codes += max_level*2; | 63 ctx->vlc_codes += max_level*2; |
64 ctx->vlc_bits += max_level*2; | 64 ctx->vlc_bits += max_level*2; |
65 for (level = -max_level; level < max_level; level++) { | 65 for (level = -max_level; level < max_level; level++) { |
66 for (run = 0; run < 2; run++) { | 66 for (run = 0; run < 2; run++) { |
109 { | 109 { |
110 // init first elem to 1 to avoid div by 0 in convert_matrix | 110 // init first elem to 1 to avoid div by 0 in convert_matrix |
111 uint16_t weight_matrix[64] = {1,}; // convert_matrix needs uint16_t* | 111 uint16_t weight_matrix[64] = {1,}; // convert_matrix needs uint16_t* |
112 int qscale, i; | 112 int qscale, i; |
113 | 113 |
114 CHECKED_ALLOCZ(ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int)); | 114 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int) , fail); |
115 CHECKED_ALLOCZ(ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int)); | 115 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int) , fail); |
116 CHECKED_ALLOCZ(ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t)); | 116 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t), fail); |
117 CHECKED_ALLOCZ(ctx->qmatrix_c16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t)); | 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 for (i = 1; i < 64; i++) { | 119 for (i = 1; i < 64; i++) { |
120 int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]]; | 120 int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]]; |
121 weight_matrix[j] = ctx->cid_table->luma_weight[i]; | 121 weight_matrix[j] = ctx->cid_table->luma_weight[i]; |
122 } | 122 } |
140 return -1; | 140 return -1; |
141 } | 141 } |
142 | 142 |
143 static int dnxhd_init_rc(DNXHDEncContext *ctx) | 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 if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) | 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 ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8; | 149 ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8; |
150 ctx->qscale = 1; | 150 ctx->qscale = 1; |
151 ctx->lambda = 2<<LAMBDA_FRAC_BITS; // qscale 2 | 151 ctx->lambda = 2<<LAMBDA_FRAC_BITS; // qscale 2 |
152 return 0; | 152 return 0; |
201 if (dnxhd_init_vlc(ctx) < 0) | 201 if (dnxhd_init_vlc(ctx) < 0) |
202 return -1; | 202 return -1; |
203 if (dnxhd_init_rc(ctx) < 0) | 203 if (dnxhd_init_rc(ctx) < 0) |
204 return -1; | 204 return -1; |
205 | 205 |
206 CHECKED_ALLOCZ(ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t)); | 206 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t), fail); |
207 CHECKED_ALLOCZ(ctx->mb_bits, ctx->m.mb_num *sizeof(uint16_t)); | 207 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_bits, ctx->m.mb_num *sizeof(uint16_t), fail); |
208 CHECKED_ALLOCZ(ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t)); | 208 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t) , fail); |
209 | 209 |
210 ctx->frame.key_frame = 1; | 210 ctx->frame.key_frame = 1; |
211 ctx->frame.pict_type = FF_I_TYPE; | 211 ctx->frame.pict_type = FF_I_TYPE; |
212 ctx->m.avctx->coded_frame = &ctx->frame; | 212 ctx->m.avctx->coded_frame = &ctx->frame; |
213 | 213 |
226 ctx->thread[i]->m.start_mb_y = (ctx->m.mb_height*(i ) + avctx->thread_count/2) / avctx->thread_count; | 226 ctx->thread[i]->m.start_mb_y = (ctx->m.mb_height*(i ) + avctx->thread_count/2) / avctx->thread_count; |
227 ctx->thread[i]->m.end_mb_y = (ctx->m.mb_height*(i+1) + avctx->thread_count/2) / avctx->thread_count; | 227 ctx->thread[i]->m.end_mb_y = (ctx->m.mb_height*(i+1) + avctx->thread_count/2) / avctx->thread_count; |
228 } | 228 } |
229 | 229 |
230 return 0; | 230 return 0; |
231 fail: //for CHECKED_ALLOCZ | 231 fail: //for FF_ALLOCZ_OR_GOTO |
232 return -1; | 232 return -1; |
233 } | 233 } |
234 | 234 |
235 static int dnxhd_write_header(AVCodecContext *avctx, uint8_t *buf) | 235 static int dnxhd_write_header(AVCodecContext *avctx, uint8_t *buf) |
236 { | 236 { |