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

mercurial