use ec_av1_syntax::sequence::{ColorConfig, OperatingPoint, SequenceHeader}; use ec_av1_syntax::{ CdefParams, ChromaSamplePosition, FrameHeader, FrameType, LoopFilterParams, LoopRestorationParams, PRIMARY_REF_NONE, QuantizationParams, TileInfo, TxMode, }; use ec_core::{Error, Result}; use crate::cdf; use crate::cdf_state::TxbSet; use crate::frame::frame_obu; use crate::intra::{ D67_PRED, DC_PRED, H_PRED, KEY_FRAME_MODES, PAETH_PRED, SMOOTH_H_PRED, SMOOTH_PRED, SMOOTH_V_PRED, V_PRED, }; use crate::mc; use crate::motion; use crate::mvstack::{MiGrid, MiInfo, MvStack, NO_REF1, find_mv_stack, mv16}; use crate::obu::temporal_delimiter; use crate::quant::ac_q; use crate::sequence::sequence_header_obu; use crate::tile::{ BlockCoeffs, Coeff, INTRA_MODE_CTX, InterInfo, InterMode, Quadrant, Superblock, partition_bits, }; use crate::transform::{ TxType, dequant_and_inverse_typed_wh, forward_and_quantize_typed, forward_and_quantize_typed_scaled, }; type SbSet = Vec<(usize, Superblock, Vec)>; type CompCands = Vec<(((i32, i32), (i32, i32)), f64, InterInfo)>; type CoefPlanes = [(Vec, Vec); 3]; const BLOCK: usize = 32; const SUB: usize = 16; pub(crate) const SUPERBLOCK: usize = 64; fn reach_sb_px(fctx: &crate::decode::FrameCtx) -> usize { fctx.reach_sb_px.get() } pub(crate) fn reach_sb_mi(fctx: &crate::decode::FrameCtx) -> usize { reach_sb_px(fctx) / 4 } pub(crate) fn chroma_mi_shape(bw: usize, bh: usize, ss_x: usize, ss_y: usize) -> (usize, usize) { match (bw, bh, ss_x, ss_y) { (4, 4, 1, 1) => (2, 2), (4, 4, 1, 0) => (2, 1), (4, 4, 0, 1) => (1, 2), (4, 8, 1, _) => (2, 2), (4, 8, 0, 1) => (1, 2), (8, 4, 1, 0) => (2, 1), (8, 4, 1, 1) | (8, 4, 0, 1) => (2, 2), (4, 16, 1, _) => (2, 4), (4, 16, 0, 1) => (1, 4), (16, 4, 1, 0) => (4, 1), (16, 4, 1, 1) | (16, 4, 0, 1) => (4, 2), _ => (bw / 4, bh / 4), } } const LAMBDA_SCALE: f64 = 0.0275; const HIDDEN_LAMBDA_FACTOR: f64 = 1.0; const KEY_LAMBDA_FACTOR: f64 = 1.0; #[cfg(test)] thread_local! { static PREDICTED_BITS: std::cell::RefCell> = const { std::cell::RefCell::new(Vec::new()) }; } #[cfg(test)] fn record_predicted_bits(bits: f64) { PREDICTED_BITS.with(|p| p.borrow_mut().push(bits)); } #[cfg(test)] pub(crate) fn take_predicted_bits() -> Vec { PREDICTED_BITS.with(|p| std::mem::take(&mut *p.borrow_mut())) } pub(crate) const SPLIT_INTER_8: bool = true; fn tx_select_inter() -> bool { crate::speed::at(&crate::speed::TX_SELECT_INTER) } pub(crate) fn tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] { const DCT: [TxType; 1] = [TxType::DctDct]; const INTRA1: [TxType; 7] = [ TxType::DctDct, TxType::AdstAdst, TxType::AdstDct, TxType::DctAdst, TxType::Idtx, TxType::VDct, TxType::HDct, ]; const INTRA2: [TxType; 5] = [ TxType::DctDct, TxType::AdstAdst, TxType::AdstDct, TxType::DctAdst, TxType::Idtx, ]; match set { TxbSet::Luma16 | TxbSet::Luma8 | TxbSet::Luma4 if intra_tx_search_on(screen) => &INTRA2, TxbSet::Luma8Set1 | TxbSet::Luma4Set1 if intra_tx_search_on(screen) => &INTRA1, _ => &DCT, } } pub(crate) fn inter_tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] { const DCT: [TxType; 1] = [TxType::DctDct]; const INTER3: [TxType; 2] = [TxType::DctDct, TxType::Idtx]; const INTER_WIDE: [TxType; 7] = [ TxType::DctDct, TxType::AdstAdst, TxType::AdstDct, TxType::DctAdst, TxType::Idtx, TxType::VDct, TxType::HDct, ]; let mode = inter_tx_type_search(); let on = match mode { InterTxSearch::Off => false, InterTxSearch::Screen => screen, InterTxSearch::Le16 => true, }; match set { TxbSet::Luma32Inter if on && mode != InterTxSearch::Le16 => &INTER3, TxbSet::Luma16Inter | TxbSet::Luma8Inter | TxbSet::Luma4Inter if on => &INTER3, TxbSet::Luma16InterSet1 | TxbSet::Luma8InterSet1 | TxbSet::Luma4InterSet1 if on => { &INTER_WIDE } _ => &DCT, } } pub(crate) fn wide_tx_set(screen: bool) -> bool { crate::speed::at(&crate::speed::WIDE_TX_SET) && screen } pub(crate) fn luma_set_for(set: TxbSet, screen: bool) -> TxbSet { if wide_tx_set(screen) { set.wide() } else { set } } #[derive(Clone, Copy, PartialEq)] pub(crate) enum InterTxSearch { Off, Screen, Le16, } fn inter_tx_type_search() -> InterTxSearch { if crate::speed::at(&crate::speed::TX_TYPE_SEARCH_INTER) { InterTxSearch::Screen } else { InterTxSearch::Off } } fn inter_luma_set(tx: usize) -> Option { Some(match tx { 4 => TxbSet::Luma4Inter, 8 => TxbSet::Luma8Inter, 16 => TxbSet::Luma16Inter, 32 => TxbSet::Luma32Inter, _ => return None, }) } fn tx_type_search() -> bool { crate::speed::at(&crate::speed::TX_TYPE_SEARCH) } fn intra_tx_search_on(screen: bool) -> bool { screen && tx_type_search() } fn tx_select() -> bool { crate::speed::at(&crate::speed::TX_SELECT_KEY) } fn split_inter_8() -> bool { crate::speed::at(&crate::speed::SPLIT_8) } pub(crate) const LEAF_NEW_MV: bool = true; pub(crate) const EXTRA_REF_NEW_MV: bool = true; const EXTRA_NEW_SKIP_MARGIN: f64 = 0.35; const LEAF_SECOND_NEW_MARGIN: f64 = 1.2; fn leaf_second_new_mv() -> bool { crate::speed::at(&crate::speed::LEAF_SECOND) } pub(crate) const LEAF_COMPOUND: bool = true; fn leaf_compound() -> bool { crate::speed::at(&crate::speed::LEAF_COMPOUND) } pub(crate) const SPLIT_INTER_BLOCKS: bool = true; fn split_inter_blocks() -> bool { crate::speed::at(&crate::speed::SPLIT_INTER) } pub(crate) const B64_ROOT: bool = true; static B64_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); pub fn take_b64_root_hits() -> usize { B64_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) } pub(crate) fn delta_q_bits(target: i32, cur: i32, res: i32) -> f64 { if res <= 0 { return 0.0; } const DELTA_Q_SMALL: usize = 3; let reduced = (target - cur) / res; let abs = reduced.unsigned_abs() as usize; let mut enc = crate::msac::SymbolEncoder::pricer(); enc.reset_bits(); enc.symbol_fixed(abs.min(DELTA_Q_SMALL), &cdf::DELTA_Q); if abs >= DELTA_Q_SMALL { let rem_bits = 31 - ((abs as u32) - 1).leading_zeros(); enc.literal(rem_bits - 1, 3); enc.literal(abs as u32 - ((1u32 << rem_bits) + 1), rem_bits); } if abs != 0 { enc.literal(u32::from(reduced < 0), 1); } enc.bits() } fn delta_q_bits_at_root( sb_q: Option<&Vec>, sb_cols: usize, base_q_idx: u8, res: i32, (root_r, root_c): (usize, usize), ) -> f64 { if res <= 0 { return 0.0; } let Some(q) = sb_q.filter(|q| !q.is_empty()) else { return 0.0; }; let at = |r: usize, c: usize| i32::from(q[(r * sb_cols + c).min(q.len() - 1)]); let target = at(root_r, root_c); let cur = if root_c >= 2 { at(root_r, root_c - 2) } else if root_r >= 2 { at(root_r - 2, (sb_cols.saturating_sub(1)) & !1) } else { i32::from(base_q_idx) }; delta_q_bits(target, cur, res) } pub(crate) fn ab128_pieces( symbol: usize, (mi_row, mi_col): (usize, usize), ) -> [((usize, usize), (usize, usize)); 3] { const S: usize = SUPERBLOCK; let (r, c) = (mi_row, mi_col); let (r1, c1) = (mi_row + 16, mi_col + 16); match symbol { 4 => [((r, c), (S, S)), ((r, c1), (S, S)), ((r1, c), (S * 2, S))], 5 => [((r, c), (S * 2, S)), ((r1, c), (S, S)), ((r1, c1), (S, S))], 6 => [((r, c), (S, S)), ((r1, c), (S, S)), ((r, c1), (S, S * 2))], _ => [((r, c), (S, S * 2)), ((r, c1), (S, S)), ((r1, c1), (S, S))], } } fn rdoq_on() -> bool { crate::speed::at(&crate::speed::RDOQ) } const RDOQ_LAMBDA_MULT: f64 = 2.2; fn b64_root() -> bool { crate::speed::at(&crate::speed::B64_ROOT) } pub(crate) const I64_ROOT: bool = true; static I64_HITS: [std::sync::atomic::AtomicUsize; 3] = [const { std::sync::atomic::AtomicUsize::new(0) }; 3]; pub fn take_i64_root_hits() -> [usize; 3] { std::array::from_fn(|i| I64_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed)) } fn i64_root() -> bool { crate::speed::at(&crate::speed::I64_ROOT) } static B64_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); pub fn take_b64_residual_hits() -> usize { B64_RESIDUAL_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) } static B64_COMPOUND_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); pub fn take_b64_compound_hits() -> usize { B64_COMPOUND_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) } static B64_VAR_TX_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); pub fn take_b64_var_tx_hits() -> usize { B64_VAR_TX_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) } static B64_EDGE_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); pub fn take_b64_edge_hits() -> usize { B64_EDGE_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) } pub(crate) const RESTORATION: bool = true; fn restoration_enabled() -> bool { crate::speed::at(&crate::speed::RESTORATION) } pub(crate) const SPLIT_BREAKOUT_COEFFS: usize = 0; pub(crate) const SPLIT_RD_THRESHOLD: f64 = 0.125; fn split_rd_threshold() -> f64 { crate::speed::at(&crate::speed::SPLIT_RD) } fn split_rd_breakout(cost: f64, side: usize, lambda: f64) -> bool { split_rd_breakout_at(split_rd_threshold(), cost, side, lambda) } fn split_rd_breakout_at(t: f64, cost: f64, side: usize, lambda: f64) -> bool { t > 0.0 && cost < t * lambda * (side * side) as f64 } fn b64_breakout_threshold() -> f64 { split_rd_threshold().min(SPLIT_RD_THRESHOLD) } fn split_breakout_coeffs() -> usize { crate::speed::at(&crate::speed::SPLIT_BREAKOUT) } pub(crate) const SPLIT_BLOCKS: bool = true; #[derive(Clone, Debug, PartialEq, Eq)] pub struct Picture { pub width: usize, pub height: usize, pub y: Vec, pub u: Vec, pub v: Vec, } impl Picture { #[must_use] pub fn grey(width: usize, height: usize) -> Self { Self { width, height, y: vec![128; width * height], u: vec![128; width * height / 4], v: vec![128; width * height / 4], } } fn check_planes(&self) -> Result<()> { let (luma, chroma) = (self.width * self.height, self.width * self.height / 4); if self.y.len() != luma || self.u.len() != chroma || self.v.len() != chroma { return Err(Error::unsupported( "AV1 encode", "each plane must carry one sample per position at 4:2:0", )); } Ok(()) } pub(crate) fn check(&self) -> Result<()> { if self.width == 0 || !self.width.is_multiple_of(BLOCK) || self.height == 0 || !self.height.is_multiple_of(BLOCK) { return Err(Error::unsupported( "AV1 encode", "the picture must be a whole number of 32x32 blocks in each direction", )); } self.check_planes() } pub(crate) fn check_even(&self) -> Result<()> { if self.width == 0 || self.height == 0 || !self.width.is_multiple_of(2) || !self.height.is_multiple_of(2) { return Err(Error::unsupported( "AV1 encode", "the picture's width and height must each be even and nonzero", )); } self.check_planes() } pub(crate) fn padded_to(&self, align: usize) -> Picture { let padded_width = self.width.next_multiple_of(align); let padded_height = self.height.next_multiple_of(align); if padded_width == self.width && padded_height == self.height { return self.clone(); } Picture { width: padded_width, height: padded_height, y: pad_plane( &self.y, self.width, self.height, padded_width, padded_height, ), u: pad_plane( &self.u, self.width / 2, self.height / 2, padded_width / 2, padded_height / 2, ), v: pad_plane( &self.v, self.width / 2, self.height / 2, padded_width / 2, padded_height / 2, ), } } } fn intra_predict_u8( mode: u8, angle_delta: i32, above: Option<&[u8]>, left: Option<&[u8]>, corner: Option, bw: usize, bh: usize, enable_edge_filter: bool, smooth_neighbor: bool, dst: &mut [u8], fctx: &crate::decode::FrameCtx, ) { let mut above_buf = [0u16; 2 * SUPERBLOCK]; let mut left_buf = [0u16; 2 * SUPERBLOCK]; let widen = |src: &[u8], buf: &mut [u16; 2 * SUPERBLOCK]| { for (d, &v) in buf[..src.len()].iter_mut().zip(src) { *d = u16::from(v); } }; if let Some(s) = above { widen(s, &mut above_buf); } if let Some(s) = left { widen(s, &mut left_buf); } let above16 = above.map(|s| &above_buf[..s.len()]); let left16 = left.map(|s| &left_buf[..s.len()]); let mut run = |dst16: &mut [u16]| { crate::intra::predict( mode, angle_delta, above16, left16, corner.map(u16::from), bw, bh, enable_edge_filter, smooth_neighbor, dst16, fctx, ); for (d, &s) in dst.iter_mut().zip(dst16.iter()) { *d = s as u8; } }; let n = bw * bh; if n <= 64 { run(&mut [0u16; 64][..n]); } else if n <= 256 { run(&mut [0u16; 256][..n]); } else if n <= BLOCK * BLOCK { run(&mut [0u16; BLOCK * BLOCK][..n]); } else { run(&mut [0u16; SUPERBLOCK * SUPERBLOCK][..n]); } } fn filter_intra_predict_u8( mode: usize, above: Option<&[u8]>, left: Option<&[u8]>, corner: Option, side: usize, dst: &mut [u8], fctx: &crate::decode::FrameCtx, ) { let mut above_buf = [0u16; 2 * BLOCK]; let mut left_buf = [0u16; 2 * BLOCK]; let widen = |src: &[u8], buf: &mut [u16; 2 * BLOCK]| { for (d, &v) in buf[..src.len()].iter_mut().zip(src) { *d = u16::from(v); } }; if let Some(a) = above { widen(a, &mut above_buf); } if let Some(l) = left { widen(l, &mut left_buf); } let mut dst16 = [0u16; BLOCK * BLOCK]; let n = side * side; crate::intra::predict_filter_intra( mode, above.map(|a| &above_buf[..a.len()]), left.map(|l| &left_buf[..l.len()]), corner.map(u16::from), side, side, &mut dst16[..n], fctx, ); for (d, &v) in dst.iter_mut().zip(dst16[..n].iter()) { *d = v as u8; } } fn pad_plane( source: &[T], width: usize, height: usize, padded_width: usize, padded_height: usize, ) -> Vec { let mut out = vec![T::default(); padded_width * padded_height]; for row in 0..padded_height { let src = source[row.min(height - 1) * width..][..width].as_ref(); let dst = &mut out[row * padded_width..][..padded_width]; dst[..width].copy_from_slice(src); dst[width..].fill(src[width - 1]); } out } fn crop_plane(source: &[T], padded_width: usize, width: usize, height: usize) -> Vec { let mut out = Vec::with_capacity(width * height); for row in 0..height { out.extend_from_slice(&source[row * padded_width..][..width]); } out } pub(crate) fn crop_encoded(encoded: &Encoded, width: usize, height: usize) -> Encoded { let reconstruction = &encoded.reconstruction; let (cw, ch) = (width.div_ceil(2), height.div_ceil(2)); let cropped = if reconstruction.width == width && reconstruction.height == height { reconstruction.clone() } else { Picture { width, height, y: crop_plane(&reconstruction.y, reconstruction.width, width, height), u: crop_plane(&reconstruction.u, reconstruction.width / 2, cw, ch), v: crop_plane(&reconstruction.v, reconstruction.width / 2, cw, ch), } }; Encoded { stream: encoded.stream.clone(), modes: encoded.modes.clone(), inter_block_share: encoded.inter_block_share, reconstruction: cropped, tile: encoded.tile.clone(), mi_cols: encoded.mi_cols, mi_rows: encoded.mi_rows, base_q_idx: encoded.base_q_idx, tx_select: encoded.tx_select, switchable_motion_mode: encoded.switchable_motion_mode, screen: encoded.screen, reduced_tx_set: encoded.reduced_tx_set, start_cdfs: encoded.start_cdfs.clone(), next_cdfs: encoded.next_cdfs.clone(), loop_filter: encoded.loop_filter, loop_restoration: encoded.loop_restoration, allow_intrabc: encoded.allow_intrabc, delta: encoded.delta, cdef: encoded.cdef, } } #[derive(Clone)] pub(crate) struct CdfSnapshot(pub(crate) crate::cdf_state::Cdfs); impl std::fmt::Debug for CdfSnapshot { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str("CdfSnapshot") } } #[derive(Clone, Debug)] pub struct Encoded { pub stream: Vec, pub reconstruction: Picture, pub modes: Vec, pub inter_block_share: f64, pub(crate) tile: Vec, pub(crate) mi_cols: u32, pub(crate) mi_rows: u32, pub(crate) base_q_idx: u8, pub(crate) tx_select: bool, pub(crate) switchable_motion_mode: bool, pub(crate) start_cdfs: Box, pub(crate) next_cdfs: Box, pub(crate) loop_filter: LoopFilterParams, pub(crate) cdef: CdefParams, pub(crate) screen: bool, pub(crate) reduced_tx_set: bool, pub(crate) loop_restoration: LoopRestorationParams, pub(crate) allow_intrabc: bool, pub(crate) delta: ec_av1_syntax::DeltaParams, } fn screen_content(y: &[u8], width: usize, true_width: usize, true_height: usize) -> bool { let (blk, limit, floor) = (16usize, 16, 16); let mut counted = 0usize; for by in (0..true_height).step_by(blk) { for bx in (0..true_width).step_by(blk) { let (h, w) = ((true_height - by).min(blk), (true_width - bx).min(blk)); let mut seen = [false; 256]; let (mut colors, mut sum, mut sq) = (0usize, 0u64, 0u64); for row in 0..h { for col in 0..w { let v = y[(by + row) * width + bx + col]; sum += u64::from(v); sq += u64::from(v) * u64::from(v); if !seen[usize::from(v)] { seen[usize::from(v)] = true; colors += 1; } } } let n = (h * w) as u64; let var = (sq - sum * sum / n) / n; if colors > 1 && colors <= limit && var > floor { counted += 1; } } } counted * blk * blk * 10 > true_width * true_height } pub(crate) fn picture_is_screen(picture: &Picture) -> bool { let y: Vec = picture.y.iter().map(|&v| v as u8).collect(); screen_content(&y, picture.width, picture.width, picture.height) } pub fn key_frame_headers( width: usize, height: usize, base_q_idx: u8, ) -> Result<(SequenceHeader, FrameHeader)> { key_frame_headers_colour(width, height, base_q_idx, unspecified_color_config()) } fn unspecified_color_config() -> ColorConfig { ColorConfig { bit_depth: 8, mono_chrome: false, num_planes: 3, color_primaries: 2, transfer_characteristics: 2, matrix_coefficients: 2, color_range: false, subsampling_x: 1, subsampling_y: 1, chroma_sample_position: ChromaSamplePosition::Unknown, separate_uv_delta_q: false, } } pub fn key_frame_headers_colour( width: usize, height: usize, base_q_idx: u8, color_config: ColorConfig, ) -> Result<(SequenceHeader, FrameHeader)> { key_frame_headers_seq(width, height, base_q_idx, color_config, false) } pub(crate) fn key_frame_headers_seq( width: usize, height: usize, base_q_idx: u8, color_config: ColorConfig, seq_screen: bool, ) -> Result<(SequenceHeader, FrameHeader)> { let bits = |n: usize| -> Result { let n = u32::try_from(n).map_err(|_| too_large())?; if n == 0 || n > 1 << 16 { return Err(too_large()); } Ok((32 - (n - 1).leading_zeros()).max(1)) }; let (frame_width_bits, frame_height_bits) = (bits(width)?, bits(height)?); let (w, h) = (width as u32, height as u32); let seq = SequenceHeader { seq_profile: 0, operating_points: vec![OperatingPoint { seq_level_idx: 8, ..OperatingPoint::default() }], frame_width_bits, frame_height_bits, max_frame_width: w, max_frame_height: h, use_128x128_superblock: SB128_DEFAULT, enable_filter_intra: filter_intra_on(), enable_intra_edge_filter: false, enable_order_hint: true, order_hint_bits: 7, enable_superres: false, enable_cdef: true, enable_restoration: true, seq_force_screen_content_tools: if seq_screen { ec_av1_syntax::sequence::SELECT_SCREEN_CONTENT_TOOLS } else { 0 }, seq_force_integer_mv: 0, color_config, still_picture: false, reduced_still_picture_header: false, timing_info: None, decoder_model_info: None, initial_display_delay_present_flag: false, operating_point: 0, operating_point_idc: 0, frame_id_numbers_present_flag: false, delta_frame_id_length: 0, additional_frame_id_length: 0, enable_interintra_compound: false, enable_masked_compound: false, enable_warped_motion: warp_on(), enable_dual_filter: false, enable_jnt_comp: false, enable_ref_frame_mvs: false, film_grain_params_present: false, }; let (mi_cols, mi_rows) = (2 * ((w + 7) >> 3), 2 * ((h + 7) >> 3)); let header = FrameHeader { frame_type: FrameType::Key, frame_is_intra: true, show_frame: true, error_resilient_mode: true, disable_cdf_update: false, disable_frame_end_update_cdf: true, force_integer_mv: true, refresh_frame_flags: 0xFF, primary_ref_frame: PRIMARY_REF_NONE, frame_width: w, frame_height: h, upscaled_width: w, render_width: w, render_height: h, mi_cols, mi_rows, tile_info: TileInfo { uniform_spacing: true, cols: 1, rows: 1, mi_col_starts: vec![0, mi_cols], mi_row_starts: vec![0, mi_rows], tile_size_bytes: 1, ..TileInfo::default() }, quantization: QuantizationParams { base_q_idx, ..QuantizationParams::default() }, tx_mode: TxMode::Largest, reduced_tx_set: true, ..FrameHeader::default() }; Ok((seq, header)) } pub const GOLDEN_SLOT: u8 = 1; pub fn inter_frame_headers( width: usize, height: usize, base_q_idx: u8, order_hint: u32, last_slot: u8, ) -> Result<(SequenceHeader, FrameHeader)> { inter_frame_headers_slots( width, height, base_q_idx, order_hint, last_slot, last_slot, last_slot, false, ) } pub fn inter_frame_headers_slots( width: usize, height: usize, base_q_idx: u8, order_hint: u32, last_slot: u8, self_slot: u8, altref_slot: u8, seq_screen: bool, ) -> Result<(SequenceHeader, FrameHeader)> { let (seq, key) = key_frame_headers_seq( width, height, base_q_idx, unspecified_color_config(), seq_screen, )?; let header = FrameHeader { frame_type: FrameType::Inter, frame_is_intra: false, show_frame: true, error_resilient_mode: false, disable_cdf_update: false, disable_frame_end_update_cdf: false, force_integer_mv: false, order_hint, primary_ref_frame: 0, refresh_frame_flags: 1 << self_slot, ref_frame_idx: { let mut idx = [last_slot; ec_av1_syntax::REFS_PER_FRAME]; idx[3] = GOLDEN_SLOT; idx[6] = altref_slot; idx }, allow_high_precision_mv: high_precision_mv_at(base_q_idx), interpolation_filter: ec_av1_syntax::InterpolationFilter::Eighttap, is_motion_mode_switchable: warp_on(), allow_warped_motion: warp_on(), use_ref_frame_mvs: false, reduced_tx_set: true, ..key }; Ok((seq, header)) } fn too_large() -> Error { Error::unsupported( "AV1 encode", "the picture is larger than a frame size can carry", ) } mod coef; pub(super) use coef::*; mod split; pub(crate) use split::*; mod inter_search; pub use inter_search::{ encode_key_frame, encode_key_frame_at_size, encode_key_frame_with_modes, encode_sequence, take_arfmode_hits, }; pub(crate) use inter_search::*; mod frame; pub use frame::EncodedSequence; pub(crate) use frame::*; #[cfg(test)] mod tests; #[cfg(test)] mod more_tests;