Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

New Latency APIs

This section discusses the new latency APIs available in QuickTime 5.

In this section:

Overview
Usage
Video Codec Latency API
Sound Output Latency API


Overview

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.

Usage

Applications

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

Video codecs for a given hardware should report the actual latency time required for the hardware.

Sound Output Components

Sound Output Components for a given hardware should report the actual latency time required for the hardware.

Video Codec Latency API

The following API is used by QuickTime to retrieve the video latency:

ImageCodecGetDecompressLatency

Retrieves the video latency from the specified video codec.

pascal ComponentResult ImageCodecGetDecompressLatency(ComponentInstance                                              ci, TimeRecord * latency);

Parameters
ci

Specifies the image compressor component for the request.

latency

Pointer to a time record containing the latency required for that codec.

Discussion

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;
}
Availability
Declared In
ImageCodec.h

Sound Output Latency API

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;
 
. . .
 
}


< Previous PageNext Page > Hide TOC


Last updated: 2001-10-01




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice