Graphics Reference
In-Depth Information
Layer Timing
Notice in both
-canDrawInCGLContext
and
-drawInCGLContext,
two fields relate to time:
.
forLayerTime
, which is a
CFTimeInterval
.
displayTime
, which is a
CVTimeStamp
We won't focus on
forLayerTime
because we won't be using it with
CAOpenGLLayer
;
however,
displayTime
is important for this exercise.
Playing back movies correctly with a display's refresh rate and in-sync with the movie's
sound can be tricky. However, Apple has achieved stable movie playback in the Mac OS
using what they refer to as a
display link
. Here is how Apple defines a display link in the
Core Video Programming Guide
:
1
To simplify synchronization of video with a display's refresh rate, Core Video
provides a special timer called a display link. The display link runs as a separate
high priority thread, which is not affected by interactions within your applica-
tion process.
In the past, synchronizing your video frames with the display's refresh rate was
often a problem, especially if you also had audio. You could make only simple
guesses for when to output a frame (by using a timer, for example), which didn't
take into account possible latency from user interactions, CPU loading, window
compositing, and so on. The Core Video display link can make intelligent esti-
mates for when a frame needs to be output, based on display type and latencies.
In essence this means that you must set up a callback that will get called periodically, at
which point you can check to see if a new frame is available for display at the time speci-
fied in the callback's
inOutputTime CVTimeStamp
field. The display link callback signature
is in Listing 8-2.
LISTING 8-2
Display Link Callback Signature
CVReturn MyDisplayLinkCallback (
CVDisplayLinkRef
displayLink,
const
CVTimeStamp
*inNow,
const
CVTimeStamp
*inOutputTime,
CVOptionFlags
flagsIn,
CVOptionFlags
*flagsOut,
void
*displayLinkContext);
1
Apple's
Core Video Programming Guide
(p. 10): http://developer.apple.com/mac/library/
documentation/GraphicsImaging/Conceptual/CoreVideo/CoreVideo.pdf.