\section{Functions for Decoding}
\label{group__decfuncs}\index{Functions for Decoding@{Functions for Decoding}}
\subsection*{Functions for decoding}
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}


\subsection{Function Documentation}
\index{decfuncs@{decfuncs}!th_decode_alloc@{th\_\-decode\_\-alloc}}
\index{th_decode_alloc@{th\_\-decode\_\-alloc}!decfuncs@{decfuncs}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf th\_\-dec\_\-ctx}$\ast$ th\_\-decode\_\-alloc (const {\bf th\_\-info} $\ast$ {\em \_\-info}, const {\bf th\_\-setup\_\-info} $\ast$ {\em \_\-setup})}\label{group__decfuncs_g48da74f31b3d34387d14760a41c5da89}


Allocates a decoder instance. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em \_\-info}]A \doxyref{th\_\-info}{p.}{structth__info} struct filled via \doxyref{th\_\-decode\_\-headerin()}{p.}{group__decfuncs_gb6616614374d049781bf883f995b43d8}. \item[{\em \_\-setup}]A \doxyref{th\_\-setup\_\-info}{p.}{theoradec_8h_3a168eee25f3d0e907a9d094ca344992} handle returned via \doxyref{th\_\-decode\_\-headerin()}{p.}{group__decfuncs_gb6616614374d049781bf883f995b43d8}. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The initialized \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_e57d28984ca7a50fa99faaff751e433f} handle. \end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em NULL}]If the decoding parameters were invalid. \end{description}
\end{Desc}
\index{decfuncs@{decfuncs}!th_decode_ctl@{th\_\-decode\_\-ctl}}
\index{th_decode_ctl@{th\_\-decode\_\-ctl}!decfuncs@{decfuncs}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int th\_\-decode\_\-ctl ({\bf th\_\-dec\_\-ctx} $\ast$ {\em \_\-dec}, int {\em \_\-req}, void $\ast$ {\em \_\-buf}, size\_\-t {\em \_\-buf\_\-sz})}\label{group__decfuncs_g7393610f40038a80dc1555e510c0b15f}


Decoder control function. 

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


Frees an allocated decoder instance. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em \_\-dec}]A \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_e57d28984ca7a50fa99faaff751e433f} handle. \end{description}
\end{Desc}
\index{decfuncs@{decfuncs}!th_decode_headerin@{th\_\-decode\_\-headerin}}
\index{th_decode_headerin@{th\_\-decode\_\-headerin}!decfuncs@{decfuncs}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int th\_\-decode\_\-headerin ({\bf th\_\-info} $\ast$ {\em \_\-info}, {\bf th\_\-comment} $\ast$ {\em \_\-tc}, {\bf th\_\-setup\_\-info} $\ast$$\ast$ {\em \_\-setup}, ogg\_\-packet $\ast$ {\em \_\-op})}\label{group__decfuncs_gb6616614374d049781bf883f995b43d8}


Decodes the header packets of a Theora stream. 

