vpx_encoder.h 35 KB

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