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
use thiserror::Error;
use crate::rate::*;
#[derive(Debug, Error)]
pub enum Error {
#[error("Incompatible version {0}")]
InvalidVersion(i64),
#[error("The summary content is invalid: {0}")]
CorruptedSummary(String),
}
#[derive(Clone, Debug, Default)]
pub struct RateControlConfig {
pub(crate) emit_pass_data: bool,
pub(crate) summary: Option<RateControlSummary>,
}
pub use crate::rate::RCSummary as RateControlSummary;
impl RateControlSummary {
pub(crate) fn from_slice(bytes: &[u8]) -> Result<Self, Error> {
let mut de = RCDeserialize::default();
let _ = de.buffer_fill(bytes, 0, TWOPASS_HEADER_SZ);
de.parse_summary().map_err(Error::CorruptedSummary)
}
}
impl RateControlConfig {
pub fn from_summary_slice(bytes: &[u8]) -> Result<Self, Error> {
Ok(Self {
summary: Some(RateControlSummary::from_slice(bytes)?),
..Default::default()
})
}
pub fn new() -> Self {
Default::default()
}
pub fn with_summary(mut self, summary: RateControlSummary) -> Self {
self.summary = Some(summary);
self
}
pub fn with_emit_data(mut self, emit: bool) -> Self {
self.emit_pass_data = emit;
self
}
}