\section{theoradec.h File Reference}
\label{theoradec_8h}\index{theoradec.h@{theoradec.h}}
The {\tt libtheoradec} C decoding API. 

{\tt \#include $<$ogg/ogg.h$>$}\par
{\tt \#include \char`\"{}codec.h\char`\"{}}\par
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct {\bf th\_\-stripe\_\-callback}
\begin{CompactList}\small\item\em The striped decode callback data to pass to \doxyref{TH\_\-DECCTL\_\-SET\_\-STRIPE\_\-CB}{p.}{theoradec_8h_4395ec9e75f08d00df4a83cb478d9f44}. \item\end{CompactList}\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define \textbf{\_\-O\_\-THEORA\_\-THEORADEC\_\-H\_\-}~(1)\label{theoradec_8h_2b23bc282e12c97568befda446d3869f}

\end{CompactItemize}
\begin{Indent}{\bf th\_\-decode\_\-ctl() codes}\par
{\em \label{theoradec_8h_decctlcodes}
 These are the available request codes for \doxyref{th\_\-decode\_\-ctl()}{p.}{group__decfuncs_g7393610f40038a80dc1555e510c0b15f}.

By convention, these are odd, to distinguish them from the \doxyref{encoder control codes}{p.}{theora_8h_encctlcodes}. Keep any experimental or vendor-specific values above {\tt 0x8000}. }\begin{CompactItemize}
\item 
\#define {\bf TH\_\-DECCTL\_\-GET\_\-PPLEVEL\_\-MAX}~(1)
\begin{CompactList}\small\item\em Gets the maximum post-processing level. \item\end{CompactList}\item 
\#define {\bf TH\_\-DECCTL\_\-SET\_\-PPLEVEL}~(3)
\begin{CompactList}\small\item\em Sets the post-processing level. \item\end{CompactList}\item 
\#define {\bf TH\_\-DECCTL\_\-SET\_\-GRANPOS}~(5)
\begin{CompactList}\small\item\em Sets the granule position. \item\end{CompactList}\item 
\#define {\bf TH\_\-DECCTL\_\-SET\_\-STRIPE\_\-CB}~(7)
\begin{CompactList}\small\item\em Sets the striped decode callback function. \item\end{CompactList}\end{CompactItemize}
\end{Indent}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
typedef void($\ast$) {\bf th\_\-stripe\_\-decoded\_\-func} (void $\ast$\_\-ctx, {\bf th\_\-ycbcr\_\-buffer} \_\-buf, int \_\-yfrag0, int \_\-yfrag\_\-end)
\begin{CompactList}\small\item\em A callback function for striped decode. \item\end{CompactList}\end{CompactItemize}
\begin{Indent}{\bf Decoder state}\par
{\em The following data structures are opaque, and their contents are not publicly defined by this API.

Referring to their internals directly is unsupported, and may break without warning. }\begin{CompactItemize}
\item 
typedef {\bf th\_\-dec\_\-ctx} {\bf th\_\-dec\_\-ctx}\label{theoradec_8h_e57d28984ca7a50fa99faaff751e433f}

\begin{CompactList}\small\item\em The decoder context. \item\end{CompactList}\item 
typedef {\bf th\_\-setup\_\-info} {\bf th\_\-setup\_\-info}
\begin{CompactList}\small\item\em Setup information. \item\end{CompactList}\end{CompactItemize}
\end{Indent}
\subsection*{Functions}
\begin{Indent}{\bf Functions for decoding}\par
{\em You must link to {\tt libtheoradec} if you use any of the functions in this section.

The functions are listed in the order they are used in a typical decode. The basic steps are:\begin{itemize}
\item Parse the header packets by repeatedly calling \doxyref{th\_\-decode\_\-headerin()}{p.}{group__decfuncs_gb6616614374d049781bf883f995b43d8}.\item Allocate a \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_e57d28984ca7a50fa99faaff751e433f} handle with \doxyref{th\_\-decode\_\-alloc()}{p.}{group__decfuncs_g48da74f31b3d34387d14760a41c5da89}.\item Call \doxyref{th\_\-setup\_\-free()}{p.}{group__decfuncs_gfc2356433984f842f1720c7c3433ba83} to free any memory used for codec setup information.\item Perform any additional decoder configuration with \doxyref{th\_\-decode\_\-ctl()}{p.}{group__decfuncs_g7393610f40038a80dc1555e510c0b15f}.\item For each video data packet:\begin{itemize}
\item Submit the packet to the decoder via \doxyref{th\_\-decode\_\-packetin()}{p.}{group__decfuncs_ga1f3ee21bdb5bbde01315af07ba8d29e}.\item Retrieve the uncompressed video data via \doxyref{th\_\-decode\_\-ycbcr\_\-out()}{p.}{group__decfuncs_gcc244f49a31ef7fab2fdfa06bf3525b0}.\end{itemize}
\item Call \doxyref{th\_\-decode\_\-free()}{p.}{group__decfuncs_ge3c9c9fbfd22ee72a3d8941c29b81034} to release all decoder memory. \end{itemize}
}\begin{CompactItemize}
\item 
int {\bf th\_\-decode\_\-headerin} ({\bf th\_\-info} $\ast$\_\-info, {\bf th\_\-comment} $\ast$\_\-tc, {\bf th\_\-setup\_\-info} $\ast$$\ast$\_\-setup, ogg\_\-packet $\ast$\_\-op)
\begin{CompactList}\small\item\em Decodes the header packets of a Theora stream. \item\end{CompactList}\item 
{\bf th\_\-dec\_\-ctx} $\ast$ {\bf th\_\-decode\_\-alloc} (const {\bf th\_\-info} $\ast$\_\-info, const {\bf th\_\-setup\_\-info} $\ast$\_\-setup)
\begin{CompactList}\small\item\em Allocates a decoder instance. \item\end{CompactList}\item 
void {\bf th\_\-setup\_\-free} ({\bf th\_\-setup\_\-info} $\ast$\_\-setup)
\begin{CompactList}\small\item\em Releases all storage used for the decoder setup information. \item\end{CompactList}\item 
int {\bf th\_\-decode\_\-ctl} ({\bf th\_\-dec\_\-ctx} $\ast$\_\-dec, int \_\-req, void $\ast$\_\-buf, size\_\-t \_\-buf\_\-sz)
\begin{CompactList}\small\item\em Decoder control function. \item\end{CompactList}\item 
int {\bf th\_\-decode\_\-packetin} ({\bf th\_\-dec\_\-ctx} $\ast$\_\-dec, const ogg\_\-packet $\ast$\_\-op, ogg\_\-int64\_\-t $\ast$\_\-granpos)
\begin{CompactList}\small\item\em Submits a packet containing encoded video data to the decoder. \item\end{CompactList}\item 
int {\bf th\_\-decode\_\-ycbcr\_\-out} ({\bf th\_\-dec\_\-ctx} $\ast$\_\-dec, {\bf th\_\-ycbcr\_\-buffer} \_\-ycbcr)
\begin{CompactList}\small\item\em Outputs the next available frame of decoded Y'Cb\-Cr data. \item\end{CompactList}\item 
void {\bf th\_\-decode\_\-free} ({\bf th\_\-dec\_\-ctx} $\ast$\_\-dec)
\begin{CompactList}\small\item\em Frees an allocated decoder instance. \item\end{CompactList}\end{CompactItemize}
\end{Indent}


\subsection{Detailed Description}
The {\tt libtheoradec} C decoding API. 



\subsection{Define Documentation}
\index{theoradec.h@{theoradec.h}!TH_DECCTL_GET_PPLEVEL_MAX@{TH\_\-DECCTL\_\-GET\_\-PPLEVEL\_\-MAX}}
\index{TH_DECCTL_GET_PPLEVEL_MAX@{TH\_\-DECCTL\_\-GET\_\-PPLEVEL\_\-MAX}!theoradec.h@{theoradec.h}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define TH\_\-DECCTL\_\-GET\_\-PPLEVEL\_\-MAX~(1)}\label{theoradec_8h_65bcee69b870122fb6632b69c3d3c1eb}


Gets the maximum post-processing level. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[\mbox{$\rightarrow$} {\em \_\-buf}]int: The maximum post-processing level. \end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em TH\_\-EFAULT}]{\em \_\-dec\_\-ctx\/} or {\em \_\-buf\/} is {\tt NULL}. \item[{\em TH\_\-EINVAL}]{\em \_\-buf\_\-sz\/} is not {\tt sizeof(int)}. \item[{\em TH\_\-EIMPL}]Not supported by this implementation. \end{description}
\end{Desc}
\index{theoradec.h@{theoradec.h}!TH_DECCTL_SET_GRANPOS@{TH\_\-DECCTL\_\-SET\_\-GRANPOS}}
\index{TH_DECCTL_SET_GRANPOS@{TH\_\-DECCTL\_\-SET\_\-GRANPOS}!theoradec.h@{theoradec.h}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define TH\_\-DECCTL\_\-SET\_\-GRANPOS~(5)}\label{theoradec_8h_6c80846ad5cbcaa4718dc716664ec812}


