Path: blob/master/thirdparty/libtheora/theora/theoradec.h
9903 views
/********************************************************************1* *2* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *3* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *4* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *5* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *6* *7* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *8* by the Xiph.Org Foundation https://www.xiph.org/ *9* *10********************************************************************1112function:1314********************************************************************/1516/**\file17* The <tt>libtheoradec</tt> C decoding API.*/1819#if !defined(OGG_THEORA_THEORADEC_HEADER)20# define OGG_THEORA_THEORADEC_HEADER (1)21# include <stddef.h>22# include <ogg/ogg.h>23# include "codec.h"2425#if defined(__cplusplus)26extern "C" {27#endif28293031/**\name th_decode_ctl() codes32* \anchor decctlcodes33* These are the available request codes for th_decode_ctl().34* By convention, these are odd, to distinguish them from the35* \ref encctlcodes "encoder control codes".36* Keep any experimental or vendor-specific values above \c 0x8000.*/37/*@{*/38/**Gets the maximum post-processing level.39* The decoder supports a post-processing filter that can improve40* the appearance of the decoded images. This returns the highest41* level setting for this post-processor, corresponding to maximum42* improvement and computational expense.43*44* \param[out] _buf int: The maximum post-processing level.45* \retval TH_EFAULT \a _dec_ctx or \a _buf is <tt>NULL</tt>.46* \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(int)</tt>.47* \retval TH_EIMPL Not supported by this implementation.*/48#define TH_DECCTL_GET_PPLEVEL_MAX (1)49/**Sets the post-processing level.50* By default, post-processing is disabled.51*52* Sets the level of post-processing to use when decoding the53* compressed stream. This must be a value between zero (off)54* and the maximum returned by TH_DECCTL_GET_PPLEVEL_MAX.55*56* \param[in] _buf int: The new post-processing level.57* 0 to disable; larger values use more CPU.58* \retval TH_EFAULT \a _dec_ctx or \a _buf is <tt>NULL</tt>.59* \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(int)</tt>, or the60* post-processing level is out of bounds.61* The maximum post-processing level may be62* implementation-specific, and can be obtained via63* #TH_DECCTL_GET_PPLEVEL_MAX.64* \retval TH_EIMPL Not supported by this implementation.*/65#define TH_DECCTL_SET_PPLEVEL (3)66/**Sets the granule position.67* Call this after a seek, before decoding the first frame, to ensure that the68* proper granule position is returned for all subsequent frames.69* If you track timestamps yourself and do not use the granule position70* returned by the decoder, then you need not call this function.71*72* \param[in] _buf <tt>ogg_int64_t</tt>: The granule position of the next73* frame.74* \retval TH_EFAULT \a _dec_ctx or \a _buf is <tt>NULL</tt>.75* \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(ogg_int64_t)</tt>, or the76* granule position is negative.*/77#define TH_DECCTL_SET_GRANPOS (5)78/**Sets the striped decode callback function.79* If set, this function will be called as each piece of a frame is fully80* decoded in th_decode_packetin().81* You can pass in a #th_stripe_callback with82* th_stripe_callback#stripe_decoded set to <tt>NULL</tt> to disable the83* callbacks at any point.84* Enabling striped decode does not prevent you from calling85* th_decode_ycbcr_out() after the frame is fully decoded.86*87* \param[in] _buf #th_stripe_callback: The callback parameters.88* \retval TH_EFAULT \a _dec_ctx or \a _buf is <tt>NULL</tt>.89* \retval TH_EINVAL \a _buf_sz is not90* <tt>sizeof(th_stripe_callback)</tt>.*/91#define TH_DECCTL_SET_STRIPE_CB (7)9293/**Sets the macroblock display mode. Set to 0 to disable displaying94* macroblocks.*/95#define TH_DECCTL_SET_TELEMETRY_MBMODE (9)96/**Sets the motion vector display mode. Set to 0 to disable displaying motion97* vectors.*/98#define TH_DECCTL_SET_TELEMETRY_MV (11)99/**Sets the adaptive quantization display mode. Set to 0 to disable displaying100* adaptive quantization. */101#define TH_DECCTL_SET_TELEMETRY_QI (13)102/**Sets the bitstream breakdown visualization mode. Set to 0 to disable103* displaying bitstream breakdown.*/104#define TH_DECCTL_SET_TELEMETRY_BITS (15)105/*@}*/106107108109/**A callback function for striped decode.110* This is a function pointer to an application-provided function that will be111* called each time a section of the image is fully decoded in112* th_decode_packetin().113* This allows the application to process the section immediately, while it is114* still in cache.115* Note that the frame is decoded bottom to top, so \a _yfrag0 will steadily116* decrease with each call until it reaches 0, at which point the full frame117* is decoded.118* The number of fragment rows made available in each call depends on the pixel119* format and the number of post-processing filters enabled, and may not even120* be constant for the entire frame.121* If a non-<tt>NULL</tt> \a _granpos pointer is passed to122* th_decode_packetin(), the granule position for the frame will be stored123* in it before the first callback is made.124* If an entire frame is dropped (a 0-byte packet), then no callbacks will be125* made at all for that frame.126* \param _ctx An application-provided context pointer.127* \param _buf The image buffer for the decoded frame.128* \param _yfrag0 The Y coordinate of the first row of 8x8 fragments129* decoded.130* Multiply this by 8 to obtain the pixel row number in the131* luma plane.132* If the chroma planes are subsampled in the Y direction,133* this will always be divisible by two.134* \param _yfrag_end The Y coordinate of the first row of 8x8 fragments past135* the newly decoded section.136* If the chroma planes are subsampled in the Y direction,137* this will always be divisible by two.138* I.e., this section contains fragment rows139* <tt>\a _yfrag0 ...\a _yfrag_end -1</tt>.*/140typedef void (*th_stripe_decoded_func)(void *_ctx,th_ycbcr_buffer _buf,141int _yfrag0,int _yfrag_end);142143/**The striped decode callback data to pass to #TH_DECCTL_SET_STRIPE_CB.*/144typedef struct{145/**An application-provided context pointer.146* This will be passed back verbatim to the application.*/147void *ctx;148/**The callback function pointer.*/149th_stripe_decoded_func stripe_decoded;150}th_stripe_callback;151152153154/**\name Decoder state155The following data structures are opaque, and their contents are not156publicly defined by this API.157Referring to their internals directly is unsupported, and may break without158warning.*/159/*@{*/160/**The decoder context.*/161typedef struct th_dec_ctx th_dec_ctx;162/**Setup information.163This contains auxiliary information (Huffman tables and quantization164parameters) decoded from the setup header by th_decode_headerin() to be165passed to th_decode_alloc().166It can be re-used to initialize any number of decoders, and can be freed167via th_setup_free() at any time.*/168typedef struct th_setup_info th_setup_info;169/*@}*/170171172173/**\defgroup decfuncs Functions for Decoding*/174/*@{*/175/**\name Functions for decoding176* You must link to <tt>libtheoradec</tt> if you use any of the177* functions in this section.178*179* The functions are listed in the order they are used in a typical decode.180* The basic steps are:181* - Parse the header packets by repeatedly calling th_decode_headerin().182* - Allocate a #th_dec_ctx handle with th_decode_alloc().183* - Call th_setup_free() to free any memory used for codec setup184* information.185* - Perform any additional decoder configuration with th_decode_ctl().186* - For each video data packet:187* - Submit the packet to the decoder via th_decode_packetin().188* - Retrieve the uncompressed video data via th_decode_ycbcr_out().189* - Call th_decode_free() to release all decoder memory.*/190/*@{*/191/**Decodes the header packets of a Theora stream.192* This should be called on the initial packets of the stream, in succession,193* until it returns <tt>0</tt>, indicating that all headers have been194* processed, or an error is encountered.195* At least three header packets are required, and additional optional header196* packets may follow.197* This can be used on the first packet of any logical stream to determine if198* that stream is a Theora stream.199* \param _info A #th_info structure to fill in.200* This must have been previously initialized with201* th_info_init().202* The application may immediately begin using the contents of203* this structure after the first header is decoded, though it204* must continue to be passed in on all subsequent calls.205* \param _tc A #th_comment structure to fill in.206* The application may immediately begin using the contents of207* this structure after the second header is decoded, though it208* must continue to be passed in on all subsequent calls.209* \param _setup Returns a pointer to additional, private setup information210* needed by the decoder.211* The contents of this pointer must be initialized to212* <tt>NULL</tt> on the first call, and the returned value must213* continue to be passed in on all subsequent calls.214* \param _op An <tt>ogg_packet</tt> structure which contains one of the215* initial packets of an Ogg logical stream.216* \return A positive value indicates that a Theora header was successfully217* processed.218* \retval 0 The first video data packet was encountered after all219* required header packets were parsed.220* The packet just passed in on this call should be saved221* and fed to th_decode_packetin() to begin decoding222* video data.223* \retval TH_EFAULT One of \a _info, \a _tc, or \a _setup was224* <tt>NULL</tt>.225* \retval TH_EBADHEADER \a _op was <tt>NULL</tt>, the packet was not the next226* header packet in the expected sequence, or the format227* of the header data was invalid.228* \retval TH_EVERSION The packet data was a Theora info header, but for a229* bitstream version not decodable with this version of230* <tt>libtheoradec</tt>.231* \retval TH_ENOTFORMAT The packet was not a Theora header.232*/233extern int th_decode_headerin(th_info *_info,th_comment *_tc,234th_setup_info **_setup,ogg_packet *_op);235/**Allocates a decoder instance.236*237* <b>Security Warning:</b> The Theora format supports very large frame sizes,238* potentially even larger than the address space of a 32-bit machine, and239* creating a decoder context allocates the space for several frames of data.240* If the allocation fails here, your program will crash, possibly at some241* future point because the OS kernel returned a valid memory range and will242* only fail when it tries to map the pages in it the first time they are243* used.244* Even if it succeeds, you may experience a denial of service if the frame245* size is large enough to cause excessive paging.246* If you are integrating libtheora in a larger application where such things247* are undesirable, it is highly recommended that you check the frame size in248* \a _info before calling this function and refuse to decode streams where it249* is larger than some reasonable maximum.250* libtheora will not check this for you, because there may be machines that251* can handle such streams and applications that wish to.252* \param _info A #th_info struct filled via th_decode_headerin().253* \param _setup A #th_setup_info handle returned via254* th_decode_headerin().255* \return The initialized #th_dec_ctx handle.256* \retval NULL If the decoding parameters were invalid.*/257extern th_dec_ctx *th_decode_alloc(const th_info *_info,258const th_setup_info *_setup);259/**Releases all storage used for the decoder setup information.260* This should be called after you no longer want to create any decoders for261* a stream whose headers you have parsed with th_decode_headerin().262* \param _setup The setup information to free.263* This can safely be <tt>NULL</tt>.*/264extern void th_setup_free(th_setup_info *_setup);265/**Decoder control function.266* This is used to provide advanced control of the decoding process.267* \param _dec A #th_dec_ctx handle.268* \param _req The control code to process.269* See \ref decctlcodes "the list of available control codes"270* for details.271* \param _buf The parameters for this control code.272* \param _buf_sz The size of the parameter buffer.273* \return Possible return values depend on the control code used.274* See \ref decctlcodes "the list of control codes" for275* specific values. Generally 0 indicates success.*/276extern int th_decode_ctl(th_dec_ctx *_dec,int _req,void *_buf,277size_t _buf_sz);278/**Submits a packet containing encoded video data to the decoder.279* \param _dec A #th_dec_ctx handle.280* \param _op An <tt>ogg_packet</tt> containing encoded video data.281* \param _granpos Returns the granule position of the decoded packet.282* If non-<tt>NULL</tt>, the granule position for this specific283* packet is stored in this location.284* This is computed incrementally from previously decoded285* packets.286* After a seek, the correct granule position must be set via287* #TH_DECCTL_SET_GRANPOS for this to work properly.288* \retval 0 Success.289* A new decoded frame can be retrieved by calling290* th_decode_ycbcr_out().291* \retval TH_DUPFRAME The packet represented a dropped frame (either a292* 0-byte frame or an INTER frame with no coded blocks).293* The player can skip the call to th_decode_ycbcr_out(),294* as the contents of the decoded frame buffer have not295* changed.296* \retval TH_EFAULT \a _dec or \a _op was <tt>NULL</tt>.297* \retval TH_EBADPACKET \a _op does not contain encoded video data.298* \retval TH_EIMPL The video data uses bitstream features which this299* library does not support.*/300extern int th_decode_packetin(th_dec_ctx *_dec,const ogg_packet *_op,301ogg_int64_t *_granpos);302/**Outputs the next available frame of decoded Y'CbCr data.303* If a striped decode callback has been set with #TH_DECCTL_SET_STRIPE_CB,304* then the application does not need to call this function.305* \param _dec A #th_dec_ctx handle.306* \param _ycbcr A video buffer structure to fill in.307* <tt>libtheoradec</tt> will fill in all the members of this308* structure, including the pointers to the uncompressed video309* data.310* The memory for this video data is owned by311* <tt>libtheoradec</tt>.312* It may be freed or overwritten without notification when313* subsequent frames are decoded.314* \retval 0 Success315* \retval TH_EFAULT \a _dec or \a _ycbcr was <tt>NULL</tt>.316*/317extern int th_decode_ycbcr_out(th_dec_ctx *_dec,318th_ycbcr_buffer _ycbcr);319/**Frees an allocated decoder instance.320* \param _dec A #th_dec_ctx handle.*/321extern void th_decode_free(th_dec_ctx *_dec);322/*@}*/323/*@}*/324325326327#if defined(__cplusplus)328}329#endif330331#endif /* OGG_THEORA_THEORADEC_HEADER */332333334