]> granicus.if.org Git - libvpx/blob - vpx/vpx_encoder.h
Merge "Simplify decode_macroblock."
[libvpx] / vpx / vpx_encoder.h
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
11
12 /*!\defgroup encoder Encoder Algorithm Interface
13  * \ingroup codec
14  * This abstraction allows applications using this encoder to easily support
15  * multiple video formats with minimal code duplication. This section describes
16  * the interface common to all encoders.
17  * @{
18  */
19
20 /*!\file
21  * \brief Describes the encoder algorithm interface to applications.
22  *
23  * This file describes the interface between an application and a
24  * video encoder algorithm.
25  *
26  */
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #ifndef VPX_ENCODER_H
32 #define VPX_ENCODER_H
33 #include "vpx_codec.h"
34
35
36     /*!\brief Current ABI version number
37      *
38      * \internal
39      * If this file is altered in any way that changes the ABI, this value
40      * must be bumped.  Examples include, but are not limited to, changing
41      * types, removing or reassigning enums, adding/removing/rearranging
42      * fields to structures
43      */
44 #define VPX_ENCODER_ABI_VERSION (2 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/
45
46
47     /*! \brief Encoder capabilities bitfield
48      *
49      *  Each encoder advertises the capabilities it supports as part of its
50      *  ::vpx_codec_iface_t interface structure. Capabilities are extra
51      *  interfaces or functionality, and are not required to be supported
52      *  by an encoder.
53      *
54      *  The available flags are specified by VPX_CODEC_CAP_* defines.
55      */
56 #define VPX_CODEC_CAP_PSNR  0x10000 /**< Can issue PSNR packets */
57
58     /*! Can output one partition at a time. Each partition is returned in its
59      *  own VPX_CODEC_CX_FRAME_PKT, with the FRAME_IS_FRAGMENT flag set for
60      *  every partition but the last. In this mode all frames are always
61      *  returned partition by partition.
62      */
63 #define VPX_CODEC_CAP_OUTPUT_PARTITION  0x20000
64
65
66     /*! \brief Initialization-time Feature Enabling
67      *
68      *  Certain codec features must be known at initialization time, to allow
69      *  for proper memory allocation.
70      *
71      *  The available flags are specified by VPX_CODEC_USE_* defines.
72      */
73 #define VPX_CODEC_USE_PSNR  0x10000 /**< Calculate PSNR on each frame */
74 #define VPX_CODEC_USE_OUTPUT_PARTITION  0x20000 /**< Make the encoder output one
75                                                      partition at a time. */
76
77
78     /*!\brief Generic fixed size buffer structure
79      *
80      * This structure is able to hold a reference to any fixed size buffer.
81      */
82     typedef struct vpx_fixed_buf
83     {
84         void          *buf; /**< Pointer to the data */
85         size_t         sz;  /**< Length of the buffer, in chars */
86     } vpx_fixed_buf_t; /**< alias for struct vpx_fixed_buf */
87
88
89     /*!\brief Time Stamp Type
90      *
91      * An integer, which when multiplied by the stream's time base, provides
92      * the absolute time of a sample.
93      */
94     typedef int64_t vpx_codec_pts_t;
95
96
97     /*!\brief Compressed Frame Flags
98      *
99      * This type represents a bitfield containing information about a compressed
100      * frame that may be useful to an application. The most significant 16 bits
101      * can be used by an algorithm to provide additional detail, for example to
102      * support frame types that are codec specific (MPEG-1 D-frames for example)
103      */
104     typedef uint32_t vpx_codec_frame_flags_t;
105 #define VPX_FRAME_IS_KEY       0x1 /**< frame is the start of a GOP */
106 #define VPX_FRAME_IS_DROPPABLE 0x2 /**< frame can be dropped without affecting
107     the stream (no future frame depends on
108                 this one) */
109 #define VPX_FRAME_IS_INVISIBLE 0x4 /**< frame should be decoded but will not
110     be shown */
111 #define VPX_FRAME_IS_FRAGMENT  0x8 /**< this is a fragment of the encoded
112     frame */
113
114     /*!\brief Error Resilient flags
115      *
116      * These flags define which error resilient features to enable in the
117      * encoder. The flags are specified through the
118      * vpx_codec_enc_cfg::g_error_resilient variable.
119      */
120     typedef uint32_t vpx_codec_er_flags_t;
121 #define VPX_ERROR_RESILIENT_DEFAULT     0x1 /**< Improve resiliency against
122                                                  losses of whole frames */
123 #define VPX_ERROR_RESILIENT_PARTITIONS  0x2 /**< The frame partitions are
124                                                  independently decodable by the
125                                                  bool decoder, meaning that
126                                                  partitions can be decoded even
127                                                  though earlier partitions have
128                                                  been lost. Note that intra
129                                                  predicition is still done over
130                                                  the partition boundary. */
131
132     /*!\brief Encoder output packet variants
133      *
134      * This enumeration lists the different kinds of data packets that can be
135      * returned by calls to vpx_codec_get_cx_data(). Algorithms \ref MAY
136      * extend this list to provide additional functionality.
137      */
138     enum vpx_codec_cx_pkt_kind
139     {
140         VPX_CODEC_CX_FRAME_PKT,    /**< Compressed video frame */
141         VPX_CODEC_STATS_PKT,       /**< Two-pass statistics for this frame */
142         VPX_CODEC_PSNR_PKT,        /**< PSNR statistics for this frame */
143         VPX_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions  */
144     };
145
146
147     /*!\brief Encoder output packet
148      *
149      * This structure contains the different kinds of output data the encoder
150      * may produce while compressing a frame.
151      */
152     typedef struct vpx_codec_cx_pkt
153     {
154         enum vpx_codec_cx_pkt_kind  kind; /**< packet variant */
155         union
156         {
157             struct
158             {
159                 void                    *buf;      /**< compressed data buffer */
160                 size_t                   sz;       /**< length of compressed data */
161                 vpx_codec_pts_t          pts;      /**< time stamp to show frame
162                                                     (in timebase units) */
163                 unsigned long            duration; /**< duration to show frame
164                                                     (in timebase units) */
165                 vpx_codec_frame_flags_t  flags;    /**< flags for this frame */
166                 int                      partition_id; /**< the partition id
167                                               defines the decoding order
168                                               of the partitions. Only
169                                               applicable when "output partition"
170                                               mode is enabled. First partition
171                                               has id 0.*/
172
173             } frame;  /**< data for compressed frame packet */
174             struct vpx_fixed_buf twopass_stats;  /**< data for two-pass packet */
175             struct vpx_psnr_pkt
176             {
177                 unsigned int samples[4];  /**< Number of samples, total/y/u/v */
178                 uint64_t     sse[4];      /**< sum squared error, total/y/u/v */
179                 double       psnr[4];     /**< PSNR, total/y/u/v */
180             } psnr;                       /**< data for PSNR packet */
181             struct vpx_fixed_buf raw;     /**< data for arbitrary packets */
182
183             /* This packet size is fixed to allow codecs to extend this
184              * interface without having to manage storage for raw packets,
185              * i.e., if it's smaller than 128 bytes, you can store in the
186              * packet list directly.
187              */
188             char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)]; /**< fixed sz */
189         } data; /**< packet data */
190     } vpx_codec_cx_pkt_t; /**< alias for struct vpx_codec_cx_pkt */
191
192
193     /*!\brief Rational Number
194      *
195      * This structure holds a fractional value.
196      */
197     typedef struct vpx_rational
198     {
199         int num; /**< fraction numerator */
200         int den; /**< fraction denominator */
201     } vpx_rational_t; /**< alias for struct vpx_rational */
202
203
204     /*!\brief Multi-pass Encoding Pass */
205     enum vpx_enc_pass
206     {
207         VPX_RC_ONE_PASS,   /**< Single pass mode */
208         VPX_RC_FIRST_PASS, /**< First pass of multi-pass mode */
209         VPX_RC_LAST_PASS   /**< Final pass of multi-pass mode */
210     };
211
212
213     /*!\brief Rate control mode */
214     enum vpx_rc_mode
215     {
216         VPX_VBR, /**< Variable Bit Rate (VBR) mode */
217         VPX_CBR,  /**< Constant Bit Rate (CBR) mode */
218         VPX_CQ   /**< Constant Quality  (CQ)  mode */
219     };
220
221
222     /*!\brief Keyframe placement mode.
223      *
224      * This enumeration determines whether keyframes are placed automatically by
225      * the encoder or whether this behavior is disabled. Older releases of this
226      * SDK were implemented such that VPX_KF_FIXED meant keyframes were disabled.
227      * This name is confusing for this behavior, so the new symbols to be used
228      * are VPX_KF_AUTO and VPX_KF_DISABLED.
229      */
230     enum vpx_kf_mode
231     {
232         VPX_KF_FIXED, /**< deprecated, implies VPX_KF_DISABLED */
233         VPX_KF_AUTO,  /**< Encoder determines optimal placement automatically */
234         VPX_KF_DISABLED = 0 /**< Encoder does not place keyframes. */
235     };
236
237
238     /*!\brief Encoded Frame Flags
239      *
240      * This type indicates a bitfield to be passed to vpx_codec_encode(), defining
241      * per-frame boolean values. By convention, bits common to all codecs will be
242      * named VPX_EFLAG_*, and bits specific to an algorithm will be named
243      * /algo/_eflag_*. The lower order 16 bits are reserved for common use.
244      */
245     typedef long vpx_enc_frame_flags_t;
246 #define VPX_EFLAG_FORCE_KF (1<<0)  /**< Force this frame to be a keyframe */
247
248
249     /*!\brief Encoder configuration structure
250      *
251      * This structure contains the encoder settings that have common representations
252      * across all codecs. This doesn't imply that all codecs support all features,
253      * however.
254      */
255     typedef struct vpx_codec_enc_cfg
256     {
257         /*
258          * generic settings (g)
259          */
260
261         /*!\brief Algorithm specific "usage" value
262          *
263          * Algorithms may define multiple values for usage, which may convey the
264          * intent of how the application intends to use the stream. If this value
265          * is non-zero, consult the documentation for the codec to determine its
266          * meaning.
267          */
268         unsigned int           g_usage;
269
270
271         /*!\brief Maximum number of threads to use
272          *
273          * For multi-threaded implementations, use no more than this number of
274          * threads. The codec may use fewer threads than allowed. The value
275          * 0 is equivalent to the value 1.
276          */
277         unsigned int           g_threads;
278
279
280         /*!\brief Bitstream profile to use
281          *
282          * Some codecs support a notion of multiple bitstream profiles. Typically
283          * this maps to a set of features that are turned on or off. Often the
284          * profile to use is determined by the features of the intended decoder.
285          * Consult the documentation for the codec to determine the valid values
286          * for this parameter, or set to zero for a sane default.
287          */
288         unsigned int           g_profile;  /**< profile of bitstream to use */
289
290
291
292         /*!\brief Width of the frame
293          *
294          * This value identifies the presentation resolution of the frame,
295          * in pixels. Note that the frames passed as input to the encoder must
296          * have this resolution. Frames will be presented by the decoder in this
297          * resolution, independent of any spatial resampling the encoder may do.
298          */
299         unsigned int           g_w;
300
301
302         /*!\brief Height of the frame
303          *
304          * This value identifies the presentation resolution of the frame,
305          * in pixels. Note that the frames passed as input to the encoder must
306          * have this resolution. Frames will be presented by the decoder in this
307          * resolution, independent of any spatial resampling the encoder may do.
308          */
309         unsigned int           g_h;
310
311
312         /*!\brief Stream timebase units
313          *
314          * Indicates the smallest interval of time, in seconds, used by the stream.
315          * For fixed frame rate material, or variable frame rate material where
316          * frames are timed at a multiple of a given clock (ex: video capture),
317          * the \ref RECOMMENDED method is to set the timebase to the reciprocal
318          * of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the
319          * pts to correspond to the frame number, which can be handy. For
320          * re-encoding video from containers with absolute time timestamps, the
321          * \ref RECOMMENDED method is to set the timebase to that of the parent
322          * container or multimedia framework (ex: 1/1000 for ms, as in FLV).
323          */
324         struct vpx_rational    g_timebase;
325
326
327         /*!\brief Enable error resilient modes.
328          *
329          * The error resilient bitfield indicates to the encoder which features
330          * it should enable to take measures for streaming over lossy or noisy
331          * links.
332          */
333         vpx_codec_er_flags_t   g_error_resilient;
334
335
336         /*!\brief Multi-pass Encoding Mode
337          *
338          * This value should be set to the current phase for multi-pass encoding.
339          * For single pass, set to #VPX_RC_ONE_PASS.
340          */
341         enum vpx_enc_pass      g_pass;
342
343
344         /*!\brief Allow lagged encoding
345          *
346          * If set, this value allows the encoder to consume a number of input
347          * frames before producing output frames. This allows the encoder to
348          * base decisions for the current frame on future frames. This does
349          * increase the latency of the encoding pipeline, so it is not appropriate
350          * in all situations (ex: realtime encoding).
351          *
352          * Note that this is a maximum value -- the encoder may produce frames
353          * sooner than the given limit. Set this value to 0 to disable this
354          * feature.
355          */
356         unsigned int           g_lag_in_frames;
357
358
359         /*
360          * rate control settings (rc)
361          */
362
363         /*!\brief Temporal resampling configuration, if supported by the codec.
364          *
365          * Temporal resampling allows the codec to "drop" frames as a strategy to
366          * meet its target data rate. This can cause temporal discontinuities in
367          * the encoded video, which may appear as stuttering during playback. This
368          * trade-off is often acceptable, but for many applications is not. It can
369          * be disabled in these cases.
370          *
371          * Note that not all codecs support this feature. All vpx VPx codecs do.
372          * For other codecs, consult the documentation for that algorithm.
373          *
374          * This threshold is described as a percentage of the target data buffer.
375          * When the data buffer falls below this percentage of fullness, a
376          * dropped frame is indicated. Set the threshold to zero (0) to disable
377          * this feature.
378          */
379         unsigned int           rc_dropframe_thresh;
380
381
382         /*!\brief Enable/disable spatial resampling, if supported by the codec.
383          *
384          * Spatial resampling allows the codec to compress a lower resolution
385          * version of the frame, which is then upscaled by the encoder to the
386          * correct presentation resolution. This increases visual quality at
387          * low data rates, at the expense of CPU time on the encoder/decoder.
388          */
389         unsigned int           rc_resize_allowed;
390
391
392         /*!\brief Spatial resampling up watermark.
393          *
394          * This threshold is described as a percentage of the target data buffer.
395          * When the data buffer rises above this percentage of fullness, the
396          * encoder will step up to a higher resolution version of the frame.
397          */
398         unsigned int           rc_resize_up_thresh;
399
400
401         /*!\brief Spatial resampling down watermark.
402          *
403          * This threshold is described as a percentage of the target data buffer.
404          * When the data buffer falls below this percentage of fullness, the
405          * encoder will step down to a lower resolution version of the frame.
406          */
407         unsigned int           rc_resize_down_thresh;
408
409
410         /*!\brief Rate control algorithm to use.
411          *
412          * Indicates whether the end usage of this stream is to be streamed over
413          * a bandwidth constrained link, indicating that Constant Bit Rate (CBR)
414          * mode should be used, or whether it will be played back on a high
415          * bandwidth link, as from a local disk, where higher variations in
416          * bitrate are acceptable.
417          */
418         enum vpx_rc_mode       rc_end_usage;
419
420
421         /*!\brief Two-pass stats buffer.
422          *
423          * A buffer containing all of the stats packets produced in the first
424          * pass, concatenated.
425          */
426         struct vpx_fixed_buf   rc_twopass_stats_in;
427
428
429         /*!\brief Target data rate
430          *
431          * Target bandwidth to use for this stream, in kilobits per second.
432          */
433         unsigned int           rc_target_bitrate;
434
435
436         /*!\brief Max data rate for Intra frames
437          *
438          * This value controls additional clamping on the maximum size of a
439          * keyframe. It is expressed as a percentage of the average
440          * per-frame bitrate, with the special (and default) value 0 meaning
441          * unlimited, or no additional clamping beyond the codec's built-in
442          * algorithm.
443          *
444          * For example, to allocate no more than 4.5 frames worth of bitrate
445          * to a keyframe, set this to 450.
446          *
447          */
448         unsigned int           rc_max_intra_bitrate_pct;
449
450
451         /*
452          * quantizer settings
453          */
454
455
456         /*!\brief Minimum (Best Quality) Quantizer
457          *
458          * The quantizer is the most direct control over the quality of the
459          * encoded image. The range of valid values for the quantizer is codec
460          * specific. Consult the documentation for the codec to determine the
461          * values to use. To determine the range programmatically, call
462          * vpx_codec_enc_config_default() with a usage value of 0.
463          */
464         unsigned int           rc_min_quantizer;
465
466
467         /*!\brief Maximum (Worst Quality) Quantizer
468          *
469          * The quantizer is the most direct control over the quality of the
470          * encoded image. The range of valid values for the quantizer is codec
471          * specific. Consult the documentation for the codec to determine the
472          * values to use. To determine the range programmatically, call
473          * vpx_codec_enc_config_default() with a usage value of 0.
474          */
475         unsigned int           rc_max_quantizer;
476
477
478         /*
479          * bitrate tolerance
480          */
481
482
483         /*!\brief Rate control adaptation undershoot control
484          *
485          * This value, expressed as a percentage of the target bitrate,
486          * controls the maximum allowed adaptation speed of the codec.
487          * This factor controls the maximum amount of bits that can
488          * be subtracted from the target bitrate in order to compensate
489          * for prior overshoot.
490          *
491          * Valid values in the range 0-1000.
492          */
493         unsigned int           rc_undershoot_pct;
494
495
496         /*!\brief Rate control adaptation overshoot control
497          *
498          * This value, expressed as a percentage of the target bitrate,
499          * controls the maximum allowed adaptation speed of the codec.
500          * This factor controls the maximum amount of bits that can
501          * be added to the target bitrate in order to compensate for
502          * prior undershoot.
503          *
504          * Valid values in the range 0-1000.
505          */
506         unsigned int           rc_overshoot_pct;
507
508
509         /*
510          * decoder buffer model parameters
511          */
512
513
514         /*!\brief Decoder Buffer Size
515          *
516          * This value indicates the amount of data that may be buffered by the
517          * decoding application. Note that this value is expressed in units of
518          * time (milliseconds). For example, a value of 5000 indicates that the
519          * client will buffer (at least) 5000ms worth of encoded data. Use the
520          * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
521          * necessary.
522          */
523         unsigned int           rc_buf_sz;
524
525
526         /*!\brief Decoder Buffer Initial Size
527          *
528          * This value indicates the amount of data that will be buffered by the
529          * decoding application prior to beginning playback. This value is
530          * expressed in units of time (milliseconds). Use the target bitrate
531          * (#rc_target_bitrate) to convert to bits/bytes, if necessary.
532          */
533         unsigned int           rc_buf_initial_sz;
534
535
536         /*!\brief Decoder Buffer Optimal Size
537          *
538          * This value indicates the amount of data that the encoder should try
539          * to maintain in the decoder's buffer. This value is expressed in units
540          * of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
541          * to convert to bits/bytes, if necessary.
542          */
543         unsigned int           rc_buf_optimal_sz;
544
545
546         /*
547          * 2 pass rate control parameters
548          */
549
550
551         /*!\brief Two-pass mode CBR/VBR bias
552          *
553          * Bias, expressed on a scale of 0 to 100, for determining target size
554          * for the current frame. The value 0 indicates the optimal CBR mode
555          * value should be used. The value 100 indicates the optimal VBR mode
556          * value should be used. Values in between indicate which way the
557          * encoder should "lean."
558          */
559         unsigned int           rc_2pass_vbr_bias_pct;       /**< RC mode bias between CBR and VBR(0-100: 0->CBR, 100->VBR)   */
560
561
562         /*!\brief Two-pass mode per-GOP minimum bitrate
563          *
564          * This value, expressed as a percentage of the target bitrate, indicates
565          * the minimum bitrate to be used for a single GOP (aka "section")
566          */
567         unsigned int           rc_2pass_vbr_minsection_pct;
568
569
570         /*!\brief Two-pass mode per-GOP maximum bitrate
571          *
572          * This value, expressed as a percentage of the target bitrate, indicates
573          * the maximum bitrate to be used for a single GOP (aka "section")
574          */
575         unsigned int           rc_2pass_vbr_maxsection_pct;
576
577
578         /*
579          * keyframing settings (kf)
580          */
581
582         /*!\brief Keyframe placement mode
583          *
584          * This value indicates whether the encoder should place keyframes at a
585          * fixed interval, or determine the optimal placement automatically
586          * (as governed by the #kf_min_dist and #kf_max_dist parameters)
587          */
588         enum vpx_kf_mode       kf_mode;
589
590
591         /*!\brief Keyframe minimum interval
592          *
593          * This value, expressed as a number of frames, prevents the encoder from
594          * placing a keyframe nearer than kf_min_dist to the previous keyframe. At
595          * least kf_min_dist frames non-keyframes will be coded before the next
596          * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval.
597          */
598         unsigned int           kf_min_dist;
599
600
601         /*!\brief Keyframe maximum interval
602          *
603          * This value, expressed as a number of frames, forces the encoder to code
604          * a keyframe if one has not been coded in the last kf_max_dist frames.
605          * A value of 0 implies all frames will be keyframes. Set kf_min_dist
606          * equal to kf_max_dist for a fixed interval.
607          */
608         unsigned int           kf_max_dist;
609
610     } vpx_codec_enc_cfg_t; /**< alias for struct vpx_codec_enc_cfg */
611
612
613     /*!\brief Initialize an encoder instance
614      *
615      * Initializes a encoder context using the given interface. Applications
616      * should call the vpx_codec_enc_init convenience macro instead of this
617      * function directly, to ensure that the ABI version number parameter
618      * is properly initialized.
619      *
620      * In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags
621      * parameter), the storage pointed to by the cfg parameter must be
622      * kept readable and stable until all memory maps have been set.
623      *
624      * \param[in]    ctx     Pointer to this instance's context.
625      * \param[in]    iface   Pointer to the algorithm interface to use.
626      * \param[in]    cfg     Configuration to use, if known. May be NULL.
627      * \param[in]    flags   Bitfield of VPX_CODEC_USE_* flags
628      * \param[in]    ver     ABI version number. Must be set to
629      *                       VPX_ENCODER_ABI_VERSION
630      * \retval #VPX_CODEC_OK
631      *     The decoder algorithm initialized.
632      * \retval #VPX_CODEC_MEM_ERROR
633      *     Memory allocation failed.
634      */
635     vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t      *ctx,
636                                            vpx_codec_iface_t    *iface,
637                                            vpx_codec_enc_cfg_t  *cfg,
638                                            vpx_codec_flags_t     flags,
639                                            int                   ver);
640
641
642     /*!\brief Convenience macro for vpx_codec_enc_init_ver()
643      *
644      * Ensures the ABI version parameter is properly set.
645      */
646 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
647     vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
648
649
650     /*!\brief Get a default configuration
651      *
652      * Initializes a encoder configuration structure with default values. Supports
653      * the notion of "usages" so that an algorithm may offer different default
654      * settings depending on the user's intended goal. This function \ref SHOULD
655      * be called by all applications to initialize the configuration structure
656      * before specializing the configuration with application specific values.
657      *
658      * \param[in]    iface   Pointer to the algorithm interface to use.
659      * \param[out]   cfg     Configuration buffer to populate
660      * \param[in]    usage   End usage. Set to 0 or use codec specific values.
661      *
662      * \retval #VPX_CODEC_OK
663      *     The configuration was populated.
664      * \retval #VPX_CODEC_INCAPABLE
665      *     Interface is not an encoder interface.
666      * \retval #VPX_CODEC_INVALID_PARAM
667      *     A parameter was NULL, or the usage value was not recognized.
668      */
669     vpx_codec_err_t  vpx_codec_enc_config_default(vpx_codec_iface_t    *iface,
670             vpx_codec_enc_cfg_t  *cfg,
671             unsigned int          usage);
672
673
674     /*!\brief Set or change configuration
675      *
676      * Reconfigures an encoder instance according to the given configuration.
677      *
678      * \param[in]    ctx     Pointer to this instance's context
679      * \param[in]    cfg     Configuration buffer to use
680      *
681      * \retval #VPX_CODEC_OK
682      *     The configuration was populated.
683      * \retval #VPX_CODEC_INCAPABLE
684      *     Interface is not an encoder interface.
685      * \retval #VPX_CODEC_INVALID_PARAM
686      *     A parameter was NULL, or the usage value was not recognized.
687      */
688     vpx_codec_err_t  vpx_codec_enc_config_set(vpx_codec_ctx_t            *ctx,
689             const vpx_codec_enc_cfg_t  *cfg);
690
691
692     /*!\brief Get global stream headers
693      *
694      * Retrieves a stream level global header packet, if supported by the codec.
695      *
696      * \param[in]    ctx     Pointer to this instance's context
697      *
698      * \retval NULL
699      *     Encoder does not support global header
700      * \retval Non-NULL
701      *     Pointer to buffer containing global header packet
702      */
703     vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t   *ctx);
704
705
706 #define VPX_DL_REALTIME     (1)        /**< deadline parameter analogous to
707     *   VPx REALTIME mode. */
708 #define VPX_DL_GOOD_QUALITY (1000000)  /**< deadline parameter analogous to
709     *   VPx GOOD QUALITY mode. */
710 #define VPX_DL_BEST_QUALITY (0)        /**< deadline parameter analogous to
711     *   VPx BEST QUALITY mode. */
712     /*!\brief Encode a frame
713      *
714      * Encodes a video frame at the given "presentation time." The presentation
715      * time stamp (PTS) \ref MUST be strictly increasing.
716      *
717      * The encoder supports the notion of a soft real-time deadline. Given a
718      * non-zero value to the deadline parameter, the encoder will make a "best
719      * effort" guarantee to  return before the given time slice expires. It is
720      * implicit that limiting the available time to encode will degrade the
721      * output quality. The encoder can be given an unlimited time to produce the
722      * best possible frame by specifying a deadline of '0'. This deadline
723      * supercedes the VPx notion of "best quality, good quality, realtime".
724      * Applications that wish to map these former settings to the new deadline
725      * based system can use the symbols #VPX_DL_REALTIME, #VPX_DL_GOOD_QUALITY,
726      * and #VPX_DL_BEST_QUALITY.
727      *
728      * When the last frame has been passed to the encoder, this function should
729      * continue to be called, with the img parameter set to NULL. This will
730      * signal the end-of-stream condition to the encoder and allow it to encode
731      * any held buffers. Encoding is complete when vpx_codec_encode() is called
732      * and vpx_codec_get_cx_data() returns no data.
733      *
734      * \param[in]    ctx       Pointer to this instance's context
735      * \param[in]    img       Image data to encode, NULL to flush.
736      * \param[in]    pts       Presentation time stamp, in timebase units.
737      * \param[in]    duration  Duration to show frame, in timebase units.
738      * \param[in]    flags     Flags to use for encoding this frame.
739      * \param[in]    deadline  Time to spend encoding, in microseconds. (0=infinite)
740      *
741      * \retval #VPX_CODEC_OK
742      *     The configuration was populated.
743      * \retval #VPX_CODEC_INCAPABLE
744      *     Interface is not an encoder interface.
745      * \retval #VPX_CODEC_INVALID_PARAM
746      *     A parameter was NULL, the image format is unsupported, etc.
747      */
748     vpx_codec_err_t  vpx_codec_encode(vpx_codec_ctx_t            *ctx,
749                                       const vpx_image_t          *img,
750                                       vpx_codec_pts_t             pts,
751                                       unsigned long               duration,
752                                       vpx_enc_frame_flags_t       flags,
753                                       unsigned long               deadline);
754
755
756     /*!\brief Set compressed data output buffer
757      *
758      * Sets the buffer that the codec should output the compressed data
759      * into. This call effectively sets the buffer pointer returned in the
760      * next VPX_CODEC_CX_FRAME_PKT packet. Subsequent packets will be
761      * appended into this buffer. The buffer is preserved across frames,
762      * so applications must periodically call this function after flushing
763      * the accumulated compressed data to disk or to the network to reset
764      * the pointer to the buffer's head.
765      *
766      * `pad_before` bytes will be skipped before writing the compressed
767      * data, and `pad_after` bytes will be appended to the packet. The size
768      * of the packet will be the sum of the size of the actual compressed
769      * data, pad_before, and pad_after. The padding bytes will be preserved
770      * (not overwritten).
771      *
772      * Note that calling this function does not guarantee that the returned
773      * compressed data will be placed into the specified buffer. In the
774      * event that the encoded data will not fit into the buffer provided,
775      * the returned packet \ref MAY point to an internal buffer, as it would
776      * if this call were never used. In this event, the output packet will
777      * NOT have any padding, and the application must free space and copy it
778      * to the proper place. This is of particular note in configurations
779      * that may output multiple packets for a single encoded frame (e.g., lagged
780      * encoding) or if the application does not reset the buffer periodically.
781      *
782      * Applications may restore the default behavior of the codec providing
783      * the compressed data buffer by calling this function with a NULL
784      * buffer.
785      *
786      * Applications \ref MUSTNOT call this function during iteration of
787      * vpx_codec_get_cx_data().
788      *
789      * \param[in]    ctx         Pointer to this instance's context
790      * \param[in]    buf         Buffer to store compressed data into
791      * \param[in]    pad_before  Bytes to skip before writing compressed data
792      * \param[in]    pad_after   Bytes to skip after writing compressed data
793      *
794      * \retval #VPX_CODEC_OK
795      *     The buffer was set successfully.
796      * \retval #VPX_CODEC_INVALID_PARAM
797      *     A parameter was NULL, the image format is unsupported, etc.
798      */
799     vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t       *ctx,
800             const vpx_fixed_buf_t *buf,
801             unsigned int           pad_before,
802             unsigned int           pad_after);
803
804
805     /*!\brief Encoded data iterator
806      *
807      * Iterates over a list of data packets to be passed from the encoder to the
808      * application. The different kinds of packets available are enumerated in
809      * #vpx_codec_cx_pkt_kind.
810      *
811      * #VPX_CODEC_CX_FRAME_PKT packets should be passed to the application's
812      * muxer. Multiple compressed frames may be in the list.
813      * #VPX_CODEC_STATS_PKT packets should be appended to a global buffer.
814      *
815      * The application \ref MUST silently ignore any packet kinds that it does
816      * not recognize or support.
817      *
818      * The data buffers returned from this function are only guaranteed to be
819      * valid until the application makes another call to any vpx_codec_* function.
820      *
821      * \param[in]     ctx      Pointer to this instance's context
822      * \param[in,out] iter     Iterator storage, initialized to NULL
823      *
824      * \return Returns a pointer to an output data packet (compressed frame data,
825      *         two-pass statistics, etc.) or NULL to signal end-of-list.
826      *
827      */
828     const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t   *ctx,
829             vpx_codec_iter_t  *iter);
830
831
832     /*!\brief Get Preview Frame
833      *
834      * Returns an image that can be used as a preview. Shows the image as it would
835      * exist at the decompressor. The application \ref MUST NOT write into this
836      * image buffer.
837      *
838      * \param[in]     ctx      Pointer to this instance's context
839      *
840      * \return Returns a pointer to a preview image, or NULL if no image is
841      *         available.
842      *
843      */
844     const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t   *ctx);
845
846
847     /*!@} - end defgroup encoder*/
848
849 #endif
850 #ifdef __cplusplus
851 }
852 #endif