// Copyright 2020 The Chromium OS Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. //! Implementation of data structures for virtio-video controls. use std::convert::From; use std::io; use data_model::Le32; use crate::virtio::video::format::{Format, Level, Profile}; use crate::virtio::video::protocol::*; use crate::virtio::video::response::Response; use crate::virtio::Writer; #[derive(Debug)] pub enum QueryCtrlType { Bitrate, Profile(Format), Level(Format), } #[derive(Debug)] pub enum QueryCtrlResponse { Profile(Vec), #[allow(dead_code)] Level(Vec), } impl Response for QueryCtrlResponse { fn write(&self, w: &mut Writer) -> Result<(), io::Error> { match self { QueryCtrlResponse::Profile(ps) => { w.write_obj(virtio_video_query_control_resp_profile { num: Le32::from(ps.len() as u32), ..Default::default() })?; w.write_iter(ps.iter().map(|p| Le32::from(*p as u32))) } QueryCtrlResponse::Level(ls) => { w.write_obj(virtio_video_query_control_resp_level { num: Le32::from(ls.len() as u32), ..Default::default() })?; w.write_iter(ls.iter().map(|l| Le32::from(*l as u32))) } } } } #[derive(Debug)] pub enum CtrlType { Bitrate, Profile, Level, } #[derive(Debug)] pub enum CtrlVal { Bitrate(u32), Profile(Profile), Level(Level), } impl Response for CtrlVal { fn write(&self, w: &mut Writer) -> Result<(), io::Error> { match self { CtrlVal::Bitrate(r) => w.write_obj(virtio_video_control_val_bitrate { bitrate: Le32::from(*r), ..Default::default() }), CtrlVal::Profile(p) => w.write_obj(virtio_video_control_val_profile { profile: Le32::from(*p as u32), ..Default::default() }), CtrlVal::Level(l) => w.write_obj(virtio_video_control_val_level { level: Le32::from(*l as u32), ..Default::default() }), } } }