media/libtheora/include/theora/theora.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial