TerminalCapabilities.cpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: TerminalCapabilities.cpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #include "TerminalCapabilities.hpp" 00045 #include "debug.hpp" 00046 #include <string.h> 00047 00049 TerminalCapabilities::TerminalCapabilities() { 00050 maxDecoderBufferSizeInByte=0; 00051 maxDecoderBitRateInBit=0; 00052 displayBitsPerPixel=0; 00053 colorDisplay=0; 00054 displayWidth=0; 00055 displayHeight=0; 00056 displayRefreshRate=0; 00057 memoryStorageMB=0; 00058 networkCapacityInByte=0; 00059 minGuaranteedNetworkCapacityInByte=0; 00060 networkDelayVariationInMs=0; 00061 bufferingDelayInMs=0; 00062 numAudioChannels=0; 00063 audioBitsPerSample=16; 00064 audioSamplingFrequency=44100; 00065 00066 }; 00067 00069 TerminalCapabilities::TerminalCapabilities( 00070 u32 maxDecBufSize, u32 maxDecBitrate, 00071 u32 displayBits, bool color, 00072 u32 width, u32 height, u32 refreshRate, 00073 float mem, u32 netCap, u32 minNetCap, 00074 u32 netDelayVar, u32 buffDelay, 00075 u8 numAudioChann,u8 audiBitsPerSample,u32 samplFreq) { 00076 maxDecoderBufferSizeInByte=maxDecBufSize; 00077 maxDecoderBitRateInBit=maxDecBitrate; 00078 displayBitsPerPixel=displayBits; 00079 colorDisplay=(u32)color; 00080 displayWidth=width; 00081 displayHeight=height; 00082 displayRefreshRate=refreshRate; 00083 memoryStorageMB=mem; 00084 networkCapacityInByte=netCap; 00085 minGuaranteedNetworkCapacityInByte=minNetCap; 00086 networkDelayVariationInMs=netDelayVar; 00087 bufferingDelayInMs=buffDelay; 00088 numAudioChannels=numAudioChann; 00089 audioBitsPerSample=audiBitsPerSample; 00090 audioSamplingFrequency=samplFreq; 00091 }; 00092 00093 TerminalCapabilities* TerminalCapabilities::clone() const { 00094 return new TerminalCapabilities( 00095 maxDecoderBufferSizeInByte, 00096 maxDecoderBitRateInBit, 00097 displayBitsPerPixel, 00098 (colorDisplay==0) ? false:true, 00099 // (((bool)colorDisplay)!=false), 00100 displayWidth, 00101 displayHeight, 00102 displayRefreshRate, 00103 memoryStorageMB, 00104 networkCapacityInByte, 00105 minGuaranteedNetworkCapacityInByte, 00106 networkDelayVariationInMs, 00107 bufferingDelayInMs, 00108 numAudioChannels, 00109 audioBitsPerSample, 00110 audioSamplingFrequency); 00111 }; 00112 00113 u32 TerminalCapabilities::getMaxDecoderBufferSizeInByte() const { 00114 return maxDecoderBufferSizeInByte; 00115 }; 00116 00117 u32 TerminalCapabilities::getMaxDecoderBitRateInBit() const { 00118 return maxDecoderBitRateInBit; 00119 }; 00120 00121 u32 TerminalCapabilities::getDisplayBitsPerPixel() const { 00122 return displayBitsPerPixel; 00123 }; 00124 00125 bool TerminalCapabilities::getColorDisplay() const { 00126 return colorDisplay!=0; 00127 }; 00128 00129 u32 TerminalCapabilities::getDisplayWidth() const { 00130 return displayWidth; 00131 }; 00132 00133 u32 TerminalCapabilities::getDisplayHeight() const { 00134 return displayHeight; 00135 }; 00136 00137 u32 TerminalCapabilities::getDisplayRefreshRate() const { 00138 return displayRefreshRate; 00139 }; 00140 00141 float TerminalCapabilities::getMemoryStorageMB() const { 00142 return memoryStorageMB; 00143 }; 00144 00145 u32 TerminalCapabilities::getNetworkCapacityInByte() const { 00146 return networkCapacityInByte; 00147 }; 00148 00149 u32 TerminalCapabilities::getMinGuaranteedNetworkCapacityInByte() const { 00150 return minGuaranteedNetworkCapacityInByte; 00151 }; 00152 00153 u32 TerminalCapabilities::getNetworkDelayVariationInMs() const { 00154 return networkDelayVariationInMs; 00155 }; 00156 00157 u32 TerminalCapabilities::getBufferingDelayInMs() const { 00158 return bufferingDelayInMs; 00159 }; 00160 00161 u8 TerminalCapabilities::getNumAudioChannels() const 00162 { 00163 return numAudioChannels; 00164 }; 00165 00166 bool TerminalCapabilities::supportsAudio() const 00167 { 00168 return numAudioChannels>0; 00169 }; 00170 00171 u8 TerminalCapabilities::getAudioBitsPerSample() const 00172 { 00173 return audioBitsPerSample; 00174 }; 00175 00176 u32 TerminalCapabilities::getAudioSamplingFrequency() const 00177 { 00178 return audioSamplingFrequency; 00179 }; 00180 00181 void TerminalCapabilities::setMaxDecoderBufferSizeInByte(const u32 t) { 00182 maxDecoderBufferSizeInByte=t; 00183 }; 00184 00185 void TerminalCapabilities::setMaxDecoderBitRateInBit(const u32 t) { 00186 maxDecoderBitRateInBit=t; 00187 }; 00188 00189 void TerminalCapabilities::setDisplayBitsPerPixel(const u32 t) { 00190 displayBitsPerPixel=t; 00191 }; 00192 00193 void TerminalCapabilities::setColorDisplay(const bool c) { 00194 colorDisplay=(u32)c; 00195 }; 00196 00197 void TerminalCapabilities::setDisplayWidth(const u32 w) { 00198 displayWidth=w; 00199 }; 00200 00201 void TerminalCapabilities::setDisplayHeight(const u32 h) { 00202 displayHeight=h; 00203 }; 00204 00205 void TerminalCapabilities::setDisplayRefreshRate(const u32 r) { 00206 displayRefreshRate=r; 00207 }; 00208 00209 void TerminalCapabilities::setMemoryStorageMB(const float s) { 00210 memoryStorageMB=s; 00211 }; 00212 00213 void TerminalCapabilities::setNetworkCapacityInByte(const u32 c) { 00214 networkCapacityInByte=c; 00215 }; 00216 00217 void TerminalCapabilities::setMinGuaranteedNetworkCapacityInByte(const u32 n) { 00218 minGuaranteedNetworkCapacityInByte=n; 00219 }; 00220 00221 void TerminalCapabilities::setNetworkDelayVariationInMs(const u32 d) { 00222 networkDelayVariationInMs=d; 00223 }; 00224 00225 void TerminalCapabilities::setBufferingDelayInMs(const u32 b) { 00226 bufferingDelayInMs=b; 00227 }; 00228 00229 void TerminalCapabilities::setNumAudioChannels(const u8 ac) 00230 { 00231 numAudioChannels=ac; 00232 }; 00233 00234 void TerminalCapabilities::setAudioBitsPerSample(const u8 ab) 00235 { 00236 audioBitsPerSample=ab; 00237 }; 00238 00239 void TerminalCapabilities::setAudioSamplingFrequency(const u32 as) 00240 { 00241 audioSamplingFrequency=as; 00242 }; 00243 00244 bool TerminalCapabilities::initFromFile(const char* file) 00245 { 00246 FILE* fp=fopen(file,"rb"); 00247 if(!fp) { 00248 return false; 00249 } 00250 fseek(fp,0L,SEEK_END); 00251 long size=ftell(fp); 00252 //rewind(fp); 00253 fseek(fp, 0L, SEEK_SET); 00254 00255 if(size==-1) { 00256 dprintf_err("TerminalCapabilities::initFromFile failed. Size of %s unknown\n",file); 00257 fclose(fp); 00258 return false; 00259 } 00260 char* buffer=new char[size+1]; 00261 fread(buffer,1,size,fp); 00262 fclose(fp); 00263 char* pBuf=strstr(buffer,"maxDecoderBufferSizeInByte"); 00264 if(pBuf) { 00265 sscanf(pBuf,"maxDecoderBufferSizeInByte %u", &maxDecoderBufferSizeInByte); 00266 } 00267 pBuf=strstr(buffer,"maxDecoderBitRateInBit"); 00268 if(pBuf) { 00269 sscanf(pBuf,"maxDecoderBitRateInBit %u", &maxDecoderBitRateInBit); 00270 } 00271 pBuf=strstr(buffer,"displayBitsPerPixel"); 00272 if(pBuf) { 00273 sscanf(pBuf,"displayBitsPerPixel %u", &displayBitsPerPixel); 00274 } 00275 pBuf=strstr(buffer,"colorDisplay"); 00276 if(pBuf) { 00277 sscanf(pBuf,"colorDisplay %u", &colorDisplay); 00278 } 00279 pBuf=strstr(buffer,"displayWidth"); 00280 if(pBuf) { 00281 sscanf(pBuf,"displayWidth %u", &displayWidth); 00282 } 00283 pBuf=strstr(buffer,"displayHeight"); 00284 if(pBuf) { 00285 sscanf(pBuf,"displayHeight %u", &displayHeight); 00286 } 00287 pBuf=strstr(buffer,"displayRefreshRate"); 00288 if(pBuf) { 00289 sscanf(pBuf,"displayRefreshRate %u", &displayRefreshRate); 00290 } 00291 pBuf=strstr(buffer,"memoryStorageMB"); 00292 if(pBuf) { 00293 sscanf(pBuf,"memoryStorageMB %f", &memoryStorageMB); 00294 } 00295 pBuf=strstr(buffer,"networkCapacityInByte"); 00296 if(pBuf) { 00297 sscanf(pBuf,"networkCapacityInByte %u", &networkCapacityInByte); 00298 } 00299 pBuf=strstr(buffer,"minGuaranteedNetworkCapacityInByte"); 00300 if(pBuf) { 00301 sscanf(pBuf,"minGuaranteedNetworkCapacityInByte %u", &minGuaranteedNetworkCapacityInByte); 00302 } 00303 pBuf=strstr(buffer,"networkDelayVariationInMs"); 00304 if(pBuf) { 00305 sscanf(pBuf,"networkDelayVariationInMs %u", &networkDelayVariationInMs); 00306 } 00307 pBuf=strstr(buffer,"bufferingDelayInMs"); 00308 if(pBuf) { 00309 sscanf(pBuf,"bufferingDelayInMs %u", &bufferingDelayInMs); 00310 } 00311 pBuf=strstr(buffer,"bufferingDelayInMs"); 00312 if(pBuf) { 00313 sscanf(pBuf,"bufferingDelayInMs %u", &bufferingDelayInMs); 00314 } 00315 u32 tmp=0; 00316 pBuf=strstr(buffer,"numAudioChannels"); 00317 if(pBuf) { 00318 sscanf(pBuf,"numAudioChannels %u", &tmp); 00319 numAudioChannels=(u8)tmp; 00320 } 00321 pBuf=strstr(buffer,"audioBitsPerSample"); 00322 if(pBuf) { 00323 sscanf(pBuf,"audioBitsPerSample %u", &tmp); 00324 audioBitsPerSample=(u8)tmp; 00325 } 00326 pBuf=strstr(buffer,"audioSamplingFrequency"); 00327 if(pBuf) { 00328 sscanf(pBuf,"audioSamplingFrequency %u", &tmp); 00329 audioSamplingFrequency=tmp; 00330 } 00331 delete buffer; 00332 return true; 00333 }; 00334 00335 bool TerminalCapabilities::saveToFile(const char* file, bool overWrite) const 00336 { 00337 FILE* fp=NULL; 00338 00339 if(!overWrite) { 00340 fp=fopen(file,"rb"); 00341 if(fp) { 00342 // we are not allowed to overwrite this file 00343 dprintf_err("TerminalCapabilities::saveToFile %s not allowed. File exists\r\n", 00344 file); 00345 fclose(fp); 00346 return false; 00347 } 00348 } 00349 00350 fp=fopen(file,"wb"); 00351 00352 if(!fp) { 00353 dprintf_err( 00354 "TerminalCapabilities::saveToFile %s failed. Couldn't open/create file\r\n", 00355 file); 00356 return false; 00357 } 00358 00359 fprintf(fp,"maxDecoderBufferSizeInByte %u\n", maxDecoderBufferSizeInByte); 00360 fprintf(fp,"maxDecoderBitRateInBit %u\n", maxDecoderBitRateInBit); 00361 fprintf(fp,"displayBitsPerPixel %u\n", displayBitsPerPixel); 00362 fprintf(fp,"colorDisplay %u\n", colorDisplay); 00363 fprintf(fp,"displayWidth %u\n", displayWidth); 00364 fprintf(fp,"displayHeight %u\n", displayHeight); 00365 fprintf(fp,"displayRefreshRate %u\n", displayRefreshRate); 00366 fprintf(fp,"memoryStorageMB %f\n", memoryStorageMB); 00367 fprintf(fp,"networkCapacityInByte %u\n", networkCapacityInByte); 00368 fprintf(fp,"minGuaranteedNetworkCapacityInByte %u\n", minGuaranteedNetworkCapacityInByte); 00369 fprintf(fp,"networkDelayVariationInMs %u\n", networkDelayVariationInMs); 00370 fprintf(fp,"bufferingDelayInMs %u\n", bufferingDelayInMs); 00371 fprintf(fp,"numAudioChannels %u\n", numAudioChannels); 00372 fprintf(fp,"audioBitsPerSample %u\n", audioBitsPerSample); 00373 fprintf(fp,"audioSamplingFrequency %u\n", audioSamplingFrequency); 00374 00375 fclose(fp); 00376 return true; 00377 };