\doxysection{Using Oggz\+Metric}
\label{group__metric}\index{Using OggzMetric@{Using OggzMetric}}
\doxysubsubsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef ogg\+\_\+int64\+\_\+t($\ast$ \textbf{ Oggz\+Metric}) (\textbf{ OGGZ} $\ast$oggz, long serialno, ogg\+\_\+int64\+\_\+t granulepos, void $\ast$user\+\_\+data)
\begin{DoxyCompactList}\small\item\em This is the signature of a function to correlate Ogg streams. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
int \textbf{ oggz\+\_\+get\+\_\+preroll} (\textbf{ OGGZ} $\ast$oggz, long serialno)
\begin{DoxyCompactList}\small\item\em Retrieve the preroll of a logical bitstream. \end{DoxyCompactList}\item 
int \textbf{ oggz\+\_\+set\+\_\+preroll} (\textbf{ OGGZ} $\ast$oggz, long serialno, int preroll)
\begin{DoxyCompactList}\small\item\em Specify the preroll of a logical bitstream. \end{DoxyCompactList}\item 
int \textbf{ oggz\+\_\+get\+\_\+granuleshift} (\textbf{ OGGZ} $\ast$oggz, long serialno)
\begin{DoxyCompactList}\small\item\em Retrieve the granuleshift of a logical bitstream. \end{DoxyCompactList}\item 
int \textbf{ oggz\+\_\+set\+\_\+granuleshift} (\textbf{ OGGZ} $\ast$oggz, long serialno, int granuleshift)
\begin{DoxyCompactList}\small\item\em Specify the granuleshift of a logical bitstream. \end{DoxyCompactList}\item 
int \textbf{ oggz\+\_\+get\+\_\+granulerate} (\textbf{ OGGZ} $\ast$oggz, long serialno, ogg\+\_\+int64\+\_\+t $\ast$granulerate\+\_\+n, ogg\+\_\+int64\+\_\+t $\ast$granulerate\+\_\+d)
\begin{DoxyCompactList}\small\item\em Retrieve the granulerate of a logical bitstream. \end{DoxyCompactList}\item 
int \textbf{ oggz\+\_\+set\+\_\+granulerate} (\textbf{ OGGZ} $\ast$oggz, long serialno, ogg\+\_\+int64\+\_\+t granule\+\_\+rate\+\_\+numerator, ogg\+\_\+int64\+\_\+t granule\+\_\+rate\+\_\+denominator)
\begin{DoxyCompactList}\small\item\em Specify the granulerate of a logical bitstream. \end{DoxyCompactList}\item 
int \textbf{ oggz\+\_\+set\+\_\+metric} (\textbf{ OGGZ} $\ast$oggz, long serialno, \textbf{ Oggz\+Metric} metric, void $\ast$user\+\_\+data)
\begin{DoxyCompactList}\small\item\em Set the \doxyref{Oggz\+Metric}{p.}{group__metric_ga6e060f8616a8f8b3c76cb829a8227938} to use for an \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} handle. \end{DoxyCompactList}\item 
int \textbf{ oggz\+\_\+set\+\_\+data\+\_\+start} (\textbf{ OGGZ} $\ast$oggz, \textbf{ oggz\+\_\+off\+\_\+t} offset)
\begin{DoxyCompactList}\small\item\em Tell Oggz to remember the given offset as the start of data. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
\doxysubsection{Introduction}\label{group__metric_metric_intro}
An \doxyref{Oggz\+Metric}{p.}{group__metric_ga6e060f8616a8f8b3c76cb829a8227938} is a helper function for Oggz\textquotesingle{}s seeking mechanism.

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.

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.\doxysubsection{How to set metrics}\label{group__metric_setting}
You don\textquotesingle{}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.

For most others it is simply a matter of providing a "{}granulerate"{}\+: a frame or sampling rate, if each packet\textquotesingle{}s granulepos represents a sample number.


\begin{DoxyItemize}
\item Set the {\itshape granule\+\_\+rate\+\_\+numerator} and {\itshape granule\+\_\+rate\+\_\+denominator} appropriately using \doxyref{oggz\+\_\+set\+\_\+granulerate()}{p.}{group__metric_gaa2a86ec590161bc2295a2c8e91cefa49}
\end{DoxyItemize}

Some codecs use a "{}granuleshift"{} 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.


\begin{DoxyItemize}
\item Set the {\itshape granuleshift} appropriately using \doxyref{oggz\+\_\+set\+\_\+granuleshift()}{p.}{group__metric_ga7ca67e0344580bf1541b9fbde39d481b}
\end{DoxyItemize}\doxysubsubsection{Custom Metrics}\label{group__metric_custom}
For streams with non-\/linear granulepos, you need to set a custom metric\+:


