aboutsummaryrefslogtreecommitdiff
path: root/evc/src/codec/encode.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-12-06 22:16:50 +0100
committermetamuffin <metamuffin@disroot.org>2022-12-06 22:16:50 +0100
commita713143ef9c1187c37004043b1d3322d773f9ea0 (patch)
treeb5d390a77fa6428d0648d9446a75978f85fdbb5f /evc/src/codec/encode.rs
parent39cb075c7f58e78899be43ca9ad4d65837f53a26 (diff)
downloadvideo-codec-experiments-a713143ef9c1187c37004043b1d3322d773f9ea0.tar
video-codec-experiments-a713143ef9c1187c37004043b1d3322d773f9ea0.tar.bz2
video-codec-experiments-a713143ef9c1187c37004043b1d3322d773f9ea0.tar.zst
webm + variable amount of threads
Diffstat (limited to 'evc/src/codec/encode.rs')
-rw-r--r--evc/src/codec/encode.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/evc/src/codec/encode.rs b/evc/src/codec/encode.rs
index 13df17d..dbefdb4 100644
--- a/evc/src/codec/encode.rs
+++ b/evc/src/codec/encode.rs
@@ -8,6 +8,7 @@ pub struct EncodeConfig {
pub ref_thres: f64,
pub max_diff_size: isize,
pub min_block_size: isize,
+ pub max_threads: usize,
// pub importance_k: f64,
// pub importance_scale: f64,
}
@@ -40,7 +41,7 @@ pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfi
if diff < (config.ref_thres) {
Block::Reference { translation }
} else {
- if view.size.x < config.min_block_size {
+ if view.size.x < config.min_block_size || view.size.y < config.min_block_size {
Block::Literal(view.pixels())
} else {
let [av, bv] =
@@ -48,10 +49,18 @@ pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfi
let [ap, bp] =
unsafe { std::mem::transmute::<_, [View<&'static Frame>; 2]>(prev.split()) };
let config = unsafe { std::mem::transmute::<_, &'static EncodeConfig>(config) };
- let (a, b) = both_par(
- || encode_block(av, ap, config),
- || encode_block(bv, bp, config),
- );
+
+ // only bother to do multithreading, when the block is big.
+ let (a, b) = if view.size.x > 64 {
+ both_par(
+ || encode_block(av, ap, config),
+ || encode_block(bv, bp, config),
+ config.max_threads,
+ )
+ } else {
+ (encode_block(av, ap, config), encode_block(bv, bp, config))
+ };
+
if a.is_literal() && b.is_literal() {
Block::Literal(view.pixels())
} else {