libtheora 1.1.1

theora.h
Go to the documentation of this file.
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.17 2003/12/06 18:06:19 arc Exp $
15
16 ********************************************************************/
17
18#ifndef _O_THEORA_H_
19#define _O_THEORA_H_
20
21#ifdef __cplusplus
22 extern "C"
23{
24#endif /* __cplusplus */
25
26#include <stddef.h> /* for size_t */
27
28#include <ogg/ogg.h>
29
121/* @{ */
122
147 typedef struct {
148 int y_width;
149 int y_height;
150 int y_stride;
152 int uv_width;
153 int uv_height;
154 int uv_stride;
155 unsigned char *y;
156 unsigned char *u;
157 unsigned char *v;
159} yuv_buffer;
160
164 typedef enum {
165 OC_CS_UNSPECIFIED,
166 OC_CS_ITU_REC_470M,
167 OC_CS_ITU_REC_470BG,
168 OC_CS_NSPACES
169} theora_colorspace;
170
178 typedef enum {
179 OC_PF_420,
180 OC_PF_RSVD,
181 OC_PF_422,
182 OC_PF_444,
183} theora_pixelformat;
184
206 typedef struct {
207 ogg_uint32_t width;
208 ogg_uint32_t height;
209 ogg_uint32_t frame_width;
210 ogg_uint32_t frame_height;
211 ogg_uint32_t offset_x;
212 ogg_uint32_t offset_y;
213 ogg_uint32_t fps_numerator;
214 ogg_uint32_t fps_denominator;
215 ogg_uint32_t aspect_numerator;
216 ogg_uint32_t aspect_denominator;
217 theora_colorspace colorspace;
218 int target_bitrate;
219 int quality;
220 int quick_p;
222 /* decode only */
223 unsigned char version_major;
224 unsigned char version_minor;
225 unsigned char version_subminor;
226
227 void *codec_setup;
228
229 /* encode only */
230 int dropframes_p;
231 int keyframe_auto_p;
232 ogg_uint32_t keyframe_frequency;
233 ogg_uint32_t keyframe_frequency_force; /* also used for decode init to
234 get granpos shift correct */
235 ogg_uint32_t keyframe_data_target_bitrate;
236 ogg_int32_t keyframe_auto_threshold;
237 ogg_uint32_t keyframe_mindistance;
238 ogg_int32_t noise_sensitivity;
239 ogg_int32_t sharpness;
240
241 theora_pixelformat pixelformat;
243} theora_info;
244
247 typedef struct{
248 theora_info *i;
249 ogg_int64_t granulepos;
250
251 void *internal_encode;
252 void *internal_decode;
253
254} theora_state;
255
275 typedef struct theora_comment{
276 char **user_comments;
277 int *comment_lengths;
278 int comments;
279 char *vendor;
281} theora_comment;
282
283
285/* \anchor decctlcodes_old
286 * These are the available request codes for theora_control()
287 * when called with a decoder instance.
288 * By convention decoder control codes are odd, to distinguish
289 * them from \ref encctlcodes_old "encoder control codes" which
290 * are even.
291 *
292 * Note that since the 1.0 release, both the legacy and the final
293 * implementation accept all the same control codes, but only the
294 * final API declares the newer codes.
295 *
296 * Keep any experimental or vendor-specific values above \c 0x8000.*/
297
306#define TH_DECCTL_GET_PPLEVEL_MAX (1)
307
313#define TH_DECCTL_SET_PPLEVEL (3)
314
327#define TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE (4)
328
336#define TH_DECCTL_SET_GRANPOS (5)
337
353#define TH_ENCCTL_SET_QUANT_PARAMS (2)
354
382#define TH_ENCCTL_SET_VP3_COMPATIBLE (10)
383
397#define TH_ENCCTL_GET_SPLEVEL_MAX (12)
398
412#define TH_ENCCTL_SET_SPLEVEL (14)
413
416#define OC_FAULT -1
417#define OC_EINVAL -10
418#define OC_DISABLED -11
419#define OC_BADHEADER -20
420#define OC_NOTFORMAT -21
421#define OC_VERSION -22
422#define OC_IMPL -23
423#define OC_BADPACKET -24
424#define OC_NEWPACKET -25
425#define OC_DUPFRAME 1
431 extern const char *theora_version_string(void);
432
442 extern ogg_uint32_t theora_version_number(void);
443
450 extern int theora_encode_init(theora_state *th, theora_info *ti);
451
462 extern int theora_encode_YUVin(theora_state *t, yuv_buffer *yuv);
463
476 extern int theora_encode_packetout( theora_state *t, int last_p,
477 ogg_packet *op);
478
489 extern int theora_encode_header(theora_state *t, ogg_packet *op);
490
502 extern int theora_encode_comment(theora_comment *tc, ogg_packet *op);
503
514 extern int theora_encode_tables(theora_state *t, ogg_packet *op);
515
557 extern int theora_decode_header(theora_info *ci, theora_comment *cc,
558 ogg_packet *op);
559
568 extern int theora_decode_init(theora_state *th, theora_info *c);
569
577 extern int theora_decode_packetin(theora_state *th,ogg_packet *op);
578
589 extern int theora_decode_YUVout(theora_state *th,yuv_buffer *yuv);
590
603 extern int theora_packet_isheader(ogg_packet *op);
604
615 extern int theora_packet_iskeyframe(ogg_packet *op);
616
642 int theora_granule_shift(theora_info *ti);
643
660 extern ogg_int64_t theora_granule_frame(theora_state *th,ogg_int64_t granulepos);
661
677 extern double theora_granule_time(theora_state *th,ogg_int64_t granulepos);
678
685 extern void theora_info_init(theora_info *c);
686
692 extern void theora_info_clear(theora_info *c);
693
698 extern void theora_clear(theora_state *t);
699
704 extern void theora_comment_init(theora_comment *tc);
705
718 extern void theora_comment_add(theora_comment *tc, char *comment);
719
732 extern void theora_comment_add_tag(theora_comment *tc,
733 char *tag, char *value);
734
749 extern char *theora_comment_query(theora_comment *tc, char *tag, int count);
750
760 extern int theora_comment_query_count(theora_comment *tc, char *tag);
761
766 extern void theora_comment_clear(theora_comment *tc);
767
776 extern int theora_control(theora_state *th,int req,void *buf,size_t buf_sz);
777
778/* @} */ /* end oldfuncs doxygen group */
779
780#ifdef __cplusplus
781}
782#endif /* __cplusplus */
783
784#endif /* _O_THEORA_H_ */
theora_comment
Comment header metadata.
Definition: theora.h:275
theora_comment::comments
int comments
The total number of comment string vectors.
Definition: theora.h:278
theora_comment::user_comments
char ** user_comments
An array of comment string vectors.
Definition: theora.h:276
theora_comment::comment_lengths
int * comment_lengths
An array of corresponding string vector lengths in bytes.
Definition: theora.h:277
theora_comment::vendor
char * vendor
The vendor string identifying the encoder, null terminated.
Definition: theora.h:279
theora_info
Theora bitstream info.
Definition: theora.h:206
theora_info::keyframe_frequency
ogg_uint32_t keyframe_frequency
Definition: theora.h:232
theora_info::target_bitrate
int target_bitrate
nominal bitrate in bits per second
Definition: theora.h:218
theora_info::width
ogg_uint32_t width
encoded frame width
Definition: theora.h:207
theora_info::keyframe_auto_p
int keyframe_auto_p
Definition: theora.h:231
theora_info::frame_height
ogg_uint32_t frame_height
display frame height
Definition: theora.h:210
theora_info::quick_p
int quick_p
Quick encode/decode.
Definition: theora.h:220
theora_info::fps_numerator
ogg_uint32_t fps_numerator
frame rate numerator
Definition: theora.h:213
theora_info::sharpness
ogg_int32_t sharpness
Definition: theora.h:239
theora_info::keyframe_data_target_bitrate
ogg_uint32_t keyframe_data_target_bitrate
Definition: theora.h:235
theora_info::aspect_numerator
ogg_uint32_t aspect_numerator
pixel aspect ratio numerator
Definition: theora.h:215
theora_info::colorspace
theora_colorspace colorspace
colorspace
Definition: theora.h:217
theora_info::pixelformat
theora_pixelformat pixelformat
chroma subsampling mode to expect
Definition: theora.h:241
theora_info::codec_setup
void * codec_setup
Definition: theora.h:227
theora_info::quality
int quality
Nominal quality setting, 0-63.
Definition: theora.h:219
theora_info::version_minor
unsigned char version_minor
Definition: theora.h:224
theora_info::version_major
unsigned char version_major
Definition: theora.h:223
theora_info::frame_width
ogg_uint32_t frame_width
display frame width
Definition: theora.h:209
theora_info::offset_y
ogg_uint32_t offset_y
vertical offset of the displayed frame
Definition: theora.h:212
theora_info::keyframe_auto_threshold
ogg_int32_t keyframe_auto_threshold
Definition: theora.h:236
theora_info::fps_denominator
ogg_uint32_t fps_denominator
frame rate denominator
Definition: theora.h:214
theora_info::version_subminor
unsigned char version_subminor
Definition: theora.h:225
theora_info::keyframe_mindistance
ogg_uint32_t keyframe_mindistance
Definition: theora.h:237
theora_info::noise_sensitivity
ogg_int32_t noise_sensitivity
Definition: theora.h:238
theora_info::keyframe_frequency_force
ogg_uint32_t keyframe_frequency_force
Definition: theora.h:233
theora_info::height
ogg_uint32_t height
encoded frame height
Definition: theora.h:208
theora_info::dropframes_p
int dropframes_p
Definition: theora.h:230
theora_info::offset_x
ogg_uint32_t offset_x
horizontal offset of the displayed frame
Definition: theora.h:211
theora_info::aspect_denominator
ogg_uint32_t aspect_denominator
pixel aspect ratio denominator
Definition: theora.h:216
theora_state
Codec internal state and context.
Definition: theora.h:247
theora_state::i
theora_info * i
Definition: theora.h:248
theora_state::internal_encode
void * internal_encode
Definition: theora.h:251
theora_state::granulepos
ogg_int64_t granulepos
Definition: theora.h:249
theora_state::internal_decode
void * internal_decode
Definition: theora.h:252
yuv_buffer
A YUV buffer for passing uncompressed frames to and from the codec.
Definition: theora.h:147
yuv_buffer::y_height
int y_height
Height of the luminance plane.
Definition: theora.h:149
yuv_buffer::uv_height
int uv_height
Height of the chroma planes.
Definition: theora.h:153
yuv_buffer::y
unsigned char * y
Pointer to start of luminance data.
Definition: theora.h:155
yuv_buffer::u
unsigned char * u
Pointer to start of Cb data.
Definition: theora.h:156
yuv_buffer::uv_width
int uv_width
Width of the Cb and Cr chroma planes.
Definition: theora.h:152
yuv_buffer::y_stride
int y_stride
Offset in bytes between successive rows.
Definition: theora.h:150
yuv_buffer::v
unsigned char * v
Pointer to start of Cr data.
Definition: theora.h:157
yuv_buffer::y_width
int y_width
Width of the Y' luminance plane.
Definition: theora.h:148
yuv_buffer::uv_stride
int uv_stride
Offset between successive chroma rows.
Definition: theora.h:154
theora_decode_header
int theora_decode_header(theora_info *ci, theora_comment *cc, ogg_packet *op)
Decode an Ogg packet, with the expectation that the packet contains an initial header,...
theora_comment_clear
void theora_comment_clear(theora_comment *tc)
Clear an allocated theora_comment struct so that it can be freed.
theora_decode_YUVout
int theora_decode_YUVout(theora_state *th, yuv_buffer *yuv)
Output the next available frame of decoded YUV data.
theora_encode_init
int theora_encode_init(theora_state *th, theora_info *ti)
Initialize the theora encoder.
theora_comment_query_count
int theora_comment_query_count(theora_comment *tc, char *tag)
Look up the number of instances of a tag.
theora_control
int theora_control(theora_state *th, int req, void *buf, size_t buf_sz)
Encoder control function.
theora_decode_init
int theora_decode_init(theora_state *th, theora_info *c)
Initialize a theora_state handle for decoding.
theora_info_init
void theora_info_init(theora_info *c)
Initialize a theora_info structure.
theora_comment_add_tag
void theora_comment_add_tag(theora_comment *tc, char *tag, char *value)
Add a comment to an initialized theora_comment structure.
theora_packet_iskeyframe
int theora_packet_iskeyframe(ogg_packet *op)
Report whether a theora packet is a keyframe or not.
theora_granule_time
double theora_granule_time(theora_state *th, ogg_int64_t granulepos)
Convert a granulepos to absolute time in seconds.
theora_encode_header
int theora_encode_header(theora_state *t, ogg_packet *op)
Request a packet containing the initial header.
theora_encode_comment
int theora_encode_comment(theora_comment *tc, ogg_packet *op)
Request a comment header packet from provided metadata.
theora_encode_tables
int theora_encode_tables(theora_state *t, ogg_packet *op)
Request a packet containing the codebook tables for the stream.
theora_encode_packetout
int theora_encode_packetout(theora_state *t, int last_p, ogg_packet *op)
Request the next packet of encoded video.
theora_comment_add
void theora_comment_add(theora_comment *tc, char *comment)
Add a comment to an initialized theora_comment structure.
theora_granule_frame
ogg_int64_t theora_granule_frame(theora_state *th, ogg_int64_t granulepos)
Convert a granulepos to an absolute frame index, starting at 0.
theora_comment_init
void theora_comment_init(theora_comment *tc)
Initialize an allocated theora_comment structure.
theora_colorspace
theora_colorspace
A Colorspace.
Definition: theora.h:164
OC_CS_ITU_REC_470BG
@ OC_CS_ITU_REC_470BG
This is the best option for 'PAL' content.
Definition: theora.h:167
OC_CS_NSPACES
@ OC_CS_NSPACES
This marks the end of the defined colorspaces.
Definition: theora.h:168
OC_CS_ITU_REC_470M
@ OC_CS_ITU_REC_470M
This is the best option for 'NTSC' content.
Definition: theora.h:166
OC_CS_UNSPECIFIED
@ OC_CS_UNSPECIFIED
The colorspace is unknown or unspecified.
Definition: theora.h:165
theora_decode_packetin
int theora_decode_packetin(theora_state *th, ogg_packet *op)
Input a packet containing encoded data into the theora decoder.
theora_clear
void theora_clear(theora_state *t)
Free all internal data associated with a theora_state handle.
theora_packet_isheader
int theora_packet_isheader(ogg_packet *op)
Report whether a theora packet is a header or not This function does no verification beyond checking ...
theora_info_clear
void theora_info_clear(theora_info *c)
Clear a theora_info structure.
theora_encode_YUVin
int theora_encode_YUVin(theora_state *t, yuv_buffer *yuv)
Submit a YUV buffer to the theora encoder.
theora_version_string
const char * theora_version_string(void)
Retrieve a human-readable string to identify the encoder vendor and version.
theora_comment_query
char * theora_comment_query(theora_comment *tc, char *tag, int count)
Look up a comment value by tag.
theora_comment
struct theora_comment theora_comment
Comment header metadata.
theora_granule_shift
int theora_granule_shift(theora_info *ti)
Report the granulepos shift radix.
theora_version_number
ogg_uint32_t theora_version_number(void)
Retrieve a 32-bit version number.
theora_pixelformat
theora_pixelformat
A Chroma subsampling.
Definition: theora.h:178
OC_PF_444
@ OC_PF_444
No chroma subsampling at all (4:4:4)
Definition: theora.h:182
OC_PF_422
@ OC_PF_422
Horizonatal chroma subsampling by 2 (4:2:2)
Definition: theora.h:181
OC_PF_420
@ OC_PF_420
Chroma subsampling by 2 in each direction (4:2:0)
Definition: theora.h:179
OC_PF_RSVD
@ OC_PF_RSVD
Reserved value.
Definition: theora.h:180