Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
time-dropframe-test.cpp
Go to the documentation of this file.
1/*
2 TimeDropframe(test) - document drop-frame calculation
3
4 Copyright (C)
5 2010 Stefan Kangas <skangas@skangas.se>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
23#include "lib/test/run.hpp"
27
28
29namespace lib {
30namespace time{
31namespace test{
32
33 using time::Time;
34 using time::TimeVar;
35 using time::FSecs;
37
38 namespace {// Test setup
39 const int FRAMES = 15;
40 const int MILLIS = 700;
41 const int SECONDS = 20;
42 const int MINUTES = 55;
43 const int HOURS = 3;
44
45
46 /* ====== conversion helpers to verify results ====== */
47
48 const auto TIME_SCALE_sec{lib::time::TimeValue::SCALE };
49 const auto TIME_SCALE_ms {lib::time::TimeValue::SCALE / 1'000};
50
51 int
52 dropframe_frames (raw_time_64 timecode)
53 {
54 return calculate_ntsc_drop_frame_number(timecode) % 30;
55 }
56
57 int
58 dropframe_seconds (raw_time_64 timecode)
59 {
60 return calculate_ntsc_drop_frame_number(timecode) / 30 % 60;
61 }
62
63 int
64 dropframe_minutes (raw_time_64 timecode)
65 {
66 return calculate_ntsc_drop_frame_number(timecode) / 30 / 60 % 60;
67 }
68
69 int
70 dropframe_hours (raw_time_64 timecode)
71 {
72 return calculate_ntsc_drop_frame_number(timecode) / 30 / 60 / 60 % 24;
73 }
74
75 int
76 time_hours (raw_time_64 time)
77 {
78 return time / TIME_SCALE_sec / 60 / 60;
79 }
80
81 int
82 time_minutes (raw_time_64 time)
83 {
84 return (time / TIME_SCALE_sec / 60) % 60;
85 }
86
87 int
88 time_seconds (raw_time_64 time)
89 {
90 return (time / TIME_SCALE_sec) % 60;
91 }
92
93 int
94 time_millis (raw_time_64 time)
95 {
96 return (time / TIME_SCALE_ms) % 1000;
97 }
98 }
99
100
101
102
103 /******************************************************************/
106 class TimeDropframe_test : public Test
107 {
108 virtual void
109 run (Arg)
110 {
113 }
114
115
119 void
121 {
122 // Make sure frame 0 begins at 0
124 CHECK (t == 0);
125
126 t = build_time_from_ntsc_drop_frame (FRAMES, SECONDS, MINUTES, HOURS);
127
128 // Calculate manually what result to expect....
129 int frames = FRAMES + 30*SECONDS + 30*60*MINUTES + 30*60*60*HOURS; // sum up using nominal 30fps
130 int minutes_to_drop_frames = (MINUTES - MINUTES/10) + (HOURS * 54); // but every minute, with the exception of every 10 minutes...
131 frames -= 2*minutes_to_drop_frames; // ...drop 2 frames
132 int64_t expectedMillis = 1000LL * frames * 1001/30000; // now convert frames to time, using the real framerate
133
134 expectedMillis %= 1000; // look at the remainder..
135 CHECK (time_millis (t) == expectedMillis);
136
137 CHECK (time_seconds (t) == SECONDS); // while all other components should come out equal as set
138 CHECK (time_minutes (t) == MINUTES);
139 CHECK (time_hours (t) == HOURS);
140
141 // Reverse calculate frames for NTSC drop
142 //CHECK (lumiera_quantise_frames (t, 0, dropFrameDuration) == frames); // the total nominal frames
143 CHECK (dropframe_frames (t) == FRAMES); // maximum one frame off due to rounding
144
145 }
146
147
148
153 void
155 {
156 for (int hrs = 0; hrs <= 24; hrs += 6)
157 for (int min = 0; min <= 59; min += 1)
158 for (int sec = 0; sec <= 59; sec += 10)
159 for (int frame = 0; frame <= 29; frame++)
160 {
161 // Skip dropped frames
162 if (min % 10 and sec == 0 and frame < 2)
163 continue;
164
165 raw_time_64 t = build_time_from_ntsc_drop_frame(frame, sec, min, hrs);
166 /*
167 ECHO ("%02d:%02d:%02d;%02d"
168 , lumiera_time_ntsc_drop_hours (t)
169 , lumiera_time_ntsc_drop_minutes (t)
170 , lumiera_time_ntsc_drop_seconds (t)
171 , lumiera_time_ntsc_drop_frames (t)
172 );
173 */
174 CHECK (dropframe_frames (t) == frame);
175 CHECK (dropframe_seconds (t) == sec);
176 CHECK (dropframe_minutes (t) == min);
177 CHECK (dropframe_hours (t) == hrs % 24);
178 }
179
180 // Make sure we do not get non-existent frames
181 for (int i = 0; i < 59; i++)
182 {
183 int frame = (i % 10 == 0) ? 0 : 2;
184 raw_time_64 t = build_time_from_ntsc_drop_frame (frame, 0, i, 0);
185 CHECK (dropframe_frames (t) == frame);
186 }
187 }
188 };
189
190
192 LAUNCHER (TimeDropframe_test, "unit common");
193
194
195
196}}} // namespace lib::time::test
static const raw_time_64 SCALE
Number of micro ticks (µs) per second as basic time scale.
a mutable time value, behaving like a plain number, allowing copy and re-accessing
Lumiera's internal time value datatype.
Calculations to support mapping into NTSC drop frame timecode.
raw_time_64 build_time_from_ntsc_drop_frame(uint frames, uint secs, uint mins, uint hours)
Build effective time from a NTSC drop frame timecode.
int64_t raw_time_64
Raw µ-tick time representation used in Lumiera.
int64_t calculate_ntsc_drop_frame_number(raw_time_64 time)
Compute the consecutive frame number from a given time, which is interpreted at the NTSC drop frame t...
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
A collection of frequently used helper functions to support unit testing.
a family of time value like entities and their relationships.