annexe a l`implementation en langage c de l`algorithme svbr

publicité
L’implementation en langage C de l’algorithme SVBR
ANNEXE A
L’IMPLEMENTATION EN LANGAGE C DE L’ALGORITHME
SVBR
/* lissage.c, procédure de contrôle de débit pour Mpeg1 et mpeg2 qui garantit
la conformité du débit de sortie a un modèle du seau perce (leaky bucket)*/
/* Droits Réservés a Maher Hamdi, James Roberts et Pierre Rolin (France Telecom)
Email: [email protected]
Tel: (33) 99 12 70 23
Fax: (33) 99 12 70 30
Adresse: ENST de Bretagne, Département RSM
BP 78 35512 Cesson Sévigné Cedex */
/* Cette procédure (algorithme et implémentation) a été développée au sein
du département Réseaux et services Multimedia de l’ENST de Bretagne.
Cette procédure (algorithme et implémentation) est protégée par un dépôt
de Brevet. La description y est suffisamment générale pour protéger
l’algorithme indépendamment de l’implémentation (langage, système ...) */
/* Cette procédure peut être utilisée avec les logiciels de compression video
du domaine public ou autres. Le rôle de cette procédure est de contrôler
le débit a long terme et est donc compatible avec les autres algorithmes
de contrôle de débit a court termes comme par exemple le contrôle de débit
crête.*/
#include <stdio.h>
#include <math.h>
#include <stdio.h>
#include <math.h>
static int Q0;
/* The reference mquant for a VBR coding */
static int Q;
/* The GoP by GoP varying quantization parameter */
static double Lambda; /* The leak rate in bits/sec */
static double b; /* The bucket size of the LB(b,Lambda) in bits */
static double X; /* The bucket fulness updated at the end of each GOP */
static double R;
/* The instantaneous SVBR bit rate computed on GoP
by GoP basis */
static double Alpha; /* for the non linear reaction functions */
/* Power function used for the non linear feedback of the buffer fulness */
double E1 (double x) { /* to be called with X/b as argument */
return pow(x,Alpha);
}
/* Power function used for the non linear feedback of the buffer fulness */
89
Contrôle de trafic ATM pour sources vidéo à débit variable
double E2 (double x) { /* to be called with X/b as argument */
return 1-pow(1-x,Alpha);
}
/* Adjustment function for active scenes */
double K1(double y) { /* to be called with Lambda/R0(t) < 1 as argument */
double e;
e = E1((X > b?1:X/b));
return 1.0/(1-e+y*e);
}
/* Adjustment function for low activity scenes */
double K2(double y) { /* to be called with Lambda/R0(t) > 1 as argument */
double e;
e = E2((X > b?1:X/b));
return 1.0/(e+y*(1-e));
}
/* Reaction function */
double React_On_Q(double R,int Q){
double y;
y = Lambda*Q0/R/Q; /* y = Lambda / R0(t) */
if (y < .95) return K1(y);
if (y > 1.05) return K2(y);
return 1.0;
}
/* This function must be called at the initialization of the coder i.e. before
compression starts. */
void SVBR_init(int Frames_In_GoP, /* number of frames in one GoP */
double Frame_Rate, /* number of frames per second */
int Q_Reference, /* a reference quantization parameter */
double Leak_Rate, /* the target average rate in bits/sec */
double Bucket_Size, /* size of the virtual buffer in bits */
double Reaction) /* power of the non linerar feedback */
{
Lambda = Leak_Rate;
Q0 = Q_Reference;
Q = Q0;
b = Bucket_Size;
X
= b/2;
Alpha = 5;
R = Lambda * Frames_In_GoP/Frame_Rate;
}
/* This function must be called before coding each GoP. It gives the value
of the quantization parameter to be used for the compression of the GoP */
int SVBR_Get_Q_OF_GoP(int Frames_In_GoP, /* number of frames in one GoP */
double Size_Of_Last_GoP,/* number of bits generated by
last compressed GoP
*/
double Frame_Rate) /* number of frames per second */
90
L’implementation en langage C de l’algorithme SVBR
{
/* update the virtual buffer of the LB(b,Lambda) */
X -= Frames_In_GoP*Lambda/Frame_Rate;
if (X<0)
X = 0;
X += Size_Of_Last_GoP;
/* average bit rate over the last GoP */
R = Frame_Rate*Size_Of_Last_GoP/Frames_In_GoP;
Q = (int)floor(Q0*React_On_Q(R,Q)+0.5);
return Q;
}
91
Contrôle de trafic ATM pour sources vidéo à débit variable
92
Téléchargement