vpx_rs/enc/ctrl.rs
1/*
2 * Copyright (c) 2025, Saso Kiselkov. All rights reserved.
3 *
4 * Use of this source code is governed by the 2-clause BSD license,
5 * which can be found in a file named LICENSE, located at the root
6 * of this source tree.
7 */
8
9use crate::{call_vpx, Error, Result};
10
11/// Encapsulates the vp8e_enc_control_id values with their associated argument
12/// types to provide enhanced type safety. Enum values prefixed with the
13/// respective codec type (`Vp8` or `Vp9`) are codec-specific. Values without
14/// the prefix apply to all codecs.
15///
16/// <div class="warning">Attempting to set a control on the wrong codec type
17/// will result in an error.</div>
18#[derive(Clone, Debug)]
19pub enum EncoderControlSet<'a> {
20    /**
21     * Codec control function to pass an ROI map to encoder.
22     *
23     * Supported in codecs: VP8                                    
24     */
25    Vp8RoiMap(&'a vpx_sys::vpx_roi_map),
26    /**
27     * Codec control function to pass an Active map to encoder.
28     *
29     * Supported in codecs: VP8, VP9
30     */
31    ActiveMap(&'a vpx_sys::vpx_active_map),
32    /**
33     * Codec control function to set encoder scaling mode.
34     *
35     * Supported in codecs: VP8, VP9
36     */
37    ScaleMode(vpx_sys::vpx_scaling_mode),
38    /**
39     * Codec control function to set encoder internal speed settings.
40     *
41     * Changes in this value influences, among others, the encoder's selection
42     * of motion estimation methods. Values greater than 0 will increase
43     * encoder speed at the expense of quality.
44     *
45     * - Note: Valid range for VP8: -16..16
46     * - Note: Valid range for VP9: -9..9
47     * - Note: A negative value (-n) is treated as its absolute value (n) in
48     *   VP9.
49     *
50     * Supported in codecs: VP8, VP9
51     */
52    CpuUsed(i32),
53    /**
54     * Codec control function to enable automatic use of arf frames.
55     *
56     * - Note: Valid range for VP8: 0..1
57     * - Note: Valid range for VP9: 0..6
58     *
59     * Supported in codecs: VP8, VP9
60     */
61    EnableAutoAltRef(u32),
62    /**
63     * control function to set noise sensitivity
64     *
65     * Supported in codecs: VP8
66     */
67    Vp8NoiseSensitivity(Vp8NoiseSensitivity),
68    /**
69     * Codec control function to set higher sharpness at the expense
70     * of a lower PSNR.
71     *
72     * - Note: Valid range: 0..7
73     *
74     * Supported in codecs: VP8, VP9
75     */
76    Sharpness(u32),
77    /**
78     * Codec control function to set the threshold for MBs treated static.
79     *
80     * Supported in codecs: VP8, VP9
81     */
82    StaticThreshold(u32),
83    /**
84     * Codec control function to set the number of token partitions.
85     *
86     * Supported in codecs: VP8
87     */
88    Vp8TokenPartitions(vpx_sys::vp8e_token_partitions),
89    /**
90     * Codec control function to set the max no of frames to create arf.
91     *
92     * Supported in codecs: VP8, VP9
93     */
94    ARNRMaxFrames(u32),
95    /**
96     * Codec control function to set the filter strength for the arf.
97     *
98     * Supported in codecs: VP8, VP9
99     */
100    ARNRStrength(u32),
101    /**
102     * Codec control function to set visual tuning.
103     *
104     * Supported in codecs: VP8, VP9
105     */
106    Tuning(vpx_sys::vp8e_tuning),
107    /**
108     * Codec control function to set constrained / constant quality level.
109     *
110     * <div class="warning">
111     *
112     * For this value to be used, you must construct
113     * the encoder with [`super::EncoderConfig::rate_control`]
114     * set to [`super::RateControl::ConstrainedQuality`] or
115     * [`super::RateControl::ConstantQuality`].
116     *
117     * </div>
118     *
119     * Note: Valid range: 0..63
120     *
121     * Supported in codecs: VP8, VP9
122     */
123    CQLevel(u32),
124    /**
125     * Codec control function to set Max data rate for Intra frames.
126     *
127     * This value controls additional clamping on the maximum size of a
128     * keyframe. It is expressed as a percentage of the average
129     * per-frame bitrate, with the special (and default) value 0 meaning
130     * unlimited, or no additional clamping beyond the codec's built-in
131     * algorithm.
132     *
133     * For example, to allocate no more than 4.5 frames worth of bitrate
134     * to a keyframe, set this to 450.
135     *
136     * Supported in codecs: VP8, VP9
137     */
138    MaxIntraBitratePct(u32),
139    /**
140     * Codec control function to set reference and update frame flags.
141     *
142     *  Supported in codecs: VP8
143     */
144    Vp8FrameFlags(i32),
145    /**
146     * Codec control function to set max data rate for Inter frames.
147     *
148     * This value controls additional clamping on the maximum size of an
149     * inter frame. It is expressed as a percentage of the average
150     * per-frame bitrate, with the special (and default) value 0 meaning
151     * unlimited, or no additional clamping beyond the codec's built-in
152     * algorithm.
153     *
154     * For example, to allow no more than 4.5 frames worth of bitrate
155     * to an inter frame, set this to 450.
156     *
157     * Supported in codecs: VP9
158     */
159    Vp9MaxInterBitratePct(u32),
160    /**
161     * Boost percentage for Golden Frame in CBR mode.
162     *
163     * This value controls the amount of boost given to Golden Frame in
164     * CBR mode. It is expressed as a percentage of the average
165     * per-frame bitrate, with the special (and default) value 0 meaning
166     * the feature is off, i.e., no golden frame boost in CBR mode and
167     * average bitrate target is used.
168     *
169     * For example, to allow 100% more bits, i.e., 2X, in a golden frame
170     * than average frame, set this to 100.
171     *
172     * Supported in codecs: VP9
173     */
174    Vp9GoldenFrameCBRBoostPct(u32),
175    /**
176     * Codec control function to set the temporal layer id.
177     *
178     * For temporal scalability: this control allows the application to set
179     * the layer id for each frame to be encoded. Note that this control must
180     * be set for every frame prior to encoding. The usage of this control
181     * function supersedes the internal temporal pattern counter, which is
182     * now deprecated.
183     *
184     * Supported in codecs: VP8
185     */
186    Vp8TemporalLayerID(i32),
187    /**
188     * Codec control function to set encoder screen content mode.
189     *
190     * Supported in codecs: VP8
191     */
192    Vp8ScreenContentMode(Vp8ScreenContentMode),
193    /**
194     * Codec control function to set encoding mode.
195     *
196     * VP9 can operate in lossless encoding mode, in which the bitstream
197     * produced will be able to decode and reconstruct a perfect copy of
198     * input source. This control function provides a mean to switch encoder
199     * into lossless coding mode or normal coding mode that may be lossy.
200     *
201     * By default, encoder operates in normal coding mode (lossy).
202     *
203     * Supported in codecs: VP9
204     */
205    Vp9CodingMode(Vp9CodingMode),
206    /**
207     * Codec control function to set number of tile columns.
208     *
209     * In encoding and decoding, VP9 allows an input image frame be partitioned
210     * into separated vertical tile columns, which can be encoded or decoded
211     * independently. This enables easy implementation of parallel encoding and
212     * decoding. This control requests the encoder to use column tiles in
213     * encoding an input frame, with number of tile columns (in Log2 unit) as
214     * the parameter:
215     *
216     * - 0 = 1 tile column
217     * - 1 = 2 tile columns
218     * - 2 = 4 tile columns
219     * - .....
220     * - n = 2<sup>n</sup> tile columns
221     *
222     * The requested tile columns will be capped by the encoder based on image
223     * size limitations (The minimum width of a tile column is 256 pixels, the
224     * maximum is 4096).
225     *
226     * By default, the value is 6, i.e., the maximum number of tiles supported
227     * by the resolution.
228     *
229     * Supported in codecs: VP9
230     */
231    Vp9TileColumns(u32),
232    /**
233     * Codec control function to set number of tile rows.
234     *
235     * In encoding and decoding, VP9 allows an input image frame be partitioned
236     * into separated horizontal tile rows. Tile rows are encoded or decoded
237     * sequentially. Even though encoding/decoding of later tile rows depends
238     * on earlier ones, this allows the encoder to output data packets for tile
239     * rows prior to completely processing all tile rows in a frame, thereby
240     * reducing the latency in processing between input and output. The
241     * parameter for this control describes the number of tile rows, which has
242     * a valid range [0, 2]:
243     *
244     * - 0 = 1 tile row
245     * - 1 = 2 tile rows
246     * - 2 = 4 tile rows
247     *
248     * By default, the value is 0, i.e. one single row tile for entire image.
249     *
250     * Supported in codecs: VP9
251     */
252    Vp9TileRows(u32),
253    /**
254     * Codec control function to enable frame parallel decoding feature.
255     *
256     * VP9 has a bitstream feature to reduce decoding dependency between frames
257     * by turning off backward update of probability context used in encoding
258     * and decoding. This allows staged parallel processing of more than one
259     * video frame in the decoder. This control function provides a means to
260     * turn this feature on or off for bitstreams produced by encoder.
261     *
262     * By default, this feature is on.
263     *
264     * Supported in codecs: VP9
265     */
266    Vp9FrameParallelDecoding(bool),
267    /**
268     * Codec control function to set adaptive quantization mode.
269     *
270     * VP9 has a segment based feature that allows encoder to adaptively change
271     * quantization parameter for each segment within a frame to improve the
272     * subjective quality. This control makes encoder operate in one of the
273     * several AQ_modes supported.
274     *
275     * By default, encoder operates with AQ_Mode 0(adaptive quantization off).
276     *
277     * Supported in codecs: VP9
278     */
279    Vp9AQMode(Vp9AQMode),
280    /**
281     * Codec control function to enable/disable periodic Q boost.
282     *
283     * One VP9 encoder speed feature is to enable quality boost by lowering
284     * frame level Q periodically. This control function provides a mean to
285     * turn on/off this feature.
286     *
287     * By default, the encoder is allowed to use this feature for appropriate
288     * encoding modes.
289     *
290     * Supported in codecs: VP9
291     */
292    Vp9FramePeriodicBoost(bool),
293    /**
294     * Codec control function to set noise sensitivity.
295     *
296     * Supported in codecs: VP9
297     */
298    Vp9NoiseSensitivity(Vp9NoiseSensitivity),
299    /**
300     * Codec control function to turn on/off SVC in encoder.
301     *
302     * Note: Returns an error if the encoder does not support SVC in its
303     * current encoding mode
304     *
305     * Supported in codecs: VP9
306     */
307    Vp9Svc(bool),
308    /**
309     * Codec control function to pass an ROI map to encoder.
310     *
311     * Supported in codecs: VP9
312     */
313    Vp9RoiMap(Option<&'a vpx_sys::vpx_roi_map>),
314    // VP9E_SET_SVC_PARAMETERS and VP9E_SET_SVC_LAYER_ID intentionally skipped
315    // for lack of clarity of the parameter data types and how to make them
316    // at least reasonably work in Rust.
317    /**
318     * Codec control function to set content type.
319     *
320     * Supported in codecs: VP9
321     */
322    Vp9TuneContent(Vp9TuneContent),
323    /**
324     * Codec control function to set color space info.
325     *
326     * Supported in codecs: VP9
327     */
328    Vp9ColorSpace(vpx_sys::vpx_color_space),
329    /**
330     * Codec control function to set minimum interval between GF/ARF frames.
331     *
332     * By default the value is set as 4.
333     *
334     * Supported in codecs: VP9
335     */
336    Vp9MinGFInterval(u32),
337    /**
338     * Codec control function to set miximum interval between GF/ARF frames.
339     *
340     * By default the value is set as 16.
341     *
342     * Supported in codecs: VP9
343     */
344    Vp9MaxGFInterval(u32),
345    /**
346     * Codec control function to set color range bit.
347     * Supported in codecs: VP9
348     */
349    Vp9ColorRange(Vp9ColorRange),
350    /**
351     * Codec control function to set the frame flags and buffer indices
352     * for spatial layers. The frame flags and buffer indices are set using the
353     * struct #vpx_svc_ref_frame_config defined below.
354     *
355     * Supported in codecs: VP9
356     */
357    Vp9SvcRefFrameConfig(&'a vpx_sys::vpx_svc_ref_frame_config),
358    /**
359     * Codec control function to set intended rendering image size
360     *
361     * By default, this is identical to the image size in pixels.
362     *
363     * Supported in codecs: VP9
364     */
365    Vp9RenderSize {
366        /// Rendering image width in pixels.
367        width: i32,
368        /// Rendering image height in pixels.
369        height: i32,
370    },
371    /**
372     * Codec control function to set target level.
373     *
374     * - 255: off (default)
375     * - 0: only keep level stats
376     * - 10: target for level 1.0
377     * - 11: target for level 1.1
378     * - ...
379     * - 62: target for level 6.2
380     *
381     * Supported in codecs: VP9
382     */
383    Vp9TargetLevel(u8),
384    /**
385     * Codec control function to set row level multi-threading.
386     *
387     * Supported in codecs: VP9
388     */
389    Vp9RowMT(bool),
390    /**
391     * Codec control function to enable/disable special mode for altref
392     * adaptive quantization. You can use it with --aq-mode concurrently.
393     *
394     * Enable special adaptive quantization for altref frames based on their
395     * expected prediction quality for the future frames.
396     *
397     * Supported in codecs: VP9
398     */
399    Vp9AltRefAQ(bool),
400    /**
401     * Boost percentage for Golden Frame in CBR mode.
402     *
403     * This value controls the amount of boost given to Golden Frame in
404     * CBR mode. It is expressed as a percentage of the average
405     * per-frame bitrate, with the special (and default) value 0 meaning
406     * the feature is off, i.e., no golden frame boost in CBR mode and
407     * average bitrate target is used.
408     *
409     * For example, to allow 100% more bits, i.e., 2X, in a golden frame
410     * than average frame, set this to 100.
411     *
412     * Supported in codecs: VP8
413     */
414    Vp8GoldenFrameCBRBoostPct(u32),
415    // VP9E_ENABLE_MOTION_VECTOR_UNIT_TEST intentionally skipped
416    /**
417     * Codec control function to constrain the inter-layer prediction
418     * (prediction of lower spatial resolution) in VP9 SVC.
419     *
420     * Supported in codecs: VP9
421     */
422    Vp9SvcInterLayerPred(Vp9SvcInterLayerPred),
423    /**
424     * Codec control function to set mode and thresholds for frame
425     * dropping in SVC. Drop frame thresholds are set per-layer. Mode is set
426     * as:
427     * 0 : layer-dependent dropping, 1 : constrained dropping, current layer
428     *  drop forces drop on all upper layers. Default mode is 0.
429     *
430     * Supported in codecs: VP9
431     */
432    Vp9SvcFrameDropLayer(vpx_sys::vpx_svc_frame_drop),
433    /**
434     * Codec control function to enable/disable use of golden
435     * reference as a second temporal reference for SVC. Only used when
436     * inter-layer prediction is disabled on INTER frames.
437     *
438     * Supported in codecs: VP9
439     */
440    Vp9SvcGFTemporalRef(bool),
441    /**
442     * Codec control function to enable spatial layer sync frame, for
443     * any spatial layer. Enabling it for layer k means spatial layer k will
444     * disable all temporal prediction, but keep the inter-layer prediction.
445     * It will refresh any temporal reference buffer for that layer, and reset
446     * the* temporal layer for the superframe to 0. Setting the layer sync for
447     * base spatial layer forces a key frame. Default is off (0) for all spatial
448     * layers. Spatial layer sync flag is reset to 0 after each encoded layer,
449     * so when control is invoked it is only used for the current superframe.
450     *
451     * Supported in codecs: VP9
452     */
453    Vp9SvcSpatialLayerSync(vpx_sys::vpx_svc_spatial_layer_sync),
454    /**
455     * Codec control function to enable temporal dependency model.
456     *
457     * Vp9 allows the encoder to run temporal dependency model and use it to
458     * improve the compression performance. The default value is true.
459     */
460    Vp9SetTPL(bool),
461    /**
462     * Codec control function to enable postencode frame drop.
463     *
464     * This will allow encoder to drop frame after it's encoded.
465     * Default: false.
466     *
467     * Supported in codecs: VP9
468     */
469    Vp9PostEncodeDrop(bool),
470    /**
471     * Codec control function to set delta q for uv.
472     *
473     * Cap it at +/-15.
474     *
475     * Supported in codecs: VP9
476     */
477    Vp9DeltaQUV(i32),
478    /**
479     * Codec control function to disable increase Q on overshoot in CBR.
480     * Default is true (Q increase is NOT allowed to overshoot CBR).
481     *
482     * Supported in codecs: VP9
483     */
484    Vp9DisableOvershootMaxQCBR(bool),
485    /**
486     * Codec control function to disable loopfilter.
487     *
488     * 0: Loopfilter on all frames, 1: Disable on non reference frames.
489     * 2: Disable on all frames.
490     *
491     * Supported in codecs: VP9
492     */
493    Vp9Loopfilter(Vp9Loopfilter),
494    /**
495     * Specifies custom callbacks for external rate control.
496     *
497     * Supported in codecs: VP9
498     */
499    Vp9ExternalRateControl(&'a vpx_sys::vpx_rc_funcs),
500    /**
501     * Codec control to set quantizer for the next frame.
502     *
503     * This will turn off cyclic refresh. Only applicable to 1-pass without
504     * spatial layers.
505     *
506     * Supported in codecs: VP9
507     *
508     */
509    Vp9SetQuantizerOnePass(i32),
510}
511
512impl EncoderControlSet<'_> {
513    pub(crate) fn set(&self, ctx: &mut vpx_sys::vpx_codec_ctx_t) -> Result<()> {
514        macro_rules! ctrl {
515            ($ctx: expr, $ctrl_id: expr$(,)?) => {
516                call_vpx!(
517                    vpx_sys::vpx_codec_control_($ctx, $ctrl_id as i32),
518                    Error::CodecControlFailed,
519                )
520            };
521            ($ctx: expr, $ctrl_id: expr, $arg: expr$(,)?) => {
522                call_vpx!(
523                    vpx_sys::vpx_codec_control_($ctx, $ctrl_id as i32, $arg),
524                    Error::CodecControlFailed,
525                )
526            };
527        }
528        use vpx_sys::vp8e_enc_control_id::*;
529        match self {
530            Self::Vp8RoiMap(map) => ctrl!(ctx, VP8E_SET_ROI_MAP, *map),
531            Self::ActiveMap(map) => ctrl!(ctx, VP8E_SET_ACTIVEMAP, *map),
532            Self::ScaleMode(mode) => ctrl!(ctx, VP8E_SET_SCALEMODE, mode),
533            Self::CpuUsed(cpu_used) => ctrl!(ctx, VP8E_SET_CPUUSED, cpu_used),
534            Self::EnableAutoAltRef(arf) => {
535                ctrl!(ctx, VP8E_SET_ENABLEAUTOALTREF, *arf)
536            }
537            Self::Vp8NoiseSensitivity(sens) => {
538                ctrl!(ctx, VP8E_SET_NOISE_SENSITIVITY, *sens)
539            }
540            Self::Sharpness(sharpness) => {
541                ctrl!(ctx, VP8E_SET_SHARPNESS, *sharpness)
542            }
543            Self::StaticThreshold(thresh) => {
544                ctrl!(ctx, VP8E_SET_STATIC_THRESHOLD, *thresh)
545            }
546            Self::Vp8TokenPartitions(part) => {
547                ctrl!(ctx, VP8E_SET_TOKEN_PARTITIONS, *part)
548            }
549            Self::ARNRMaxFrames(frames) => {
550                ctrl!(ctx, VP8E_SET_ARNR_MAXFRAMES, *frames)
551            }
552            Self::ARNRStrength(strength) => {
553                ctrl!(ctx, VP8E_SET_ARNR_STRENGTH, *strength)
554            }
555            Self::Tuning(tuning) => ctrl!(ctx, VP8E_SET_TUNING, *tuning),
556            Self::CQLevel(level) => ctrl!(ctx, VP8E_SET_CQ_LEVEL, *level),
557            Self::MaxIntraBitratePct(pct) => {
558                ctrl!(ctx, VP8E_SET_MAX_INTRA_BITRATE_PCT, *pct)
559            }
560            Self::Vp8FrameFlags(flags) => {
561                ctrl!(ctx, VP8E_SET_FRAME_FLAGS, *flags)
562            }
563            Self::Vp9MaxInterBitratePct(pct) => {
564                ctrl!(ctx, VP9E_SET_MAX_INTER_BITRATE_PCT, *pct)
565            }
566            Self::Vp9GoldenFrameCBRBoostPct(layer_id) => {
567                ctrl!(ctx, VP9E_SET_GF_CBR_BOOST_PCT, *layer_id)
568            }
569            Self::Vp8TemporalLayerID(pct) => {
570                ctrl!(ctx, VP8E_SET_TEMPORAL_LAYER_ID, *pct)
571            }
572            Self::Vp8ScreenContentMode(mode) => {
573                ctrl!(ctx, VP8E_SET_SCREEN_CONTENT_MODE, *mode)
574            }
575            Self::Vp9CodingMode(mode) => {
576                ctrl!(ctx, VP9E_SET_LOSSLESS, *mode as u32)
577            }
578            Self::Vp9TileColumns(cols) => {
579                ctrl!(ctx, VP9E_SET_TILE_COLUMNS, *cols)
580            }
581            Self::Vp9TileRows(cols) => ctrl!(ctx, VP9E_SET_TILE_ROWS, *cols),
582            Self::Vp9FrameParallelDecoding(flag) => {
583                ctrl!(ctx, VP9E_SET_FRAME_PARALLEL_DECODING, *flag as u32)
584            }
585            Self::Vp9AQMode(mode) => ctrl!(ctx, VP9E_SET_AQ_MODE, *mode),
586            Self::Vp9FramePeriodicBoost(flag) => {
587                ctrl!(ctx, VP9E_SET_FRAME_PERIODIC_BOOST, *flag as u32)
588            }
589            Self::Vp9NoiseSensitivity(sens) => {
590                ctrl!(ctx, VP9E_SET_NOISE_SENSITIVITY, *sens)
591            }
592            Self::Vp9Svc(flag) => ctrl!(ctx, VP9E_SET_SVC, *flag as i32),
593            Self::Vp9RoiMap(map) => {
594                ctrl!(
595                    ctx,
596                    VP9E_SET_ROI_MAP,
597                    map.map_or(std::ptr::null(), |map| map as *const _)
598                )
599            }
600            Self::Vp9TuneContent(content) => {
601                ctrl!(ctx, VP9E_SET_TUNE_CONTENT, *content)
602            }
603            Self::Vp9ColorSpace(space) => {
604                ctrl!(ctx, VP9E_SET_COLOR_SPACE, *space as i32)
605            }
606            Self::Vp9MinGFInterval(intval) => {
607                ctrl!(ctx, VP9E_SET_MIN_GF_INTERVAL, *intval)
608            }
609            Self::Vp9MaxGFInterval(intval) => {
610                ctrl!(ctx, VP9E_SET_MAX_GF_INTERVAL, *intval)
611            }
612            Self::Vp9ColorRange(range) => {
613                ctrl!(ctx, VP9E_SET_COLOR_RANGE, *range)
614            }
615            Self::Vp9SvcRefFrameConfig(config) => {
616                ctrl!(ctx, VP9E_SET_SVC_REF_FRAME_CONFIG, *config)
617            }
618            Self::Vp9RenderSize { width, height } => {
619                ctrl!(ctx, VP9E_SET_RENDER_SIZE, &[width, height])
620            }
621            Self::Vp9TargetLevel(level) => {
622                ctrl!(ctx, VP9E_SET_TARGET_LEVEL, *level as i32)
623            }
624            Self::Vp9RowMT(flag) => ctrl!(ctx, VP9E_SET_ROW_MT, *flag as u32),
625            Self::Vp9AltRefAQ(aq) => {
626                ctrl!(ctx, VP9E_SET_ALT_REF_AQ, *aq as i32)
627            }
628            Self::Vp8GoldenFrameCBRBoostPct(pct) => {
629                ctrl!(ctx, VP8E_SET_GF_CBR_BOOST_PCT, *pct)
630            }
631            Self::Vp9SvcInterLayerPred(pred) => {
632                ctrl!(ctx, VP9E_SET_SVC_INTER_LAYER_PRED, *pred)
633            }
634            Self::Vp9SvcFrameDropLayer(drop) => {
635                ctrl!(ctx, VP9E_SET_SVC_FRAME_DROP_LAYER, drop)
636            }
637            Self::Vp9SvcGFTemporalRef(flag) => {
638                ctrl!(ctx, VP9E_SET_SVC_GF_TEMPORAL_REF, *flag as u32)
639            }
640            Self::Vp9SvcSpatialLayerSync(sync) => {
641                ctrl!(ctx, VP9E_SET_SVC_SPATIAL_LAYER_SYNC, sync)
642            }
643            Self::Vp9SetTPL(flag) => {
644                ctrl!(ctx, VP9E_SET_TPL, *flag as i32)
645            }
646            Self::Vp9PostEncodeDrop(flag) => {
647                ctrl!(ctx, VP9E_SET_POSTENCODE_DROP, *flag as i32)
648            }
649            Self::Vp9DeltaQUV(delta) => {
650                ctrl!(ctx, VP9E_SET_DELTA_Q_UV, *delta)
651            }
652            Self::Vp9DisableOvershootMaxQCBR(flag) => {
653                // CAVEAT: libvpx says 0=On, 1=Disable, so invert the bool
654                // result before passing it to libvpx
655                ctrl!(ctx, VP9E_SET_DELTA_Q_UV, !*flag as i32)
656            }
657            Self::Vp9Loopfilter(filter) => {
658                ctrl!(ctx, VP9E_SET_DISABLE_LOOPFILTER, *filter as i32)
659            }
660            Self::Vp9ExternalRateControl(rc_funcs) => {
661                ctrl!(ctx, VP9E_SET_EXTERNAL_RATE_CONTROL, *rc_funcs)
662            }
663            Self::Vp9SetQuantizerOnePass(qp) => {
664                ctrl!(ctx, VP9E_SET_QUANTIZER_ONE_PASS, *qp)
665            }
666        }
667    }
668}
669
670/// Control function to set noise sensitivity.
671#[allow(missing_docs)]
672#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
673#[repr(u32)]
674pub enum Vp8NoiseSensitivity {
675    Off = 0,
676    OnYOnly = 1,
677    OnYuv = 2,
678    OnYuvAggressive = 3,
679    Adaptive = 4,
680}
681
682/// VP9 noise sensitivity setting
683#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
684#[repr(u32)]
685pub enum Vp9NoiseSensitivity {
686    /// Off
687    Off = 0,
688    /// On (YOnly)
689    OnYOnly = 1,
690    /// For SVC only, on top two spatial layers (YOnly)
691    SvcOnly = 2,
692}
693
694/// Codec control function to set encoder screen content mode.
695#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
696#[repr(u32)]
697pub enum Vp8ScreenContentMode {
698    /// Off
699    Off = 0,
700    /// On
701    On = 1,
702    /// On with more aggressive rate control.
703    OnWithAggressiveRC = 2,
704}
705
706#[allow(missing_docs)]
707/// Codec adaptive quantization mode
708#[derive(Copy, Clone, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
709#[repr(u32)]
710pub enum Vp9AQMode {
711    #[default]
712    No = vpx_sys::AQ_MODE::NO_AQ as u32,
713    Variance = vpx_sys::AQ_MODE::VARIANCE_AQ as u32,
714    Complexity = vpx_sys::AQ_MODE::COMPLEXITY_AQ as u32,
715    CyclicRefresh = vpx_sys::AQ_MODE::CYCLIC_REFRESH_AQ as u32,
716    Equator360 = vpx_sys::AQ_MODE::EQUATOR360_AQ as u32,
717    Lookahead = vpx_sys::AQ_MODE::LOOKAHEAD_AQ as u32,
718}
719
720/// Sets the encoded content type to help optimize encoder settings
721#[derive(Copy, Clone, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
722#[repr(u32)]
723pub enum Vp9TuneContent {
724    #[default]
725    /// Regular video content (Default)
726    Default = vpx_sys::vp9e_tune_content::VP9E_CONTENT_DEFAULT as u32,
727    /// Screen capture content
728    Screen = vpx_sys::vp9e_tune_content::VP9E_CONTENT_SCREEN as u32,
729    /// Film content: improves grain retention
730    Film = vpx_sys::vp9e_tune_content::VP9E_CONTENT_FILM as u32,
731}
732
733#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
734#[repr(u32)]
735#[allow(non_camel_case_types)]
736/// Sets the VP9 set color range bit.
737pub enum Vp9ColorRange {
738    /// Limited range (16..235 or HBD equivalent)
739    Limited = 0,
740    /// Full range (0..255 or HBD equivalent)
741    Full = 1,
742}
743
744#[allow(missing_docs)]
745/// Codec control function to constrain the inter-layer prediction
746/// (prediction of lower spatial resolution) in VP9 SVC.
747#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
748#[repr(u32)]
749pub enum Vp9SvcInterLayerPred {
750    On = 0,
751    Off = 1,
752    OffOnlyOnNonKeyFrames = 2,
753}
754
755/// Codec control function to disable loopfilter.
756#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
757#[repr(u32)]
758pub enum Vp9Loopfilter {
759    /// Loopfilter on all frames, 1:
760    EnableAll = 0,
761    /// Disable on non reference frames.
762    DisableNonRef = 1,
763    /// Disable on all frames.
764    DisableAll = 2,
765}
766
767/// Defines the VP9 encoder coding mode (lossy or lossless).
768#[derive(Copy, Clone, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
769#[repr(u32)]
770pub enum Vp9CodingMode {
771    #[default]
772    /// The encoder operates in lossy (default) mode.
773    Lossy = 0,
774    /// The encoder operates in lossless mode.
775    Lossless = 1,
776}