Sets the granule position. 

Call this after a seek, before decoding the first frame, to ensure that the proper granule position is returned for all subsequent frames. If you track timestamps yourself and do not use the granule position returned by the decoder, then you need not call this function.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[\mbox{$\leftarrow$} {\em \_\-buf}]{\tt ogg\_\-int64\_\-t}: The granule position of the next frame. \end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em TH\_\-EFAULT}]{\em \_\-dec\_\-ctx\/} or {\em \_\-buf\/} is {\tt NULL}. \item[{\em TH\_\-EINVAL}]{\em \_\-buf\_\-sz\/} is not {\tt sizeof(ogg\_\-int64\_\-t)}, or the granule position is negative. \end{description}
\end{Desc}
\index{theoradec.h@{theoradec.h}!TH_DECCTL_SET_PPLEVEL@{TH\_\-DECCTL\_\-SET\_\-PPLEVEL}}
\index{TH_DECCTL_SET_PPLEVEL@{TH\_\-DECCTL\_\-SET\_\-PPLEVEL}!theoradec.h@{theoradec.h}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define TH\_\-DECCTL\_\-SET\_\-PPLEVEL~(3)}\label{theoradec_8h_72d56e667f939d0ebaa78ef7b786386f}


Sets the post-processing level. 

By default, post-processing is disabled.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[\mbox{$\leftarrow$} {\em \_\-buf}]int: The new post-processing level. 0 to disable; larger values use more CPU. \end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em TH\_\-EFAULT}]{\em \_\-dec\_\-ctx\/} or {\em \_\-buf\/} is {\tt NULL}. \item[{\em TH\_\-EINVAL}]{\em \_\-buf\_\-sz\/} is not {\tt sizeof(int)}, or the post-processing level is out of bounds. The maximum post-processing level may be implementation-specific, and can be obtained via \doxyref{TH\_\-DECCTL\_\-GET\_\-PPLEVEL\_\-MAX}{p.}{theoradec_8h_65bcee69b870122fb6632b69c3d3c1eb}. \item[{\em TH\_\-EIMPL}]Not supported by this implementation. \end{description}
\end{Desc}
\index{theoradec.h@{theoradec.h}!TH_DECCTL_SET_STRIPE_CB@{TH\_\-DECCTL\_\-SET\_\-STRIPE\_\-CB}}
\index{TH_DECCTL_SET_STRIPE_CB@{TH\_\-DECCTL\_\-SET\_\-STRIPE\_\-CB}!theoradec.h@{theoradec.h}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define TH\_\-DECCTL\_\-SET\_\-STRIPE\_\-CB~(7)}\label{theoradec_8h_4395ec9e75f08d00df4a83cb478d9f44}


