Commit 8d78f0db884815263214441e5974936a711e405f
1 parent
d1ae1645
Fix FPSSynch, rename FPSLimit
Fix a bug in FPSSynch, also rename it FPSLimit because it only reduces the max frame rate of an algorithm, it doesn't do frame dropping or anything.
Showing
1 changed file
with
13 additions
and
8 deletions
openbr/plugins/gui.cpp
| @@ -220,16 +220,16 @@ signals: | @@ -220,16 +220,16 @@ signals: | ||
| 220 | 220 | ||
| 221 | BR_REGISTER(Transform, ShowTransform) | 221 | BR_REGISTER(Transform, ShowTransform) |
| 222 | 222 | ||
| 223 | -class FPSSynch : public TimeVaryingTransform | 223 | +class FPSLimit : public TimeVaryingTransform |
| 224 | { | 224 | { |
| 225 | Q_OBJECT | 225 | Q_OBJECT |
| 226 | Q_PROPERTY(int targetFPS READ get_targetFPS WRITE set_targetFPS RESET reset_targetFPS STORED false) | 226 | Q_PROPERTY(int targetFPS READ get_targetFPS WRITE set_targetFPS RESET reset_targetFPS STORED false) |
| 227 | BR_PROPERTY(int, targetFPS, 30) | 227 | BR_PROPERTY(int, targetFPS, 30) |
| 228 | 228 | ||
| 229 | public: | 229 | public: |
| 230 | - FPSSynch() : TimeVaryingTransform(false, false) {} | 230 | + FPSLimit() : TimeVaryingTransform(false, false) {} |
| 231 | 231 | ||
| 232 | - ~FPSSynch() {} | 232 | + ~FPSLimit() {} |
| 233 | 233 | ||
| 234 | void train(const TemplateList &data) { (void) data; } | 234 | void train(const TemplateList &data) { (void) data; } |
| 235 | 235 | ||
| @@ -237,16 +237,19 @@ public: | @@ -237,16 +237,19 @@ public: | ||
| 237 | void projectUpdate(const TemplateList &src, TemplateList &dst) | 237 | void projectUpdate(const TemplateList &src, TemplateList &dst) |
| 238 | { | 238 | { |
| 239 | dst = src; | 239 | dst = src; |
| 240 | - qint64 time_delta = timer.elapsed(); | 240 | + qint64 current_time = timer.elapsed(); |
| 241 | + qint64 target_time = last_time + target_wait; | ||
| 242 | + qint64 wait_time = target_time - current_time; | ||
| 241 | 243 | ||
| 242 | - qint64 wait_time = target_wait - time_delta; | ||
| 243 | - timer.start(); | 244 | + last_time = current_time; |
| 244 | 245 | ||
| 246 | + qDebug("time is %d wait is %d", current_time, wait_time); | ||
| 245 | if (wait_time < 0) { | 247 | if (wait_time < 0) { |
| 246 | return; | 248 | return; |
| 247 | } | 249 | } |
| 248 | 250 | ||
| 249 | QThread::msleep(wait_time); | 251 | QThread::msleep(wait_time); |
| 252 | + last_time = timer.elapsed(); | ||
| 250 | } | 253 | } |
| 251 | 254 | ||
| 252 | void finalize(TemplateList & output) | 255 | void finalize(TemplateList & output) |
| @@ -256,15 +259,17 @@ public: | @@ -256,15 +259,17 @@ public: | ||
| 256 | 259 | ||
| 257 | void init() | 260 | void init() |
| 258 | { | 261 | { |
| 259 | - target_wait = 1000 / targetFPS; | 262 | + target_wait = 1000.0 / targetFPS; |
| 260 | timer.start(); | 263 | timer.start(); |
| 264 | + last_time = timer.elapsed(); | ||
| 261 | } | 265 | } |
| 262 | 266 | ||
| 263 | protected: | 267 | protected: |
| 264 | QElapsedTimer timer; | 268 | QElapsedTimer timer; |
| 265 | qint64 target_wait; | 269 | qint64 target_wait; |
| 270 | + qint64 last_time; | ||
| 266 | }; | 271 | }; |
| 267 | -BR_REGISTER(Transform, FPSSynch) | 272 | +BR_REGISTER(Transform, FPSLimit) |
| 268 | 273 | ||
| 269 | class FPSCalc : public TimeVaryingTransform | 274 | class FPSCalc : public TimeVaryingTransform |
| 270 | { | 275 | { |