1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// 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<Profile>),
#[allow(dead_code)]
Level(Vec<Level>),
}
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()
}),
}
}
}
|