Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/libtheora/theora/theora.h
9912 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
#ifndef OGG_THEORA_HEADER
18
#define OGG_THEORA_HEADER
19
20
#ifdef __cplusplus
21
extern "C"
22
{
23
#endif /* __cplusplus */
24
25
#include <stddef.h> /* for size_t */
26
27
#include <ogg/ogg.h>
28
29
/** \file
30
* The libtheora pre-1.0 legacy C API.
31
*
32
* \ingroup oldfuncs
33
*
34
* \section intro Introduction
35
*
36
* This is the documentation for the libtheora legacy C API, declared in
37
* the theora.h header, which describes the old interface used before
38
* the 1.0 release. This API was widely deployed for several years and
39
* remains supported, but for new code we recommend the cleaner API
40
* declared in theoradec.h and theoraenc.h.
41
*
42
* libtheora is the reference implementation for
43
* <a href="https://www.theora.org/">Theora</a>, a free video codec.
44
* Theora is derived from On2's VP3 codec with improved integration with
45
* Ogg multimedia formats by <a href="https://www.xiph.org/">Xiph.Org</a>.
46
*
47
* \section overview Overview
48
*
49
* This library will both decode and encode theora packets to/from raw YUV
50
* frames. In either case, the packets will most likely either come from or
51
* need to be embedded in an Ogg stream. Use
52
* <a href="https://www.xiph.org/ogg/">libogg</a> or
53
* <a href="http://www.annodex.net/software/liboggz/index.html">liboggz</a>
54
* to extract/package these packets.
55
*
56
* \section decoding Decoding Process
57
*
58
* Decoding can be separated into the following steps:
59
* -# initialise theora_info and theora_comment structures using
60
* theora_info_init() and theora_comment_init():
61
\verbatim
62
theora_info info;
63
theora_comment comment;
64
65
theora_info_init(&info);
66
theora_comment_init(&comment);
67
\endverbatim
68
* -# retrieve header packets from Ogg stream (there should be 3) and decode
69
* into theora_info and theora_comment structures using
70
* theora_decode_header(). See \ref identification for more information on
71
* identifying which packets are theora packets.
72
\verbatim
73
int i;
74
for (i = 0; i < 3; i++)
75
{
76
(get a theora packet "op" from the Ogg stream)
77
theora_decode_header(&info, &comment, op);
78
}
79
\endverbatim
80
* -# initialise the decoder based on the information retrieved into the
81
* theora_info struct by theora_decode_header(). You will need a
82
* theora_state struct.
83
\verbatim
84
theora_state state;
85
86
theora_decode_init(&state, &info);
87
\endverbatim
88
* -# pass in packets and retrieve decoded frames! See the yuv_buffer
89
* documentation for information on how to retrieve raw YUV data.
90
\verbatim
91
yuf_buffer buffer;
92
while (last packet was not e_o_s) {
93
(get a theora packet "op" from the Ogg stream)
94
theora_decode_packetin(&state, op);
95
theora_decode_YUVout(&state, &buffer);
96
}
97
\endverbatim
98
*
99
*
100
* \subsection identification Identifying Theora Packets
101
*
102
* All streams inside an Ogg file have a unique serial_no attached to the
103
* stream. Typically, you will want to
104
* - retrieve the serial_no for each b_o_s (beginning of stream) page
105
* encountered within the Ogg file;
106
* - test the first (only) packet on that page to determine if it is a theora
107
* packet;
108
* - once you have found a theora b_o_s page then use the retrieved serial_no
109
* to identify future packets belonging to the same theora stream.
110
*
111
* Note that you \e cannot use theora_packet_isheader() to determine if a
112
* packet is a theora packet or not, as this function does not perform any
113
* checking beyond whether a header bit is present. Instead, use the
114
* theora_decode_header() function and check the return value; or examine the
115
* header bytes at the beginning of the Ogg page.
116
*/
117
118
119
/** \defgroup oldfuncs Legacy pre-1.0 C API */
120
/* @{ */
121
122
/**
123
* A YUV buffer for passing uncompressed frames to and from the codec.
124
* This holds a Y'CbCr frame in planar format. The CbCr planes can be
125
* subsampled and have their own separate dimensions and row stride
126
* offsets. Note that the strides may be negative in some
127
* configurations. For theora the width and height of the largest plane
128
* must be a multiple of 16. The actual meaningful picture size and
129
* offset are stored in the theora_info structure; frames returned by
130
* the decoder may need to be cropped for display.
131
*
132
* All samples are 8 bits. Within each plane samples are ordered by
133
* row from the top of the frame to the bottom. Within each row samples
134
* are ordered from left to right.
135
*
136
* During decode, the yuv_buffer struct is allocated by the user, but all
137
* fields (including luma and chroma pointers) are filled by the library.
138
* These pointers address library-internal memory and their contents should
139
* not be modified.
140
*
141
* Conversely, during encode the user allocates the struct and fills out all
142
* fields. The user also manages the data addressed by the luma and chroma
143
* pointers. See the encoder_example.c and dump_video.c example files in
144
* theora/examples/ for more information.
145
*/
146
typedef struct {
147
int y_width; /**< Width of the Y' luminance plane */
148
int y_height; /**< Height of the luminance plane */
149
int y_stride; /**< Offset in bytes between successive rows */
150
151
int uv_width; /**< Width of the Cb and Cr chroma planes */
152
int uv_height; /**< Height of the chroma planes */
153
int uv_stride; /**< Offset between successive chroma rows */
154
unsigned char *y; /**< Pointer to start of luminance data */
155
unsigned char *u; /**< Pointer to start of Cb data */
156
unsigned char *v; /**< Pointer to start of Cr data */
157
158
} yuv_buffer;
159
160
/**
161
* A Colorspace.
162
*/
163
typedef enum {
164
OC_CS_UNSPECIFIED, /**< The colorspace is unknown or unspecified */
165
OC_CS_ITU_REC_470M, /**< This is the best option for 'NTSC' content */
166
OC_CS_ITU_REC_470BG, /**< This is the best option for 'PAL' content */
167
OC_CS_NSPACES /**< This marks the end of the defined colorspaces */
168
} theora_colorspace;
169
170
/**
171
* A Chroma subsampling
172
*
173
* These enumerate the available chroma subsampling options supported
174
* by the theora format. See Section 4.4 of the specification for
175
* exact definitions.
176
*/
177
typedef enum {
178
OC_PF_420, /**< Chroma subsampling by 2 in each direction (4:2:0) */
179
OC_PF_RSVD, /**< Reserved value */
180
OC_PF_422, /**< Horizonatal chroma subsampling by 2 (4:2:2) */
181
OC_PF_444 /**< No chroma subsampling at all (4:4:4) */
182
} theora_pixelformat;
183
184
/**
185
* Theora bitstream info.
186
* Contains the basic playback parameters for a stream,
187
* corresponding to the initial 'info' header packet.
188
*
189
* Encoded theora frames must be a multiple of 16 in width and height.
190
* To handle other frame sizes, a crop rectangle is specified in
191
* frame_height and frame_width, offset_x and * offset_y. The offset
192
* and size should still be a multiple of 2 to avoid chroma sampling
193
* shifts. Offset values in this structure are measured from the
194
* upper left of the image.
195
*
196
* Frame rate, in frames per second, is stored as a rational
197
* fraction. Aspect ratio is also stored as a rational fraction, and
198
* refers to the aspect ratio of the frame pixels, not of the
199
* overall frame itself.
200
*
201
* See <a href="http://svn.xiph.org/trunk/theora/examples/encoder_example.c">
202
* examples/encoder_example.c</a> for usage examples of the
203
* other parameters and good default settings for the encoder parameters.
204
*/
205
typedef struct {
206
ogg_uint32_t width; /**< encoded frame width */
207
ogg_uint32_t height; /**< encoded frame height */
208
ogg_uint32_t frame_width; /**< display frame width */
209
ogg_uint32_t frame_height; /**< display frame height */
210
ogg_uint32_t offset_x; /**< horizontal offset of the displayed frame */
211
ogg_uint32_t offset_y; /**< vertical offset of the displayed frame */
212
ogg_uint32_t fps_numerator; /**< frame rate numerator **/
213
ogg_uint32_t fps_denominator; /**< frame rate denominator **/
214
ogg_uint32_t aspect_numerator; /**< pixel aspect ratio numerator */
215
ogg_uint32_t aspect_denominator; /**< pixel aspect ratio denominator */
216
theora_colorspace colorspace; /**< colorspace */
217
int target_bitrate; /**< nominal bitrate in bits per second */
218
int quality; /**< Nominal quality setting, 0-63 */
219
int quick_p; /**< Quick encode/decode */
220
221
/* decode only */
222
unsigned char version_major;
223
unsigned char version_minor;
224
unsigned char version_subminor;
225
226
void *codec_setup;
227
228
/* encode only */
229
int dropframes_p;
230
int keyframe_auto_p;
231
ogg_uint32_t keyframe_frequency;
232
ogg_uint32_t keyframe_frequency_force; /* also used for decode init to
233
get granpos shift correct */
234
ogg_uint32_t keyframe_data_target_bitrate;
235
ogg_int32_t keyframe_auto_threshold;
236
ogg_uint32_t keyframe_mindistance;
237
ogg_int32_t noise_sensitivity;
238
ogg_int32_t sharpness;
239
240
theora_pixelformat pixelformat; /**< chroma subsampling mode to expect */
241
242
} theora_info;
243
244
/** Codec internal state and context.
245
*/
246
typedef struct{
247
theora_info *i;
248
ogg_int64_t granulepos;
249
250
void *internal_encode;
251
void *internal_decode;
252
253
} theora_state;
254
255
/**
256
* Comment header metadata.
257
*
258
* This structure holds the in-stream metadata corresponding to
259
* the 'comment' header packet.
260
*
261
* Meta data is stored as a series of (tag, value) pairs, in
262
* length-encoded string vectors. The first occurrence of the
263
* '=' character delimits the tag and value. A particular tag
264
* may occur more than once. The character set encoding for
265
* the strings is always UTF-8, but the tag names are limited
266
* to case-insensitive ASCII. See the spec for details.
267
*
268
* In filling in this structure, theora_decode_header() will
269
* null-terminate the user_comment strings for safety. However,
270
* the bitstream format itself treats them as 8-bit clean,
271
* and so the length array should be treated as authoritative
272
* for their length.
273
*/
274
typedef struct theora_comment{
275
char **user_comments; /**< An array of comment string vectors */
276
int *comment_lengths; /**< An array of corresponding string vector lengths in bytes */
277
int comments; /**< The total number of comment string vectors */
278
char *vendor; /**< The vendor string identifying the encoder, null terminated */
279
280
} theora_comment;
281
282
283
/**\name theora_control() codes */
284
/* \anchor decctlcodes_old
285
* These are the available request codes for theora_control()
286
* when called with a decoder instance.
287
* By convention decoder control codes are odd, to distinguish
288
* them from \ref encctlcodes_old "encoder control codes" which
289
* are even.
290
*
291
* Note that since the 1.0 release, both the legacy and the final
292
* implementation accept all the same control codes, but only the
293
* final API declares the newer codes.
294
*
295
* Keep any experimental or vendor-specific values above \c 0x8000.*/
296
297
/*@{*/
298
299
/**Get the maximum post-processing level.
300
* The decoder supports a post-processing filter that can improve
301
* the appearance of the decoded images. This returns the highest
302
* level setting for this post-processor, corresponding to maximum
303
* improvement and computational expense.
304
*/
305
#define TH_DECCTL_GET_PPLEVEL_MAX (1)
306
307
/**Set the post-processing level.
308
* Sets the level of post-processing to use when decoding the
309
* compressed stream. This must be a value between zero (off)
310
* and the maximum returned by TH_DECCTL_GET_PPLEVEL_MAX.
311
*/
312
#define TH_DECCTL_SET_PPLEVEL (3)
313
314
/**Sets the maximum distance between key frames.
315
* This can be changed during an encode, but will be bounded by
316
* <tt>1<<th_info#keyframe_granule_shift</tt>.
317
* If it is set before encoding begins, th_info#keyframe_granule_shift will
318
* be enlarged appropriately.
319
*
320
* \param[in] buf <tt>ogg_uint32_t</tt>: The maximum distance between key
321
* frames.
322
* \param[out] buf <tt>ogg_uint32_t</tt>: The actual maximum distance set.
323
* \retval OC_FAULT \a theora_state or \a buf is <tt>NULL</tt>.
324
* \retval OC_EINVAL \a buf_sz is not <tt>sizeof(ogg_uint32_t)</tt>.
325
* \retval OC_IMPL Not supported by this implementation.*/
326
#define TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE (4)
327
328
/**Set the granule position.
329
* Call this after a seek, to update the internal granulepos
330
* in the decoder, to insure that subsequent frames are marked
331
* properly. If you track timestamps yourself and do not use
332
* the granule position returned by the decoder, then you do
333
* not need to use this control.
334
*/
335
#define TH_DECCTL_SET_GRANPOS (5)
336
337
/**\anchor encctlcodes_old */
338
339
/**Sets the quantization parameters to use.
340
* The parameters are copied, not stored by reference, so they can be freed
341
* after this call.
342
* <tt>NULL</tt> may be specified to revert to the default parameters.
343
*
344
* \param[in] buf #th_quant_info
345
* \retval OC_FAULT \a theora_state is <tt>NULL</tt>.
346
* \retval OC_EINVAL Encoding has already begun, the quantization parameters
347
* are not acceptable to this version of the encoder,
348
* \a buf is <tt>NULL</tt> and \a buf_sz is not zero,
349
* or \a buf is non-<tt>NULL</tt> and \a buf_sz is
350
* not <tt>sizeof(#th_quant_info)</tt>.
351
* \retval OC_IMPL Not supported by this implementation.*/
352
#define TH_ENCCTL_SET_QUANT_PARAMS (2)
353
354
/**Disables any encoder features that would prevent lossless transcoding back
355
* to VP3.
356
* This primarily means disabling block-level QI values and not using 4MV mode
357
* when any of the luma blocks in a macro block are not coded.
358
* It also includes using the VP3 quantization tables and Huffman codes; if you
359
* set them explicitly after calling this function, the resulting stream will
360
* not be VP3-compatible.
361
* If you enable VP3-compatibility when encoding 4:2:2 or 4:4:4 source
362
* material, or when using a picture region smaller than the full frame (e.g.
363
* a non-multiple-of-16 width or height), then non-VP3 bitstream features will
364
* still be disabled, but the stream will still not be VP3-compatible, as VP3
365
* was not capable of encoding such formats.
366
* If you call this after encoding has already begun, then the quantization
367
* tables and codebooks cannot be changed, but the frame-level features will
368
* be enabled or disabled as requested.
369
*
370
* \param[in] buf <tt>int</tt>: a non-zero value to enable VP3 compatibility,
371
* or 0 to disable it (the default).
372
* \param[out] buf <tt>int</tt>: 1 if all bitstream features required for
373
* VP3-compatibility could be set, and 0 otherwise.
374
* The latter will be returned if the pixel format is not
375
* 4:2:0, the picture region is smaller than the full frame,
376
* or if encoding has begun, preventing the quantization
377
* tables and codebooks from being set.
378
* \retval OC_FAULT \a theora_state or \a buf is <tt>NULL</tt>.
379
* \retval OC_EINVAL \a buf_sz is not <tt>sizeof(int)</tt>.
380
* \retval OC_IMPL Not supported by this implementation.*/
381
#define TH_ENCCTL_SET_VP3_COMPATIBLE (10)
382
383
/**Gets the maximum speed level.
384
* Higher speed levels favor quicker encoding over better quality per bit.
385
* Depending on the encoding mode, and the internal algorithms used, quality
386
* may actually improve, but in this case bitrate will also likely increase.
387
* In any case, overall rate/distortion performance will probably decrease.
388
* The maximum value, and the meaning of each value, may change depending on
389
* the current encoding mode (VBR vs. CQI, etc.).
390
*
391
* \param[out] buf int: The maximum encoding speed level.
392
* \retval OC_FAULT \a theora_state or \a buf is <tt>NULL</tt>.
393
* \retval OC_EINVAL \a buf_sz is not <tt>sizeof(int)</tt>.
394
* \retval OC_IMPL Not supported by this implementation in the current
395
* encoding mode.*/
396
#define TH_ENCCTL_GET_SPLEVEL_MAX (12)
397
398
/**Sets the speed level.
399
* By default a speed value of 1 is used.
400
*
401
* \param[in] buf int: The new encoding speed level.
402
* 0 is slowest, larger values use less CPU.
403
* \retval OC_FAULT \a theora_state or \a buf is <tt>NULL</tt>.
404
* \retval OC_EINVAL \a buf_sz is not <tt>sizeof(int)</tt>, or the
405
* encoding speed level is out of bounds.
406
* The maximum encoding speed level may be
407
* implementation- and encoding mode-specific, and can be
408
* obtained via #TH_ENCCTL_GET_SPLEVEL_MAX.
409
* \retval OC_IMPL Not supported by this implementation in the current
410
* encoding mode.*/
411
#define TH_ENCCTL_SET_SPLEVEL (14)
412
413
/*@}*/
414
415
#define OC_FAULT -1 /**< General failure */
416
#define OC_EINVAL -10 /**< Library encountered invalid internal data */
417
#define OC_DISABLED -11 /**< Requested action is disabled */
418
#define OC_BADHEADER -20 /**< Header packet was corrupt/invalid */
419
#define OC_NOTFORMAT -21 /**< Packet is not a theora packet */
420
#define OC_VERSION -22 /**< Bitstream version is not handled */
421
#define OC_IMPL -23 /**< Feature or action not implemented */
422
#define OC_BADPACKET -24 /**< Packet is corrupt */
423
#define OC_NEWPACKET -25 /**< Packet is an (ignorable) unhandled extension */
424
#define OC_DUPFRAME 1 /**< Packet is a dropped frame */
425
426
/**
427
* Retrieve a human-readable string to identify the encoder vendor and version.
428
* \returns A version string.
429
*/
430
extern const char *theora_version_string(void);
431
432
/**
433
* Retrieve a 32-bit version number.
434
* This number is composed of a 16-bit major version, 8-bit minor version
435
* and 8 bit sub-version, composed as follows:
436
<pre>
437
(VERSION_MAJOR<<16) + (VERSION_MINOR<<8) + (VERSION_SUB)
438
</pre>
439
* \returns The version number.
440
*/
441
extern ogg_uint32_t theora_version_number(void);
442
443
/**
444
* Initialize the theora encoder.
445
* \param th The theora_state handle to initialize for encoding.
446
* \param ti A theora_info struct filled with the desired encoding parameters.
447
* \retval 0 Success
448
*/
449
extern int theora_encode_init(theora_state *th, theora_info *ti);
450
451
/**
452
* Submit a YUV buffer to the theora encoder.
453
* \param t A theora_state handle previously initialized for encoding.
454
* \param yuv A buffer of YUV data to encode. Note that both the yuv_buffer
455
* struct and the luma/chroma buffers within should be allocated by
456
* the user.
457
* \retval OC_EINVAL Encoder is not ready, or is finished.
458
* \retval -1 The size of the given frame differs from those previously input
459
* \retval 0 Success
460
*/
461
extern int theora_encode_YUVin(theora_state *t, yuv_buffer *yuv);
462
463
/**
464
* Request the next packet of encoded video.
465
* The encoded data is placed in a user-provided ogg_packet structure.
466
* \param t A theora_state handle previously initialized for encoding.
467
* \param last_p whether this is the last packet the encoder should produce.
468
* \param op An ogg_packet structure to fill. libtheora will set all
469
* elements of this structure, including a pointer to encoded
470
* data. The memory for the encoded data is owned by libtheora.
471
* \retval 0 No internal storage exists OR no packet is ready
472
* \retval -1 The encoding process has completed
473
* \retval 1 Success
474
*/
475
extern int theora_encode_packetout( theora_state *t, int last_p,
476
ogg_packet *op);
477
478
/**
479
* Request a packet containing the initial header.
480
* A pointer to the header data is placed in a user-provided ogg_packet
481
* structure.
482
* \param t A theora_state handle previously initialized for encoding.
483
* \param op An ogg_packet structure to fill. libtheora will set all
484
* elements of this structure, including a pointer to the header
485
* data. The memory for the header data is owned by libtheora.
486
* \retval 0 Success
487
*/
488
extern int theora_encode_header(theora_state *t, ogg_packet *op);
489
490
/**
491
* Request a comment header packet from provided metadata.
492
* A pointer to the comment data is placed in a user-provided ogg_packet
493
* structure.
494
* \param tc A theora_comment structure filled with the desired metadata
495
* \param op An ogg_packet structure to fill. libtheora will set all
496
* elements of this structure, including a pointer to the encoded
497
* comment data. The memory for the comment data is owned by
498
* the application, and must be freed by it using _ogg_free().
499
* On some systems (such as Windows when using dynamic linking), this
500
* may mean the free is executed in a different module from the
501
* malloc, which will crash; there is no way to free this memory on
502
* such systems.
503
* \retval 0 Success
504
*/
505
extern int theora_encode_comment(theora_comment *tc, ogg_packet *op);
506
507
/**
508
* Request a packet containing the codebook tables for the stream.
509
* A pointer to the codebook data is placed in a user-provided ogg_packet
510
* structure.
511
* \param t A theora_state handle previously initialized for encoding.
512
* \param op An ogg_packet structure to fill. libtheora will set all
513
* elements of this structure, including a pointer to the codebook
514
* data. The memory for the header data is owned by libtheora.
515
* \retval 0 Success
516
*/
517
extern int theora_encode_tables(theora_state *t, ogg_packet *op);
518
519
/**
520
* Decode an Ogg packet, with the expectation that the packet contains
521
* an initial header, comment data or codebook tables.
522
*
523
* \param ci A theora_info structure to fill. This must have been previously
524
* initialized with theora_info_init(). If \a op contains an initial
525
* header, theora_decode_header() will fill \a ci with the
526
* parsed header values. If \a op contains codebook tables,
527
* theora_decode_header() will parse these and attach an internal
528
* representation to \a ci->codec_setup.
529
* \param cc A theora_comment structure to fill. If \a op contains comment
530
* data, theora_decode_header() will fill \a cc with the parsed
531
* comments.
532
* \param op An ogg_packet structure which you expect contains an initial
533
* header, comment data or codebook tables.
534
*
535
* \retval OC_BADHEADER \a op is NULL; OR the first byte of \a op->packet
536
* has the signature of an initial packet, but op is
537
* not a b_o_s packet; OR this packet has the signature
538
* of an initial header packet, but an initial header
539
* packet has already been seen; OR this packet has the
540
* signature of a comment packet, but the initial header
541
* has not yet been seen; OR this packet has the signature
542
* of a comment packet, but contains invalid data; OR
543
* this packet has the signature of codebook tables,
544
* but the initial header or comments have not yet
545
* been seen; OR this packet has the signature of codebook
546
* tables, but contains invalid data;
547
* OR the stream being decoded has a compatible version
548
* but this packet does not have the signature of a
549
* theora initial header, comments, or codebook packet
550
* \retval OC_VERSION The packet data of \a op is an initial header with
551
* a version which is incompatible with this version of
552
* libtheora.
553
* \retval OC_NEWPACKET the stream being decoded has an incompatible (future)
554
* version and contains an unknown signature.
555
* \retval 0 Success
556
*
557
* \note The normal usage is that theora_decode_header() be called on the
558
* first three packets of a theora logical bitstream in succession.
559
*/
560
extern int theora_decode_header(theora_info *ci, theora_comment *cc,
561
ogg_packet *op);
562
563
/**
564
* Initialize a theora_state handle for decoding.
565
* \param th The theora_state handle to initialize.
566
* \param c A theora_info struct filled with the desired decoding parameters.
567
* This is of course usually obtained from a previous call to
568
* theora_decode_header().
569
* \retval 0 Success
570
*/
571
extern int theora_decode_init(theora_state *th, theora_info *c);
572
573
/**
574
* Input a packet containing encoded data into the theora decoder.
575
* \param th A theora_state handle previously initialized for decoding.
576
* \param op An ogg_packet containing encoded theora data.
577
* \retval 0 Success
578
* \retval OC_BADPACKET \a op does not contain encoded video data
579
*/
580
extern int theora_decode_packetin(theora_state *th,ogg_packet *op);
581
582
/**
583
* Output the next available frame of decoded YUV data.
584
* \param th A theora_state handle previously initialized for decoding.
585
* \param yuv A yuv_buffer in which libtheora should place the decoded data.
586
* Note that the buffer struct itself is allocated by the user, but
587
* that the luma and chroma pointers will be filled in by the
588
* library. Also note that these luma and chroma regions should be
589
* considered read-only by the user.
590
* \retval 0 Success
591
*/
592
extern int theora_decode_YUVout(theora_state *th,yuv_buffer *yuv);
593
594
/**
595
* Report whether a theora packet is a header or not
596
* This function does no verification beyond checking the header
597
* flag bit so it should not be used for bitstream identification;
598
* use theora_decode_header() for that.
599
*
600
* \param op An ogg_packet containing encoded theora data.
601
* \retval 1 The packet is a header packet
602
* \retval 0 The packet is not a header packet (and so contains frame data)
603
*
604
* Thus function was added in the 1.0alpha4 release.
605
*/
606
extern int theora_packet_isheader(ogg_packet *op);
607
608
/**
609
* Report whether a theora packet is a keyframe or not
610
*
611
* \param op An ogg_packet containing encoded theora data.
612
* \retval 1 The packet contains a keyframe image
613
* \retval 0 The packet is contains an interframe delta
614
* \retval -1 The packet is not an image data packet at all
615
*
616
* Thus function was added in the 1.0alpha4 release.
617
*/
618
extern int theora_packet_iskeyframe(ogg_packet *op);
619
620
/**
621
* Report the granulepos shift radix
622
*
623
* When embedded in Ogg, Theora uses a two-part granulepos,
624
* splitting the 64-bit field into two pieces. The more-significant
625
* section represents the frame count at the last keyframe,
626
* and the less-significant section represents the count of
627
* frames since the last keyframe. In this way the overall
628
* field is still non-decreasing with time, but usefully encodes
629
* a pointer to the last keyframe, which is necessary for
630
* correctly restarting decode after a seek.
631
*
632
* This function reports the number of bits used to represent
633
* the distance to the last keyframe, and thus how the granulepos
634
* field must be shifted or masked to obtain the two parts.
635
*
636
* Since libtheora returns compressed data in an ogg_packet
637
* structure, this may be generally useful even if the Theora
638
* packets are not being used in an Ogg container.
639
*
640
* \param ti A previously initialized theora_info struct
641
* \returns The bit shift dividing the two granulepos fields
642
*
643
* This function was added in the 1.0alpha5 release.
644
*/
645
int theora_granule_shift(theora_info *ti);
646
647
/**
648
* Convert a granulepos to an absolute frame index, starting at 0.
649
* The granulepos is interpreted in the context of a given theora_state handle.
650
*
651
* Note that while the granulepos encodes the frame count (i.e. starting
652
* from 1) this call returns the frame index, starting from zero. Thus
653
* One can calculate the presentation time by multiplying the index by
654
* the rate.
655
*
656
* \param th A previously initialized theora_state handle (encode or decode)
657
* \param granulepos The granulepos to convert.
658
* \returns The frame index corresponding to \a granulepos.
659
* \retval -1 The given granulepos is undefined (i.e. negative)
660
*
661
* Thus function was added in the 1.0alpha4 release.
662
*/
663
extern ogg_int64_t theora_granule_frame(theora_state *th,ogg_int64_t granulepos);
664
665
/**
666
* Convert a granulepos to absolute time in seconds. The granulepos is
667
* interpreted in the context of a given theora_state handle, and gives
668
* the end time of a frame's presentation as used in Ogg mux ordering.
669
*
670
* \param th A previously initialized theora_state handle (encode or decode)
671
* \param granulepos The granulepos to convert.
672
* \returns The absolute time in seconds corresponding to \a granulepos.
673
* This is the "end time" for the frame, or the latest time it should
674
* be displayed.
675
* It is not the presentation time.
676
* \retval -1. The given granulepos is undefined (i.e. negative).
677
*/
678
extern double theora_granule_time(theora_state *th,ogg_int64_t granulepos);
679
680
/**
681
* Initialize a theora_info structure. All values within the given theora_info
682
* structure are initialized, and space is allocated within libtheora for
683
* internal codec setup data.
684
* \param c A theora_info struct to initialize.
685
*/
686
extern void theora_info_init(theora_info *c);
687
688
/**
689
* Clear a theora_info structure. All values within the given theora_info
690
* structure are cleared, and associated internal codec setup data is freed.
691
* \param c A theora_info struct to initialize.
692
*/
693
extern void theora_info_clear(theora_info *c);
694
695
/**
696
* Free all internal data associated with a theora_state handle.
697
* \param t A theora_state handle.
698
*/
699
extern void theora_clear(theora_state *t);
700
701
/**
702
* Initialize an allocated theora_comment structure
703
* \param tc An allocated theora_comment structure
704
**/
705
extern void theora_comment_init(theora_comment *tc);
706
707
/**
708
* Add a comment to an initialized theora_comment structure
709
* \param tc A previously initialized theora comment structure
710
* \param comment A null-terminated string encoding the comment in the form
711
* "TAG=the value"
712
*
713
* Neither theora_comment_add() nor theora_comment_add_tag() support
714
* comments containing null values, although the bitstream format
715
* supports this. To add such comments you will need to manipulate
716
* the theora_comment structure directly.
717
**/
718
719
extern void theora_comment_add(theora_comment *tc, char *comment);
720
721
/**
722
* Add a comment to an initialized theora_comment structure.
723
* \param tc A previously initialized theora comment structure
724
* \param tag A null-terminated string containing the tag
725
* associated with the comment.
726
* \param value The corresponding value as a null-terminated string
727
*
728
* Neither theora_comment_add() nor theora_comment_add_tag() support
729
* comments containing null values, although the bitstream format
730
* supports this. To add such comments you will need to manipulate
731
* the theora_comment structure directly.
732
**/
733
extern void theora_comment_add_tag(theora_comment *tc,
734
char *tag, char *value);
735
736
/**
737
* Look up a comment value by tag.
738
* \param tc Tn initialized theora_comment structure
739
* \param tag The tag to look up
740
* \param count The instance of the tag. The same tag can appear multiple
741
* times, each with a distinct and ordered value, so an index
742
* is required to retrieve them all.
743
* \returns A pointer to the queried tag's value
744
* \retval NULL No matching tag is found
745
*
746
* \note Use theora_comment_query_count() to get the legal range for the
747
* count parameter.
748
**/
749
750
extern char *theora_comment_query(theora_comment *tc, char *tag, int count);
751
752
/** Look up the number of instances of a tag.
753
* \param tc An initialized theora_comment structure
754
* \param tag The tag to look up
755
* \returns The number on instances of a particular tag.
756
*
757
* Call this first when querying for a specific tag and then iterate
758
* over the number of instances with separate calls to
759
* theora_comment_query() to retrieve all instances in order.
760
**/
761
extern int theora_comment_query_count(theora_comment *tc, char *tag);
762
763
/**
764
* Clear an allocated theora_comment struct so that it can be freed.
765
* \param tc An allocated theora_comment structure.
766
**/
767
extern void theora_comment_clear(theora_comment *tc);
768
769
/**Encoder control function.
770
* This is used to provide advanced control the encoding process.
771
* \param th A #theora_state handle.
772
* \param req The control code to process.
773
* See \ref encctlcodes_old "the list of available
774
* control codes" for details.
775
* \param buf The parameters for this control code.
776
* \param buf_sz The size of the parameter buffer.*/
777
extern int theora_control(theora_state *th,int req,void *buf,size_t buf_sz);
778
779
/* @} */ /* end oldfuncs doxygen group */
780
781
#ifdef __cplusplus
782
}
783
#endif /* __cplusplus */
784
785
#endif /* OGG_THEORA_HEADER */
786
787