aboutsummaryrefslogtreecommitdiff
path: root/evc
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-03-07 08:00:00 +0100
committermetamuffin <metamuffin@disroot.org>2023-03-07 08:00:00 +0100
commit2167abcf72d978b4ac2f08fa7cbbddaada01f165 (patch)
tree3f384b868333271ba8e47ed583bae0a6af62b3fb /evc
parent200f8064e1b1b96acc7d4a6f0f8321b2da5c2830 (diff)
downloadvideo-codec-experiments-2167abcf72d978b4ac2f08fa7cbbddaada01f165.tar
video-codec-experiments-2167abcf72d978b4ac2f08fa7cbbddaada01f165.tar.bz2
video-codec-experiments-2167abcf72d978b4ac2f08fa7cbbddaada01f165.tar.zst
a
Diffstat (limited to 'evc')
-rw-r--r--evc/Cargo.lock97
-rw-r--r--evc/Cargo.toml1
-rw-r--r--evc/src/bin/decode.rs7
-rw-r--r--evc/src/bin/encode.rs17
-rw-r--r--evc/src/codec/compress.rs9
-rw-r--r--evc/src/codec/decode.rs7
-rw-r--r--evc/src/codec/encode/mod.rs4
7 files changed, 112 insertions, 30 deletions
diff --git a/evc/Cargo.lock b/evc/Cargo.lock
index 632b23f..ee6d574 100644
--- a/evc/Cargo.lock
+++ b/evc/Cargo.lock
@@ -92,6 +92,55 @@ dependencies = [
]
[[package]]
+name = "crossbeam-channel"
+version = "0.5.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c"
+dependencies = [
+ "cfg-if",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-deque"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
+dependencies = [
+ "cfg-if",
+ "crossbeam-epoch",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-epoch"
+version = "0.9.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695"
+dependencies = [
+ "autocfg",
+ "cfg-if",
+ "crossbeam-utils",
+ "memoffset",
+ "scopeguard",
+]
+
+[[package]]
+name = "crossbeam-utils"
+version = "0.8.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "either"
+version = "1.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
+
+[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -207,6 +256,7 @@ dependencies = [
"env_logger",
"indicatif",
"log",
+ "rayon",
"rustdct",
]
@@ -232,6 +282,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
+name = "memoffset"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
name = "num-complex"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -260,6 +319,16 @@ dependencies = [
]
[[package]]
+name = "num_cpus"
+version = "1.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
+dependencies = [
+ "hermit-abi",
+ "libc",
+]
+
+[[package]]
name = "number_prefix"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -335,6 +404,28 @@ dependencies = [
]
[[package]]
+name = "rayon"
+version = "1.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b"
+dependencies = [
+ "either",
+ "rayon-core",
+]
+
+[[package]]
+name = "rayon-core"
+version = "1.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d"
+dependencies = [
+ "crossbeam-channel",
+ "crossbeam-deque",
+ "crossbeam-utils",
+ "num_cpus",
+]
+
+[[package]]
name = "regex"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -390,6 +481,12 @@ dependencies = [
]
[[package]]
+name = "scopeguard"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
+
+[[package]]
name = "strength_reduce"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/evc/Cargo.toml b/evc/Cargo.toml
index 9669d1c..ceed3a6 100644
--- a/evc/Cargo.toml
+++ b/evc/Cargo.toml
@@ -7,6 +7,7 @@ edition = "2021"
clap = { version = "*", features = ["derive"] }
anyhow = "1.0.66"
log = "0.4.17"
+rayon = "1.7.0"
env_logger = "0.10.0"
rustdct = "0.7.1"
indicatif = "*"
diff --git a/evc/src/bin/decode.rs b/evc/src/bin/decode.rs
index 4ac4fc8..fbf5624 100644
--- a/evc/src/bin/decode.rs
+++ b/evc/src/bin/decode.rs
@@ -17,9 +17,6 @@ use std::io::{BufReader, BufWriter};
pub struct DecodeArgs {
#[arg(long)]
debug: bool,
-
- #[arg(short, long, default_value = "8")]
- jobs: usize,
}
fn main() -> anyhow::Result<()> {
@@ -36,9 +33,7 @@ fn main() -> anyhow::Result<()> {
}
let size = header.resolution;
- let config = DecodeConfig {
- max_threads: args.jobs,
- };
+ let config = DecodeConfig {};
let progress_bar = ProgressBar::new(header.frame_count as u64);
diff --git a/evc/src/bin/encode.rs b/evc/src/bin/encode.rs
index e1f6730..6d18992 100644
--- a/evc/src/bin/encode.rs
+++ b/evc/src/bin/encode.rs
@@ -3,6 +3,7 @@ use clap::Parser;
use indicatif::ProgressBar;
use libreschmux::{
codec::{
+ compress::compress_block,
decode::{decode_block, DecodeConfig},
encode::{encode_block, EncodeConfig, EncodeMode},
},
@@ -11,6 +12,7 @@ use libreschmux::{
helpers::vector::Vec2,
};
use log::info;
+use rayon::{ThreadPool, ThreadPoolBuilder};
use std::io::{BufReader, BufWriter};
#[derive(Parser)]
@@ -35,9 +37,6 @@ pub struct EncodeArgs {
length: Option<usize>,
#[arg(short, long, default_value = "8")]
- jobs: usize,
-
- #[arg(short, long, default_value = "8")]
min_block_size: isize,
#[arg(short = 't', long, default_value = "200")]
@@ -57,7 +56,6 @@ fn main() -> anyhow::Result<()> {
weight_factor: 50.0,
max_diff_area: 10_000,
min_block_size: args.min_block_size,
- max_threads: args.jobs,
do_translate: !args.no_translate,
do_linear_transform: !args.no_linear_transform,
do_value_scale: !args.no_value_scale,
@@ -75,8 +73,8 @@ fn main() -> anyhow::Result<()> {
.context("writing header")?;
let progress_bar = args.length.map(|len| ProgressBar::new(len as u64));
-
let mut prev_frame = Frame::new(size);
+
for i in 0.. {
info!("encode frame {i}");
let mut frame = Frame::read(&mut input, size).context("reading raw frame")?;
@@ -106,14 +104,7 @@ fn main() -> anyhow::Result<()> {
progress_bar.inc(1);
}
- decode_block(
- &root,
- frame.view_mut(),
- prev_frame.view(),
- &DecodeConfig {
- max_threads: config.max_threads,
- },
- );
+ decode_block(&root, frame.view_mut(), prev_frame.view(), &DecodeConfig {});
prev_frame = frame;
}
diff --git a/evc/src/codec/compress.rs b/evc/src/codec/compress.rs
index 688f04b..09d1f29 100644
--- a/evc/src/codec/compress.rs
+++ b/evc/src/codec/compress.rs
@@ -65,17 +65,20 @@ pub fn lit_compress(w: usize, h: usize, pixels: &[Pixel]) -> Vec<u8> {
norm_dct_channel(w, h, &mut ch);
for i in 0..w * h {
- out.push(unsafe { std::mem::transmute(ch[i] as i8) });
+ out.extend(unsafe { std::mem::transmute::<_, [u8; 4]>(ch[i]) });
}
}
out
}
+
pub fn lit_decompress(compressed: &[u8], mut target: View<&mut Frame>) {
let (w, h) = (target.size.x as usize, target.size.y as usize);
for ci in 0..3 {
let mut ch = compressed[ci * w * h..(ci + 1) * w * h]
- .iter()
- .map(|v| unsafe { std::mem::transmute::<_, i8>(*v) } as f32)
+ .chunks_exact(4)
+ .map(|v| unsafe {
+ std::mem::transmute::<_, f32>(TryInto::<[u8; 4]>::try_into(v).unwrap())
+ })
.collect::<Vec<_>>();
norm_idct_channel(w, h, &mut ch);
for y in 0..h {
diff --git a/evc/src/codec/decode.rs b/evc/src/codec/decode.rs
index bb2aadf..b1f6a3d 100644
--- a/evc/src/codec/decode.rs
+++ b/evc/src/codec/decode.rs
@@ -3,9 +3,7 @@ use crate::{
block::Block, frame::Frame, helpers::threading::both_par, refsampler::Sampler, view::View,
};
-pub struct DecodeConfig {
- pub max_threads: usize,
-}
+pub struct DecodeConfig {}
pub fn decode_block(
block: &Block,
@@ -24,10 +22,9 @@ pub fn decode_block(
unsafe { std::mem::transmute::<_, [View<&'static Frame>; 2]>(prev.split()) };
let config = unsafe { std::mem::transmute::<_, &'static DecodeConfig>(config) };
- both_par(
+ rayon::join(
move || decode_block(a, at, ap, config),
move || decode_block(b, bt, bp, config),
- config.max_threads,
);
}
Block::CompressedLiteral(data) => {
diff --git a/evc/src/codec/encode/mod.rs b/evc/src/codec/encode/mod.rs
index 8b7b342..43607aa 100644
--- a/evc/src/codec/encode/mod.rs
+++ b/evc/src/codec/encode/mod.rs
@@ -15,7 +15,6 @@ pub struct EncodeConfig {
pub ref_thres: f64,
pub max_diff_area: isize,
pub min_block_size: isize,
- pub max_threads: usize,
pub weight_factor: f64,
pub do_translate: bool,
@@ -72,10 +71,9 @@ pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfi
// only bother to do multithreading, when the block is big.
let ((ad, a), (bd, b)) = if view.area() > 100 {
- both_par(
+ rayon::join(
|| encode_block(av, ap, config),
|| encode_block(bv, bp, config),
- config.max_threads,
)
} else {
(encode_block(av, ap, config), encode_block(bv, bp, config))