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