\begin{DoxyItemize}
\item Implement an \doxyref{Oggz\+Metric}{p.}{group__metric_ga6e060f8616a8f8b3c76cb829a8227938} callback
\item Set the \doxyref{Oggz\+Metric}{p.}{group__metric_ga6e060f8616a8f8b3c76cb829a8227938} callback using \doxyref{oggz\+\_\+set\+\_\+metric()}{p.}{group__metric_ga5a630e8dcd04e1dd6601d8f56f0af3f6}
\end{DoxyItemize}\doxysubsection{Seeking with Oggz\+Metrics}\label{group__metric_using}
To seek, use \doxyref{oggz\+\_\+seek\+\_\+units()}{p.}{group__seek__api_ga60bac88ef3695629efacec43a21927e5}. Oggz will perform a ratio search through the Ogg bitstream, using the \doxyref{Oggz\+Metric}{p.}{group__metric_ga6e060f8616a8f8b3c76cb829a8227938} callback to determine its position relative to the desired unit.

\begin{DoxyNote}{Note}

\end{DoxyNote}
Many data streams begin with headers describing such things as codec setup parameters. One of the assumptions Monty makes is\+:


\begin{DoxyItemize}
\item Given pre-\/cached decode headers, a player may seek into a stream at any point and begin decode.
\end{DoxyItemize}

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.

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}. 

\doxysubsection{Typedef Documentation}
\index{Using OggzMetric@{Using OggzMetric}!OggzMetric@{OggzMetric}}
\index{OggzMetric@{OggzMetric}!Using OggzMetric@{Using OggzMetric}}
\doxysubsubsection{OggzMetric}
{\footnotesize\ttfamily \label{group__metric_ga6e060f8616a8f8b3c76cb829a8227938} 
typedef ogg\+\_\+int64\+\_\+t($\ast$ Oggz\+Metric) (\textbf{ OGGZ} $\ast$oggz, long serialno, ogg\+\_\+int64\+\_\+t granulepos, void $\ast$user\+\_\+data)}



This is the signature of a function to correlate Ogg streams. 

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.


\begin{DoxyParams}{Parameters}
{\em oggz} & An \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} handle \\
\hline
{\em serialno} & Identifies a logical bitstream within {\itshape oggz} \\
\hline
{\em granulepos} & A granulepos within the logical bitstream identified by {\itshape serialno} \\
\hline
{\em user\+\_\+data} & Arbitrary data you wish to pass to your callback \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A conversion of the (serialno, granulepos) pair into a measure in units which is consistent across all logical bitstreams within {\itshape oggz} 
\end{DoxyReturn}


\doxysubsection{Function Documentation}
\index{Using OggzMetric@{Using OggzMetric}!oggz\_get\_granulerate@{oggz\_get\_granulerate}}
\index{oggz\_get\_granulerate@{oggz\_get\_granulerate}!Using OggzMetric@{Using OggzMetric}}
\doxysubsubsection{oggz\_get\_granulerate()}
{\footnotesize\ttfamily \label{group__metric_ga72a9a24e6f8483986859d7697fa611b6} 
int oggz\+\_\+get\+\_\+granulerate (\begin{DoxyParamCaption}\item[{\textbf{ OGGZ} $\ast$}]{oggz}{, }\item[{long}]{serialno}{, }\item[{ogg\+\_\+int64\+\_\+t $\ast$}]{granulerate\+\_\+n}{, }\item[{ogg\+\_\+int64\+\_\+t $\ast$}]{granulerate\+\_\+d}{}\end{DoxyParamCaption})}



Retrieve the granulerate of a logical bitstream. 


\begin{DoxyParams}{Parameters}
{\em oggz} & An \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} handle \\
\hline
{\em serialno} & Identify the logical bitstream in {\itshape oggz} \\
\hline
{\em granulerate\+\_\+n} & Return location for the granulerate numerator \\
\hline
{\em granulerate\+\_\+d} & Return location for the granulerate denominator \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 Success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+SERIALNO} & {\itshape serialno} does not identify an existing logical bitstream in {\itshape oggz}. \\
\hline
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+OGGZ} & {\itshape oggz} does not refer to an existing \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} \\
\hline
\end{DoxyRetVals}
\index{Using OggzMetric@{Using OggzMetric}!oggz\_get\_granuleshift@{oggz\_get\_granuleshift}}
\index{oggz\_get\_granuleshift@{oggz\_get\_granuleshift}!Using OggzMetric@{Using OggzMetric}}
\doxysubsubsection{oggz\_get\_granuleshift()}
{\footnotesize\ttfamily \label{group__metric_gad9b55e525a6e0b994a133314fd78e2c0} 
int oggz\+\_\+get\+\_\+granuleshift (\begin{DoxyParamCaption}\item[{\textbf{ OGGZ} $\ast$}]{oggz}{, }\item[{long}]{serialno}{}\end{DoxyParamCaption})}



