00001
00015 #include "contributors.h"
00016 #include "global.h"
00017
00018 #ifdef _LEAKYBUCKET_
00019
00037
00038 unsigned long GetBigDoubleWord(FILE *fp)
00039 {
00040 unsigned long dw;
00041 dw = (unsigned long) (fgetc(fp) & 0xFF);
00042 dw = ((unsigned long) (fgetc(fp) & 0xFF)) | (dw << 0x08);
00043 dw = ((unsigned long) (fgetc(fp) & 0xFF)) | (dw << 0x08);
00044 dw = ((unsigned long) (fgetc(fp) & 0xFF)) | (dw << 0x08);
00045 return(dw);
00046 }
00047
00068
00069 void calc_buffer(InputParameters *p_Inp)
00070 {
00071 unsigned long NumberLeakyBuckets, *Rmin, *Bmin, *Fmin;
00072 float B_interp, F_interp;
00073 unsigned long iBucket;
00074 float dnr, frac1, frac2;
00075 unsigned long R_decoder, B_decoder, F_decoder;
00076 FILE *outf;
00077
00078 if ((outf=fopen(p_Inp->LeakyBucketParamFile,"rb"))==NULL)
00079 {
00080 snprintf(errortext, ET_SIZE, "Error open file %s \n",p_Inp->LeakyBucketParamFile);
00081 error(errortext,1);
00082 }
00083
00084 NumberLeakyBuckets = GetBigDoubleWord(outf);
00085 printf(" Number Leaky Buckets: %8ld \n\n", NumberLeakyBuckets);
00086 Rmin = calloc(sizeof(unsigned long), NumberLeakyBuckets);
00087 Bmin = calloc(sizeof(unsigned long), NumberLeakyBuckets);
00088 Fmin = calloc(sizeof(unsigned long), NumberLeakyBuckets);
00089
00090 for(iBucket =0; iBucket < NumberLeakyBuckets; iBucket++)
00091 {
00092 Rmin[iBucket] = GetBigDoubleWord(outf);
00093 Bmin[iBucket] = GetBigDoubleWord(outf);
00094 Fmin[iBucket] = GetBigDoubleWord(outf);
00095 printf(" %8ld %8ld %8ld \n", Rmin[iBucket], Bmin[iBucket], Fmin[iBucket]);
00096 }
00097 fclose(outf);
00098
00099 R_decoder = p_Inp->R_decoder;
00100 F_decoder = p_Inp->F_decoder;
00101 B_decoder = p_Inp->B_decoder;
00102
00103 for( iBucket =0; iBucket < NumberLeakyBuckets; iBucket++)
00104 {
00105 if(R_decoder < Rmin[iBucket])
00106 break;
00107 }
00108
00109 printf("\n");
00110 if(iBucket > 0 )
00111 {
00112 if(iBucket < NumberLeakyBuckets)
00113 {
00114 dnr = (float) (Rmin[iBucket] - Rmin[iBucket-1]);
00115 frac1 = (float) (R_decoder - Rmin[iBucket-1]);
00116 frac2 = (float) (Rmin[iBucket] - R_decoder);
00117 B_interp = (float) (Bmin[iBucket] * frac1 + Bmin[iBucket-1] * frac2) /dnr;
00118 F_interp = (float) (Fmin[iBucket] * frac1 + Fmin[iBucket-1] * frac2) /dnr;
00119 }
00120 else {
00121 B_interp = (float) Bmin[iBucket-1];
00122 F_interp = (float) Fmin[iBucket-1];
00123 }
00124 printf(" Min.buffer %8.2f Decoder buffer size %ld \n Minimum Delay %8.2f DecoderDelay %ld \n", B_interp, B_decoder, F_interp, F_decoder);
00125 if(B_decoder > B_interp && F_decoder > F_interp)
00126 printf(" HRD Compliant \n");
00127 else
00128 printf(" HRD Non Compliant \n");
00129 }
00130 else {
00131 printf(" Decoder Rate is too small; HRD cannot be verified \n");
00132 }
00133
00134 free(Rmin);
00135 free(Bmin);
00136 free(Fmin);
00137 return;
00138 }
00139 #endif