devices/virtio/video/
event.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//! Events can happen in virtio video devices.
6
7use std::io;
8
9use data_model::Le32;
10use enumn::N;
11
12use crate::virtio::video::protocol::*;
13use crate::virtio::video::response::Response;
14use crate::virtio::Writer;
15
16#[derive(Debug, Copy, Clone, N)]
17pub enum EvtType {
18    Error = VIRTIO_VIDEO_EVENT_ERROR as isize,
19    #[cfg(feature = "video-decoder")]
20    DecResChanged = VIRTIO_VIDEO_EVENT_DECODER_RESOLUTION_CHANGED as isize,
21}
22
23#[derive(Debug, Clone)]
24pub struct VideoEvt {
25    pub typ: EvtType,
26    pub stream_id: u32,
27}
28
29impl Response for VideoEvt {
30    fn write(&self, w: &mut Writer) -> Result<(), io::Error> {
31        w.write_obj(virtio_video_event {
32            event_type: Le32::from(self.typ as u32),
33            stream_id: Le32::from(self.stream_id),
34        })
35    }
36}