devices/virtio/video/decoder/
capability.rs

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//! Capablities of the virtio video decoder device.
6
7use std::collections::BTreeMap;
8
9use crate::virtio::video::control::*;
10use crate::virtio::video::format::*;
11
12#[derive(Clone)]
13pub struct Capability {
14    in_fmts: Vec<FormatDesc>,
15    out_fmts: Vec<FormatDesc>,
16
17    // Stores supporterd profiles and levels for each format.
18    profiles: BTreeMap<Format, Vec<Profile>>,
19    levels: BTreeMap<Format, Vec<Level>>,
20}
21
22impl Capability {
23    // Make this method pub(super) so backends can create capabilities.
24    pub(super) fn new(
25        in_fmts: Vec<FormatDesc>,
26        out_fmts: Vec<FormatDesc>,
27        profiles: BTreeMap<Format, Vec<Profile>>,
28        levels: BTreeMap<Format, Vec<Level>>,
29    ) -> Self {
30        Self {
31            in_fmts,
32            out_fmts,
33            profiles,
34            levels,
35        }
36    }
37
38    pub fn input_formats(&self) -> &Vec<FormatDesc> {
39        &self.in_fmts
40    }
41
42    pub fn output_formats(&self) -> &Vec<FormatDesc> {
43        &self.out_fmts
44    }
45
46    pub fn query_control(&self, t: &QueryCtrlType) -> Option<QueryCtrlResponse> {
47        use QueryCtrlType::*;
48        match *t {
49            Profile(fmt) => {
50                let profiles = self.profiles.get(&fmt)?;
51                Some(QueryCtrlResponse::Profile(profiles.to_vec()))
52            }
53            Level(fmt) => {
54                let levels = self.levels.get(&fmt)?;
55                Some(QueryCtrlResponse::Level(levels.to_vec()))
56            }
57        }
58    }
59}