summary refs log tree commit diff
path: root/devices/src/virtio/video/event.rs
blob: 8c49253cc060612a07fc3f7944560016665e6bbf (plain) (blame)
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
// 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.

//! Events can happen in virtio video devices.

use std::io;

use data_model::Le32;
use enumn::N;

use crate::virtio::video::protocol::*;
use crate::virtio::video::response::Response;
use crate::virtio::Writer;

#[allow(dead_code)] // TODO(keiichiw): Remove this attribute
#[derive(Debug, Copy, Clone, N)]
pub enum EvtType {
    Error = VIRTIO_VIDEO_EVENT_ERROR as isize,
    DecResChanged = VIRTIO_VIDEO_EVENT_DECODER_RESOLUTION_CHANGED as isize,
}

#[derive(Debug, Clone)]
pub struct VideoEvt {
    pub typ: EvtType,
    pub stream_id: u32,
}

impl Response for VideoEvt {
    fn write(&self, w: &mut Writer) -> Result<(), io::Error> {
        w.write_obj(virtio_video_event {
            event_type: Le32::from(self.typ as u32),
            stream_id: Le32::from(self.stream_id),
        })
    }
}