aboutsummaryrefslogtreecommitdiff
path: root/evc/src/codec/encode.rs
diff options
context:
space:
mode:
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 {