Blame doc/rfc3533.txt

Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Network Working Group                                        S. Pfeiffer
Packit 8debe6
Request for Comments: 3533                                         CSIRO
Packit 8debe6
Category: Informational                                         May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
                 The Ogg Encapsulation Format Version 0
Packit 8debe6
Packit 8debe6
Status of this Memo
Packit 8debe6
Packit 8debe6
   This memo provides information for the Internet community.  It does
Packit 8debe6
   not specify an Internet standard of any kind.  Distribution of this
Packit 8debe6
   memo is unlimited.
Packit 8debe6
Packit 8debe6
Copyright Notice
Packit 8debe6
Packit 8debe6
   Copyright (C) The Internet Society (2003).  All Rights Reserved.
Packit 8debe6
Packit 8debe6
Abstract
Packit 8debe6
Packit 8debe6
   This document describes the Ogg bitstream format version 0, which is
Packit 8debe6
   a general, freely-available encapsulation format for media streams.
Packit 8debe6
   It is able to encapsulate any kind and number of video and audio
Packit 8debe6
   encoding formats as well as other data streams in a single bitstream.
Packit 8debe6
Packit 8debe6
Terminology
Packit 8debe6
Packit 8debe6
   The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
Packit 8debe6
   "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
Packit 8debe6
   document are to be interpreted as described in BCP 14, RFC 2119 [2].
Packit 8debe6
Packit 8debe6
Table of Contents
Packit 8debe6
Packit 8debe6
   1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . .   2
Packit 8debe6
   2. Definitions  . . . . . . . . . . . . . . . . . . . . . . . . .   2
Packit 8debe6
   3. Requirements for a generic encapsulation format  . . . . . . .   3
Packit 8debe6
   4. The Ogg bitstream format . . . . . . . . . . . . . . . . . . .   3
Packit 8debe6
   5. The encapsulation process  . . . . . . . . . . . . . . . . . .   6
Packit 8debe6
   6. The Ogg page format  . . . . . . . . . . . . . . . . . . . . .   9
Packit 8debe6
   7. Security Considerations  . . . . . . . . . . . . . . . . . . .  11
Packit 8debe6
   8. References . . . . . . . . . . . . . . . . . . . . . . . . . .  12
Packit 8debe6
   A. Glossary of terms and abbreviations  . . . . . . . . . . . . .  13
Packit 8debe6
   B. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . .  14
Packit 8debe6
      Author's Address . . . . . . . . . . . . . . . . . . . . . . .  14
Packit 8debe6
      Full Copyright Statement . . . . . . . . . . . . . . . . . . .  15
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                      [Page 1]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
1. Introduction
Packit 8debe6
Packit 8debe6
   The Ogg bitstream format has been developed as a part of a larger
Packit 8debe6
   project aimed at creating a set of components for the coding and
Packit 8debe6
   decoding of multimedia content (codecs) which are to be freely
Packit 8debe6
   available and freely re-implementable, both in software and in
Packit 8debe6
   hardware for the computing community at large, including the Internet
Packit 8debe6
   community.  It is the intention of the Ogg developers represented by
Packit 8debe6
   Xiph.Org that it be usable without intellectual property concerns.
Packit 8debe6
Packit 8debe6
   This document describes the Ogg bitstream format and how to use it to
Packit 8debe6
   encapsulate one or several media bitstreams created by one or several
Packit 8debe6
   encoders.  The Ogg transport bitstream is designed to provide
Packit 8debe6
   framing, error protection and seeking structure for higher-level
Packit 8debe6
   codec streams that consist of raw, unencapsulated data packets, such
Packit 8debe6
   as the Vorbis audio codec or the upcoming Tarkin and Theora video
Packit 8debe6
   codecs.  It is capable of interleaving different binary media and
Packit 8debe6
   other time-continuous data streams that are prepared by an encoder as
Packit 8debe6
   a sequence of data packets.  Ogg provides enough information to
Packit 8debe6
   properly separate data back into such encoder created data packets at
Packit 8debe6
   the original packet boundaries without relying on decoding to find
Packit 8debe6
   packet boundaries.
Packit 8debe6
Packit 8debe6
   Please note that the MIME type application/ogg has been registered
Packit 8debe6
   with the IANA [1].
Packit 8debe6
Packit 8debe6
2. Definitions
Packit 8debe6
Packit 8debe6
   For describing the Ogg encapsulation process, a set of terms will be
Packit 8debe6
   used whose meaning needs to be well understood.  Therefore, some of
Packit 8debe6
   the most fundamental terms are defined now before we start with the
Packit 8debe6
   description of the requirements for a generic media stream
Packit 8debe6
   encapsulation format, the process of encapsulation, and the concrete
Packit 8debe6
   format of the Ogg bitstream.  See the Appendix for a more complete
