Blame doc/liboggz/latex/group__metric.tex

Packit a38265
\section{Using OggzMetric}
Packit a38265
\label{group__metric}\index{Using OggzMetric@{Using OggzMetric}}
Packit a38265
\subsection*{Typedefs}
Packit a38265
\begin{DoxyCompactItemize}
Packit a38265
\item 
Packit a38265
typedef ogg\_\-int64\_\-t($\ast$ {\bf OggzMetric} )({\bf OGGZ} $\ast$oggz, long serialno, ogg\_\-int64\_\-t granulepos, void $\ast$user\_\-data)
Packit a38265
\begin{DoxyCompactList}\small\item\em This is the signature of a function to correlate Ogg streams. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
Packit a38265
\subsection*{Functions}
Packit a38265
\begin{DoxyCompactItemize}
Packit a38265
\item 
Packit a38265
int {\bf oggz\_\-get\_\-preroll} ({\bf OGGZ} $\ast$oggz, long serialno)
Packit a38265
\begin{DoxyCompactList}\small\item\em Retrieve the preroll of a logical bitstream. \item\end{DoxyCompactList}\item 
Packit a38265
int {\bf oggz\_\-set\_\-preroll} ({\bf OGGZ} $\ast$oggz, long serialno, int preroll)
Packit a38265
\begin{DoxyCompactList}\small\item\em Specify the preroll of a logical bitstream. \item\end{DoxyCompactList}\item 
Packit a38265
int {\bf oggz\_\-get\_\-granuleshift} ({\bf OGGZ} $\ast$oggz, long serialno)
Packit a38265
\begin{DoxyCompactList}\small\item\em Retrieve the granuleshift of a logical bitstream. \item\end{DoxyCompactList}\item 
Packit a38265
int {\bf oggz\_\-set\_\-granuleshift} ({\bf OGGZ} $\ast$oggz, long serialno, int granuleshift)
Packit a38265
\begin{DoxyCompactList}\small\item\em Specify the granuleshift of a logical bitstream. \item\end{DoxyCompactList}\item 
Packit a38265
int {\bf oggz\_\-get\_\-granulerate} ({\bf OGGZ} $\ast$oggz, long serialno, ogg\_\-int64\_\-t $\ast$granulerate\_\-n, ogg\_\-int64\_\-t $\ast$granulerate\_\-d)
Packit a38265
\begin{DoxyCompactList}\small\item\em Retrieve the granulerate of a logical bitstream. \item\end{DoxyCompactList}\item 
Packit a38265
int {\bf oggz\_\-set\_\-granulerate} ({\bf OGGZ} $\ast$oggz, long serialno, ogg\_\-int64\_\-t granule\_\-rate\_\-numerator, ogg\_\-int64\_\-t granule\_\-rate\_\-denominator)
Packit a38265
\begin{DoxyCompactList}\small\item\em Specify the granulerate of a logical bitstream. \item\end{DoxyCompactList}\item 
Packit a38265
int {\bf oggz\_\-set\_\-metric} ({\bf OGGZ} $\ast$oggz, long serialno, {\bf OggzMetric} metric, void $\ast$user\_\-data)
Packit a38265
\begin{DoxyCompactList}\small\item\em Set the OggzMetric to use for an OGGZ handle. \item\end{DoxyCompactList}\item 
Packit a38265
int {\bf oggz\_\-set\_\-data\_\-start} ({\bf OGGZ} $\ast$oggz, oggz\_\-off\_\-t offset)
Packit a38265
\begin{DoxyCompactList}\small\item\em Tell Oggz to remember the given offset as the start of data. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
Packit a38265
Packit a38265
Packit a38265
\subsection{Detailed Description}
Packit a38265
\subsection{Introduction}\label{group__metric_metric_intro}
Packit a38265
An OggzMetric is a helper function for Oggz's seeking mechanism.
Packit a38265
Packit a38265
If every position in an Ogg stream can be described by a metric such as time, then it is possible to define a function that, given a serialno and granulepos, returns a measurement in units such as milliseconds. Oggz will use this function repeatedly while seeking in order to navigate through the Ogg stream.
Packit a38265
Packit a38265
The meaning of the units is arbitrary, but must be consistent across all logical bitstreams. This allows Oggz to seek accurately through Ogg bitstreams containing multiple logical bitstreams such as tracks of media.\subsection{How to set metrics}\label{group__metric_setting}
Packit a38265
You don't need to set metrics for Speex, Vorbis, FLAC, Theora, CMML or Annodex. These can be handled \doxyref{automatically }{p.}{group__seek__api} by Oggz.
Packit a38265
Packit a38265
For most others it is simply a matter of providing a \char`\"{}granulerate\char`\"{}: a frame or sampling rate, if each packet's granulepos represents a sample number.
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyItemize}
Packit a38265
\item Set the {\itshape granule\_\-rate\_\-numerator\/} and {\itshape granule\_\-rate\_\-denominator\/} appropriately using \doxyref{oggz\_\-set\_\-granulerate()}{p.}{group__metric_gaa2a86ec590161bc2295a2c8e91cefa49}
Packit a38265
\end{DoxyItemize}
Packit a38265
Packit a38265
Some codecs use a \char`\"{}granuleshift\char`\"{} to divide a granulepos into two halves; the first describing a dependency on a previous packet, the second giving the offset since that packet. This is used to mark keyframes and intermediate frames.
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyItemize}
Packit a38265
\item Set the {\itshape granuleshift\/} appropriately using \doxyref{oggz\_\-set\_\-granuleshift()}{p.}{group__metric_ga7ca67e0344580bf1541b9fbde39d481b}
Packit a38265
\end{DoxyItemize}\subsubsection{Custom Metrics}\label{group__metric_custom}
Packit a38265
For streams with non-\/linear granulepos, you need to set a custom metric:
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyItemize}
Packit a38265
\item Implement an OggzMetric callback
Packit a38265
\item Set the OggzMetric callback using \doxyref{oggz\_\-set\_\-metric()}{p.}{group__metric_ga5a630e8dcd04e1dd6601d8f56f0af3f6}
Packit a38265
\end{DoxyItemize}\subsection{Seeking with OggzMetrics}\label{group__metric_using}
Packit a38265
To seek, use \doxyref{oggz\_\-seek\_\-units()}{p.}{group__seek__api_ga60bac88ef3695629efacec43a21927e5}. Oggz will perform a ratio search through the Ogg bitstream, using the OggzMetric callback to determine its position relative to the desired unit.
Packit a38265
Packit a38265
\begin{DoxyNote}{Note}
Packit a38265
Packit a38265
\end{DoxyNote}
Packit a38265
Many data streams begin with headers describing such things as codec setup parameters. One of the assumptions Monty makes is:
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyItemize}
Packit a38265
\item Given pre-\/cached decode headers, a player may seek into a stream at any point and begin decode.
Packit a38265
\end{DoxyItemize}
Packit a38265
Packit a38265
Thus, the first action taken by applications dealing with such data is to read in and cache the decode headers; thereafter the application can safely seek to arbitrary points in the data.
Packit a38265
Packit a38265
This impacts seeking because the portion of the bitstream containing decode headers should not be considered part of the metric space. To inform Oggz not to seek earlier than the end of the decode headers, use \doxyref{oggz\_\-set\_\-data\_\-start()}{p.}{group__metric_gaaec9a54e9b231797d245042ce23b619a}. 
Packit a38265
Packit a38265
\subsection{Typedef Documentation}
Packit a38265
\index{metric@{metric}!OggzMetric@{OggzMetric}}
Packit a38265
\index{OggzMetric@{OggzMetric}!metric@{metric}}
Packit a38265
\subsubsection[{OggzMetric}]{\setlength{\rightskip}{0pt plus 5cm}typedef ogg\_\-int64\_\-t($\ast$ {\bf OggzMetric})({\bf OGGZ} $\ast$oggz, long serialno, ogg\_\-int64\_\-t granulepos, void $\ast$user\_\-data)}\label{group__metric_ga8803bb406015a32f5172902e3e4e76e8}
Packit a38265
Packit a38265
Packit a38265
This is the signature of a function to correlate Ogg streams. 
Packit a38265
Packit a38265
If every position in an Ogg stream can be described by a metric (eg. time) then define this function that returns some arbitrary unit value. This is the normal use of Oggz for media streams. The meaning of units is arbitrary, but must be consistent across all logical bitstreams; for example a conversion of the time offset of a given packet into nanoseconds or a similar stream-\/specific subdivision may be appropriate.
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyParams}{Parameters}
Packit a38265
\item[{\em oggz}]An OGGZ handle \item[{\em serialno}]Identifies a logical bitstream within {\itshape oggz\/} \item[{\em granulepos}]A granulepos within the logical bitstream identified by {\itshape serialno\/} \item[{\em user\_\-data}]Arbitrary data you wish to pass to your callback \end{DoxyParams}
Packit a38265
\begin{DoxyReturn}{Returns}
Packit a38265
A conversion of the (serialno, granulepos) pair into a measure in units which is consistent across all logical bitstreams within {\itshape oggz\/} 
Packit a38265
\end{DoxyReturn}
Packit a38265
Packit a38265
Packit a38265
\subsection{Function Documentation}
Packit a38265
\index{metric@{metric}!oggz\_\-get\_\-granulerate@{oggz\_\-get\_\-granulerate}}
Packit a38265
\index{oggz\_\-get\_\-granulerate@{oggz\_\-get\_\-granulerate}!metric@{metric}}
Packit a38265
\subsubsection[{oggz\_\-get\_\-granulerate}]{\setlength{\rightskip}{0pt plus 5cm}int oggz\_\-get\_\-granulerate ({\bf OGGZ} $\ast$ {\em oggz}, \/  long {\em serialno}, \/  ogg\_\-int64\_\-t $\ast$ {\em granulerate\_\-n}, \/  ogg\_\-int64\_\-t $\ast$ {\em granulerate\_\-d})}\label{group__metric_ga72a9a24e6f8483986859d7697fa611b6}
Packit a38265
Packit a38265
Packit a38265
Retrieve the granulerate of a logical bitstream. 
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyParams}{Parameters}
Packit a38265
\item[{\em oggz}]An OGGZ handle \item[{\em serialno}]Identify the logical bitstream in {\itshape oggz\/} \item[{\em granulerate\_\-n}]Return location for the granulerate numerator \item[{\em granulerate\_\-d}]Return location for the granulerate denominator \end{DoxyParams}
Packit a38265
\begin{DoxyReturn}{Returns}
Packit a38265
0 Success 
Packit a38265
\end{DoxyReturn}
Packit a38265
Packit a38265
\begin{DoxyRetVals}{Return values}
Packit a38265
\item[{\em OGGZ\_\-ERR\_\-BAD\_\-SERIALNO}]{\itshape serialno\/} does not identify an existing logical bitstream in {\itshape oggz\/}. \item[{\em OGGZ\_\-ERR\_\-BAD\_\-OGGZ}]{\itshape oggz\/} does not refer to an existing OGGZ \end{DoxyRetVals}
Packit a38265
\index{metric@{metric}!oggz\_\-get\_\-granuleshift@{oggz\_\-get\_\-granuleshift}}
Packit a38265
\index{oggz\_\-get\_\-granuleshift@{oggz\_\-get\_\-granuleshift}!metric@{metric}}
Packit a38265
\subsubsection[{oggz\_\-get\_\-granuleshift}]{\setlength{\rightskip}{0pt plus 5cm}int oggz\_\-get\_\-granuleshift ({\bf OGGZ} $\ast$ {\em oggz}, \/  long {\em serialno})}\label{group__metric_gad9b55e525a6e0b994a133314fd78e2c0}
Packit a38265
Packit a38265
Packit a38265
Retrieve the granuleshift of a logical bitstream. 
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyParams}{Parameters}
Packit a38265
\item[{\em oggz}]An OGGZ handle \item[{\em serialno}]Identify the logical bitstream in {\itshape oggz\/} \end{DoxyParams}
Packit a38265
\begin{DoxyReturn}{Returns}
Packit a38265
The granuleshift of the specified logical bitstream. 
Packit a38265
\end{DoxyReturn}
Packit a38265
Packit a38265
\begin{DoxyRetVals}{Return values}
Packit a38265
\item[{\em OGGZ\_\-ERR\_\-BAD\_\-SERIALNO}]{\itshape serialno\/} does not identify an existing logical bitstream in {\itshape oggz\/}. \item[{\em OGGZ\_\-ERR\_\-BAD\_\-OGGZ}]{\itshape oggz\/} does not refer to an existing OGGZ \end{DoxyRetVals}
Packit a38265
\index{metric@{metric}!oggz\_\-get\_\-preroll@{oggz\_\-get\_\-preroll}}
Packit a38265
\index{oggz\_\-get\_\-preroll@{oggz\_\-get\_\-preroll}!metric@{metric}}
Packit a38265
\subsubsection[{oggz\_\-get\_\-preroll}]{\setlength{\rightskip}{0pt plus 5cm}int oggz\_\-get\_\-preroll ({\bf OGGZ} $\ast$ {\em oggz}, \/  long {\em serialno})}\label{group__metric_gab411ab113d5f0f67bf77506724c25633}
Packit a38265
Packit a38265
Packit a38265
Retrieve the preroll of a logical bitstream. 
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyParams}{Parameters}
Packit a38265
\item[{\em oggz}]An OGGZ handle \item[{\em serialno}]Identify the logical bitstream in {\itshape oggz\/} \end{DoxyParams}
Packit a38265
\begin{DoxyReturn}{Returns}
Packit a38265
The preroll of the specified logical bitstream. 
Packit a38265
\end{DoxyReturn}
Packit a38265
Packit a38265
\begin{DoxyRetVals}{Return values}
Packit a38265
\item[{\em OGGZ\_\-ERR\_\-BAD\_\-SERIALNO}]{\itshape serialno\/} does not identify an existing logical bitstream in {\itshape oggz\/}. \item[{\em OGGZ\_\-ERR\_\-BAD\_\-OGGZ}]{\itshape oggz\/} does not refer to an existing OGGZ \end{DoxyRetVals}
Packit a38265
\index{metric@{metric}!oggz\_\-set\_\-data\_\-start@{oggz\_\-set\_\-data\_\-start}}
Packit a38265
\index{oggz\_\-set\_\-data\_\-start@{oggz\_\-set\_\-data\_\-start}!metric@{metric}}
Packit a38265
\subsubsection[{oggz\_\-set\_\-data\_\-start}]{\setlength{\rightskip}{0pt plus 5cm}int oggz\_\-set\_\-data\_\-start ({\bf OGGZ} $\ast$ {\em oggz}, \/  oggz\_\-off\_\-t {\em offset})}\label{group__metric_gaaec9a54e9b231797d245042ce23b619a}
Packit a38265
Packit a38265
Packit a38265
Tell Oggz to remember the given offset as the start of data. 
Packit a38265
Packit a38265
This informs the seeking mechanism that when seeking back to unit 0, go to the given offset, not to the start of the file, which is usually codec headers. The usual usage is: 
Packit a38265
\begin{DoxyPre}
Packit a38265
    oggz\_set\_data\_start (oggz, oggz\_tell (oggz));
