Lines Matching refs:rc

27 void updateRateControl(rateControl *rc, VideoEncData *video);
28 void updateRC_PostProc(rateControl *rc, VideoEncData *video);
34 PV_STATUS RC_Cleanup(rateControl *rc[],Int numLayers);
35 PV_STATUS RC_VopQPSetting(VideoEncData *video,rateControl *rc[]);
36 PV_STATUS RC_VopUpdateStat(VideoEncData *video,rateControl *rc[]);
54 rateControl **rc = video->rc;
65 rc[n]->fine_frame_skip = encParams->FineFrameSkip_Enabled;
66 rc[n]->no_frame_skip = encParams->NoFrameSkip_Enabled;
67 rc[n]->no_pre_skip = encParams->NoPreSkip_Enabled;
68 rc[n]->skip_next_frame = 0; /* must be initialized */
70 //rc[n]->TMN_TH = (Int)((float)LayerBitRate[n]/LayerFrameRate[n]);
71 rc[n]->Bs = video->encParams->BufferSize[n];
72 rc[n]->TMN_W = 0;
73 rc[n]->VBV_fullness = (Int)(rc[n]->Bs * 0.5); /* rc[n]->Bs */
74 rc[n]->encoded_frames = 0;
75 rc[n]->framerate = LayerFrameRate[n];
78 rc[n]->TMN_TH = (Int)((float)LayerBitRate[n] / LayerFrameRate[n]);
79 rc[n]->bitrate = LayerBitRate[n];
80 rc[n]->framerate = LayerFrameRate[n];
85 rc[n]->max_BitVariance_num = (Int)((rc[n]->Bs - video->encParams->maxFrameSize) / 2 / (rc[n]->bitrate / rc[n]->framerate / 10.0)) - 5;
86 if (rc[n]->max_BitVariance_num < 0) rc[n]->max_BitVariance_num += 5;
90 rc[n]->max_BitVariance_num = (Int)((float)(rc[n]->Bs - rc[n]->VBV_fullness) / ((float)LayerBitRate[n] / LayerFrameRate[n] / 10.0)) - 5;
91 if (rc[n]->max_BitVariance_num < 0) rc[n]->max_BitVariance_num += 5;
98 rc[n]->TMN_TH = (Int)((float)(LayerBitRate[n] - LayerBitRate[n-1]) / (LayerFrameRate[n] - LayerFrameRate[n-1]));
99 rc[n]->max_BitVariance_num = (Int)((float)(rc[n]->Bs - rc[n]->VBV_fullness) * 10 / ((float)rc[n]->TMN_TH)) - 5;
100 if (rc[n]->max_BitVariance_num < 0) rc[n]->max_BitVariance_num += 5;
104 rc[n]->TMN_TH = 1 << 30;
105 rc[n]->max_BitVariance_num = 0;
107 rc[n]->bitrate = LayerBitRate[n] - LayerBitRate[n-1];
108 rc[n]->framerate = LayerFrameRate[n] - LayerFrameRate[n-1];
115 rc[n]->VBV_fullness = (Int)(rc[n]->Bs / 3.0 - rc[n]->Bs / 2.0); /* the buffer range is [-Bs/2, Bs/2] */
116 pMP[n]->counter_BTsrc = (Int)((rc[n]->Bs / 2.0 - rc[n]->Bs / 3.0) / (rc[n]->bitrate / rc[n]->framerate / 10.0));
117 rc[n]->TMN_W = (Int)(rc[n]->VBV_fullness + pMP[n]->counter_BTsrc * (rc[n]->bitrate / rc[n]->framerate / 10.0));
119 rc[n]->low_bound = -rc[n]->Bs / 2;
120 rc[n]-> VBV_fullness_offset = 0;
124 rc[n]->VBV_fullness = rc[n]->Bs - (Int)(video->encParams->VBV_delay * rc[n]->bitrate);
125 if (rc[n]->VBV_fullness < 0) rc[n]->VBV_fullness = 0;
126 //rc[n]->VBV_fullness = (rc[n]->Bs-video->encParams->maxFrameSize)/2 + video->encParams->maxFrameSize;
128 rc[n]->VBV_fullness -= rc[n]->Bs / 2; /* the buffer range is [-Bs/2, Bs/2] */
129 rc[n]->low_bound = -rc[n]->Bs / 2 + video->encParams->maxFrameSize; /* too high */
130 rc[n]->VBV_fullness_offset = video->encParams->maxFrameSize / 2; /* don't understand the meaning of this */
136 pMP[n]->bitrate = rc[n]->bitrate;
137 pMP[n]->framerate = rc[n]->framerate;
156 PV_STATUS RC_Cleanup(rateControl *rc[], Int numLayers)
158 OSCL_UNUSED_ARG(rc);
171 reset QPMB[], currVop->quantizer, rc->Ec, video->header_bits */
192 rateControl *rc = video->rc[currLayer];
205 if (video->rc[currLayer]->encoded_frames == 0) /* rc[currLayer]->totalFrameNumber*/
208 video->rc[currLayer]->Qc = video->encParams->InitQuantIvop[currLayer];
213 currVop->quantizer = video->rc[currLayer]->Qc;
232 if (rc->T == 0)
235 pMP->counter_BTdst = PV_MIN(pMP->counter_BTdst, (Int)(rc->max_BitVariance_num / 2 * 0.40)); /* 0.75s time frame may go beyond VBV buffer if we set the buffer size smaller than 0.75s */
236 pMP->counter_BTdst = PV_MAX(pMP->counter_BTdst, (Int)((rc->Bs / 2 - rc->VBV_fullness) * 0.30 / (rc->TMN_TH / 10.0) + 0.5)); /* At least 30% of VBV buffer size/2 */
239 pMP->target_bits = rc->T = rc->TMN_TH = (Int)(rc->TMN_TH * (1.0 + pMP->counter_BTdst * 0.1));
244 pMP->target_bits = rc->T;
250 pMP->bitrate = rc->bitrate; /* calculated in RCVopQPSetting */
251 pMP->framerate = rc->framerate;
291 PV_STATUS RC_VopUpdateStat(VideoEncData *video, rateControl *rc)
323 diff_BTCounter = (Int)((float)(rc->TMN_TH - rc->TMN_W - pMP->actual_bits) /
330 rc->TMN_TH -= (Int)((float)pMP->bitrate / (pMP->framerate + 0.0001) * (diff_BTCounter * 0.1));
331 rc->T = pMP->target_bits = rc->TMN_TH - rc->TMN_W;
334 rc->Rc = currVol->stream->byteCount << 3; /* Total Bits for current frame */
335 rc->Hc = video->header_bits; /* Total Bits in Header and Motion Vector */
338 updateRateControl(rc, video);
362 return video->rc[currLayer]->skip_next_frame;
368 video->rc[currLayer]->skip_next_frame = 0;
385 rateControl *rc = video->rc[currLayer];
388 if (video == NULL || rc == NULL || pMP == NULL)
391 rc->VBV_fullness -= (Int)(rc->bitrate / rc->framerate * num_skip); //rc[currLayer]->Rp;
395 if (rc->VBV_fullness < rc->low_bound)
397 rc->VBV_fullness = rc->low_bound; // -rc->Bs/2;
398 rc->TMN_W = rc->VBV_fullness - rc->low_bound;
399 pMP->counter_BTsrc = pMP->counter_BTdst + (Int)((float)(rc->Bs / 2 - rc->low_bound) / 2.0 / (pMP->target_bits_per_frame / 10));
420 rateControl **rc = video->rc;
438 updateRC_PostProc(rc[n], video);
439 rc[n]->skip_next_frame = 0; /* must be initialized */
442 rc[n]->Bs = video->encParams->BufferSize[n];
443 VBV_fullness = (Int)(rc[n]->Bs * 0.5);
447 rc[n]->TMN_TH = (Int)((float)LayerBitRate[n] / LayerFrameRate[n]);
448 rc[n]->bitrate = pMP[n]->bitrate = LayerBitRate[n];
449 rc[n]->framerate = pMP[n]->framerate = LayerFrameRate[n];
454 rc[n]->max_BitVariance_num = (Int)((rc[n]->Bs - video->encParams->maxFrameSize) / 2 / (rc[n]->bitrate / rc[n]->framerate / 10.0)) - 5;
455 //rc[n]->max_BitVariance_num = (Int)((float)(rc[n]->Bs - rc[n]->VBV_fullness)/((float)LayerBitRate[n]/LayerFrameRate[n]/10.0))-5;
459 rc[n]->max_BitVariance_num = (Int)((float)(rc[n]->Bs - VBV_fullness) * 10 / ((float)LayerBitRate[n] / LayerFrameRate[n])) - 5;
466 rc[n]->TMN_TH = (Int)((float)(LayerBitRate[n] - LayerBitRate[n-1]) / (LayerFrameRate[n] - LayerFrameRate[n-1]));
467 rc[n]->max_BitVariance_num = (Int)((float)(rc[n]->Bs - VBV_fullness) * 10 / ((float)rc[n]->TMN_TH)) - 5;
468 if (rc[n]->max_BitVariance_num < 0) rc[n]->max_BitVariance_num += 5;
472 rc[n]->TMN_TH = 1 << 30;
473 rc[n]->max_BitVariance_num = 0;
475 rc[n]->bitrate = pMP[n]->bitrate = LayerBitRate[n] - LayerBitRate[n-1];
476 rc[n]->framerate = pMP[n]->framerate = LayerFrameRate[n] - LayerFrameRate[n-1];
482 /* rc[n]->VBV_fullness and rc[n]->TMN_W should be kept same */
484 diff_counter = (Int)((float)(rc[n]->VBV_fullness - rc[n]->TMN_W) /
494 rc[n]->TMN_W = (Int)(rc[n]->VBV_fullness - /* re-calculate rc[n]->TMN_W in order for higher accuracy */
524 /* In/out : rc->T */
534 rateControl *rc = video->rc[video->currLayer];
540 if (video == NULL || currVol == NULL || pMP == NULL || rc == NULL)
544 updateRC_PostProc(rc, video);
621 bound = (Int)((rc->Bs / 2 - rc->VBV_fullness) * 0.6 / (pMP->target_bits_per_frame / 10)); /* rc->Bs */
638 if (PV_ABS(prev_counter_diff) >= rc->max_BitVariance_num || PV_ABS(curr_counter_diff) >= rc->max_BitVariance_num) // PV_ABS(curr_counter_diff) >= PV_ABS(prev_counter_diff) )
641 if (curr_counter_diff > rc->max_BitVariance_num && diff_counter_BTdst)
643 diff_counter_BTdst = (rc->max_BitVariance_num - prev_counter_diff) + diff_counter_BTsrc;
647 else if (curr_counter_diff < -rc->max_BitVariance_num && diff_counter_BTsrc)
649 diff_counter_BTsrc = diff_counter_BTdst - (-rc->max_BitVariance_num - prev_counter_diff);
656 //rc->TMN_TH = (Int)((float)pMP->bitrate/pMP->framerate);
657 rc->TMN_TH = (Int)(pMP->target_bits_per_frame);
662 rc->TMN_TH -= (Int)(pMP->target_bits_per_frame * diff_counter_BTsrc * 0.1);
667 rc->TMN_TH += (Int)(pMP->target_bits_per_frame * diff_counter_BTdst * 0.1);
678 rc->T = rc->TMN_TH - rc->TMN_W;
679 //rc->T = rc->TMN_TH - (Int)((float)rc->TMN_W/rc->frameRate);
681 if (video->encParams->H263_Enabled && rc->T > video->encParams->maxFrameSize)
683 rc->T = video->encParams->maxFrameSize; // added this 11/07/05
693 /* In/out : rc->T and rc->Qc */
704 rateControl *rc = video->rc[video->currLayer];
711 if (video == NULL || currVol == NULL || pMP == NULL || rc == NULL)
717 if (rc->T <= 0 || video->sumMAD == 0)
719 if (rc->T < 0) rc->Qc = 31;
725 curr_target = rc->T;
756 //rc->Qc = (Int)(prev_QP * sqrt(prev_actual_bits/curr_target) + 0.4);
759 rc->Qc = (Int)(prev_RD / curr_RD + 0.5);
763 rc->Qc = (Int)(prev_QP * M4VENC_SQRT(prev_RD / curr_RD) + 0.9);
766 rc->Qc = (Int)(prev_QP * (M4VENC_SQRT(prev_RD / curr_RD) + prev_RD / curr_RD) / 2.0 + 0.9); /* Quadratic and linear approximation */
768 rc->Qc = (Int)(prev_QP * (M4VENC_SQRT(prev_RD / curr_RD) + M4VENC_POW(prev_RD / curr_RD, 1.0 / 3.0)) / 2.0 + 0.9);
770 //rc->Qc =(Int)(prev_QP * sqrt(prev_RD/curr_RD) + 0.4);
776 /// if((curr_mad < 8) && (rc->Qc < 12)) rc->Qc = 12;
777 // else if((curr_mad < 128) && (rc->Qc < 3)) rc->Qc = 3;
779 if (rc->Qc < 1) rc->Qc = 1;
780 if (rc->Qc > 31) rc->Qc = 31;
787 ((float)rc->Qc <= aver_QP*1.1 || curr_mad <= average_mad*1.1) &&
790 rc->TMN_TH -= (Int)(pMP->target_bits_per_frame / 10.0);
791 rc->T = rc->TMN_TH - rc->TMN_W;
808 void updateRateControl(rateControl *rc, VideoEncData *video)
814 frame_bits = (Int)(rc->bitrate / rc->framerate);
815 rc->TMN_W += (rc->Rc - rc->TMN_TH);
816 rc->VBV_fullness += (rc->Rc - frame_bits); //rc->Rp);
817 //if(rc->VBV_fullness < 0) rc->VBV_fullness = -1;
819 rc->encoded_frames++;
822 rc->skip_next_frame = 0;
824 if ((video->encParams->H263_Enabled && rc->Rc > video->encParams->maxFrameSize) || /* For H263/short header mode, drop the frame if the actual frame size exceeds the bound */
825 (rc->VBV_fullness > rc->Bs / 2 && !rc->no_pre_skip)) /* skip the current frame */ /* rc->Bs */
827 rc->TMN_W -= (rc->Rc - rc->TMN_TH);
828 rc->VBV_fullness -= rc->Rc;
829 rc->skip_next_frame = -1;
831 else if ((float)(rc->VBV_fullness - rc->VBV_fullness_offset) > (rc->Bs / 2 - rc->VBV_fullness_offset)*0.95 &&
832 !rc->no_frame_skip) /* skip next frame */
834 rc->VBV_fullness -= frame_bits; //rc->Rp;
835 rc->skip_next_frame = 1;
837 //while(rc->VBV_fullness > rc->Bs*0.475)
838 while ((rc->VBV_fullness - rc->VBV_fullness_offset) > (rc->Bs / 2 - rc->VBV_fullness_offset)*0.95)
840 rc->VBV_fullness -= frame_bits; //rc->Rp;
841 rc->skip_next_frame++;
857 void updateRC_PostProc(rateControl *rc, VideoEncData *video)
861 if (rc->skip_next_frame == 1 && !rc->no_frame_skip) /* skip next frame */
863 pMP->counter_BTsrc += 10 * rc->skip_next_frame;
866 else if (rc->skip_next_frame == -1 && !rc->no_pre_skip) /* skip current frame */
877 //if(rc->VBV_fullness < -rc->Bs/2) /* rc->Bs */
878 if (rc->VBV_fullness < rc->low_bound)
880 rc->VBV_fullness = rc->low_bound; // -rc->Bs/2;
881 rc->TMN_W = rc->VBV_fullness - rc->low_bound;
882 pMP->counter_BTsrc = pMP->counter_BTdst + (Int)((float)(rc->Bs / 2 - rc->low_bound) / 2.0 / (pMP->target_bits_per_frame / 10));