| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | use ec_va::va::{ |
| 8 | BufferType, PictureParameter, PictureParameterBufferVP9 as CrosPicture, |
| 9 | SegmentParameterVP9 as CrosSegment, SliceParameter, SliceParameterBufferVP9 as CrosSlice, |
| 10 | VP9PicFields, VP9SegmentFlags, |
| 11 | }; |
| 12 | |
| 13 | use super::INVALID_SURFACE; |
| 14 | |
| 15 | |
| 16 | |
| 17 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 18 | pub struct PicFields { |
| 19 | |
| 20 | pub subsampling_x: u32, |
| 21 | |
| 22 | pub subsampling_y: u32, |
| 23 | |
| 24 | pub frame_type: u32, |
| 25 | |
| 26 | pub show_frame: u32, |
| 27 | |
| 28 | pub error_resilient_mode: u32, |
| 29 | |
| 30 | pub intra_only: u32, |
| 31 | |
| 32 | pub allow_high_precision_mv: u32, |
| 33 | |
| 34 | pub mcomp_filter_type: u32, |
| 35 | |
| 36 | pub frame_parallel_decoding_mode: u32, |
| 37 | |
| 38 | pub reset_frame_context: u32, |
| 39 | |
| 40 | pub refresh_frame_context: u32, |
| 41 | |
| 42 | pub frame_context_idx: u32, |
| 43 | |
| 44 | pub segmentation_enabled: u32, |
| 45 | |
| 46 | pub segmentation_temporal_update: u32, |
| 47 | |
| 48 | pub segmentation_update_map: u32, |
| 49 | |
| 50 | pub last_ref_frame: u32, |
| 51 | |
| 52 | pub last_ref_frame_sign_bias: u32, |
| 53 | |
| 54 | pub golden_ref_frame: u32, |
| 55 | |
| 56 | pub golden_ref_frame_sign_bias: u32, |
| 57 | |
| 58 | pub alt_ref_frame: u32, |
| 59 | |
| 60 | pub alt_ref_frame_sign_bias: u32, |
| 61 | |
| 62 | pub lossless_flag: u32, |
| 63 | } |
| 64 | |
| 65 | impl PicFields { |
| 66 | fn to_cros(self) -> VP9PicFields { |
| 67 | VP9PicFields::new( |
| 68 | self.subsampling_x, |
| 69 | self.subsampling_y, |
| 70 | self.frame_type, |
| 71 | self.show_frame, |
| 72 | self.error_resilient_mode, |
| 73 | self.intra_only, |
| 74 | self.allow_high_precision_mv, |
| 75 | self.mcomp_filter_type, |
| 76 | self.frame_parallel_decoding_mode, |
| 77 | self.reset_frame_context, |
| 78 | self.refresh_frame_context, |
| 79 | self.frame_context_idx, |
| 80 | self.segmentation_enabled, |
| 81 | self.segmentation_temporal_update, |
| 82 | self.segmentation_update_map, |
| 83 | self.last_ref_frame, |
| 84 | self.last_ref_frame_sign_bias, |
| 85 | self.golden_ref_frame, |
| 86 | self.golden_ref_frame_sign_bias, |
| 87 | self.alt_ref_frame, |
| 88 | self.alt_ref_frame_sign_bias, |
| 89 | self.lossless_flag, |
| 90 | ) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | |
| 95 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 96 | pub struct PictureParameterBufferVP9 { |
| 97 | |
| 98 | pub frame_width: u16, |
| 99 | |
| 100 | pub frame_height: u16, |
| 101 | |
| 102 | pub reference_frames: [u32; 8], |
| 103 | |
| 104 | pub pic_fields: PicFields, |
| 105 | |
| 106 | pub filter_level: u8, |
| 107 | |
| 108 | pub sharpness_level: u8, |
| 109 | |
| 110 | pub log2_tile_rows: u8, |
| 111 | |
| 112 | pub log2_tile_columns: u8, |
| 113 | |
| 114 | pub frame_header_length_in_bytes: u8, |
| 115 | |
| 116 | pub first_partition_size: u16, |
| 117 | |
| 118 | pub mb_segment_tree_probs: [u8; 7], |
| 119 | |
| 120 | pub segment_pred_probs: [u8; 3], |
| 121 | |
| 122 | pub profile: u8, |
| 123 | |
| 124 | pub bit_depth: u8, |
| 125 | } |
| 126 | |
| 127 | impl Default for PictureParameterBufferVP9 { |
| 128 | fn default() -> Self { |
| 129 | PictureParameterBufferVP9 { |
| 130 | frame_width: 0, |
| 131 | frame_height: 0, |
| 132 | reference_frames: [INVALID_SURFACE; 8], |
| 133 | pic_fields: PicFields::default(), |
| 134 | filter_level: 0, |
| 135 | sharpness_level: 0, |
| 136 | log2_tile_rows: 0, |
| 137 | log2_tile_columns: 0, |
| 138 | frame_header_length_in_bytes: 0, |
| 139 | first_partition_size: 0, |
| 140 | |
| 141 | |
| 142 | mb_segment_tree_probs: [255; 7], |
| 143 | segment_pred_probs: [255; 3], |
| 144 | profile: 0, |
| 145 | bit_depth: 8, |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | impl PictureParameterBufferVP9 { |
| 151 | |
| 152 | pub fn to_buffer(&self) -> BufferType { |
| 153 | BufferType::PictureParameter(PictureParameter::VP9(CrosPicture::new( |
| 154 | self.frame_width, |
| 155 | self.frame_height, |
| 156 | self.reference_frames, |
| 157 | &self.pic_fields.to_cros(), |
| 158 | self.filter_level, |
| 159 | self.sharpness_level, |
| 160 | self.log2_tile_rows, |
| 161 | self.log2_tile_columns, |
| 162 | self.frame_header_length_in_bytes, |
| 163 | self.first_partition_size, |
| 164 | self.mb_segment_tree_probs, |
| 165 | self.segment_pred_probs, |
| 166 | self.profile, |
| 167 | self.bit_depth, |
| 168 | ))) |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | |
| 173 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 174 | pub struct SegmentFlags { |
| 175 | |
| 176 | pub segment_reference_enabled: u16, |
| 177 | |
| 178 | pub segment_reference: u16, |
| 179 | |
| 180 | pub segment_reference_skipped: u16, |
| 181 | } |
| 182 | |
| 183 | |
| 184 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 185 | pub struct SegmentParameterVP9 { |
| 186 | |
| 187 | pub segment_flags: SegmentFlags, |
| 188 | |
| 189 | pub filter_level: [[u8; 2]; 4], |
| 190 | |
| 191 | pub luma_ac_quant_scale: i16, |
| 192 | |
| 193 | pub luma_dc_quant_scale: i16, |
| 194 | |
| 195 | pub chroma_ac_quant_scale: i16, |
| 196 | |
| 197 | pub chroma_dc_quant_scale: i16, |
| 198 | } |
| 199 | |
| 200 | impl SegmentParameterVP9 { |
| 201 | fn to_cros(self) -> CrosSegment { |
| 202 | let flags = self.segment_flags; |
| 203 | let segment_flags = VP9SegmentFlags::new( |
| 204 | flags.segment_reference_enabled, |
| 205 | flags.segment_reference, |
| 206 | flags.segment_reference_skipped, |
| 207 | ); |
| 208 | CrosSegment::new( |
| 209 | &segment_flags, |
| 210 | self.filter_level, |
| 211 | self.luma_ac_quant_scale, |
| 212 | self.luma_dc_quant_scale, |
| 213 | self.chroma_ac_quant_scale, |
| 214 | self.chroma_dc_quant_scale, |
| 215 | ) |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | |
| 220 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 221 | pub struct SliceParameterBufferVP9 { |
| 222 | |
| 223 | pub slice_data_size: u32, |
| 224 | |
| 225 | pub slice_data_offset: u32, |
| 226 | |
| 227 | pub slice_data_flag: u32, |
| 228 | |
| 229 | pub seg_param: [SegmentParameterVP9; 8], |
| 230 | } |
| 231 | |
| 232 | impl SliceParameterBufferVP9 { |
| 233 | |
| 234 | pub fn to_buffer(&self) -> BufferType { |
| 235 | BufferType::SliceParameter(SliceParameter::VP9(CrosSlice::new( |
| 236 | self.slice_data_size, |
| 237 | self.slice_data_offset, |
| 238 | self.slice_data_flag, |
| 239 | self.seg_param.map(SegmentParameterVP9::to_cros), |
| 240 | ))) |
| 241 | } |
| 242 | } |