This should be called on the initial packets of the stream, in succession, until it returns {\tt 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{Desc}
\item[Parameters:]
\begin{description}
\item[{\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_g47dd4fd90382e1fcf11f27c8b8eeb860}. 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. \item[{\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. \item[{\em \_\-setup}]Returns a pointer to additional, private setup information needed by the decoder. The contents of this pointer must be initialized to {\tt NULL} on the first call, and the returned value must continue to be passed in on all subsequent calls. \item[{\em \_\-op}]An {\tt ogg\_\-packet} structure which contains one of the initial packets of an Ogg logical stream. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]A positive value indicates that a Theora header was successfully processed. \end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\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_ga1f3ee21bdb5bbde01315af07ba8d29e} to begin decoding video data. \item[{\em TH\_\-EFAULT}]One of {\em \_\-info\/}, {\em \_\-tc\/}, or {\em \_\-setup\/} was {\tt NULL}. \item[{\em TH\_\-EBADHEADER}]{\em \_\-op\/} was {\tt NULL}, the packet was not the next header packet in the expected sequence, or the format of the header data was invalid. \item[{\em TH\_\-EVERSION}]The packet data was a Theora info header, but for a bitstream version not decodable with this version of {\tt libtheoradec}. \item[{\em TH\_\-ENOTFORMAT}]The packet was not a Theora header. \end{description}
\end{Desc}
\index{decfuncs@{decfuncs}!th_decode_packetin@{th\_\-decode\_\-packetin}}
\index{th_decode_packetin@{th\_\-decode\_\-packetin}!decfuncs@{decfuncs}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int th\_\-decode\_\-packetin ({\bf th\_\-dec\_\-ctx} $\ast$ {\em \_\-dec}, const ogg\_\-packet $\ast$ {\em \_\-op}, ogg\_\-int64\_\-t $\ast$ {\em \_\-granpos})}\label{group__decfuncs_ga1f3ee21bdb5bbde01315af07ba8d29e}


Submits a packet containing encoded video data to the decoder. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em \_\-dec}]A \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_e57d28984ca7a50fa99faaff751e433f} handle. \item[{\em \_\-op}]An {\tt ogg\_\-packet} containing encoded video data. \item[{\em \_\-granpos}]Returns the granule position of the decoded packet. If non-{\tt NULL}, 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{TH\_\-DECCTL\_\-SET\_\-GRANPOS}{p.}{theoradec_8h_6c80846ad5cbcaa4718dc716664ec812} for this to work properly. \end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]Success. A new decoded frame can be retrieved by calling \doxyref{th\_\-decode\_\-ycbcr\_\-out()}{p.}{group__decfuncs_gcc244f49a31ef7fab2fdfa06bf3525b0}. \item[{\em TH\_\-DUPFRAME}]The packet represented a dropped (0-byte) frame. The player can skip the call to \doxyref{th\_\-decode\_\-ycbcr\_\-out()}{p.}{group__decfuncs_gcc244f49a31ef7fab2fdfa06bf3525b0}, as the contents of the decoded frame buffer have not changed. \item[{\em TH\_\-EFAULT}]{\em \_\-dec\/} or \_\-op was {\tt NULL}. \item[{\em TH\_\-EBADPACKET}]{\em \_\-op\/} does not contain encoded video data. \item[{\em TH\_\-EIMPL}]The video data uses bitstream features which this library does not support. \end{description}
\end{Desc}
\index{decfuncs@{decfuncs}!th_decode_ycbcr_out@{th\_\-decode\_\-ycbcr\_\-out}}
\index{th_decode_ycbcr_out@{th\_\-decode\_\-ycbcr\_\-out}!decfuncs@{decfuncs}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int th\_\-decode\_\-ycbcr\_\-out ({\bf th\_\-dec\_\-ctx} $\ast$ {\em \_\-dec}, {\bf th\_\-ycbcr\_\-buffer} {\em \_\-ycbcr})}\label{group__decfuncs_gcc244f49a31ef7fab2fdfa06bf3525b0}


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

If a striped decode callback has been set with \doxyref{TH\_\-DECCTL\_\-SET\_\-STRIPE\_\-CB}{p.}{theoradec_8h_4395ec9e75f08d00df4a83cb478d9f44}, then the application does not need to call this function. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em \_\-dec}]A \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_e57d28984ca7a50fa99faaff751e433f} handle. \item[{\em \_\-ycbcr}]A video buffer structure to fill in. {\tt 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 {\tt libtheoradec}. It may be freed or overwritten without notification when subsequent frames are decoded. \end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]Success \end{description}
\end{Desc}
\index{decfuncs@{decfuncs}!th_setup_free@{th\_\-setup\_\-free}}
\index{th_setup_free@{th\_\-setup\_\-free}!decfuncs@{decfuncs}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void th\_\-setup\_\-free ({\bf th\_\-setup\_\-info} $\ast$ {\em \_\-setup})}\label{group__decfuncs_gfc2356433984f842f1720c7c3433ba83}


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_gb6616614374d049781bf883f995b43d8}. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em \_\-setup}]The setup information to free. This can safely be {\tt NULL}. \end{description}
\end{Desc}
