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