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) Lumiera.org
5  2012, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
33 #include "steam/play/timings.hpp"
34 #include "lib/time/formats.hpp"
35 #include "lib/time/timequant.hpp"
36 #include "lib/rational.hpp"
37 
38 
39 namespace steam {
40 namespace play {
41 
42  using lib::time::PQuant;
43  using lib::time::Time;
44  using lib::time::TimeVar;
45  using lib::time::FrameCnt;
46  using lib::time::FSecs;
47 
48  namespace { // Hard wired placeholder settings...
49 
50  const Duration DEFAULT_ENGINE_LATENCY = Duration{Time{10,0}};
51  const Duration DEFAULT_JOB_PLANNING_TURNOVER(FSecs(3,2));
52 
53  }//(End)hard wired settings
54 
55 
56  namespace { // hidden local details of the service implementation....
57 
58  inline PQuant
59  buildStandardGridForFramerate (FrameRate fps)
60  {
61  return PQuant (new lib::time::FixedFrameQuantiser (fps));
62  }
63 
64  } // (End) hidden service impl details
65 
66 
67 
79  : grid_{buildStandardGridForFramerate(fps)}
80  , playbackUrgency {ASAP}
81  , playbackSpeed {1}
83  , outputLatency{Duration::NIL}
84  , engineLatency{DEFAULT_ENGINE_LATENCY}
85  {
86  ENSURE (grid_);
87  }
88 
89  Timings::Timings (FrameRate fps, Time realTimeAnchor)
90  : grid_{buildStandardGridForFramerate(fps)}
91  , playbackUrgency {TIMEBOUND}
92  , playbackSpeed {1}
93  , scheduledDelivery{realTimeAnchor}
94  , outputLatency {Duration::NIL}
95  , engineLatency{DEFAULT_ENGINE_LATENCY}
96  {
97  ENSURE (grid_);
98  }
99 
101 
102 
105  Timings Timings::DISABLED(FrameRate::HALTED);
106 
107 
108 
110  bool
112  {
113  return bool(grid_)
114  && (( (ASAP == playbackUrgency || NICE == playbackUrgency)
116  ||
117  (TIMEBOUND == playbackUrgency
118  && Time::MIN < scheduledDelivery && scheduledDelivery < Time::MAX)
119  );
120  }
121 
122  Time
123  Timings::getOrigin() const
124  {
125  return Time(grid_->timeOf(0));
126  }
127 
128 
129  Time
130  Timings::getFrameStartAt (FrameCnt frameNr) const
131  {
132  return Time(grid_->timeOf(frameNr));
133  }
134 
135 
136  Duration
137  Timings::getFrameDurationAt (TimeValue refPoint) const
138  {
139  FrameCnt frameNr = grid_->gridPoint (refPoint);
140  return getFrameDurationAt(frameNr);
141  }
142 
143 
144  Duration
145  Timings::getFrameDurationAt (FrameCnt refFrameNr) const
146  {
147  return Offset (grid_->timeOf(refFrameNr), grid_->timeOf(refFrameNr + 1));
148  }
149 
150 
151  FrameCnt
153  {
154  FrameCnt frameNr = grid_->gridPoint (refPoint);
155  return grid_->timeOf(frameNr) == refPoint? frameNr
156  : frameNr+1;
157  }
158 
159 
160 
167  Duration
169  {
170  return Duration (Time::MAX);
171  }
172 
173 
174  Time
175  Timings::getTimeDue(FrameCnt frameOffset) const
176  {
177  if (TIMEBOUND == playbackUrgency)
178  {
179  REQUIRE (scheduledDelivery != Time::NEVER);
180  return scheduledDelivery
181  + getRealOffset (frameOffset);
182  }
183  else
184  return Time::NEVER;
185  }
186 
187 
188  Offset
189  Timings::getRealOffset (FrameCnt frameOffset) const
190  {
191  Offset nominalOffset (grid_->timeOf(0), grid_->timeOf(frameOffset));
192  return isOriginalSpeed()? nominalOffset
193  : nominalOffset * playbackSpeed;
195  }
196 
197 
198  Duration
200  {
201  UNIMPLEMENTED ("controlling the job planning rhythm");
202  }
203 
204 
205  FrameCnt
206  Timings::establishNextPlanningChunkStart(FrameCnt anchorFrame) const
207  {
208  TimeVar breakingPoint = grid_->timeOf(anchorFrame);
209  breakingPoint += getPlanningChunkDuration();
210  FrameCnt nextFrame = grid_->gridPoint (breakingPoint);
211 
212  ASSERT (breakingPoint <= grid_->timeOf(nextFrame));
213  ASSERT (breakingPoint > grid_->timeOf(nextFrame-1));
214 
215  if (grid_->timeOf(nextFrame) == breakingPoint)
216  return nextFrame;
217  else
218  return nextFrame+1;
219  }
220 
221 
222 
223  Timings
224  Timings::constrainedBy (Timings additionalConditions)
225  {
226  UNIMPLEMENTED ("how to combine timing constraints");
227  }
228 
229 
230 
231 }} // namespace steam::play
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:241
FrameCnt getBreakPointAfter(TimeValue refPoint) const
the next grid point at or after the given reference time
Definition: timings.cpp:152
Time scheduledDelivery
a wall clock time corresponding to the Grid&#39;s origin. Can be Time::Never (=not time bound) ...
Definition: timings.hpp:102
bool isValid() const
Consistency self-check.
Definition: timings.cpp:111
Rational number support, based on boost::rational.
Framerate specified as frames per second.
Definition: timevalue.hpp:664
Generic frame timing specification.
Definition: timings.hpp:95
FrameCnt establishNextPlanningChunkStart(FrameCnt anchorFrame) const
establish the time point to anchor the next planning chunk, in accordance with getPlanningChunkDurati...
Definition: timings.cpp:206
Steam-Layer implementation namespace root.
static const Duration NIL
constant to indicate "no duration"
Definition: timevalue.hpp:515
Time getTimeDue(FrameCnt frameOffset) const
real time deadline for the given frame, without any latency.
Definition: timings.cpp:175
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
static Timings DISABLED
marker for halted output
Definition: timings.hpp:115
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:189
Duration getPlanningChunkDuration() const
the minimum time span to be covered by frame calculation jobs planned in one sway.
Definition: timings.cpp:199
Duration engineLatency
reasonable guess at the scheduling and dispatch-delay of the render engine
Definition: timings.hpp:104
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:229
Duration constantFrameTimingsInterval(TimeValue startPoint) const
the frame spacing and duration remains constant for some time...
Definition: timings.cpp:168
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:78
static const Time NEVER
border condition marker value. NEVER >= any time value
Definition: timevalue.hpp:323
Offset measures a distance in time.
Definition: timevalue.hpp:367
How to define a timing specification or constraint.
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:477
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:321
basic constant internal time value.
Definition: timevalue.hpp:142
static const Time MAX
Definition: timevalue.hpp:318
Simple stand-alone Quantiser implementation based on a constant sized gird.
Definition: quantiser.hpp:144