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

< Previous PageNext Page > Hide TOC

Atoms, QuickTime Atoms, and Atom Containers

QuickTime makes frequent use of data types known as atoms. You do not normally need to deal with QuickTime at the atomic level. In general, there are higher-level functions that allow you to, for example, create a movie, add or delete a track, or set a track’s media type, without directly manipulating, or necessarily knowing anything about, atoms.

To understand the various ways movies can be delivered over a network, however, it is useful to know how movies are stored in files, and QuickTime movies are stored in files as atoms.

An atom is simply a container; it has a 4-byte length field, which specifies its total size (including the length field), and a 4-byte type field, typically four ASCII characters, which specifies the type of atom it is. The type field can be followed by data, the amount and kind of data depending on the atom type.


Figure 1-8  Atom layout

Atom layout

The smallest possible atom is therefore 8 bytes: a 4-byte size field and a 4-byte type field, with no data.

Note: Because no atom can be smaller than 8 bytes, the size field can contain the values 0 through 7 as special flags; a flag could indicate, for example, that the atom extends to the end of a file, or that the atom is larger than a 32-bit field can describe, and the actual size is in a 64-bit field following the type field.

One atom can contain other atoms, allowing you to nest them in arbitrary hierarchies. This makes atoms handy building blocks for larger data structures.

You can “insert” one atom into another simply by appending the new atom and adding its size to the size field of the original atom. The original atom has now been extended to “contain” the new atom. If the original atom is inside yet another atom, that atom can be extended in the same manner.

An atom inside another atom is sometimes called a child atom. Child atoms at the same level in a hierarchy are called siblings. An atom that has other atoms inside is called a parent atom or container atom. An atom that has tabular data inside, instead of other atoms, is called a leaf atom.

Note: It is possible for an atom to contain both tabular data and other atoms, but this is discouraged.


Figure 1-9  Parent atoms and leaf atoms

Parent atoms and leaf atoms

Because an atom begins with its size, it is easy to “walk” an atom structure by skipping from atom to atom within the structure. You can quickly scan a collection of atoms for an atom of a particular type or skip over an atom you are not interested in.

A QuickTime movie is a parent atom whose type is 'moov'.

Each track in a movie is a child atom of type 'trak' inside a 'moov' atom.

Each track atom contains other child atoms, such as an edit list atom and a media atom. These atoms in turn contain other atoms, such as a media handler atom or various sample table atoms. The sample tables are leaf atoms.


Figure 1-10  Layout of a movie atom

Layout of a movie atom

Specific atoms are documented in the QuickTime API Reference, and may also be described conceptually in the documentation of a relevant topic, function, or group of functions. Additional details of the content and structure of various atoms can be found in the QuickTime File Format specification.

A refinement of the basic atom, used for some types of QuickTime data, is the QuickTime atom, or QT atom. This type of atom has additional header fields that specify the version of a particular atom type, an ID that allows you to distinguish one atom of a given type from its siblings in a hierarchy, and other useful information. It also has the restriction of containing either tabular data or other atoms, but never both. (If a QT atom needs to contain data about itself, in addition to containing other atoms, the necessary data is simply wrapped in an atom.)


Figure 1-11  QT Atom Layout

QT Atom Layout

At the highest level, a hierarchy of QT atoms is stored in an atom container. This is a unique data structure (not an atom) that contains a hierarchy of QT atoms.


Figure 1-12  Atom container and QT atoms

Atom container and QT atoms

Important: An atom container is not an atom; it is a non-atom data structure that contains a hierarchy of QT atoms. Do not confuse it with a “container atom” (another name for a parent atom), which is simply an atom that contains other atoms. To prevent confusion with atom containers, the term “parent atom” is preferred rather than “container atom.”

Complex data structures, such as compression settings, are commonly stored in atom containers. This allows these data structures to be flexible and extensible, unlike a rigid struct. Properties can be stored as atoms, and it is possible to find out if a particular instance of the structure has a given property, and what data format the property takes, before getting or setting the property. The QT atoms within a container are typically accessed by their byte offsets within the container, which makes data transfer quick and efficient.



< Previous PageNext Page > Hide TOC


Last updated: 2005-08-11




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