Blame doc/05-comment.tex

Packit 06404a
% -*- mode: latex; TeX-master: "Vorbis_I_spec"; -*-
Packit 06404a
%!TEX root = Vorbis_I_spec.tex
Packit 06404a
% $Id$
Packit 06404a
\section{comment field and header specification} \label{vorbis:spec:comment}
Packit 06404a
Packit 06404a
\subsection{Overview}
Packit 06404a
Packit 06404a
The Vorbis text comment header is the second (of three) header
Packit 06404a
packets that begin a Vorbis bitstream. It is meant for short text
Packit 06404a
comments, not arbitrary metadata; arbitrary metadata belongs in a
Packit 06404a
separate logical bitstream (usually an XML stream type) that provides
Packit 06404a
greater structure and machine parseability.
Packit 06404a
Packit 06404a
The comment field is meant to be used much like someone jotting a
Packit 06404a
quick note on the bottom of a CDR. It should be a little information to
Packit 06404a
remember the disc by and explain it to others; a short, to-the-point
Packit 06404a
text note that need not only be a couple words, but isn't going to be
Packit 06404a
more than a short paragraph.  The essentials, in other words, whatever
Packit 06404a
they turn out to be, eg:
Packit 06404a
Packit 06404a
\begin{quote}
Packit 06404a
Honest Bob and the Factory-to-Dealer-Incentives, \textit{``I'm Still
Packit 06404a
Around''}, opening for Moxy Fr\"{u}vous, 1997.
Packit 06404a
\end{quote}
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
\subsection{Comment encoding}
Packit 06404a
Packit 06404a
\subsubsection{Structure}
Packit 06404a
Packit 06404a
The comment header is logically a list of eight-bit-clean vectors; the
Packit 06404a
number of vectors is bounded to $2^{32}-1$ and the length of each vector
Packit 06404a
is limited to $2^{32}-1$ bytes. The vector length is encoded; the vector
Packit 06404a
contents themselves are not null terminated. In addition to the vector
Packit 06404a
list, there is a single vector for vendor name (also 8 bit clean,
Packit 06404a
length encoded in 32 bits). For example, the 1.0 release of libvorbis
Packit 06404a
set the vendor string to ``Xiph.Org libVorbis I 20020717''.
Packit 06404a
Packit 06404a
The vector lengths and number of vectors are stored lsb first, according
Packit 06404a
to the bit packing conventions of the vorbis codec. However, since data
Packit 06404a
in the comment header is octet-aligned, they can simply be read as
Packit 06404a
unaligned 32 bit little endian unsigned integers.
Packit 06404a
Packit 06404a
The comment header is decoded as follows:
Packit 06404a
Packit 06404a
\begin{programlisting}
Packit 06404a
  1) [vendor\_length] = read an unsigned integer of 32 bits
Packit 06404a
  2) [vendor\_string] = read a UTF-8 vector as [vendor\_length] octets
Packit 06404a
  3) [user\_comment\_list\_length] = read an unsigned integer of 32 bits
Packit 06404a
  4) iterate [user\_comment\_list\_length] times {
Packit 06404a
       5) [length] = read an unsigned integer of 32 bits
Packit 06404a
       6) this iteration's user comment = read a UTF-8 vector as [length] octets
Packit 06404a
     }
Packit 06404a
  7) [framing\_bit] = read a single bit as boolean
Packit 06404a
  8) if ( [framing\_bit] unset or end-of-packet ) then ERROR
Packit 06404a
  9) done.
