w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rate.c File Reference
#include <sys/times.h>
#include "all.h"
#include "mtypes.h"
#include "bitio.h"
#include "frames.h"
#include "prototypes.h"
#include "param.h"
#include "mheaders.h"
#include "fsize.h"
#include "postdct.h"
#include "mpeg.h"
#include "parallel.h"
#include "dct.h"
#include "rate.h"
Include dependency graph for rate.c:

Go to the source code of this file.

Macros

#define MAX_BIT_RATE   104857600 /* 18 digit number in units of 400 */
 
#define MAX_BUFFER_SIZE   16760832 /* 10 digit number in units of 16k */
 
#define DEFAULT_BUFFER_SIZE   327680 /* maximun for "constrained" bitstream */
 
#define DEFAULT_VBV_FULLNESS   3 /* wait till 1/3 full */
 
#define DEFAULT_PICT_RATE_CODE   5 /* code for 30 Frames/sec */
 
#define DEFAULT_PICT_RATE   30 /* 30 frames per second */
 
#define MAX_VBV_DELAY   32768 /* 16 digits */
 

Functions

int initGOPRateControl (void)
 
int determineMBCount (void)
 
void checkBufferFullness (int count)
 
void checkSpatialActivity (Block blk0, Block blk1, Block blk2, Block blk3)
 
void incNumBlocks (int num)
 
void calculateVBVDelay (int num)
 
void updateVBVBuffer (int frameBits)
 
int BlockExperiments (int16 *OrigBlock, int16 *NewBlock, int control)
 
int initRateControl ()
 
void targetRateControl (MpegFrame *frame)
 
void updateRateControl (int type)
 
void MB_RateOut (int type)
 
void incMacroBlockBits (int num)
 
int needQScaleChange (int oldQScale, Block blk0, Block blk1, Block blk2, Block blk3)
 
int getRateMode ()
 
void setBitRate (char *charPtr)
 
int getBitRate ()
 
void setBufferSize (char *charPtr)
 
int getBufferSize ()
 

Variables

static int RateControlMode = 0
 
static int32 buffer_size = 327680
 
static int32 bit_rate = -1
 
static int32 VBV_delay =0
 
static int32 VBV_buffer = 0
 
static int32 bufferFillRate = 0
 
static int32 frameDelayIncrement = 0
 
static int Xi
 
static int Xp
 
static int Xb
 
static int Si
 
static int Sp
 
static int Sb
 
static float Qi
 
static float Qp
 
static float Qb
 
int Ti
 
int Tp
 
int Tb
 
int current_Tx
 
int GOP_X = 0
 
int GOP_I = 0
 
int GOP_P = 0
 
int GOP_B = 0
 
int Nx = 0
 
int Ni = 0
 
int Np = 0
 
int Nb = 0
 
int rc_numBlocks = 0
 
int rc_totalQuant = 0
 
int rc_bitsThisMB
 
int rc_totalMBBits
 
int rc_totalFrameBits
 
int rc_totalOverheadBits = 0
 
int RC_MB_SAMPLE_RATE = 0
 
static float Ki = .7
 
static float Kp = 1
 
static float Kb = 1.4
 
static int rc_R
 
static int rc_G
 
static int d0_i
 
static int d0_p
 
static int d0_b
 
static int lastFrameVirtBuf
 
static int currentVirtBuf
 
static int MB_cnt = -1
 
static int rc_Q
 
static int reactionParameter
 
static int act_j
 
static float N_act
 
static int avg_act
 
static int total_act_j
 
static int var_sblk
 
static int P_mean
 
static int mquant
 
static int Qscale
 
static char * Frame_header1 = " Fm # Bit GOP V "
 
static char * Frame_header2 = " # type MBs Alloc left Ni Np Nb N_act buff Q_rc Qscale"
 
static char * Frame_header3 = "---- - ---- ------ ------- -- -- -- ----- ------ ---- ----"
 
static char * Frame_trailer1 = " avg virt % GOP % VBV"
 
static char * Frame_trailer2 = " Sx Qx Xx act N_act buffer alloc left left buf delay"
 
static char * Frame_trailer3 = "------ --.-- ------- --- --.-- ------- --- ------- --- ------- ------"
 
static char * MB_header1 = "MB# #bits Q mqt Dj Q_j actj N_act totbits b/MB %alloc %done"
 
static char * MB_header2 = "--- ----- -- --- ------ --- ----- --.-- ------ ---- --- ---"
 
static char rc_buffer [101]
 
char * framePattern
 
int framePatternLen
 

Macro Definition Documentation

◆ DEFAULT_BUFFER_SIZE

#define DEFAULT_BUFFER_SIZE   327680 /* maximun for "constrained" bitstream */

