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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use std::error;
use std::fmt;
use std::fmt::Display;
use enumn::N;
use super::bindings;
use super::session::VeaInputBufferId;
use super::session::VeaOutputBufferId;
use crate::error::*;
#[derive(Debug, Clone, Copy, N)]
#[repr(u32)]
pub enum VeaError {
IllegalState = bindings::vea_error_ILLEGAL_STATE_ERROR,
InvalidArgument = bindings::vea_error_INVALID_ARGUMENT_ERROR,
PlatformFailure = bindings::vea_error_PLATFORM_FAILURE_ERROR,
}
impl error::Error for VeaError {}
impl VeaError {
pub(crate) fn new(res: bindings::vea_error_t) -> VeaError {
VeaError::n(res).unwrap_or_else(|| panic!("Unknown error is reported from VEA: {}", res))
}
}
impl Display for VeaError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use self::VeaError::*;
match self {
IllegalState => write!(f, "illegal state"),
InvalidArgument => write!(f, "invalid argument"),
PlatformFailure => write!(f, "platform failure"),
}
}
}
#[derive(Debug)]
pub enum Event {
RequireInputBuffers {
input_count: u32,
input_frame_width: u32,
input_frame_height: u32,
output_buffer_size: u32,
},
ProcessedInputBuffer(VeaInputBufferId),
ProcessedOutputBuffer {
output_buffer_id: VeaOutputBufferId,
payload_size: u32,
key_frame: bool,
timestamp: i64,
},
FlushResponse { flush_done: bool },
NotifyError(VeaError),
}
impl Event {
pub(crate) unsafe fn new(event: bindings::vea_event_t) -> Result<Self> {
use self::Event::*;
let bindings::vea_event_t {
event_data,
event_type,
} = event;
match event_type {
bindings::vea_event_type_REQUIRE_INPUT_BUFFERS => {
let d = event_data.require_input_buffers;
Ok(RequireInputBuffers {
input_count: d.input_count,
input_frame_width: d.input_frame_width,
input_frame_height: d.input_frame_height,
output_buffer_size: d.output_buffer_size,
})
}
bindings::vea_event_type_PROCESSED_INPUT_BUFFER => {
Ok(ProcessedInputBuffer(event_data.processed_input_buffer_id))
}
bindings::vea_event_type_PROCESSED_OUTPUT_BUFFER => {
let d = event_data.processed_output_buffer;
Ok(ProcessedOutputBuffer {
output_buffer_id: d.output_buffer_id,
payload_size: d.payload_size,
key_frame: d.key_frame == 1,
timestamp: d.timestamp,
})
}
bindings::vea_event_type_VEA_FLUSH_RESPONSE => Ok(FlushResponse {
flush_done: event_data.flush_done == 1,
}),
bindings::vea_event_type_VEA_NOTIFY_ERROR => {
Ok(NotifyError(VeaError::new(event_data.error)))
}
t => panic!("Unknown event is reported from VEA: {}", t),
}
}
}