Packit 8debe6
   glossary.
Packit 8debe6
Packit 8debe6
   The result of an Ogg encapsulation is called the "Physical (Ogg)
Packit 8debe6
   Bitstream".  It encapsulates one or several encoder-created
Packit 8debe6
   bitstreams, which are called "Logical Bitstreams".  A logical
Packit 8debe6
   bitstream, provided to the Ogg encapsulation process, has a
Packit 8debe6
   structure, i.e., it is split up into a sequence of so-called
Packit 8debe6
   "Packets".  The packets are created by the encoder of that logical
Packit 8debe6
   bitstream and represent meaningful entities for that encoder only
Packit 8debe6
   (e.g., an uncompressed stream may use video frames as packets).  They
Packit 8debe6
   do not contain boundary information - strung together they appear to
Packit 8debe6
   be streams of random bytes with no landmarks.
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                      [Page 2]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
   Please note that the term "packet" is not used in this document to
Packit 8debe6
   signify entities for transport over a network.
Packit 8debe6
Packit 8debe6
3. Requirements for a generic encapsulation format
Packit 8debe6
Packit 8debe6
   The design idea behind Ogg was to provide a generic, linear media
Packit 8debe6
   transport format to enable both file-based storage and stream-based
Packit 8debe6
   transmission of one or several interleaved media streams independent
Packit 8debe6
   of the encoding format of the media data.  Such an encapsulation
Packit 8debe6
   format needs to provide:
Packit 8debe6
Packit 8debe6
   o  framing for logical bitstreams.
Packit 8debe6
Packit 8debe6
   o  interleaving of different logical bitstreams.
Packit 8debe6
Packit 8debe6
   o  detection of corruption.
Packit 8debe6
Packit 8debe6
   o  recapture after a parsing error.
Packit 8debe6
Packit 8debe6
   o  position landmarks for direct random access of arbitrary positions
Packit 8debe6
      in the bitstream.
Packit 8debe6
Packit 8debe6
   o  streaming capability (i.e., no seeking is needed to build a 100%
Packit 8debe6
      complete bitstream).
Packit 8debe6
Packit 8debe6
   o  small overhead (i.e., use no more than approximately 1-2% of
Packit 8debe6
      bitstream bandwidth for packet boundary marking, high-level
Packit 8debe6
      framing, sync and seeking).
Packit 8debe6
Packit 8debe6
   o  simplicity to enable fast parsing.
Packit 8debe6
Packit 8debe6
   o  simple concatenation mechanism of several physical bitstreams.
Packit 8debe6
Packit 8debe6
   All of these design considerations have been taken into consideration
Packit 8debe6
   for Ogg.  Ogg supports framing and interleaving of logical
Packit 8debe6
   bitstreams, seeking landmarks, detection of corruption, and stream
Packit 8debe6
   resynchronisation after a parsing error with no more than
Packit 8debe6
   approximately 1-2% overhead.  It is a generic framework to perform
Packit 8debe6
   encapsulation of time-continuous bitstreams.  It does not know any
Packit 8debe6
   specifics about the codec data that it encapsulates and is thus
Packit 8debe6
   independent of any media codec.
Packit 8debe6
Packit 8debe6
4. The Ogg bitstream format
Packit 8debe6
Packit 8debe6
   A physical Ogg bitstream consists of multiple logical bitstreams
Packit 8debe6
   interleaved in so-called "Pages".  Whole pages are taken in order
Packit 8debe6
   from multiple logical bitstreams multiplexed at the page level.  The
Packit 8debe6
   logical bitstreams are identified by a unique serial number in the
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                      [Page 3]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
   header of each page of the physical bitstream.  This unique serial
Packit 8debe6
   number is created randomly and does not have any connection to the
Packit 8debe6
   content or encoder of the logical bitstream it represents.  Pages of
Packit 8debe6
   all logical bitstreams are concurrently interleaved, but they need
Packit 8debe6
   not be in a regular order - they are only required to be consecutive
Packit 8debe6
   within the logical bitstream.  Ogg demultiplexing reconstructs the
Packit 8debe6
   original logical bitstreams from the physical bitstream by taking the
Packit 8debe6
   pages in order from the physical bitstream and redirecting them into
Packit 8debe6
   the appropriate logical decoding entity.
Packit 8debe6
Packit 8debe6
   Each Ogg page contains only one type of data as it belongs to one
Packit 8debe6
   logical bitstream only.  Pages are of variable size and have a page
Packit 8debe6
   header containing encapsulation and error recovery information.  Each
Packit 8debe6
   logical bitstream in a physical Ogg bitstream starts with a special
Packit 8debe6
   start page (bos=beginning of stream) and ends with a special page
Packit 8debe6
   (eos=end of stream).
