Lumiera
0.pre.03
»edit your freedom«
|
Go to the source code of this file.
Lumiera time handling core implementation unit.
This translation unit generates code for the Lumiera internal time wrapper, based on gavl_time_t, associated constants, marker classes for the derived time entities (TimeVar, Offset, Duration, TimeSpan, FrameRate) and for the basic time and frame rate conversion functions.
Client code includes either time.h (for basics and conversion functions) or timevalue.hpp (for the time entities), timequant.hpp for grid aligned time values or timecode.hpp
Definition in file time.cpp.
#include "lib/error.hpp"
#include "lib/time.h"
#include "lib/time/timevalue.hpp"
#include "lib/rational.hpp"
#include "lib/util-quant.hpp"
#include "lib/format-string.hpp"
#include "lib/util.hpp"
#include "lib/tmpbuf.h"
#include <math.h>
#include <limits>
#include <string>
#include <sstream>
#include <boost/rational.hpp>
#include <boost/lexical_cast.hpp>
Macros | |
#define | TIME_SCALE_MS (lib::time::TimeValue::SCALE / 1000) |
scale factor used locally within this implementation header. More... | |
Functions | |
boost::rational< uint > | __framerate_approximation (double fps) |
boost::rational< uint > | __framerate_approximation (size_t cnt, Duration timeReference) |
int64_t | calculate_drop_frame_number (gavl_time_t time) |
reverse the drop-frame calculation More... | |
int64_t | calculate_quantisation (gavl_time_t time, gavl_time_t origin, gavl_time_t grid) |
int64_t | calculate_quantisation (gavl_time_t time, gavl_time_t origin, uint framerate, uint framerate_divisor=1) |
gavl_time_t | lumiera_build_time (long millis, uint secs, uint mins, uint hours) |
Build a time value by summing up the given components. More... | |
gavl_time_t | lumiera_build_time_fps (uint fps, uint frames, uint secs, uint mins, uint hours) |
Builds a time value by summing up the given components. More... | |
gavl_time_t | lumiera_build_time_ntsc_drop (uint frames, uint secs, uint mins, uint hours) |
Builds a time value by summing up the given components. More... | |
gavl_time_t | lumiera_frame_duration (FrameRate const &fps) |
Calculates the duration of one frame in Lumiera time units. More... | |
gavl_time_t | lumiera_framecount_to_time (uint64_t frameCount, FrameRate const &fps) |
Converts a frame count into Lumiera's internal time scale. More... | |
int64_t | lumiera_quantise_frames (gavl_time_t time, gavl_time_t origin, gavl_time_t grid) |
Quantise the given time into a fixed grid, relative to the origin. More... | |
int64_t | lumiera_quantise_frames_fps (gavl_time_t time, gavl_time_t origin, uint framerate) |
gavl_time_t | lumiera_quantise_time (gavl_time_t time, gavl_time_t origin, gavl_time_t grid) |
Similar to lumiera_quantise_frames, but returns a grid aligned relative time. More... | |
gavl_time_t | lumiera_rational_to_time (FSecs const &fractionalSeconds) |
int | lumiera_time_frames (gavl_time_t time, uint fps) |
Extract the remaining frame part of given time. More... | |
int | lumiera_time_hours (gavl_time_t time) |
Extract the hour part of given time. More... | |
int | lumiera_time_millis (gavl_time_t time) |
Extract the milliseconds part of given time. More... | |
int | lumiera_time_minutes (gavl_time_t time) |
Extract the minute part of given time. More... | |
int | lumiera_time_ntsc_drop_frames (gavl_time_t time) |
Extract the frame part of given time, using NTSC drop-frame timecode. | |
int | lumiera_time_ntsc_drop_hours (gavl_time_t time) |
Extract the hour part of given time, using NTSC drop-frame timecode. | |
int | lumiera_time_ntsc_drop_minutes (gavl_time_t time) |
Extract the minute part of given time, using NTSC drop-frame timecode. | |
int | lumiera_time_ntsc_drop_seconds (gavl_time_t time) |
Extract the second part of given time, using NTSC drop-frame timecode. | |
gavl_time_t | lumiera_time_of_gridpoint (int64_t nr, gavl_time_t origin, gavl_time_t grid) |
Calculate time of a grid point (frame start) More... | |
int | lumiera_time_seconds (gavl_time_t time) |
Extract the seconds part of given time. More... | |
char * | lumiera_tmpbuf_print_time (gavl_time_t time) |
template<typename RAT > | |
string | renderFraction (RAT const &frac, Literal postfx) noexcept |
Variables | |
Literal | DIAGNOSTIC_FORMAT {"%s%01d:%02d:%02d.%03d"} |
const uint | DISCREPANCY = (1*60 * 30) - FRAMES_PER_1min |
const uint | FRAMES_PER_10min = 10*60 * 30000/1001 |
const uint | FRAMES_PER_1min = 1*60 * 30000/1001 |
const FSecs | FSEC_MAX {std::numeric_limits<int64_t>::max() / lib::time::TimeValue::SCALE} |
const uint | RATE_LIMIT {std::numeric_limits<uint>::max() / 1024} |
a rather arbitrary safety limit imposed on internal numbers used to represent a frame rate. More... | |
Namespaces | |
lib | |
Implementation namespace for support and library code. | |
#define TIME_SCALE_MS (lib::time::TimeValue::SCALE / 1000) |
scale factor used locally within this implementation header.
GAVL_TIME_SCALE rsp. TimeValue::SCALE is the correct factor or dividend when using gavl_time_t for display on a scale with seconds. Since we want to use milliseconds, we need to multiply or divide by 1000 to get correct results.
Definition at line 109 of file time.cpp.
Referenced by lumiera_time_hours(), lumiera_time_millis(), lumiera_time_minutes(), lumiera_time_seconds(), and lumiera_tmpbuf_print_time().
boost::rational< uint > __framerate_approximation | ( | double | fps | ) |
helper to work around the limitations of uint
.
Definition at line 286 of file time.cpp.
References lib::time::__framerate_approximation(), and lib::time::RATE_LIMIT.
Referenced by lib::time::__framerate_approximation().
boost::rational< uint > __framerate_approximation | ( | size_t | cnt, |
Duration | timeReference | ||
) |
helper calculate the count per time span approximately, to the precision possible to represent as fractional uint
.
Definition at line 317 of file time.cpp.
References lib::time::__framerate_approximation(), TimeValue::_raw, lib::time::RATE_LIMIT, and TimeValue::SCALE.
char* lumiera_tmpbuf_print_time | ( | gavl_time_t | time | ) |
Diagnostics helper: render time value in H:MM:SS.mmm format.
safeclib
temporary buffer containing formatted time string Definition at line 395 of file time.cpp.
References lumiera_tmpbuf_snprintf(), and TIME_SCALE_MS.
gavl_time_t lumiera_rational_to_time | ( | FSecs const & | fractionalSeconds | ) |
FSecs
or RSec
class ///////////////////////TICKET #1262 Definition at line 422 of file time.cpp.
References Offset::abs().
gavl_time_t lumiera_framecount_to_time | ( | uint64_t | frameCount, |
lib::time::FrameRate const & | fps | ||
) |
Converts a frame count into Lumiera's internal time scale.
based on a framerate given as rational number (e.g. NTSC)
Definition at line 436 of file time.cpp.
Referenced by Offset::Offset().
gavl_time_t lumiera_frame_duration | ( | lib::time::FrameRate const & | fps | ) |
int64_t lumiera_quantise_frames | ( | gavl_time_t | time, |
gavl_time_t | origin, | ||
gavl_time_t | grid | ||
) |
Quantise the given time into a fixed grid, relative to the origin.
The time grid used for quantisation is comprised of equally spaced intervals, rooted at the given origin. The interval starting with the origin is numbered as zero. Each interval includes its lower bound, but excludes its upper bound.
grid | spacing of the grid intervals, measured in GAVL_TIME_SCALE |
Definition at line 494 of file time.cpp.
Referenced by FixedFrameQuantiser::gridPoint().
gavl_time_t lumiera_quantise_time | ( | gavl_time_t | time, |
gavl_time_t | origin, | ||
gavl_time_t | grid | ||
) |
Similar to lumiera_quantise_frames, but returns a grid aligned relative time.
Definition at line 506 of file time.cpp.
Referenced by FixedFrameQuantiser::gridLocal().
gavl_time_t lumiera_time_of_gridpoint | ( | int64_t | nr, |
gavl_time_t | origin, | ||
gavl_time_t | grid | ||
) |
Calculate time of a grid point (frame start)
nr | index number of the grid point (0 is at origin) |
grid | spacing of the grid intervals, measured in GAVL_TIME_SCALE |
Definition at line 514 of file time.cpp.
Referenced by FixedFrameQuantiser::timeOf().
gavl_time_t lumiera_build_time | ( | long | millis, |
uint | secs, | ||
uint | mins, | ||
uint | hours | ||
) |
gavl_time_t lumiera_build_time_fps | ( | uint | fps, |
uint | frames, | ||
uint | secs, | ||
uint | mins, | ||
uint | hours | ||
) |
int lumiera_time_hours | ( | gavl_time_t | time | ) |
Extract the hour part of given time.
Definition at line 544 of file time.cpp.
References TIME_SCALE_MS.
int lumiera_time_minutes | ( | gavl_time_t | time | ) |
Extract the minute part of given time.
Definition at line 550 of file time.cpp.
References TIME_SCALE_MS.
int lumiera_time_seconds | ( | gavl_time_t | time | ) |
Extract the seconds part of given time.
Definition at line 556 of file time.cpp.
References TIME_SCALE_MS.
int lumiera_time_millis | ( | gavl_time_t | time | ) |
Extract the milliseconds part of given time.
Definition at line 562 of file time.cpp.
References TIME_SCALE_MS.
int lumiera_time_frames | ( | gavl_time_t | time, |
uint | fps | ||
) |
gavl_time_t lumiera_build_time_ntsc_drop | ( | uint | frames, |
uint | secs, | ||
uint | mins, | ||
uint | hours | ||
) |
const uint RATE_LIMIT {std::numeric_limits<uint>::max() / 1024} |
a rather arbitrary safety limit imposed on internal numbers used to represent a frame rate.
Definition at line 277 of file time.cpp.
Referenced by lib::time::__framerate_approximation().