Important: The information in this document is obsolete and should not be used for new development.
This section discusses the new latency APIs available in QuickTime 5.
Overview
Usage
Video Codec Latency API
Sound Output Latency API
QuickTime 5 has defined new APIs to retrieve the video and sound latencies from Video Codecs and Sound Output Components.
The latency values are used to separately offset the timebases of the video and/or sound media from that of the movie timebase. The offsets are based on pipeline delays within the implementation of the sound or video components. For example, given some video hardware that has several stages that will take five frames to go through between the start of decompression and when the data is displayed, the video codec should report a latency of five frames, so that QuickTime will schedule the frames in advance. The codec is responsible for reporting a latency that represents its accurate pipeline in order to maintain audio and video synchronization.
Some performance implications occur when dealing with implementations that have latency. Notably, starting and stopping a movie requires extra time since the media’s timebases will start before the movie timebase. When latency is present, an application should avoid setting the movies rate directly from positive to negative without going through zero first, since otherwise the latency will not be correctly taken into account (and video and sound will not be synchronized thereafter).
A limitation in the current implementation is that QuickTime does not support mixing different video latencies between different codecs. This limitation is within QuickTime and cannot be overcome by the codecs. Applications should avoid creating movies that mix multiple types of video codecs if the codecs have different latencies.
Video codecs for a given hardware should report the actual latency time required for the hardware.
Sound Output Components for a given hardware should report the actual latency time required for the hardware.
The following API is used by QuickTime to retrieve the video latency:
Retrieves the video latency from the specified video codec.
pascal ComponentResult ImageCodecGetDecompressLatency(ComponentInstance ci, TimeRecord * latency);
Specifies the image compressor component for the request.
Pointer to a time record containing the latency required for that codec.
The following code snippet shows an example implementation of this function:
pascal ComponentResult myCodecGetDecompressLatency(myCodecGlobals *glob, |
TimeRecord *latency) |
{ |
OSErr result = paramErr; |
// Example setting 33 ms latency |
if (latency != nil) { |
latency->value.hi = 0; |
latency->value.lo = 33; // latency value |
latency->scale = 1000; // 1 ms scale |
latency->base = nil; |
result = noErr; |
} |
return result; |
} |
ImageCodec.h
Retrieves the audio latency from the specified sound output component.
The new selector siOutputLatency for
the SoundComponentGetInfo function
is used by QuickTime to retrieve the sound latency. (The infoPtr parameter
points to a time record.)
#define siOutputLatency ‘olte’ |
The following code snippet shows an example implementation of this selector:
static pascal ComponentResult mySoundGetInfo(SoundComponentGlobalsPtr globals, SoundSource sourceID, OSType selector, void *infoPtr) |
{ |
ComponentResult result = noErr; |
PrefStructPtr prefsPtr; |
prefsPtr = *(globals->prefsHandle); |
switch (selector) { |
case siSampleSize: // return current sample size |
*((short *) infoPtr) = (short)prefsPtr->sampleSize; |
break; |
case siOutputLatency: // return the sound output latency |
// in this example, 25 ms |
if (infoPtr != nil) { |
infoPtr->value.hi = 0; |
infoPtr->value.lo = 25; // sound latency |
infoPtr->scale = 1000; // 1 ms scale |
infoPtr->base = nil; |
} |
break; |
. . . |
} |
Last updated: 2001-10-01