Sets the striped decode callback function. 

If set, this function will be called as each piece of a frame is fully decoded in \doxyref{th\_\-decode\_\-packetin()}{p.}{group__decfuncs_ga1f3ee21bdb5bbde01315af07ba8d29e}. You can pass in a \doxyref{th\_\-stripe\_\-callback}{p.}{structth__stripe__callback} with \doxyref{th\_\-stripe\_\-callback::stripe\_\-decoded}{p.}{structth__stripe__callback_b523cc1ed9c812d2ceb40a9a07ae87b3} set to {\tt NULL} to disable the callbacks at any point. Enabling striped decode does not prevent you from calling \doxyref{th\_\-decode\_\-ycbcr\_\-out()}{p.}{group__decfuncs_gcc244f49a31ef7fab2fdfa06bf3525b0} after the frame is fully decoded.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[\mbox{$\leftarrow$} {\em \_\-buf}]\doxyref{th\_\-stripe\_\-callback}{p.}{structth__stripe__callback}: The callback parameters. \end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em TH\_\-EFAULT}]{\em \_\-dec\_\-ctx\/} or {\em \_\-buf\/} is {\tt NULL}. \item[{\em TH\_\-EINVAL}]{\em \_\-buf\_\-sz\/} is not {\tt sizeof(th\_\-stripe\_\-callback)}. \end{description}
\end{Desc}


