diff --git a/doc/fish_xiph_org.png b/doc/fish_xiph_org.png new file mode 100644 index 0000000..b398c06 Binary files /dev/null and b/doc/fish_xiph_org.png differ diff --git a/doc/framing.html b/doc/framing.html index 26293dc..191c1fb 100644 --- a/doc/framing.html +++ b/doc/framing.html @@ -1,23 +1,87 @@ -xiph.org: Ogg Vorbis documentation - -

+ + + -

-Ogg logical bitstream framing -

+ +Ogg Documentation -Last update to this document: July 14, 2002
+ + + + + + + + +

Ogg logical bitstream framing

Ogg bitstreams

-The Ogg transport bitstream is designed to provide framing, error +

The Ogg transport bitstream is designed to provide framing, error protection and seeking structure for higher-level codec streams that consist of raw, unencapsulated data packets, such as the Vorbis audio -codec or Tarkin video codec. +codec or Tarkin video codec.

Application example: Vorbis

-Vorbis encodes short-time blocks of PCM data into raw packets of + +

Vorbis encodes short-time blocks of PCM data into raw packets of bit-packed data. These raw packets may be used directly by transport mechanisms that provide their own framing and packet-separation mechanisms (such as UDP datagrams). For stream based storage (such as @@ -25,29 +89,24 @@ files) and transport (such as TCP streams or pipes), Vorbis uses the Ogg bitstream format to provide framing/sync, sync recapture after error, landmarks during seeking, and enough information to properly separate data back into packets at the original packet -boundaries without relying on decoding to find packet boundaries.

+boundaries without relying on decoding to find packet boundaries.

Design constraints for Ogg bitstreams

