xref: /aosp_15_r20/external/crosvm/devices/src/virtio/video/vda.rs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1 // Copyright 2021 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 //! Utility features shared by both the decoder and encoder VDA backends.
6 
7 use crate::virtio::video::error::VideoError;
8 use crate::virtio::video::format::Profile;
9 
10 /// Transparent convertion from libvda error to VideoError backend failure.
11 impl From<libvda::Error> for VideoError {
from(error: libvda::Error) -> Self12     fn from(error: libvda::Error) -> Self {
13         VideoError::BackendFailure(error.into())
14     }
15 }
16 
17 macro_rules! impl_libvda_conversion {
18     ( $( ( $x:ident, $y:ident ) ),* ) => {
19         pub fn from_libvda_profile(p: libvda::Profile) -> Option<Self> {
20             match p {
21                 $(libvda::Profile::$x => Some(Self::$y),)*
22                 _ => None
23             }
24         }
25 
26         #[cfg(feature = "video-encoder")]
27         pub fn to_libvda_profile(self) -> Option<libvda::Profile> {
28             match self {
29                 $(Self::$y => Some(libvda::Profile::$x),)*
30                 _ => None
31             }
32         }
33     }
34 }
35 
36 impl Profile {
37     impl_libvda_conversion!(
38         (H264ProfileBaseline, H264Baseline),
39         (H264ProfileMain, H264Main),
40         (H264ProfileExtended, H264Extended),
41         (H264ProfileHigh, H264High),
42         (H264ProfileHigh10Profile, H264High10),
43         (H264ProfileHigh422Profile, H264High422),
44         (
45             H264ProfileHigh444PredictiveProfile,
46             H264High444PredictiveProfile
47         ),
48         (H264ProfileScalableBaseline, H264ScalableBaseline),
49         (H264ProfileScalableHigh, H264ScalableHigh),
50         (H264ProfileStereoHigh, H264StereoHigh),
51         (H264ProfileMultiviewHigh, H264MultiviewHigh),
52         (HevcProfileMain, HevcMain),
53         (HevcProfileMain10, HevcMain10),
54         (HevcProfileMainStillPicture, HevcMainStillPicture),
55         (VP8, VP8Profile0),
56         (VP9Profile0, VP9Profile0),
57         (VP9Profile1, VP9Profile1),
58         (VP9Profile2, VP9Profile2),
59         (VP9Profile3, VP9Profile3)
60     );
61 }
62