Packit 8debe6
Packit 8debe6
   The bos page contains information to uniquely identify the codec type
Packit 8debe6
   and MAY contain information to set up the decoding process.  The bos
Packit 8debe6
   page SHOULD also contain information about the encoded media - for
Packit 8debe6
   example, for audio, it should contain the sample rate and number of
Packit 8debe6
   channels.  By convention, the first bytes of the bos page contain
Packit 8debe6
   magic data that uniquely identifies the required codec.  It is the
Packit 8debe6
   responsibility of anyone fielding a new codec to make sure it is
Packit 8debe6
   possible to reliably distinguish his/her codec from all other codecs
Packit 8debe6
   in use.  There is no fixed way to detect the end of the codec-
Packit 8debe6
   identifying marker.  The format of the bos page is dependent on the
Packit 8debe6
   codec and therefore MUST be given in the encapsulation specification
Packit 8debe6
   of that logical bitstream type.  Ogg also allows but does not require
Packit 8debe6
   secondary header packets after the bos page for logical bitstreams
Packit 8debe6
   and these must also precede any data packets in any logical
Packit 8debe6
   bitstream.  These subsequent header packets are framed into an
Packit 8debe6
   integral number of pages, which will not contain any data packets.
Packit 8debe6
   So, a physical bitstream begins with the bos pages of all logical
Packit 8debe6
   bitstreams containing one initial header packet per page, followed by
Packit 8debe6
   the subsidiary header packets of all streams, followed by pages
Packit 8debe6
   containing data packets.
Packit 8debe6
Packit 8debe6
   The encapsulation specification for one or more logical bitstreams is
Packit 8debe6
   called a "media mapping".  An example for a media mapping is "Ogg
Packit 8debe6
   Vorbis", which uses the Ogg framework to encapsulate Vorbis-encoded
Packit 8debe6
   audio data for stream-based storage (such as files) and transport
Packit 8debe6
   (such as TCP streams or pipes).  Ogg Vorbis provides the name and
Packit 8debe6
   revision of the Vorbis codec, the audio rate and the audio quality on
Packit 8debe6
   the Ogg Vorbis bos page.  It also uses two additional header pages
Packit 8debe6
   per logical bitstream.  The Ogg Vorbis bos page starts with the byte
Packit 8debe6
   0x01, followed by "vorbis" (a total of 7 bytes of identifier).
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                      [Page 4]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
   Ogg knows two types of multiplexing: concurrent multiplexing (so-
Packit 8debe6
   called "Grouping") and sequential multiplexing (so-called
Packit 8debe6
   "Chaining").  Grouping defines how to interleave several logical
Packit 8debe6
   bitstreams page-wise in the same physical bitstream.  Grouping is for
Packit 8debe6
   example needed for interleaving a video stream with several
Packit 8debe6
   synchronised audio tracks using different codecs in different logical
Packit 8debe6
   bitstreams.  Chaining on the other hand, is defined to provide a
Packit 8debe6
   simple mechanism to concatenate physical Ogg bitstreams, as is often
Packit 8debe6
   needed for streaming applications.
Packit 8debe6
Packit 8debe6
   In grouping, all bos pages of all logical bitstreams MUST appear
Packit 8debe6
   together at the beginning of the Ogg bitstream.  The media mapping
Packit 8debe6
   specifies the order of the initial pages.  For example, the grouping
Packit 8debe6
   of a specific Ogg video and Ogg audio bitstream may specify that the
Packit 8debe6
   physical bitstream MUST begin with the bos page of the logical video
Packit 8debe6
   bitstream, followed by the bos page of the audio bitstream.  Unlike
Packit 8debe6
   bos pages, eos pages for the logical bitstreams need not all occur
Packit 8debe6
   contiguously.  Eos pages may be 'nil' pages, that is, pages
Packit 8debe6
   containing no content but simply a page header with position
Packit 8debe6
   information and the eos flag set in the page header.  Each grouped
Packit 8debe6
   logical bitstream MUST have a unique serial number within the scope
Packit 8debe6
   of the physical bitstream.
Packit 8debe6
Packit 8debe6
   In chaining, complete logical bitstreams are concatenated.  The
Packit 8debe6
   bitstreams do not overlap, i.e., the eos page of a given logical
Packit 8debe6
   bitstream is immediately followed by the bos page of the next.  Each
Packit 8debe6
   chained logical bitstream MUST have a unique serial number within the
Packit 8debe6
   scope of the physical bitstream.
Packit 8debe6
Packit 8debe6
   It is possible to consecutively chain groups of concurrently
Packit 8debe6
   multiplexed bitstreams.  The groups, when unchained, MUST stand on
Packit 8debe6
   their own as a valid concurrently multiplexed bitstream.  The
