onix 0.1.0

Decode image files using V4L2
Documentation
//! Stateless VP8 control

use bitflags::bitflags;

/// Set on an [`crate::ExtControls`] to not attach a request fd.
pub const V4L2_CTRL_WHICH_CUR_VAL: u32 = 0;

/// Set on an [`crate::ExtControls`] when a request fd has been set.
pub const V4L2_CTRL_WHICH_REQUEST_VAL: u32 = 0x0f010000;

bitflags! {
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    pub struct Vp8SegmentFlags: u32 {
        const ENABLED = 0x01;
        const UPDATE_MAP = 0x02;
        const UPDATE_FEATURE_DATA = 0x04;
        const DELTA_VALUE_MODE = 0x08;
    }
}

/**
 * VP8 segment-based adjustments parameters
 *
 * This structure contains segment-based adjustments related parameters.
 * See the 'update_segmentation()' part of the frame header syntax,
 * and section '9.3. Segment-Based Adjustments' of the VP8 specification
 * for more details.
 */
#[repr(C)]
#[derive(Debug, Clone)]
pub struct v4l2_vp8_segment {
    /// Update values for the segment quantizer.
    pub quant_update: [i8; 4],

    /// Update values for the loop filter level.
    pub lf_update: [i8; 4],

    /// Branch probabilities of the segment_id decoding tree.
    pub segment_probs: [u8; 3],

    /// Padding field. Should be zeroed by applications.
    pub padding: u8,

    /// See [`Vp8SegmentFlags`].
    pub flags: Vp8SegmentFlags,
}

bitflags! {
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    pub struct Vp8LoopFilter: u32 {
        const ADJ_ENABLE = 0x01;
        const DELTA_UPDATE = 0x02;
        const FILTER_TYPE_SIMPLE = 0x04;
    }
}

/**
 * VP8 loop filter parameters
 *
 * This structure contains loop filter related parameters.
 * See the 'mb_lf_adjustments()' part of the frame header syntax,
 * and section '9.4. Loop Filter Type and Levels' of the VP8 specification
 * for more details.
 */
#[repr(C)]
#[derive(Debug, Clone)]
pub struct v4l2_vp8_loop_filter {
    /// Reference frame signed delta values.
    pub ref_frm_delta: [i8; 4],

    /// MB prediction mode signed delta values.
    pub mb_mode_delta: [i8; 4],

    /// Matches sharpness_level syntax element.
    pub sharpness_level: u8,

    /// Matches loop_filter_level syntax element.
    pub level: u8,

    /// Padding field. Should be zeroed by applications.
    pub padding: u16,

    /// See [`Vp8LoopFilter`].
    pub flags: Vp8LoopFilter,
}

/**
 * VP8 quantizattion indices
 *
 * This structure contains the quantization indices present
 * in 'quant_indices()' part of the frame header syntax.
 * See section '9.6. Dequantization Indices' of the VP8 specification
 * for more details.
 */
#[repr(C)]
#[derive(Debug, Clone)]
pub struct v4l2_vp8_quantization {
    /// Luma AC coefficient table index.
    pub y_ac_qi: u8,

    /// Luma DC delta value.
    pub y_dc_delta: i8,

    /// Y2 block DC delta value.
    pub y2_dc_delta: i8,

    /// Y2 block AC delta value.
    pub y2_ac_delta: i8,

    /// Chroma DC delta value.
    pub uv_dc_delta: i8,

    /// Chroma AC delta value.
    pub uv_ac_delta: i8,

    /// Padding field. Should be zeroed by applications.
    pub padding: u16,
}

pub const V4L2_VP8_COEFF_PROB_CNT: usize = 11;
pub const V4L2_VP8_MV_PROB_CNT: usize = 19;

/**
 * VP8 update probabilities
 *
 * This structure contains the update probabilities present in
 * 'token_prob_update()' and 'mv_prob_update()' part of the frame header.
 * See section '17.2. Probability Updates' of the VP8 specification
 * for more details.
 */
