Revision 2cd34043

View differences:

libavcodec/snow.c
3331 3331
 
3332 3332
    s->version=0;
3333 3333
    
3334
    s->m.avctx   = avctx;
3335
    s->m.flags   = avctx->flags;
3336
    s->m.bit_rate= avctx->bit_rate;
3337

  
3334 3338
    s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t));
3335 3339
    s->m.me.map       = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
3336 3340
    s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
3337 3341
    h263_encode_init(&s->m); //mv_penalty
3338 3342

  
3343
    if(avctx->flags&CODEC_FLAG_PASS1){
3344
        if(!avctx->stats_out)
3345
            avctx->stats_out = av_mallocz(256);
3346
    }
3347
    if(avctx->flags&CODEC_FLAG_PASS2){
3348
        if(ff_rate_control_init(&s->m) < 0)
3349
            return -1;
3350
    }
3351

  
3339 3352
    for(plane_index=0; plane_index<3; plane_index++){
3340 3353
        calculate_vissual_weight(s, &s->plane[plane_index]);
3341 3354
    }
......
3401 3414
    
3402 3415
    s->input_picture = *pict;
3403 3416

  
3404
    s->keyframe=avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0;
3405
    pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE;
3417
    if(avctx->flags&CODEC_FLAG_PASS2){
3418
        s->m.pict_type =
3419
        pict->pict_type= s->m.rc_context.entry[avctx->frame_number].new_pict_type;
3420
        s->keyframe= pict->pict_type==FF_I_TYPE;
3421
        s->m.picture_number= avctx->frame_number;
3422
        pict->quality= ff_rate_estimate_qscale(&s->m);
3423
    }else{
3424
        s->keyframe= avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0;
3425
        pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE;
3426
    }
3406 3427
    
3407 3428
    if(pict->quality){
3408 3429
        s->qlog= rint(QROOT*log(pict->quality / (float)FF_QP2LAMBDA)/log(2));
......
3415 3436
    frame_start(s);
3416 3437
    s->current_picture.key_frame= s->keyframe;
3417 3438

  
3439
    s->m.current_picture_ptr= &s->m.current_picture;
3418 3440
    if(pict->pict_type == P_TYPE){
3419 3441
        int block_width = (width +15)>>4;
3420 3442
        int block_height= (height+15)>>4;
......
3427 3449
        s->m.current_picture.data[0]= s->current_picture.data[0];
3428 3450
        s->m.   last_picture.data[0]= s->   last_picture.data[0];
3429 3451
        s->m.    new_picture.data[0]= s->  input_picture.data[0];
3430
        s->m.current_picture_ptr= &s->m.current_picture;
3431 3452
        s->m.   last_picture_ptr= &s->m.   last_picture;
3432 3453
        s->m.linesize=
3433 3454
        s->m.   last_picture.linesize[0]=
......
3462 3483
    s->qbias= pict->pict_type == P_TYPE ? 2 : 0;
3463 3484

  
3464 3485
    encode_header(s);
3486
    s->m.misc_bits = 8*(s->c.bytestream - s->c.bytestream_start);
3465 3487
    encode_blocks(s);
3488
    s->m.mv_bits = 8*(s->c.bytestream - s->c.bytestream_start) - s->m.misc_bits;
3466 3489
      
3467 3490
    for(plane_index=0; plane_index<3; plane_index++){
3468 3491
        Plane *p= &s->plane[plane_index];
......
3553 3576
    if(s->last_picture.data[0])
3554 3577
        avctx->release_buffer(avctx, &s->last_picture);
3555 3578

  
3579
    s->current_picture.coded_picture_number = avctx->frame_number;
3580
    s->current_picture.pict_type = pict->pict_type;
3581
    s->current_picture.quality = pict->quality;
3582
    if(avctx->flags&CODEC_FLAG_PASS1){
3583
        s->m.p_tex_bits = 8*(s->c.bytestream - s->c.bytestream_start) - s->m.misc_bits - s->m.mv_bits;
3584
        s->m.current_picture.display_picture_number =
3585
        s->m.current_picture.coded_picture_number = avctx->frame_number;
3586
        s->m.pict_type = pict->pict_type;
3587
        s->m.current_picture.quality = pict->quality;
3588
        ff_write_pass1_stats(&s->m);
3589
    }
3590
    if(avctx->flags&CODEC_FLAG_PASS2){
3591
        s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start);
3592
    }
3593

  
3556 3594
    emms_c();
3557 3595
    
3558 3596
    return ff_rac_terminate(c);
......
3585 3623
    SnowContext *s = avctx->priv_data;
3586 3624

  
3587 3625
    common_end(s);
3626
    av_free(avctx->stats_out);
3588 3627

  
3589 3628
    return 0;
3590 3629
}

Also available in: Unified diff