Packit 8debe6
   following diagram shows a schematic example of such a physical
Packit 8debe6
   bitstream that obeys all the rules of both grouped and chained
Packit 8debe6
   multiplexed bitstreams.
Packit 8debe6
Packit 8debe6
               physical bitstream with pages of
Packit 8debe6
          different logical bitstreams grouped and chained
Packit 8debe6
      -------------------------------------------------------------
Packit 8debe6
      |*A*|*B*|*C*|A|A|C|B|A|B|#A#|C|...|B|C|#B#|#C#|*D*|D|...|#D#|
Packit 8debe6
      -------------------------------------------------------------
Packit 8debe6
       bos bos bos             eos           eos eos bos       eos
Packit 8debe6
Packit 8debe6
   In this example, there are two chained physical bitstreams, the first
Packit 8debe6
   of which is a grouped stream of three logical bitstreams A, B, and C.
Packit 8debe6
   The second physical bitstream is chained after the end of the grouped
Packit 8debe6
   bitstream, which ends after the last eos page of all its grouped
Packit 8debe6
   logical bitstreams.  As can be seen, grouped bitstreams begin
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                      [Page 5]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
   together - all of the bos pages MUST appear before any data pages.
Packit 8debe6
   It can also be seen that pages of concurrently multiplexed bitstreams
Packit 8debe6
   need not conform to a regular order.  And it can be seen that a
Packit 8debe6
   grouped bitstream can end long before the other bitstreams in the
Packit 8debe6
   group end.
Packit 8debe6
Packit 8debe6
   Ogg does not know any specifics about the codec data except that each
Packit 8debe6
   logical bitstream belongs to a different codec, the data from the