Packit 06404a
\end{programlisting}
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
\subsubsection{Content vector format}
Packit 06404a
Packit 06404a
The comment vectors are structured similarly to a UNIX environment variable.
Packit 06404a
That is, comment fields consist of a field name and a corresponding value and
Packit 06404a
look like:
Packit 06404a
Packit 06404a
\begin{quote}
Packit 06404a
\begin{programlisting}
Packit 06404a
comment[0]="ARTIST=me";
Packit 06404a
comment[1]="TITLE=the sound of Vorbis";
Packit 06404a
\end{programlisting}
Packit 06404a
\end{quote}
Packit 06404a
Packit 06404a
The field name is case-insensitive and may consist of ASCII 0x20
Packit 06404a
through 0x7D, 0x3D ('=') excluded. ASCII 0x41 through 0x5A inclusive
Packit 06404a
(characters A-Z) is to be considered equivalent to ASCII 0x61 through
Packit 06404a
0x7A inclusive (characters a-z).
Packit 06404a
Packit 06404a
Packit 06404a
The field name is immediately followed by ASCII 0x3D ('=');
Packit 06404a
this equals sign is used to terminate the field name.
Packit 06404a
Packit 06404a
Packit 06404a
0x3D is followed by 8 bit clean UTF-8 encoded value of the
Packit 06404a
field contents to the end of the field.
Packit 06404a
Packit 06404a
Packit 06404a
\paragraph{Field names}
Packit 06404a
Packit 06404a
Below is a proposed, minimal list of standard field names with a
Packit 06404a
description of intended use.  No single or group of field names is
Packit 06404a
mandatory; a comment header may contain one, all or none of the names
Packit 06404a
in this list.
Packit 06404a
Packit 06404a
\begin{description} %[style=nextline]
Packit 06404a
\item[TITLE]
Packit 06404a
	Track/Work name
Packit 06404a
Packit 06404a
\item[VERSION]
Packit 06404a
	The version field may be used to differentiate multiple
Packit 06404a
versions of the same track title in a single collection. (e.g. remix
Packit 06404a
info)
Packit 06404a
Packit 06404a
\item[ALBUM]
Packit 06404a
	The collection name to which this track belongs
Packit 06404a
Packit 06404a
\item[TRACKNUMBER]
Packit 06404a
	The track number of this piece if part of a specific larger collection or album
Packit 06404a
Packit 06404a
\item[ARTIST]
Packit 06404a
	The artist generally considered responsible for the work. In popular music this is usually the performing band or singer. For classical music it would be the composer. For an audio book it would be the author of the original text.
Packit 06404a
Packit 06404a
\item[PERFORMER]
Packit 06404a
	The artist(s) who performed the work. In classical music this would be the conductor, orchestra, soloists. In an audio book it would be the actor who did the reading. In popular music this is typically the same as the ARTIST and is omitted.
Packit 06404a
Packit 06404a
\item[COPYRIGHT]
Packit 06404a
	Copyright attribution, e.g., '2001 Nobody's Band' or '1999 Jack Moffitt'
Packit 06404a
Packit 06404a
\item[LICENSE]
Packit 06404a
	License information, eg, 'All Rights Reserved', 'Any
