-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathvideo_recorder.rs
79 lines (68 loc) · 1.67 KB
/
video_recorder.rs
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
use std::sync::{Condvar, Mutex};
use crate::{platform::impl_video_recorder::ImplVideoRecorder, XCapResult};
#[derive(Debug, Clone)]
pub struct Frame {
pub width: u32,
pub height: u32,
pub raw: Vec<u8>,
}
impl Frame {
pub fn new(width: u32, height: u32, raw: Vec<u8>) -> Self {
Self { width, height, raw }
}
}
#[allow(dead_code)]
#[derive(Debug)]
pub(crate) struct RecorderWaker {
parking: Mutex<bool>,
condvar: Condvar,
}
impl RecorderWaker {
#[allow(dead_code)]
pub fn new() -> Self {
Self {
parking: Mutex::new(true),
condvar: Condvar::new(),
}
}
#[allow(dead_code)]
pub fn wake(&self) -> XCapResult<()> {
let mut parking = self.parking.lock()?;
*parking = false;
self.condvar.notify_one();
Ok(())
}
#[allow(dead_code)]
pub fn sleep(&self) -> XCapResult<()> {
let mut parking = self.parking.lock()?;
*parking = true;
Ok(())
}
#[allow(dead_code)]
pub fn wait(&self) -> XCapResult<()> {
let mut parking = self.parking.lock()?;
while *parking {
parking = self.condvar.wait(parking)?;
}
Ok(())
}
}
#[derive(Debug, Clone)]
pub struct VideoRecorder {
impl_video_recorder: ImplVideoRecorder,
}
impl VideoRecorder {
pub(crate) fn new(impl_video_recorder: ImplVideoRecorder) -> VideoRecorder {
VideoRecorder {
impl_video_recorder,
}
}
}
impl VideoRecorder {
pub fn start(&self) -> XCapResult<()> {
self.impl_video_recorder.start()
}
pub fn stop(&self) -> XCapResult<()> {
self.impl_video_recorder.stop()
}
}