1 | /******************************************************************** |
2 | * * |
3 | * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. * |
4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
7 | * * |
8 | * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 * |
9 | * by the Xiph.Org Foundation http://www.xiph.org/ * |
10 | * * |
11 | ******************************************************************** |
12 | |
13 | function: |
14 | last mod: $Id: theora.h,v 1.8 2004/03/15 22:17:32 derf Exp $ |
15 | |
16 | ********************************************************************/ |
17 | |
18 | /**\file |
19 | * The <tt>libtheoradec</tt> C decoding API.*/ |
20 | |
21 | #if !defined(_O_THEORA_THEORADEC_H_) |
22 | # define _O_THEORA_THEORADEC_H_ (1) |
23 | # include <stddef.h> |
24 | # include <ogg/ogg.h> |
25 | # include "codec.h" |
26 | |
27 | #if defined(__cplusplus) |
28 | extern "C" { |
29 | #endif |
30 | |
31 | |
32 | |
33 | /**\name th_decode_ctl() codes |
34 | * \anchor decctlcodes |
35 | * These are the available request codes for th_decode_ctl(). |
36 | * By convention, these are odd, to distinguish them from the |
37 | * \ref encctlcodes "encoder control codes". |
38 | * Keep any experimental or vendor-specific values above \c 0x8000.*/ |
39 | /*@{*/ |
40 | /**Gets the maximum post-processing level. |
41 | * The decoder supports a post-processing filter that can improve |
42 | * the appearance of the decoded images. This returns the highest |
43 | * level setting for this post-processor, corresponding to maximum |
44 | * improvement and computational expense. |
45 | * |
46 | * \param[out] _buf int: The maximum post-processing level. |
47 | * \retval TH_EFAULT \a _dec_ctx or \a _buf is <tt>NULL</tt>. |
48 | * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(int)</tt>. |
49 | * \retval TH_EIMPL Not supported by this implementation.*/ |
50 | #define TH_DECCTL_GET_PPLEVEL_MAX (1) |
51 | /**Sets the post-processing level. |
52 | * By default, post-processing is disabled. |
53 | * |
54 | * Sets the level of post-processing to use when decoding the |
55 | * compressed stream. This must be a value between zero (off) |
56 | * and the maximum returned by TH_DECCTL_GET_PPLEVEL_MAX. |
57 | * |
58 | * \param[in] _buf int: The new post-processing level. |
59 | * 0 to disable; larger values use more CPU. |
60 | * \retval TH_EFAULT \a _dec_ctx or \a _buf is <tt>NULL</tt>. |
61 | * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(int)</tt>, or the |
62 | * post-processing level is out of bounds. |
63 | * The maximum post-processing level may be |
64 | * implementation-specific, and can be obtained via |
65 | * #TH_DECCTL_GET_PPLEVEL_MAX. |
66 | * \retval TH_EIMPL Not supported by this implementation.*/ |
67 | #define TH_DECCTL_SET_PPLEVEL (3) |
68 | /**Sets the granule position. |
69 | * Call this after a seek, before decoding the first frame, to ensure that the |
70 | * proper granule position is returned for all subsequent frames. |
71 | * If you track timestamps yourself and do not use the granule position |
72 | * returned by the decoder, then you need not call this function. |
73 | * |
74 | * \param[in] _buf <tt>ogg_int64_t</tt>: The granule position of the next |
75 | * frame. |
76 | * \retval TH_EFAULT \a _dec_ctx or \a _buf is <tt>NULL</tt>. |
77 | * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(ogg_int64_t)</tt>, or the |
78 | * granule position is negative.*/ |
79 | #define TH_DECCTL_SET_GRANPOS (5) |
80 | /**Sets the striped decode callback function. |
81 | * If set, this function will be called as each piece of a frame is fully |
82 | * decoded in th_decode_packetin(). |
83 | * You can pass in a #th_stripe_callback with |
84 | * th_stripe_callback#stripe_decoded set to <tt>NULL</tt> to disable the |
85 | * callbacks at any point. |
86 | * Enabling striped decode does not prevent you from calling |
87 | * th_decode_ycbcr_out() after the frame is fully decoded. |
88 | * |
89 | * \param[in] _buf #th_stripe_callback: The callback parameters. |
90 | * \retval TH_EFAULT \a _dec_ctx or \a _buf is <tt>NULL</tt>. |
91 | * \retval TH_EINVAL \a _buf_sz is not |
92 | * <tt>sizeof(th_stripe_callback)</tt>.*/ |
93 | #define TH_DECCTL_SET_STRIPE_CB (7) |
94 | |
95 | /**Sets the macroblock display mode. Set to 0 to disable displaying |
96 | * macroblocks.*/ |
97 | #define TH_DECCTL_SET_TELEMETRY_MBMODE (9) |
98 | /**Sets the motion vector display mode. Set to 0 to disable displaying motion |
99 | * vectors.*/ |
100 | #define TH_DECCTL_SET_TELEMETRY_MV (11) |
101 | /**Sets the adaptive quantization display mode. Set to 0 to disable displaying |
102 | * adaptive quantization. */ |
103 | #define TH_DECCTL_SET_TELEMETRY_QI (13) |
104 | /**Sets the bitstream breakdown visualization mode. Set to 0 to disable |
105 | * displaying bitstream breakdown.*/ |
106 | #define TH_DECCTL_SET_TELEMETRY_BITS (15) |
107 | /*@}*/ |
108 | |
109 | |
110 | |
111 | /**A callback function for striped decode. |
112 | * This is a function pointer to an application-provided function that will be |
113 | * called each time a section of the image is fully decoded in |
114 | * th_decode_packetin(). |
115 | * This allows the application to process the section immediately, while it is |
116 | * still in cache. |
117 | * Note that the frame is decoded bottom to top, so \a _yfrag0 will steadily |
118 | * decrease with each call until it reaches 0, at which point the full frame |
119 | * is decoded. |
120 | * The number of fragment rows made available in each call depends on the pixel |
121 | * format and the number of post-processing filters enabled, and may not even |
122 | * be constant for the entire frame. |
123 | * If a non-<tt>NULL</tt> \a _granpos pointer is passed to |
124 | * th_decode_packetin(), the granule position for the frame will be stored |
125 | * in it before the first callback is made. |
126 | * If an entire frame is dropped (a 0-byte packet), then no callbacks will be |
127 | * made at all for that frame. |
128 | * \param _ctx An application-provided context pointer. |
129 | * \param _buf The image buffer for the decoded frame. |
130 | * \param _yfrag0 The Y coordinate of the first row of 8x8 fragments |
131 | * decoded. |
132 | * Multiply this by 8 to obtain the pixel row number in the |
133 | * luma plane. |
134 | * If the chroma planes are subsampled in the Y direction, |
135 | * this will always be divisible by two. |
136 | * \param _yfrag_end The Y coordinate of the first row of 8x8 fragments past |
137 | * the newly decoded section. |
138 | * If the chroma planes are subsampled in the Y direction, |
139 | * this will always be divisible by two. |
140 | * I.e., this section contains fragment rows |
141 | * <tt>\a _yfrag0 ...\a _yfrag_end -1</tt>.*/ |
142 | typedef void (*th_stripe_decoded_func)(void *_ctx,th_ycbcr_buffer _buf, |
143 | int _yfrag0,int _yfrag_end); |
144 | |
145 | /**The striped decode callback data to pass to #TH_DECCTL_SET_STRIPE_CB.*/ |
146 | typedef struct{ |
147 | /**An application-provided context pointer. |
148 | * This will be passed back verbatim to the application.*/ |
149 | void *ctx; |
150 | /**The callback function pointer.*/ |
151 | th_stripe_decoded_func stripe_decoded; |
152 | }th_stripe_callback; |
153 | |
154 | |
155 | |
156 | /**\name Decoder state |
157 | The following data structures are opaque, and their contents are not |
158 | publicly defined by this API. |
159 | Referring to their internals directly is unsupported, and may break without |
160 | warning.*/ |
161 | /*@{*/ |
162 | /**The decoder context.*/ |
163 | typedef struct th_dec_ctx th_dec_ctx; |
164 | /**Setup information. |
165 | This contains auxiliary information (Huffman tables and quantization |
166 | parameters) decoded from the setup header by th_decode_headerin() to be |
167 | passed to th_decode_alloc(). |
168 | It can be re-used to initialize any number of decoders, and can be freed |
169 | via th_setup_free() at any time.*/ |
170 | typedef struct th_setup_info th_setup_info; |
171 | /*@}*/ |
172 | |
173 | |
174 | |
175 | /**\defgroup decfuncs Functions for Decoding*/ |
176 | /*@{*/ |
177 | /**\name Functions for decoding |
178 | * You must link to <tt>libtheoradec</tt> if you use any of the |
179 | * functions in this section. |
180 | * |
181 | * The functions are listed in the order they are used in a typical decode. |
182 | * The basic steps are: |
183 | * - Parse the header packets by repeatedly calling th_decode_headerin(). |
184 | * - Allocate a #th_dec_ctx handle with th_decode_alloc(). |
185 | * - Call th_setup_free() to free any memory used for codec setup |
186 | * information. |
187 | * - Perform any additional decoder configuration with th_decode_ctl(). |
188 | * - For each video data packet: |
189 | * - Submit the packet to the decoder via th_decode_packetin(). |
190 | * - Retrieve the uncompressed video data via th_decode_ycbcr_out(). |
191 | * - Call th_decode_free() to release all decoder memory.*/ |
192 | /*@{*/ |
193 | /**Decodes the header packets of a Theora stream. |
194 | * This should be called on the initial packets of the stream, in succession, |
195 | * until it returns <tt>0</tt>, indicating that all headers have been |
196 | * processed, or an error is encountered. |
197 | * At least three header packets are required, and additional optional header |
198 | * packets may follow. |
199 | * This can be used on the first packet of any logical stream to determine if |
200 | * that stream is a Theora stream. |
201 | * \param _info A #th_info structure to fill in. |
202 | * This must have been previously initialized with |
203 | * th_info_init(). |
204 | * The application may immediately begin using the contents of |
205 | * this structure after the first header is decoded, though it |
206 | * must continue to be passed in on all subsequent calls. |
207 | * \param _tc A #th_comment structure to fill in. |
208 | * The application may immediately begin using the contents of |
209 | * this structure after the second header is decoded, though it |
210 | * must continue to be passed in on all subsequent calls. |
211 | * \param _setup Returns a pointer to additional, private setup information |
212 | * needed by the decoder. |
213 | * The contents of this pointer must be initialized to |
214 | * <tt>NULL</tt> on the first call, and the returned value must |
215 | * continue to be passed in on all subsequent calls. |
216 | * \param _op An <tt>ogg_packet</tt> structure which contains one of the |
217 | * initial packets of an Ogg logical stream. |
218 | * \return A positive value indicates that a Theora header was successfully |
219 | * processed. |
220 | * \retval 0 The first video data packet was encountered after all |
221 | * required header packets were parsed. |
222 | * The packet just passed in on this call should be saved |
223 | * and fed to th_decode_packetin() to begin decoding |
224 | * video data. |
225 | * \retval TH_EFAULT One of \a _info, \a _tc, or \a _setup was |
226 | * <tt>NULL</tt>. |
227 | * \retval TH_EBADHEADER \a _op was <tt>NULL</tt>, the packet was not the next |
228 | * header packet in the expected sequence, or the format |
229 | * of the header data was invalid. |
230 | * \retval TH_EVERSION The packet data was a Theora info header, but for a |
231 | * bitstream version not decodable with this version of |
232 | * <tt>libtheoradec</tt>. |
233 | * \retval TH_ENOTFORMAT The packet was not a Theora header. |
234 | */ |
235 | extern int (th_info *_info,th_comment *_tc, |
236 | th_setup_info **_setup,ogg_packet *_op); |
237 | /**Allocates a decoder instance. |
238 | * |
239 | * <b>Security Warning:</b> The Theora format supports very large frame sizes, |
240 | * potentially even larger than the address space of a 32-bit machine, and |
241 | * creating a decoder context allocates the space for several frames of data. |
242 | * If the allocation fails here, your program will crash, possibly at some |
243 | * future point because the OS kernel returned a valid memory range and will |
244 | * only fail when it tries to map the pages in it the first time they are |
245 | * used. |
246 | * Even if it succeeds, you may experience a denial of service if the frame |
247 | * size is large enough to cause excessive paging. |
248 | * If you are integrating libtheora in a larger application where such things |
249 | * are undesirable, it is highly recommended that you check the frame size in |
250 | * \a _info before calling this function and refuse to decode streams where it |
251 | * is larger than some reasonable maximum. |
252 | * libtheora will not check this for you, because there may be machines that |
253 | * can handle such streams and applications that wish to. |
254 | * \param _info A #th_info struct filled via th_decode_headerin(). |
255 | * \param _setup A #th_setup_info handle returned via |
256 | * th_decode_headerin(). |
257 | * \return The initialized #th_dec_ctx handle. |
258 | * \retval NULL If the decoding parameters were invalid.*/ |
259 | extern th_dec_ctx *th_decode_alloc(const th_info *_info, |
260 | const th_setup_info *_setup); |
261 | /**Releases all storage used for the decoder setup information. |
262 | * This should be called after you no longer want to create any decoders for |
263 | * a stream whose headers you have parsed with th_decode_headerin(). |
264 | * \param _setup The setup information to free. |
265 | * This can safely be <tt>NULL</tt>.*/ |
266 | extern void th_setup_free(th_setup_info *_setup); |
267 | /**Decoder control function. |
268 | * This is used to provide advanced control of the decoding process. |
269 | * \param _dec A #th_dec_ctx handle. |
270 | * \param _req The control code to process. |
271 | * See \ref decctlcodes "the list of available control codes" |
272 | * for details. |
273 | * \param _buf The parameters for this control code. |
274 | * \param _buf_sz The size of the parameter buffer. |
275 | * \return Possible return values depend on the control code used. |
276 | * See \ref decctlcodes "the list of control codes" for |
277 | * specific values. Generally 0 indicates success.*/ |
278 | extern int th_decode_ctl(th_dec_ctx *_dec,int _req,void *_buf, |
279 | size_t _buf_sz); |
280 | /**Submits a packet containing encoded video data to the decoder. |
281 | * \param _dec A #th_dec_ctx handle. |
282 | * \param _op An <tt>ogg_packet</tt> containing encoded video data. |
283 | * \param _granpos Returns the granule position of the decoded packet. |
284 | * If non-<tt>NULL</tt>, the granule position for this specific |
285 | * packet is stored in this location. |
286 | * This is computed incrementally from previously decoded |
287 | * packets. |
288 | * After a seek, the correct granule position must be set via |
289 | * #TH_DECCTL_SET_GRANPOS for this to work properly. |
290 | * \retval 0 Success. |
291 | * A new decoded frame can be retrieved by calling |
292 | * th_decode_ycbcr_out(). |
293 | * \retval TH_DUPFRAME The packet represented a dropped frame (either a |
294 | * 0-byte frame or an INTER frame with no coded blocks). |
295 | * The player can skip the call to th_decode_ycbcr_out(), |
296 | * as the contents of the decoded frame buffer have not |
297 | * changed. |
298 | * \retval TH_EFAULT \a _dec or \a _op was <tt>NULL</tt>. |
299 | * \retval TH_EBADPACKET \a _op does not contain encoded video data. |
300 | * \retval TH_EIMPL The video data uses bitstream features which this |
301 | * library does not support.*/ |
302 | extern int th_decode_packetin(th_dec_ctx *_dec,const ogg_packet *_op, |
303 | ogg_int64_t *_granpos); |
304 | /**Outputs the next available frame of decoded Y'CbCr data. |
305 | * If a striped decode callback has been set with #TH_DECCTL_SET_STRIPE_CB, |
306 | * then the application does not need to call this function. |
307 | * \param _dec A #th_dec_ctx handle. |
308 | * \param _ycbcr A video buffer structure to fill in. |
309 | * <tt>libtheoradec</tt> will fill in all the members of this |
310 | * structure, including the pointers to the uncompressed video |
311 | * data. |
312 | * The memory for this video data is owned by |
313 | * <tt>libtheoradec</tt>. |
314 | * It may be freed or overwritten without notification when |
315 | * subsequent frames are decoded. |
316 | * \retval 0 Success |
317 | * \retval TH_EFAULT \a _dec or \a _ycbcr was <tt>NULL</tt>. |
318 | */ |
319 | extern int th_decode_ycbcr_out(th_dec_ctx *_dec, |
320 | th_ycbcr_buffer _ycbcr); |
321 | /**Frees an allocated decoder instance. |
322 | * \param _dec A #th_dec_ctx handle.*/ |
323 | extern void th_decode_free(th_dec_ctx *_dec); |
324 | /*@}*/ |
325 | /*@}*/ |
326 | |
327 | |
328 | |
329 | #if defined(__cplusplus) |
330 | } |
331 | #endif |
332 | |
333 | #endif |
334 | |