Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
rate_ctl.c
Upload User: hbbaokai
Upload Date: 2009-07-13
Package Size: 328k
Code Size: 3k
Category:
VOIP program
Development Platform:
Visual C++
- #include "stdio.h"
- extern FILE *ftrace;
- extern int max_quantizer, min_quantizer;
- typedef struct _rc_param_ {
- double quant;
- int rc_period;
- double target_rate;
- double average_rate;
- double reaction_rate;
- double average_delta;
- double reaction_delta;
- double reaction_ratio;
- } RC_Param;
- static RC_Param rc_param;
- void RateCtlInit(double quant, double target_rate,
- long rc_period, long rc_reaction_period, long rc_reaction_ratio)
- {
- #ifdef _RC_
- fprintf(ftrace, "Initializing Rate Control module:n");
- fprintf(ftrace, "Initial quantizer is %f.n", quant);
- fprintf(ftrace, "Target rate is %f bits per frame.n", target_rate);
- fprintf(ftrace, "RC averaging period is %d.n", rc_period);
- fprintf(ftrace, "RC reaction period is %d.n", rc_reaction_period);
- fprintf(ftrace, "RC reaction ratio is %d.n", rc_reaction_ratio);
- #endif
- rc_param.quant = quant;
- rc_param.rc_period = rc_period;
- rc_param.target_rate = target_rate;
- rc_param.reaction_ratio = rc_reaction_ratio;
- rc_param.average_delta = 1. / rc_period;
- rc_param.reaction_delta = 1. / rc_reaction_period;
- rc_param.average_rate = target_rate;
- rc_param.reaction_rate = target_rate;
- return;
- }
- int RateCtlGetQ(double MAD)
- {
- double quant;
- quant = rc_param.quant;
- return (int)(quant + 0.5);
- }
- void RateCtlUpdate(int current_frame)
- {
- double rate, delta, decay;
- double target, current_target;
- double median_quant;
- #ifdef _RC_
- fprintf(ftrace, "Quantizer is currently %f.n", rc_param.quant);
- fprintf(ftrace, "Current frame is %d bits long.n", current_frame);
- #endif
- rate = rc_param.average_rate;
- delta = rc_param.average_delta;
- decay = 1 - delta;
- rate = rate * decay + current_frame * delta;
- rc_param.average_rate = rate;
- target = rc_param.target_rate;
- if (rate > target) {
- current_target = target - (rate - target);
- if (current_target < target * 0.75) current_target = target * 0.75;
- } else {
- current_target = target;
- }
- #ifdef _RC_
- fprintf(ftrace, "Target rate is %f.n", target);
- fprintf(ftrace, "Average rate is %f.n", rate);
- fprintf(ftrace, "Target rate for current frame is %f.n", current_target);
- #endif
- rate = rc_param.reaction_rate;
- delta = rc_param.reaction_delta;
- decay = 1 - delta;
- rate = rate * decay + current_frame * delta;
- rc_param.reaction_rate = rate;
- median_quant = min_quantizer + (max_quantizer - min_quantizer) / 2;
- if (rate < current_target) rc_param.quant *=
- (1 - rc_param.reaction_delta * ((current_target - rate) / current_target / 0.20) );
- if (rc_param.quant < min_quantizer) rc_param.quant = min_quantizer;
- if (rate > current_target) {
- if (rc_param.quant > median_quant)
- rc_param.quant *= (1 + rc_param.reaction_delta / rc_param.reaction_ratio);
- else if (rate > current_target * 1.20) rc_param.quant *=
- (1 + rc_param.reaction_delta);
- else rc_param.quant *=
- (1 + rc_param.reaction_delta * ((rate - current_target) / current_target / 0.20) );
- }
- if (rc_param.quant > max_quantizer) rc_param.quant = max_quantizer;
- #ifdef _RC_
- fprintf(ftrace, "Reaction rate is %f.n", rate);
- fprintf(ftrace, "Quantizer is updated to %f.n", rc_param.quant);
- #endif
- return;
- }