Revision ce5e49b0 libavcodec/ratecontrol.c

View differences:

libavcodec/ratecontrol.c
144 144
        /* init all to skipped p frames (with b frames we might have a not encoded frame at the end FIXME) */
145 145
        for(i=0; i<rcc->num_entries; i++){
146 146
            RateControlEntry *rce= &rcc->entry[i];
147
            rce->pict_type= rce->new_pict_type=FF_P_TYPE;
147
            rce->pict_type= rce->new_pict_type=AV_PICTURE_TYPE_P;
148 148
            rce->qscale= rce->new_qscale=FF_QP2LAMBDA * 2;
149 149
            rce->misc_bits= s->mb_num + 10;
150 150
            rce->mb_var_sum= s->mb_num*100;
......
211 211
                double bits= s->avctx->rc_initial_cplx * (i/10000.0 + 1.0)*s->mb_num;
212 212
                RateControlEntry rce;
213 213

  
214
                if     (i%((s->gop_size+3)/4)==0) rce.pict_type= FF_I_TYPE;
215
                else if(i%(s->max_b_frames+1))    rce.pict_type= FF_B_TYPE;
216
                else                              rce.pict_type= FF_P_TYPE;
214
                if     (i%((s->gop_size+3)/4)==0) rce.pict_type= AV_PICTURE_TYPE_I;
215
                else if(i%(s->max_b_frames+1))    rce.pict_type= AV_PICTURE_TYPE_B;
216
                else                              rce.pict_type= AV_PICTURE_TYPE_P;
217 217

  
218 218
                rce.new_pict_type= rce.pict_type;
219 219
                rce.mc_mb_var_sum= bits*s->mb_num/100000;
......
223 223
                rce.b_code   = 1;
224 224
                rce.misc_bits= 1;
225 225

  
226
                if(s->pict_type== FF_I_TYPE){
226
                if(s->pict_type== AV_PICTURE_TYPE_I){
227 227
                    rce.i_count   = s->mb_num;
228 228
                    rce.i_tex_bits= bits;
229 229
                    rce.p_tex_bits= 0;
......
317 317
        rce->p_tex_bits*rce->qscale,
318 318
        (rce->i_tex_bits + rce->p_tex_bits)*(double)rce->qscale,
319 319
        rce->mv_bits/mb_num,
320
        rce->pict_type == FF_B_TYPE ? (rce->f_code + rce->b_code)*0.5 : rce->f_code,
320
        rce->pict_type == AV_PICTURE_TYPE_B ? (rce->f_code + rce->b_code)*0.5 : rce->f_code,
321 321
        rce->i_count/mb_num,
322 322
        rce->mc_mb_var_sum/mb_num,
323 323
        rce->mb_var_sum/mb_num,
324
        rce->pict_type == FF_I_TYPE,
325
        rce->pict_type == FF_P_TYPE,
326
        rce->pict_type == FF_B_TYPE,
324
        rce->pict_type == AV_PICTURE_TYPE_I,
325
        rce->pict_type == AV_PICTURE_TYPE_P,
326
        rce->pict_type == AV_PICTURE_TYPE_B,
327 327
        rcc->qscale_sum[pict_type] / (double)rcc->frame_count[pict_type],
328 328
        a->qcompress,
329
/*        rcc->last_qscale_for[FF_I_TYPE],
330
        rcc->last_qscale_for[FF_P_TYPE],
331
        rcc->last_qscale_for[FF_B_TYPE],
329
/*        rcc->last_qscale_for[AV_PICTURE_TYPE_I],
330
        rcc->last_qscale_for[AV_PICTURE_TYPE_P],
331
        rcc->last_qscale_for[AV_PICTURE_TYPE_B],
332 332
        rcc->next_non_b_qscale,*/
333
        rcc->i_cplx_sum[FF_I_TYPE] / (double)rcc->frame_count[FF_I_TYPE],
334
        rcc->i_cplx_sum[FF_P_TYPE] / (double)rcc->frame_count[FF_P_TYPE],
335
        rcc->p_cplx_sum[FF_P_TYPE] / (double)rcc->frame_count[FF_P_TYPE],
336
        rcc->p_cplx_sum[FF_B_TYPE] / (double)rcc->frame_count[FF_B_TYPE],
333
        rcc->i_cplx_sum[AV_PICTURE_TYPE_I] / (double)rcc->frame_count[AV_PICTURE_TYPE_I],
334
        rcc->i_cplx_sum[AV_PICTURE_TYPE_P] / (double)rcc->frame_count[AV_PICTURE_TYPE_P],
335
        rcc->p_cplx_sum[AV_PICTURE_TYPE_P] / (double)rcc->frame_count[AV_PICTURE_TYPE_P],
336
        rcc->p_cplx_sum[AV_PICTURE_TYPE_B] / (double)rcc->frame_count[AV_PICTURE_TYPE_B],
337 337
        (rcc->i_cplx_sum[pict_type] + rcc->p_cplx_sum[pict_type]) / (double)rcc->frame_count[pict_type],
338 338
        0
339 339
    };
......
364 364
    q= bits2qp(rce, bits);
365 365

  
366 366
    /* I/B difference */
367
    if     (pict_type==FF_I_TYPE && s->avctx->i_quant_factor<0.0)
367
    if     (pict_type==AV_PICTURE_TYPE_I && s->avctx->i_quant_factor<0.0)
368 368
        q= -q*s->avctx->i_quant_factor + s->avctx->i_quant_offset;
369
    else if(pict_type==FF_B_TYPE && s->avctx->b_quant_factor<0.0)
369
    else if(pict_type==AV_PICTURE_TYPE_B && s->avctx->b_quant_factor<0.0)
370 370
        q= -q*s->avctx->b_quant_factor + s->avctx->b_quant_offset;
371 371
    if(q<1) q=1;
372 372

  
......
377 377
    RateControlContext *rcc= &s->rc_context;
378 378
    AVCodecContext *a= s->avctx;
379 379
    const int pict_type= rce->new_pict_type;
380
    const double last_p_q    = rcc->last_qscale_for[FF_P_TYPE];
380
    const double last_p_q    = rcc->last_qscale_for[AV_PICTURE_TYPE_P];
381 381
    const double last_non_b_q= rcc->last_qscale_for[rcc->last_non_b_pict_type];
382 382

  
383
    if     (pict_type==FF_I_TYPE && (a->i_quant_factor>0.0 || rcc->last_non_b_pict_type==FF_P_TYPE))
383
    if     (pict_type==AV_PICTURE_TYPE_I && (a->i_quant_factor>0.0 || rcc->last_non_b_pict_type==AV_PICTURE_TYPE_P))
384 384
        q= last_p_q    *FFABS(a->i_quant_factor) + a->i_quant_offset;
385
    else if(pict_type==FF_B_TYPE && a->b_quant_factor>0.0)
385
    else if(pict_type==AV_PICTURE_TYPE_B && a->b_quant_factor>0.0)
386 386
        q= last_non_b_q*    a->b_quant_factor  + a->b_quant_offset;
387 387
    if(q<1) q=1;
388 388

  
389 389
    /* last qscale / qdiff stuff */
390
    if(rcc->last_non_b_pict_type==pict_type || pict_type!=FF_I_TYPE){
390
    if(rcc->last_non_b_pict_type==pict_type || pict_type!=AV_PICTURE_TYPE_I){
391 391
        double last_q= rcc->last_qscale_for[pict_type];
392 392
        const int maxdiff= FF_QP2LAMBDA * a->max_qdiff;
393 393

  
......
397 397

  
398 398
    rcc->last_qscale_for[pict_type]= q; //Note we cannot do that after blurring
399 399

  
400
    if(pict_type!=FF_B_TYPE)
400
    if(pict_type!=AV_PICTURE_TYPE_B)
401 401
        rcc->last_non_b_pict_type= pict_type;
402 402

  
403 403
    return q;
......
412 412

  
413 413
    assert(qmin <= qmax);
414 414

  
415
    if(pict_type==FF_B_TYPE){
415
    if(pict_type==AV_PICTURE_TYPE_B){
416 416
        qmin= (int)(qmin*FFABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5);
417 417
        qmax= (int)(qmax*FFABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5);
418
    }else if(pict_type==FF_I_TYPE){
418
    }else if(pict_type==AV_PICTURE_TYPE_I){
419 419
        qmin= (int)(qmin*FFABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5);
420 420
        qmax= (int)(qmax*FFABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5);
421 421
    }
......
441 441
    get_qminmax(&qmin, &qmax, s, pict_type);
442 442

  
443 443
    /* modulation */
444
    if(s->avctx->rc_qmod_freq && frame_num%s->avctx->rc_qmod_freq==0 && pict_type==FF_P_TYPE)
444
    if(s->avctx->rc_qmod_freq && frame_num%s->avctx->rc_qmod_freq==0 && pict_type==AV_PICTURE_TYPE_P)
445 445
        q*= s->avctx->rc_qmod_amp;
446 446

  
447 447
//printf("q:%f\n", q);
......
684 684
//printf("input_pic_num:%d pic_num:%d frame_rate:%d\n", s->input_picture_number, s->picture_number, s->frame_rate);
685 685
        /* update predictors */
686 686
    if(picture_number>2 && !dry_run){
687
        const int last_var= s->last_pict_type == FF_I_TYPE ? rcc->last_mb_var_sum : rcc->last_mc_mb_var_sum;
687
        const int last_var= s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum : rcc->last_mc_mb_var_sum;
688 688
        update_predictor(&rcc->pred[s->last_pict_type], rcc->last_qscale, sqrt(last_var), s->frame_bits);
689 689
    }
690 690

  
......
699 699

  
700 700
        //FIXME add a dts field to AVFrame and ensure its set and use it here instead of reordering
701 701
        //but the reordering is simpler for now until h.264 b pyramid must be handeld
702
        if(s->pict_type == FF_B_TYPE || s->low_delay)
702
        if(s->pict_type == AV_PICTURE_TYPE_B || s->low_delay)
703 703
            dts_pic= s->current_picture_ptr;
704 704
        else
705 705
            dts_pic= s->last_picture_ptr;
......
717 717
    br_compensation= (a->bit_rate_tolerance - diff)/a->bit_rate_tolerance;
718 718
    if(br_compensation<=0.0) br_compensation=0.001;
719 719

  
720
    var= pict_type == FF_I_TYPE ? pic->mb_var_sum : pic->mc_mb_var_sum;
720
    var= pict_type == AV_PICTURE_TYPE_I ? pic->mb_var_sum : pic->mc_mb_var_sum;
721 721

  
722 722
    short_term_q = 0; /* avoid warning */
723 723
    if(s->flags&CODEC_FLAG_PASS2){
724
        if(pict_type!=FF_I_TYPE)
724
        if(pict_type!=AV_PICTURE_TYPE_I)
725 725
            assert(pict_type == rce->new_pict_type);
726 726

  
727 727
        q= rce->new_qscale / br_compensation;
......
737 737
        rce->misc_bits= 1;
738 738

  
739 739
        bits= predict_size(&rcc->pred[pict_type], rce->qscale, sqrt(var));
740
        if(pict_type== FF_I_TYPE){
740
        if(pict_type== AV_PICTURE_TYPE_I){
741 741
            rce->i_count   = s->mb_num;
742 742
            rce->i_tex_bits= bits;
743 743
            rce->p_tex_bits= 0;
......
767 767
//printf("%f ", q);
768 768
        assert(q>0.0);
769 769

  
770
        if(pict_type==FF_P_TYPE || s->intra_only){ //FIXME type dependent blur like in 2-pass
770
        if(pict_type==AV_PICTURE_TYPE_P || s->intra_only){ //FIXME type dependent blur like in 2-pass
771 771
            rcc->short_term_qsum*=a->qblur;
772 772
            rcc->short_term_qcount*=a->qblur;
773 773

  
......
842 842
        complexity[rce->new_pict_type]+= (rce->i_tex_bits+ rce->p_tex_bits)*(double)rce->qscale;
843 843
        const_bits[rce->new_pict_type]+= rce->mv_bits + rce->misc_bits;
844 844
    }
845
    all_const_bits= const_bits[FF_I_TYPE] + const_bits[FF_P_TYPE] + const_bits[FF_B_TYPE];
845
    all_const_bits= const_bits[AV_PICTURE_TYPE_I] + const_bits[AV_PICTURE_TYPE_P] + const_bits[AV_PICTURE_TYPE_B];
846 846

  
847 847
    if(all_available_bits < all_const_bits){
848 848
        av_log(s->avctx, AV_LOG_ERROR, "requested bitrate is too low\n");

Also available in: Unified diff