1 // Copyright 2020 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use enumn::N; 6 7 use super::bindings; 8 use crate::error::Result; 9 use crate::format::*; 10 11 /// Represents an output profile for VEA. 12 #[derive(Debug, Clone, Copy)] 13 pub struct OutputProfile { 14 pub profile: Profile, 15 pub max_width: u32, 16 pub max_height: u32, 17 pub max_framerate_numerator: u32, 18 pub max_framerate_denominator: u32, 19 } 20 21 impl OutputProfile { new(p: &bindings::vea_profile_t) -> Result<Self>22 pub(crate) fn new(p: &bindings::vea_profile_t) -> Result<Self> { 23 Ok(Self { 24 profile: Profile::new(p.profile)?, 25 max_width: p.max_width, 26 max_height: p.max_height, 27 max_framerate_numerator: p.max_framerate_numerator, 28 max_framerate_denominator: p.max_framerate_denominator, 29 }) 30 } 31 from_raw_parts( data: *const bindings::vea_profile_t, len: usize, ) -> Result<Vec<Self>>32 pub(crate) unsafe fn from_raw_parts( 33 data: *const bindings::vea_profile_t, 34 len: usize, 35 ) -> Result<Vec<Self>> { 36 validate_formats(data, len, Self::new) 37 } 38 } 39 40 /// Represents a bitrate mode for the VEA. 41 #[derive(Debug, Clone, Copy, N)] 42 #[repr(u32)] 43 pub enum BitrateMode { 44 VBR = bindings::vea_bitrate_mode_VBR, 45 CBR = bindings::vea_bitrate_mode_CBR, 46 } 47 48 /// Represents a bitrate for the VEA. 49 #[derive(Debug, Clone, Copy)] 50 pub struct Bitrate { 51 pub mode: BitrateMode, 52 pub target: u32, 53 pub peak: u32, 54 } 55 56 impl Bitrate { to_raw_bitrate(&self) -> bindings::vea_bitrate_t57 pub fn to_raw_bitrate(&self) -> bindings::vea_bitrate_t { 58 bindings::vea_bitrate_t { 59 mode: match self.mode { 60 BitrateMode::VBR => bindings::vea_bitrate_mode_VBR, 61 BitrateMode::CBR => bindings::vea_bitrate_mode_CBR, 62 }, 63 target: self.target, 64 peak: self.peak, 65 } 66 } 67 } 68