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