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