aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dabOutput/dabOutputSimul.cpp47
1 files changed, 6 insertions, 41 deletions
diff --git a/src/dabOutput/dabOutputSimul.cpp b/src/dabOutput/dabOutputSimul.cpp
index 347b29c..d874603 100644
--- a/src/dabOutput/dabOutputSimul.cpp
+++ b/src/dabOutput/dabOutputSimul.cpp
@@ -2,7 +2,7 @@
Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Her Majesty the Queen in
Right of Canada (Communications Research Center Canada)
- Copyright (C) 2016 Matthias P. Braendli
+ Copyright (C) 2018 Matthias P. Braendli
http://mpb.li
SIMUL throttling output. It guarantees correct frame generation rate
@@ -30,63 +30,28 @@
#include <limits.h>
#include <chrono>
#include <thread>
-#ifdef _WIN32
-# include <io.h>
-# ifdef __MINGW32__
-# define FS_DECLARE_CFG_ARRAYS
-# include <winioctl.h>
-# endif
-# include <sdci.h>
-#else
-# include <unistd.h>
-# include <sys/time.h>
-# ifndef O_BINARY
-# define O_BINARY 0
-# endif // O_BINARY
-#endif
int DabOutputSimul::Open(const char* name)
{
-#ifdef _WIN32
- startTime_ = GetTickCount();
-#else
startTime_ = std::chrono::steady_clock::now();
-#endif
-
return 0;
}
int DabOutputSimul::Write(void* buffer, int size)
{
-#ifdef _WIN32
- unsigned long current;
- unsigned long start;
- unsigned long waiting;
- current = GetTickCount();
- start = this->startTime_;
- if (current < start) {
- waiting = start - current + 24;
- Sleep(waiting);
- } else {
- waiting = 24 - (current - start);
- if ((current - start) < 24) {
- Sleep(waiting);
- }
- }
- this->startTime_ += 24;
-#else
auto curTime = std::chrono::steady_clock::now();
+ const auto frameinterval = std::chrono::milliseconds(24);
+
auto diff = curTime - startTime_;
- auto waiting = std::chrono::milliseconds(24) - diff;
+ auto waiting = frameinterval - diff;
- if (diff < std::chrono::milliseconds(24)) {
+ if (diff < frameinterval) {
std::this_thread::sleep_for(waiting);
}
- startTime_ += std::chrono::milliseconds(24);
-#endif
+ startTime_ += frameinterval;
return size;
}