• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 #ifndef VPX_DECODER_H
11 #define VPX_DECODER_H
12 
13 /*!\defgroup decoder Decoder Algorithm Interface
14  * \ingroup codec
15  * This abstraction allows applications using this decoder to easily support
16  * multiple video formats with minimal code duplication. This section describes
17  * the interface common to all decoders.
18  * @{
19  */
20 
21 /*!\file
22  * \brief Describes the decoder algorithm interface to applications.
23  *
24  * This file describes the interface between an application and a
25  * video decoder algorithm.
26  *
27  */
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include "vpx_codec.h"
33 
34   /*!\brief Current ABI version number
35    *
36    * \internal
37    * If this file is altered in any way that changes the ABI, this value
38    * must be bumped.  Examples include, but are not limited to, changing
39    * types, removing or reassigning enums, adding/removing/rearranging
40    * fields to structures
41    */
42 #define VPX_DECODER_ABI_VERSION (2 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/
43 
44   /*! \brief Decoder capabilities bitfield
45    *
46    *  Each decoder advertises the capabilities it supports as part of its
47    *  ::vpx_codec_iface_t interface structure. Capabilities are extra interfaces
48    *  or functionality, and are not required to be supported by a decoder.
49    *
50    *  The available flags are specified by VPX_CODEC_CAP_* defines.
51    */
52 #define VPX_CODEC_CAP_PUT_SLICE  0x10000 /**< Will issue put_slice callbacks */
53 #define VPX_CODEC_CAP_PUT_FRAME  0x20000 /**< Will issue put_frame callbacks */
54 #define VPX_CODEC_CAP_POSTPROC   0x40000 /**< Can postprocess decoded frame */
55 #define VPX_CODEC_CAP_ERROR_CONCEALMENT   0x80000 /**< Can conceal errors due to
56   packet loss */
57 #define VPX_CODEC_CAP_INPUT_FRAGMENTS   0x100000 /**< Can receive encoded frames
58   one fragment at a time */
59 
60   /*! \brief Initialization-time Feature Enabling
61    *
62    *  Certain codec features must be known at initialization time, to allow for
63    *  proper memory allocation.
64    *
65    *  The available flags are specified by VPX_CODEC_USE_* defines.
66    */
67 #define VPX_CODEC_CAP_FRAME_THREADING   0x200000 /**< Can support frame-based
68                                                       multi-threading */
69 
70 #define VPX_CODEC_USE_POSTPROC   0x10000 /**< Postprocess decoded frame */
71 #define VPX_CODEC_USE_ERROR_CONCEALMENT 0x20000 /**< Conceal errors in decoded
72   frames */
73 #define VPX_CODEC_USE_INPUT_FRAGMENTS   0x40000 /**< The input frame should be
74   passed to the decoder one
75   fragment at a time */
76 #define VPX_CODEC_USE_FRAME_THREADING   0x80000 /**< Enable frame-based
77                                                      multi-threading */
78 
79   /*!\brief Stream properties
80    *
81    * This structure is used to query or set properties of the decoded
82    * stream. Algorithms may extend this structure with data specific
83    * to their bitstream by setting the sz member appropriately.
84    */
85   typedef struct vpx_codec_stream_info {
86     unsigned int sz;     /**< Size of this structure */
87     unsigned int w;      /**< Width (or 0 for unknown/default) */
88     unsigned int h;      /**< Height (or 0 for unknown/default) */
89     unsigned int is_kf;  /**< Current frame is a keyframe */
90   } vpx_codec_stream_info_t;
91 
92   /* REQUIRED FUNCTIONS
93    *
94    * The following functions are required to be implemented for all decoders.
95    * They represent the base case functionality expected of all decoders.
96    */
97 
98 
99   /*!\brief Initialization Configurations
100    *
101    * This structure is used to pass init time configuration options to the
102    * decoder.
103    */
104   typedef struct vpx_codec_dec_cfg {
105     unsigned int threads; /**< Maximum number of threads to use, default 1 */
106     unsigned int w;      /**< Width */
107     unsigned int h;      /**< Height */
108   } vpx_codec_dec_cfg_t; /**< alias for struct vpx_codec_dec_cfg */
109 
110 
111   /*!\brief Initialize a decoder instance
112    *
113    * Initializes a decoder context using the given interface. Applications
114    * should call the vpx_codec_dec_init convenience macro instead of this
115    * function directly, to ensure that the ABI version number parameter
116    * is properly initialized.
117    *
118    * If the library was configured with --disable-multithread, this call
119    * is not thread safe and should be guarded with a lock if being used
120    * in a multithreaded context.
121    *
122    * In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags
123    * parameter), the storage pointed to by the cfg parameter must be
124    * kept readable and stable until all memory maps have been set.
125    *
126    * \param[in]    ctx     Pointer to this instance's context.
127    * \param[in]    iface   Pointer to the algorithm interface to use.
128    * \param[in]    cfg     Configuration to use, if known. May be NULL.
129    * \param[in]    flags   Bitfield of VPX_CODEC_USE_* flags
130    * \param[in]    ver     ABI version number. Must be set to
131    *                       VPX_DECODER_ABI_VERSION
132    * \retval #VPX_CODEC_OK
133    *     The decoder algorithm initialized.
134    * \retval #VPX_CODEC_MEM_ERROR
135    *     Memory allocation failed.
136    */
137   vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t      *ctx,
138                                          vpx_codec_iface_t    *iface,
139                                          vpx_codec_dec_cfg_t  *cfg,
140                                          vpx_codec_flags_t     flags,
141                                          int                   ver);
142 
143   /*!\brief Convenience macro for vpx_codec_dec_init_ver()
144    *
145    * Ensures the ABI version parameter is properly set.
146    */
147 #define vpx_codec_dec_init(ctx, iface, cfg, flags) \
148   vpx_codec_dec_init_ver(ctx, iface, cfg, flags, VPX_DECODER_ABI_VERSION)
149 
150 
151   /*!\brief Parse stream info from a buffer
152    *
153    * Performs high level parsing of the bitstream. Construction of a decoder
154    * context is not necessary. Can be used to determine if the bitstream is
155    * of the proper format, and to extract information from the stream.
156    *
157    * \param[in]      iface   Pointer to the algorithm interface
158    * \param[in]      data    Pointer to a block of data to parse
159    * \param[in]      data_sz Size of the data buffer
160    * \param[in,out]  si      Pointer to stream info to update. The size member
161    *                         \ref MUST be properly initialized, but \ref MAY be
162    *                         clobbered by the algorithm. This parameter \ref MAY
163    *                         be NULL.
164    *
165    * \retval #VPX_CODEC_OK
166    *     Bitstream is parsable and stream information updated
167    */
168   vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t       *iface,
169                                              const uint8_t           *data,
170                                              unsigned int             data_sz,
171                                              vpx_codec_stream_info_t *si);
172 
173 
174   /*!\brief Return information about the current stream.
175    *
176    * Returns information about the stream that has been parsed during decoding.
177    *
178    * \param[in]      ctx     Pointer to this instance's context
179    * \param[in,out]  si      Pointer to stream info to update. The size member
180    *                         \ref MUST be properly initialized, but \ref MAY be
181    *                         clobbered by the algorithm. This parameter \ref MAY
182    *                         be NULL.
183    *
184    * \retval #VPX_CODEC_OK
185    *     Bitstream is parsable and stream information updated
186    */
187   vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t         *ctx,
188                                             vpx_codec_stream_info_t *si);
189 
190 
191   /*!\brief Decode data
192    *
193    * Processes a buffer of coded data. If the processing results in a new
194    * decoded frame becoming available, PUT_SLICE and PUT_FRAME events may be
195    * generated, as appropriate. Encoded data \ref MUST be passed in DTS (decode
196    * time stamp) order. Frames produced will always be in PTS (presentation
197    * time stamp) order.
198    * If the decoder is configured with VPX_CODEC_USE_INPUT_FRAGMENTS enabled,
199    * data and data_sz can contain a fragment of the encoded frame. Fragment
200    * \#n must contain at least partition \#n, but can also contain subsequent
201    * partitions (\#n+1 - \#n+i), and if so, fragments \#n+1, .., \#n+i must
202    * be empty. When no more data is available, this function should be called
203    * with NULL as data and 0 as data_sz. The memory passed to this function
204    * must be available until the frame has been decoded.
205    *
206    * \param[in] ctx          Pointer to this instance's context
207    * \param[in] data         Pointer to this block of new coded data. If
208    *                         NULL, a VPX_CODEC_CB_PUT_FRAME event is posted
209    *                         for the previously decoded frame.
210    * \param[in] data_sz      Size of the coded data, in bytes.
211    * \param[in] user_priv    Application specific data to associate with
212    *                         this frame.
213    * \param[in] deadline     Soft deadline the decoder should attempt to meet,
214    *                         in us. Set to zero for unlimited.
215    *
216    * \return Returns #VPX_CODEC_OK if the coded data was processed completely
217    *         and future pictures can be decoded without error. Otherwise,
218    *         see the descriptions of the other error codes in ::vpx_codec_err_t
219    *         for recoverability capabilities.
220    */
221   vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t    *ctx,
222                                    const uint8_t        *data,
223                                    unsigned int            data_sz,
224                                    void               *user_priv,
225                                    long                deadline);
226 
227 
228   /*!\brief Decoded frames iterator
229    *
230    * Iterates over a list of the frames available for display. The iterator
231    * storage should be initialized to NULL to start the iteration. Iteration is
232    * complete when this function returns NULL.
233    *
234    * The list of available frames becomes valid upon completion of the
235    * vpx_codec_decode call, and remains valid until the next call to vpx_codec_decode.
236    *
237    * \param[in]     ctx      Pointer to this instance's context
238    * \param[in,out] iter     Iterator storage, initialized to NULL
239    *
240    * \return Returns a pointer to an image, if one is ready for display. Frames
241    *         produced will always be in PTS (presentation time stamp) order.
242    */
243   vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t  *ctx,
244                                    vpx_codec_iter_t *iter);
245 
246 
247   /*!\defgroup cap_put_frame Frame-Based Decoding Functions
248    *
249    * The following functions are required to be implemented for all decoders
250    * that advertise the VPX_CODEC_CAP_PUT_FRAME capability. Calling these functions
251    * for codecs that don't advertise this capability will result in an error
252    * code being returned, usually VPX_CODEC_ERROR
253    * @{
254    */
255 
256   /*!\brief put frame callback prototype
257    *
258    * This callback is invoked by the decoder to notify the application of
259    * the availability of decoded image data.
260    */
261   typedef void (*vpx_codec_put_frame_cb_fn_t)(void        *user_priv,
262                                               const vpx_image_t *img);
263 
264 
265   /*!\brief Register for notification of frame completion.
266    *
267    * Registers a given function to be called when a decoded frame is
268    * available.
269    *
270    * \param[in] ctx          Pointer to this instance's context
271    * \param[in] cb           Pointer to the callback function
272    * \param[in] user_priv    User's private data
273    *
274    * \retval #VPX_CODEC_OK
275    *     Callback successfully registered.
276    * \retval #VPX_CODEC_ERROR
277    *     Decoder context not initialized, or algorithm not capable of
278    *     posting slice completion.
279    */
280   vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t             *ctx,
281                                                   vpx_codec_put_frame_cb_fn_t  cb,
282                                                   void                        *user_priv);
283 
284 
285   /*!@} - end defgroup cap_put_frame */
286 
287   /*!\defgroup cap_put_slice Slice-Based Decoding Functions
288    *
289    * The following functions are required to be implemented for all decoders
290    * that advertise the VPX_CODEC_CAP_PUT_SLICE capability. Calling these functions
291    * for codecs that don't advertise this capability will result in an error
292    * code being returned, usually VPX_CODEC_ERROR
293    * @{
294    */
295 
296   /*!\brief put slice callback prototype
297    *
298    * This callback is invoked by the decoder to notify the application of
299    * the availability of partially decoded image data. The
300    */
301   typedef void (*vpx_codec_put_slice_cb_fn_t)(void         *user_priv,
302                                               const vpx_image_t      *img,
303                                               const vpx_image_rect_t *valid,
304                                               const vpx_image_rect_t *update);
305 
306 
307   /*!\brief Register for notification of slice completion.
308    *
309    * Registers a given function to be called when a decoded slice is
310    * available.
311    *
312    * \param[in] ctx          Pointer to this instance's context
313    * \param[in] cb           Pointer to the callback function
314    * \param[in] user_priv    User's private data
315    *
316    * \retval #VPX_CODEC_OK
317    *     Callback successfully registered.
318    * \retval #VPX_CODEC_ERROR
319    *     Decoder context not initialized, or algorithm not capable of
320    *     posting slice completion.
321    */
322   vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t             *ctx,
323                                                   vpx_codec_put_slice_cb_fn_t  cb,
324                                                   void                        *user_priv);
325 
326 
327   /*!@} - end defgroup cap_put_slice*/
328 
329   /*!@} - end defgroup decoder*/
330 #ifdef __cplusplus
331 }
332 #endif
333 #endif
334 
335