Skip to content

Commit ab2bedf

Browse files
committed
working av1 and h264 decoder, h265 is fucked up for some reason and idk why??
1 parent 3848c41 commit ab2bedf

211 files changed

Lines changed: 395 additions & 160 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎flake.lock‎

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix‎

Lines changed: 77 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,102 +5,100 @@
55
rust-overlay.url = "github:oxalica/rust-overlay";
66
};
77

8-
outputs =
9-
{
10-
self,
11-
nixpkgs,
12-
rust-overlay,
13-
flake-utils,
14-
...
15-
}:
8+
outputs = {
9+
self,
10+
nixpkgs,
11+
rust-overlay,
12+
flake-utils,
13+
...
14+
}:
1615
flake-utils.lib.eachDefaultSystem (
17-
system:
18-
let
16+
system: let
1917
pkgs = import nixpkgs {
2018
inherit system;
21-
overlays = [ rust-overlay.overlays.default ];
19+
overlays = [rust-overlay.overlays.default];
2220
config.allowUnfree = true;
2321
};
2422
rustshell = pkgs.mkShell.override {
25-
stdenv = pkgs.gccStdenv;
23+
stdenv = pkgs.gccStdenv;
2624
};
2725
rustbin = pkgs.rust-bin.selectLatestNightlyWith (
2826
toolchain:
29-
toolchain.default.override {
30-
extensions = [
31-
"rust-src"
32-
"clippy"
33-
"rustfmt"
34-
"miri"
35-
"rust-analyzer"
36-
];
37-
}
27+
toolchain.default.override {
28+
extensions = [
29+
"rust-src"
30+
"clippy"
31+
"rustfmt"
32+
"miri"
33+
"rust-analyzer"
34+
];
35+
}
3836
);
39-
in
40-
{
37+
in {
4138
formatter = pkgs.alejandra;
4239

4340
devShells.default = rustshell {
44-
packages = [
45-
rustbin
46-
]
47-
++ (with pkgs; [
48-
llvmPackages_21.clangWithLibcAndBasicRtAndLibcxx
49-
pkg-config
50-
cmake
51-
vcpkg
52-
lldb
53-
rustPlatform.bindgenHook
54-
xmlstarlet
55-
opencv
56-
alsa-lib
57-
systemdLibs
58-
cmake
59-
fontconfig
60-
linuxHeaders
61-
v4l-utils
62-
libv4l
63-
pipewire
64-
rustup
65-
gcc
66-
ffmpeg-full
67-
nasm
68-
libGL
69-
flite
70-
quirc
71-
lcevcdec
72-
xz
73-
celt
74-
opencore-amr
75-
snappy
76-
codec2
77-
gsm
78-
ilbc
79-
lame
80-
libtheora
81-
libogg
82-
twolame
83-
vo-amrwbenc
84-
vvenc
85-
xavs
86-
xvidcore
87-
soxr
88-
libvdpau
89-
jetbrains.rust-rover
90-
]);
41+
packages =
42+
[
43+
rustbin
44+
]
45+
++ (with pkgs; [
46+
llvmPackages_21.clangWithLibcAndBasicRtAndLibcxx
47+
pkg-config
48+
cmake
49+
vcpkg
50+
lldb
51+
rustPlatform.bindgenHook
52+
xmlstarlet
53+
opencv
54+
alsa-lib
55+
systemdLibs
56+
cmake
57+
fontconfig
58+
linuxHeaders
59+
v4l-utils
60+
libv4l
61+
pipewire
62+
rustup
63+
gcc
64+
ffmpeg_8-full
65+
nasm
66+
libGL
67+
flite
68+
quirc
69+
lcevcdec
70+
xz
71+
celt
72+
opencore-amr
73+
snappy
74+
codec2
75+
gsm
76+
ilbc
77+
lame
78+
libtheora
79+
libogg
80+
twolame
81+
vo-amrwbenc
82+
vvenc
83+
xavs
84+
xvidcore
85+
soxr
86+
libvdpau
87+
gmp
88+
openapv
89+
svt-av1
90+
]);
9191

9292
env.RUST_SRC_PATH = "${rustbin}/lib/rustlib/src/rust/library";
9393
env.LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
9494

95-
shellHook =
96-
let
97-
pathToRustProject = "/project/component[@name='RustProjectSettings']";
98-
in
99-
''
100-
echo "WONDERHOOOOOY!!!!"
101-
xmlstarlet edit --inplace --update "${pathToRustProject}/option[@name='explicitPathToStdlib']/@value" --value "${rustbin}/lib/rustlib/src/rust/library" .idea/workspace.xml
102-
xmlstarlet edit --inplace --update "${pathToRustProject}/option[@name='toolchainHomeDirectory']/@value" --value "${rustbin}/bin" .idea/workspace.xml
103-
'';
95+
shellHook = let
96+
pathToRustProject = "/project/component[@name='RustProjectSettings']";
97+
in ''
98+
echo "WONDERHOOOOOY!!!!"
99+
xmlstarlet edit --inplace --update "${pathToRustProject}/option[@name='explicitPathToStdlib']/@value" --value "${rustbin}/lib/rustlib/src/rust/library" .idea/workspace.xml
100+
xmlstarlet edit --inplace --update "${pathToRustProject}/option[@name='toolchainHomeDirectory']/@value" --value "${rustbin}/bin" .idea/workspace.xml
101+
'';
104102
};
105103
}
106104
);

‎nokhwa-core/src/codec.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub trait CodecAsync: Codec {
4747
async fn set_format_async(&self, format: CameraFormat) -> Result<(), NokhwaError>;
4848

4949
fn set_config_async(&mut self, config: Self::Config) -> Result<(), NokhwaError> {
50-
self.set_config(config)
50+
self.set_config(&config)
5151
}
5252

5353
fn send_item_async(&mut self, input: Self::Input<'_>) -> Result<(), NokhwaError>;

‎nokhwa-core/src/error.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616
use crate::frame_format::{CustomFrameFormat, FrameFormat};
17-
use std::fmt::Debug;
18-
use thiserror::Error;
1917
use crate::pixel_destination::PixelDestination;
2018
use crate::types::Backends;
19+
use std::fmt::Debug;
20+
use thiserror::Error;
2121

2222
pub type NokhwaResult<T> = Result<T, NokhwaError>;
2323

@@ -85,7 +85,19 @@ pub enum NokhwaError {
8585
DecoderDestinationHintRequired,
8686
#[error("Decoder already deinitialized. Unusable, please make a new decoder.")]
8787
DecoderAlreadyDeinitialized,
88+
#[error(
89+
"Decoder requires more data to process - not actual error - please send more data to decode: {0}"
90+
)]
91+
DecoderNeedsMoreData(String),
8892
}
93+
94+
impl NokhwaError {
95+
#[must_use]
96+
pub fn is_needs_more(&self) -> bool {
97+
matches!(self, NokhwaError::DecoderNeedsMoreData(_))
98+
}
99+
}
100+
89101
//
90102
// pub enum InitializeError {}
91103
//

‎nokhwa-core/src/frame_buffer.rs‎

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,31 @@ pub struct FrameBuffer<'a> {
9090
impl<'a> FrameBuffer<'a> {
9191
/// Creates a new buffer with a [`&[u8]`].
9292
#[must_use]
93-
#[inline]
9493
pub fn new(buffer: Cow<'a, [u8]>, metadata: Option<Metadata>) -> Self {
9594
Self { buffer, metadata }
9695
}
9796

97+
#[must_use]
98+
pub fn from_buffer(buffer: &'a [u8], metadata: Option<Metadata>) -> Self {
99+
FrameBuffer {
100+
buffer: Cow::Borrowed(buffer),
101+
metadata,
102+
}
103+
}
104+
105+
#[must_use]
106+
pub fn from_cow(buffer: Cow<'a, [u8]>, metadata: Option<Metadata>) -> Self {
107+
FrameBuffer { buffer, metadata }
108+
}
109+
110+
#[must_use]
111+
pub fn from_vec(buffer: Vec<u8>, metadata: Option<Metadata>) -> Self {
112+
FrameBuffer {
113+
buffer: Cow::Owned(buffer),
114+
metadata,
115+
}
116+
}
117+
98118
/// Get the data of this buffer.
99119
#[must_use]
100120
pub fn buffer(&'a self) -> &'a [u8] {
@@ -147,22 +167,28 @@ impl Deref for FrameBuffer<'_> {
147167
}
148168
}
149169

150-
impl From<Vec<u8>> for FrameBuffer<'_> {
151-
fn from(value: Vec<u8>) -> Self {
152-
let buffer = Cow::Owned(value);
170+
impl<'a> From<&'a [u8]> for FrameBuffer<'a> {
171+
fn from(value: &'a [u8]) -> Self {
172+
FrameBuffer {
173+
buffer: Cow::Borrowed(value),
174+
metadata: None,
175+
}
176+
}
177+
}
153178

179+
impl From<Vec<u8>> for FrameBuffer<'static> {
180+
fn from(value: Vec<u8>) -> Self {
154181
FrameBuffer {
155-
buffer,
182+
buffer: Cow::Owned(value),
156183
metadata: None,
157184
}
158185
}
159186
}
160187

161-
impl<'a> From<&'a [u8]> for FrameBuffer<'a> {
162-
fn from(value: &'a [u8]) -> Self {
163-
let buffer = Cow::Borrowed(value);
188+
impl<'a> From<Cow<'a, [u8]>> for FrameBuffer<'a> {
189+
fn from(value: Cow<'a, [u8]>) -> Self {
164190
FrameBuffer {
165-
buffer,
191+
buffer: value,
166192
metadata: None,
167193
}
168194
}

‎nokhwa-decoders/Cargo.toml‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
[package]
2-
name = "nokhwa-decoders"
2+
name = "nokhwa-decoders"
33
version = "0.1.0"
44
edition = "2024"
55

66
[features]
7-
ffmpeg = [ "ffmpeg-the-third" ]
8-
yuyv = [ "dcv-color-primitives", "yuv" ]
9-
mjpeg = [ "zune-jpeg", "zune-core" ]
10-
luma = [ "nokhwa-iter-extensions", "itermore" ]
11-
# static = ["ffmpeg-the-third/static"]
7+
ffmpeg = ["ffmpeg-the-third"]
8+
yuyv = ["dcv-color-primitives", "yuv"]
9+
mjpeg = ["zune-jpeg", "zune-core"]
10+
luma = ["nokhwa-iter-extensions", "itermore"]
11+
static = ["ffmpeg-the-third/static"]
1212
#async = []
1313

1414
[dependencies]
1515
bytemuck = "1.23"
1616

1717
[dependencies.nokhwa-core]
1818
version = "0.2"
19-
path = "../nokhwa-core"
19+
path = "../nokhwa-core"
2020

2121
[dependencies.ffmpeg-the-third]
22-
version = "4.0.0"
22+
version = "4.0.0"
2323
optional = true
2424

2525
[dependencies.yuv]
26-
version = "0.8"
26+
version = "0.8"
2727
optional = true
2828

2929
[dependencies.dcv-color-primitives]
30-
version = "0.7"
30+
version = "0.7"
3131
optional = true
3232

3333
[dependencies.zune-jpeg]
34-
version = "0.5.0-rc9"
34+
version = "0.5.0-rc9"
3535
optional = true
3636

3737
[dependencies.zune-core]
38-
version = "0.5.0-rc2"
38+
version = "0.5.0-rc2"
3939
optional = true
4040

4141
[dependencies.itermore]
42-
version = "0.8"
43-
features = [ "array_chunks" ]
42+
version = "0.8"
43+
features = ["array_chunks"]
4444
optional = true
4545

4646
[dependencies.nokhwa-iter-extensions]
47-
version = "0.1"
48-
path = "../nokhwa-iter-extensions"
47+
version = "0.1"
48+
path = "../nokhwa-iter-extensions"
4949
optional = true
5050

5151
[dev-dependencies.image]
5252
workspace = true
53-
features = [ "png", "jpeg", "avif" ]
53+
features = ["png", "jpeg", "avif"]

0 commit comments

Comments
 (0)