Definition at line 73 of file rate.c.

◆ DEFAULT_PICT_RATE

#define DEFAULT_PICT_RATE   30 /* 30 frames per second */

Definition at line 76 of file rate.c.

◆ DEFAULT_PICT_RATE_CODE

#define DEFAULT_PICT_RATE_CODE   5 /* code for 30 Frames/sec */

Definition at line 75 of file rate.c.

◆ DEFAULT_VBV_FULLNESS

#define DEFAULT_VBV_FULLNESS   3 /* wait till 1/3 full */

Definition at line 74 of file rate.c.

◆ MAX_BIT_RATE

#define MAX_BIT_RATE   104857600 /* 18 digit number in units of 400 */

Definition at line 71 of file rate.c.

◆ MAX_BUFFER_SIZE

#define MAX_BUFFER_SIZE   16760832 /* 10 digit number in units of 16k */

Definition at line 72 of file rate.c.

◆ MAX_VBV_DELAY

#define MAX_VBV_DELAY   32768 /* 16 digits */

Definition at line 77 of file rate.c.

Function Documentation

◆ BlockExperiments()

int BlockExperiments ( int16 OrigBlock,
int16 NewBlock,
int  control 
)

◆ calculateVBVDelay()

void calculateVBVDelay ( int  num)

◆ checkBufferFullness()

void checkBufferFullness ( int  count)

◆ checkSpatialActivity()

void checkSpatialActivity ( Block  blk0,
Block  blk1,
Block  blk2,
Block  blk3 
)

Definition at line 724 of file rate.c.

References act_j, avg_act, DCTSIZE_SQ, i, j, N_act, P_mean, printf(), temp, total_act_j, and var_sblk.

Referenced by needQScaleChange().

◆ determineMBCount()

int determineMBCount ( void  )

Definition at line 668 of file rate.c.

References Fsize_x, Fsize_y, cordic::x, and y.

Referenced by targetRateControl().

◆ getBitRate()

int getBitRate ( )

Definition at line 863 of file rate.c.

References bit_rate.

Referenced by GenMPEGStream(), and PrintStartStats().

◆ getBufferSize()

int getBufferSize ( )

Definition at line 916 of file rate.c.

References buffer_size.

Referenced by GenMPEGStream(), and PrintStartStats().

◆ getRateMode()

int getRateMode ( )

Definition at line 806 of file rate.c.

References RateControlMode.

Referenced by GenBFrame(), GenIFrame(), GenMPEGStream(), GenPFrame(), and PrintStartStats().

◆ incMacroBlockBits()

void incMacroBlockBits ( int  num)

Definition at line 609 of file rate.c.

References num, rc_bitsThisMB, rc_totalFrameBits, and rc_totalMBBits.

Referenced by GenBFrame(), GenIFrame(), and GenPFrame().

◆ incNumBlocks()

void incNumBlocks ( int  num)

Definition at line 588 of file rate.c.

References num, and rc_numBlocks.

◆ initGOPRateControl()

int initGOPRateControl ( void  )

Definition at line 312 of file rate.c.

References avg_act, bit_rate, buffer_size, d0_b, d0_i, d0_p, DBG_PRINT, frameRateRounded, GOP_B, GOP_I, GOP_P, GOP_X, mquant, Nb, Ni, Np, Nx, rc_G, rc_Q, rc_R, Xb, Xi, and Xp.

Referenced by initRateControl(), and targetRateControl().

◆ initRateControl()

◆ MB_RateOut()

◆ needQScaleChange()

int needQScaleChange ( int  oldQScale,
Block  blk0,
Block  blk1,
Block  blk2,
Block  blk3 
)

◆ setBitRate()

void setBitRate ( char *  charPtr)

Definition at line 827 of file rate.c.

References atoi(), bit_rate, DBG_PRINT, FIXED_RATE, MAX_BIT_RATE, printf(), RateControlMode, rnd, and VARIABLE_RATE.

Referenced by ReadParamFile().

◆ setBufferSize()

void setBufferSize ( char *  charPtr)

Definition at line 885 of file rate.c.

References atoi(), buffer_size, DBG_PRINT, DEFAULT_BUFFER_SIZE, MAX_BUFFER_SIZE, printf(), and size.

Referenced by ReadParamFile().

◆ targetRateControl()

◆ updateRateControl()

◆ updateVBVBuffer()

void updateVBVBuffer ( int  frameBits)

Definition at line 938 of file rate.c.

References buffer_size, bufferFillRate, fprintf, frameDelayIncrement, VBV_buffer, and VBV_delay.

Referenced by updateRateControl().

Variable Documentation

◆ act_j

int act_j
static

Definition at line 152 of file rate.c.

Referenced by checkSpatialActivity(), and MB_RateOut().

