comparison svq1enc.c @ 10855:423410fc29b1 libavcodec

Reduce stack usage in svq1_encode_plane(). Reuse context scratch buffer instead. Avoid a crash on MinGW.
author zuxy
date Tue, 12 Jan 2010 09:13:32 +0000
parents f6afc7837f83
children 8a4984c5cacc
comparison
equal deleted inserted replaced
10854:f6fc6ace95e3 10855:423410fc29b1
267 int x, y; 267 int x, y;
268 int i; 268 int i;
269 int block_width, block_height; 269 int block_width, block_height;
270 int level; 270 int level;
271 int threshold[6]; 271 int threshold[6];
272 uint8_t *src = s->scratchbuf + stride * 16;
272 const int lambda= (s->picture.quality*s->picture.quality) >> (2*FF_LAMBDA_SHIFT); 273 const int lambda= (s->picture.quality*s->picture.quality) >> (2*FF_LAMBDA_SHIFT);
273 274
274 /* figure out the acceptable level thresholds in advance */ 275 /* figure out the acceptable level thresholds in advance */
275 threshold[5] = QUALITY_THRESHOLD; 276 threshold[5] = QUALITY_THRESHOLD;
276 for (level = 4; level >= 0; level--) 277 for (level = 4; level >= 0; level--)
325 ff_init_me(&s->m); 326 ff_init_me(&s->m);
326 327
327 s->m.me.dia_size= s->avctx->dia_size; 328 s->m.me.dia_size= s->avctx->dia_size;
328 s->m.first_slice_line=1; 329 s->m.first_slice_line=1;
329 for (y = 0; y < block_height; y++) { 330 for (y = 0; y < block_height; y++) {
330 uint8_t src[stride*16];
331
332 s->m.new_picture.data[0]= src - y*16*stride; //ugly 331 s->m.new_picture.data[0]= src - y*16*stride; //ugly
333 s->m.mb_y= y; 332 s->m.mb_y= y;
334 333
335 for(i=0; i<16 && i + 16*y<height; i++){ 334 for(i=0; i<16 && i + 16*y<height; i++){
336 memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width); 335 memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width);
354 ff_fix_long_mvs(&s->m, NULL, 0, s->m.p_mv_table, s->m.f_code, CANDIDATE_MB_TYPE_INTER, 0); 353 ff_fix_long_mvs(&s->m, NULL, 0, s->m.p_mv_table, s->m.f_code, CANDIDATE_MB_TYPE_INTER, 0);
355 } 354 }
356 355
357 s->m.first_slice_line=1; 356 s->m.first_slice_line=1;
358 for (y = 0; y < block_height; y++) { 357 for (y = 0; y < block_height; y++) {
359 uint8_t src[stride*16];
360
361 for(i=0; i<16 && i + 16*y<height; i++){ 358 for(i=0; i<16 && i + 16*y<height; i++){
362 memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width); 359 memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width);
363 for(x=width; x<16*block_width; x++) 360 for(x=width; x<16*block_width; x++)
364 src[i*stride+x]= src[i*stride+x-1]; 361 src[i*stride+x]= src[i*stride+x-1];
365 } 362 }
519 } 516 }
520 517
521 if(!s->current_picture.data[0]){ 518 if(!s->current_picture.data[0]){
522 avctx->get_buffer(avctx, &s->current_picture); 519 avctx->get_buffer(avctx, &s->current_picture);
523 avctx->get_buffer(avctx, &s->last_picture); 520 avctx->get_buffer(avctx, &s->last_picture);
524 s->scratchbuf = av_malloc(s->current_picture.linesize[0] * 16); 521 s->scratchbuf = av_malloc(s->current_picture.linesize[0] * 16 * 2);
525 } 522 }
526 523
527 temp= s->current_picture; 524 temp= s->current_picture;
528 s->current_picture= s->last_picture; 525 s->current_picture= s->last_picture;
529 s->last_picture= temp; 526 s->last_picture= temp;