summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libcamera/timer.h4
-rw-r--r--src/libcamera/timer.cpp19
-rw-r--r--src/qcam/qt_event_dispatcher.cpp7
3 files changed, 13 insertions, 17 deletions
diff --git a/include/libcamera/timer.h b/include/libcamera/timer.h
index 476ae45f..09f426a5 100644
--- a/include/libcamera/timer.h
+++ b/include/libcamera/timer.h
@@ -24,11 +24,10 @@ public:
~Timer();
void start(unsigned int msec) { start(std::chrono::milliseconds(msec)); }
- void start(std::chrono::milliseconds interval);
+ void start(std::chrono::milliseconds duration);
void stop();
bool isRunning() const;
- std::chrono::milliseconds interval() const { return interval_; }
std::chrono::steady_clock::time_point deadline() const { return deadline_; }
Signal<Timer *> timeout;
@@ -40,7 +39,6 @@ private:
void registerTimer();
void unregisterTimer();
- std::chrono::milliseconds interval_;
std::chrono::steady_clock::time_point deadline_;
};
diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp
index b3cea3da..34410bab 100644
--- a/src/libcamera/timer.cpp
+++ b/src/libcamera/timer.cpp
@@ -61,19 +61,18 @@ Timer::~Timer()
*/
/**
- * \brief Start or restart the timer with a timeout of \a interval
- * \param[in] interval The timer duration in milliseconds
+ * \brief Start or restart the timer with a timeout of \a duration
+ * \param[in] duration The timer duration in milliseconds
*
* If the timer is already running it will be stopped and restarted.
*/
-void Timer::start(std::chrono::milliseconds interval)
+void Timer::start(std::chrono::milliseconds duration)
{
- interval_ = interval;
- deadline_ = utils::clock::now() + interval;
+ deadline_ = utils::clock::now() + duration;
LOG(Timer, Debug)
- << "Starting timer " << this << " with interval "
- << interval.count() << ": deadline "
+ << "Starting timer " << this << " with duration "
+ << duration.count() << ": deadline "
<< utils::time_point_to_string(deadline_);
registerTimer();
@@ -114,12 +113,6 @@ bool Timer::isRunning() const
}
/**
- * \fn Timer::interval()
- * \brief Retrieve the timer interval
- * \return The timer interval in milliseconds
- */
-
-/**
* \fn Timer::deadline()
* \brief Retrieve the timer deadline
* \return The timer deadline
diff --git a/src/qcam/qt_event_dispatcher.cpp b/src/qcam/qt_event_dispatcher.cpp
index 994af3ea..9e989bef 100644
--- a/src/qcam/qt_event_dispatcher.cpp
+++ b/src/qcam/qt_event_dispatcher.cpp
@@ -5,6 +5,7 @@
* qt_event_dispatcher.cpp - qcam - Qt-based event dispatcher
*/
+#include <chrono>
#include <iostream>
#include <QAbstractEventDispatcher>
@@ -112,7 +113,11 @@ void QtEventDispatcher::exceptionNotifierActivated(int socket)
void QtEventDispatcher::registerTimer(Timer *timer)
{
- int timerId = startTimer(timer->interval());
+ std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
+ std::chrono::steady_clock::duration duration = timer->deadline() - now;
+ std::chrono::milliseconds msec =
+ std::chrono::duration_cast<std::chrono::milliseconds>(duration);
+ int timerId = startTimer(msec);
timers_[timerId] = timer;
timerIds_[timer] = timerId;
}