cannam@86: cannam@86: cannam@86:
cannam@86: cannam@86: cannam@86:Ogg codecs use octet vectors of raw, compressed data cannam@86: (packets). These compressed packets do not have any cannam@86: high-level structure or boundary information; strung together, they cannam@86: appear to be streams of random bytes with no landmarks.
cannam@86: cannam@86:Raw packets may be used directly by transport mechanisms that provide cannam@86: their own framing and packet-separation mechanisms (such as UDP cannam@86: datagrams). For stream based storage (such as files) and transport cannam@86: (such as TCP streams or pipes), Vorbis and other future Ogg codecs use cannam@86: the Ogg bitstream format to provide framing/sync, sync recapture cannam@86: after error, landmarks during seeking, and enough information to cannam@86: properly separate data back into packets at the original packet cannam@86: boundaries without relying on decoding to find packet boundaries.
cannam@86: cannam@86:Raw packets are grouped and encoded into contiguous pages of cannam@86: structured bitstream data called logical bitstreams. A cannam@86: logical bitstream consists of pages, in order, belonging to a single cannam@86: codec instance. Each page is a self contained entity (although it is cannam@86: possible that a packet may be split and encoded across one or more cannam@86: pages); that is, the page decode mechanism is designed to recognize, cannam@86: verify and handle single pages at a time from the overall bitstream.
cannam@86: cannam@86:Multiple logical bitstreams can be combined (with restrictions) into a cannam@86: single physical bitstream. A physical bitstream consists of cannam@86: multiple logical bitstreams multiplexed at the page level and may cannam@86: include a 'meta-header' at the beginning of the multiplexed logical cannam@86: stream that serves as identification magic. Whole pages are taken in cannam@86: order from multiple logical bitstreams and combined into a single cannam@86: physical stream of pages. The decoder reconstructs the original cannam@86: logical bitstreams from the physical bitstream by taking the pages in cannam@86: order from the physical bitstream and redirecting them into the cannam@86: appropriate logical decoding entity. The simplest physical bitstream cannam@86: is a single, unmultiplexed logical bitstream with no meta-header; this cannam@86: is referred to as a 'degenerate stream'.
cannam@86: cannam@86:Ogg Logical Bitstream Framing discusses cannam@86: the page format of an Ogg bitstream, the packet coding process cannam@86: and logical bitstreams in detail. The remainder of this document cannam@86: specifies requirements for constructing finished, physical Ogg cannam@86: bitstreams.
cannam@86: cannam@86:Logical bitstreams may not be mapped/multiplexed into physical cannam@86: bitstreams without restriction. Here we discuss design restrictions cannam@86: on Ogg physical bitstreams in general, mostly to introduce cannam@86: design rationale. Each 'media' format defines its own (generally more cannam@86: restrictive) mapping. An 'Ogg Vorbis Audio Bitstream', for example, has a cannam@86: specific physical bitstream structure. cannam@86: An 'Ogg A/V' bitstream (not currently specified) will also mandate a cannam@86: specific, restricted physical bitstream format.
cannam@86: cannam@86:The framing specification defines cannam@86: 'beginning of stream' and 'end of stream' page markers via a header cannam@86: flag (it is possible for a stream to consist of a single page). A cannam@86: stream always consists of an integer number of pages, an easy cannam@86: requirement given the variable size nature of pages.
cannam@86: cannam@86:In addition to the header flag marking the first and last pages of a cannam@86: logical bitstream, the first page of an Ogg bitstream obeys cannam@86: additional restrictions. Each individual media mapping specifies its cannam@86: own implementation details regarding these restrictions.
cannam@86: cannam@86:The first page of a logical Ogg bitstream consists of a single, cannam@86: small 'initial header' packet that includes sufficient information to cannam@86: identify the exact CODEC type and media requirements of the logical cannam@86: bitstream. The intent of this restriction is to simplify identifying cannam@86: the bitstream type and content; for a given media type (or across all cannam@86: Ogg media types) we can know that we only need a small, fixed cannam@86: amount of data to uniquely identify the bitstream type.
cannam@86: cannam@86:As an example, Ogg Vorbis places the name and revision of the Vorbis cannam@86: CODEC, the audio rate and the audio quality into this initial header, cannam@86: thus simplifying vastly the certain identification of an Ogg Vorbis cannam@86: audio bitstream.
cannam@86: cannam@86:The simplest form of logical bitstream multiplexing is concatenation cannam@86: (chaining). Complete logical bitstreams are strung cannam@86: one-after-another in order. The bitstreams do not overlap; the final cannam@86: page of a given logical bitstream is immediately followed by the cannam@86: initial page of the next. Chaining is the only logical->physical cannam@86: mapping allowed by Ogg Vorbis.
cannam@86: cannam@86:Each chained logical bitstream must have a unique serial number within cannam@86: the scope of the physical bitstream.
cannam@86: cannam@86:Logical bitstreams may also be multiplexed 'in parallel' cannam@86: (grouped). An example of grouping would be to allow cannam@86: streaming of separate audio and video streams, using different codecs cannam@86: and different logical bitstreams, in the same physical bitstream. cannam@86: Whole pages from multiple logical bitstreams are mixed together.
cannam@86: cannam@86:The initial pages of each logical bitstream must appear first; the cannam@86: media mapping specifies the order of the initial pages. For example, cannam@86: Ogg A/V will eventually specify an Ogg video bitstream with cannam@86: audio. The mapping may specify that the physical bitstream must begin cannam@86: with the initial page of a logical video bitstream, followed by the cannam@86: initial page of an audio stream. Unlike initial pages, terminal pages cannam@86: for the logical bitstreams need not all occur contiguously (although a cannam@86: specific media mapping may require this; it is not mandated by the cannam@86: generic Ogg stream spec). Terminal pages may be 'nil' pages, cannam@86: that is, pages containing no content but simply a page header with cannam@86: position information and the 'last page of bitstream' flag set in the cannam@86: page header.
cannam@86: cannam@86:Each grouped bitstream must have a unique serial number within the cannam@86: scope of the physical bitstream.
cannam@86: cannam@86:Groups of concurrently multiplexed bitstreams may be chained cannam@86: consecutively. Such a physical bitstream obeys all the rules of both cannam@86: grouped and chained multiplexed streams; the groups, when unchained , cannam@86: must stand on their own as a valid concurrently multiplexed cannam@86: bitstream.
cannam@86: cannam@86:Below, we present an example of a grouped and chained bitstream:
cannam@86: cannam@86:In this example, we see pages from five total logical bitstreams cannam@86: multiplexed into a physical bitstream. Note the following cannam@86: characteristics:
cannam@86: cannam@86: