Lumiera  0.pre.03
»edit your freedom«
timings.cpp
Go to the documentation of this file.
1 /*
2  Timings - timing specifications for a frame quantised data stream
3 
4  Copyright (C)
5  2012, Hermann Vosseler <Ichthyostega@web.de>
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 
14 
24 #include "steam/play/timings.hpp"
25 #include "lib/time/formats.hpp"
26 #include "lib/time/timequant.hpp"
27 #include "lib/rational.hpp"
28 
29 
30 namespace steam {
31 namespace play {
32 
33  using lib::time::PQuant;
34  using lib::time::Time;
35  using lib::time::TimeVar;
36  using lib::time::FrameCnt;
37  using lib::time::FSecs;
38 
39  namespace { // Hard wired placeholder settings...
40 
41  const Duration DEFAULT_ENGINE_LATENCY = Duration{Time{10,0}};
42  const Duration DEFAULT_JOB_PLANNING_TURNOVER(FSecs(3,2));
43 
44  }//(End)hard wired settings
45 
46 
47  namespace { // hidden local details of the service implementation....
48 
49  inline PQuant
50  buildStandardGridForFramerate (FrameRate fps)
51  {
52  return PQuant (new lib::time::FixedFrameQuantiser (fps));
53  }
54 
55  } // (End) hidden service impl details
56 
57 
58 
70  : grid_{buildStandardGridForFramerate(fps)}
71  , playbackUrgency {ASAP}
72  , playbackSpeed {1}
74  , outputLatency{Duration::NIL}
75  , engineLatency{DEFAULT_ENGINE_LATENCY}
76  {
77  ENSURE (grid_);
78  }
79 
80  Timings::Timings (FrameRate fps, Time realTimeAnchor)
81  : grid_{buildStandardGridForFramerate(fps)}
82  , playbackUrgency {TIMEBOUND}
83  , playbackSpeed {1}
84  , scheduledDelivery{realTimeAnchor}
85  , outputLatency {Duration::NIL}
86  , engineLatency{DEFAULT_ENGINE_LATENCY}
87  {
88  ENSURE (grid_);
89  }
90 
92 
93 
96  Timings Timings::DISABLED(FrameRate::HALTED);
97 
98 
99 
101  bool
103  {
104  return bool(grid_)
105  && (( (ASAP == playbackUrgency || NICE == playbackUrgency)
107  ||
108  (TIMEBOUND == playbackUrgency
109  && Time::MIN < scheduledDelivery && scheduledDelivery < Time::MAX)
110  );
111  }
112 
113  Time
114  Timings::getOrigin() const
115  {
116  return Time(grid_->timeOf(0));
117  }
118 
119 
120  Time
121  Timings::getFrameStartAt (FrameCnt frameNr) const
122  {
123  return Time(grid_->timeOf(frameNr));
124  }
125 
126 
127  Duration
128  Timings::getFrameDurationAt (TimeValue refPoint) const
129  {
130  FrameCnt frameNr = grid_->gridPoint (refPoint);
131  return getFrameDurationAt(frameNr);
132  }
133 
134 
135  Duration
136  Timings::getFrameDurationAt (FrameCnt refFrameNr) const
137  {
138  return Offset (grid_->timeOf(refFrameNr), grid_->timeOf(refFrameNr + 1));
139  }
140 
141 
142  FrameCnt
144  {
145  FrameCnt frameNr = grid_->gridPoint (refPoint);
146  return grid_->timeOf(frameNr) == refPoint? frameNr
147  : frameNr+1;
148  }
149 
150 
151 
158  Duration
160  {
161  return Duration (Time::MAX);
162  }
163 
164 
165  Time
166  Timings::getTimeDue(FrameCnt frameOffset) const
167  {
168  if (TIMEBOUND == playbackUrgency)
169  {
170  REQUIRE (scheduledDelivery != Time::NEVER);
171  return scheduledDelivery
172  + getRealOffset (frameOffset);
173  }
174  else
175  return Time::NEVER;
176  }
177 
178 
179  Offset
180  Timings::getRealOffset (FrameCnt frameOffset) const
181  {
182  Offset nominalOffset (grid_->timeOf(0), grid_->timeOf(frameOffset));
183  return isOriginalSpeed()? nominalOffset
184  : nominalOffset * playbackSpeed;
186  }
187 
188 
189  Duration
191  {
192  UNIMPLEMENTED ("controlling the job planning rhythm");
193  }
194 
195 
196  FrameCnt
197  Timings::establishNextPlanningChunkStart(FrameCnt anchorFrame) const
198  {
199  TimeVar breakingPoint = grid_->timeOf(anchorFrame);
200  breakingPoint += getPlanningChunkDuration();
201  FrameCnt nextFrame = grid_->gridPoint (breakingPoint);
202 
203  ASSERT (breakingPoint <= grid_->timeOf(nextFrame));
204  ASSERT (breakingPoint > grid_->timeOf(nextFrame-1));
205 
206  if (grid_->timeOf(nextFrame) == breakingPoint)
207  return nextFrame;
208  else
209  return nextFrame+1;
210  }
211 
212 
213 
214  Timings
215  Timings::constrainedBy (Timings additionalConditions)
216  {
217  UNIMPLEMENTED ("how to combine timing constraints");
218  }
219 
220 
221 
222 }} // namespace steam::play
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:232
FrameCnt getBreakPointAfter(TimeValue refPoint) const
the next grid point at or after the given reference time
Definition: timings.cpp:143
Time scheduledDelivery
a wall clock time corresponding to the Grid&#39;s origin. Can be Time::Never (=not time bound) ...
Definition: timings.hpp:93
bool isValid() const
Consistency self-check.
Definition: timings.cpp:102
Rational number support, based on boost::rational.
Framerate specified as frames per second.
Definition: timevalue.hpp:655
Generic frame timing specification.
Definition: timings.hpp:86
FrameCnt establishNextPlanningChunkStart(FrameCnt anchorFrame) const
establish the time point to anchor the next planning chunk, in accordance with getPlanningChunkDurati...
Definition: timings.cpp:197
Steam-Layer implementation namespace root.
static const Duration NIL
constant to indicate "no duration"
Definition: timevalue.hpp:506
Time getTimeDue(FrameCnt frameOffset) const
real time deadline for the given frame, without any latency.
Definition: timings.cpp:166
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
static Timings DISABLED
marker for halted output
Definition: timings.hpp:106
Offset getRealOffset(FrameCnt frameOffset) const
calculate the given frame&#39;s distance from origin, but do so using the real time scale, including any playback speed factor and similar corrections.
Definition: timings.cpp:180
Duration getPlanningChunkDuration() const
the minimum time span to be covered by frame calculation jobs planned in one sway.
Definition: timings.cpp:190
Duration engineLatency
reasonable guess at the scheduling and dispatch-delay of the render engine
Definition: timings.hpp:95
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:220
Duration constantFrameTimingsInterval(TimeValue startPoint) const
the frame spacing and duration remains constant for some time...
Definition: timings.cpp:159
Support library to represent grid-aligned time specifications This is part of Lumiera&#39;s time and time...
Timings(FrameRate fps)
Create a default initialised Timing constraint record.
Definition: timings.cpp:69
static const Time NEVER
border condition marker value. NEVER >= any time value
Definition: timevalue.hpp:314
Offset measures a distance in time.
Definition: timevalue.hpp:358
How to define a timing specification or constraint.
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:468
Definition of time code formats This header is part of the Lumiera time and timecode handling library...
int64_t FrameCnt
relative framecount or frame number.
Definition: digxel.hpp:312
basic constant internal time value.
Definition: timevalue.hpp:133
static const Time MAX
Definition: timevalue.hpp:309
Simple stand-alone Quantiser implementation based on a constant sized gird.
Definition: quantiser.hpp:135