Commit 64c55950 authored by Luca Barbato's avatar Luca Barbato Committed by Luca Barbato

Move the context inner allocation

parent fdbdb227
......@@ -481,14 +481,6 @@ impl Config {
pub fn new_context<T: Pixel>(&self) -> Context<T> {
assert!(8 * std::mem::size_of::<T>() >= self.enc.bit_depth, "The Pixel u{} does not match the Config bit_depth {}",
8 * std::mem::size_of::<T>(), self.enc.bit_depth);
// initialize with temporal delimiter
let packet_data = TEMPORAL_DELIMITER.to_vec();
let maybe_ac_qi_max = if self.enc.quantizer < 255 {
Some(self.enc.quantizer as u8)
} else {
None
};
let pool = rayon::ThreadPoolBuilder::new().num_threads(self.threads).build().unwrap();
......@@ -507,32 +499,10 @@ impl Config {
config.speed_settings.rdo_tx_decision = false;
}
let inner = ContextInner::new(&config);
Context {
inner: ContextInner {
frame_count: 0,
limit: 0,
idx: 0,
frames_processed: 0,
frame_q: BTreeMap::new(),
frame_invariants: BTreeMap::new(),
keyframes: BTreeSet::new(),
packet_data,
segment_start_idx: 0,
segment_start_frame: 0,
keyframe_detector: SceneChangeDetector::new(self.enc.bit_depth),
config: self.enc.clone(),
rc_state: RCState::new(
self.enc.width as i32,
self.enc.height as i32,
self.enc.time_base.num as i64,
self.enc.time_base.den as i64,
self.enc.bitrate,
maybe_ac_qi_max,
self.enc.max_key_frame_interval as i32
),
maybe_prev_log_base_q: None,
first_pass_data: FirstPassData { frames: Vec::new() },
},
inner,
pool,
config
}
......@@ -677,6 +647,43 @@ impl<T: Pixel> Context<T> {
impl<T: Pixel> ContextInner<T> {
pub fn new(enc: &EncoderConfig) -> Self {
// initialize with temporal delimiter
let packet_data = TEMPORAL_DELIMITER.to_vec();
let maybe_ac_qi_max = if enc.quantizer < 255 {
Some(enc.quantizer as u8)
} else {
None
};
ContextInner {
frame_count: 0,
limit: 0,
idx: 0,
frames_processed: 0,
frame_q: BTreeMap::new(),
frame_invariants: BTreeMap::new(),
keyframes: BTreeSet::new(),
packet_data,
segment_start_idx: 0,
segment_start_frame: 0,
keyframe_detector: SceneChangeDetector::new(enc.bit_depth),
config: enc.clone(),
rc_state: RCState::new(
enc.width as i32,
enc.height as i32,
enc.time_base.num as i64,
enc.time_base.den as i64,
enc.bitrate,
maybe_ac_qi_max,
enc.max_key_frame_interval as i32
),
maybe_prev_log_base_q: None,
first_pass_data: FirstPassData { frames: Vec::new() },
}
}
pub fn send_frame<F>(&mut self, frame: F) -> Result<(), EncoderStatus>
where
F: Into<Option<Arc<Frame<T>>>>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment