Blame doc/libtheora/latex/group__decfuncs.tex

Packit 00c01a
\section{Functions for Decoding}
Packit 00c01a
\label{group__decfuncs}\index{Functions for Decoding@{Functions for Decoding}}
Packit 00c01a
\subsection*{Functions for decoding}
Packit 00c01a
\label{_amgrp9d29c94aa62f20426aa5ff062c7daedd}
Packit 00c01a
You must link to {\ttfamily libtheoradec} if you use any of the functions in this section.
Packit 00c01a
Packit 00c01a
The functions are listed in the order they are used in a typical decode. The basic steps are:
Packit 00c01a
\begin{DoxyItemize}
Packit 00c01a
\item Parse the header packets by repeatedly calling \doxyref{th\_\-decode\_\-headerin()}{p.}{group__decfuncs_ga006d01d36fbe64768c571e6a12b7fc50}.
Packit 00c01a
\item Allocate a \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle with \doxyref{th\_\-decode\_\-alloc()}{p.}{group__decfuncs_ga0ef07a9a97849054aa606c595a2d807e}.
Packit 00c01a
\item Call \doxyref{th\_\-setup\_\-free()}{p.}{group__decfuncs_gadef55431b68aaa59d0d7b32b2f118f27} to free any memory used for codec setup information.
Packit 00c01a
\item Perform any additional decoder configuration with \doxyref{th\_\-decode\_\-ctl()}{p.}{group__decfuncs_ga1a8051958d75b1012573b6e3c8f670e1}.
Packit 00c01a
\item For each video data packet:
Packit 00c01a
\begin{DoxyItemize}
Packit 00c01a
\item Submit the packet to the decoder via \doxyref{th\_\-decode\_\-packetin()}{p.}{group__decfuncs_ga31c814bf09b2232aff69c57ae20f04eb}.
Packit 00c01a
\item Retrieve the uncompressed video data via \doxyref{th\_\-decode\_\-ycbcr\_\-out()}{p.}{group__decfuncs_gaa9cc8af63fa8540e0fc95572f259cdcb}.
Packit 00c01a
\end{DoxyItemize}
Packit 00c01a
\item Call \doxyref{th\_\-decode\_\-free()}{p.}{group__decfuncs_gafb6684ad8ba507b71112bc9de148e7d0} to release all decoder memory. 
Packit 00c01a
\end{DoxyItemize}\begin{DoxyCompactItemize}
Packit 00c01a
\item 
Packit 00c01a
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)
Packit 00c01a
\begin{DoxyCompactList}\small\item\em Decodes the header packets of a Theora stream. \item\end{DoxyCompactList}\item 
Packit 00c01a
{\bf th\_\-dec\_\-ctx} $\ast$ {\bf th\_\-decode\_\-alloc} (const {\bf th\_\-info} $\ast$\_\-info, const {\bf th\_\-setup\_\-info} $\ast$\_\-setup)
Packit 00c01a
\begin{DoxyCompactList}\small\item\em Allocates a decoder instance. \item\end{DoxyCompactList}\item 
Packit 00c01a
void {\bf th\_\-setup\_\-free} ({\bf th\_\-setup\_\-info} $\ast$\_\-setup)
Packit 00c01a
\begin{DoxyCompactList}\small\item\em Releases all storage used for the decoder setup information. \item\end{DoxyCompactList}\item 
Packit 00c01a
int {\bf th\_\-decode\_\-ctl} ({\bf th\_\-dec\_\-ctx} $\ast$\_\-dec, int \_\-req, void $\ast$\_\-buf, size\_\-t \_\-buf\_\-sz)
Packit 00c01a
\begin{DoxyCompactList}\small\item\em Decoder control function. \item\end{DoxyCompactList}\item 
Packit 00c01a
int {\bf th\_\-decode\_\-packetin} ({\bf th\_\-dec\_\-ctx} $\ast$\_\-dec, const ogg\_\-packet $\ast$\_\-op, ogg\_\-int64\_\-t $\ast$\_\-granpos)
Packit 00c01a
\begin{DoxyCompactList}\small\item\em Submits a packet containing encoded video data to the decoder. \item\end{DoxyCompactList}\item 
Packit 00c01a
int {\bf th\_\-decode\_\-ycbcr\_\-out} ({\bf th\_\-dec\_\-ctx} $\ast$\_\-dec, {\bf th\_\-ycbcr\_\-buffer} \_\-ycbcr)
Packit 00c01a
\begin{DoxyCompactList}\small\item\em Outputs the next available frame of decoded Y'CbCr data. \item\end{DoxyCompactList}\item 
Packit 00c01a
void {\bf th\_\-decode\_\-free} ({\bf th\_\-dec\_\-ctx} $\ast$\_\-dec)
Packit 00c01a
\begin{DoxyCompactList}\small\item\em Frees an allocated decoder instance. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
Packit 00c01a
Packit 00c01a
Packit 00c01a
\subsection{Function Documentation}
Packit 00c01a
\index{decfuncs@{decfuncs}!th\_\-decode\_\-alloc@{th\_\-decode\_\-alloc}}
Packit 00c01a
\index{th\_\-decode\_\-alloc@{th\_\-decode\_\-alloc}!decfuncs@{decfuncs}}
Packit 00c01a
\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}
Packit 00c01a
Packit 00c01a
Packit 00c01a
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. 
Packit 00c01a
\begin{DoxyParams}{Parameters}
Packit 00c01a
\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}
Packit 00c01a
\begin{DoxyReturn}{Returns}
Packit 00c01a
The initialized \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle. 
Packit 00c01a
\end{DoxyReturn}
Packit 00c01a
Packit 00c01a
\begin{DoxyRetVals}{Return values}
Packit 00c01a
\item[{\em NULL}]If the decoding parameters were invalid. \end{DoxyRetVals}
Packit 00c01a
\index{decfuncs@{decfuncs}!th\_\-decode\_\-ctl@{th\_\-decode\_\-ctl}}
Packit 00c01a
\index{th\_\-decode\_\-ctl@{th\_\-decode\_\-ctl}!decfuncs@{decfuncs}}
Packit 00c01a
\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}
Packit 00c01a
Packit 00c01a
Packit 00c01a
Decoder control function. This is used to provide advanced control of the decoding process. 
Packit 00c01a
\begin{DoxyParams}{Parameters}
Packit 00c01a
\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}
Packit 00c01a
\index{decfuncs@{decfuncs}!th\_\-decode\_\-free@{th\_\-decode\_\-free}}
Packit 00c01a
\index{th\_\-decode\_\-free@{th\_\-decode\_\-free}!decfuncs@{decfuncs}}
Packit 00c01a
\subsubsection[{th\_\-decode\_\-free}]{\setlength{\rightskip}{0pt plus 5cm}void th\_\-decode\_\-free ({\bf th\_\-dec\_\-ctx} $\ast$ {\em \_\-dec})}\label{group__decfuncs_gafb6684ad8ba507b71112bc9de148e7d0}
Packit 00c01a
Packit 00c01a
Packit 00c01a
Frees an allocated decoder instance. 
Packit 00c01a
\begin{DoxyParams}{Parameters}
Packit 00c01a
\item[{\em \_\-dec}]A \doxyref{th\_\-dec\_\-ctx}{p.}{theoradec_8h_a843d70bb02563885a8d54b9c1a781729} handle. \end{DoxyParams}
Packit 00c01a
\index{decfuncs@{decfuncs}!th\_\-decode\_\-headerin@{th\_\-decode\_\-headerin}}
Packit 00c01a
\index{th\_\-decode\_\-headerin@{th\_\-decode\_\-headerin}!decfuncs@{decfuncs}}
Packit 00c01a
\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}
Packit 00c01a
Packit 00c01a
Packit 00c01a
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. 
Packit 00c01a
\begin{DoxyParams}{Parameters}
Packit 00c01a
\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}
Packit 00c01a
\begin{DoxyReturn}{Returns}
Packit 00c01a
A positive value indicates that a Theora header was successfully processed. 
Packit 00c01a
\end{DoxyReturn}
Packit 00c01a
Packit 00c01a
\begin{DoxyRetVals}{Return values}
Packit 00c01a
\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}
Packit 00c01a
\index{decfuncs@{decfuncs}!th\_\-decode\_\-packetin@{th\_\-decode\_\-packetin}}
Packit 00c01a
\index{th\_\-decode\_\-packetin@{th\_\-decode\_\-packetin}!decfuncs@{decfuncs}}
Packit 00c01a
\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}
Packit 00c01a
Packit 00c01a
Packit 00c01a
Submits a packet containing encoded video data to the decoder. 
Packit 00c01a
\begin{DoxyParams}{Parameters}
Packit 00c01a
\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}
Packit 00c01a
Packit 00c01a
\begin{DoxyRetVals}{Return values}
Packit 00c01a
\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}
Packit 00c01a
\index{decfuncs@{decfuncs}!th\_\-decode\_\-ycbcr\_\-out@{th\_\-decode\_\-ycbcr\_\-out}}
Packit 00c01a
\index{th\_\-decode\_\-ycbcr\_\-out@{th\_\-decode\_\-ycbcr\_\-out}!decfuncs@{decfuncs}}
Packit 00c01a
\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}
Packit 00c01a
Packit 00c01a
Packit 00c01a
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. 
Packit 00c01a
\begin{DoxyParams}{Parameters}
Packit 00c01a
\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}
Packit 00c01a
Packit 00c01a
\begin{DoxyRetVals}{Return values}
Packit 00c01a
\item[{\em 0}]Success \item[{\em TH\_\-EFAULT}]{\itshape \_\-dec\/} or {\itshape \_\-ycbcr\/} was {\ttfamily NULL}. \end{DoxyRetVals}
Packit 00c01a
\index{decfuncs@{decfuncs}!th\_\-setup\_\-free@{th\_\-setup\_\-free}}
Packit 00c01a
\index{th\_\-setup\_\-free@{th\_\-setup\_\-free}!decfuncs@{decfuncs}}
Packit 00c01a
\subsubsection[{th\_\-setup\_\-free}]{\setlength{\rightskip}{0pt plus 5cm}void th\_\-setup\_\-free ({\bf th\_\-setup\_\-info} $\ast$ {\em \_\-setup})}\label{group__decfuncs_gadef55431b68aaa59d0d7b32b2f118f27}
Packit 00c01a
Packit 00c01a
Packit 00c01a
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}. 
Packit 00c01a
\begin{DoxyParams}{Parameters}
Packit 00c01a
\item[{\em \_\-setup}]The setup information to free. This can safely be {\ttfamily NULL}. \end{DoxyParams}