#[repr(C)]
#[derive(Debug, Clone)]
pub struct v4l2_vp8_entropy {
    /// Coefficient probability update values.
    pub coeff_probs: [[[[u8; V4L2_VP8_COEFF_PROB_CNT]; 3]; 8]; 4],

    /// Luma intra-prediction probabilities.
    pub y_mode_probs: [u8; 4],

    /// Chroma intra-prediction probabilities.
    pub uv_mode_probs: [u8; 3],

    /// MV decoding probability.
    pub mv_probs: [[u8; V4L2_VP8_MV_PROB_CNT]; 2],

    /// Padding field. Should be zeroed by applications.
    pub padding: [u8; 3],
}

/**
 * VP8 boolean coder state
 *
 * This structure contains the state for the boolean coder, as
 * explained in section '7. Boolean Entropy Decoder' of the VP8 specification.
 */
#[repr(C)]
#[derive(Debug, Clone)]
pub struct v4l2_vp8_entropy_coder_state {
    /// Coder state value for "Range".
    pub range: u8,

    /// Coder state value for "Value".
    pub value: u8,

    /// Number of bits left in range "Value".
    pub bit_count: u8,

    /// Padding field. Should be zeroed by applications.
    pub padding: u8,
}

bitflags! {
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    pub struct Vp8FrameFlags: u64 {
        const KEY_FRAME = 0x01;
        const EXPERIMENTAL = 0x02;
        const SHOW_FRAME = 0x04;
        const MB_NO_SKIP_COEFF = 0x08;
        const SIGN_BIAS_GOLDEN = 0x10;
        const SIGN_BIAS_ALT = 0x20;
    }
}

pub const V4L2_CID_STATELESS_VP8_FRAME: u32 = (0x00a40000 | 0x900) + 200;

/// VP8 frame parameters
#[repr(C)]
#[derive(Debug, Clone)]
pub struct CtrlVp8Frame {
    /// Segmentation parameters. See &v4l2_vp8_segment for more details
    pub segment: v4l2_vp8_segment,

    /// Loop filter parameters. See &v4l2_vp8_loop_filter for more details
    pub lf: v4l2_vp8_loop_filter,

    /// Quantization parameters. See &v4l2_vp8_quantization for more details
    pub quant: v4l2_vp8_quantization,

    /// Update probabilities. See &v4l2_vp8_entropy for more details
    pub entropy: v4l2_vp8_entropy,

    /// Boolean coder state. See &v4l2_vp8_entropy_coder_state for more details
    pub coder_state: v4l2_vp8_entropy_coder_state,

    /// Frame width.
    pub width: u16,

    /// Frame height.
    pub height: u16,

    /// Horizontal scaling factor.
    pub horizontal_scale: u8,

    /// Vertical scaling factor.
    pub vertical_scale: u8,

    /// Bitstream version.
    pub version: u8,

    /// Frame header syntax element.
    pub prob_skip_false: u8,

    /// Frame header syntax element.
    pub prob_intra: u8,

    /// Frame header syntax element.
    pub prob_last: u8,

    /// Frame header syntax element.
    pub prob_gf: u8,

    /// Number of DCT coefficients partitions.
    pub num_dct_parts: u8,

    /// Size of the first partition, i.e. the control partition.
    pub first_part_size: u32,

    /// Size in bits of the first partition header portion.
    pub first_part_header_bits: u32,

    /// DCT coefficients sizes.
    pub dct_part_sizes: [u32; 8],

    /// "last" reference buffer timestamp.
    ///
    ///  The timestamp refers to the timestamp field in struct v4l2_buffer.
    ///  Use v4l2_timeval_to_ns() to convert the struct timeval to a __u64.
    pub last_frame_ts: u64,

    /// "golden" reference buffer timestamp.
    pub golden_frame_ts: u64,

    /// "alt" reference buffer timestamp.
    pub alt_frame_ts: u64,

    /// See [`Vp8FrameFlags`].
    pub flags: Vp8FrameFlags,
}