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