Retrieve the granuleshift of a logical bitstream. 


\begin{DoxyParams}{Parameters}
{\em oggz} & An \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} handle \\
\hline
{\em serialno} & Identify the logical bitstream in {\itshape oggz} \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The granuleshift of the specified logical bitstream. 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+SERIALNO} & {\itshape serialno} does not identify an existing logical bitstream in {\itshape oggz}. \\
\hline
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+OGGZ} & {\itshape oggz} does not refer to an existing \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} \\
\hline
\end{DoxyRetVals}
\index{Using OggzMetric@{Using OggzMetric}!oggz\_get\_preroll@{oggz\_get\_preroll}}
\index{oggz\_get\_preroll@{oggz\_get\_preroll}!Using OggzMetric@{Using OggzMetric}}
\doxysubsubsection{oggz\_get\_preroll()}
{\footnotesize\ttfamily \label{group__metric_gab411ab113d5f0f67bf77506724c25633} 
int oggz\+\_\+get\+\_\+preroll (\begin{DoxyParamCaption}\item[{\textbf{ OGGZ} $\ast$}]{oggz}{, }\item[{long}]{serialno}{}\end{DoxyParamCaption})}



Retrieve the preroll of a logical bitstream. 


\begin{DoxyParams}{Parameters}
{\em oggz} & An \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} handle \\
\hline
{\em serialno} & Identify the logical bitstream in {\itshape oggz} \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The preroll of the specified logical bitstream. 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+SERIALNO} & {\itshape serialno} does not identify an existing logical bitstream in {\itshape oggz}. \\
\hline
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+OGGZ} & {\itshape oggz} does not refer to an existing \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} \\
\hline
\end{DoxyRetVals}
\index{Using OggzMetric@{Using OggzMetric}!oggz\_set\_data\_start@{oggz\_set\_data\_start}}
\index{oggz\_set\_data\_start@{oggz\_set\_data\_start}!Using OggzMetric@{Using OggzMetric}}
\doxysubsubsection{oggz\_set\_data\_start()}
{\footnotesize\ttfamily \label{group__metric_gaaec9a54e9b231797d245042ce23b619a} 
int oggz\+\_\+set\+\_\+data\+\_\+start (\begin{DoxyParamCaption}\item[{\textbf{ OGGZ} $\ast$}]{oggz}{, }\item[{\textbf{ oggz\+\_\+off\+\_\+t}}]{offset}{}\end{DoxyParamCaption})}



Tell Oggz to remember the given offset as the start of data. 

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\+: 
\begin{DoxyPre}
    oggz\_set\_data\_start (oggz, oggz\_tell (oggz));
\end{DoxyPre}
 
\begin{DoxyParams}{Parameters}
{\em oggz} & An \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} handle previously opened for reading \\
\hline
{\em offset} & The offset of the start of data \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 on success, -\/1 on failure. 
\end{DoxyReturn}
\index{Using OggzMetric@{Using OggzMetric}!oggz\_set\_granulerate@{oggz\_set\_granulerate}}
\index{oggz\_set\_granulerate@{oggz\_set\_granulerate}!Using OggzMetric@{Using OggzMetric}}
\doxysubsubsection{oggz\_set\_granulerate()}
{\footnotesize\ttfamily \label{group__metric_gaa2a86ec590161bc2295a2c8e91cefa49} 
int oggz\+\_\+set\+\_\+granulerate (\begin{DoxyParamCaption}\item[{\textbf{ OGGZ} $\ast$}]{oggz}{, }\item[{long}]{serialno}{, }\item[{ogg\+\_\+int64\+\_\+t}]{granule\+\_\+rate\+\_\+numerator}{, }\item[{ogg\+\_\+int64\+\_\+t}]{granule\+\_\+rate\+\_\+denominator}{}\end{DoxyParamCaption})}



Specify the granulerate of a logical bitstream. 


