\section{Functions for Decoding}
\label{group__decfuncs}\index{Functions for Decoding@{Functions for Decoding}}
\subsection*{Functions for decoding}
\label{_amgrp9d29c94aa62f20426aa5ff062c7daedd}%
You must link to {\ttfamily 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{DoxyItemize}
\item Parse the header packets by repeatedly calling \doxyref{th\-\_\-decode\-\_\-headerin()}{p.}{group__decfuncs_ga006d01d36fbe64768c571e6a12b7fc50}.
\item Allocate a \doxyref{th\-\_\-dec\-\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle with \doxyref{th\-\_\-decode\-\_\-alloc()}{p.}{group__decfuncs_ga0ef07a9a97849054aa606c595a2d807e}.
\item Call \doxyref{th\-\_\-setup\-\_\-free()}{p.}{group__decfuncs_gadef55431b68aaa59d0d7b32b2f118f27} to free any memory used for codec setup information.
\item Perform any additional decoder configuration with \doxyref{th\-\_\-decode\-\_\-ctl()}{p.}{group__decfuncs_ga1a8051958d75b1012573b6e3c8f670e1}.
\item For each video data packet\-:
\begin{DoxyItemize}
\item Submit the packet to the decoder via \doxyref{th\-\_\-decode\-\_\-packetin()}{p.}{group__decfuncs_ga31c814bf09b2232aff69c57ae20f04eb}.
\item Retrieve the uncompressed video data via \doxyref{th\-\_\-decode\-\_\-ycbcr\-\_\-out()}{p.}{group__decfuncs_gaa9cc8af63fa8540e0fc95572f259cdcb}.
\end{DoxyItemize}
\item Call \doxyref{th\-\_\-decode\-\_\-free()}{p.}{group__decfuncs_gafb6684ad8ba507b71112bc9de148e7d0} to release all decoder memory. 
\end{DoxyItemize}\begin{DoxyCompactItemize}
\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{DoxyCompactList}\small\item\em Decodes the header packets of a Theora stream. \end{DoxyCompactList}\item 
{\bf th\-\_\-dec\-\_\-ctx} $\ast$ {\bf th\-\_\-decode\-\_\-alloc} (const {\bf th\-\_\-info} $\ast$\-\_\-info, const {\bf th\-\_\-setup\-\_\-info} $\ast$\-\_\-setup)
\begin{DoxyCompactList}\small\item\em Allocates a decoder instance. \end{DoxyCompactList}\item 
void {\bf th\-\_\-setup\-\_\-free} ({\bf th\-\_\-setup\-\_\-info} $\ast$\-\_\-setup)
\begin{DoxyCompactList}\small\item\em Releases all storage used for the decoder setup information. \end{DoxyCompactList}\item 
int {\bf th\-\_\-decode\-\_\-ctl} ({\bf th\-\_\-dec\-\_\-ctx} $\ast$\-\_\-dec, int \-\_\-req, void $\ast$\-\_\-buf, size\-\_\-t \-\_\-buf\-\_\-sz)
\begin{DoxyCompactList}\small\item\em Decoder control function. \end{DoxyCompactList}\item 
int {\bf th\-\_\-decode\-\_\-packetin} ({\bf th\-\_\-dec\-\_\-ctx} $\ast$\-\_\-dec, const ogg\-\_\-packet $\ast$\-\_\-op, ogg\-\_\-int64\-\_\-t $\ast$\-\_\-granpos)
\begin{DoxyCompactList}\small\item\em Submits a packet containing encoded video data to the decoder. \end{DoxyCompactList}\item 
int {\bf th\-\_\-decode\-\_\-ycbcr\-\_\-out} ({\bf th\-\_\-dec\-\_\-ctx} $\ast$\-\_\-dec, {\bf th\-\_\-ycbcr\-\_\-buffer} \-\_\-ycbcr)
\begin{DoxyCompactList}\small\item\em Outputs the next available frame of decoded Y'Cb\-Cr data. \end{DoxyCompactList}\item 
void {\bf th\-\_\-decode\-\_\-free} ({\bf th\-\_\-dec\-\_\-ctx} $\ast$\-\_\-dec)
\begin{DoxyCompactList}\small\item\em Frees an allocated decoder instance. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}


\subsection{Function Documentation}
\index{Functions for Decoding@{Functions for Decoding}!th\-\_\-decode\-\_\-alloc@{th\-\_\-decode\-\_\-alloc}}
\index{th\-\_\-decode\-\_\-alloc@{th\-\_\-decode\-\_\-alloc}!Functions for Decoding@{Functions for Decoding}}
\subsubsection[{th\-\_\-decode\-\_\-alloc}]{\setlength{\rightskip}{0pt plus 5cm}{\bf th\-\_\-dec\-\_\-ctx}$\ast$ th\-\_\-decode\-\_\-alloc (
\begin{DoxyParamCaption}
\item[{const {\bf th\-\_\-info} $\ast$}]{\-\_\-info, }
\item[{const {\bf th\-\_\-setup\-\_\-info} $\ast$}]{\-\_\-setup}
\end{DoxyParamCaption}
)}\label{group__decfuncs_ga0ef07a9a97849054aa606c595a2d807e}


Allocates a decoder instance. 

{\bfseries Security Warning\-:} The Theora format supports very large frame sizes, potentially even larger than the address space of a 32-\/bit machine, and creating a decoder context allocates the space for several frames of data. If the allocation fails here, your program will crash, possibly at some future point because the O\-S kernel returned a valid memory range and will only fail when it tries to map the pages in it the first time they are used. Even if it succeeds, you may experience a denial of service if the frame size is large enough to cause excessive paging. If you are integrating libtheora in a larger application where such things are undesirable, it is highly recommended that you check the frame size in {\itshape \-\_\-info} before calling this function and refuse to decode streams where it is larger than some reasonable maximum. libtheora will not check this for you, because there may be machines that can handle such streams and applications that wish to. 
\begin{DoxyParams}{Parameters}
{\em \-\_\-info} & A \doxyref{th\-\_\-info}{p.}{structth__info} struct filled via \doxyref{th\-\_\-decode\-\_\-headerin()}{p.}{group__decfuncs_ga006d01d36fbe64768c571e6a12b7fc50}. \\
\hline
{\em \-\_\-setup} & A \doxyref{th\-\_\-setup\-\_\-info}{p.}{theoradec_8h_ab71cd2657455cc27d6c0127c66a89f28} handle returned via \doxyref{th\-\_\-decode\-\_\-headerin()}{p.}{group__decfuncs_ga006d01d36fbe64768c571e6a12b7fc50}. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The initialized \doxyref{th\-\_\-dec\-\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle. 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em N\-U\-L\-L} & If the decoding parameters were invalid. \\
\hline
\end{DoxyRetVals}
\index{Functions for Decoding@{Functions for Decoding}!th\-\_\-decode\-\_\-ctl@{th\-\_\-decode\-\_\-ctl}}
\index{th\-\_\-decode\-\_\-ctl@{th\-\_\-decode\-\_\-ctl}!Functions for Decoding@{Functions for Decoding}}
\subsubsection[{th\-\_\-decode\-\_\-ctl}]{\setlength{\rightskip}{0pt plus 5cm}int th\-\_\-decode\-\_\-ctl (
\begin{DoxyParamCaption}
\item[{{\bf th\-\_\-dec\-\_\-ctx} $\ast$}]{\-\_\-dec, }
\item[{int}]{\-\_\-req, }
\item[{void $\ast$}]{\-\_\-buf, }
\item[{size\-\_\-t}]{\-\_\-buf\-\_\-sz}
\end{DoxyParamCaption}
)}\label{group__decfuncs_ga1a8051958d75b1012573b6e3c8f670e1}


Decoder control function. 

This is used to provide advanced control of the decoding process. 
\begin{DoxyParams}{Parameters}
{\em \-\_\-dec} & A \doxyref{th\-\_\-dec\-\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle. \\
\hline
{\em \-\_\-req} & The control code to process. See \doxyref{the list of available control codes}{p.}{theoradec_8h_decctlcodes} for details. \\
\hline
{\em \-\_\-buf} & The parameters for this control code. \\
\hline
{\em \-\_\-buf\-\_\-sz} & The size of the parameter buffer. \\
\hline
\end{DoxyParams}
\index{Functions for Decoding@{Functions for Decoding}!th\-\_\-decode\-\_\-free@{th\-\_\-decode\-\_\-free}}
\index{th\-\_\-decode\-\_\-free@{th\-\_\-decode\-\_\-free}!Functions for Decoding@{Functions for Decoding}}
\subsubsection[{th\-\_\-decode\-\_\-free}]{\setlength{\rightskip}{0pt plus 5cm}void th\-\_\-decode\-\_\-free (
\begin{DoxyParamCaption}
\item[{{\bf th\-\_\-dec\-\_\-ctx} $\ast$}]{\-\_\-dec}
\end{DoxyParamCaption}
)}\label{group__decfuncs_gafb6684ad8ba507b71112bc9de148e7d0}


Frees an allocated decoder instance. 


\begin{DoxyParams}{Parameters}
{\em \-\_\-dec} & A \doxyref{th\-\_\-dec\-\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle. \\
\hline
\end{DoxyParams}
\index{Functions for Decoding@{Functions for Decoding}!th\-\_\-decode\-\_\-headerin@{th\-\_\-decode\-\_\-headerin}}
\index{th\-\_\-decode\-\_\-headerin@{th\-\_\-decode\-\_\-headerin}!Functions for Decoding@{Functions for Decoding}}
\subsubsection[{th\-\_\-decode\-\_\-headerin}]{\setlength{\rightskip}{0pt plus 5cm}int th\-\_\-decode\-\_\-headerin (
\begin{DoxyParamCaption}
\item[{{\bf th\-\_\-info} $\ast$}]{\-\_\-info, }
\item[{{\bf th\-\_\-comment} $\ast$}]{\-\_\-tc, }
\item[{{\bf th\-\_\-setup\-\_\-info} $\ast$$\ast$}]{\-\_\-setup, }
\item[{ogg\-\_\-packet $\ast$}]{\-\_\-op}
\end{DoxyParamCaption}
)}\label{group__decfuncs_ga006d01d36fbe64768c571e6a12b7fc50}


Decodes the header packets of a Theora stream. 

This should be called on the initial packets of the stream, in succession, until it returns {\ttfamily 0}, indicating that all headers have been processed, or an error is encountered. At least three header packets are required, and additional optional header packets may follow. This can be used on the first packet of any logical stream to determine if that stream is a Theora stream. 
\begin{DoxyParams}{Parameters}
{\em \-\_\-info} & A \doxyref{th\-\_\-info}{p.}{structth__info} structure to fill in. This must have been previously initialized with \doxyref{th\-\_\-info\-\_\-init()}{p.}{group__basefuncs_ga430d9c605816a6ca0bdce3a0b965b926}. The application may immediately begin using the contents of this structure after the first header is decoded, though it must continue to be passed in on all subsequent calls. \\
\hline
{\em \-\_\-tc} & A \doxyref{th\-\_\-comment}{p.}{structth__comment} structure to fill in. The application may immediately begin using the contents of this structure after the second header is decoded, though it must continue to be passed in on all subsequent calls. \\
\hline
{\em \-\_\-setup} & Returns a pointer to additional, private setup information needed by the decoder. The contents of this pointer must be initialized to {\ttfamily N\-U\-L\-L} on the first call, and the returned value must continue to be passed in on all subsequent calls. \\
\hline
{\em \-\_\-op} & An {\ttfamily ogg\-\_\-packet} structure which contains one of the initial packets of an Ogg logical stream. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A positive value indicates that a Theora header was successfully processed. 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & The first video data packet was encountered after all required header packets were parsed. The packet just passed in on this call should be saved and fed to \doxyref{th\-\_\-decode\-\_\-packetin()}{p.}{group__decfuncs_ga31c814bf09b2232aff69c57ae20f04eb} to begin decoding video data. \\
\hline
{\em T\-H\-\_\-\-E\-F\-A\-U\-L\-T} & One of {\itshape \-\_\-info}, {\itshape \-\_\-tc}, or {\itshape \-\_\-setup} was {\ttfamily N\-U\-L\-L}. \\
\hline
{\em T\-H\-\_\-\-E\-B\-A\-D\-H\-E\-A\-D\-E\-R} & {\itshape \-\_\-op} was {\ttfamily N\-U\-L\-L}, the packet was not the next header packet in the expected sequence, or the format of the header data was invalid. \\
\hline
{\em T\-H\-\_\-\-E\-V\-E\-R\-S\-I\-O\-N} & The packet data was a Theora info header, but for a bitstream version not decodable with this version of {\ttfamily libtheoradec}. \\
\hline
{\em T\-H\-\_\-\-E\-N\-O\-T\-F\-O\-R\-M\-A\-T} & The packet was not a Theora header. \\
\hline
\end{DoxyRetVals}
\index{Functions for Decoding@{Functions for Decoding}!th\-\_\-decode\-\_\-packetin@{th\-\_\-decode\-\_\-packetin}}
\index{th\-\_\-decode\-\_\-packetin@{th\-\_\-decode\-\_\-packetin}!Functions for Decoding@{Functions for Decoding}}
\subsubsection[{th\-\_\-decode\-\_\-packetin}]{\setlength{\rightskip}{0pt plus 5cm}int th\-\_\-decode\-\_\-packetin (
\begin{DoxyParamCaption}
\item[{{\bf th\-\_\-dec\-\_\-ctx} $\ast$}]{\-\_\-dec, }
\item[{const ogg\-\_\-packet $\ast$}]{\-\_\-op, }
\item[{ogg\-\_\-int64\-\_\-t $\ast$}]{\-\_\-granpos}
\end{DoxyParamCaption}
)}\label{group__decfuncs_ga31c814bf09b2232aff69c57ae20f04eb}


Submits a packet containing encoded video data to the decoder. 


\begin{DoxyParams}{Parameters}
{\em \-\_\-dec} & A \doxyref{th\-\_\-dec\-\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle. \\
\hline
{\em \-\_\-op} & An {\ttfamily ogg\-\_\-packet} containing encoded video data. \\
\hline
{\em \-\_\-granpos} & Returns the granule position of the decoded packet. If non-\/{\ttfamily N\-U\-L\-L}, the granule position for this specific packet is stored in this location. This is computed incrementally from previously decoded packets. After a seek, the correct granule position must be set via \doxyref{T\-H\-\_\-\-D\-E\-C\-C\-T\-L\-\_\-\-S\-E\-T\-\_\-\-G\-R\-A\-N\-P\-O\-S}{p.}{theoradec_8h_a1e870c654d35394f0d490045df04e0f5} for this to work properly. \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 0} & Success. A new decoded frame can be retrieved by calling \doxyref{th\-\_\-decode\-\_\-ycbcr\-\_\-out()}{p.}{group__decfuncs_gaa9cc8af63fa8540e0fc95572f259cdcb}. \\
\hline
{\em T\-H\-\_\-\-D\-U\-P\-F\-R\-A\-M\-E} & The packet represented a dropped (0-\/byte) frame. The player can skip the call to \doxyref{th\-\_\-decode\-\_\-ycbcr\-\_\-out()}{p.}{group__decfuncs_gaa9cc8af63fa8540e0fc95572f259cdcb}, as the contents of the decoded frame buffer have not changed. \\
\hline
{\em T\-H\-\_\-\-E\-F\-A\-U\-L\-T} & {\itshape \-\_\-dec} or {\itshape \-\_\-op} was {\ttfamily N\-U\-L\-L}. \\
\hline
{\em T\-H\-\_\-\-E\-B\-A\-D\-P\-A\-C\-K\-E\-T} & {\itshape \-\_\-op} does not contain encoded video data. \\
\hline
{\em T\-H\-\_\-\-E\-I\-M\-P\-L} & The video data uses bitstream features which this library does not support. \\
\hline
\end{DoxyRetVals}
\index{Functions for Decoding@{Functions for Decoding}!th\-\_\-decode\-\_\-ycbcr\-\_\-out@{th\-\_\-decode\-\_\-ycbcr\-\_\-out}}
\index{th\-\_\-decode\-\_\-ycbcr\-\_\-out@{th\-\_\-decode\-\_\-ycbcr\-\_\-out}!Functions for Decoding@{Functions for Decoding}}
\subsubsection[{th\-\_\-decode\-\_\-ycbcr\-\_\-out}]{\setlength{\rightskip}{0pt plus 5cm}int th\-\_\-decode\-\_\-ycbcr\-\_\-out (
\begin{DoxyParamCaption}
\item[{{\bf th\-\_\-dec\-\_\-ctx} $\ast$}]{\-\_\-dec, }
\item[{{\bf th\-\_\-ycbcr\-\_\-buffer}}]{\-\_\-ycbcr}
\end{DoxyParamCaption}
)}\label{group__decfuncs_gaa9cc8af63fa8540e0fc95572f259cdcb}


Outputs the next available frame of decoded Y'Cb\-Cr data. 

If a striped decode callback has been set with \doxyref{T\-H\-\_\-\-D\-E\-C\-C\-T\-L\-\_\-\-S\-E\-T\-\_\-\-S\-T\-R\-I\-P\-E\-\_\-\-C\-B}{p.}{theoradec_8h_ac95cc9e109474b0fa4bb920ab2cfdf1e}, then the application does not need to call this function. 
\begin{DoxyParams}{Parameters}
{\em \-\_\-dec} & A \doxyref{th\-\_\-dec\-\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle. \\
\hline
{\em \-\_\-ycbcr} & A video buffer structure to fill in. {\ttfamily libtheoradec} will fill in all the members of this structure, including the pointers to the uncompressed video data. The memory for this video data is owned by {\ttfamily libtheoradec}. It may be freed or overwritten without notification when subsequent frames are decoded. \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 0} & Success \\
\hline
{\em T\-H\-\_\-\-E\-F\-A\-U\-L\-T} & {\itshape \-\_\-dec} or {\itshape \-\_\-ycbcr} was {\ttfamily N\-U\-L\-L}. \\
\hline
\end{DoxyRetVals}
\index{Functions for Decoding@{Functions for Decoding}!th\-\_\-setup\-\_\-free@{th\-\_\-setup\-\_\-free}}
\index{th\-\_\-setup\-\_\-free@{th\-\_\-setup\-\_\-free}!Functions for Decoding@{Functions for Decoding}}
\subsubsection[{th\-\_\-setup\-\_\-free}]{\setlength{\rightskip}{0pt plus 5cm}void th\-\_\-setup\-\_\-free (
\begin{DoxyParamCaption}
\item[{{\bf th\-\_\-setup\-\_\-info} $\ast$}]{\-\_\-setup}
\end{DoxyParamCaption}
)}\label{group__decfuncs_gadef55431b68aaa59d0d7b32b2f118f27}


Releases all storage used for the decoder setup information. 

This should be called after you no longer want to create any decoders for a stream whose headers you have parsed with \doxyref{th\-\_\-decode\-\_\-headerin()}{p.}{group__decfuncs_ga006d01d36fbe64768c571e6a12b7fc50}. 
\begin{DoxyParams}{Parameters}
{\em \-\_\-setup} & The setup information to free. This can safely be {\ttfamily N\-U\-L\-L}. \\
\hline
\end{DoxyParams}