-
  1. True streaming; we must not need to seek to build a 100% - complete bitstream. - -
  2. Use no more than approximately 1-2% of bitstream bandwidth for - packet boundary marking, high-level framing, sync and seeking. - -
  3. Specification of absolute position within the original sample - stream. - -
  4. Simple mechanism to ease limited editing, such as a simplified - concatenation mechanism. - -
  5. Detection of corruption, recapture after error and direct, random - access to data at arbitrary positions in the bitstream. +
      +
    1. True streaming; we must not need to seek to build a 100% complete bitstream.
    2. +
    3. Use no more than approximately 1-2% of bitstream bandwidth for packet + boundary marking, high-level framing, sync and seeking.
    4. +
    5. Specification of absolute position within the original sample stream.
    6. +
    7. Simple mechanism to ease limited editing, such as a simplified concatenation + mechanism.
    8. +
    9. Detection of corruption, recapture after error and direct, random + access to data at arbitrary positions in the bitstream.

    Logical and Physical Bitstreams

    -A logical Ogg bitstream is a contiguous stream of +

    A logical Ogg bitstream is a contiguous stream of sequential pages belonging only to the logical bitstream. A physical Ogg bitstream is constructed from one or more than one logical Ogg bitstream (the simplest physical bitstream @@ -57,38 +116,38 @@ bitstreams into more complex physical bitstreams is described in the Ogg bitstream overview. The exact mapping of raw Vorbis packets into a valid Ogg Vorbis physical bitstream is described in Vorbis -bitstream mapping. +bitstream mapping.

    Bitstream structure

    -An Ogg stream is structured by dividing incoming packets into +

    An Ogg stream is structured by dividing incoming packets into segments of up to 255 bytes and then wrapping a group of contiguous packet segments into a variable length page preceded by a page header. Both the header size and page size are variable; the page header contains sizing information and checksum data to determine -header/page size and data integrity.

    +header/page size and data integrity.

    -The bitstream is captured (or recaptured) by looking for the beginning +

    The bitstream is captured (or recaptured) by looking for the beginning of a page, specifically the capture pattern. Once the capture pattern is found, the decoder verifies page sync and integrity by computing and comparing the checksum. At that point, the decoder can extract the -packets themselves.

    +packets themselves.

    Packet segmentation

    -Packets are logically divided into multiple segments before encoding +

    Packets are logically divided into multiple segments before encoding into a page. Note that the segmentation and fragmentation process is a logical one; it's used to compute page header values and the original page data need not be disturbed, even when a packet spans page -boundaries.

    +boundaries.

    -The raw packet is logically divided into [n] 255 byte segments and a -last fractional segment of < 255 bytes. A packet size may well +

    The raw packet is logically divided into [n] 255 byte segments and a +last fractional segment of < 255 bytes. A packet size may well consist only of the trailing fractional segment, and a fractional segment may be zero length. These values, called "lacing values" are -then saved and placed into the header segment table.

    +then saved and placed into the header segment table.

    -An example should make the basic concept clear:

    +

    An example should make the basic concept clear:

     
    @@ -100,21 +159,21 @@ lacing values for page header segment table: 255,255,243
     
     
    -We simply add the lacing values for the total size; the last lacing +

    We simply add the lacing values for the total size; the last lacing value for a packet is always the value that is less than 255. Note that this encoding both avoids imposing a maximum packet size as well as imposing minimum overhead on small packets (as opposed to, eg, simply using two bytes at the head of every packet and having a max -packet size of 32k. Small packets (<255, the typical case) are +packet size of 32k. Small packets (<255, the typical case) are penalized with twice the segmentation overhead). Using the lacing values as suggested, small packets see the minimum possible byte-aligned overheade (1 byte) and large packets, over 512 bytes or -so, see a fairly constant ~.5% overhead on encoding space.

    +so, see a fairly constant ~.5% overhead on encoding space.

    -Note that a lacing value of 255 implies that a second lacing value -follows in the packet, and a value of < 255 marks the end of the +

    Note that a lacing value of 255 implies that a second lacing value +follows in the packet, and a value of < 255 marks the end of the packet after that many additional bytes. A packet of 255 bytes (or a -multiple of 255 bytes) is terminated by a lacing value of 0:

    +multiple of 255 bytes) is terminated by a lacing value of 0:

    
     raw packet:
    @@ -124,20 +183,20 @@ raw packet:
     lacing values: 255, 0
     
    -Note also that a 'nil' (zero length) packet is not an error; it -consists of nothing more than a lacing value of zero in the header.

    +

    Note also that a 'nil' (zero length) packet is not an error; it +consists of nothing more than a lacing value of zero in the header.

    Packets spanning pages

    -Packets are not restricted to beginning and ending within a page, +

    Packets are not restricted to beginning and ending within a page, although individual segments are, by definition, required to do so. Packets are not restricted to a maximum size, although excessively large packets in the data stream are discouraged; the Ogg bitstream specification strongly recommends nominal page size of approximately 4-8kB (large packets are foreseen as being useful for -initialization data at the beginning of a logical bitstream).

    +initialization data at the beginning of a logical bitstream).

    -After segmenting a packet, the encoder may decide not to place all the +

    After segmenting a packet, the encoder may decide not to place all the resulting segments into the current page; to do so, the encoder places the lacing values of the segments it wishes to belong to the current page into the current segment table, then finishes the page. The next @@ -147,9 +206,9 @@ packet body must also correspond properly to the lacing values in the spanned pages. The segment data in the first packet corresponding to the lacing values of the first page belong in that page; packet segments listed in the segment table of the following page must begin -the page body of the subsequent page).

    +the page body of the subsequent page).

    -The last mechanic to spanning a page boundary is to set the header +

    The last mechanic to spanning a page boundary is to set the header flag in the new page to indicate that the first lacing value in the segment table continues rather than begins a packet; a header flag of 0x01 is set to indicate a continued packet. Although mandatory, it @@ -160,45 +219,45 @@ simpler design (with no overhead) that needs only inspect the current page header after frame capture. This also allows faster error recovery in the event that the packet originates in a corrupt preceding page, implying that the previous page's segment table -cannot be trusted.

    +cannot be trusted.

    -Note that a packet can span an arbitrary number of pages; the above +

    Note that a packet can span an arbitrary number of pages; the above spanning process is repeated for each spanned page boundary. Also a 'zero termination' on a packet size that is an even multiple of 255 must appear even if the lacing value appears in the next page as a zero-length continuation of the current packet. The header flag should be set to 0x01 to indicate that the packet spanned, even though -the span is a nil case as far as data is concerned.

    +the span is a nil case as far as data is concerned.

    -The encoding looks odd, but is properly optimized for speed and the +

    The encoding looks odd, but is properly optimized for speed and the expected case of the majority of packets being between 50 and 200 bytes (note that it is designed such that packets of wildly different sizes can be handled within the model; placing packet size restrictions on the encoder would have only slightly simplified design -in page generation and increased overall encoder complexity).

    +in page generation and increased overall encoder complexity).

    -The main point behind tracking individual packets (and packet +

    The main point behind tracking individual packets (and packet segments) is to allow more flexible encoding tricks that requiring explicit knowledge of packet size. An example is simple bandwidth limiting, implemented by simply truncating packets in the nominal case if the packet is arranged so that the least sensitive portion of the -data comes last.

    +data comes last.

    Page header

    -The headering mechanism is designed to avoid copying and re-assembly +

    The headering mechanism is designed to avoid copying and re-assembly of the packet data (ie, making the packet segmentation process a logical one); the header can be generated directly from incoming packet data. The encoder buffers packet data until it finishes a complete page at which point it writes the header followed by the -buffered packet segments.

    +buffered packet segments.

    capture_pattern

    - A header begins with a capture pattern that simplifies identifying - pages; once the decoder has found the capture pattern it can do a more - intensive job of verifying that it has in fact found a page boundary - (as opposed to an inadvertent coincidence in the byte stream).

    +

    A header begins with a capture pattern that simplifies identifying +pages; once the decoder has found the capture pattern it can do a more +intensive job of verifying that it has in fact found a page boundary +(as opposed to an inadvertent coincidence in the byte stream).

    
      byte value
    @@ -211,7 +270,7 @@ buffered packet segments.

    stream_structure_version

    - The capture pattern is followed by the stream structure revision: +

    The capture pattern is followed by the stream structure revision:

    
      byte value
    @@ -221,7 +280,7 @@ buffered packet segments.

    header_type_flag

    - The header type flag identifies this page's context in the bitstream: +

    The header type flag identifies this page's context in the bitstream:

    
      byte value
    @@ -236,21 +295,21 @@ buffered packet segments.

    absolute granule position

    - (This is packed in the same way the rest of Ogg data is packed; LSb - of LSB first. Note that the 'position' data specifies a 'sample' - number (eg, in a CD quality sample is four octets, 16 bits for left - and 16 bits for right; in video it would likely be the frame number. - It is up to the specific codec in use to define the semantic meaning - of the granule position value). The position specified is the total - samples encoded after including all packets finished on this page - (packets begun on this page but continuing on to the next page do not - count). The rationale here is that the position specified in the - frame header of the last page tells how long the data coded by the - bitstream is. A truncated stream will still return the proper number - of samples that can be decoded fully. -

    - A special value of '-1' (in two's complement) indicates that no packets - finish on this page. +

    (This is packed in the same way the rest of Ogg data is packed; LSb +of LSB first. Note that the 'position' data specifies a 'sample' +number (eg, in a CD quality sample is four octets, 16 bits for left +and 16 bits for right; in video it would likely be the frame number. +It is up to the specific codec in use to define the semantic meaning +of the granule position value). The position specified is the total +samples encoded after including all packets finished on this page +(packets begun on this page but continuing on to the next page do not +count). The rationale here is that the position specified in the +frame header of the last page tells how long the data coded by the +bitstream is. A truncated stream will still return the proper number +of samples that can be decoded fully.

    + +

    A special value of '-1' (in two's complement) indicates that no packets +finish on this page.

    
      byte value
    @@ -267,13 +326,13 @@ buffered packet segments.

    stream serial number

    - Ogg allows for separate logical bitstreams to be mixed at page - granularity in a physical bitstream. The most common case would be - sequential arrangement, but it is possible to interleave pages for - two separate bitstreams to be decoded concurrently. The serial - number is the means by which pages physical pages are associated with - a particular logical stream. Each logical stream must have a unique - serial number within a physical stream: +

    Ogg allows for separate logical bitstreams to be mixed at page +granularity in a physical bitstream. The most common case would be +sequential arrangement, but it is possible to interleave pages for +two separate bitstreams to be decoded concurrently. The serial +number is the means by which pages physical pages are associated with +a particular logical stream. Each logical stream must have a unique +serial number within a physical stream:

    
      byte value
    @@ -286,8 +345,8 @@ buffered packet segments.

    page sequence no

    - Page counter; lets us know if a page is lost (useful where packets - span page boundaries). +

    Page counter; lets us know if a page is lost (useful where packets +span page boundaries).

    
      byte value
    @@ -300,17 +359,17 @@ buffered packet segments.

    page checksum

    - 32 bit CRC value (direct algorithm, initial val and final XOR = 0, - generator polynomial=0x04c11db7). The value is computed over the - entire header (with the CRC field in the header set to zero) and then - continued over the page. The CRC field is then filled with the - computed value.

    +

    32 bit CRC value (direct algorithm, initial val and final XOR = 0, +generator polynomial=0x04c11db7). The value is computed over the +entire header (with the CRC field in the header set to zero) and then +continued over the page. The CRC field is then filled with the +computed value.

    - (A thorough discussion of CRC algorithms can be found in "A - Painless Guide to CRC Error Detection Algorithms" by Ross - Williams ross@guest.adelaide.edu.au.) +

    (A thorough discussion of CRC algorithms can be found in "A +Painless Guide to CRC Error Detection Algorithms" by Ross +Williams ross@guest.adelaide.edu.au.)

    
      byte value
    @@ -323,14 +382,14 @@ buffered packet segments.

    page_segments

    - The number of segment entries to appear in the segment table. The - maximum number of 255 segments (255 bytes each) sets the maximum - possible physical page size at 65307 bytes or just under 64kB (thus - we know that a header corrupted so as destroy sizing/alignment - information will not cause a runaway bitstream. We'll read in the - page according to the corrupted size information that's guaranteed to - be a reasonable size regardless, notice the checksum mismatch, drop - sync and then look for recapture).

    +

    The number of segment entries to appear in the segment table. The +maximum number of 255 segments (255 bytes each) sets the maximum +possible physical page size at 65307 bytes or just under 64kB (thus +we know that a header corrupted so as destroy sizing/alignment +information will not cause a runaway bitstream. We'll read in the +page according to the corrupted size information that's guaranteed to +be a reasonable size regardless, notice the checksum mismatch, drop +sync and then look for recapture).

    
      byte value
    @@ -340,8 +399,8 @@ buffered packet segments.

    segment_table (containing packet lacing values)

    - The lacing values for each packet segment physically appearing in - this page are listed in contiguous order. +

    The lacing values for each packet segment physically appearing in +this page are listed in contiguous order.

    
      byte value
    @@ -351,45 +410,22 @@ buffered packet segments.

    n 0x00-0xff (0-255, n=page_segments+26)

    -Total page size is calculated directly from the known header size and +

    Total page size is calculated directly from the known header size and lacing values in the segment table. Packet data segments follow -immediately after the header.

    +immediately after the header.

    -Page headers typically impose a flat .25-.5% space overhead assuming +

    Page headers typically impose a flat .25-.5% space overhead assuming nominal ~8k page sizes. The segmentation table needed for exact packet recovery in the streaming layer adds approximately .5-1% nominal assuming expected encoder behavior in the 44.1kHz, 128kbps -stereo encodings.

    +stereo encodings.

    -
    - - - - + - - + diff --git a/doc/index.html b/doc/index.html index b7ad768..78050a0 100644 --- a/doc/index.html +++ b/doc/index.html @@ -1,4 +1,92 @@ -Ogg logical and physical bitstream overview
    -Ogg logical bitstream framing
    -Ogg multi-stream multiplexing
    + + + + +Ogg Documentation + + + + + + + + + + + + + + + + + diff --git a/doc/ogg-multiplex.html b/doc/ogg-multiplex.html index 046c0cd..1f5dd41 100644 --- a/doc/ogg-multiplex.html +++ b/doc/ogg-multiplex.html @@ -1,162 +1,225 @@ -xiph.org: Ogg documentation - -

    + + + -

    -Page Multiplexing and Ordering in a Physical Ogg Stream -

    + +Ogg Documentation -Last update to this document: May 17, 2004
    -

    + + + + + + +

    + +

    Page Multiplexing and Ordering in a Physical Ogg Stream

    + +

    The low-level mechanisms of an Ogg stream (as described in the Ogg Bitstream Overview) provide means for mixing multiple logical streams -and media types into a single linear-chronological stream. This +and media types into a single linear-chronological stream. This document specifies the high-level arrangement and use of page structure to multiplex multiple streams of mixed media type within a -physical Ogg stream. +physical Ogg stream.

    Design Elements

    -The design and arrangement of the Ogg container format is governed by +

    The design and arrangement of the Ogg container format is governed by several high-level design decisions that form the reasoning behind -specific low-level design decisions. +specific low-level design decisions.

    Linear media

    -The Ogg bitstream is intended to encapsulate chronological, -time-linear mixed media into a single delivery stream or file. The +

    The Ogg bitstream is intended to encapsulate chronological, +time-linear mixed media into a single delivery stream or file. The design is such that an application can always encode and/or decode a full-featured bitstream in one pass with no seeking and minimal -buffering. Seeking to provide optimized encoding (such as two-pass +buffering. Seeking to provide optimized encoding (such as two-pass encoding) or interactive decoding (such as scrubbing or instant replay) is not disallowed or discouraged, however no bitstream feature -must require nonlinear operation on the bitstream.

    +must require nonlinear operation on the bitstream.

    Multiplexing

    -Ogg bitstreams multiplex multiple logical streams into a single -physical stream at the page level. Each page contains an abstract +

    Ogg bitstreams multiplex multiple logical streams into a single +physical stream at the page level. Each page contains an abstract time stamp (the Granule Position) that represents an absolute time -landmark within the stream. After the pages representing stream +landmark within the stream. After the pages representing stream headers (all logical stream headers occur at the beginning of a physical bitstream section before any logical stream data), logical stream data pages are arranged in strict, monotonically increasing order of chronological absolute time as specified by the granule -position.

    +position.

    -The only exception to arranging pages in strictly ascending time order +

    The only exception to arranging pages in strictly ascending time order by granule position is those pages that do not set the granule -position value. This is a special case when exceptionally large +position value. This is a special case when exceptionally large packets span multiple pages; the specifics of handling this special case are described later under 'Continuous and Discontinuous -Streams'.

    +Streams'.

    Seeking

    -Ogg is designed to use a bisection search to implement exact +

    Ogg is designed to use a bisection search to implement exact positional seeking rather than building an index; an index requires two-pass encoding and as such is not acceptable given the requirement -for full-featured linear encoding.

    +for full-featured linear encoding.

    -Even making an index optional then requires an +

    Even making an index optional then requires an application to support multiple methods (bisection search for a one-pass stream, indexing for a two-pass stream), which adds no additional functionality as bisection search delivers the same -functionality for both stream types.

    +functionality for both stream types.

    -Seek operations are by absolute time; a direct bisection search must -find the exact time position requested. Information in the Ogg +

    Seek operations are by absolute time; a direct bisection search must +find the exact time position requested. Information in the Ogg bitstream is arranged such that all information to be presented for playback from the desired seek point will occur at or after the -desired seek point. Seek operations are neither 'fuzzy' nor -heuristic.

    +desired seek point. Seek operations are neither 'fuzzy' nor +heuristic.

    -Although key frame handling in video appears to be an exception to +

    Although key frame handling in video appears to be an exception to "all needed playback information lies ahead of a given seek", key frames can still be handled directly within this indexless framework. Seeking to a key frame in video (as well as seeking in other media types with analogous restraints) is handled as two seeks; first a seek to the desired time which extracts state information that decodes to the time of the last key frame, followed by a second seek -directly to the key frame. The location of the previous key frame is +directly to the key frame. The location of the previous key frame is embedded as state information in the granulepos; this mechanism is -described in more detail later. +described in more detail later.

    Continuous and Discontinuous Streams

    -Logical streams within a physical Ogg stream belong to one of two +

    Logical streams within a physical Ogg stream belong to one of two categories, "Continuous" streams and "Discontinuous" streams. Although these are discussed in more detail later, the distinction is important to a high-level understanding of how to buffer an Ogg -stream.

    +stream.

    -A stream that provides a gapless, time-continuous media type with a -fine-grained timebase is considered to be 'Continuous'. A continuous -stream should never be starved of data. Clear examples of continuous -data types include broadcast audio and video.

    +

    A stream that provides a gapless, time-continuous media type with a +fine-grained timebase is considered to be 'Continuous'. A continuous +stream should never be starved of data. Clear examples of continuous +data types include broadcast audio and video.

    -A stream that delivers data in a potentially irregular pattern or with -widely spaced timing gaps is considered to be 'Discontinuous'. A +

    A stream that delivers data in a potentially irregular pattern or with +widely spaced timing gaps is considered to be 'Discontinuous'. A discontinuous stream may be best thought of as data representing scattered events; although they happen in order, they are typically unconnected data often located far apart. One possible example of a -discontinuous stream types would be captioning. Although it's +discontinuous stream types would be captioning. Although it's possible to design captions as a continuous stream type, it's most natural to think of captions as widely spaced pieces of text with -little happening between.

    +little happening between.

    -The fundamental design distinction between continuous and -discontinuous streams concerns buffering.

    +

    The fundamental design distinction between continuous and +discontinuous streams concerns buffering.

    Buffering

    -Because a continuous stream is, by definition, gapless, Ogg buffering +

    Because a continuous stream is, by definition, gapless, Ogg buffering is based on the simple premise of never allowing any active continuous stream to starve for data during decode; buffering proceeds ahead until all continuous streams in a physical stream have data ready to -decode on demand.

    +decode on demand.

    -Discontinuous stream data may occur on a fairly regular basis, but the +

    Discontinuous stream data may occur on a fairly regular basis, but the timing of, for example, a specific caption is impossible to predict with certainty in most captioning systems. Thus the buffering system should take discontinuous data 'as it comes' rather than working ahead (for a potentially unbounded period) to look for future discontinuous -data. As such, discontinuous streams are ignored when managing +data. As such, discontinuous streams are ignored when managing buffering; their pages simply 'fall out' of the stream when continuous -streams are handled properly.

    +streams are handled properly.

    -Buffering requirements need not be explicitly declared or managed for +

    Buffering requirements need not be explicitly declared or managed for the encoded stream; the decoder simply reads as much data as is necessary to keep all continuous stream types gapless (also ensuring discontinuous data arrives in time) and no more, resulting in optimum -implicit buffer usage for a given stream. Because all pages of all +implicit buffer usage for a given stream. Because all pages of all data types are stamped with absolute timing information within the stream, inter-stream synchronization timing is always explicitly maintained without the need for explicitly declared buffer-ahead -hinting.

    +hinting.

    -Further details, mechanisms and reasons for the differing arrangement +

    Further details, mechanisms and reasons for the differing arrangement and behavior of continuous and discontinuous streams is discussed -later.

    +later.

    Whole-stream navigation

    -Ogg is designed so that the simplest navigation operations treat the +

    Ogg is designed so that the simplest navigation operations treat the physical Ogg stream as a whole summary of its streams, rather than -navigating each interleaved stream as a separate entity.

    +navigating each interleaved stream as a separate entity.

    -First Example: seeking to a desired time position in a multiplexed (or +

    First Example: seeking to a desired time position in a multiplexed (or unmultiplexed) Ogg stream can be accomplished through a bisection search on time position of all pages in the stream (as encoded in the granule position). More powerful searches (such as a key frame-aware seek within video) are also possible with additional search -complexity, but similar computational complexity.

    +complexity, but similar computational complexity.

    -Second Example: A bitstream section may consist of three multiplexed -streams of differing lengths. The result of multiplexing these +

    Second Example: A bitstream section may consist of three multiplexed +streams of differing lengths. The result of multiplexing these streams should be thought of as a single mixed stream with a length -equal to the longest of the three component streams. Although it is +equal to the longest of the three component streams. Although it is also possible to think of the multiplexed results as three concurrent streams of different lengths and it is possible to recover the three original streams, it will also become obvious that once multiplexed, @@ -164,21 +227,22 @@ it isn't possible to find the internal lengths of the component streams without a linear search of the whole bitstream section. However, it is possible to find the length of the whole bitstream section easily (in near-constant time per section) just as it is for a -single-media unmultiplexed stream.

    +single-media unmultiplexed stream.

    Granule Position

    Description

    -The Granule Position is a signed 64 bit field appearing in the header -of every Ogg page. Although the granule position represents absolute +

    The Granule Position is a signed 64 bit field appearing in the header +of every Ogg page. Although the granule position represents absolute time within a logical stream, its value does not necessarily directly -encode a simple timestamp. It may represent frames elapsed (as in +encode a simple timestamp. It may represent frames elapsed (as in Vorbis), a simple timestamp, or a more complex bit-division encoding -(such as in Theora). The exact encoding of the granule position is up -to a specific codec.

    +(such as in Theora). The exact encoding of the granule position is up +to a specific codec.

    + +

    The granule position is governed by the following rules:

    -The granule position is governed by the following rules:
    • Granule Position must always increase forward or remain equal from @@ -187,183 +251,195 @@ time to which any correct sequence of granule position maps must similarly always increase forward or remain equal. (A codec may make use of data, such as a control sequence, that only affects codec working state without producing data and thus advancing granule -position and time. Although the packet sequence number increases in +position and time. Although the packet sequence number increases in this case, the granule position, and thus the time position, do -not.)
      +not.)
    • Granule position may only be unset if there no packet defining a time boundary on the page (that is, if no packet in a continuous stream ends on the page, or no packet in a discontinuous stream begins -on the page. This will be discussed in more detail under Continuous -and Discontinuous streams).
      +on the page. This will be discussed in more detail under Continuous +and Discontinuous streams).
    • A codec must be able to translate a given granule position value to a unique, deterministic absolute time value through direct -calculation. A codec is not required to be able to translate an -absolute time value into a unique granule position value.
      +calculation. A codec is not required to be able to translate an +absolute time value into a unique granule position value.
    • Codecs shall choose a granule position definition that allows that codec means to seek as directly as possible to an immediately decodable point, such as the bit-divided granule position encoding of Theora allows the codec to seek efficiently to key frame without using -an index. That is, additional information other than absolute time +an index. That is, additional information other than absolute time may be encoded into a granule position value so long as the granule -position obeys the above points. +position obeys the above points.
    • +

    Example: timestamp

    -In general, a codec/stream type should choose the simplest granule -position encoding that addresses its requirements. The examples here -are by no means exhaustive of the possibilities within Ogg.

    +

    In general, a codec/stream type should choose the simplest granule +position encoding that addresses its requirements. The examples here +are by no means exhaustive of the possibilities within Ogg.

    -A simple granule position could encode a timestamp directly. For +

    A simple granule position could encode a timestamp directly. For example, a granule position that encoded milliseconds from beginning of stream would allow a logical stream length of over 100,000,000,000 days before beginning a new logical stream (to avoid the granule -position wrapping).

    +position wrapping).

    Example: framestamp

    -A simple millisecond timestamp granule encoding might suit many stream +

    A simple millisecond timestamp granule encoding might suit many stream types, but a millisecond resolution is inappropriate to, eg, most audio encodings where exact single-sample resolution is generally a -requirement. A millisecond is both too large a granule and often does -not represent an integer number of samples.

    +requirement. A millisecond is both too large a granule and often does +not represent an integer number of samples.

    -In the event that audio frames are always encoded as the same number of +

    In the event that audio frames are always encoded as the same number of samples, the granule position could simply be a linear count of frames since beginning of stream. This has the advantages of being exact and -efficient. Position in time would simply be [granule_position] * -[samples_per_frame] / [samples_per_second]. +efficient. Position in time would simply be [granule_position] * +[samples_per_frame] / [samples_per_second].

    Example: samplestamp (Vorbis)

    -Frame counting is insufficient in codecs such as Vorbis where an audio -frame [packet] encodes a variable number of samples. In Vorbis's +

    Frame counting is insufficient in codecs such as Vorbis where an audio +frame [packet] encodes a variable number of samples. In Vorbis's case, the granule position is a count of the number of raw samples from the beginning of stream; the absolute time of a granule position is [granule_position] / -[samples_per_second]. +[samples_per_second].

    Example: bit-divided framestamp (Theora)

    -Some video codecs may be able to use the simple framestamp scheme for -granule position. However, most modern video codecs introduce at -least the following complications:

    +

    Some video codecs may be able to use the simple framestamp scheme for +granule position. However, most modern video codecs introduce at +least the following complications:

    +
    • video frames are relatively far apart compared to audio samples; for this reason, the point at which a video frame changes to the next frame is usually a strictly defined offset within the frame 'period'. That is, video at 50fps could just as easily define frame transitions -<.015, .035, .055...> as at <.00, .02, .04...>. +<.015, .035, .055...> as at <.00, .02, .04...>.
    • frame rates often include drop-frames, leap-frames or other -rational-but-non-integer timings. +rational-but-non-integer timings.
    • + +
    • Decode must begin at a 'key frame' or 'I frame'. Keyframes usually +occur relatively seldom.
    • -
    • Decode must begin at a 'key frame' or 'I frame'. Keyframes usually -occur relatively seldom.
    -The first two points can be handled straightforwardly via the fact +

    The first two points can be handled straightforwardly via the fact that the codec has complete control mapping granule position to absolute time; non-integer frame rates and offsets can be set in the -codec's initial header, and the rest is just arithmetic.

    +codec's initial header, and the rest is just arithmetic.

    -The third point appears trickier at first glance, but it too can be -handled through the granule position mapping mechanism. Here we +

    The third point appears trickier at first glance, but it too can be +handled through the granule position mapping mechanism. Here we arrange the granule position in such a way that granule positions of -key frames are easy to find. Divide the granule position into two +key frames are easy to find. Divide the granule position into two fields; the most-significant bits are an absolute frame counter, but -it's only updated at each key frame. The least significant bits encode -the number of frames since the last key frame. In this way, each +it's only updated at each key frame. The least significant bits encode +the number of frames since the last key frame. In this way, each granule position both encodes the absolute time of the current frame -as well as the absolute time of the last key frame.

    +as well as the absolute time of the last key frame.

    -Seeking to a most recent preceding key frame is then accomplished by +

    Seeking to a most recent preceding key frame is then accomplished by first seeking to the original desired point, inspecting the granulepos of the resulting video page, extracting from that granulepos the absolute time of the desired key frame, and then seeking directly to -that key frame's page. Of course, it's still possible for an +that key frame's page. Of course, it's still possible for an application to ignore key frames and use a simpler seeking algorithm (decode would be unable to present decoded video until the next -key frame). Surprisingly many player applications do choose the -simpler approach.

    +key frame). Surprisingly many player applications do choose the +simpler approach.

    granule position, packets and pages

    -Although each packet of data in a logical stream theoretically has a +

    Although each packet of data in a logical stream theoretically has a specific granule position, only one granule position is encoded -per page. It is possible to encode a logical stream such that each +per page. It is possible to encode a logical stream such that each page contains only a single packet (so that granule positions are preserved for each packet), however a one-to-one packet/page mapping -is not intended to be the general case.

    +is not intended to be the general case.

    -Because Ogg functions at the page, not packet, level, this +

    Because Ogg functions at the page, not packet, level, this once-per-page time information provides Ogg with the finest-grained -time information is can use. Ogg passes this granule positioning data +time information is can use. Ogg passes this granule positioning data to the codec (along with the packets extracted from a page); it is the responsibility of codecs to track timing information at granularities -finer than a single page.

    +finer than a single page.

    start-time and end-time positioning

    -A granule position represents the instantaneous time location -between two pages. However, continuous streams and discontinuous +

    A granule position represents the instantaneous time location +between two pages. However, continuous streams and discontinuous streams differ on whether the granulepos represents the end-time of -the data on a page or the start-time. Continuous streams are +the data on a page or the start-time. Continuous streams are 'end-time' encoded; the granulepos represents the point in time -immediately after the last data decoded from a page. Discontinuous +immediately after the last data decoded from a page. Discontinuous streams are 'start-time' encoded; the granulepos represents the point -in time of the first data decoded from the page.

    +in time of the first data decoded from the page.

    -An Ogg stream type is declared continuous or discontinuous by its -codec. A given codec may support both continuous and discontinuous +

    An Ogg stream type is declared continuous or discontinuous by its +codec. A given codec may support both continuous and discontinuous operation so long as any given logical stream is continuous or discontinuous for its entirety and the codec is able to ascertain (and inform the Ogg layer) as to which after decoding the initial stream -header. The majority of codecs will always be continuous (such as -Vorbis) or discontinuous (such as Writ).

    +header. The majority of codecs will always be continuous (such as +Vorbis) or discontinuous (such as Writ).

    -Start- and end-time encoding do not affect multiplexing sort-order; +

    Start- and end-time encoding do not affect multiplexing sort-order; pages are still sorted by the absolute time a given granulepos maps to regardless of whether that granulepos represents start- or -end-time.

    +end-time.

    Multiplex/Demultiplex Division of Labor

    -The Ogg multiplex/demultiplex layer provides mechanisms for encoding +

    The Ogg multiplex/demultiplex layer provides mechanisms for encoding raw packets into Ogg pages, decoding Ogg pages back into the original codec packets, determining the logical structure of an Ogg stream, and navigating through and synchronizing with an Ogg stream at a desired -stream location. Strict multiplex/demultiplex operations are entirely -in the Ogg domain and require no intervention from codecs.

    +stream location. Strict multiplex/demultiplex operations are entirely +in the Ogg domain and require no intervention from codecs.

    -Implementation of more complex operations does require codec -knowledge, however. Unlike other framing systems, Ogg maintains +

    Implementation of more complex operations does require codec +knowledge, however. Unlike other framing systems, Ogg maintains strict separation between framing and the framed bitstream data; Ogg does not replicate codec-specific information in the page/framing data, nor does Ogg blur the line between framing and stream -data/metadata. Because Ogg is fully data-agnostic toward the data it +data/metadata. Because Ogg is fully data-agnostic toward the data it frames, operations which require specifics of bitstream data (such as 'seek to key frame') also require interaction with the codec layer (because, in this example, the Ogg layer is not aware of the concept -of key frames). This is different from systems that blur the +of key frames). This is different from systems that blur the separation between framing and stream data in order to simplify the -separation of code. The Ogg system purposely keeps the distinction in +separation of code. The Ogg system purposely keeps the distinction in data simple so that later codec innovations are not constrained by -framing design.

    +framing design.

    -For this reason, however, complex seeking operations require +

    For this reason, however, complex seeking operations require interaction with the codecs in order to decode the granule position of a given stream type back to absolute time or in order to find -'decodable points' such as key frames in video. +'decodable points' such as key frames in video.

    Unsorted Discussion Points

    -flushes around key frames? RFC suggestion: repaginating or building a -stream this way is nice but not required - +

    flushes around key frames? RFC suggestion: repaginating or building a +stream this way is nice but not required

    Appendix A: multiplexing examples

    + + + + + diff --git a/doc/oggstream.html b/doc/oggstream.html index 4df3346..d9b80db 100644 --- a/doc/oggstream.html +++ b/doc/oggstream.html @@ -1,43 +1,105 @@ -xiph.org: Ogg Vorbis documentation - -

    + + + + +Ogg Documentation -

    -Ogg logical and physical bitstream overview -

    + + + + + + + + +

    Ogg logical and physical bitstream overview

    Ogg bitstreams

    -Ogg codecs use octet vectors of raw, compressed data +

    Ogg codecs use octet vectors of raw, compressed data (packets). These compressed packets do not have any high-level structure or boundary information; strung together, they -appear to be streams of random bytes with no landmarks.

    +appear to be streams of random bytes with no landmarks.

    -Raw packets may be used directly by transport mechanisms that provide +

    Raw packets may be used directly by transport mechanisms that provide their own framing and packet-separation mechanisms (such as UDP -datagrams). For stream based storage (such as files) and transport +datagrams). For stream based storage (such as files) and transport (such as TCP streams or pipes), Vorbis and other future Ogg codecs use the Ogg bitstream format to provide framing/sync, sync recapture after error, landmarks during seeking, and enough information to properly separate data back into packets at the original packet -boundaries without relying on decoding to find packet boundaries.

    +boundaries without relying on decoding to find packet boundaries.

    Logical and physical bitstreams

    -Raw packets are grouped and encoded into contiguous pages of -structured bitstream data called logical bitstreams. A +

    Raw packets are grouped and encoded into contiguous pages of +structured bitstream data called logical bitstreams. A logical bitstream consists of pages, in order, belonging to a single -codec instance. Each page is a self contained entity (although it is +codec instance. Each page is a self contained entity (although it is possible that a packet may be split and encoded across one or more pages); that is, the page decode mechanism is designed to recognize, -verify and handle single pages at a time from the overall bitstream.

    +verify and handle single pages at a time from the overall bitstream.

    -Multiple logical bitstreams can be combined (with restrictions) into a -single physical bitstream. A physical bitstream consists of +

    Multiple logical bitstreams can be combined (with restrictions) into a +single physical bitstream. A physical bitstream consists of multiple logical bitstreams multiplexed at the page level and may include a 'meta-header' at the beginning of the multiplexed logical stream that serves as identification magic. Whole pages are taken in @@ -47,150 +109,126 @@ logical bitstreams from the physical bitstream by taking the pages in order from the physical bitstream and redirecting them into the appropriate logical decoding entity. The simplest physical bitstream is a single, unmultiplexed logical bitstream with no meta-header; this -is referred to as a 'degenerate stream'.

    +is referred to as a 'degenerate stream'.

    -Ogg Logical Bitstream Framing discusses +

    Ogg Logical Bitstream Framing discusses the page format of an Ogg bitstream, the packet coding process -and logical bitstreams in detail. The remainder of this document +and logical bitstreams in detail. The remainder of this document specifies requirements for constructing finished, physical Ogg -bitstreams.

    +bitstreams.

    Mapping Restrictions

    -Logical bitstreams may not be mapped/multiplexed into physical -bitstreams without restriction. Here we discuss design restrictions +

    Logical bitstreams may not be mapped/multiplexed into physical +bitstreams without restriction. Here we discuss design restrictions on Ogg physical bitstreams in general, mostly to introduce design rationale. Each 'media' format defines its own (generally more -restrictive) mapping. An 'Ogg Vorbis -Audio Bitstream', for example, has a specific physical bitstream structure. +restrictive) mapping. An 'Ogg Vorbis Audio Bitstream', for example, has a +specific physical bitstream structure. An 'Ogg A/V' bitstream (not currently specified) will also mandate a -specific, restricted physical bitstream format.

    +specific, restricted physical bitstream format.

    additional end-to-end structure

    -The framing specification defines +

    The framing specification defines 'beginning of stream' and 'end of stream' page markers via a header -flag (it is possible for a stream to consist of a single page). A +flag (it is possible for a stream to consist of a single page). A stream always consists of an integer number of pages, an easy -requirement given the variable size nature of pages.

    +requirement given the variable size nature of pages.

    -In addition to the header flag marking the first and last pages of a +

    In addition to the header flag marking the first and last pages of a logical bitstream, the first page of an Ogg bitstream obeys -additional restrictions. Each individual media mapping specifies its -own implementation details regarding these restrictions.

    +additional restrictions. Each individual media mapping specifies its +own implementation details regarding these restrictions.

    -The first page of a logical Ogg bitstream consists of a single, +

    The first page of a logical Ogg bitstream consists of a single, small 'initial header' packet that includes sufficient information to identify the exact CODEC type and media requirements of the logical -bitstream. The intent of this restriction is to simplify identifying +bitstream. The intent of this restriction is to simplify identifying the bitstream type and content; for a given media type (or across all Ogg media types) we can know that we only need a small, fixed -amount of data to uniquely identify the bitstream type.

    +amount of data to uniquely identify the bitstream type.

    -As an example, Ogg Vorbis places the name and revision of the Vorbis +

    As an example, Ogg Vorbis places the name and revision of the Vorbis CODEC, the audio rate and the audio quality into this initial header, thus simplifying vastly the certain identification of an Ogg Vorbis -audio bitstream.

    +audio bitstream.

    sequential multiplexing (chaining)

    -The simplest form of logical bitstream multiplexing is concatenation -(chaining). Complete logical bitstreams are strung -one-after-another in order. The bitstreams do not overlap; the final +

    The simplest form of logical bitstream multiplexing is concatenation +(chaining). Complete logical bitstreams are strung +one-after-another in order. The bitstreams do not overlap; the final page of a given logical bitstream is immediately followed by the -initial page of the next. Chaining is the only logical->physical -mapping allowed by Ogg Vorbis.

    +initial page of the next. Chaining is the only logical->physical +mapping allowed by Ogg Vorbis.

    -Each chained logical bitstream must have a unique serial number within -the scope of the physical bitstream.

    +

    Each chained logical bitstream must have a unique serial number within +the scope of the physical bitstream.

    concurrent multiplexing (grouping)

    -Logical bitstreams may also be multiplexed 'in parallel' -(grouped). An example of grouping would be to allow +

    Logical bitstreams may also be multiplexed 'in parallel' +(grouped). An example of grouping would be to allow streaming of separate audio and video streams, using different codecs and different logical bitstreams, in the same physical bitstream. -Whole pages from multiple logical bitstreams are mixed together.

    +Whole pages from multiple logical bitstreams are mixed together.

    -The initial pages of each logical bitstream must appear first; the -media mapping specifies the order of the initial pages. For example, +

    The initial pages of each logical bitstream must appear first; the +media mapping specifies the order of the initial pages. For example, Ogg A/V will eventually specify an Ogg video bitstream with -audio. The mapping may specify that the physical bitstream must begin +audio. The mapping may specify that the physical bitstream must begin with the initial page of a logical video bitstream, followed by the -initial page of an audio stream. Unlike initial pages, terminal pages +initial page of an audio stream. Unlike initial pages, terminal pages for the logical bitstreams need not all occur contiguously (although a specific media mapping may require this; it is not mandated by the -generic Ogg stream spec). Terminal pages may be 'nil' pages, +generic Ogg stream spec). Terminal pages may be 'nil' pages, that is, pages containing no content but simply a page header with position information and the 'last page of bitstream' flag set in the -page header.

    +page header.

    -Each grouped bitstream must have a unique serial number within the -scope of the physical bitstream.

    +

    Each grouped bitstream must have a unique serial number within the +scope of the physical bitstream.

    sequential and concurrent multiplexing

    -Groups of concurrently multiplexed bitstreams may be chained -consecutively. Such a physical bitstream obeys all the rules of both +

    Groups of concurrently multiplexed bitstreams may be chained +consecutively. Such a physical bitstream obeys all the rules of both grouped and chained multiplexed streams; the groups, when unchained , must stand on their own as a valid concurrently multiplexed -bitstream.

    +bitstream.

    multiplexing example

    -Below, we present an example of a grouped and chained bitstream:

    +

    Below, we present an example of a grouped and chained bitstream:

    -

    +

    stream

    -In this example, we see pages from five total logical bitstreams -multiplexed into a physical bitstream. Note the following -characteristics: +

    In this example, we see pages from five total logical bitstreams +multiplexed into a physical bitstream. Note the following +characteristics:

    -
    1. Grouped bitstreams begin together; all of the initial pages -must appear before any data pages. When concurrently multiplexed +
        +
      1. Grouped bitstreams begin together; all of the initial pages +must appear before any data pages. When concurrently multiplexed groups are chained, the new group does not begin until all the -bitstreams in the previous group have terminated.

        +bitstreams in the previous group have terminated.

      2. The pages of concurrently multiplexed bitstreams need not conform to a regular order; the only requirement is that page n of a logical bitstream follow page n-1 in the physical bitstream. There are no restrictions on intervening pages belonging to other -logical bitstreams. (Tying page appearance to bitrate demands is one +logical bitstreams. (Tying page appearance to bitrate demands is one logical strategy, ie, the page appears at the chronological point -where decode requires more information). - +where decode requires more information).
      -
      - - - - + - - +