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