theora_8h.tex 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. \section{theora.h File Reference}
  2. \label{theora_8h}\index{theora.h@{theora.h}}
  3. The libtheora pre-\/1.0 legacy C API.
  4. {\ttfamily \#include $<$stddef.h$>$}\par
  5. {\ttfamily \#include $<$ogg/ogg.h$>$}\par
  6. \subsection*{Data Structures}
  7. \begin{DoxyCompactItemize}
  8. \item
  9. struct {\bf yuv\_\-buffer}
  10. \begin{DoxyCompactList}\small\item\em A YUV buffer for passing uncompressed frames to and from the codec. \item\end{DoxyCompactList}\item
  11. struct {\bf theora\_\-info}
  12. \begin{DoxyCompactList}\small\item\em Theora bitstream info. \item\end{DoxyCompactList}\item
  13. struct {\bf theora\_\-state}
  14. \begin{DoxyCompactList}\small\item\em Codec internal state and context. \item\end{DoxyCompactList}\item
  15. struct {\bf theora\_\-comment}
  16. \begin{DoxyCompactList}\small\item\em Comment header metadata. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
  17. \subsection*{Defines}
  18. \begin{DoxyCompactItemize}
  19. \item
  20. \#define {\bf OC\_\-FAULT}~-\/1
  21. \begin{DoxyCompactList}\small\item\em General failure. \item\end{DoxyCompactList}\item
  22. \#define {\bf OC\_\-EINVAL}~-\/10
  23. \begin{DoxyCompactList}\small\item\em Library encountered invalid internal data. \item\end{DoxyCompactList}\item
  24. \#define {\bf OC\_\-DISABLED}~-\/11
  25. \begin{DoxyCompactList}\small\item\em Requested action is disabled. \item\end{DoxyCompactList}\item
  26. \#define {\bf OC\_\-BADHEADER}~-\/20
  27. \begin{DoxyCompactList}\small\item\em Header packet was corrupt/invalid. \item\end{DoxyCompactList}\item
  28. \#define {\bf OC\_\-NOTFORMAT}~-\/21
  29. \begin{DoxyCompactList}\small\item\em Packet is not a theora packet. \item\end{DoxyCompactList}\item
  30. \#define {\bf OC\_\-VERSION}~-\/22
  31. \begin{DoxyCompactList}\small\item\em Bitstream version is not handled. \item\end{DoxyCompactList}\item
  32. \#define {\bf OC\_\-IMPL}~-\/23
  33. \begin{DoxyCompactList}\small\item\em Feature or action not implemented. \item\end{DoxyCompactList}\item
  34. \#define {\bf OC\_\-BADPACKET}~-\/24
  35. \begin{DoxyCompactList}\small\item\em Packet is corrupt. \item\end{DoxyCompactList}\item
  36. \#define {\bf OC\_\-NEWPACKET}~-\/25
  37. \begin{DoxyCompactList}\small\item\em Packet is an (ignorable) unhandled extension. \item\end{DoxyCompactList}\item
  38. \#define {\bf OC\_\-DUPFRAME}~1
  39. \begin{DoxyCompactList}\small\item\em Packet is a dropped frame. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
  40. \begin{Indent}{\bf theora\_\-control() codes}\par
  41. {\em \label{_amgrp13fd61986cff4566fe89a40e30b74ad9}
  42. }\begin{DoxyCompactItemize}
  43. \item
  44. \#define {\bf TH\_\-DECCTL\_\-GET\_\-PPLEVEL\_\-MAX}~(1)
  45. \begin{DoxyCompactList}\small\item\em Get the maximum post-\/processing level. \item\end{DoxyCompactList}\item
  46. \#define {\bf TH\_\-DECCTL\_\-SET\_\-PPLEVEL}~(3)
  47. \begin{DoxyCompactList}\small\item\em Set the post-\/processing level. \item\end{DoxyCompactList}\item
  48. \#define {\bf TH\_\-ENCCTL\_\-SET\_\-KEYFRAME\_\-FREQUENCY\_\-FORCE}~(4)
  49. \begin{DoxyCompactList}\small\item\em Sets the maximum distance between key frames. \item\end{DoxyCompactList}\item
  50. \#define {\bf TH\_\-DECCTL\_\-SET\_\-GRANPOS}~(5)
  51. \begin{DoxyCompactList}\small\item\em Set the granule position. \item\end{DoxyCompactList}\item
  52. \#define {\bf TH\_\-ENCCTL\_\-SET\_\-QUANT\_\-PARAMS}~(2)
  53. \begin{DoxyCompactList}\small\item\em Sets the quantization parameters to use. \item\end{DoxyCompactList}\item
  54. \#define {\bf TH\_\-ENCCTL\_\-SET\_\-VP3\_\-COMPATIBLE}~(10)
  55. \begin{DoxyCompactList}\small\item\em Disables any encoder features that would prevent lossless transcoding back to VP3. \item\end{DoxyCompactList}\item
  56. \#define {\bf TH\_\-ENCCTL\_\-GET\_\-SPLEVEL\_\-MAX}~(12)
  57. \begin{DoxyCompactList}\small\item\em Gets the maximum speed level. \item\end{DoxyCompactList}\item
  58. \#define {\bf TH\_\-ENCCTL\_\-SET\_\-SPLEVEL}~(14)
  59. \begin{DoxyCompactList}\small\item\em Sets the speed level. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
  60. \end{Indent}
  61. \subsection*{Enumerations}
  62. \begin{DoxyCompactItemize}
  63. \item
  64. enum {\bf theora\_\-colorspace} \{ {\bf OC\_\-CS\_\-UNSPECIFIED},
  65. {\bf OC\_\-CS\_\-ITU\_\-REC\_\-470M},
  66. {\bf OC\_\-CS\_\-ITU\_\-REC\_\-470BG},
  67. {\bf OC\_\-CS\_\-NSPACES}
  68. \}
  69. \begin{DoxyCompactList}\small\item\em A Colorspace. \item\end{DoxyCompactList}\item
  70. enum {\bf theora\_\-pixelformat} \{ {\bf OC\_\-PF\_\-420},
  71. {\bf OC\_\-PF\_\-RSVD},
  72. {\bf OC\_\-PF\_\-422},
  73. {\bf OC\_\-PF\_\-444}
  74. \}
  75. \begin{DoxyCompactList}\small\item\em A Chroma subsampling. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
  76. \subsection*{Functions}
  77. \begin{DoxyCompactItemize}
  78. \item
  79. const char $\ast$ {\bf theora\_\-version\_\-string} (void)
  80. \begin{DoxyCompactList}\small\item\em Retrieve a human-\/readable string to identify the encoder vendor and version. \item\end{DoxyCompactList}\item
  81. ogg\_\-uint32\_\-t {\bf theora\_\-version\_\-number} (void)
  82. \begin{DoxyCompactList}\small\item\em Retrieve a 32-\/bit version number. \item\end{DoxyCompactList}\item
  83. int {\bf theora\_\-encode\_\-init} ({\bf theora\_\-state} $\ast$th, {\bf theora\_\-info} $\ast$ti)
  84. \begin{DoxyCompactList}\small\item\em Initialize the theora encoder. \item\end{DoxyCompactList}\item
  85. int {\bf theora\_\-encode\_\-YUVin} ({\bf theora\_\-state} $\ast$t, {\bf yuv\_\-buffer} $\ast$yuv)
  86. \begin{DoxyCompactList}\small\item\em Submit a YUV buffer to the theora encoder. \item\end{DoxyCompactList}\item
  87. int {\bf theora\_\-encode\_\-packetout} ({\bf theora\_\-state} $\ast$t, int last\_\-p, ogg\_\-packet $\ast$op)
  88. \begin{DoxyCompactList}\small\item\em Request the next packet of encoded video. \item\end{DoxyCompactList}\item
  89. int {\bf theora\_\-encode\_\-header} ({\bf theora\_\-state} $\ast$t, ogg\_\-packet $\ast$op)
  90. \begin{DoxyCompactList}\small\item\em Request a packet containing the initial header. \item\end{DoxyCompactList}\item
  91. int {\bf theora\_\-encode\_\-comment} ({\bf theora\_\-comment} $\ast$tc, ogg\_\-packet $\ast$op)
  92. \begin{DoxyCompactList}\small\item\em Request a comment header packet from provided metadata. \item\end{DoxyCompactList}\item
  93. int {\bf theora\_\-encode\_\-tables} ({\bf theora\_\-state} $\ast$t, ogg\_\-packet $\ast$op)
  94. \begin{DoxyCompactList}\small\item\em Request a packet containing the codebook tables for the stream. \item\end{DoxyCompactList}\item
  95. int {\bf theora\_\-decode\_\-header} ({\bf theora\_\-info} $\ast$ci, {\bf theora\_\-comment} $\ast$cc, ogg\_\-packet $\ast$op)
  96. \begin{DoxyCompactList}\small\item\em Decode an Ogg packet, with the expectation that the packet contains an initial header, comment data or codebook tables. \item\end{DoxyCompactList}\item
  97. int {\bf theora\_\-decode\_\-init} ({\bf theora\_\-state} $\ast$th, {\bf theora\_\-info} $\ast$c)
  98. \begin{DoxyCompactList}\small\item\em Initialize a \doxyref{theora\_\-state}{p.}{structtheora__state} handle for decoding. \item\end{DoxyCompactList}\item
  99. int {\bf theora\_\-decode\_\-packetin} ({\bf theora\_\-state} $\ast$th, ogg\_\-packet $\ast$op)
  100. \begin{DoxyCompactList}\small\item\em Input a packet containing encoded data into the theora decoder. \item\end{DoxyCompactList}\item
  101. int {\bf theora\_\-decode\_\-YUVout} ({\bf theora\_\-state} $\ast$th, {\bf yuv\_\-buffer} $\ast$yuv)
  102. \begin{DoxyCompactList}\small\item\em Output the next available frame of decoded YUV data. \item\end{DoxyCompactList}\item
  103. int {\bf theora\_\-packet\_\-isheader} (ogg\_\-packet $\ast$op)
  104. \begin{DoxyCompactList}\small\item\em Report whether a theora packet is a header or not This function does no verification beyond checking the header flag bit so it should not be used for bitstream identification; use \doxyref{theora\_\-decode\_\-header()}{p.}{group__oldfuncs_ga02915e63c1bd733ee291f577a8b75a82} for that. \item\end{DoxyCompactList}\item
  105. int {\bf theora\_\-packet\_\-iskeyframe} (ogg\_\-packet $\ast$op)
  106. \begin{DoxyCompactList}\small\item\em Report whether a theora packet is a keyframe or not. \item\end{DoxyCompactList}\item
  107. int {\bf theora\_\-granule\_\-shift} ({\bf theora\_\-info} $\ast$ti)
  108. \begin{DoxyCompactList}\small\item\em Report the granulepos shift radix. \item\end{DoxyCompactList}\item
  109. ogg\_\-int64\_\-t {\bf theora\_\-granule\_\-frame} ({\bf theora\_\-state} $\ast$th, ogg\_\-int64\_\-t granulepos)
  110. \begin{DoxyCompactList}\small\item\em Convert a granulepos to an absolute frame index, starting at 0. \item\end{DoxyCompactList}\item
  111. double {\bf theora\_\-granule\_\-time} ({\bf theora\_\-state} $\ast$th, ogg\_\-int64\_\-t granulepos)
  112. \begin{DoxyCompactList}\small\item\em Convert a granulepos to absolute time in seconds. \item\end{DoxyCompactList}\item
  113. void {\bf theora\_\-info\_\-init} ({\bf theora\_\-info} $\ast$c)
  114. \begin{DoxyCompactList}\small\item\em Initialize a \doxyref{theora\_\-info}{p.}{structtheora__info} structure. \item\end{DoxyCompactList}\item
  115. void {\bf theora\_\-info\_\-clear} ({\bf theora\_\-info} $\ast$c)
  116. \begin{DoxyCompactList}\small\item\em Clear a \doxyref{theora\_\-info}{p.}{structtheora__info} structure. \item\end{DoxyCompactList}\item
  117. void {\bf theora\_\-clear} ({\bf theora\_\-state} $\ast$t)
  118. \begin{DoxyCompactList}\small\item\em Free all internal data associated with a \doxyref{theora\_\-state}{p.}{structtheora__state} handle. \item\end{DoxyCompactList}\item
  119. void {\bf theora\_\-comment\_\-init} ({\bf theora\_\-comment} $\ast$tc)
  120. \begin{DoxyCompactList}\small\item\em Initialize an allocated \doxyref{theora\_\-comment}{p.}{structtheora__comment} structure. \item\end{DoxyCompactList}\item
  121. void {\bf theora\_\-comment\_\-add} ({\bf theora\_\-comment} $\ast$tc, char $\ast$comment)
  122. \begin{DoxyCompactList}\small\item\em Add a comment to an initialized \doxyref{theora\_\-comment}{p.}{structtheora__comment} structure. \item\end{DoxyCompactList}\item
  123. void {\bf theora\_\-comment\_\-add\_\-tag} ({\bf theora\_\-comment} $\ast$tc, char $\ast$tag, char $\ast$value)
  124. \begin{DoxyCompactList}\small\item\em Add a comment to an initialized \doxyref{theora\_\-comment}{p.}{structtheora__comment} structure. \item\end{DoxyCompactList}\item
  125. char $\ast$ {\bf theora\_\-comment\_\-query} ({\bf theora\_\-comment} $\ast$tc, char $\ast$tag, int count)
  126. \begin{DoxyCompactList}\small\item\em Look up a comment value by tag. \item\end{DoxyCompactList}\item
  127. int {\bf theora\_\-comment\_\-query\_\-count} ({\bf theora\_\-comment} $\ast$tc, char $\ast$tag)
  128. \begin{DoxyCompactList}\small\item\em Look up the number of instances of a tag. \item\end{DoxyCompactList}\item
  129. void {\bf theora\_\-comment\_\-clear} ({\bf theora\_\-comment} $\ast$tc)
  130. \begin{DoxyCompactList}\small\item\em Clear an allocated \doxyref{theora\_\-comment}{p.}{structtheora__comment} struct so that it can be freed. \item\end{DoxyCompactList}\item
  131. int {\bf theora\_\-control} ({\bf theora\_\-state} $\ast$th, int req, void $\ast$buf, size\_\-t buf\_\-sz)
  132. \begin{DoxyCompactList}\small\item\em Encoder control function. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
  133. \subsection{Detailed Description}
  134. The libtheora pre-\/1.0 legacy C API. \subsection{Introduction}\label{index_intro}
  135. This is the documentation for the libtheora legacy C API, declared in the \doxyref{theora.h}{p.}{theora_8h} header, which describes the old interface used before the 1.0 release. This API was widely deployed for several years and remains supported, but for new code we recommend the cleaner API declared in \doxyref{theoradec.h}{p.}{theoradec_8h} and \doxyref{theoraenc.h}{p.}{theoraenc_8h}.
  136. libtheora is the reference implementation for {\tt Theora}, a free video codec. Theora is derived from On2's VP3 codec with improved integration with Ogg multimedia formats by {\tt Xiph.Org}.\subsection{Overview}\label{theora_8h_overview}
  137. This library will both decode and encode theora packets to/from raw YUV frames. In either case, the packets will most likely either come from or need to be embedded in an Ogg stream. Use {\tt libogg} or {\tt liboggz} to extract/package these packets.\subsection{Decoding Process}\label{theora_8h_decoding}
  138. Decoding can be separated into the following steps:
  139. \begin{DoxyEnumerate}
  140. \item initialise \doxyref{theora\_\-info}{p.}{structtheora__info} and \doxyref{theora\_\-comment}{p.}{structtheora__comment} structures using \doxyref{theora\_\-info\_\-init()}{p.}{group__oldfuncs_ga3091c87d48f1faba018c5956379a6d90} and \doxyref{theora\_\-comment\_\-init()}{p.}{group__oldfuncs_ga811b92785df3bdbbebb3de612d9d6ce0}: \begin{DoxyVerb}
  141. theora_info info;
  142. theora_comment comment;
  143. theora_info_init(&info);
  144. theora_comment_init(&comment);
  145. \end{DoxyVerb}
  146. \item retrieve header packets from Ogg stream (there should be 3) and decode into \doxyref{theora\_\-info}{p.}{structtheora__info} and \doxyref{theora\_\-comment}{p.}{structtheora__comment} structures using \doxyref{theora\_\-decode\_\-header()}{p.}{group__oldfuncs_ga02915e63c1bd733ee291f577a8b75a82}. See \doxyref{Identifying Theora Packets}{p.}{theora_8h_identification} for more information on identifying which packets are theora packets. \begin{DoxyVerb}
  147. int i;
  148. for (i = 0; i < 3; i++)
  149. {
  150. (get a theora packet "op" from the Ogg stream)
  151. theora_decode_header(&info, &comment, op);
  152. }
  153. \end{DoxyVerb}
  154. \item initialise the decoder based on the information retrieved into the \doxyref{theora\_\-info}{p.}{structtheora__info} struct by \doxyref{theora\_\-decode\_\-header()}{p.}{group__oldfuncs_ga02915e63c1bd733ee291f577a8b75a82}. You will need a \doxyref{theora\_\-state}{p.}{structtheora__state} struct. \begin{DoxyVerb}
  155. theora_state state;
  156. theora_decode_init(&state, &info);
  157. \end{DoxyVerb}
  158. \item pass in packets and retrieve decoded frames! See the \doxyref{yuv\_\-buffer}{p.}{structyuv__buffer} documentation for information on how to retrieve raw YUV data. \begin{DoxyVerb}
  159. yuf_buffer buffer;
  160. while (last packet was not e_o_s) {
  161. (get a theora packet "op" from the Ogg stream)
  162. theora_decode_packetin(&state, op);
  163. theora_decode_YUVout(&state, &buffer);
  164. }
  165. \end{DoxyVerb}
  166. \end{DoxyEnumerate}\subsubsection{Identifying Theora Packets}\label{theora_8h_identification}
  167. All streams inside an Ogg file have a unique serial\_\-no attached to the stream. Typically, you will want to
  168. \begin{DoxyItemize}
  169. \item retrieve the serial\_\-no for each b\_\-o\_\-s (beginning of stream) page encountered within the Ogg file;
  170. \item test the first (only) packet on that page to determine if it is a theora packet;
  171. \item once you have found a theora b\_\-o\_\-s page then use the retrieved serial\_\-no to identify future packets belonging to the same theora stream.
  172. \end{DoxyItemize}
  173. Note that you {\itshape cannot\/} use \doxyref{theora\_\-packet\_\-isheader()}{p.}{group__oldfuncs_gab969f9d0407683f0e5abe73d0839a25b} to determine if a packet is a theora packet or not, as this function does not perform any checking beyond whether a header bit is present. Instead, use the \doxyref{theora\_\-decode\_\-header()}{p.}{group__oldfuncs_ga02915e63c1bd733ee291f577a8b75a82} function and check the return value; or examine the header bytes at the beginning of the Ogg page.