예제 #1
0
PV_STATUS RC_VopUpdateStat(VideoEncData *video, rateControl *rc)
{
    Int currLayer = video->currLayer;
    Vol *currVol = video->vol[currLayer];
    MultiPass *pMP = video->pMP[currLayer];
    Int diff_BTCounter;

    switch (video->encParams->RC_Type)
    {
        case CONSTANT_Q:
            break;

        case CBR_1:
        case CBR_2:
        case VBR_1:
        case VBR_2:
        case CBR_LOWDELAY:

            pMP->actual_bits = currVol->stream->byteCount << 3;

            SaveRDSamples(pMP, 0);

            pMP->encoded_frames++;

            /* for pMP->samplesPerFrame */
            pMP->samplesPerFrame[pMP->framePos] = 0;

            pMP->sum_QP += pMP->QP;


            /* update pMP->counter_BTsrc, pMP->counter_BTdst */
            /* re-allocate the target bit again and then stop encoding */
            diff_BTCounter = (Int)((float)(rc->TMN_TH - rc->TMN_W - pMP->actual_bits) /
                                   (pMP->bitrate / (pMP->framerate + 0.0001) + 0.0001) / 0.1);
            if (diff_BTCounter >= 0)
                pMP->counter_BTsrc += diff_BTCounter; /* pMP->actual_bits is smaller */
            else
                pMP->counter_BTdst -= diff_BTCounter; /* pMP->actual_bits is bigger */

            rc->TMN_TH -= (Int)((float)pMP->bitrate / (pMP->framerate + 0.0001) * (diff_BTCounter * 0.1));
            rc->T = pMP->target_bits = rc->TMN_TH - rc->TMN_W;
            pMP->diff_counter -= diff_BTCounter;

            rc->Rc = currVol->stream->byteCount << 3;   /* Total Bits for current frame */
            rc->Hc = video->header_bits;    /* Total Bits in Header and Motion Vector */

            /* BX_RC */
            updateRateControl(rc, video);

            break;

        default: /* for case CBR_1/2, VBR_1/2 */

            return PV_FAIL;
    }


    return PV_SUCCESS;
}
AVCEnc_Status RCUpdateFrame(AVCEncObject *encvid)
{
    AVCCommonObj *video = encvid->common;
    AVCRateControl *rateCtrl = encvid->rateCtrl;
    AVCEnc_Status status = AVCENC_SUCCESS;
    MultiPass *pMP = rateCtrl->pMP;
    int diff_BTCounter;
    int nal_type = video->nal_unit_type;

    /* update the complexity weight of I, P, B frame */

    if (rateCtrl->rcEnable == TRUE)
    {
        pMP->actual_bits = rateCtrl->numFrameBits;
        pMP->mad = (OsclFloat)rateCtrl->totalSAD / video->PicSizeInMbs; //ComputeFrameMAD(video, rateCtrl);

        AVCSaveRDSamples(pMP, 0);

        pMP->encoded_frames++;

        /* for pMP->samplesPerFrame */
        pMP->samplesPerFrame[pMP->framePos] = 0;

        pMP->sum_QP += pMP->QP;

        /* update pMP->counter_BTsrc, pMP->counter_BTdst */
        /* re-allocate the target bit again and then stop encoding */
        diff_BTCounter = (int)((OsclFloat)(rateCtrl->TMN_TH - rateCtrl->TMN_W - pMP->actual_bits) /
                               (pMP->bitrate / (pMP->framerate + 0.0001) + 0.0001) / 0.1);
        if (diff_BTCounter >= 0)
            pMP->counter_BTsrc += diff_BTCounter; /* pMP->actual_bits is smaller */
        else
            pMP->counter_BTdst -= diff_BTCounter; /* pMP->actual_bits is bigger */

        rateCtrl->TMN_TH -= (int)((OsclFloat)pMP->bitrate / (pMP->framerate + 0.0001) * (diff_BTCounter * 0.1));
        rateCtrl->T = pMP->target_bits = rateCtrl->TMN_TH - rateCtrl->TMN_W;
        pMP->diff_counter -= diff_BTCounter;

        rateCtrl->Rc = rateCtrl->numFrameBits;  /* Total Bits for current frame */
        rateCtrl->Hc = rateCtrl->NumberofHeaderBits;    /* Total Bits in Header and Motion Vector */

        /* BX_RC */
        updateRateControl(rateCtrl, nal_type);
        if (rateCtrl->skip_next_frame == -1) // skip current frame
        {
            status = AVCENC_SKIPPED_PICTURE;
        }
    }

    rateCtrl->first_frame = 0;  // reset here after we encode the first frame.

    return status;
}