Add frame counting capabilities to time conversion lib.
This commit is contained in:
parent
ebd93b0f12
commit
d2702e8254
3 changed files with 36 additions and 0 deletions
|
|
@ -91,3 +91,16 @@ lumiera_time_millis(gavl_time_t time)
|
|||
{
|
||||
return (time / GAVL_TIME_SCALE_MS) % 1000;
|
||||
}
|
||||
|
||||
int
|
||||
lumiera_time_frames(gavl_time_t time, float fps)
|
||||
{
|
||||
return (fps * (lumiera_time_millis(time))) / 1000;
|
||||
}
|
||||
|
||||
int
|
||||
lumiera_time_frame_count(gavl_time_t time, float fps)
|
||||
{
|
||||
int ms = (time / GAVL_TIME_SCALE_MS);
|
||||
return fps * ms / 1000;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,5 +60,19 @@ int lumiera_time_seconds(gavl_time_t time);
|
|||
*/
|
||||
int lumiera_time_millis(gavl_time_t time);
|
||||
|
||||
/**
|
||||
* Get the frame part of given time, using the given number of frames.
|
||||
* @param gavl_time_t the time we are interested in converting
|
||||
* @param fps Frame rate (float for now, but should be a rational)
|
||||
*/
|
||||
int lumiera_time_frames(gavl_time_t time, float fps);
|
||||
|
||||
/**
|
||||
* Get the frame count for the given time.
|
||||
* @param gavl_time_t the time we are interested in converting
|
||||
* @param fps Frame rate (float for now, but should be a rational)
|
||||
*/
|
||||
int lumiera_time_frame_count(gavl_time_t time, float fps);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ const int MILLIS = 700;
|
|||
const int SECONDS = 20;
|
||||
const int MINUTES = 55;
|
||||
const int HOURS = 3;
|
||||
const float FPS = 24.0;
|
||||
|
||||
/*
|
||||
* 1. Basic functionality
|
||||
|
|
@ -46,6 +47,10 @@ TEST (basic) {
|
|||
CHECK (lumiera_time_seconds(t) == 0);
|
||||
CHECK (lumiera_time_minutes(t) == 0);
|
||||
CHECK (lumiera_time_hours(t) == 0);
|
||||
CHECK (lumiera_time_frames(t, FPS) == 0);
|
||||
CHECK (lumiera_time_frames(t, FPS+5) == 0);
|
||||
CHECK (lumiera_time_frame_count(t, FPS) == 0);
|
||||
CHECK (lumiera_time_frame_count(t, FPS+5) == 0);
|
||||
|
||||
ECHO ("%s", lumiera_tmpbuf_print_time(t));
|
||||
|
||||
|
|
@ -56,6 +61,10 @@ TEST (basic) {
|
|||
CHECK (lumiera_time_seconds(t) == SECONDS);
|
||||
CHECK (lumiera_time_minutes(t) == MINUTES);
|
||||
CHECK (lumiera_time_hours(t) == HOURS);
|
||||
CHECK (lumiera_time_frames(t, FPS) == (int)((FPS * MILLIS) / 1000));
|
||||
CHECK (lumiera_time_frames(t, FPS+5) == (int)(((FPS+5) * MILLIS) / 1000));
|
||||
CHECK (lumiera_time_frame_count(t, FPS) == 338896);
|
||||
CHECK (lumiera_time_frame_count(t, FPS+5) == 409500);
|
||||
|
||||
ECHO ("%s", lumiera_tmpbuf_print_time(t));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue