00001 00018 #include "vetNetClient.h" 00019 #include "../vetUtility.h" 00020 00021 00027 vetNetClient::vetNetClient(RUNMODE mode) : vetOutput() 00028 { 00029 DEBUGMSG("vetNetClient::vetNetClient(RUNMODE mode) : vetOutput() [CONTRUCTOR]", mode) 00030 00031 runmode = mode; 00032 v_sleeptime = 0; 00033 00034 reset(); 00035 } 00036 00037 00046 int vetNetClient::reset(bool startTimers) 00047 { 00048 lastFps = 0; 00049 mediumFps = 0; 00050 lastExTime = 0; 00051 mediumExTime = 0; 00052 v_sleeptime = 0; 00053 00054 if ( startTimers ) 00055 { 00056 lastFrameTime = clock(); 00057 frameCount = 1; 00058 } 00059 else 00060 { 00061 frameCount = 0; 00062 lastFrameTime = 0; 00063 } 00064 return VETRET_OK; 00065 } 00066 00067 00068 00077 int vetNetClient::setInputFrameRate(float fps) 00078 { 00079 if (fps < 0.) 00080 return VETRET_PARAM_ERR; 00081 00082 if ( fps == 0 ) 00083 v_sleeptime = 0; 00084 else 00085 v_sleeptime = (long)( (float)1000 / fps ); // milliseconds 00086 00087 return VETRET_OK; 00088 } 00089 00097 void vetNetClient::updateFps() 00098 { 00099 if ( frameCount == 0 || clock() - lastFrameTime == 0) 00100 { 00101 lastFrameTime = clock(); 00102 frameCount++; 00103 return; 00104 } 00105 //CLOCKS_PER_SEC;//CLK_TCK; 00106 lastFps = 1 / ( ( clock() - lastFrameTime ) / CLOCKS_PER_SEC ); // fps = 1/elapsedsecond 00107 mediumFps = (mediumFps * (frameCount-1) + lastFps ) / frameCount; 00108 00109 lastFrameTime = clock(); 00110 frameCount++; 00111 } 00112 00120 void vetNetClient::updateExtime() 00121 { 00122 if ( frameCount == 0 || clock() - lastFrameTime == 0 ) 00123 { 00124 lastExTime = clock(); 00125 return; 00126 } 00127 00128 //CLOCKS_PER_SEC;//CLK_TCK; 00129 lastExTime = 1000 * ( clock() - lastFrameTime ) / CLOCKS_PER_SEC; //milliseconds 00130 mediumExTime = (mediumExTime * (frameCount-1) + lastExTime ) / frameCount; 00131 } 00132 00133 00134 long vetNetClient::getElapsedTime() const 00135 { 00136 return (long) ( 1000 * ( clock() - lastFrameTime ) / CLOCKS_PER_SEC); //milliseconds 00137 } 00138 00139 00140 00141 00142 00154 int vetNetClient::importFrom(vetFrameCache& img) 00155 { 00156 INFO("int vetNetClient::importFrom(vetFrameCache& img) [reading data]") 00157 00158 return VETRET_NOT_IMPLEMENTED; 00159 } 00160 00172 int vetNetClient::importFrom(vetFrameCache24& img) 00173 { 00174 INFO("int vetNetClient::importFrom(vetFrameCache24& img) [reading data]") 00175 00176 return VETRET_NOT_IMPLEMENTED; 00177 } 00178 00190 int vetNetClient::importFrom(vetFrameRGB& img) 00191 { 00192 INFO("int vetNetClient::importFrom(vetFrameRGB& img) [reading data]") 00193 00194 return VETRET_NOT_IMPLEMENTED; 00195 } 00196 00208 int vetNetClient::importFrom(vetFrameGrey& img) 00209 { 00210 INFO("int vetNetClient::importFrom(vetFrameGrey& img) [reading data]") 00211 00212 return VETRET_NOT_IMPLEMENTED; 00213 } 00214 00215 00225 void vetNetClient::operator << (vetFrameCache& img) 00226 { 00227 INFO("void vetNetClient::operator << (vetFrameCache& img) [importing data]") 00228 00229 updateFps(); 00230 00231 if ( runmode ) 00232 importFrom(img); 00233 00234 updateExtime(); 00235 00236 if ( v_sleeptime ) 00237 vetUtility::vetSleep(v_sleeptime); 00238 } 00239 00249 void vetNetClient::operator << (vetFrameCache24& img) 00250 { 00251 INFO("void vetNetClient::operator << (vetFrameCache24& img) [importing data]") 00252 00253 updateFps(); 00254 00255 if ( runmode ) 00256 importFrom(img); 00257 00258 updateExtime(); 00259 00260 if ( v_sleeptime ) 00261 vetUtility::vetSleep(v_sleeptime); 00262 } 00263 00273 void vetNetClient::operator << (vetFrameRGB& img) 00274 { 00275 INFO("void vetNetClient::operator << (vetFrameRGB& img) [importing data]") 00276 00277 updateFps(); 00278 00279 if ( runmode ) 00280 importFrom(img); 00281 00282 updateExtime(); 00283 00284 if ( v_sleeptime ) 00285 vetUtility::vetSleep(v_sleeptime); 00286 } 00287 00297 void vetNetClient::operator << (vetFrameGrey& img) 00298 { 00299 INFO("void vetNetClient::operator << (vetFrameGrey& img) [importing data]") 00300 00301 updateFps(); 00302 00303 if ( runmode ) 00304 importFrom(img); 00305 00306 updateExtime(); 00307 00308 if ( v_sleeptime ) 00309 vetUtility::vetSleep(v_sleeptime); 00310 } 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330
1.4.4