edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·9b67700·Tahinli·3 days ago·4021 commits
| 1 | //! AV1 decoding over Vulkan Video: the reference slots over DPB slot indices. |
| 2 | |
| 3 | use std::cell::RefCell; |
| 4 | use std::collections::VecDeque; |
| 5 | use std::rc::Rc; |
| 6 | |
| 7 | use ec_av1::encode::Picture; |
| 8 | use ec_av1_syntax::{ |
| 9 | Av1Parser, ChromaSamplePosition, ColorConfig, FilmGrainParams, FrameHeader, FrameType, |
| 10 | InterpolationFilter, NUM_REF_FRAMES, ObuKind, REFS_PER_FRAME, RestorationType, SequenceHeader, |
| 11 | Tile, TxMode, WarpModel, |
| 12 | }; |
| 13 | use ec_vk::{ |
| 14 | Av1Cdef, Av1ColorConfig, Av1DecodeConfig, Av1DecodePicture, Av1DecodeSession, Av1DeltaParams, |
| 15 | Av1FrameHeader, Av1FrameType, Av1GlobalMotion, Av1InterpolationFilter, Av1LoopFilter, |
| 16 | Av1LoopRestoration, Av1Quantization, Av1RefSlot, Av1Restoration, Av1Segmentation, |
| 17 | Av1SequenceHeader, Av1TileInfo, Av1TimingInfo, Av1TxMode, Av1WarpModel, |
| 18 | }; |
| 19 | |
| 20 | use crate::ref_slots::RefSlots; |
| 21 | use crate::error::{Error, Result}; |
| 22 | use ec_core::color::{ColorDescription, Tags}; |
| 23 | |
| 24 | use crate::output::{HwPicture, Ring, Surfaces, VkPicture}; |
| 25 | use crate::picture::{I420, I420_16}; |
| 26 | |
| 27 | const DPB_SLOTS: u32 = NUM_REF_FRAMES as u32 + 1; |
| 28 | |
| 29 | struct Session { |
| 30 | av1: Rc<RefCell<Av1DecodeSession>>, |
| 31 | ring: Rc<RefCell<Ring>>, |
| 32 | bit_depth: u8, |
| 33 | width: u32, |
| 34 | height: u32, |
| 35 | sequence: Option<SequenceHeader>, |
| 36 | } |
| 37 | |
| 38 | struct Reference { |
| 39 | state: Av1RefSlot, |
| 40 | picture: VkPicture, |
| 41 | } |
| 42 | |
| 43 | /// AV1 Vulkan Video decoder: reference bookkeeping in Rust, frames decoded into DPB slots. |
| 44 | pub(crate) struct VkAv1Decoder { |
| 45 | gpu: ec_vk::Gpu, |
| 46 | parser: Av1Parser, |
| 47 | session: Option<Session>, |
| 48 | refs: RefSlots<Rc<Reference>>, |
| 49 | ready: VecDeque<HwPicture>, |
| 50 | } |
| 51 | |
| 52 | impl VkAv1Decoder { |
| 53 | pub(crate) fn new() -> Result<Self> { |
| 54 | let gpu = crate::hw::vk_gpu() |
| 55 | .ok_or_else(|| Error::unsupported("Vulkan Video AV1 decode", "no Vulkan device"))?; |
| 56 | Ok(VkAv1Decoder { |
| 57 | gpu, |
| 58 | parser: Av1Parser::new(), |
| 59 | session: None, |
| 60 | refs: RefSlots::new(), |
| 61 | ready: VecDeque::new(), |
| 62 | }) |
| 63 | } |
| 64 | |
| 65 | pub(crate) fn decode(&mut self, data: &[u8], timestamp: i64) -> Result<()> { |
| 66 | let mut pending: Option<Box<FrameHeader>> = None; |
| 67 | for obu in self.parser.parse_temporal_unit(data)? { |
| 68 | match obu.kind { |
| 69 | ObuKind::FrameHeader(header) if header.show_existing_frame => { |
| 70 | self.show_existing(&header, timestamp)?; |
| 71 | } |
| 72 | ObuKind::FrameHeader(header) => pending = Some(header), |
| 73 | ObuKind::TileGroup(tiles) => { |
| 74 | if let Some(header) = pending.take() { |
| 75 | self.decode_frame(&header, &tiles, data, timestamp)?; |
| 76 | } |
| 77 | } |
| 78 | ObuKind::Frame(header, _) if header.show_existing_frame => { |
| 79 | self.show_existing(&header, timestamp)?; |
| 80 | } |
| 81 | ObuKind::Frame(header, tiles) => { |
| 82 | self.decode_frame(&header, &tiles, data, timestamp)?; |
| 83 | } |
| 84 | _ => {} |
| 85 | } |
| 86 | } |
| 87 | Ok(()) |
| 88 | } |
| 89 | |
| 90 | pub(crate) fn next_frame(&mut self) -> Option<HwPicture> { |
| 91 | self.ready.pop_front() |
| 92 | } |
| 93 | |
| 94 | pub(crate) fn reset(&mut self) { |
| 95 | self.parser = Av1Parser::new(); |
| 96 | self.refs = RefSlots::new(); |
| 97 | self.ready.clear(); |
| 98 | } |
| 99 | |
| 100 | pub(crate) fn flush(&mut self) -> Result<()> { |
| 101 | Ok(()) |
| 102 | } |
| 103 | |
| 104 | fn show_existing(&mut self, header: &FrameHeader, timestamp: i64) -> Result<()> { |
| 105 | let reference = self |
| 106 | .refs |
| 107 | .get(usize::from(header.frame_to_show_map_idx)) |
| 108 | .cloned() |
| 109 | .ok_or_else(|| { |
| 110 | Error::Stream(ec_core::Error::corrupt( |
| 111 | "AV1 show_existing_frame names an empty reference slot", |
| 112 | )) |
| 113 | })?; |
| 114 | let seq = self |
| 115 | .parser |
| 116 | .sequence_header() |
| 117 | .ok_or_else(|| Error::config("AV1 frame before any sequence header"))?; |
| 118 | let shown = reference.picture.with_grain(&header.film_grain, seq); |
| 119 | self.ready.push_back(HwPicture::vk(timestamp, shown)); |
| 120 | if header.frame_type == FrameType::Key { |
| 121 | self.refs.refresh(u8::MAX, Some(reference)); |
| 122 | } |
| 123 | Ok(()) |
| 124 | } |
| 125 | |
| 126 | fn decode_frame( |
| 127 | &mut self, |
| 128 | header: &FrameHeader, |
| 129 | tiles: &[Tile], |
| 130 | data: &[u8], |
| 131 | timestamp: i64, |
| 132 | ) -> Result<()> { |
| 133 | let seq = self |
| 134 | .parser |
| 135 | .sequence_header() |
| 136 | .cloned() |
| 137 | .ok_or_else(|| Error::config("AV1 frame before any sequence header"))?; |
| 138 | check_supported(&seq)?; |
| 139 | let (width, height) = (header.upscaled_width, header.frame_height); |
| 140 | self.ensure_session(&seq, width, height)?; |
| 141 | |
| 142 | let mut ref_frame_slot = [-1i32; REFS_PER_FRAME]; |
| 143 | let mut refs: Vec<Av1RefSlot> = Vec::new(); |
| 144 | if matches!(header.frame_type, FrameType::Inter | FrameType::Switch) { |
| 145 | for (name, &index) in header.ref_frame_idx.iter().enumerate() { |
| 146 | let reference = self.refs.get(usize::from(index)).ok_or_else(|| { |
| 147 | Error::Stream(ec_core::Error::corrupt(format!( |
| 148 | "AV1 inter frame names reference slot {index} (ref {name}), \ |
| 149 | which no decoded frame has filled" |
| 150 | ))) |
| 151 | })?; |
| 152 | ref_frame_slot[name] = reference.state.slot as i32; |
| 153 | if !refs.iter().any(|r| r.slot == reference.state.slot) { |
| 154 | refs.push(reference.state); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | let setup_slot = self.free_slot()?; |
| 160 | let frame = frame_header(header, &seq); |
| 161 | let offsets: Vec<u32> = tiles.iter().map(|t| t.offset as u32).collect(); |
| 162 | let sizes: Vec<u32> = tiles.iter().map(|t| t.size as u32).collect(); |
| 163 | let picture = Av1DecodePicture { |
| 164 | header: &frame, |
| 165 | setup_slot, |
| 166 | ref_frame_slot, |
| 167 | refs: &refs, |
| 168 | tile_data: data, |
| 169 | tile_offsets: &offsets, |
| 170 | tile_sizes: &sizes, |
| 171 | }; |
| 172 | let session = self |
| 173 | .session |
| 174 | .as_mut() |
| 175 | .ok_or_else(|| Error::config("AV1 picture before any session"))?; |
| 176 | session.av1.borrow_mut().decode(&picture)?; |
| 177 | |
| 178 | if !(header.show_frame || header.refresh_frame_flags != 0) { |
| 179 | return Ok(()); |
| 180 | } |
| 181 | let slot = session |
| 182 | .ring |
| 183 | .borrow_mut() |
| 184 | .take(|| Ok(session.av1.borrow_mut().add_ring_slot()?))?; |
| 185 | session.av1.borrow_mut().store_output( |
| 186 | slot.index(), |
| 187 | (0, 0, width.next_multiple_of(2), height.next_multiple_of(2)), |
| 188 | )?; |
| 189 | let codes = Tags::from_codes(u64::from(seq.color_config.matrix_coefficients), 0, 0); |
| 190 | let matrix = ColorDescription::resolve(Tags::default(), codes, height).matrix; |
| 191 | let decoded = VkPicture::new( |
| 192 | Surfaces::Av1(session.av1.clone()), |
| 193 | slot, |
| 194 | (width, height), |
| 195 | session.bit_depth, |
| 196 | matrix, |
| 197 | ) |
| 198 | .with_ring(session.ring.clone()); |
| 199 | let state = Av1RefSlot { |
| 200 | slot: setup_slot, |
| 201 | frame_type: av1_frame_type(header.frame_type), |
| 202 | order_hint: header.order_hint as u8, |
| 203 | ref_order_hints: saved_order_hints(&header.order_hints), |
| 204 | sign_bias: sign_bias(&header.ref_frame_sign_bias), |
| 205 | disable_frame_end_update_cdf: header.disable_frame_end_update_cdf, |
| 206 | segmentation_enabled: header.segmentation.enabled, |
| 207 | extent: (width, height), |
| 208 | }; |
| 209 | if header.show_frame { |
| 210 | let shown = decoded.with_grain(&header.film_grain, &seq); |
| 211 | self.ready.push_back(HwPicture::vk(timestamp, shown)); |
| 212 | } |
| 213 | if header.refresh_frame_flags != 0 { |
| 214 | let reference = Rc::new(Reference { |
| 215 | state, |
| 216 | picture: decoded, |
| 217 | }); |
| 218 | self.refs |
| 219 | .refresh(header.refresh_frame_flags, Some(reference)); |
| 220 | } |
| 221 | Ok(()) |
| 222 | } |
| 223 | |
| 224 | fn ensure_session(&mut self, seq: &SequenceHeader, width: u32, height: u32) -> Result<()> { |
| 225 | let bit_depth = seq.color_config.bit_depth; |
| 226 | let width = seq.max_frame_width.max(width); |
| 227 | let height = seq.max_frame_height.max(height); |
| 228 | let mut session = match self.session.take() { |
| 229 | Some(s) if s.bit_depth == bit_depth && s.width == width && s.height == height => s, |
| 230 | _ => { |
| 231 | self.refs = RefSlots::new(); |
| 232 | let av1 = Av1DecodeSession::new( |
| 233 | &self.gpu, |
| 234 | &Av1DecodeConfig { |
| 235 | max_width: width, |
| 236 | max_height: height, |
| 237 | max_dpb_slots: DPB_SLOTS, |
| 238 | bit_depth, |
| 239 | }, |
| 240 | )?; |
| 241 | let ring = Ring::new(av1.ring_len()); |
| 242 | Session { |
| 243 | av1: Rc::new(RefCell::new(av1)), |
| 244 | ring: Rc::new(RefCell::new(ring)), |
| 245 | bit_depth, |
| 246 | width, |
| 247 | height, |
| 248 | sequence: None, |
| 249 | } |
| 250 | } |
| 251 | }; |
| 252 | if session.sequence.as_ref() != Some(seq) { |
| 253 | session |
| 254 | .av1 |
| 255 | .borrow_mut() |
| 256 | .set_sequence_header(&av1_sequence(seq))?; |
| 257 | session.sequence = Some(seq.clone()); |
| 258 | } |
| 259 | self.session = Some(session); |
| 260 | Ok(()) |
| 261 | } |
| 262 | |
| 263 | fn free_slot(&self) -> Result<u32> { |
| 264 | (0..DPB_SLOTS) |
| 265 | .find(|slot| self.refs.filled().all(|r| r.state.slot != *slot)) |
| 266 | .ok_or_else(|| Error::config("AV1 Vulkan decode: every DPB slot is in use")) |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | fn check_supported(seq: &SequenceHeader) -> Result<()> { |
| 271 | let c = &seq.color_config; |
| 272 | if seq.seq_profile != 0 |
| 273 | || !matches!(c.bit_depth, 8 | 10) |
| 274 | || c.mono_chrome |
| 275 | || c.subsampling_x != 1 |
| 276 | || c.subsampling_y != 1 |
| 277 | { |
| 278 | return Err(Error::unsupported( |
| 279 | "Vulkan AV1 decode", |
| 280 | "only Main 8- and 10-bit 4:2:0", |
| 281 | )); |
| 282 | } |
| 283 | Ok(()) |
| 284 | } |
| 285 | |
| 286 | pub(crate) fn synthesize16(frame: I420_16, grain: &FilmGrainParams, seq: &SequenceHeader) -> I420_16 { |
| 287 | let bit_depth = u32::from(seq.color_config.bit_depth); |
| 288 | let shift = if bit_depth == 8 { 2 } else { 0 }; |
| 289 | let narrow = |p: &[u16]| p.iter().map(|&s| s >> shift).collect::<Vec<u16>>(); |
| 290 | let clean = Picture { |
| 291 | width: frame.width as usize, |
| 292 | height: frame.height as usize, |
| 293 | y: narrow(&frame.y), |
| 294 | u: narrow(&frame.u), |
| 295 | v: narrow(&frame.v), |
| 296 | }; |
| 297 | let out = ec_av1::apply_film_grain( |
| 298 | &clean, |
| 299 | grain, |
| 300 | seq.color_config.matrix_coefficients == 0, |
| 301 | bit_depth, |
| 302 | ); |
| 303 | let widen = |p: &[u16]| p.iter().map(|&s| s << shift).collect::<Vec<u16>>(); |
| 304 | I420_16 { |
| 305 | y: widen(&out.y), |
| 306 | u: widen(&out.u), |
| 307 | v: widen(&out.v), |
| 308 | width: frame.width, |
| 309 | height: frame.height, |
| 310 | bit_depth: 10, |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | pub(crate) fn synthesize(frame: I420, grain: &FilmGrainParams, seq: &SequenceHeader) -> I420 { |
| 315 | let wide = |p: &[u8]| p.iter().map(|&s| u16::from(s)).collect::<Vec<u16>>(); |
| 316 | let clean = Picture { |
| 317 | width: frame.width as usize, |
| 318 | height: frame.height as usize, |
| 319 | y: wide(&frame.y), |
| 320 | u: wide(&frame.u), |
| 321 | v: wide(&frame.v), |
| 322 | }; |
| 323 | let out = ec_av1::apply_film_grain( |
| 324 | &clean, |
| 325 | grain, |
| 326 | seq.color_config.matrix_coefficients == 0, |
| 327 | u32::from(seq.color_config.bit_depth), |
| 328 | ); |
| 329 | let narrow = |p: &[u16]| p.iter().map(|&s| s as u8).collect::<Vec<u8>>(); |
| 330 | I420 { |
| 331 | y: narrow(&out.y), |
| 332 | u: narrow(&out.u), |
| 333 | v: narrow(&out.v), |
| 334 | width: frame.width, |
| 335 | height: frame.height, |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | fn av1_frame_type(t: FrameType) -> Av1FrameType { |
| 340 | match t { |
| 341 | FrameType::Key => Av1FrameType::Key, |
| 342 | FrameType::Inter => Av1FrameType::Inter, |
| 343 | FrameType::IntraOnly => Av1FrameType::IntraOnly, |
| 344 | FrameType::Switch => Av1FrameType::Switch, |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /// `RefFrameSignBias` as a mask: bit `n` set when reference name `n` (LAST = 1) is a future frame. |
| 349 | fn sign_bias(bias: &[bool; REFS_PER_FRAME]) -> u8 { |
| 350 | bias.iter() |
| 351 | .enumerate() |
| 352 | .filter(|(_, set)| **set) |
| 353 | .fold(0u8, |mask, (name, _)| mask | 1 << (name + 1)) |
| 354 | } |
| 355 | |
| 356 | /// `SavedOrderHints` indexed by reference name, index 0 (INTRA_FRAME) unused. |
| 357 | fn saved_order_hints(hints: &[u32; REFS_PER_FRAME]) -> [u8; NUM_REF_FRAMES] { |
| 358 | let mut out = [0u8; NUM_REF_FRAMES]; |
| 359 | for (name, &hint) in hints.iter().enumerate() { |
| 360 | out[name + 1] = hint as u8; |
| 361 | } |
| 362 | out |
| 363 | } |
| 364 | |
| 365 | fn color(c: &ColorConfig) -> Av1ColorConfig { |
| 366 | Av1ColorConfig { |
| 367 | bit_depth: c.bit_depth, |
| 368 | mono_chrome: c.mono_chrome, |
| 369 | color_range: c.color_range, |
| 370 | separate_uv_delta_q: c.separate_uv_delta_q, |
| 371 | subsampling_x: c.subsampling_x, |
| 372 | subsampling_y: c.subsampling_y, |
| 373 | color_primaries: c.color_primaries, |
| 374 | transfer_characteristics: c.transfer_characteristics, |
| 375 | matrix_coefficients: c.matrix_coefficients, |
| 376 | chroma_sample_position: match c.chroma_sample_position { |
| 377 | ChromaSamplePosition::Unknown => 0, |
| 378 | ChromaSamplePosition::Vertical => 1, |
| 379 | ChromaSamplePosition::Colocated => 2, |
| 380 | ChromaSamplePosition::Reserved => 3, |
| 381 | }, |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | fn av1_sequence(s: &SequenceHeader) -> Av1SequenceHeader { |
| 386 | Av1SequenceHeader { |
| 387 | seq_profile: s.seq_profile, |
| 388 | still_picture: s.still_picture, |
| 389 | reduced_still_picture_header: s.reduced_still_picture_header, |
| 390 | timing_info: s.timing_info.map(|t| Av1TimingInfo { |
| 391 | equal_picture_interval: t.equal_picture_interval, |
| 392 | num_units_in_display_tick: t.num_units_in_display_tick, |
| 393 | time_scale: t.time_scale, |
| 394 | num_ticks_per_picture_minus_1: t.num_ticks_per_picture.saturating_sub(1), |
| 395 | }), |
| 396 | initial_display_delay_present: s.initial_display_delay_present_flag, |
| 397 | frame_width_bits_minus_1: (s.frame_width_bits - 1) as u8, |
| 398 | frame_height_bits_minus_1: (s.frame_height_bits - 1) as u8, |
| 399 | max_frame_width_minus_1: (s.max_frame_width - 1) as u16, |
| 400 | max_frame_height_minus_1: (s.max_frame_height - 1) as u16, |
| 401 | frame_id_numbers_present: s.frame_id_numbers_present_flag, |
| 402 | delta_frame_id_length_minus_2: s.delta_frame_id_length.saturating_sub(2) as u8, |
| 403 | additional_frame_id_length_minus_1: s.additional_frame_id_length.saturating_sub(1) as u8, |
| 404 | order_hint_bits_minus_1: s.order_hint_bits.saturating_sub(1) as u8, |
| 405 | seq_force_integer_mv: s.seq_force_integer_mv, |
| 406 | seq_force_screen_content_tools: s.seq_force_screen_content_tools, |
| 407 | use_128x128_superblock: s.use_128x128_superblock, |
| 408 | enable_filter_intra: s.enable_filter_intra, |
| 409 | enable_intra_edge_filter: s.enable_intra_edge_filter, |
| 410 | enable_interintra_compound: s.enable_interintra_compound, |
| 411 | enable_masked_compound: s.enable_masked_compound, |
| 412 | enable_warped_motion: s.enable_warped_motion, |
| 413 | enable_dual_filter: s.enable_dual_filter, |
| 414 | enable_order_hint: s.enable_order_hint, |
| 415 | enable_jnt_comp: s.enable_jnt_comp, |
| 416 | enable_ref_frame_mvs: s.enable_ref_frame_mvs, |
| 417 | enable_superres: s.enable_superres, |
| 418 | enable_cdef: s.enable_cdef, |
| 419 | enable_restoration: s.enable_restoration, |
| 420 | color_config: color(&s.color_config), |
| 421 | film_grain_params_present: s.film_grain_params_present, |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | fn restoration(r: RestorationType) -> Av1Restoration { |
| 426 | match r { |
| 427 | RestorationType::None => Av1Restoration::None, |
| 428 | RestorationType::Wiener => Av1Restoration::Wiener, |
| 429 | RestorationType::Sgrproj => Av1Restoration::Sgrproj, |
| 430 | RestorationType::Switchable => Av1Restoration::Switchable, |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | fn frame_header(h: &FrameHeader, s: &SequenceHeader) -> Av1FrameHeader { |
| 435 | let sb_shift = s.sb_shift(); |
| 436 | let mut global_motion = [Av1GlobalMotion::default(); 8]; |
| 437 | let mut order_hints = [0u8; 8]; |
| 438 | for i in 0..REFS_PER_FRAME { |
| 439 | global_motion[i + 1] = Av1GlobalMotion { |
| 440 | model: match h.global_motion[i].model { |
| 441 | WarpModel::Identity => Av1WarpModel::Identity, |
| 442 | WarpModel::Translation => Av1WarpModel::Translation, |
| 443 | WarpModel::Rotzoom => Av1WarpModel::Rotzoom, |
| 444 | WarpModel::Affine => Av1WarpModel::Affine, |
| 445 | }, |
| 446 | params: h.global_motion[i].params, |
| 447 | }; |
| 448 | order_hints[i + 1] = h.order_hints[i] as u8; |
| 449 | } |
| 450 | Av1FrameHeader { |
| 451 | frame_type: av1_frame_type(h.frame_type), |
| 452 | show_frame: h.show_frame, |
| 453 | showable_frame: h.showable_frame, |
| 454 | error_resilient_mode: h.error_resilient_mode, |
| 455 | disable_cdf_update: h.disable_cdf_update, |
| 456 | allow_screen_content_tools: h.allow_screen_content_tools, |
| 457 | force_integer_mv: h.force_integer_mv, |
| 458 | current_frame_id: h.current_frame_id, |
| 459 | frame_size_override_flag: h.frame_size_override_flag, |
| 460 | order_hint: h.order_hint as u8, |
| 461 | primary_ref_frame: h.primary_ref_frame, |
| 462 | refresh_frame_flags: h.refresh_frame_flags, |
| 463 | frame_width: h.frame_width, |
| 464 | frame_height: h.frame_height, |
| 465 | upscaled_width: h.upscaled_width, |
| 466 | render_width: h.render_width, |
| 467 | render_height: h.render_height, |
| 468 | use_superres: h.use_superres, |
| 469 | superres_denom: h.superres_denom, |
| 470 | allow_intrabc: h.allow_intrabc, |
| 471 | allow_high_precision_mv: h.allow_high_precision_mv, |
| 472 | is_motion_mode_switchable: h.is_motion_mode_switchable, |
| 473 | use_ref_frame_mvs: h.use_ref_frame_mvs, |
| 474 | frame_refs_short_signaling: h.frame_refs_short_signaling, |
| 475 | disable_frame_end_update_cdf: h.disable_frame_end_update_cdf, |
| 476 | reference_select: h.reference_select, |
| 477 | skip_mode_present: h.skip_mode_present, |
| 478 | allow_warped_motion: h.allow_warped_motion, |
| 479 | reduced_tx_set: h.reduced_tx_set, |
| 480 | interpolation_filter: match h.interpolation_filter { |
| 481 | InterpolationFilter::Eighttap => Av1InterpolationFilter::EightTap, |
| 482 | InterpolationFilter::EighttapSmooth => Av1InterpolationFilter::EightTapSmooth, |
| 483 | InterpolationFilter::EighttapSharp => Av1InterpolationFilter::EightTapSharp, |
| 484 | InterpolationFilter::Bilinear => Av1InterpolationFilter::Bilinear, |
| 485 | InterpolationFilter::Switchable => Av1InterpolationFilter::Switchable, |
| 486 | }, |
| 487 | tx_mode: match h.tx_mode { |
| 488 | TxMode::Only4x4 => Av1TxMode::Only4x4, |
| 489 | TxMode::Largest => Av1TxMode::Largest, |
| 490 | TxMode::Select => Av1TxMode::Select, |
| 491 | }, |
| 492 | tile_info: Av1TileInfo { |
| 493 | uniform_spacing: h.tile_info.uniform_spacing, |
| 494 | cols: h.tile_info.cols as u8, |
| 495 | rows: h.tile_info.rows as u8, |
| 496 | mi_col_starts: h |
| 497 | .tile_info |
| 498 | .mi_col_starts |
| 499 | .iter() |
| 500 | .map(|&v| v as u16) |
| 501 | .collect(), |
| 502 | mi_row_starts: h |
| 503 | .tile_info |
| 504 | .mi_row_starts |
| 505 | .iter() |
| 506 | .map(|&v| v as u16) |
| 507 | .collect(), |
| 508 | width_in_sbs_minus_1: h.tile_info.width_in_sbs_minus_1(sb_shift), |
| 509 | height_in_sbs_minus_1: h.tile_info.height_in_sbs_minus_1(sb_shift), |
| 510 | context_update_tile_id: h.tile_info.context_update_tile_id as u16, |
| 511 | tile_size_bytes_minus_1: h.tile_info.tile_size_bytes.saturating_sub(1) as u8, |
| 512 | }, |
| 513 | quantization: Av1Quantization { |
| 514 | base_q_idx: h.quantization.base_q_idx, |
| 515 | delta_q_y_dc: h.quantization.delta_q_y_dc, |
| 516 | delta_q_u_dc: h.quantization.delta_q_u_dc, |
| 517 | delta_q_u_ac: h.quantization.delta_q_u_ac, |
| 518 | delta_q_v_dc: h.quantization.delta_q_v_dc, |
| 519 | delta_q_v_ac: h.quantization.delta_q_v_ac, |
| 520 | using_qmatrix: h.quantization.using_qmatrix, |
| 521 | qm_y: h.quantization.qm_y, |
| 522 | qm_u: h.quantization.qm_u, |
| 523 | qm_v: h.quantization.qm_v, |
| 524 | }, |
| 525 | segmentation: Av1Segmentation { |
| 526 | enabled: h.segmentation.enabled, |
| 527 | update_map: h.segmentation.update_map, |
| 528 | temporal_update: h.segmentation.temporal_update, |
| 529 | update_data: h.segmentation.update_data, |
| 530 | feature_enabled: h.segmentation.feature_enabled, |
| 531 | feature_data: h.segmentation.feature_data, |
| 532 | }, |
| 533 | delta: Av1DeltaParams { |
| 534 | q_present: h.delta.q_present, |
| 535 | q_res: h.delta.q_res, |
| 536 | lf_present: h.delta.lf_present, |
| 537 | lf_res: h.delta.lf_res, |
| 538 | lf_multi: h.delta.lf_multi, |
| 539 | }, |
| 540 | loop_filter: Av1LoopFilter { |
| 541 | level: h.loop_filter.level, |
| 542 | sharpness: h.loop_filter.sharpness, |
| 543 | delta_enabled: h.loop_filter.delta_enabled, |
| 544 | delta_update: h.loop_filter.delta_update, |
| 545 | ref_deltas: h.loop_filter.ref_deltas, |
| 546 | mode_deltas: h.loop_filter.mode_deltas, |
| 547 | }, |
| 548 | cdef: Av1Cdef { |
| 549 | damping_minus_3: h.cdef.damping.saturating_sub(3), |
| 550 | bits: h.cdef.bits, |
| 551 | y_pri: h.cdef.y_pri_strength, |
| 552 | y_sec: h.cdef.y_sec_strength, |
| 553 | uv_pri: h.cdef.uv_pri_strength, |
| 554 | uv_sec: h.cdef.uv_sec_strength, |
| 555 | }, |
| 556 | loop_restoration: Av1LoopRestoration { |
| 557 | frame_restoration_type: h.loop_restoration.frame_restoration_type.map(restoration), |
| 558 | loop_restoration_size: h |
| 559 | .loop_restoration |
| 560 | .loop_restoration_size |
| 561 | .map(|v| v as u16), |
| 562 | }, |
| 563 | global_motion, |
| 564 | order_hints, |
| 565 | skip_mode_frame: h.skip_mode_frame, |
| 566 | expected_frame_id: [0; 8], |
| 567 | apply_grain: false, |
| 568 | } |
| 569 | } |