Blob Blame History Raw
\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. \item\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. \item\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. \item\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. \item\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. \item\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'CbCr data. \item\end{DoxyCompactList}\item 
void {\bf th\_\-decode\_\-free} ({\bf th\_\-dec\_\-ctx} $\ast$\_\-dec)
\begin{DoxyCompactList}\small\item\em Frees an allocated decoder instance. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function Documentation}
\index{decfuncs@{decfuncs}!th\_\-decode\_\-alloc@{th\_\-decode\_\-alloc}}
\index{th\_\-decode\_\-alloc@{th\_\-decode\_\-alloc}!decfuncs@{decfuncs}}
\subsubsection[{th\_\-decode\_\-alloc}]{\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_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 OS 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}
\item[{\em \_\-info}]A \doxyref{th\_\-info}{p.}{structth__info} struct filled via \doxyref{th\_\-decode\_\-headerin()}{p.}{group__decfuncs_ga006d01d36fbe64768c571e6a12b7fc50}. \item[{\em \_\-setup}]A \doxyref{th\_\-setup\_\-info}{p.}{theoradec_8h_ab71cd2657455cc27d6c0127c66a89f28} handle returned via \doxyref{th\_\-decode\_\-headerin()}{p.}{group__decfuncs_ga006d01d36fbe64768c571e6a12b7fc50}. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
The initialized \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle. 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
\item[{\em NULL}]If the decoding parameters were invalid. \end{DoxyRetVals}
\index{decfuncs@{decfuncs}!th\_\-decode\_\-ctl@{th\_\-decode\_\-ctl}}
\index{th\_\-decode\_\-ctl@{th\_\-decode\_\-ctl}!decfuncs@{decfuncs}}
\subsubsection[{th\_\-decode\_\-ctl}]{\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_ga1a8051958d75b1012573b6e3c8f670e1}


Decoder control function. This is used to provide advanced control of the decoding process. 
\begin{DoxyParams}{Parameters}
\item[{\em \_\-dec}]A \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} 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{DoxyParams}
\index{decfuncs@{decfuncs}!th\_\-decode\_\-free@{th\_\-decode\_\-free}}
\index{th\_\-decode\_\-free@{th\_\-decode\_\-free}!decfuncs@{decfuncs}}
\subsubsection[{th\_\-decode\_\-free}]{\setlength{\rightskip}{0pt plus 5cm}void th\_\-decode\_\-free ({\bf th\_\-dec\_\-ctx} $\ast$ {\em \_\-dec})}\label{group__decfuncs_gafb6684ad8ba507b71112bc9de148e7d0}


Frees an allocated decoder instance. 
\begin{DoxyParams}{Parameters}
\item[{\em \_\-dec}]A \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle. \end{DoxyParams}
\index{decfuncs@{decfuncs}!th\_\-decode\_\-headerin@{th\_\-decode\_\-headerin}}
\index{th\_\-decode\_\-headerin@{th\_\-decode\_\-headerin}!decfuncs@{decfuncs}}
\subsubsection[{th\_\-decode\_\-headerin}]{\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_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}
\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_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. \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 {\ttfamily NULL} on the first call, and the returned value must continue to be passed in on all subsequent calls. \item[{\em \_\-op}]An {\ttfamily ogg\_\-packet} structure which contains one of the initial packets of an Ogg logical stream. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
A positive value indicates that a Theora header was successfully processed. 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
\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_ga31c814bf09b2232aff69c57ae20f04eb} to begin decoding video data. \item[{\em TH\_\-EFAULT}]One of {\itshape \_\-info\/}, {\itshape \_\-tc\/}, or {\itshape \_\-setup\/} was {\ttfamily NULL}. \item[{\em TH\_\-EBADHEADER}]{\itshape \_\-op\/} was {\ttfamily 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 {\ttfamily libtheoradec}. \item[{\em TH\_\-ENOTFORMAT}]The packet was not a Theora header. \end{DoxyRetVals}
\index{decfuncs@{decfuncs}!th\_\-decode\_\-packetin@{th\_\-decode\_\-packetin}}
\index{th\_\-decode\_\-packetin@{th\_\-decode\_\-packetin}!decfuncs@{decfuncs}}
\subsubsection[{th\_\-decode\_\-packetin}]{\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_ga31c814bf09b2232aff69c57ae20f04eb}


Submits a packet containing encoded video data to the decoder. 
\begin{DoxyParams}{Parameters}
\item[{\em \_\-dec}]A \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle. \item[{\em \_\-op}]An {\ttfamily ogg\_\-packet} containing encoded video data. \item[{\em \_\-granpos}]Returns the granule position of the decoded packet. If non-\/{\ttfamily 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_a1e870c654d35394f0d490045df04e0f5} for this to work properly. \end{DoxyParams}

\begin{DoxyRetVals}{Return values}
\item[{\em 0}]Success. A new decoded frame can be retrieved by calling \doxyref{th\_\-decode\_\-ycbcr\_\-out()}{p.}{group__decfuncs_gaa9cc8af63fa8540e0fc95572f259cdcb}. \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_gaa9cc8af63fa8540e0fc95572f259cdcb}, as the contents of the decoded frame buffer have not changed. \item[{\em TH\_\-EFAULT}]{\itshape \_\-dec\/} or {\itshape \_\-op\/} was {\ttfamily NULL}. \item[{\em TH\_\-EBADPACKET}]{\itshape \_\-op\/} does not contain encoded video data. \item[{\em TH\_\-EIMPL}]The video data uses bitstream features which this library does not support. \end{DoxyRetVals}
\index{decfuncs@{decfuncs}!th\_\-decode\_\-ycbcr\_\-out@{th\_\-decode\_\-ycbcr\_\-out}}
\index{th\_\-decode\_\-ycbcr\_\-out@{th\_\-decode\_\-ycbcr\_\-out}!decfuncs@{decfuncs}}
\subsubsection[{th\_\-decode\_\-ycbcr\_\-out}]{\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_gaa9cc8af63fa8540e0fc95572f259cdcb}


Outputs the next available frame of decoded Y'CbCr data. If a striped decode callback has been set with \doxyref{TH\_\-DECCTL\_\-SET\_\-STRIPE\_\-CB}{p.}{theoradec_8h_ac95cc9e109474b0fa4bb920ab2cfdf1e}, then the application does not need to call this function. 
\begin{DoxyParams}{Parameters}
\item[{\em \_\-dec}]A \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle. \item[{\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. \end{DoxyParams}

\begin{DoxyRetVals}{Return values}
\item[{\em 0}]Success \item[{\em TH\_\-EFAULT}]{\itshape \_\-dec\/} or {\itshape \_\-ycbcr\/} was {\ttfamily NULL}. \end{DoxyRetVals}
\index{decfuncs@{decfuncs}!th\_\-setup\_\-free@{th\_\-setup\_\-free}}
\index{th\_\-setup\_\-free@{th\_\-setup\_\-free}!decfuncs@{decfuncs}}
\subsubsection[{th\_\-setup\_\-free}]{\setlength{\rightskip}{0pt plus 5cm}void th\_\-setup\_\-free ({\bf th\_\-setup\_\-info} $\ast$ {\em \_\-setup})}\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}
\item[{\em \_\-setup}]The setup information to free. This can safely be {\ttfamily NULL}. \end{DoxyParams}