◆ avg_act

int avg_act
static

◆ bit_rate

int32 bit_rate = -1
static

Definition at line 84 of file rate.c.

Referenced by getBitRate(), initGOPRateControl(), initRateControl(), setBitRate(), and targetRateControl().

◆ buffer_size

◆ bufferFillRate

int32 bufferFillRate = 0
static

Definition at line 90 of file rate.c.

Referenced by initRateControl(), and updateVBVBuffer().

◆ current_Tx

int current_Tx

Definition at line 103 of file rate.c.

Referenced by checkBufferFullness(), MB_RateOut(), targetRateControl(), and updateRateControl().

◆ currentVirtBuf

int currentVirtBuf
static

Definition at line 143 of file rate.c.

Referenced by checkBufferFullness(), MB_RateOut(), and updateRateControl().

◆ d0_b

int d0_b
static

Definition at line 140 of file rate.c.

Referenced by initGOPRateControl(), initRateControl(), targetRateControl(), and updateRateControl().

◆ d0_i

int d0_i
static

Definition at line 138 of file rate.c.

Referenced by initGOPRateControl(), initRateControl(), targetRateControl(), and updateRateControl().

◆ d0_p

int d0_p
static

Definition at line 139 of file rate.c.

Referenced by initGOPRateControl(), initRateControl(), targetRateControl(), and updateRateControl().

◆ Frame_header1

char* Frame_header1 = " Fm # Bit GOP V "
static

Definition at line 170 of file rate.c.

Referenced by targetRateControl().

◆ Frame_header2

char* Frame_header2 = " # type MBs Alloc left Ni Np Nb N_act buff Q_rc Qscale"
static

Definition at line 171 of file rate.c.

Referenced by targetRateControl().

◆ Frame_header3

char* Frame_header3 = "---- - ---- ------ ------- -- -- -- ----- ------ ---- ----"
static

Definition at line 172 of file rate.c.

Referenced by targetRateControl().

◆ Frame_trailer1

char* Frame_trailer1 = " avg virt % GOP % VBV"
static

Definition at line 173 of file rate.c.

Referenced by updateRateControl().

◆ Frame_trailer2

char* Frame_trailer2 = " Sx Qx Xx act N_act buffer alloc left left buf delay"
static

Definition at line 174 of file rate.c.

Referenced by updateRateControl().

◆ Frame_trailer3

char* Frame_trailer3 = "------ --.-- ------- --- --.-- ------- --- ------- --- ------- ------"
static

Definition at line 175 of file rate.c.

Referenced by updateRateControl().

◆ frameDelayIncrement

int32 frameDelayIncrement = 0
static

Definition at line 91 of file rate.c.

Referenced by initRateControl(), and updateVBVBuffer().

◆ framePattern

char* framePattern
extern

Definition at line 201 of file mpeg.c.

Referenced by initRateControl(), and PrintStartStats().

◆ framePatternLen

int framePatternLen
extern

Definition at line 202 of file mpeg.c.

Referenced by initRateControl().

◆ GOP_B

int GOP_B = 0

Definition at line 109 of file rate.c.

Referenced by initGOPRateControl(), and initRateControl().

◆ GOP_I

int GOP_I = 0

Definition at line 107 of file rate.c.

Referenced by initGOPRateControl(), and initRateControl().

◆ GOP_P

int GOP_P = 0

Definition at line 108 of file rate.c.

Referenced by initGOPRateControl(), and initRateControl().

◆ GOP_X

int GOP_X = 0

Definition at line 106 of file rate.c.

Referenced by initGOPRateControl(), and initRateControl().

◆ Kb

float Kb = 1.4
static

Definition at line 131 of file rate.c.

Referenced by initRateControl(), and targetRateControl().

◆ Ki

float Ki = .7
static

Definition at line 129 of file rate.c.

Referenced by targetRateControl().

◆ Kp

float Kp = 1
static

Definition at line 130 of file rate.c.

Referenced by initRateControl(), and targetRateControl().

◆ lastFrameVirtBuf

int lastFrameVirtBuf
static

Definition at line 142 of file rate.c.

Referenced by checkBufferFullness(), initRateControl(), and targetRateControl().

◆ MB_cnt

int MB_cnt = -1
static

Definition at line 145 of file rate.c.

Referenced by checkBufferFullness(), MB_RateOut(), targetRateControl(), and updateRateControl().

◆ MB_header1

char* MB_header1 = "MB# #bits Q mqt Dj Q_j actj N_act totbits b/MB %alloc %done"
static

Definition at line 177 of file rate.c.

Referenced by targetRateControl().

◆ MB_header2

char* MB_header2 = "--- ----- -- --- ------ --- ----- --.-- ------ ---- --- ---"
static