\subsection{Typedef Documentation}
\index{theoradec.h@{theoradec.h}!th_setup_info@{th\_\-setup\_\-info}}
\index{th_setup_info@{th\_\-setup\_\-info}!theoradec.h@{theoradec.h}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}typedef struct {\bf th\_\-setup\_\-info} {\bf th\_\-setup\_\-info}}\label{theoradec_8h_3a168eee25f3d0e907a9d094ca344992}


Setup information. 

This contains auxiliary information (Huffman tables and quantization parameters) decoded from the setup header by \doxyref{th\_\-decode\_\-headerin()}{p.}{group__decfuncs_gb6616614374d049781bf883f995b43d8} to be passed to \doxyref{th\_\-decode\_\-alloc()}{p.}{group__decfuncs_g48da74f31b3d34387d14760a41c5da89}. It can be re-used to initialize any number of decoders, and can be freed via \doxyref{th\_\-setup\_\-free()}{p.}{group__decfuncs_gfc2356433984f842f1720c7c3433ba83} at any time. \index{theoradec.h@{theoradec.h}!th_stripe_decoded_func@{th\_\-stripe\_\-decoded\_\-func}}
\index{th_stripe_decoded_func@{th\_\-stripe\_\-decoded\_\-func}!theoradec.h@{theoradec.h}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}typedef void($\ast$) {\bf th\_\-stripe\_\-decoded\_\-func}(void $\ast$\_\-ctx, {\bf th\_\-ycbcr\_\-buffer} \_\-buf, int \_\-yfrag0, int \_\-yfrag\_\-end)}\label{theoradec_8h_0433da05ee2a3f447963e23c17540b61}


A callback function for striped decode. 

This is a function pointer to an application-provided function that will be called each time a section of the image is fully decoded in \doxyref{th\_\-decode\_\-packetin()}{p.}{group__decfuncs_ga1f3ee21bdb5bbde01315af07ba8d29e}. This allows the application to process the section immediately, while it is still in cache. Note that the frame is decoded bottom to top, so {\em \_\-yfrag0\/} will steadily decrease with each call until it reaches 0, at which point the full frame is decoded. The number of fragment rows made available in each call depends on the pixel format and the number of post-processing filters enabled, and may not even be constant for the entire frame. If a non-{\tt NULL} {\em \_\-granpos\/} pointer is passed to \doxyref{th\_\-decode\_\-packetin()}{p.}{group__decfuncs_ga1f3ee21bdb5bbde01315af07ba8d29e}, the granule position for the frame will be stored in it before the first callback is made. If an entire frame is dropped (a 0-byte packet), then no callbacks will be made at all for that frame. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em \_\-ctx}]An application-provided context pointer. \item[{\em \_\-buf}]The image buffer for the decoded frame. \item[{\em \_\-yfrag0}]The Y coordinate of the first row of 8x8 fragments decoded. Multiply this by 8 to obtain the pixel row number in the luma plane. If the chroma planes are subsampled in the Y direction, this will always be divisible by two. \item[{\em \_\-yfrag\_\-end}]The Y coordinate of the first row of 8x8 fragments past the newly decoded section. If the chroma planes are subsampled in the Y direction, this will always be divisible by two. I.e., this section contains fragment rows {\tt {\em \_\-yfrag0\/} ...{\em \_\-yfrag\_\-end\/} -1}. \end{description}
\end{Desc}
