xref: /aosp_15_r20/external/libogg/doc/oggstream.html (revision 4d5d8b54cec1a9622d79143ad0e145ea73da2224)
1*4d5d8b54SAndroid Build Coastguard Worker<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2*4d5d8b54SAndroid Build Coastguard Worker<html>
3*4d5d8b54SAndroid Build Coastguard Worker<head>
4*4d5d8b54SAndroid Build Coastguard Worker
5*4d5d8b54SAndroid Build Coastguard Worker<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15"/>
6*4d5d8b54SAndroid Build Coastguard Worker<title>Ogg Documentation</title>
7*4d5d8b54SAndroid Build Coastguard Worker
8*4d5d8b54SAndroid Build Coastguard Worker<style type="text/css">
9*4d5d8b54SAndroid Build Coastguard Workerbody {
10*4d5d8b54SAndroid Build Coastguard Worker  margin: 0 18px 0 18px;
11*4d5d8b54SAndroid Build Coastguard Worker  padding-bottom: 30px;
12*4d5d8b54SAndroid Build Coastguard Worker  font-family: Verdana, Arial, Helvetica, sans-serif;
13*4d5d8b54SAndroid Build Coastguard Worker  color: #333333;
14*4d5d8b54SAndroid Build Coastguard Worker  font-size: .8em;
15*4d5d8b54SAndroid Build Coastguard Worker}
16*4d5d8b54SAndroid Build Coastguard Worker
17*4d5d8b54SAndroid Build Coastguard Workera {
18*4d5d8b54SAndroid Build Coastguard Worker  color: #3366cc;
19*4d5d8b54SAndroid Build Coastguard Worker}
20*4d5d8b54SAndroid Build Coastguard Worker
21*4d5d8b54SAndroid Build Coastguard Workerimg {
22*4d5d8b54SAndroid Build Coastguard Worker  border: 0;
23*4d5d8b54SAndroid Build Coastguard Worker}
24*4d5d8b54SAndroid Build Coastguard Worker
25*4d5d8b54SAndroid Build Coastguard Worker#xiphlogo {
26*4d5d8b54SAndroid Build Coastguard Worker  margin: 30px 0 16px 0;
27*4d5d8b54SAndroid Build Coastguard Worker}
28*4d5d8b54SAndroid Build Coastguard Worker
29*4d5d8b54SAndroid Build Coastguard Worker#content p {
30*4d5d8b54SAndroid Build Coastguard Worker  line-height: 1.4;
31*4d5d8b54SAndroid Build Coastguard Worker}
32*4d5d8b54SAndroid Build Coastguard Worker
33*4d5d8b54SAndroid Build Coastguard Workerh1, h1 a, h2, h2 a, h3, h3 a {
34*4d5d8b54SAndroid Build Coastguard Worker  font-weight: bold;
35*4d5d8b54SAndroid Build Coastguard Worker  color: #ff9900;
36*4d5d8b54SAndroid Build Coastguard Worker  margin: 1.3em 0 8px 0;
37*4d5d8b54SAndroid Build Coastguard Worker}
38*4d5d8b54SAndroid Build Coastguard Worker
39*4d5d8b54SAndroid Build Coastguard Workerh1 {
40*4d5d8b54SAndroid Build Coastguard Worker  font-size: 1.3em;
41*4d5d8b54SAndroid Build Coastguard Worker}
42*4d5d8b54SAndroid Build Coastguard Worker
43*4d5d8b54SAndroid Build Coastguard Workerh2 {
44*4d5d8b54SAndroid Build Coastguard Worker  font-size: 1.2em;
45*4d5d8b54SAndroid Build Coastguard Worker}
46*4d5d8b54SAndroid Build Coastguard Worker
47*4d5d8b54SAndroid Build Coastguard Workerh3 {
48*4d5d8b54SAndroid Build Coastguard Worker  font-size: 1.1em;
49*4d5d8b54SAndroid Build Coastguard Worker}
50*4d5d8b54SAndroid Build Coastguard Worker
51*4d5d8b54SAndroid Build Coastguard Workerli {
52*4d5d8b54SAndroid Build Coastguard Worker  line-height: 1.4;
53*4d5d8b54SAndroid Build Coastguard Worker}
54*4d5d8b54SAndroid Build Coastguard Worker
55*4d5d8b54SAndroid Build Coastguard Worker#copyright {
56*4d5d8b54SAndroid Build Coastguard Worker  margin-top: 30px;
57*4d5d8b54SAndroid Build Coastguard Worker  line-height: 1.5em;
58*4d5d8b54SAndroid Build Coastguard Worker  text-align: center;
59*4d5d8b54SAndroid Build Coastguard Worker  font-size: .8em;
60*4d5d8b54SAndroid Build Coastguard Worker  color: #888888;
61*4d5d8b54SAndroid Build Coastguard Worker  clear: both;
62*4d5d8b54SAndroid Build Coastguard Worker}
63*4d5d8b54SAndroid Build Coastguard Worker
64*4d5d8b54SAndroid Build Coastguard Worker.caption {
65*4d5d8b54SAndroid Build Coastguard Worker  color: #000000;
66*4d5d8b54SAndroid Build Coastguard Worker  background-color: #aabbff;
67*4d5d8b54SAndroid Build Coastguard Worker  margin: 1em;
68*4d5d8b54SAndroid Build Coastguard Worker  margin-left: 2em;
69*4d5d8b54SAndroid Build Coastguard Worker  margin-right: 2em;
70*4d5d8b54SAndroid Build Coastguard Worker  padding: 1em;
71*4d5d8b54SAndroid Build Coastguard Worker  padding-bottom: 0em;
72*4d5d8b54SAndroid Build Coastguard Worker  overflow: hidden;
73*4d5d8b54SAndroid Build Coastguard Worker}
74*4d5d8b54SAndroid Build Coastguard Worker
75*4d5d8b54SAndroid Build Coastguard Worker.caption p {
76*4d5d8b54SAndroid Build Coastguard Worker  clear: none;
77*4d5d8b54SAndroid Build Coastguard Worker}
78*4d5d8b54SAndroid Build Coastguard Worker
79*4d5d8b54SAndroid Build Coastguard Worker.caption img {
80*4d5d8b54SAndroid Build Coastguard Worker  display: block;
81*4d5d8b54SAndroid Build Coastguard Worker  margin: 0px;
82*4d5d8b54SAndroid Build Coastguard Worker  margin-left: auto;
83*4d5d8b54SAndroid Build Coastguard Worker  margin-right: auto;
84*4d5d8b54SAndroid Build Coastguard Worker  margin-bottom: 1.5em;
85*4d5d8b54SAndroid Build Coastguard Worker  background-color: #ffffff;
86*4d5d8b54SAndroid Build Coastguard Worker  padding: 10px;
87*4d5d8b54SAndroid Build Coastguard Worker}
88*4d5d8b54SAndroid Build Coastguard Worker
89*4d5d8b54SAndroid Build Coastguard Worker#thepage {
90*4d5d8b54SAndroid Build Coastguard Worker  margin-left: auto;
91*4d5d8b54SAndroid Build Coastguard Worker  margin-right: auto;
92*4d5d8b54SAndroid Build Coastguard Worker  width: 840px;
93*4d5d8b54SAndroid Build Coastguard Worker}
94*4d5d8b54SAndroid Build Coastguard Worker
95*4d5d8b54SAndroid Build Coastguard Worker</style>
96*4d5d8b54SAndroid Build Coastguard Worker
97*4d5d8b54SAndroid Build Coastguard Worker</head>
98*4d5d8b54SAndroid Build Coastguard Worker
99*4d5d8b54SAndroid Build Coastguard Worker<body>
100*4d5d8b54SAndroid Build Coastguard Worker<div id="thepage">
101*4d5d8b54SAndroid Build Coastguard Worker
102*4d5d8b54SAndroid Build Coastguard Worker<div id="xiphlogo">
103*4d5d8b54SAndroid Build Coastguard Worker  <a href="http://www.xiph.org/"><img src="fish_xiph_org.png" alt="Fish Logo and Xiph.org"/></a>
104*4d5d8b54SAndroid Build Coastguard Worker</div>
105*4d5d8b54SAndroid Build Coastguard Worker
106*4d5d8b54SAndroid Build Coastguard Worker<h1>Ogg bitstream overview</h1>
107*4d5d8b54SAndroid Build Coastguard Worker
108*4d5d8b54SAndroid Build Coastguard Worker<p>This document serves as starting point for understanding the design
109*4d5d8b54SAndroid Build Coastguard Workerand implementation of the Ogg container format.  If you're new to Ogg
110*4d5d8b54SAndroid Build Coastguard Workeror merely want a high-level technical overview, start reading here.
111*4d5d8b54SAndroid Build Coastguard WorkerOther documents linked from the <a href="index.html">index page</a>
112*4d5d8b54SAndroid Build Coastguard Workergive distilled technical descriptions and references of the container
113*4d5d8b54SAndroid Build Coastguard Workermechanisms.  This document is intended to aid understanding.
114*4d5d8b54SAndroid Build Coastguard Worker
115*4d5d8b54SAndroid Build Coastguard Worker<h2>Container format design points</h2>
116*4d5d8b54SAndroid Build Coastguard Worker
117*4d5d8b54SAndroid Build Coastguard Worker<p>Ogg is intended to be a simplest-possible container, concerned only
118*4d5d8b54SAndroid Build Coastguard Workerwith framing, ordering, and interleave. It can be used as a stream delivery
119*4d5d8b54SAndroid Build Coastguard Workermechanism, for media file storage, or as a building block toward
120*4d5d8b54SAndroid Build Coastguard Workerimplementing a more complex, non-linear container (for example, see
121*4d5d8b54SAndroid Build Coastguard Workerthe <a href="skeleton.html">Skeleton</a> or <a
122*4d5d8b54SAndroid Build Coastguard Workerhref="http://en.wikipedia.org/wiki/Annodex">Annodex/CMML</a>).
123*4d5d8b54SAndroid Build Coastguard Worker
124*4d5d8b54SAndroid Build Coastguard Worker<p>The Ogg container is not intended to be a monolithic
125*4d5d8b54SAndroid Build Coastguard Worker'kitchen-sink'.  It exists only to frame and deliver in-order stream
126*4d5d8b54SAndroid Build Coastguard Workerdata and as such is vastly simpler than most other containers.
127*4d5d8b54SAndroid Build Coastguard WorkerElementary and multiplexed streams are both constructed entirely from a
128*4d5d8b54SAndroid Build Coastguard Workersingle building block (an Ogg page) comprised of eight fields
129*4d5d8b54SAndroid Build Coastguard Workertotalling twenty-eight bytes (the page header) a list of packet lengths
130*4d5d8b54SAndroid Build Coastguard Worker(up to 255 bytes) and payload data (up to 65025 bytes).  The structure
131*4d5d8b54SAndroid Build Coastguard Workerof every page is the same.  There are no optional fields or alternate
132*4d5d8b54SAndroid Build Coastguard Workerencodings.
133*4d5d8b54SAndroid Build Coastguard Worker
134*4d5d8b54SAndroid Build Coastguard Worker<p>Stream and media metadata is contained in Ogg and not built into
135*4d5d8b54SAndroid Build Coastguard Workerthe Ogg container itself.  Metadata is thus compartmentalized and
136*4d5d8b54SAndroid Build Coastguard Workerlayered rather than part of a monolithic design, an especially good
137*4d5d8b54SAndroid Build Coastguard Workeridea as no two groups seem able to agree on what a complete or
138*4d5d8b54SAndroid Build Coastguard Workercomplete-enough metadata set should be. In this way, the container and
139*4d5d8b54SAndroid Build Coastguard Workercontainer implementation are isolated from unnecessary metadata design
140*4d5d8b54SAndroid Build Coastguard Workerflux.
141*4d5d8b54SAndroid Build Coastguard Worker
142*4d5d8b54SAndroid Build Coastguard Worker<h3>Streaming</h3>
143*4d5d8b54SAndroid Build Coastguard Worker
144*4d5d8b54SAndroid Build Coastguard Worker<p>The Ogg container is primarily a streaming format,
145*4d5d8b54SAndroid Build Coastguard Workerencapsulating chronological, time-linear mixed media into a single
146*4d5d8b54SAndroid Build Coastguard Workerdelivery stream or file. The design is such that an application can
147*4d5d8b54SAndroid Build Coastguard Workeralways encode and/or decode all features of a bitstream in one pass
148*4d5d8b54SAndroid Build Coastguard Workerwith no seeking and minimal buffering.  Seeking to provide optimized
149*4d5d8b54SAndroid Build Coastguard Workerencoding (such as two-pass encoding) or interactive decoding (such as
150*4d5d8b54SAndroid Build Coastguard Workerscrubbing or instant replay) is not disallowed or discouraged, however
151*4d5d8b54SAndroid Build Coastguard Workerno container feature requires nonlinear access of the bitstream.
152*4d5d8b54SAndroid Build Coastguard Worker
153*4d5d8b54SAndroid Build Coastguard Worker<h3>Variable Bit Rate, Variable Payload Size</h3>
154*4d5d8b54SAndroid Build Coastguard Worker
155*4d5d8b54SAndroid Build Coastguard Worker<p>Ogg is designed to contain any size data payload with bounded,
156*4d5d8b54SAndroid Build Coastguard Workerpredictable efficiency.  Ogg packets have no maximum size and a
157*4d5d8b54SAndroid Build Coastguard Workerzero-byte minimum size.  There is no restriction on size changes from
158*4d5d8b54SAndroid Build Coastguard Workerpacket to packet. Variable size packets do not require the use of any
159*4d5d8b54SAndroid Build Coastguard Workeroptional or additional container features.  There is no optimal
160*4d5d8b54SAndroid Build Coastguard Workersuggested packet size, though special consideration was paid to make
161*4d5d8b54SAndroid Build Coastguard Workersure 50-200 byte packets were no less efficient than larger packet
162*4d5d8b54SAndroid Build Coastguard Workersizes.  The original design criteria was a 2% overhead at 50 byte
163*4d5d8b54SAndroid Build Coastguard Workerpackets, dropping to a maximum working overhead of 1% with larger
164*4d5d8b54SAndroid Build Coastguard Workerpackets, and a typical working overhead of .5-.7% for most practical
165*4d5d8b54SAndroid Build Coastguard Workeruses.
166*4d5d8b54SAndroid Build Coastguard Worker
167*4d5d8b54SAndroid Build Coastguard Worker<h3>Simple pagination</h3>
168*4d5d8b54SAndroid Build Coastguard Worker
169*4d5d8b54SAndroid Build Coastguard Worker<p>Ogg is a byte-aligned container with no context-dependent, optional
170*4d5d8b54SAndroid Build Coastguard Workeror variable-length fields.  Ogg requires no repacking of codec data.
171*4d5d8b54SAndroid Build Coastguard WorkerThe page structure is written out in-line as packet data is submitted
172*4d5d8b54SAndroid Build Coastguard Workerto the streaming abstraction.  In addition, it is possible to
173*4d5d8b54SAndroid Build Coastguard Workerimplement both Ogg mux and demux as MT-hot zero-copy abstractions (as
174*4d5d8b54SAndroid Build Coastguard Workeris done in the Tremor sourcebase).
175*4d5d8b54SAndroid Build Coastguard Worker
176*4d5d8b54SAndroid Build Coastguard Worker<h3>Capture</h3>
177*4d5d8b54SAndroid Build Coastguard Worker
178*4d5d8b54SAndroid Build Coastguard Worker<p>Ogg is designed for efficient and immediate stream capture with
179*4d5d8b54SAndroid Build Coastguard Workerhigh confidence.  Although packets have no size limit in Ogg, pages
180*4d5d8b54SAndroid Build Coastguard Workerare a maximum of just under 64kB meaning that any Ogg stream can be
181*4d5d8b54SAndroid Build Coastguard Workercaptured with confidence after seeing 128kB of data or less [worst
182*4d5d8b54SAndroid Build Coastguard Workercase; typical figure is 6kB] from any random starting point in the
183*4d5d8b54SAndroid Build Coastguard Workerstream.
184*4d5d8b54SAndroid Build Coastguard Worker
185*4d5d8b54SAndroid Build Coastguard Worker<h3>Seeking</h3>
186*4d5d8b54SAndroid Build Coastguard Worker
187*4d5d8b54SAndroid Build Coastguard Worker<p>Ogg implements simple coarse- and fine-grained seeking by design.
188*4d5d8b54SAndroid Build Coastguard Worker
189*4d5d8b54SAndroid Build Coastguard Worker<p>Coarse seeking may be performed by simply 'moving the tone arm' to a
190*4d5d8b54SAndroid Build Coastguard Workernew position and 'dropping the needle'.  Rapid capture with
191*4d5d8b54SAndroid Build Coastguard Workeraccompanying timecode from any location in an Ogg file is guaranteed
192*4d5d8b54SAndroid Build Coastguard Workerby the stream design.  From the acquisition of the first timecode,
193*4d5d8b54SAndroid Build Coastguard Workerall data needed to play back from that time code forward is ahead of
194*4d5d8b54SAndroid Build Coastguard Workerthe stream cursor.
195*4d5d8b54SAndroid Build Coastguard Worker
196*4d5d8b54SAndroid Build Coastguard Worker<p>Ogg implements full sample-granularity seeking using an
197*4d5d8b54SAndroid Build Coastguard Workerinterpolated bisection search built on the capture and timecode
198*4d5d8b54SAndroid Build Coastguard Workermechanisms used by coarse seeking.  As above, once a search finds
199*4d5d8b54SAndroid Build Coastguard Workerthe desired timecode, all data needed to play back from that time code
200*4d5d8b54SAndroid Build Coastguard Workerforward is ahead of the stream cursor.
201*4d5d8b54SAndroid Build Coastguard Worker
202*4d5d8b54SAndroid Build Coastguard Worker<p>Both coarse and fine seeking use the page structure and sequencing
203*4d5d8b54SAndroid Build Coastguard Workerinherent to the Ogg format.  All Ogg streams are fully seekable from
204*4d5d8b54SAndroid Build Coastguard Workercreation; seekability is unaffected by truncation or missing data, and
205*4d5d8b54SAndroid Build Coastguard Workeris tolerant of gross corruption.  Seek operations are neither 'fuzzy' nor
206*4d5d8b54SAndroid Build Coastguard Workerheuristic.
207*4d5d8b54SAndroid Build Coastguard Worker
208*4d5d8b54SAndroid Build Coastguard Worker<p>Seeking without use of an index is a major point of the Ogg
209*4d5d8b54SAndroid Build Coastguard Workerdesign. There two primary reasons why Ogg transport forgoes an index:
210*4d5d8b54SAndroid Build Coastguard Worker
211*4d5d8b54SAndroid Build Coastguard Worker<ol>
212*4d5d8b54SAndroid Build Coastguard Worker
213*4d5d8b54SAndroid Build Coastguard Worker<li>An index is only marginally useful in Ogg for the complexity
214*4d5d8b54SAndroid Build Coastguard Workeradded; it adds no new functionality and seldom improves performance
215*4d5d8b54SAndroid Build Coastguard Workernoticeably.  Empirical testing shows that indexless interpolation
216*4d5d8b54SAndroid Build Coastguard Workersearch does not require many more seeks in practice than using an
217*4d5d8b54SAndroid Build Coastguard Workerindex would.
218*4d5d8b54SAndroid Build Coastguard Worker
219*4d5d8b54SAndroid Build Coastguard Worker<li>'Optional' indexes encourage lazy implementations that can seek
220*4d5d8b54SAndroid Build Coastguard Workeronly when indexes are present, or that implement indexless seeking
221*4d5d8b54SAndroid Build Coastguard Workeronly by building an internal index after reading the entire file
222*4d5d8b54SAndroid Build Coastguard Workerbeginning to end.  This has been the fate of other containers that
223*4d5d8b54SAndroid Build Coastguard Workerspecify optional indexing.
224*4d5d8b54SAndroid Build Coastguard Worker
225*4d5d8b54SAndroid Build Coastguard Worker</ol>
226*4d5d8b54SAndroid Build Coastguard Worker
227*4d5d8b54SAndroid Build Coastguard Worker<p>In addition, it must be possible to create an Ogg stream in a
228*4d5d8b54SAndroid Build Coastguard Workersingle pass. Although an optional index can simply be tacked on the
229*4d5d8b54SAndroid Build Coastguard Workerend of the created stream, some software groups object to
230*4d5d8b54SAndroid Build Coastguard Workerend-positioned indexes and claim to be unwilling to support indexes
231*4d5d8b54SAndroid Build Coastguard Workernot located at the stream beginning.
232*4d5d8b54SAndroid Build Coastguard Worker
233*4d5d8b54SAndroid Build Coastguard Worker<p><i>All this said, it's become clear that an optional index is a
234*4d5d8b54SAndroid Build Coastguard Workerdemanded feature.  For this reason, the <a
235*4d5d8b54SAndroid Build Coastguard Workerhref="http://wiki.xiph.org/Ogg_Index">OggSkeleton now defines a
236*4d5d8b54SAndroid Build Coastguard Workerproposed index.</a></i>
237*4d5d8b54SAndroid Build Coastguard Worker
238*4d5d8b54SAndroid Build Coastguard Worker<h3>Simple multiplexing</h3>
239*4d5d8b54SAndroid Build Coastguard Worker
240*4d5d8b54SAndroid Build Coastguard Worker<p>Ogg multiplexes streams by interleaving pages from multiple elementary streams into a
241*4d5d8b54SAndroid Build Coastguard Workermultiplexed stream in time order.  The multiplexed pages are not
242*4d5d8b54SAndroid Build Coastguard Workeraltered.  Muxing an Ogg AV stream out of separate audio,
243*4d5d8b54SAndroid Build Coastguard Workervideo and data streams is akin to shuffling several decks of cards
244*4d5d8b54SAndroid Build Coastguard Workertogether into a single deck; the cards themselves remain unchanged.
245*4d5d8b54SAndroid Build Coastguard WorkerDemultiplexing is similarly simple (as the cards are marked).
246*4d5d8b54SAndroid Build Coastguard Worker
247*4d5d8b54SAndroid Build Coastguard Worker<p>The goal of this design is to make the mux/demux operation as
248*4d5d8b54SAndroid Build Coastguard Workertrivial as possible to allow live streaming systems to build and
249*4d5d8b54SAndroid Build Coastguard Workerrebuild streams on the fly with minimal CPU usage and no additional
250*4d5d8b54SAndroid Build Coastguard Workerstorage or latency requirements.
251*4d5d8b54SAndroid Build Coastguard Worker
252*4d5d8b54SAndroid Build Coastguard Worker<h3>Continuous and Discontinuous Media</h3>
253*4d5d8b54SAndroid Build Coastguard Worker
254*4d5d8b54SAndroid Build Coastguard Worker<p>Ogg streams belong to one of two categories, "Continuous" streams and
255*4d5d8b54SAndroid Build Coastguard Worker"Discontinuous" streams.
256*4d5d8b54SAndroid Build Coastguard Worker
257*4d5d8b54SAndroid Build Coastguard Worker<p>A stream that provides a gapless, time-continuous media type with a
258*4d5d8b54SAndroid Build Coastguard Workerfine-grained timebase is considered to be 'Continuous'. A continuous
259*4d5d8b54SAndroid Build Coastguard Workerstream should never be starved of data. Examples of continuous data
260*4d5d8b54SAndroid Build Coastguard Workertypes include broadcast audio and video.
261*4d5d8b54SAndroid Build Coastguard Worker
262*4d5d8b54SAndroid Build Coastguard Worker<p>A stream that delivers data in a potentially irregular pattern or
263*4d5d8b54SAndroid Build Coastguard Workerwith widely spaced timing gaps is considered to be 'Discontinuous'. A
264*4d5d8b54SAndroid Build Coastguard Workerdiscontinuous stream may be best thought of as data representing
265*4d5d8b54SAndroid Build Coastguard Workerscattered events; although they happen in order, they are typically
266*4d5d8b54SAndroid Build Coastguard Workerunconnected data often located far apart. One example of a
267*4d5d8b54SAndroid Build Coastguard Workerdiscontinuous stream types would be captioning such as <a
268*4d5d8b54SAndroid Build Coastguard Workerhref="http://wiki.xiph.org/OggKate">Ogg Kate</a>. Although it's
269*4d5d8b54SAndroid Build Coastguard Workerpossible to design captions as a continuous stream type, it's most
270*4d5d8b54SAndroid Build Coastguard Workernatural to think of captions as widely spaced pieces of text with
271*4d5d8b54SAndroid Build Coastguard Workerlittle happening between.
272*4d5d8b54SAndroid Build Coastguard Worker
273*4d5d8b54SAndroid Build Coastguard Worker<p>The fundamental reason for distinction between continuous and
274*4d5d8b54SAndroid Build Coastguard Workerdiscontinuous streams concerns buffering.
275*4d5d8b54SAndroid Build Coastguard Worker
276*4d5d8b54SAndroid Build Coastguard Worker<h3>Buffering</h3>
277*4d5d8b54SAndroid Build Coastguard Worker
278*4d5d8b54SAndroid Build Coastguard Worker<p>A continuous stream is, by definition, gapless. Ogg buffering is based
279*4d5d8b54SAndroid Build Coastguard Workeron the simple premise of never allowing an active continuous stream
280*4d5d8b54SAndroid Build Coastguard Workerto starve for data during decode; buffering works ahead until all
281*4d5d8b54SAndroid Build Coastguard Workercontinuous streams in a physical stream have data ready and no further.
282*4d5d8b54SAndroid Build Coastguard Worker
283*4d5d8b54SAndroid Build Coastguard Worker<p>Discontinuous stream data is not assumed to be predictable. The
284*4d5d8b54SAndroid Build Coastguard Workerbuffering design takes discontinuous data 'as it comes' rather than
285*4d5d8b54SAndroid Build Coastguard Workerworking ahead to look for future discontinuous data for a potentially
286*4d5d8b54SAndroid Build Coastguard Workerunbounded period. Thus, the buffering process makes no attempt to fill
287*4d5d8b54SAndroid Build Coastguard Workerdiscontinuous stream buffers; their pages simply 'fall out' of the
288*4d5d8b54SAndroid Build Coastguard Workerstream when continuous streams are handled properly.
289*4d5d8b54SAndroid Build Coastguard Worker
290*4d5d8b54SAndroid Build Coastguard Worker<p>Buffering requirements in this design need not be explicitly
291*4d5d8b54SAndroid Build Coastguard Workerdeclared or managed in the encoded stream. The decoder simply reads as
292*4d5d8b54SAndroid Build Coastguard Workermuch data as is necessary to keep all continuous stream types gapless
293*4d5d8b54SAndroid Build Coastguard Workerand no more, with discontinuous data processed as it arrives in the
294*4d5d8b54SAndroid Build Coastguard Workercontinuous data. Buffering is implicitly optimal for the given
295*4d5d8b54SAndroid Build Coastguard Workerstream. Because all pages of all data types are stamped with absolute
296*4d5d8b54SAndroid Build Coastguard Workertiming information within the stream, inter-stream synchronization
297*4d5d8b54SAndroid Build Coastguard Workertiming is always maintained without the need for explicitly declared
298*4d5d8b54SAndroid Build Coastguard Workerbuffer-ahead hinting.
299*4d5d8b54SAndroid Build Coastguard Worker
300*4d5d8b54SAndroid Build Coastguard Worker<h3>Codec metadata</h3>
301*4d5d8b54SAndroid Build Coastguard Worker
302*4d5d8b54SAndroid Build Coastguard Worker<p>Ogg does not replicate codec-specific metadata into the mux layer
303*4d5d8b54SAndroid Build Coastguard Workerin an attempt to make the mux and codec layer implementations 'fully
304*4d5d8b54SAndroid Build Coastguard Workerseparable'.  Things like specific timebase, keyframing strategy, frame
305*4d5d8b54SAndroid Build Coastguard Workerduration, etc, do not appear in the Ogg container.  The mux layer is,
306*4d5d8b54SAndroid Build Coastguard Workerinstead, expected to query a codec through a centralized interface,
307*4d5d8b54SAndroid Build Coastguard Workerleft to the implementation, for this data when it is needed.
308*4d5d8b54SAndroid Build Coastguard Worker
309*4d5d8b54SAndroid Build Coastguard Worker<p>Though modern design wisdom usually prefers to predict all possible
310*4d5d8b54SAndroid Build Coastguard Workerneeds of current and future codecs then embed these dependencies and
311*4d5d8b54SAndroid Build Coastguard Workerthe required metadata into the container itself, this strategy
312*4d5d8b54SAndroid Build Coastguard Workerincreases container specification complexity, fragility, and rigidity.
313*4d5d8b54SAndroid Build Coastguard WorkerThe mux and codec code becomes more independent, but the
314*4d5d8b54SAndroid Build Coastguard Workerspecifications become logically less independent. A codec can't do
315*4d5d8b54SAndroid Build Coastguard Workerwhat a container hasn't already provided for.  Novel codecs are harder
316*4d5d8b54SAndroid Build Coastguard Workerto support, and you can do fewer useful things with the ones you've
317*4d5d8b54SAndroid Build Coastguard Workeralready got (eg, try to make a good splitter without using any codecs.
318*4d5d8b54SAndroid Build Coastguard WorkerSuch a splitter is limited to splitting at keyframes only, or building
319*4d5d8b54SAndroid Build Coastguard Workeryet another new mechanism into the container layer to mark what frames
320*4d5d8b54SAndroid Build Coastguard Workerto skip displaying).
321*4d5d8b54SAndroid Build Coastguard Worker
322*4d5d8b54SAndroid Build Coastguard Worker<p>Ogg's design goes the opposite direction, where the specification
323*4d5d8b54SAndroid Build Coastguard Workeris to be as simple, easy to understand, and 'proofed' against novel
324*4d5d8b54SAndroid Build Coastguard Workercodecs as possible.  When an Ogg mux layer requires codec-specific
325*4d5d8b54SAndroid Build Coastguard Workerinformation, it queries the codec (or a codec stub).  This trades a
326*4d5d8b54SAndroid Build Coastguard Workermore complex implementation for a simpler, more flexible
327*4d5d8b54SAndroid Build Coastguard Workerspecification.
328*4d5d8b54SAndroid Build Coastguard Worker
329*4d5d8b54SAndroid Build Coastguard Worker<h3>Stream structure metadata</h3>
330*4d5d8b54SAndroid Build Coastguard Worker
331*4d5d8b54SAndroid Build Coastguard Worker<p>The Ogg container itself does not define a metadata system for
332*4d5d8b54SAndroid Build Coastguard Workerdeclaring the structure and interrelations between multiple media
333*4d5d8b54SAndroid Build Coastguard Workertypes in a muxed stream.  That is, the Ogg container itself does not
334*4d5d8b54SAndroid Build Coastguard Workerspecify data like 'which steam is the subtitle stream?' or 'which
335*4d5d8b54SAndroid Build Coastguard Workervideo stream is the primary angle?'.  This metadata still exists, but
336*4d5d8b54SAndroid Build Coastguard Workeris stored by the Ogg container rather than being built into the Ogg
337*4d5d8b54SAndroid Build Coastguard Workercontainer itself.  Xiph specifies the 'Skeleton' metadata format for Ogg
338*4d5d8b54SAndroid Build Coastguard Workerstreams, but this decoupling of container and stream structure
339*4d5d8b54SAndroid Build Coastguard Workermetadata means it is possible to use Ogg with any metadata
340*4d5d8b54SAndroid Build Coastguard Workerspecification without altering the container itself, or without stream
341*4d5d8b54SAndroid Build Coastguard Workerstructure metadata at all.
342*4d5d8b54SAndroid Build Coastguard Worker
343*4d5d8b54SAndroid Build Coastguard Worker<h3>Frame accurate absolute position</h3>
344*4d5d8b54SAndroid Build Coastguard Worker
345*4d5d8b54SAndroid Build Coastguard Worker<p>Every Ogg page is stamped with a 64 bit 'granule position' that
346*4d5d8b54SAndroid Build Coastguard Workerserves as an absolute timestamp for mux and seeking.  A few nifty
347*4d5d8b54SAndroid Build Coastguard Workerlittle tricks are usually also embedded in the granpos state, but
348*4d5d8b54SAndroid Build Coastguard Workerwe'll leave those aside for the moment (strictly speaking, they're
349*4d5d8b54SAndroid Build Coastguard Workerpart of each codec's mapping, not Ogg).
350*4d5d8b54SAndroid Build Coastguard Worker
351*4d5d8b54SAndroid Build Coastguard Worker<p>As previously mentioned above, granule positions are mapped into
352*4d5d8b54SAndroid Build Coastguard Workerabsolute timestamps by the codec, rather than being a hard timestamp.
353*4d5d8b54SAndroid Build Coastguard WorkerThis allows maximally efficient use of the available 64 bits to
354*4d5d8b54SAndroid Build Coastguard Workeraddress every sample/frame position without approximation while
355*4d5d8b54SAndroid Build Coastguard Workersupporting new and previously unknown timebase encodings without
356*4d5d8b54SAndroid Build Coastguard Workerneeding to extend or update the mux layer.  When a codec needs a novel
357*4d5d8b54SAndroid Build Coastguard Workertimebase, it simply brings the code for that mapping along with it.
358*4d5d8b54SAndroid Build Coastguard WorkerThis is not a theoretical curiosity; new, wholly novel timebases were
359*4d5d8b54SAndroid Build Coastguard Workerdeployed with the adoption of both Theora and Dirac.  "Rolling INTRA"
360*4d5d8b54SAndroid Build Coastguard Worker(keyframeless video) also benefits from novel use of the granule
361*4d5d8b54SAndroid Build Coastguard Workerposition.
362*4d5d8b54SAndroid Build Coastguard Worker
363*4d5d8b54SAndroid Build Coastguard Worker<h2>Ogg stream arrangement</h2>
364*4d5d8b54SAndroid Build Coastguard Worker
365*4d5d8b54SAndroid Build Coastguard Worker<h3>Packets, pages, and bitstreams</h3>
366*4d5d8b54SAndroid Build Coastguard Worker
367*4d5d8b54SAndroid Build Coastguard Worker<p>Ogg codecs place raw compressed data into <em>packets</em>.
368*4d5d8b54SAndroid Build Coastguard WorkerPackets are octet payloads containing the data needed for a single
369*4d5d8b54SAndroid Build Coastguard Workerdecompressed unit, eg, one video frame. Packets have no maximum size
370*4d5d8b54SAndroid Build Coastguard Workerand may be zero length. They do not generally have any framing
371*4d5d8b54SAndroid Build Coastguard Workerinformation; strung together, the unframed packets form a <em>logical
372*4d5d8b54SAndroid Build Coastguard Workerbitstream</em> of codec data with no internal landmarks.
373*4d5d8b54SAndroid Build Coastguard Worker
374*4d5d8b54SAndroid Build Coastguard Worker<div class="caption">
375*4d5d8b54SAndroid Build Coastguard Worker  <img src="packets.png">
376*4d5d8b54SAndroid Build Coastguard Worker
377*4d5d8b54SAndroid Build Coastguard Worker  <p> Packets of raw codec data are not typically internally framed.
378*4d5d8b54SAndroid Build Coastguard Worker  When they are strung together into a stream without any container to
379*4d5d8b54SAndroid Build Coastguard Worker  provide framing, they lose their individual boundaries. Seek and
380*4d5d8b54SAndroid Build Coastguard Worker  capture are not possible within an unframed stream, and for many
381*4d5d8b54SAndroid Build Coastguard Worker  codecs with variable length payloads and/or early-packet termination
382*4d5d8b54SAndroid Build Coastguard Worker  (such as Vorbis), it may become impossible to recover the original
383*4d5d8b54SAndroid Build Coastguard Worker  frame boundaries even if the stream is scanned linearly from
384*4d5d8b54SAndroid Build Coastguard Worker  beginning to end.
385*4d5d8b54SAndroid Build Coastguard Worker
386*4d5d8b54SAndroid Build Coastguard Worker</div>
387*4d5d8b54SAndroid Build Coastguard Worker
388*4d5d8b54SAndroid Build Coastguard Worker<p>Logical bitstream packets are grouped and framed into Ogg pages
389*4d5d8b54SAndroid Build Coastguard Workeralong with a unique stream <em>serial number</em> to produce a
390*4d5d8b54SAndroid Build Coastguard Worker<em>physical bitstream</em>.  An <em>elementary stream</em> is a
391*4d5d8b54SAndroid Build Coastguard Workerphysical bitstream containing only a single logical bitstream. Each
392*4d5d8b54SAndroid Build Coastguard Workerpage is a self contained entity, although a packet may be split and
393*4d5d8b54SAndroid Build Coastguard Workerencoded across one or more pages. The page decode mechanism is
394*4d5d8b54SAndroid Build Coastguard Workerdesigned to recognize, verify and handle single pages at a time from
395*4d5d8b54SAndroid Build Coastguard Workerthe overall bitstream.
396*4d5d8b54SAndroid Build Coastguard Worker
397*4d5d8b54SAndroid Build Coastguard Worker<div class="caption">
398*4d5d8b54SAndroid Build Coastguard Worker  <img src="pages.png">
399*4d5d8b54SAndroid Build Coastguard Worker
400*4d5d8b54SAndroid Build Coastguard Worker  <p> The primary purpose of a container is to provide framing for raw
401*4d5d8b54SAndroid Build Coastguard Worker  packets, marking the packet boundaries so the exact packets can be
402*4d5d8b54SAndroid Build Coastguard Worker  retrieved for decode later.  The container also provides secondary
403*4d5d8b54SAndroid Build Coastguard Worker  functions such as capture, timestamping, sequencing, stream
404*4d5d8b54SAndroid Build Coastguard Worker  identification and so on.  Not all of these functions are represented in the diagram.
405*4d5d8b54SAndroid Build Coastguard Worker
406*4d5d8b54SAndroid Build Coastguard Worker  <p>In the Ogg container, pages do not necessarily contain
407*4d5d8b54SAndroid Build Coastguard Worker  integer numbers of packets. Packets may span across page boundaries
408*4d5d8b54SAndroid Build Coastguard Worker  or even multiple pages.  This is necessary as pages have a maximum
409*4d5d8b54SAndroid Build Coastguard Worker  possible size in order to provide capture guarantees, but packet
410*4d5d8b54SAndroid Build Coastguard Worker  size is unbounded.
411*4d5d8b54SAndroid Build Coastguard Worker</div>
412*4d5d8b54SAndroid Build Coastguard Worker
413*4d5d8b54SAndroid Build Coastguard Worker
414*4d5d8b54SAndroid Build Coastguard Worker<p><a href="framing.html">Ogg Bitstream Framing</a> specifies
415*4d5d8b54SAndroid Build Coastguard Workerthe page format of an Ogg bitstream, the packet coding process
416*4d5d8b54SAndroid Build Coastguard Workerand elementary bitstreams in detail.
417*4d5d8b54SAndroid Build Coastguard Worker
418*4d5d8b54SAndroid Build Coastguard Worker<h3>Multiplexed bitstreams</h3>
419*4d5d8b54SAndroid Build Coastguard Worker
420*4d5d8b54SAndroid Build Coastguard Worker<p>Multiple logical/elementary bitstreams can be combined into a single
421*4d5d8b54SAndroid Build Coastguard Worker<em>multiplexed bitstream</em> by interleaving whole pages from each
422*4d5d8b54SAndroid Build Coastguard Workercontributing elementary stream in time order. The result is a single
423*4d5d8b54SAndroid Build Coastguard Workerphysical stream that multiplexes and frames multiple logical streams.
424*4d5d8b54SAndroid Build Coastguard WorkerEach logical stream is identified by the unique stream serial number
425*4d5d8b54SAndroid Build Coastguard Workerstamped in its pages.  A physical stream may include a 'meta-header'
426*4d5d8b54SAndroid Build Coastguard Worker(such as the <a href="skeleton.html">Ogg Skeleton</a>) comprising its
427*4d5d8b54SAndroid Build Coastguard Workerown Ogg page at the beginning of the physical stream. A decoder
428*4d5d8b54SAndroid Build Coastguard Workerrecovers the original logical/elementary bitstreams out of the
429*4d5d8b54SAndroid Build Coastguard Workerphysical bitstream by taking the pages in order from the physical
430*4d5d8b54SAndroid Build Coastguard Workerbitstream and redirecting them into the appropriate logical decoding
431*4d5d8b54SAndroid Build Coastguard Workerentity.
432*4d5d8b54SAndroid Build Coastguard Worker
433*4d5d8b54SAndroid Build Coastguard Worker<div class="caption">
434*4d5d8b54SAndroid Build Coastguard Worker  <img src="multiplex1.png">
435*4d5d8b54SAndroid Build Coastguard Worker
436*4d5d8b54SAndroid Build Coastguard Worker<p>Multiple media types are mutliplexed into a single Ogg stream by
437*4d5d8b54SAndroid Build Coastguard Workerinterleaving the pages from each elementary physical stream.
438*4d5d8b54SAndroid Build Coastguard Worker
439*4d5d8b54SAndroid Build Coastguard Worker</div>
440*4d5d8b54SAndroid Build Coastguard Worker
441*4d5d8b54SAndroid Build Coastguard Worker<p><a href="ogg-multiplex.html">Ogg Bitstream Multiplexing</a> specifies
442*4d5d8b54SAndroid Build Coastguard Workerproper multiplexing of an Ogg bitstream in detail.
443*4d5d8b54SAndroid Build Coastguard Worker
444*4d5d8b54SAndroid Build Coastguard Worker<h3>Chaining</h3>
445*4d5d8b54SAndroid Build Coastguard Worker
446*4d5d8b54SAndroid Build Coastguard Worker<p>Multiple Ogg physical bitstreams may be concatenated into a single new
447*4d5d8b54SAndroid Build Coastguard Workerstream; this is <em>chaining</em>. The bitstreams do not overlap; the
448*4d5d8b54SAndroid Build Coastguard Workerfinal page of a given logical bitstream is immediately followed by the
449*4d5d8b54SAndroid Build Coastguard Workerinitial page of the next.</p>
450*4d5d8b54SAndroid Build Coastguard Worker
451*4d5d8b54SAndroid Build Coastguard Worker<p>Each logical bitstream in a chain must have a unique serial number
452*4d5d8b54SAndroid Build Coastguard Workerwithin the scope of the full physical bitstream, not only within a
453*4d5d8b54SAndroid Build Coastguard Workerparticular <em>link</em> or <em>segment</em> of the chain.</p>
454*4d5d8b54SAndroid Build Coastguard Worker
455*4d5d8b54SAndroid Build Coastguard Worker<h3>Continuous and discontinuous streams</h3>
456*4d5d8b54SAndroid Build Coastguard Worker
457*4d5d8b54SAndroid Build Coastguard Worker<p>Within Ogg, each stream must be declared (by the codec) to be
458*4d5d8b54SAndroid Build Coastguard Workercontinuous- or discontinuous-time.  Most codecs treat all streams they
459*4d5d8b54SAndroid Build Coastguard Workeruse as either inherently continuous- or discontinuous-time, although
460*4d5d8b54SAndroid Build Coastguard Workerthis is not a requirement. A codec may, as part of its mapping, choose
461*4d5d8b54SAndroid Build Coastguard Workeraccording to data in the initial header.
462*4d5d8b54SAndroid Build Coastguard Worker
463*4d5d8b54SAndroid Build Coastguard Worker<p>Continuous-time pages are stamped by end-time, discontinuous pages
464*4d5d8b54SAndroid Build Coastguard Workerare stamped by begin-time.  Pages in a multiplexed stream are
465*4d5d8b54SAndroid Build Coastguard Workerinterleaved in order of the time stamp regardless of stream type.
466*4d5d8b54SAndroid Build Coastguard WorkerBoth continuous and discontinuous logical streams are used to seek
467*4d5d8b54SAndroid Build Coastguard Workerwithin a physical stream, however only continuous streams are used to
468*4d5d8b54SAndroid Build Coastguard Workerdetermine buffering depth; because discontinuous streams are stamped
469*4d5d8b54SAndroid Build Coastguard Workerby start time, they will always 'fall out' at the proper time when
470*4d5d8b54SAndroid Build Coastguard Workerbuffering the continuous streams.  See 'Examples' for an illustration
471*4d5d8b54SAndroid Build Coastguard Workerof the buffering mechanism.
472*4d5d8b54SAndroid Build Coastguard Worker
473*4d5d8b54SAndroid Build Coastguard Worker<h2>Multiplexing Requirements</h2>
474*4d5d8b54SAndroid Build Coastguard Worker
475*4d5d8b54SAndroid Build Coastguard Worker<p>Multiplexing requirements within Ogg are straightforward. When
476*4d5d8b54SAndroid Build Coastguard Workerconstructing a single-link (unchained) physical bitstream consisting
477*4d5d8b54SAndroid Build Coastguard Workerof multiple elementary streams:
478*4d5d8b54SAndroid Build Coastguard Worker
479*4d5d8b54SAndroid Build Coastguard Worker<ol>
480*4d5d8b54SAndroid Build Coastguard Worker
481*4d5d8b54SAndroid Build Coastguard Worker<li><p> The initial header for each stream appears in sequence, each
482*4d5d8b54SAndroid Build Coastguard Workerheader on a single page.  All initial headers must appear with no
483*4d5d8b54SAndroid Build Coastguard Workerintervening data (no auxiliary header pages or packets, no data pages
484*4d5d8b54SAndroid Build Coastguard Workeror packets).  Order of the initial headers is unspecified. The
485*4d5d8b54SAndroid Build Coastguard Worker'beginning of stream' flag is set on each initial header.
486*4d5d8b54SAndroid Build Coastguard Worker
487*4d5d8b54SAndroid Build Coastguard Worker<li><p> All auxiliary headers for all streams must follow.  Order
488*4d5d8b54SAndroid Build Coastguard Workeris unspecified.  The final auxiliary header of each stream must flush
489*4d5d8b54SAndroid Build Coastguard Workerits page.
490*4d5d8b54SAndroid Build Coastguard Worker
491*4d5d8b54SAndroid Build Coastguard Worker<li><p>Data pages for each stream follow, interleaved in time order.
492*4d5d8b54SAndroid Build Coastguard Worker
493*4d5d8b54SAndroid Build Coastguard Worker<li><p>The final page of each stream sets the 'end of stream' flag.
494*4d5d8b54SAndroid Build Coastguard WorkerUnlike initial pages, terminal pages for the logical bitstreams need
495*4d5d8b54SAndroid Build Coastguard Workernot occur contiguously; indeed it may not be possible for them to do so.
496*4d5d8b54SAndroid Build Coastguard Worker</oL>
497*4d5d8b54SAndroid Build Coastguard Worker
498*4d5d8b54SAndroid Build Coastguard Worker<p><p>Each grouped bitstream must have a unique serial number within the
499*4d5d8b54SAndroid Build Coastguard Workerscope of the physical bitstream.</p>
500*4d5d8b54SAndroid Build Coastguard Worker
501*4d5d8b54SAndroid Build Coastguard Worker<h3>chaining and multiplexing</h3>
502*4d5d8b54SAndroid Build Coastguard Worker
503*4d5d8b54SAndroid Build Coastguard Worker<p>Multiplexed and/or unmultiplexed bitstreams may be chained
504*4d5d8b54SAndroid Build Coastguard Workerconsecutively. Such a physical bitstream obeys all the rules of both
505*4d5d8b54SAndroid Build Coastguard Workerchained and multiplexed streams.  Each link, when unchained, must
506*4d5d8b54SAndroid Build Coastguard Workerstand on its own as a valid physical bitstream.  Chained streams do
507*4d5d8b54SAndroid Build Coastguard Workernot mix or interleave; a new segment may not begin until all streams
508*4d5d8b54SAndroid Build Coastguard Workerin the preceding segment have terminated. </p>
509*4d5d8b54SAndroid Build Coastguard Worker
510*4d5d8b54SAndroid Build Coastguard Worker<h2>Codec Mapping Requirements</h2>
511*4d5d8b54SAndroid Build Coastguard Worker
512*4d5d8b54SAndroid Build Coastguard Worker<p>Each codec is allowed some freedom in deciding how its logical
513*4d5d8b54SAndroid Build Coastguard Workerbitstream is encapsulated into an Ogg bitstream (even if it is a
514*4d5d8b54SAndroid Build Coastguard Workertrivial mapping, eg, 'plop the packets in and go'). This is the
515*4d5d8b54SAndroid Build Coastguard Workercodec's <em>mapping</em>. Ogg imposes a few mapping requirements
516*4d5d8b54SAndroid Build Coastguard Workeron any codec.
517*4d5d8b54SAndroid Build Coastguard Worker
518*4d5d8b54SAndroid Build Coastguard Worker<ol>
519*4d5d8b54SAndroid Build Coastguard Worker
520*4d5d8b54SAndroid Build Coastguard Worker<li><p>The <a href="framing.html">framing specification</a> defines
521*4d5d8b54SAndroid Build Coastguard Worker'beginning of stream' and 'end of stream' page markers via a header
522*4d5d8b54SAndroid Build Coastguard Workerflag (it is possible for a stream to consist of a single page). A
523*4d5d8b54SAndroid Build Coastguard Workercorrect stream always consists of an integer number of pages, an easy
524*4d5d8b54SAndroid Build Coastguard Workerrequirement given the variable size nature of pages.</p>
525*4d5d8b54SAndroid Build Coastguard Worker
526*4d5d8b54SAndroid Build Coastguard Worker<li><p>The first page of an elementary Ogg bitstream consists of a single,
527*4d5d8b54SAndroid Build Coastguard Workersmall 'initial header' packet that must include sufficient information
528*4d5d8b54SAndroid Build Coastguard Workerto identify the exact CODEC type. From this initial header, the codec
529*4d5d8b54SAndroid Build Coastguard Workermust also be able to determine its timebase and whether or not it is a
530*4d5d8b54SAndroid Build Coastguard Workercontinuous- or discontinuous-time stream.  The initial header must fit
531*4d5d8b54SAndroid Build Coastguard Workeron a single page. If a codec makes use of auxiliary headers (for
532*4d5d8b54SAndroid Build Coastguard Workerexample, Vorbis uses two auxiliary headers), these headers must follow
533*4d5d8b54SAndroid Build Coastguard Workerthe initial header immediately.  The last header finishes its page;
534*4d5d8b54SAndroid Build Coastguard Workerdata begins on a fresh page.
535*4d5d8b54SAndroid Build Coastguard Worker
536*4d5d8b54SAndroid Build Coastguard Worker<p><p>As an example, Ogg Vorbis places the name and revision of the
537*4d5d8b54SAndroid Build Coastguard WorkerVorbis CODEC, the audio rate and the audio quality into this initial
538*4d5d8b54SAndroid Build Coastguard Workerheader.  Vorbis comments and detailed codec setup appears in the larger
539*4d5d8b54SAndroid Build Coastguard Workerauxiliary headers.</p>
540*4d5d8b54SAndroid Build Coastguard Worker
541*4d5d8b54SAndroid Build Coastguard Worker<li><p>Granule positions must be translatable to an exact absolute
542*4d5d8b54SAndroid Build Coastguard Workertime value.  As described above, the mux layer is permitted to query a
543*4d5d8b54SAndroid Build Coastguard Workercodec or codec stub plugin to perform this mapping. It is not
544*4d5d8b54SAndroid Build Coastguard Workernecessary for an absolute time to be mappable into a single unique
545*4d5d8b54SAndroid Build Coastguard Workergranule position value.
546*4d5d8b54SAndroid Build Coastguard Worker
547*4d5d8b54SAndroid Build Coastguard Worker<li><p>Codecs are not required to use a fixed duration-per-packet (for
548*4d5d8b54SAndroid Build Coastguard Workerexample, Vorbis does not).  the mux layer is permitted to query a
549*4d5d8b54SAndroid Build Coastguard Workercodec or codec stub plugin for the time duration of a packet.
550*4d5d8b54SAndroid Build Coastguard Worker
551*4d5d8b54SAndroid Build Coastguard Worker<li><p>Although an absolute time need not be translatable to a unique
552*4d5d8b54SAndroid Build Coastguard Workergranule position, a codec must be able to determine the unique granule
553*4d5d8b54SAndroid Build Coastguard Workerposition of the current packet using the granule position of a
554*4d5d8b54SAndroid Build Coastguard Workerpreceding packet.
555*4d5d8b54SAndroid Build Coastguard Worker
556*4d5d8b54SAndroid Build Coastguard Worker<li><p>Packets and pages must be arranged in ascending
557*4d5d8b54SAndroid Build Coastguard Workergranule-position and time order.
558*4d5d8b54SAndroid Build Coastguard Worker
559*4d5d8b54SAndroid Build Coastguard Worker</ol>
560*4d5d8b54SAndroid Build Coastguard Worker
561*4d5d8b54SAndroid Build Coastguard Worker<h2>Examples</h2>
562*4d5d8b54SAndroid Build Coastguard Worker
563*4d5d8b54SAndroid Build Coastguard Worker<em>[More to come shortly; this section is currently being revised and expanded]</em>
564*4d5d8b54SAndroid Build Coastguard Worker
565*4d5d8b54SAndroid Build Coastguard Worker<p>Below, we present an example of a multiplexed and chained bitstream:</p>
566*4d5d8b54SAndroid Build Coastguard Worker
567*4d5d8b54SAndroid Build Coastguard Worker<p><img src="stream.png" alt="stream"/></p>
568*4d5d8b54SAndroid Build Coastguard Worker
569*4d5d8b54SAndroid Build Coastguard Worker<p>In this example, we see pages from five total logical bitstreams
570*4d5d8b54SAndroid Build Coastguard Workermultiplexed into a physical bitstream. Note the following
571*4d5d8b54SAndroid Build Coastguard Workercharacteristics:</p>
572*4d5d8b54SAndroid Build Coastguard Worker
573*4d5d8b54SAndroid Build Coastguard Worker<ol>
574*4d5d8b54SAndroid Build Coastguard Worker<li>Multiplexed bitstreams in a given link begin together; all of the
575*4d5d8b54SAndroid Build Coastguard Workerinitial pages must appear before any data pages. When concurrently
576*4d5d8b54SAndroid Build Coastguard Workermultiplexed groups are chained, the new group does not begin until all
577*4d5d8b54SAndroid Build Coastguard Workerthe bitstreams in the previous group have terminated.</li>
578*4d5d8b54SAndroid Build Coastguard Worker
579*4d5d8b54SAndroid Build Coastguard Worker<li>The ordering of pages of concurrently multiplexed bitstreams is
580*4d5d8b54SAndroid Build Coastguard Workergoverened by timestamp (not shown here); there is no regular
581*4d5d8b54SAndroid Build Coastguard Workerinterleaving order.  Pages within a logical bitstream appear in
582*4d5d8b54SAndroid Build Coastguard Workersequence order.</li>
583*4d5d8b54SAndroid Build Coastguard Worker</ol>
584*4d5d8b54SAndroid Build Coastguard Worker
585*4d5d8b54SAndroid Build Coastguard Worker<div id="copyright">
586*4d5d8b54SAndroid Build Coastguard Worker  The Xiph Fish Logo is a
587*4d5d8b54SAndroid Build Coastguard Worker  trademark (&trade;) of Xiph.Org.<br/>
588*4d5d8b54SAndroid Build Coastguard Worker
589*4d5d8b54SAndroid Build Coastguard Worker  These pages &copy; 1994 - 2010 Xiph.Org. All rights reserved.
590*4d5d8b54SAndroid Build Coastguard Worker</div>
591*4d5d8b54SAndroid Build Coastguard Worker
592*4d5d8b54SAndroid Build Coastguard Worker</div>
593*4d5d8b54SAndroid Build Coastguard Worker</body>
594*4d5d8b54SAndroid Build Coastguard Worker</html>
595