Packit a38265
\end{DoxyPre}
Packit a38265
 
Packit a38265
\begin{DoxyParams}{Parameters}
Packit a38265
\item[{\em oggz}]An OGGZ handle previously opened for reading \item[{\em offset}]The offset of the start of data \end{DoxyParams}
Packit a38265
\begin{DoxyReturn}{Returns}
Packit a38265
0 on success, -\/1 on failure. 
Packit a38265
\end{DoxyReturn}
Packit a38265
\index{metric@{metric}!oggz\_\-set\_\-granulerate@{oggz\_\-set\_\-granulerate}}
Packit a38265
\index{oggz\_\-set\_\-granulerate@{oggz\_\-set\_\-granulerate}!metric@{metric}}
Packit a38265
\subsubsection[{oggz\_\-set\_\-granulerate}]{\setlength{\rightskip}{0pt plus 5cm}int oggz\_\-set\_\-granulerate ({\bf OGGZ} $\ast$ {\em oggz}, \/  long {\em serialno}, \/  ogg\_\-int64\_\-t {\em granule\_\-rate\_\-numerator}, \/  ogg\_\-int64\_\-t {\em granule\_\-rate\_\-denominator})}\label{group__metric_gaa2a86ec590161bc2295a2c8e91cefa49}
Packit a38265
Packit a38265
Packit a38265
Specify the granulerate of a logical bitstream. 
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyParams}{Parameters}
Packit a38265
\item[{\em oggz}]An OGGZ handle \item[{\em serialno}]Identify the logical bitstream in {\itshape oggz\/} to attach this linear metric to. A value of -\/1 indicates that the metric should be attached to all unattached logical bitstreams in {\itshape oggz\/}. \item[{\em granule\_\-rate\_\-numerator}]The numerator of the granule rate \item[{\em granule\_\-rate\_\-denominator}]The denominator of the granule rate \end{DoxyParams}
Packit a38265
\begin{DoxyReturn}{Returns}
Packit a38265
0 Success 
Packit a38265
\end{DoxyReturn}
Packit a38265
Packit a38265
\begin{DoxyRetVals}{Return values}
Packit a38265
\item[{\em OGGZ\_\-ERR\_\-BAD\_\-SERIALNO}]{\itshape serialno\/} does not identify an existing logical bitstream in {\itshape oggz\/}. \item[{\em OGGZ\_\-ERR\_\-BAD\_\-OGGZ}]{\itshape oggz\/} does not refer to an existing OGGZ \end{DoxyRetVals}
Packit a38265
\index{metric@{metric}!oggz\_\-set\_\-granuleshift@{oggz\_\-set\_\-granuleshift}}
Packit a38265
\index{oggz\_\-set\_\-granuleshift@{oggz\_\-set\_\-granuleshift}!metric@{metric}}
Packit a38265
\subsubsection[{oggz\_\-set\_\-granuleshift}]{\setlength{\rightskip}{0pt plus 5cm}int oggz\_\-set\_\-granuleshift ({\bf OGGZ} $\ast$ {\em oggz}, \/  long {\em serialno}, \/  int {\em granuleshift})}\label{group__metric_ga7ca67e0344580bf1541b9fbde39d481b}
Packit a38265
Packit a38265
Packit a38265
Specify the granuleshift of a logical bitstream. 
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyParams}{Parameters}
Packit a38265
\item[{\em oggz}]An OGGZ handle \item[{\em serialno}]Identify the logical bitstream in {\itshape oggz\/} to attach this granuleshift metric to. A value of -\/1 indicates that the metric should be attached to all unattached logical bitstreams in {\itshape oggz\/}. \item[{\em granuleshift}]The granuleshift \end{DoxyParams}
Packit a38265
\begin{DoxyReturn}{Returns}
Packit a38265
0 Success 
Packit a38265
\end{DoxyReturn}
Packit a38265
Packit a38265
\begin{DoxyRetVals}{Return values}
Packit a38265
\item[{\em OGGZ\_\-ERR\_\-BAD\_\-SERIALNO}]{\itshape serialno\/} does not identify an existing logical bitstream in {\itshape oggz\/}. \item[{\em OGGZ\_\-ERR\_\-BAD\_\-OGGZ}]{\itshape oggz\/} does not refer to an existing OGGZ \end{DoxyRetVals}
Packit a38265
\index{metric@{metric}!oggz\_\-set\_\-metric@{oggz\_\-set\_\-metric}}
Packit a38265
\index{oggz\_\-set\_\-metric@{oggz\_\-set\_\-metric}!metric@{metric}}
Packit a38265
\subsubsection[{oggz\_\-set\_\-metric}]{\setlength{\rightskip}{0pt plus 5cm}int oggz\_\-set\_\-metric ({\bf OGGZ} $\ast$ {\em oggz}, \/  long {\em serialno}, \/  {\bf OggzMetric} {\em metric}, \/  void $\ast$ {\em user\_\-data})}\label{group__metric_ga5a630e8dcd04e1dd6601d8f56f0af3f6}
Packit a38265
Packit a38265
Packit a38265
Set the OggzMetric to use for an OGGZ handle. 
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyParams}{Parameters}
Packit a38265
\item[{\em oggz}]An OGGZ handle \item[{\em serialno}]Identify the logical bitstream in {\itshape oggz\/} to attach this metric to. A value of -\/1 indicates that this metric should be attached to all unattached logical bitstreams in {\itshape oggz\/}. \item[{\em metric}]An OggzMetric callback \item[{\em user\_\-data}]arbitrary data to pass to the metric callback\end{DoxyParams}
Packit a38265
\begin{DoxyReturn}{Returns}
Packit a38265
0 Success 
Packit a38265
\end{DoxyReturn}
Packit a38265
Packit a38265
\begin{DoxyRetVals}{Return values}
Packit a38265
\item[{\em OGGZ\_\-ERR\_\-BAD\_\-SERIALNO}]{\itshape serialno\/} does not identify an existing logical bitstream in {\itshape oggz\/}, and is not -\/1 \item[{\em OGGZ\_\-ERR\_\-BAD\_\-OGGZ}]{\itshape oggz\/} does not refer to an existing OGGZ\end{DoxyRetVals}
Packit a38265
\begin{DoxyNote}{Note}
Packit a38265
Specifying values of {\itshape serialno\/} other than -\/1 allows you to pass logical bitstream specific user\_\-data to the same metric. 
Packit a38265
Packit a38265
Alternatively, you may use a different {\itshape metric\/} for each {\itshape serialno\/}, but all metrics used must return mutually consistent unit measurements. 
Packit a38265
\end{DoxyNote}
Packit a38265
\index{metric@{metric}!oggz\_\-set\_\-preroll@{oggz\_\-set\_\-preroll}}
Packit a38265
\index{oggz\_\-set\_\-preroll@{oggz\_\-set\_\-preroll}!metric@{metric}}
Packit a38265
\subsubsection[{oggz\_\-set\_\-preroll}]{\setlength{\rightskip}{0pt plus 5cm}int oggz\_\-set\_\-preroll ({\bf OGGZ} $\ast$ {\em oggz}, \/  long {\em serialno}, \/  int {\em preroll})}\label{group__metric_gaa2b4ab5be298a11b5b91147b76996c83}
Packit a38265
Packit a38265
Packit a38265
Specify the preroll of a logical bitstream. 
Packit a38265
Packit a38265
Packit a38265
\begin{DoxyParams}{Parameters}
Packit a38265
\item[{\em oggz}]An OGGZ handle \item[{\em serialno}]Identify the logical bitstream in {\itshape oggz\/} to attach this preroll to. \item[{\em preroll}]The preroll \end{DoxyParams}
Packit a38265
\begin{DoxyReturn}{Returns}
Packit a38265
0 Success 
Packit a38265
\end{DoxyReturn}
Packit a38265
Packit a38265
\begin{DoxyRetVals}{Return values}
Packit a38265
\item[{\em OGGZ\_\-ERR\_\-BAD\_\-SERIALNO}]{\itshape serialno\/} does not identify an existing logical bitstream in {\itshape oggz\/}. \item[{\em OGGZ\_\-ERR\_\-BAD\_\-OGGZ}]{\itshape oggz\/} does not refer to an existing OGGZ \end{DoxyRetVals}