Packit 8debe6
   codec comes in order and has position markers (so-called "Granule
Packit 8debe6
   positions").  Ogg does not have a concept of 'time': it only knows
Packit 8debe6
   about sequentially increasing, unitless position markers.  An
Packit 8debe6
   application can only get temporal information through higher layers
Packit 8debe6
   which have access to the codec APIs to assign and convert granule
Packit 8debe6
   positions or time.
Packit 8debe6
Packit 8debe6
   A specific definition of a media mapping using Ogg may put further
Packit 8debe6
   constraints on its specific use of the Ogg bitstream format.  For
Packit 8debe6
   example, a specific media mapping may require that all the eos pages
Packit 8debe6
   for all grouped bitstreams need to appear in direct sequence.  An
Packit 8debe6
   example for a media mapping is the specification of "Ogg Vorbis".
Packit 8debe6
   Another example is the upcoming "Ogg Theora" specification which
Packit 8debe6
   encapsulates Theora-encoded video data and usually comes multiplexed
Packit 8debe6
   with a Vorbis stream for an Ogg containing synchronised audio and
Packit 8debe6
   video.  As Ogg does not specify temporal relationships between the
Packit 8debe6
   encapsulated concurrently multiplexed bitstreams, the temporal
Packit 8debe6
   synchronisation between the audio and video stream will be specified
Packit 8debe6
   in this media mapping.  To enable streaming, pages from various
Packit 8debe6
   logical bitstreams will typically be interleaved in chronological
Packit 8debe6
   order.
Packit 8debe6
Packit 8debe6
5. The encapsulation process
Packit 8debe6
Packit 8debe6
   The process of multiplexing different logical bitstreams happens at
Packit 8debe6
   the level of pages as described above.  The bitstreams provided by
Packit 8debe6
   encoders are however handed over to Ogg as so-called "Packets" with
Packit 8debe6
   packet boundaries dependent on the encoding format.  The process of
Packit 8debe6
   encapsulating packets into pages will be described now.
Packit 8debe6
Packit 8debe6
   From Ogg's perspective, packets can be of any arbitrary size.  A
Packit 8debe6
   specific media mapping will define how to group or break up packets
Packit 8debe6
   from a specific media encoder.  As Ogg pages have a maximum size of
Packit 8debe6
   about 64 kBytes, sometimes a packet has to be distributed over
Packit 8debe6
   several pages.  To simplify that process, Ogg divides each packet
Packit 8debe6
   into 255 byte long chunks plus a final shorter chunk.  These chunks
Packit 8debe6
   are called "Ogg Segments".  They are only a logical construct and do
Packit 8debe6
   not have a header for themselves.
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                      [Page 6]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
   A group of contiguous segments is wrapped into a variable length page
Packit 8debe6
   preceded by a header.  A segment table in the page header tells about
Packit 8debe6
   the "Lacing values" (sizes) of the segments included in the page.  A
Packit 8debe6
   flag in the page header tells whether a page contains a packet
Packit 8debe6
   continued from a previous page.  Note that a lacing value of 255
Packit 8debe6
   implies that a second lacing value follows in the packet, and a value
Packit 8debe6
   of less than 255 marks the end of the packet after that many
Packit 8debe6
   additional bytes.  A packet of 255 bytes (or a multiple of 255 bytes)
Packit 8debe6
   is terminated by a lacing value of 0.  Note also that a 'nil' (zero
Packit 8debe6
   length) packet is not an error; it consists of nothing more than a
Packit 8debe6
   lacing value of zero in the header.
Packit 8debe6
Packit 8debe6
   The encoding is optimized for speed and the expected case of the
Packit 8debe6
   majority of packets being between 50 and 200 bytes large.  This is a
Packit 8debe6
   design justification rather than a recommendation.  This encoding
Packit 8debe6
   both avoids imposing a maximum packet size as well as imposing
Packit 8debe6
   minimum overhead on small packets.  In contrast, e.g., simply using
Packit 8debe6
   two bytes at the head of every packet and having a max packet size of
Packit 8debe6
   32 kBytes would always penalize small packets (< 255 bytes, the
Packit 8debe6
   typical case) with twice the segmentation overhead.  Using the lacing
Packit 8debe6
   values as suggested, small packets see the minimum possible byte-
Packit 8debe6
   aligned overhead (1 byte) and large packets (>512 bytes) see a fairly
Packit 8debe6
   constant ~0.5% overhead on encoding space.
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                      [Page 7]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
   The following diagram shows a schematic example of a media mapping
Packit 8debe6
   using Ogg and grouped logical bitstreams:
Packit 8debe6
Packit 8debe6
          logical bitstream with packet boundaries
Packit 8debe6
 -----------------------------------------------------------------
Packit 8debe6
 > |       packet_1             | packet_2         | packet_3 |  <
Packit 8debe6
 -----------------------------------------------------------------
Packit 8debe6
Packit 8debe6
                     |segmentation (logically only)
Packit 8debe6
                     v
Packit 8debe6
Packit 8debe6
      packet_1 (5 segments)          packet_2 (4 segs)    p_3 (2 segs)
Packit 8debe6
     ------------------------------ -------------------- ------------
Packit 8debe6
 ..  |seg_1|seg_2|seg_3|seg_4|s_5 | |seg_1|seg_2|seg_3|| |seg_1|s_2 | ..
Packit 8debe6
     ------------------------------ -------------------- ------------
Packit 8debe6
Packit 8debe6
                     | page encapsulation
Packit 8debe6
                     v
Packit 8debe6
Packit 8debe6
 page_1 (packet_1 data)   page_2 (pket_1 data)   page_3 (packet_2 data)
Packit 8debe6
------------------------  ----------------  ------------------------
Packit 8debe6
|H|------------------- |  |H|----------- |  |H|------------------- |
Packit 8debe6
|D||seg_1|seg_2|seg_3| |  |D|seg_4|s_5 | |  |D||seg_1|seg_2|seg_3| | ...
Packit 8debe6
|R|------------------- |  |R|----------- |  |R|------------------- |
Packit 8debe6
------------------------  ----------------  ------------------------
Packit 8debe6
Packit 8debe6
                    |
Packit 8debe6
pages of            |
Packit 8debe6
other    --------|  |
Packit 8debe6
logical         -------
Packit 8debe6
bitstreams      | MUX |
Packit 8debe6
                -------
Packit 8debe6
                   |
Packit 8debe6
                   v
Packit 8debe6
Packit 8debe6
              page_1  page_2          page_3
Packit 8debe6
      ------  ------  -------  -----  -------
Packit 8debe6
 ...  ||   |  ||   |  ||    |  ||  |  ||    |  ...
Packit 8debe6
      ------  ------  -------  -----  -------
Packit 8debe6
              physical Ogg bitstream
Packit 8debe6
Packit 8debe6
   In this example we take a snapshot of the encapsulation process of
Packit 8debe6
   one logical bitstream.  We can see part of that bitstream's
Packit 8debe6
   subdivision into packets as provided by the codec.  The Ogg
Packit 8debe6
   encapsulation process chops up the packets into segments.  The
Packit 8debe6
   packets in this example are rather large such that packet_1 is split
Packit 8debe6
   into 5 segments - 4 segments with 255 bytes and a final smaller one.
Packit 8debe6
   Packet_2 is split into 4 segments - 3 segments with 255 bytes and a
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                      [Page 8]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
   final very small one - and packet_3 is split into two segments.  The
Packit 8debe6
   encapsulation process then creates pages, which are quite small in
Packit 8debe6
   this example.  Page_1 consists of the first three segments of
Packit 8debe6
   packet_1, page_2 contains the remaining 2 segments from packet_1, and
Packit 8debe6
   page_3 contains the first three pages of packet_2.  Finally, this
Packit 8debe6
   logical bitstream is multiplexed into a physical Ogg bitstream with
Packit 8debe6
   pages of other logical bitstreams.
Packit 8debe6
Packit 8debe6
6. The Ogg page format
Packit 8debe6
Packit 8debe6
   A physical Ogg bitstream consists of a sequence of concatenated
Packit 8debe6
   pages.  Pages are of variable size, usually 4-8 kB, maximum 65307
Packit 8debe6
   bytes.  A page header contains all the information needed to
Packit 8debe6
   demultiplex the logical bitstreams out of the physical bitstream and
Packit 8debe6
   to perform basic error recovery and landmarks for seeking.  Each page
Packit 8debe6
   is a self-contained entity such that the page decode mechanism can
Packit 8debe6
   recognize, verify, and handle single pages at a time without
Packit 8debe6
   requiring the overall bitstream.
Packit 8debe6
Packit 8debe6
   The Ogg page header has the following format:
Packit 8debe6
Packit 8debe6
 0                   1                   2                   3
Packit 8debe6
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1| Byte
Packit 8debe6
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Packit 8debe6
| capture_pattern: Magic number for page start "OggS"           | 0-3
Packit 8debe6
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Packit 8debe6
| version       | header_type   | granule_position              | 4-7
Packit 8debe6
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Packit 8debe6
|                                                               | 8-11
Packit 8debe6
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Packit 8debe6
|                               | bitstream_serial_number       | 12-15
Packit 8debe6
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Packit 8debe6
|                               | page_sequence_number          | 16-19
Packit 8debe6
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Packit 8debe6
|                               | CRC_checksum                  | 20-23
Packit 8debe6
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Packit 8debe6
|                               |page_segments  | segment_table | 24-27
Packit 8debe6
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Packit 8debe6
| ...                                                           | 28-
Packit 8debe6
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Packit 8debe6
Packit 8debe6
   The LSb (least significant bit) comes first in the Bytes.  Fields
Packit 8debe6
   with more than one byte length are encoded LSB (least significant
Packit 8debe6
   byte) first.
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                      [Page 9]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
   The fields in the page header have the following meaning:
Packit 8debe6
Packit 8debe6
   1. capture_pattern: a 4 Byte field that signifies the beginning of a
Packit 8debe6
      page.  It contains the magic numbers:
Packit 8debe6
Packit 8debe6
            0x4f 'O'
Packit 8debe6
Packit 8debe6
            0x67 'g'
Packit 8debe6
Packit 8debe6
            0x67 'g'
Packit 8debe6
Packit 8debe6
            0x53 'S'
Packit 8debe6
Packit 8debe6
      It helps a decoder to find the page boundaries and regain
Packit 8debe6
      synchronisation after parsing a corrupted stream.  Once the
Packit 8debe6
      capture pattern is found, the decoder verifies page sync and
Packit 8debe6
      integrity by computing and comparing the checksum.
Packit 8debe6
Packit 8debe6
   2. stream_structure_version: 1 Byte signifying the version number of
Packit 8debe6
      the Ogg file format used in this stream (this document specifies
Packit 8debe6
      version 0).
Packit 8debe6
Packit 8debe6
   3. header_type_flag: the bits in this 1 Byte field identify the
Packit 8debe6
      specific type of this page.
Packit 8debe6
Packit 8debe6
      *  bit 0x01
Packit 8debe6
Packit 8debe6
         set: page contains data of a packet continued from the previous
Packit 8debe6
            page
Packit 8debe6
Packit 8debe6
         unset: page contains a fresh packet
Packit 8debe6
Packit 8debe6
      *  bit 0x02
Packit 8debe6
Packit 8debe6
         set: this is the first page of a logical bitstream (bos)
Packit 8debe6
Packit 8debe6
         unset: this page is not a first page
Packit 8debe6
Packit 8debe6
      *  bit 0x04
Packit 8debe6
Packit 8debe6
         set: this is the last page of a logical bitstream (eos)
Packit 8debe6
Packit 8debe6
         unset: this page is not a last page
Packit 8debe6
Packit 8debe6
   4. granule_position: an 8 Byte field containing position information.
Packit 8debe6
      For example, for an audio stream, it MAY contain the total number
Packit 8debe6
      of PCM samples encoded after including all frames finished on this
Packit 8debe6
      page.  For a video stream it MAY contain the total number of video
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                     [Page 10]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
      frames encoded after this page.  This is a hint for the decoder
Packit 8debe6
      and gives it some timing and position information.  Its meaning is
Packit 8debe6
      dependent on the codec for that logical bitstream and specified in
Packit 8debe6
      a specific media mapping.  A special value of -1 (in two's
Packit 8debe6
      complement) indicates that no packets finish on this page.
Packit 8debe6
Packit 8debe6
   5. bitstream_serial_number: a 4 Byte field containing the unique
Packit 8debe6
      serial number by which the logical bitstream is identified.
Packit 8debe6
Packit 8debe6
   6. page_sequence_number: a 4 Byte field containing the sequence
Packit 8debe6
      number of the page so the decoder can identify page loss.  This
Packit 8debe6
      sequence number is increasing on each logical bitstream
Packit 8debe6
      separately.
Packit 8debe6
Packit 8debe6
   7. CRC_checksum: a 4 Byte field containing a 32 bit CRC checksum of
Packit 8debe6
      the page (including header with zero CRC field and page content).
Packit 8debe6
      The generator polynomial is 0x04c11db7.
Packit 8debe6
Packit 8debe6
   8. number_page_segments: 1 Byte giving the number of segment entries
Packit 8debe6
      encoded in the segment table.
Packit 8debe6
Packit 8debe6
   9. segment_table: number_page_segments Bytes containing the lacing
Packit 8debe6
      values of all segments in this page.  Each Byte contains one
Packit 8debe6
      lacing value.
Packit 8debe6
Packit 8debe6
   The total header size in bytes is given by:
Packit 8debe6
   header_size = number_page_segments + 27 [Byte]
Packit 8debe6
Packit 8debe6
   The total page size in Bytes is given by:
Packit 8debe6
   page_size = header_size + sum(lacing_values: 1..number_page_segments)
Packit 8debe6
   [Byte]
Packit 8debe6
Packit 8debe6
7. Security Considerations
Packit 8debe6
Packit 8debe6
   The Ogg encapsulation format is a container format and only
Packit 8debe6
   encapsulates content (such as Vorbis-encoded audio).  It does not
Packit 8debe6
   provide for any generic encryption or signing of itself or its
Packit 8debe6
   contained content bitstreams.  However, it encapsulates any kind of
Packit 8debe6
   content bitstream as long as there is a codec for it, and is thus
Packit 8debe6
   able to contain encrypted and signed content data.  It is also
Packit 8debe6
   possible to add an external security mechanism that encrypts or signs
Packit 8debe6
   an Ogg physical bitstream and thus provides content confidentiality
Packit 8debe6
   and authenticity.
Packit 8debe6
Packit 8debe6
   As Ogg encapsulates binary data, it is possible to include executable
Packit 8debe6
   content in an Ogg bitstream.  This can be an issue with applications
Packit 8debe6
   that are implemented using the Ogg format, especially when Ogg is
Packit 8debe6
   used for streaming or file transfer in a networking scenario.  As
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                     [Page 11]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
   such, Ogg does not pose a threat there.  However, an application
Packit 8debe6
   decoding Ogg and its encapsulated content bitstreams has to ensure
Packit 8debe6
   correct handling of manipulated bitstreams, of buffer overflows and
Packit 8debe6
   the like.
Packit 8debe6
Packit 8debe6
8. References
Packit 8debe6
Packit 8debe6
   [1] Walleij, L., "The application/ogg Media Type", RFC 3534, May
Packit 8debe6
       2003.
Packit 8debe6
Packit 8debe6
   [2] Bradner, S., "Key words for use in RFCs to Indicate Requirement
Packit 8debe6
       Levels", BCP 14, RFC 2119, March 1997.
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                     [Page 12]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
Appendix A. Glossary of terms and abbreviations
Packit 8debe6
Packit 8debe6
   bos page: The initial page (beginning of stream) of a logical
Packit 8debe6
      bitstream which contains information to identify the codec type
Packit 8debe6
      and other decoding-relevant information.
Packit 8debe6
Packit 8debe6
   chaining (or sequential multiplexing): Concatenation of two or more
Packit 8debe6
      complete physical Ogg bitstreams.
Packit 8debe6
Packit 8debe6
   eos page: The final page (end of stream) of a logical bitstream.
Packit 8debe6
Packit 8debe6
   granule position: An increasing position number for a specific
Packit 8debe6
      logical bitstream stored in the page header.  Its meaning is
Packit 8debe6
      dependent on the codec for that logical bitstream and specified in
Packit 8debe6
      a specific media mapping.
Packit 8debe6
Packit 8debe6
   grouping (or concurrent multiplexing): Interleaving of pages of
Packit 8debe6
      several logical bitstreams into one complete physical Ogg
Packit 8debe6
      bitstream under the restriction that all bos pages of all grouped
Packit 8debe6
      logical bitstreams MUST appear before any data pages.
Packit 8debe6
Packit 8debe6
   lacing value: An entry in the segment table of a page header
Packit 8debe6
      representing the size of the related segment.
Packit 8debe6
Packit 8debe6
   logical bitstream: A sequence of bits being the result of an encoded
Packit 8debe6
      media stream.
Packit 8debe6
Packit 8debe6
   media mapping: A specific use of the Ogg encapsulation format
Packit 8debe6
      together with a specific (set of) codec(s).
Packit 8debe6
Packit 8debe6
   (Ogg) packet: A subpart of a logical bitstream that is created by the
Packit 8debe6
      encoder for that bitstream and represents a meaningful entity for
Packit 8debe6
      the encoder, but only a sequence of bits to the Ogg encapsulation.
Packit 8debe6
Packit 8debe6
   (Ogg) page: A physical bitstream consists of a sequence of Ogg pages
Packit 8debe6
      containing data of one logical bitstream only.  It usually
Packit 8debe6
      contains a group of contiguous segments of one packet only, but
Packit 8debe6
      sometimes packets are too large and need to be split over several
Packit 8debe6
      pages.
Packit 8debe6
Packit 8debe6
   physical (Ogg) bitstream: The sequence of bits resulting from an Ogg
Packit 8debe6
      encapsulation of one or several logical bitstreams.  It consists
Packit 8debe6
      of a sequence of pages from the logical bitstreams with the
Packit 8debe6
      restriction that the pages of one logical bitstream MUST come in
Packit 8debe6
      their correct temporal order.
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                     [Page 13]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
   (Ogg) segment: The Ogg encapsulation process splits each packet into
Packit 8debe6
      chunks of 255 bytes plus a last fractional chunk of less than 255
Packit 8debe6
      bytes.  These chunks are called segments.
Packit 8debe6
Packit 8debe6
Appendix B. Acknowledgements
Packit 8debe6
Packit 8debe6
   The author gratefully acknowledges the work that Christopher
Packit 8debe6
   Montgomery  and the Xiph.Org foundation have done in defining the Ogg
Packit 8debe6
   multimedia project and as part of it the open file format described
Packit 8debe6
   in this document.  The author hopes that providing this document to
Packit 8debe6
   the Internet community will help in promoting the Ogg multimedia
Packit 8debe6
   project at http://www.xiph.org/.  Many thanks also for the many
Packit 8debe6
   technical and typo corrections that C. Montgomery and the Ogg
Packit 8debe6
   community provided as feedback to this RFC.
Packit 8debe6
Packit 8debe6
Author's Address
Packit 8debe6
Packit 8debe6
   Silvia Pfeiffer
Packit 8debe6
   CSIRO, Australia
Packit 8debe6
   Locked Bag 17
Packit 8debe6
   North Ryde, NSW  2113
Packit 8debe6
   Australia
Packit 8debe6
Packit 8debe6
   Phone: +61 2 9325 3141
Packit 8debe6
   EMail: Silvia.Pfeiffer@csiro.au
Packit 8debe6
   URI:   http://www.cmis.csiro.au/Silvia.Pfeiffer/
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                     [Page 14]
Packit 8debe6

Packit 8debe6
RFC 3533                          OGG                           May 2003
Packit 8debe6
Packit 8debe6
Packit 8debe6
Full Copyright Statement
Packit 8debe6
Packit 8debe6
   Copyright (C) The Internet Society (2003).  All Rights Reserved.
Packit 8debe6
Packit 8debe6
   This document and translations of it may be copied and furnished to
Packit 8debe6
   others, and derivative works that comment on or otherwise explain it
Packit 8debe6
   or assist in its implementation may be prepared, copied, published
Packit 8debe6
   and distributed, in whole or in part, without restriction of any
Packit 8debe6
   kind, provided that the above copyright notice and this paragraph are
Packit 8debe6
   included on all such copies and derivative works.  However, this
Packit 8debe6
   document itself may not be modified in any way, such as by removing
Packit 8debe6
   the copyright notice or references to the Internet Society or other
Packit 8debe6
   Internet organizations, except as needed for the purpose of
Packit 8debe6
   developing Internet standards in which case the procedures for
Packit 8debe6
   copyrights defined in the Internet Standards process must be
Packit 8debe6
   followed, or as required to translate it into languages other than
Packit 8debe6
   English.
Packit 8debe6
Packit 8debe6
   The limited permissions granted above are perpetual and will not be
Packit 8debe6
   revoked by the Internet Society or its successors or assigns.
Packit 8debe6
Packit 8debe6
   This document and the information contained herein is provided on an
Packit 8debe6
   "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
Packit 8debe6
   TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
Packit 8debe6
   BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
Packit 8debe6
   HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
Packit 8debe6
   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
Packit 8debe6
Packit 8debe6
Acknowledgement
Packit 8debe6
Packit 8debe6
   Funding for the RFC Editor function is currently provided by the
Packit 8debe6
   Internet Society.
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Packit 8debe6
Pfeiffer                     Informational                     [Page 15]
Packit 8debe6