\begin{DoxyParams}{Parameters}
{\em oggz} & An \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} handle \\
\hline
{\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}. \\
\hline
{\em granule\+\_\+rate\+\_\+numerator} & The numerator of the granule rate \\
\hline
{\em granule\+\_\+rate\+\_\+denominator} & The denominator of the granule rate \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 Success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+SERIALNO} & {\itshape serialno} does not identify an existing logical bitstream in {\itshape oggz}. \\
\hline
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+OGGZ} & {\itshape oggz} does not refer to an existing \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} \\
\hline
\end{DoxyRetVals}
\index{Using OggzMetric@{Using OggzMetric}!oggz\_set\_granuleshift@{oggz\_set\_granuleshift}}
\index{oggz\_set\_granuleshift@{oggz\_set\_granuleshift}!Using OggzMetric@{Using OggzMetric}}
\doxysubsubsection{oggz\_set\_granuleshift()}
{\footnotesize\ttfamily \label{group__metric_ga7ca67e0344580bf1541b9fbde39d481b} 
int oggz\+\_\+set\+\_\+granuleshift (\begin{DoxyParamCaption}\item[{\textbf{ OGGZ} $\ast$}]{oggz}{, }\item[{long}]{serialno}{, }\item[{int}]{granuleshift}{}\end{DoxyParamCaption})}



Specify the granuleshift of a logical bitstream. 


\begin{DoxyParams}{Parameters}
{\em oggz} & An \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} handle \\
\hline
{\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}. \\
\hline
{\em granuleshift} & The granuleshift \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 Success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+SERIALNO} & {\itshape serialno} does not identify an existing logical bitstream in {\itshape oggz}. \\
\hline
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+OGGZ} & {\itshape oggz} does not refer to an existing \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} \\
\hline
\end{DoxyRetVals}
\index{Using OggzMetric@{Using OggzMetric}!oggz\_set\_metric@{oggz\_set\_metric}}
\index{oggz\_set\_metric@{oggz\_set\_metric}!Using OggzMetric@{Using OggzMetric}}
\doxysubsubsection{oggz\_set\_metric()}
{\footnotesize\ttfamily \label{group__metric_ga5a630e8dcd04e1dd6601d8f56f0af3f6} 
int oggz\+\_\+set\+\_\+metric (\begin{DoxyParamCaption}\item[{\textbf{ OGGZ} $\ast$}]{oggz}{, }\item[{long}]{serialno}{, }\item[{\textbf{ Oggz\+Metric}}]{metric}{, }\item[{void $\ast$}]{user\+\_\+data}{}\end{DoxyParamCaption})}



Set the \doxyref{Oggz\+Metric}{p.}{group__metric_ga6e060f8616a8f8b3c76cb829a8227938} to use for an \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} handle. 


\begin{DoxyParams}{Parameters}
{\em oggz} & An \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} handle \\
\hline
{\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}. \\
\hline
{\em metric} & An \doxyref{Oggz\+Metric}{p.}{group__metric_ga6e060f8616a8f8b3c76cb829a8227938} callback \\
\hline
{\em user\+\_\+data} & arbitrary data to pass to the metric callback\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 Success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+SERIALNO} & {\itshape serialno} does not identify an existing logical bitstream in {\itshape oggz}, and is not -\/1 \\
\hline
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+OGGZ} & {\itshape oggz} does not refer to an existing \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee}\\
\hline
\end{DoxyRetVals}
\begin{DoxyNote}{Note}
Specifying values of {\itshape serialno} other than -\/1 allows you to pass logical bitstream specific user\+\_\+data to the same metric. 

Alternatively, you may use a different {\itshape metric} for each {\itshape serialno}, but all metrics used must return mutually consistent unit measurements. 
\end{DoxyNote}
\index{Using OggzMetric@{Using OggzMetric}!oggz\_set\_preroll@{oggz\_set\_preroll}}
\index{oggz\_set\_preroll@{oggz\_set\_preroll}!Using OggzMetric@{Using OggzMetric}}
\doxysubsubsection{oggz\_set\_preroll()}
{\footnotesize\ttfamily \label{group__metric_gaa2b4ab5be298a11b5b91147b76996c83} 
int oggz\+\_\+set\+\_\+preroll (\begin{DoxyParamCaption}\item[{\textbf{ OGGZ} $\ast$}]{oggz}{, }\item[{long}]{serialno}{, }\item[{int}]{preroll}{}\end{DoxyParamCaption})}



Specify the preroll of a logical bitstream. 


\begin{DoxyParams}{Parameters}
{\em oggz} & An \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} handle \\
\hline
{\em serialno} & Identify the logical bitstream in {\itshape oggz} to attach this preroll to. \\
\hline
{\em preroll} & The preroll \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 Success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+SERIALNO} & {\itshape serialno} does not identify an existing logical bitstream in {\itshape oggz}. \\
\hline
{\em OGGZ\+\_\+\+ERR\+\_\+\+BAD\+\_\+\+OGGZ} & {\itshape oggz} does not refer to an existing \doxyref{OGGZ}{p.}{oggz_8h_a672d218df13da45a4b41d5366211bfee} \\
\hline
\end{DoxyRetVals}
