Skip to content

Commit 63ab5b3

Browse files
committed
Merge branch 'master' into yuv2rgb_perf
2 parents f2d766a + 2204f18 commit 63ab5b3

10 files changed

Lines changed: 308 additions & 57 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.jpg filter=lfs diff=lfs merge=lfs -text
55
*.jpeg filter=lfs diff=lfs merge=lfs -text
66
*.dll filter=lfs diff=lfs merge=lfs -text
7+
*.bmp filter=lfs diff=lfs merge=lfs -text
78
*.cpp linguist-detectable=false
89
*.h linguist-detectable=false
910
*.asm linguist-detectable=false

openh264-sys2/build.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Target {
7575
"unix" => TargetFamily::Unix,
7676
"windows" => TargetFamily::Windows,
7777
"wasm" => TargetFamily::Wasm,
78-
_ => panic!("Unknown target family: {}", family),
78+
_ => panic!("Unknown target family: {family}"),
7979
};
8080
let os = match os.as_str() {
8181
"windows" => TargetOs::Windows,
@@ -87,7 +87,7 @@ impl Target {
8787
"dragonfly" => TargetOs::Dragonfly,
8888
"openbsd" => TargetOs::Openbsd,
8989
"netbsd" => TargetOs::Netbsd,
90-
_ => panic!("Unknown target os: {}", os),
90+
_ => panic!("Unknown target os: {os}"),
9191
};
9292
let arch = match arch.as_str() {
9393
"x86" => TargetArch::X86,
@@ -99,15 +99,15 @@ impl Target {
9999
"powerpc64" => TargetArch::Powerpc64,
100100
"s390x" => TargetArch::S390x,
101101
"wasm32" => TargetArch::Wasm32,
102-
_ => panic!("Unknown target arch: {}", arch),
102+
_ => panic!("Unknown target arch: {arch}"),
103103
};
104104
let env = match env.as_str() {
105105
"" => TargetEnv::NoEnv,
106106
"gnu" => TargetEnv::Gnu,
107107
"msvc" => TargetEnv::Msvc,
108108
"musl" => TargetEnv::Musl,
109109
"sgx" => TargetEnv::Sgx,
110-
_ => panic!("Unknown target env: {}", env),
110+
_ => panic!("Unknown target env: {env}"),
111111
};
112112

113113
Self { family, os, arch, env }
@@ -224,10 +224,7 @@ fn try_compile_nasm(cc_build_command: &mut Build, root: &str) {
224224
let target = Target::from_env();
225225

226226
let Some(config) = NasmConfiguration::find(target) else {
227-
println!(
228-
"No NASM configuration found for target, not using any assembly.\nTarget: {:?}",
229-
target
230-
);
227+
println!("No NASM configuration found for target, not using any assembly.\nTarget: {target:?}");
231228
return;
232229
};
233230

@@ -295,9 +292,9 @@ fn compile_and_add_openh264_static_lib(name: &str, root: &str, includes: &[&str]
295292
cc_build.include(include);
296293
}
297294

298-
cc_build.compile(format!("openh264_{}", name).as_str());
295+
cc_build.compile(format!("openh264_{name}").as_str());
299296

300-
println!("cargo:rustc-link-lib=static=openh264_{}", name);
297+
println!("cargo:rustc-link-lib=static=openh264_{name}");
301298
}
302299

303300
fn main() {

openh264-sys2/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Display for Error {
3333
#[cfg(feature = "libloading")]
3434
Error::LibLoading(x) => x.fmt(f),
3535
Error::Io(x) => x.fmt(f),
36-
Error::InvalidHash(x) => format!("Invalid hash: {}", x).fmt(f),
36+
Error::InvalidHash(x) => format!("Invalid hash: {x}").fmt(f),
3737
_ => "".fmt(f),
3838
}
3939
}

openh264/src/decoder.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
//! ```
5050
5151
use crate::error::NativeErrorExt;
52-
use crate::formats::yuv2rgb::write_rgb8_f32x8_par;
53-
// use crate::formats::yuv2rgb::{write_rgb8_f32x8, write_rgb8_f32x8_par, write_rgb8_scalar, write_rgb8_scalar_par};
52+
use crate::formats::yuv2rgb::{write_rgb8_f32x8_par, write_rgba8_f32x8, write_rgba8_scalar};
53+
// use crate::formats::yuv2rgb::{write_rgb8_f32x8, write_rgb8_f32x8_par, write_rgb8_scalar, write_rgb8_scalar, write_rgba8_f32x8, write_rgba8_scalar_par};
5454
use crate::formats::{YUVSlices, YUVSource};
5555
use crate::{Error, OpenH264API, Timestamp};
5656
use openh264_sys2::{
@@ -296,7 +296,7 @@ impl Decoder {
296296

297297
#[rustfmt::skip]
298298
unsafe {
299-
raw_api.initialize(&config.params).ok()?;
299+
raw_api.initialize(&raw const config.params).ok()?;
300300
raw_api.set_option(DECODER_OPTION_TRACE_LEVEL, addr_of_mut!(config.debug).cast()).ok()?;
301301
raw_api.set_option(DECODER_OPTION_NUM_OF_THREADS, addr_of_mut!(config.num_threads).cast()).ok()?;
302302
raw_api.set_option(DECODER_OPTION_ERROR_CON_IDC, addr_of_mut!(config.error_concealment).cast()).ok()?;
@@ -348,7 +348,7 @@ impl Decoder {
348348
packet.as_ptr(),
349349
packet.len() as i32,
350350
from_mut(&mut dst).cast(),
351-
&mut buffer_info,
351+
&raw mut buffer_info,
352352
)
353353
.ok()?;
354354
}
@@ -388,7 +388,7 @@ impl Decoder {
388388

389389
if let Some(image) = unsafe { DecodedYUV::from_raw_open264_ptrs(&dst, &buffer_info) } {
390390
frames.push(image);
391-
};
391+
}
392392
}
393393

394394
Ok(frames)
@@ -420,7 +420,7 @@ impl Decoder {
420420
/// # Ok(())
421421
/// # }
422422
/// ```
423-
pub unsafe fn raw_api(&mut self) -> &mut DecoderRawAPI {
423+
pub const unsafe fn raw_api(&mut self) -> &mut DecoderRawAPI {
424424
&mut self.raw_api
425425
}
426426

@@ -445,7 +445,9 @@ impl Decoder {
445445
let mut buffer_info = SBufferInfo::default();
446446

447447
unsafe {
448-
self.raw_api().flush_frame(from_mut(&mut dst).cast(), &mut buffer_info).ok()?;
448+
self.raw_api()
449+
.flush_frame(from_mut(&mut dst).cast(), &raw mut buffer_info)
450+
.ok()?;
449451
Ok((dst, buffer_info))
450452
}
451453
}
@@ -604,25 +606,13 @@ impl DecodedYUV<'_> {
604606
wanted,
605607
target.len()
606608
);
607-
608-
for y in 0..dim.1 {
609-
for x in 0..dim.0 {
610-
let base_tgt = (y * dim.0 + x) * 4;
611-
let base_y = y * strides.0 + x;
612-
let base_u = (y / 2 * strides.1) + (x / 2);
613-
let base_v = (y / 2 * strides.2) + (x / 2);
614-
615-
let rgb_pixel = &mut target[base_tgt..base_tgt + 4];
616-
617-
let y: f32 = self.y[base_y].into();
618-
let u: f32 = self.u[base_u].into();
619-
let v: f32 = self.v[base_v].into();
620-
621-
rgb_pixel[0] = 1.402f32.mul_add(v - 128.0, y) as u8;
622-
rgb_pixel[1] = 0.714f32.mul_add(-(v - 128.0), 0.344f32.mul_add(-(u - 128.0), y)) as u8;
623-
rgb_pixel[2] = 1.772f32.mul_add(u - 128.0, y) as u8;
624-
rgb_pixel[3] = 255;
625-
}
609+
// for f32x8 math, image needs to:
610+
// - have a width divisible by 8
611+
// - have at least two rows
612+
if dim.0 % 8 == 0 && dim.1 >= 2 {
613+
write_rgba8_f32x8(self.y, self.u, self.v, dim, strides, target);
614+
} else {
615+
write_rgba8_scalar(self.y, self.u, self.v, dim, strides, target);
626616
}
627617
}
628618
}

openh264/src/encoder.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,9 @@ impl Encoder {
696696
};
697697

698698
unsafe {
699-
self.raw_api.encode_frame(&source, &mut self.bit_stream_info).ok()?;
699+
self.raw_api
700+
.encode_frame(&raw const source, &raw mut self.bit_stream_info)
701+
.ok()?;
700702
}
701703

702704
Ok(EncodedBitStream {
@@ -721,7 +723,7 @@ impl Encoder {
721723

722724
let mut params = SEncParamExt::default();
723725

724-
unsafe { self.raw_api.get_default_params(&mut params).ok()? };
726+
unsafe { self.raw_api.get_default_params(&raw mut params).ok()? };
725727

726728
params.iPicWidth = width as c_int; // If we do .into() instead, could this fail to compile on some platforms?
727729
params.iPicHeight = height as c_int; // If we do .into() instead, could this fail to compile on some platforms?
@@ -776,7 +778,7 @@ impl Encoder {
776778
unsafe {
777779
if self.previous_dimensions.is_none() {
778780
// First time we call initialize_ext
779-
self.raw_api.initialize_ext(&params).ok()?;
781+
self.raw_api.initialize_ext(&raw const params).ok()?;
780782
self.raw_api.set_option(ENCODER_OPTION_TRACE_LEVEL, addr_of_mut!(self.config.debug).cast()).ok()?;
781783
self.raw_api.set_option(ENCODER_OPTION_DATAFORMAT, addr_of_mut!(self.config.data_format).cast()).ok()?;
782784
} else {
@@ -807,7 +809,7 @@ impl Encoder {
807809
/// # Safety
808810
///
809811
/// You must not set parameters the encoder relies on, we recommend checking the source.
810-
pub unsafe fn raw_api(&mut self) -> &mut EncoderRawAPI {
812+
pub const unsafe fn raw_api(&mut self) -> &mut EncoderRawAPI {
811813
&mut self.raw_api
812814
}
813815
}
@@ -893,7 +895,7 @@ impl<'a> EncodedBitStream<'a> {
893895
return Err(Error::msg(&format!("failed to write: {e}")));
894896
}
895897
_ => {}
896-
};
898+
}
897899
}
898900
}
899901
Ok(())

0 commit comments

Comments
 (0)