Packit 06404a
Use Permitted', a URL to a license such as a Creative Commons license
Packit 06404a
("www.creativecommons.org/blahblah/license.html") or the EFF Open
Packit 06404a
Audio License ('distributed under the terms of the Open Audio
Packit 06404a
License. see http://www.eff.org/IP/Open\_licenses/eff\_oal.html for
Packit 06404a
details'), etc.
Packit 06404a
Packit 06404a
\item[ORGANIZATION]
Packit 06404a
	Name of the organization producing the track (i.e.
Packit 06404a
the 'record label')
Packit 06404a
Packit 06404a
\item[DESCRIPTION]
Packit 06404a
	A short text description of the contents
Packit 06404a
Packit 06404a
\item[GENRE]
Packit 06404a
	A short text indication of music genre
Packit 06404a
Packit 06404a
\item[DATE]
Packit 06404a
	Date the track was recorded
Packit 06404a
Packit 06404a
\item[LOCATION]
Packit 06404a
	Location where track was recorded
Packit 06404a
Packit 06404a
\item[CONTACT]
Packit 06404a
	Contact information for the creators or distributors of the track. This could be a URL, an email address, the physical address of the producing label.
Packit 06404a
Packit 06404a
\item[ISRC]
Packit 06404a
	International Standard Recording Code for the
Packit 06404a
track; see \href{http://www.ifpi.org/isrc/}{the ISRC
Packit 06404a
intro page} for more information on ISRC numbers.
Packit 06404a
Packit 06404a
\end{description}
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
\paragraph{Implications}
Packit 06404a
Packit 06404a
Field names should not be 'internationalized'; this is a
Packit 06404a
concession to simplicity not an attempt to exclude the majority of
Packit 06404a
the world that doesn't speak English. Field \emph{contents},
Packit 06404a
however, use the UTF-8 character encoding to allow easy representation
Packit 06404a
of any language.
Packit 06404a
Packit 06404a
We have the length of the entirety of the field and restrictions on
Packit 06404a
the field name so that the field name is bounded in a known way. Thus
Packit 06404a
we also have the length of the field contents.
Packit 06404a
Packit 06404a
Individual 'vendors' may use non-standard field names within
Packit 06404a
reason. The proper use of comment fields should be clear through
Packit 06404a
context at this point.  Abuse will be discouraged.
Packit 06404a
Packit 06404a
There is no vendor-specific prefix to 'nonstandard' field names.
Packit 06404a
Vendors should make some effort to avoid arbitrarily polluting the
Packit 06404a
common namespace. We will generally collect the more useful tags
Packit 06404a
here to help with standardization.
Packit 06404a
Packit 06404a
Field names are not required to be unique (occur once) within a
Packit 06404a
comment header.  As an example, assume a track was recorded by three
Packit 06404a
well know artists; the following is permissible, and encouraged:
Packit 06404a
Packit 06404a
\begin{quote}
Packit 06404a
\begin{programlisting}
Packit 06404a
ARTIST=Dizzy Gillespie
Packit 06404a
ARTIST=Sonny Rollins
Packit 06404a
ARTIST=Sonny Stitt
Packit 06404a
\end{programlisting}
Packit 06404a
\end{quote}
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
\subsubsection{Encoding}
Packit 06404a
Packit 06404a
The comment header comprises the entirety of the second bitstream
Packit 06404a
header packet.  Unlike the first bitstream header packet, it is not
Packit 06404a
generally the only packet on the second page and may not be restricted
Packit 06404a
to within the second bitstream page.  The length of the comment header
Packit 06404a
packet is (practically) unbounded.  The comment header packet is not
Packit 06404a
optional; it must be present in the bitstream even if it is
Packit 06404a
effectively empty.
Packit 06404a
Packit 06404a
The comment header is encoded as follows (as per Ogg's standard
Packit 06404a
bitstream mapping which renders least-significant-bit of the word to be
Packit 06404a
coded into the least significant available bit of the current
Packit 06404a
bitstream octet first):
Packit 06404a
Packit 06404a
\begin{enumerate}
Packit 06404a
 \item
Packit 06404a
  Vendor string length (32 bit unsigned quantity specifying number of octets)
Packit 06404a
Packit 06404a
 \item
Packit 06404a
  Vendor string ([vendor string length] octets coded from beginning of string to end of string, not null terminated)
Packit 06404a
Packit 06404a
 \item
Packit 06404a
  Number of comment fields (32 bit unsigned quantity specifying number of fields)
Packit 06404a
Packit 06404a
 \item
Packit 06404a
  Comment field 0 length (if [Number of comment fields] $>0$; 32 bit unsigned quantity specifying number of octets)
Packit 06404a
Packit 06404a
 \item
Packit 06404a
  Comment field 0 ([Comment field 0 length] octets coded from beginning of string to end of string, not null terminated)
Packit 06404a
Packit 06404a
 \item
Packit 06404a
  Comment field 1 length (if [Number of comment fields] $>1$...)...
Packit 06404a
Packit 06404a
\end{enumerate}
Packit 06404a
Packit 06404a
Packit 06404a
This is actually somewhat easier to describe in code; implementation of the above can be found in \filename{vorbis/lib/info.c}, \function{\_vorbis\_pack\_comment()} and \function{\_vorbis\_unpack\_comment()}.
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a