Home | History | Annotate | Download | only in src

Lines Matching refs:pMP

58     MultiPass **pMP = video->pMP;
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));
131 pMP[n]->counter_BTdst = pMP[n]->counter_BTsrc = 0;
136 pMP[n]->bitrate = rc[n]->bitrate;
137 pMP[n]->framerate = rc[n]->framerate;
138 pMP[n]->target_bits_per_frame = pMP[n]->bitrate / pMP[n]->framerate;
193 MultiPass *pMP = video->pMP[currLayer];
229 /* update pMP->framePos */
230 if (++pMP->framePos == pMP->frameRange) pMP->framePos = 0;
234 pMP->counter_BTdst = (Int)(video->encParams->LayerFrameRate[video->currLayer] * 7.5 + 0.5); /* 0.75s time frame */
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 */
237 pMP->counter_BTdst = PV_MIN(pMP->counter_BTdst, 20); /* Limit the target to be smaller than 3C */
239 pMP->target_bits = rc->T = rc->TMN_TH = (Int)(rc->TMN_TH * (1.0 + pMP->counter_BTdst * 0.1));
240 pMP->diff_counter = pMP->counter_BTdst;
244 pMP->target_bits = rc->T;
245 pMP->QP = currVop->quantizer;
247 pMP->mad = video->sumMAD / (float)currVol->nTotalMB;
248 if (pMP->mad < MAD_MIN) pMP->mad = MAD_MIN; /* MAD_MIN is defined as 1 in mp4def.h */
250 pMP->bitrate = rc->bitrate; /* calculated in RCVopQPSetting */
251 pMP->framerate = rc->framerate;
254 pMP->nRe_Quantized = 0;
271 Void SaveRDSamples(MultiPass *pMP, Int counter_samples)
273 /* for pMP->pRDSamples */
274 pMP->pRDSamples[pMP->framePos][counter_samples].QP = pMP->QP;
275 pMP->pRDSamples[pMP->framePos][counter_samples].actual_bits = pMP->actual_bits;
276 pMP->pRDSamples[pMP->framePos][counter_samples].mad = pMP->mad;
277 pMP->pRDSamples[pMP->framePos][counter_samples].R_D = (float)(pMP->actual_bits / (pMP->mad + 0.0001));
295 MultiPass *pMP = video->pMP[currLayer];
309 pMP->actual_bits = currVol->stream->byteCount << 3;
311 SaveRDSamples(pMP, 0);
313 pMP->encoded_frames++;
315 /* for pMP->samplesPerFrame */
316 pMP->samplesPerFrame[pMP->framePos] = 0;
318 pMP->sum_QP += pMP->QP;
321 /* update pMP->counter_BTsrc, pMP->counter_BTdst */
323 diff_BTCounter = (Int)((float)(rc->TMN_TH - rc->TMN_W - pMP->actual_bits) /
324 (pMP->bitrate / (pMP->framerate + 0.0001) + 0.0001) / 0.1);
326 pMP->counter_BTsrc += diff_BTCounter; /* pMP->actual_bits is smaller */
328 pMP->counter_BTdst -= diff_BTCounter; /* pMP->actual_bits is bigger */
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;
332 pMP->diff_counter -= diff_BTCounter;
386 MultiPass *pMP = video->pMP[currLayer];
388 if (video == NULL || rc == NULL || pMP == NULL)
392 pMP->counter_BTsrc += 10 * num_skip;
399 pMP->counter_BTsrc = pMP->counter_BTdst + (Int)((float)(rc->Bs / 2 - rc->low_bound) / 2.0 / (pMP->target_bits_per_frame / 10));
424 MultiPass **pMP = video->pMP;
448 rc[n]->bitrate = pMP[n]->bitrate = LayerBitRate[n];
449 rc[n]->framerate = pMP[n]->framerate = LayerFrameRate[n];
475 rc[n]->bitrate = pMP[n]->bitrate = LayerBitRate[n] - LayerBitRate[n-1];
476 rc[n]->framerate = pMP[n]->framerate = LayerFrameRate[n] - LayerFrameRate[n-1];
479 pMP[n]->target_bits_per_frame_prev = pMP[n]->target_bits_per_frame;
480 pMP[n]->target_bits_per_frame = pMP[n]->bitrate / (float)(pMP[n]->framerate + 0.0001); /* 7/31/03 */
483 /* update pMP[n]->counter_BTdst and pMP[n]->counter_BTsrc */
485 (pMP[n]->target_bits_per_frame / 10 + 0.0001)); /* 7/31/03 */
487 pMP[n]->counter_BTdst = pMP[n]->counter_BTsrc = 0;
489 pMP[n]->counter_BTdst = diff_counter;
492 pMP[n]->counter_BTsrc = -diff_counter;
495 (pMP[n]->target_bits_per_frame / 10) * (pMP[n]->counter_BTdst - pMP[n]->counter_BTsrc));
498 if (pMP[n]->aver_mad != 0)
500 pMP[n]->aver_mad_prev = pMP[n]->aver_mad;
501 pMP[n]->encoded_frames_prev = pMP[n]->encoded_frames;
504 pMP[n]->aver_mad = 0;
505 pMP[n]->overlapped_win_size = 4;
508 pMP[n]->sum_mad = pMP[n]->sum_QP = 0;
509 //pMP[n]->encoded_frames_prev = pMP[n]->encoded_frames;
510 pMP[n]->encoded_frames = pMP[n]->re_encoded_frames = pMP[n]->re_encoded_times = 0;
532 MultiPass *pMP = video->pMP[video->currLayer];
538 /* BT = Bit Transfer, for pMP->counter_BTsrc, pMP->counter_BTdst */
540 if (video == NULL || currVol == NULL || pMP == NULL || rc == NULL)
543 /* some stuff about frame dropping remained here to be done because pMP cannot be inserted into updateRateControl()*/
546 /* update pMP->counter_BTsrc and pMP->counter_BTdst to avoid interger overflow */
547 if (pMP->counter_BTsrc > 1000 && pMP->counter_BTdst > 1000)
549 pMP->counter_BTsrc -= 1000;
550 pMP->counter_BTdst -= 1000;
558 pMP->diff_counter = 0;
562 pMP->sum_mad += curr_mad;
563 //average_mad = (pMP->encoded_frames < 1 ? curr_mad : pMP->sum_mad/(float)(pMP->encoded_frames+1)); /* this function is called from the scond encoded frame*/
564 //pMP->aver_mad = average_mad;
565 if (pMP->encoded_frames >= 0) /* pMP->encoded_frames is set to -1 initially, so forget about the very first I frame */
566 pMP->aver_mad = (pMP->aver_mad * pMP->encoded_frames + curr_mad) / (pMP->encoded_frames + 1);
568 if (pMP->overlapped_win_size > 0 && pMP->encoded_frames_prev >= 0) /* 7/31/03 */
569 pMP->aver_mad_prev = (pMP->aver_mad_prev * pMP->encoded_frames_prev + curr_mad) / (pMP->encoded_frames_prev + 1);
572 if (pMP->overlapped_win_size == 0)
575 if (curr_mad > pMP->aver_mad*1.1)
577 if (curr_mad / (pMP->aver_mad + 0.0001) > 2)
578 diff_counter_BTdst = (Int)(M4VENC_SQRT(curr_mad / (pMP->aver_mad + 0.0001)) * 10 + 0.4) - 10;
579 //diff_counter_BTdst = (Int)((sqrt(curr_mad/pMP->aver_mad)*2+curr_mad/pMP->aver_mad)/(3*0.1) + 0.4) - 10;
581 diff_counter_BTdst = (Int)(curr_mad / (pMP->aver_mad + 0.0001) * 10 + 0.4) - 10;
584 //diff_counter_BTsrc = 10 - (Int)((sqrt(curr_mad/pMP->aver_mad) + pow(curr_mad/pMP->aver_mad, 1.0/3.0))/(2.0*0.1) + 0.4);
585 diff_counter_BTsrc = 10 - (Int)(M4VENC_SQRT(curr_mad / (pMP->aver_mad + 0.0001)) * 10 + 0.5);
586 //diff_counter_BTsrc = 10 - (Int)(curr_mad/pMP->aver_mad/0.1 + 0.5)
590 curr_mad <= pMP->aver_mad*1.1 && pMP->counter_BTsrc < pMP->counter_BTdst)
594 else if (pMP->overlapped_win_size > 0)
596 /* transition time: use previous average mad "pMP->aver_mad_prev" instead of the current average mad "pMP->aver_mad" */
597 if (curr_mad > pMP->aver_mad_prev*1.1)
599 if (curr_mad / pMP->aver_mad_prev > 2)
600 diff_counter_BTdst = (Int)(M4VENC_SQRT(curr_mad / (pMP->aver_mad_prev + 0.0001)) * 10 + 0.4) - 10;
601 //diff_counter_BTdst = (Int)((M4VENC_SQRT(curr_mad/pMP->aver_mad_prev)*2+curr_mad/pMP->aver_mad_prev)/(3*0.1) + 0.4) - 10;
603 diff_counter_BTdst = (Int)(curr_mad / (pMP->aver_mad_prev + 0.0001) * 10 + 0.4) - 10;
606 //diff_counter_BTsrc = 10 - (Int)((sqrt(curr_mad/pMP->aver_mad_prev) + pow(curr_mad/pMP->aver_mad_prev, 1.0/3.0))/(2.0*0.1) + 0.4);
607 diff_counter_BTsrc = 10 - (Int)(M4VENC_SQRT(curr_mad / (pMP->aver_mad_prev + 0.0001)) * 10 + 0.5);
608 //diff_counter_BTsrc = 10 - (Int)(curr_mad/pMP->aver_mad_prev/0.1 + 0.5)
612 curr_mad <= pMP->aver_mad_prev*1.1 && pMP->counter_BTsrc < pMP->counter_BTdst)
615 if (--pMP->overlapped_win_size <= 0) pMP->overlapped_win_size = 0;
621 bound = (Int)((rc->Bs / 2 - rc->VBV_fullness) * 0.6 / (pMP->target_bits_per_frame / 10)); /* rc->Bs */
635 prev_counter_diff = pMP->counter_BTdst - pMP->counter_BTsrc;
656 //rc->TMN_TH = (Int)((float)pMP->bitrate/pMP->framerate);
657 rc->TMN_TH = (Int)(pMP->target_bits_per_frame);
658 pMP->diff_counter = 0;
662 rc->TMN_TH -= (Int)(pMP->target_bits_per_frame * diff_counter_BTsrc * 0.1);
663 pMP->diff_counter = -diff_counter_BTsrc;
667 rc->TMN_TH += (Int)(pMP->target_bits_per_frame * diff_counter_BTdst * 0.1);
668 pMP->diff_counter = diff_counter_BTdst;
672 /*4.update pMP->counter_BTsrc, pMP->counter_BTdst */
673 pMP->counter_BTsrc += diff_counter_BTsrc;
674 pMP->counter_BTdst += diff_counter_BTdst;
702 MultiPass *pMP = video->pMP[video->currLayer];
711 if (video == NULL || currVol == NULL || pMP == NULL || rc == NULL)
731 prev_actual_bits = pMP->pRDSamples[0][0].actual_bits;
732 prev_mad = pMP->pRDSamples[0][0].mad;
734 for (i = 0, j = 0; i < pMP->frameRange; i++)
736 if (pMP->pRDSamples[i][0].mad != 0 && prev_mad != 0 &&
737 PV_ABS(prev_mad - curr_mad) > PV_ABS(pMP->pRDSamples[i][0].mad - curr_mad))
739 prev_mad = pMP
740 prev_actual_bits = pMP->pRDSamples[i][0].actual_bits;
744 prev_QP = pMP->pRDSamples[j][0].QP;
745 for (i = 1; i < pMP->samplesPerFrame[j]; i++)
747 if (PV_ABS(prev_actual_bits - curr_target) > PV_ABS(pMP->pRDSamples[j][i].actual_bits - curr_target))
749 prev_actual_bits = pMP->pRDSamples[j][i].actual_bits;
750 prev_QP = pMP->pRDSamples[j][i].QP;
784 aver_QP = (pMP->encoded_frames == 0 ? 0 : pMP->sum_QP / (float)pMP->encoded_frames);
785 average_mad = (pMP->encoded_frames == 0 ? 0 : pMP->sum_mad / (float)pMP->encoded_frames); /* this function is called from the scond encoded frame*/
786 if (pMP->diff_counter == 0 &&
788 pMP->counter_BTsrc <= (pMP->counter_BTdst + (Int)(pMP->framerate*1.0 + 0.5)))
790 rc->TMN_TH -= (Int)(pMP->target_bits_per_frame / 10.0);
792 pMP->counter_BTsrc++;
793 pMP->diff_counter--;
859 MultiPass *pMP = video->pMP[video->currLayer];
863 pMP->counter_BTsrc += 10 * rc->skip_next_frame;
868 pMP->counter_BTdst -= pMP->diff_counter;
869 pMP->counter_BTsrc += 10;
871 pMP->sum_mad -= pMP->mad;
872 pMP->aver_mad = (pMP->aver_mad * pMP->encoded_frames - pMP->mad) / (float)(pMP->encoded_frames - 1 + 0.0001);
873 pMP->sum_QP -= pMP->QP;
874 pMP->encoded_frames --;
882 pMP->counter_BTsrc = pMP->counter_BTdst + (Int)((float)(rc->Bs / 2 - rc->low_bound) / 2.0 / (pMP->target_bits_per_frame / 10));