Main Page | Class List | File List | Class Members | File Members

vid_ratectrl.c File Reference

#include "vid_sim.h"
#include "video_codec.h"
#include <math.h>

Go to the source code of this file.

Functions

void InitializeRateControl ()
void UpdateRateControl (int bits)
int InitializeQuantizer (int pict_type, float bit_rate, float target_frame_rate, float QP_mean)
int UpdateQuantizer (int mb, float QP_mean, int pict_type, float bit_rate, int mb_width, int mb_height, int bitcount)

Variables

video_codecVidSt


Function Documentation

int InitializeQuantizer int  pict_type,
float  bit_rate,
float  target_frame_rate,
float  QP_mean
 

Definition at line 95 of file vid_ratectrl.c.

References video_codec::B_prev, video_codec::B_target, video_codec::global_adj, mmax, mmin, and VidSt.

Referenced by CodeOneOrTwo().

00100                                                                 :  */
00101 /* int bitcount;                                               */
00102 /* AddBitsPicture(bits);                                       */
00103 /* bitcount = bits->total;                                     */
00104 
00105 {
00106   int newQP;
00107 
00108   if (pict_type == PCT_INTER) {
00109 
00110     (VidSt->B_target) = bit_rate / target_frame_rate;
00111 
00112     /* compute picture buffer descrepency as of the previous picture */
00113 
00114     if ((VidSt->B_prev) != 0.0) {
00115       (VidSt->global_adj) = ((VidSt->B_prev) - (VidSt->B_target)) / (2*(VidSt->B_target));
00116     }
00117     else {
00118       (VidSt->global_adj) = (float)0.0;
00119     }
00120     newQP = (int)(QP_mean * (1 + (VidSt->global_adj)) + (float)0.5);
00121     newQP = mmax(1,mmin(31,newQP));  
00122   }
00123   else if (pict_type == PCT_INTRA) {
00124     fprintf(stderr,"No need to call InititializeQuantizer() for Intra picture\n");
00125     exit(-1);
00126   }
00127   else  {
00128     fprintf(stderr,"Error (InitializePictureRate): picture type unkown.\n");
00129     exit(-1);
00130   }  
00131 #if 1
00132   printf("Global adj = %.2f\n", (VidSt->global_adj));
00133   printf("meanQP = %.2f   newQP = %d\n", QP_mean, newQP);
00134 #endif
00135   fprintf(stdout,"Target no. of bits: %.2f\n", (VidSt->B_target));
00136 
00137   return newQP;
00138 }

void InitializeRateControl  ) 
 

Definition at line 85 of file vid_ratectrl.c.

References video_codec::B_prev, and VidSt.

Referenced by code_video().

00086 {
00087   (VidSt->B_prev) = (float)0.0;
00088 }

int UpdateQuantizer int  mb,
float  QP_mean,
int  pict_type,
float  bit_rate,
int  mb_width,
int  mb_height,
int  bitcount
 

Definition at line 168 of file vid_ratectrl.c.

References video_codec::B_target, bitcount(), video_codec::global_adj, mmax, mmin, and VidSt.

Referenced by CodeOneOrTwo().

00175 {
00176   int newQP=16;
00177   float local_adj, descrepency, projection;
00178   
00179   if (pict_type == PCT_INTRA) {
00180     newQP = 16;         /* Changed from newQP = 16;, BD 8/27/96 */
00181   }
00182   else if (pict_type == PCT_INTER) {
00183     /* compute expected buffer fullness */
00184     
00185     projection = mb * ((VidSt->B_target) / (mb_width*mb_height));
00186     
00187     /* measure descrepency between current fullness and projection */
00188     descrepency= (bitcount - projection);
00189     
00190     /* scale */
00191     
00192     local_adj = 12 * descrepency / bit_rate;
00193     
00194 #if(0)
00195     printf("mb = %d\n",mb);
00196     printf("bit_count = %d projection = %.2f \n",bitcount,projection);
00197     printf("B_target = %.2f local_adj = %.2f \n",(VidSt->B_target),local_adj);
00198 #endif
00199     
00200     newQP = (int)(QP_mean * (1 + (VidSt->global_adj) + local_adj) + 0.5);
00201     
00202   /* the update equation for newQP in TMN4 document section 3.7 */
00203 
00204   }
00205   else  {
00206     fprintf(stderr,"Error (UpdateQuantizer): picture type unkown.\n");
00207   }
00208   
00209 #if(0)
00210   printf("mb = %d  newQP = %d \n",mb,newQP);
00211 #endif 
00212 
00213   newQP = mmax(1,mmin(31,newQP));
00214   return newQP;
00215 }

void UpdateRateControl int  bits  ) 
 

Definition at line 90 of file vid_ratectrl.c.

References video_codec::B_prev, and VidSt.

Referenced by code_video().

00091 {
00092   (VidSt->B_prev) = (float)bits;
00093 }


Variable Documentation

video_codec* VidSt
 

Definition at line 16 of file vid_wrapper.c.


Generated on Sun Jul 16 16:27:48 2006 by  doxygen 1.3.9.1