2012-02-04 00:52:28 +01:00
|
|
|
/*
|
|
|
|
|
TIME-ANCHOR.hpp - current render evaluation time point closure
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2012, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef PROC_ENGINE_TIME_ANCHOR_H
|
|
|
|
|
#define PROC_ENGINE_TIME_ANCHOR_H
|
|
|
|
|
|
|
|
|
|
#include "proc/common.hpp"
|
2012-03-02 01:33:57 +01:00
|
|
|
#include "backend/real-clock.hpp"
|
2012-02-04 00:52:28 +01:00
|
|
|
#include "lib/time/timevalue.hpp"
|
2012-02-09 22:24:05 +01:00
|
|
|
#include "proc/play/timings.hpp"
|
2013-01-11 18:12:40 +01:00
|
|
|
#include "proc/engine/frame-coord.hpp"
|
2012-02-04 00:52:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace proc {
|
|
|
|
|
namespace engine {
|
|
|
|
|
|
2012-03-02 01:33:57 +01:00
|
|
|
using backend::RealClock;
|
2012-02-25 00:27:50 +01:00
|
|
|
using lib::time::Offset;
|
2013-01-12 12:38:33 +01:00
|
|
|
using lib::time::Duration;
|
2012-03-02 01:33:57 +01:00
|
|
|
using lib::time::TimeVar;
|
2012-02-24 00:29:59 +01:00
|
|
|
using lib::time::Time;
|
2013-01-11 16:48:28 +01:00
|
|
|
|
2012-02-04 00:52:28 +01:00
|
|
|
|
|
|
|
|
/**
|
2012-10-06 02:29:19 +02:00
|
|
|
* The process of playback or rendering is a continued series of exploration and evaluation.
|
|
|
|
|
* The outline of what needs to be calculated is determined continuously, proceeding in
|
|
|
|
|
* chunks of evaluation. Each of these continued partial evaluations establishes a distinct
|
|
|
|
|
* anchor or breaking point in time: everything before this point can be considered settled
|
|
|
|
|
* and planned thus far. Effectively, this time point acts as a <i>evaluation closure</i>,
|
2013-01-12 12:38:33 +01:00
|
|
|
* to be picked up for the next partial evaluation. Each time anchor defines a span of the
|
|
|
|
|
* timeline, which will be covered with the next round of job planning; the successive next
|
|
|
|
|
* TimeAnchor will be located at the first frame \em after this time span, resulting in
|
|
|
|
|
* seamless coverage of the whole timeline. Whenever a TimeAnchor is created, a relation
|
|
|
|
|
* between nominal time, current engine latency and wall clock time is established, This way,
|
|
|
|
|
* the TimeAnchor closure is the definitive binding between the abstract logical time of the
|
|
|
|
|
* session timeline, and the real wall-clock time forming the deadline for rendering.
|
2012-02-04 00:52:28 +01:00
|
|
|
*
|
2012-04-18 03:46:21 +02:00
|
|
|
* \par internals
|
|
|
|
|
* The time anchor associates a nominal time, defined on the implicit time grid
|
|
|
|
|
* of some given Timings, with an actual wall clock time. Due to the usage situation,
|
|
|
|
|
* the TimeAnchor takes on the secondary meaning of a breaking point; everything \em before
|
|
|
|
|
* this anchor point has been handled during the preceding invocations of an ongoing chunk wise
|
|
|
|
|
* partial evaluation of the timeline to play back.
|
|
|
|
|
* - the #timings_ serve as an abstracted grid (actually, the implementation
|
|
|
|
|
* does refer to a grid defined somewhere within the session)
|
|
|
|
|
* - the actual #anchorPoint_ is defined as frame number relative to this grid
|
|
|
|
|
* - this anchor point is scheduled to happen at a #relatedRealTime_, based on
|
2013-01-12 12:38:33 +01:00
|
|
|
* system's real time clock scale (typically milliseconds since 1970).
|
|
|
|
|
* This schedule contains a compensation for engine and output latency.
|
|
|
|
|
*
|
|
|
|
|
* @remarks please note that time anchors are set per CalcStream.
|
|
|
|
|
* Since different streams might use different frame grids, the rhythm
|
|
|
|
|
* of these planning operations is likely to be specific for a given stream.
|
|
|
|
|
* The relation to real time is established anew at each time anchor, so any
|
|
|
|
|
* adjustments to the engine latency will be reflected in the planned job's
|
|
|
|
|
* deadlines. Actually, the embedded Timings record is responsible for these
|
|
|
|
|
* timing calculation and for fetching the current EngineConfig.
|
2012-04-18 03:46:21 +02:00
|
|
|
*
|
2013-01-12 12:38:33 +01:00
|
|
|
* @see Dispatcher
|
|
|
|
|
* @see DispatcherInterface_test
|
|
|
|
|
* @see Timings
|
2012-02-04 00:52:28 +01:00
|
|
|
*/
|
|
|
|
|
class TimeAnchor
|
|
|
|
|
{
|
2012-02-25 00:27:50 +01:00
|
|
|
play::Timings timings_;
|
2012-03-02 01:33:57 +01:00
|
|
|
int64_t anchorPoint_;
|
2012-02-24 00:29:59 +01:00
|
|
|
Time relatedRealTime_;
|
2012-02-04 00:52:28 +01:00
|
|
|
|
2012-02-25 00:27:50 +01:00
|
|
|
Time
|
2013-01-12 12:38:33 +01:00
|
|
|
expectedTimeofArival (play::Timings const& timings, int64_t startFrame, Offset startDelay)
|
2012-02-04 00:52:28 +01:00
|
|
|
{
|
2013-01-12 12:38:33 +01:00
|
|
|
Duration totalLatency = startDelay
|
|
|
|
|
+ timings.currentEngineLatency()
|
|
|
|
|
+ timings.outputLatency;
|
2012-02-25 00:27:50 +01:00
|
|
|
TimeVar deadline;
|
|
|
|
|
switch (timings.playbackUrgency)
|
|
|
|
|
{
|
|
|
|
|
case play::ASAP:
|
|
|
|
|
case play::NICE:
|
2013-01-12 12:38:33 +01:00
|
|
|
deadline = RealClock::now() + totalLatency;
|
2012-02-25 00:27:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case play::TIMEBOUND:
|
2013-01-12 12:38:33 +01:00
|
|
|
deadline = timings.getTimeDue(startFrame) - totalLatency;
|
2012-02-25 00:27:50 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2013-01-12 12:38:33 +01:00
|
|
|
return deadline;
|
2012-02-04 00:52:28 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-25 00:27:50 +01:00
|
|
|
|
2013-01-12 12:38:33 +01:00
|
|
|
TimeAnchor (play::Timings timings, int64_t startFrame, Offset startDelay =Offset::ZERO)
|
2012-02-25 00:27:50 +01:00
|
|
|
: timings_(timings)
|
2012-03-02 01:33:57 +01:00
|
|
|
, anchorPoint_(startFrame)
|
2013-01-12 12:38:33 +01:00
|
|
|
, relatedRealTime_(expectedTimeofArival(timings,startFrame,startDelay))
|
2012-02-25 00:27:50 +01:00
|
|
|
{ }
|
|
|
|
|
|
2012-02-09 22:24:05 +01:00
|
|
|
public:
|
2012-02-04 00:52:28 +01:00
|
|
|
// using default copy operations
|
2012-02-09 22:24:05 +01:00
|
|
|
|
2012-02-25 00:27:50 +01:00
|
|
|
|
2013-01-12 12:38:33 +01:00
|
|
|
/** create a TimeAnchor for playback/rendering start at the given startFrame.
|
|
|
|
|
* For latency calculations, the EngineConfig will be queried behind the scenes.
|
2012-02-25 00:27:50 +01:00
|
|
|
* regarding the reaction latency required to get the engine
|
2013-01-12 12:38:33 +01:00
|
|
|
* @note this builder function adds an additional, hard wired start margin
|
|
|
|
|
* of one frame duration, to compensate for first time effects.
|
2012-02-25 00:27:50 +01:00
|
|
|
*/
|
2012-02-09 22:24:05 +01:00
|
|
|
static TimeAnchor
|
2012-03-02 01:33:57 +01:00
|
|
|
build (play::Timings timings, int64_t startFrame)
|
2012-02-09 22:24:05 +01:00
|
|
|
{
|
2013-01-12 12:38:33 +01:00
|
|
|
Offset startDelay(timings.getFrameDurationAt(startFrame));
|
|
|
|
|
return TimeAnchor (timings,startFrame,startDelay);
|
2012-02-09 22:24:05 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-12 12:38:33 +01:00
|
|
|
|
|
|
|
|
/** create a follow-up TimeAnchor.
|
|
|
|
|
* After planning a chunk of jobs, the dispatcher uses
|
|
|
|
|
* this function to set up a new breaking point (TimeAnchor)
|
|
|
|
|
* and places a continuation job to resume the planning activity.
|
|
|
|
|
* @return new TimeAchor which precisely satisfies the <i>planning
|
|
|
|
|
* chunk duration</i>: it will be anchored at the following
|
|
|
|
|
* grid point, resulting in seamless coverage of the timeline
|
|
|
|
|
*/
|
|
|
|
|
TimeAnchor
|
|
|
|
|
buildNextAnchor() const
|
|
|
|
|
{
|
|
|
|
|
int64_t nextStart = timings_.establishNextPlanningChunkStart (this->anchorPoint_);
|
|
|
|
|
return TimeAnchor(this->timings_, nextStart);
|
|
|
|
|
}
|
2012-02-25 00:27:50 +01:00
|
|
|
|
|
|
|
|
|
2012-04-18 03:46:21 +02:00
|
|
|
/** @internal for debugging and diagnostics:
|
|
|
|
|
* explicitly cast this TimeAnchor onto the underlying
|
|
|
|
|
* nominal time scale (as defined by the Timings of this
|
|
|
|
|
* playback or render process). */
|
2012-02-09 22:24:05 +01:00
|
|
|
operator lib::time::TimeValue() const
|
|
|
|
|
{
|
2013-01-12 12:38:33 +01:00
|
|
|
return timings_.getFrameStartAt (anchorPoint_);
|
2012-02-09 22:24:05 +01:00
|
|
|
}
|
2013-01-11 18:12:40 +01:00
|
|
|
|
|
|
|
|
|
2013-01-12 12:49:26 +01:00
|
|
|
/** @return the frame at which any job planning
|
|
|
|
|
* for this planning chunk will start */
|
|
|
|
|
int64_t getStartFrame() const
|
|
|
|
|
{
|
|
|
|
|
return anchorPoint_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-11 18:12:40 +01:00
|
|
|
|
|
|
|
|
Offset
|
|
|
|
|
remainingRealTimeFor (FrameCoord plannedFrame)
|
|
|
|
|
{
|
|
|
|
|
int64_t frameOffset = plannedFrame.absoluteFrameNumber - anchorPoint_;
|
|
|
|
|
return Offset(this->relatedRealTime_
|
|
|
|
|
+ timings_.getRealOffset(frameOffset)
|
|
|
|
|
- RealClock::now());
|
|
|
|
|
}
|
2012-02-04 00:52:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}} // namespace proc::engine
|
|
|
|
|
#endif
|