Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/devices/src/virtio/video/control.rs
5394 views
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
//! Implementation of data structures for virtio-video controls.
6
7
use std::convert::From;
8
use std::io;
9
10
use data_model::Le32;
11
12
use crate::virtio::video::format::BitrateMode;
13
use crate::virtio::video::format::Format;
14
use crate::virtio::video::format::Level;
15
use crate::virtio::video::format::Profile;
16
use crate::virtio::video::protocol::*;
17
use crate::virtio::video::response::Response;
18
use crate::virtio::Writer;
19
20
#[derive(Debug)]
21
pub enum QueryCtrlType {
22
Profile(Format),
23
Level(Format),
24
}
25
26
#[derive(Debug, Clone)]
27
pub enum QueryCtrlResponse {
28
Profile(Vec<Profile>),
29
#[allow(dead_code)]
30
Level(Vec<Level>),
31
}
32
33
impl Response for QueryCtrlResponse {
34
fn write(&self, w: &mut Writer) -> Result<(), io::Error> {
35
match self {
36
QueryCtrlResponse::Profile(ps) => {
37
w.write_obj(virtio_video_query_control_resp_profile {
38
num: Le32::from(ps.len() as u32),
39
..Default::default()
40
})?;
41
w.write_iter(ps.iter().map(|p| Le32::from(*p as u32)))
42
}
43
QueryCtrlResponse::Level(ls) => {
44
w.write_obj(virtio_video_query_control_resp_level {
45
num: Le32::from(ls.len() as u32),
46
..Default::default()
47
})?;
48
w.write_iter(ls.iter().map(|l| Le32::from(*l as u32)))
49
}
50
}
51
}
52
}
53
54
#[derive(Debug)]
55
pub enum CtrlType {
56
Bitrate,
57
Profile,
58
Level,
59
ForceKeyframe,
60
BitrateMode,
61
BitratePeak,
62
PrependSpsPpsToIdr,
63
}
64
65
#[derive(Debug, Clone)]
66
pub enum CtrlVal {
67
Bitrate(u32),
68
Profile(Profile),
69
Level(Level),
70
ForceKeyframe,
71
BitrateMode(BitrateMode),
72
BitratePeak(u32),
73
PrependSpsPpsToIdr(bool),
74
}
75
76
impl Response for CtrlVal {
77
fn write(&self, w: &mut Writer) -> Result<(), io::Error> {
78
match self {
79
CtrlVal::Bitrate(r) => w.write_obj(virtio_video_control_val_bitrate {
80
bitrate: Le32::from(*r),
81
..Default::default()
82
}),
83
CtrlVal::BitratePeak(r) => w.write_obj(virtio_video_control_val_bitrate_peak {
84
bitrate_peak: Le32::from(*r),
85
..Default::default()
86
}),
87
CtrlVal::BitrateMode(m) => w.write_obj(virtio_video_control_val_bitrate_mode {
88
bitrate_mode: Le32::from(*m as u32),
89
..Default::default()
90
}),
91
CtrlVal::Profile(p) => w.write_obj(virtio_video_control_val_profile {
92
profile: Le32::from(*p as u32),
93
..Default::default()
94
}),
95
CtrlVal::Level(l) => w.write_obj(virtio_video_control_val_level {
96
level: Le32::from(*l as u32),
97
..Default::default()
98
}),
99
CtrlVal::ForceKeyframe => Err(io::Error::new(
100
io::ErrorKind::InvalidInput,
101
"Button controls should not be queried.",
102
)),
103
CtrlVal::PrependSpsPpsToIdr(p) => {
104
w.write_obj(virtio_video_control_val_prepend_spspps_to_idr {
105
prepend_spspps_to_idr: Le32::from(*p as u32),
106
..Default::default()
107
})
108
}
109
}
110
}
111
}
112
113