Definition at line 178 of file rate.c.

Referenced by targetRateControl().

◆ mquant

int mquant
static

◆ N_act

float N_act
static

◆ Nb

int Nb = 0

Definition at line 114 of file rate.c.

Referenced by initGOPRateControl(), targetRateControl(), and updateRateControl().

◆ Ni

int Ni = 0

Definition at line 112 of file rate.c.

Referenced by initGOPRateControl(), targetRateControl(), and updateRateControl().

◆ Np

◆ Nx

int Nx = 0

◆ P_mean

int P_mean
static

Definition at line 158 of file rate.c.

Referenced by checkSpatialActivity().

◆ Qb

float Qb
static

Definition at line 98 of file rate.c.

Referenced by updateRateControl().

◆ Qi

float Qi
static

Definition at line 98 of file rate.c.

Referenced by updateRateControl().

◆ Qp

float Qp
static

Definition at line 98 of file rate.c.

Referenced by updateRateControl().

◆ Qscale

int Qscale
static

Definition at line 161 of file rate.c.

Referenced by MB_RateOut(), needQScaleChange(), and targetRateControl().

◆ RateControlMode

int RateControlMode = 0
static

Definition at line 82 of file rate.c.

Referenced by getRateMode(), initRateControl(), and setBitRate().

◆ rc_bitsThisMB

int rc_bitsThisMB

Definition at line 120 of file rate.c.

Referenced by incMacroBlockBits(), initRateControl(), MB_RateOut(), and updateRateControl().

◆ rc_buffer

char rc_buffer[101]
static

Definition at line 180 of file rate.c.

Referenced by MB_RateOut(), targetRateControl(), and updateRateControl().

◆ rc_G

int rc_G
static

Definition at line 133 of file rate.c.

Referenced by initGOPRateControl(), initRateControl(), and updateRateControl().

◆ RC_MB_SAMPLE_RATE

int RC_MB_SAMPLE_RATE = 0

Definition at line 127 of file rate.c.

Referenced by MB_RateOut(), and targetRateControl().

◆ rc_numBlocks

int rc_numBlocks = 0

◆ rc_Q

◆ rc_R

int rc_R
static

Definition at line 132 of file rate.c.

Referenced by initGOPRateControl(), initRateControl(), targetRateControl(), and updateRateControl().

◆ rc_totalFrameBits

int rc_totalFrameBits

◆ rc_totalMBBits

int rc_totalMBBits

Definition at line 121 of file rate.c.

Referenced by incMacroBlockBits(), initRateControl(), and updateRateControl().

◆ rc_totalOverheadBits

int rc_totalOverheadBits = 0

Definition at line 123 of file rate.c.

Referenced by initRateControl(), and updateRateControl().

◆ rc_totalQuant

int rc_totalQuant = 0

Definition at line 119 of file rate.c.

Referenced by initRateControl(), needQScaleChange(), and updateRateControl().

◆ reactionParameter

int reactionParameter
static

Definition at line 149 of file rate.c.

Referenced by checkBufferFullness(), initRateControl(), and targetRateControl().

◆ Sb

int Sb
static

Definition at line 96 of file rate.c.

Referenced by updateRateControl().

◆ Si

int Si
static

Definition at line 96 of file rate.c.

Referenced by updateRateControl().

◆ Sp

int Sp
static

Definition at line 96 of file rate.c.

Referenced by updateRateControl().

◆ Tb

int Tb

Definition at line 101 of file rate.c.

Referenced by targetRateControl(), and updateRateControl().

◆ Ti

◆ total_act_j

int total_act_j
static

Definition at line 155 of file rate.c.

Referenced by checkSpatialActivity(), and updateRateControl().

◆ Tp

int Tp

Definition at line 101 of file rate.c.

Referenced by AllDone(), main(), targetRateControl(), and updateRateControl().

◆ var_sblk

int var_sblk
static

Definition at line 157 of file rate.c.

Referenced by checkSpatialActivity().

◆ VBV_buffer

int32 VBV_buffer = 0
static

Definition at line 89 of file rate.c.

Referenced by initRateControl(), updateRateControl(), and updateVBVBuffer().

◆ VBV_delay

int32 VBV_delay =0
static

Definition at line 88 of file rate.c.

Referenced by initRateControl(), updateRateControl(), and updateVBVBuffer().

◆ Xb

int Xb
static

Definition at line 94 of file rate.c.

Referenced by initGOPRateControl(), initRateControl(), targetRateControl(), and updateRateControl().

◆ Xi

int Xi
static

Definition at line 94 of file rate.c.

Referenced by initGOPRateControl(), initRateControl(), targetRateControl(), and updateRateControl().

◆ Xp

int Xp
static