![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/Threading/PlaybackTimer.h>
Recurring timer class that allows for playback over a range at given timestamps/intervals. More...
Recurring timer class that allows for playback over a range at given timestamps/intervals.
For setup you provide a number of frames together with their corresponding timestamps as well as a callback function. During playback this class will then call the callback function for each frame at its scheduled time passing the frame index as argument.
By default, if a scheduled frame was missed for any reason (e.g. a previous callback taking too long) PlaybackTimer will skip that frame and and play the currently scheduled one instead.
Example:
Public Types | |
using | CallbackFunction = std::function<void(size_t frameIndex)> |
Signature of the callback function used by the playback thread. | |
Public Member Functions | |
void | setRangeConstantFps (size_t numFrames, double fps) |
Configure playback to use a constant interval between frames. | |
void | setRangeConstantInterval (size_t numFrames, std::chrono::nanoseconds interval) |
Configure playback to use a constant interval between frames. | |
void | setRangeTimestamps (const std::vector< std::chrono::nanoseconds > ×tamps, bool startImmediately=false) |
Configure playback to use specific timestamps for each frame. | |
void | setRangeTimestamps (const std::vector< double > ×tampsSeconds, bool startImmediately=false) |
Configure playback to use specific timestamps for each frame. | |
const std::vector< std::chrono::nanoseconds > & | rangeTimestamps () const |
Return the configured range of frames and their corresponding timestamps. | |
void | setCallback (const CallbackFunction &callbackFunction) |
Set the callback function that is going to be called for each frame. | |
void | setLooped (bool value) |
Set whether the timer shall start over from the beginning once it reaches the end of the frames. | |
bool | isLooped () const |
Return whether the timer starts over from the beginning once it reaches the end of the frames. | |
void | setSkipDelayedFrames (bool value) |
Set whether to skip frames in case their subsequent frame is already due. | |
bool | isSkippingDelayedFrames () const |
Return whether to skip frames in case their subsequent frame is already due. | |
void | setUseAbsoluteTimesteps (bool value) |
If set to true, the current time is not taken into account, and the timer will wait for the amount of time equal to difference between consecutive timestamps In this case all the frames will be played. | |
bool | useAbsoluteTimesteps () const |
void | start (size_t startIndex=0) |
Start the timer thread. | |
void | stop () |
Stop the timer thread. | |
bool | isRunning () const |
Return if the timer thread is currently running. | |
void | pause () |
Temporarily pause the playback. | |
void | resume () |
Resume the playback. | |
bool | isPaused () const |
Return if the timer thread is currently running and paused. | |
using CallbackFunction = std::function<void(size_t frameIndex)> |
Signature of the callback function used by the playback thread.
The frameIndex describes the index of the current frame.
void setRangeConstantFps | ( | size_t | numFrames, |
double | fps ) |
Configure playback to use a constant interval between frames.
numFrames | Number of frames to play |
fps | Time interval between frames in terms of frames per second |
void setRangeConstantInterval | ( | size_t | numFrames, |
std::chrono::nanoseconds | interval ) |
Configure playback to use a constant interval between frames.
numFrames | Number of frames to play |
interval | Time interval between frames |
void setRangeTimestamps | ( | const std::vector< std::chrono::nanoseconds > & | timestamps, |
bool | startImmediately = false ) |
Configure playback to use specific timestamps for each frame.
timestamps | Set of timestamps in terms of nanoseconds. The number of timestamps defines the number of frames played. The list of timestamps must be ordered in an ascending fashion. |
startImmediately | Flag whether the timestamps shall be normalized wrt. the first frame, i.e. the first frame starts at time 0 and all subsequent frames relative to it. |
void setRangeTimestamps | ( | const std::vector< double > & | timestampsSeconds, |
bool | startImmediately = false ) |
Configure playback to use specific timestamps for each frame.
timestampsSeconds | Set of timestamps in terms of seconds. The number of timestamps defines the number of frames played. The list of timestamps must be ordered in an ascending fashion. |
startImmediately | Flag whether the timestamps shall be normalized wrt. the first frame, i.e. the first frame starts at time 0 and all subsequent frames relative to it. |
|
inline |
Return the configured range of frames and their corresponding timestamps.
void setCallback | ( | const CallbackFunction & | callbackFunction | ) |
Set the callback function that is going to be called for each frame.
void setLooped | ( | bool | value | ) |
Set whether the timer shall start over from the beginning once it reaches the end of the frames.
By default, this setting is off.
void setSkipDelayedFrames | ( | bool | value | ) |
Set whether to skip frames in case their subsequent frame is already due.
This can for instance happen if the time between frames is less than the time needed to process the callback.
void start | ( | size_t | startIndex = 0 | ) |
Start the timer thread.
This function has no effect if the timer is already running, or if the range/timestamps or the callback function are empty.
startIndex | Optional frame index to start from |
bool isRunning | ( | ) | const |
Return if the timer thread is currently running.
This function will return true also in case it is paused.
void pause | ( | ) |
Temporarily pause the playback.
This function has no effect if the timer is not started or if the playback is already paused.