Skip to content

Commit 3bf6b29

Browse files
committed
Fix clippy and fmt.
1 parent 599f316 commit 3bf6b29

19 files changed

Lines changed: 139 additions & 128 deletions

File tree

openh264-sys2/src/lib.rs

Lines changed: 71 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
//! [docs.rs]: https://docs.rs/openh264-sys2/
2121
2222
#![allow(non_snake_case)]
23+
#![allow(unpredictable_function_pointer_comparisons)]
2324
#![allow(non_camel_case_types)]
2425
#![allow(non_upper_case_globals)]
2526
#![allow(clippy::missing_safety_doc)]
@@ -102,25 +103,25 @@ pub mod source {
102103
#[allow(clippy::missing_safety_doc)]
103104
impl APILoader {
104105
pub const fn new() -> Self { Self }
105-
pub unsafe fn WelsCreateSVCEncoder(ppEncoder: *mut *mut ISVCEncoder) -> ::std::os::raw::c_int { crate::generated::fns_source::WelsCreateSVCEncoder(ppEncoder) }
106-
pub unsafe fn WelsDestroySVCEncoder(pEncoder: *mut ISVCEncoder) { crate::generated::fns_source::WelsDestroySVCEncoder(pEncoder) }
107-
pub unsafe fn WelsGetDecoderCapability(pDecCapability: *mut SDecoderCapability) -> ::std::os::raw::c_int { crate::generated::fns_source::WelsGetDecoderCapability(pDecCapability) }
108-
pub unsafe fn WelsCreateDecoder(ppDecoder: *mut *mut ISVCDecoder) -> ::std::os::raw::c_long { crate::generated::fns_source::WelsCreateDecoder(ppDecoder) }
109-
pub unsafe fn WelsDestroyDecoder(pDecoder: *mut ISVCDecoder) { crate::generated::fns_source::WelsDestroyDecoder(pDecoder) }
110-
pub unsafe fn WelsGetCodecVersion() -> OpenH264Version { crate::generated::fns_source::WelsGetCodecVersion() }
111-
pub unsafe fn WelsGetCodecVersionEx(pVersion: *mut OpenH264Version) { crate::generated::fns_source::WelsGetCodecVersionEx(pVersion) }
106+
pub unsafe fn WelsCreateSVCEncoder(ppEncoder: *mut *mut ISVCEncoder) -> ::std::os::raw::c_int { unsafe { crate::generated::fns_source::WelsCreateSVCEncoder(ppEncoder) }}
107+
pub unsafe fn WelsDestroySVCEncoder(pEncoder: *mut ISVCEncoder) { unsafe { crate::generated::fns_source::WelsDestroySVCEncoder(pEncoder) }}
108+
pub unsafe fn WelsGetDecoderCapability(pDecCapability: *mut SDecoderCapability) -> ::std::os::raw::c_int { unsafe { crate::generated::fns_source::WelsGetDecoderCapability(pDecCapability) }}
109+
pub unsafe fn WelsCreateDecoder(ppDecoder: *mut *mut ISVCDecoder) -> ::std::os::raw::c_long { unsafe { crate::generated::fns_source::WelsCreateDecoder(ppDecoder) }}
110+
pub unsafe fn WelsDestroyDecoder(pDecoder: *mut ISVCDecoder) { unsafe { crate::generated::fns_source::WelsDestroyDecoder(pDecoder) }}
111+
pub unsafe fn WelsGetCodecVersion() -> OpenH264Version { unsafe { crate::generated::fns_source::WelsGetCodecVersion() }}
112+
pub unsafe fn WelsGetCodecVersionEx(pVersion: *mut OpenH264Version) { unsafe { crate::generated::fns_source::WelsGetCodecVersionEx(pVersion) }}
112113
}
113114

114115
#[rustfmt::skip]
115116
#[allow(clippy::missing_safety_doc)]
116117
impl super::API for APILoader {
117-
unsafe fn WelsCreateSVCEncoder(&self, ppEncoder: *mut *mut ISVCEncoder) -> c_int { APILoader::WelsCreateSVCEncoder(ppEncoder) }
118-
unsafe fn WelsDestroySVCEncoder(&self, pEncoder: *mut ISVCEncoder) { APILoader::WelsDestroySVCEncoder(pEncoder) }
119-
unsafe fn WelsGetDecoderCapability(&self, pDecCapability: *mut SDecoderCapability) -> c_int { APILoader::WelsGetDecoderCapability(pDecCapability) }
120-
unsafe fn WelsCreateDecoder(&self, ppDecoder: *mut *mut ISVCDecoder) -> c_long { APILoader::WelsCreateDecoder(ppDecoder) }
121-
unsafe fn WelsDestroyDecoder(&self, pDecoder: *mut ISVCDecoder) { APILoader::WelsDestroyDecoder(pDecoder) }
122-
unsafe fn WelsGetCodecVersion(&self) -> OpenH264Version { APILoader::WelsGetCodecVersion() }
123-
unsafe fn WelsGetCodecVersionEx(&self, pVersion: *mut OpenH264Version) { APILoader::WelsGetCodecVersionEx(pVersion) }
118+
unsafe fn WelsCreateSVCEncoder(&self, ppEncoder: *mut *mut ISVCEncoder) -> c_int { unsafe { APILoader::WelsCreateSVCEncoder(ppEncoder) }}
119+
unsafe fn WelsDestroySVCEncoder(&self, pEncoder: *mut ISVCEncoder) { unsafe { APILoader::WelsDestroySVCEncoder(pEncoder) }}
120+
unsafe fn WelsGetDecoderCapability(&self, pDecCapability: *mut SDecoderCapability) -> c_int { unsafe { APILoader::WelsGetDecoderCapability(pDecCapability) }}
121+
unsafe fn WelsCreateDecoder(&self, ppDecoder: *mut *mut ISVCDecoder) -> c_long { unsafe { APILoader::WelsCreateDecoder(ppDecoder) }}
122+
unsafe fn WelsDestroyDecoder(&self, pDecoder: *mut ISVCDecoder) { unsafe { APILoader::WelsDestroyDecoder(pDecoder) }}
123+
unsafe fn WelsGetCodecVersion(&self) -> OpenH264Version { unsafe { APILoader::WelsGetCodecVersion() }}
124+
unsafe fn WelsGetCodecVersionEx(&self, pVersion: *mut OpenH264Version) { unsafe { APILoader::WelsGetCodecVersionEx(pVersion) }}
124125
}
125126
}
126127

@@ -207,72 +208,86 @@ impl DynamicAPI {
207208
#[allow(unused)]
208209
impl API for DynamicAPI {
209210
unsafe fn WelsCreateSVCEncoder(&self, ppEncoder: *mut *mut ISVCEncoder) -> c_int {
210-
match self {
211-
#[cfg(feature = "source")]
212-
DynamicAPI::Source(api) => api.WelsCreateSVCEncoder(ppEncoder),
213-
#[cfg(feature = "libloading")]
214-
DynamicAPI::Libloading(api) => api.WelsCreateSVCEncoder(ppEncoder),
215-
_ => panic!("No API enabled"),
211+
unsafe {
212+
match self {
213+
#[cfg(feature = "source")]
214+
DynamicAPI::Source(api) => api.WelsCreateSVCEncoder(ppEncoder),
215+
#[cfg(feature = "libloading")]
216+
DynamicAPI::Libloading(api) => api.WelsCreateSVCEncoder(ppEncoder),
217+
_ => panic!("No API enabled"),
218+
}
216219
}
217220
}
218221

219222
unsafe fn WelsDestroySVCEncoder(&self, pEncoder: *mut ISVCEncoder) {
220-
match self {
221-
#[cfg(feature = "source")]
222-
DynamicAPI::Source(api) => api.WelsDestroySVCEncoder(pEncoder),
223-
#[cfg(feature = "libloading")]
224-
DynamicAPI::Libloading(api) => api.WelsDestroySVCEncoder(pEncoder),
225-
_ => panic!("No API enabled"),
223+
unsafe {
224+
match self {
225+
#[cfg(feature = "source")]
226+
DynamicAPI::Source(api) => api.WelsDestroySVCEncoder(pEncoder),
227+
#[cfg(feature = "libloading")]
228+
DynamicAPI::Libloading(api) => api.WelsDestroySVCEncoder(pEncoder),
229+
_ => panic!("No API enabled"),
230+
}
226231
}
227232
}
228233

229234
unsafe fn WelsGetDecoderCapability(&self, pDecCapability: *mut SDecoderCapability) -> c_int {
230-
match self {
231-
#[cfg(feature = "source")]
232-
DynamicAPI::Source(api) => api.WelsGetDecoderCapability(pDecCapability),
233-
#[cfg(feature = "libloading")]
234-
DynamicAPI::Libloading(api) => api.WelsGetDecoderCapability(pDecCapability),
235-
_ => panic!("No API enabled"),
235+
unsafe {
236+
match self {
237+
#[cfg(feature = "source")]
238+
DynamicAPI::Source(api) => api.WelsGetDecoderCapability(pDecCapability),
239+
#[cfg(feature = "libloading")]
240+
DynamicAPI::Libloading(api) => api.WelsGetDecoderCapability(pDecCapability),
241+
_ => panic!("No API enabled"),
242+
}
236243
}
237244
}
238245

239246
unsafe fn WelsCreateDecoder(&self, ppDecoder: *mut *mut ISVCDecoder) -> c_long {
240-
match self {
241-
#[cfg(feature = "source")]
242-
DynamicAPI::Source(api) => api.WelsCreateDecoder(ppDecoder),
243-
#[cfg(feature = "libloading")]
244-
DynamicAPI::Libloading(api) => api.WelsCreateDecoder(ppDecoder),
245-
_ => panic!("No API enabled"),
247+
unsafe {
248+
match self {
249+
#[cfg(feature = "source")]
250+
DynamicAPI::Source(api) => api.WelsCreateDecoder(ppDecoder),
251+
#[cfg(feature = "libloading")]
252+
DynamicAPI::Libloading(api) => api.WelsCreateDecoder(ppDecoder),
253+
_ => panic!("No API enabled"),
254+
}
246255
}
247256
}
248257

249258
unsafe fn WelsDestroyDecoder(&self, pDecoder: *mut ISVCDecoder) {
250-
match self {
251-
#[cfg(feature = "source")]
252-
DynamicAPI::Source(api) => api.WelsDestroyDecoder(pDecoder),
253-
#[cfg(feature = "libloading")]
254-
DynamicAPI::Libloading(api) => api.WelsDestroyDecoder(pDecoder),
255-
_ => panic!("No API enabled"),
259+
unsafe {
260+
match self {
261+
#[cfg(feature = "source")]
262+
DynamicAPI::Source(api) => api.WelsDestroyDecoder(pDecoder),
263+
#[cfg(feature = "libloading")]
264+
DynamicAPI::Libloading(api) => api.WelsDestroyDecoder(pDecoder),
265+
_ => panic!("No API enabled"),
266+
}
256267
}
257268
}
258269

259270
unsafe fn WelsGetCodecVersion(&self) -> OpenH264Version {
260-
match self {
261-
#[cfg(feature = "source")]
262-
DynamicAPI::Source(api) => api.WelsGetCodecVersion(),
263-
#[cfg(feature = "libloading")]
264-
DynamicAPI::Libloading(api) => api.WelsGetCodecVersion(),
265-
_ => panic!("No API enabled"),
271+
unsafe {
272+
match self {
273+
#[cfg(feature = "source")]
274+
DynamicAPI::Source(api) => api.WelsGetCodecVersion(),
275+
#[cfg(feature = "libloading")]
276+
DynamicAPI::Libloading(api) => api.WelsGetCodecVersion(),
277+
_ => panic!("No API enabled"),
278+
}
266279
}
267280
}
268281

269282
unsafe fn WelsGetCodecVersionEx(&self, pVersion: *mut OpenH264Version) {
270-
match self {
271-
#[cfg(feature = "source")]
272-
DynamicAPI::Source(api) => api.WelsGetCodecVersionEx(pVersion),
273-
#[cfg(feature = "libloading")]
274-
DynamicAPI::Libloading(api) => api.WelsGetCodecVersionEx(pVersion),
275-
_ => panic!("No API enabled"),
283+
unsafe {
284+
match self {
285+
#[cfg(feature = "source")]
286+
DynamicAPI::Source(api) => api.WelsGetCodecVersionEx(pVersion),
287+
#[cfg(feature = "libloading")]
288+
DynamicAPI::Libloading(api) => api.WelsGetCodecVersionEx(pVersion),
289+
_ => panic!("No API enabled"),
290+
}
276291
}
277292
}
278293
}

openh264/benches/decode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extern crate test;
44

55
use openh264::decoder::Decoder;
66
use openh264::formats::YUVSource;
7-
use test::{black_box, Bencher};
7+
use test::{Bencher, black_box};
88

99
#[bench]
1010
#[cfg(feature = "source")]

openh264/benches/encode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extern crate test;
44

55
use openh264::decoder::Decoder;
66
use openh264::encoder::Encoder;
7-
use test::{black_box, Bencher};
7+
use test::{Bencher, black_box};
88

99
#[bench]
1010
#[cfg(feature = "source")]

openh264/benches/rgb2yuv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
extern crate test;
44

5+
use openh264::OpenH264API;
56
use openh264::decoder::{Decoder, DecoderConfig};
67
use openh264::formats::{RgbSliceU8, YUVBuffer, YUVSource};
7-
use openh264::OpenH264API;
88
use test::Bencher;
99

1010
#[bench]

openh264/benches/yuv2rgb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
extern crate test;
44

5+
use openh264::OpenH264API;
56
use openh264::decoder::{Decoder, DecoderConfig};
67
use openh264::formats::YUVSource;
7-
use openh264::OpenH264API;
88
use test::Bencher;
99

1010
#[bench]

openh264/examples/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use openh264::decoder::Decoder;
21
use openh264::Error;
2+
use openh264::decoder::Decoder;
33

44
#[cfg(feature = "source")]
55
fn main() -> Result<(), Error> {

openh264/examples/mp4/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ fn main() -> Result<(), Error> {
5353
save_file(&format!("{out}/frame-0{frame_idx:04}.ppm"), &rgb, width, height)?;
5454
frame_idx += 1;
5555
}
56-
Ok(None) => {
57-
// decoder is not ready to provide an image
58-
continue;
59-
}
56+
Ok(None) => {} // decoder is not ready to provide an image
6057
Err(err) => {
6158
println!("error frame {i}: {err}");
6259
}

openh264/src/decoder.rs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,17 @@ impl DecoderRawAPI {
113113
}
114114

115115
// Exposing these will probably do more harm than good.
116-
unsafe fn initialize(&self, pParam: *const SDecodingParam) -> c_long { (self.initialize)(self.decoder_ptr, pParam) }
117-
unsafe fn uninitialize(&self, ) -> c_long { (self.uninitialize)(self.decoder_ptr) }
118-
119-
pub unsafe fn decode_frame(&self, Src: *const c_uchar, iSrcLen: c_int, ppDst: *mut *mut c_uchar, pStride: *mut c_int, iWidth: *mut c_int, iHeight: *mut c_int) -> DECODING_STATE { (self.decode_frame)(self.decoder_ptr, Src, iSrcLen, ppDst, pStride, iWidth, iHeight) }
120-
pub unsafe fn decode_frame_no_delay(&self, pSrc: *const c_uchar, iSrcLen: c_int, ppDst: *mut *mut c_uchar, pDstInfo: *mut SBufferInfo) -> DECODING_STATE { (self.decode_frame_no_delay)(self.decoder_ptr, pSrc, iSrcLen, ppDst, pDstInfo) }
121-
pub unsafe fn decode_frame2(&self, pSrc: *const c_uchar, iSrcLen: c_int, ppDst: *mut *mut c_uchar, pDstInfo: *mut SBufferInfo) -> DECODING_STATE { (self.decode_frame2)(self.decoder_ptr, pSrc, iSrcLen, ppDst, pDstInfo) }
122-
pub unsafe fn flush_frame(&self, ppDst: *mut *mut c_uchar, pDstInfo: *mut SBufferInfo) -> DECODING_STATE { (self.flush_frame)(self.decoder_ptr, ppDst, pDstInfo) }
123-
pub unsafe fn decode_parser(&self, pSrc: *const c_uchar, iSrcLen: c_int, pDstInfo: *mut SParserBsInfo) -> DECODING_STATE { (self.decode_parser)(self.decoder_ptr, pSrc, iSrcLen, pDstInfo) }
124-
pub unsafe fn decode_frame_ex(&self, pSrc: *const c_uchar, iSrcLen: c_int, pDst: *mut c_uchar, iDstStride: c_int, iDstLen: *mut c_int, iWidth: *mut c_int, iHeight: *mut c_int, iColorFormat: *mut c_int) -> DECODING_STATE { (self.decode_frame_ex)(self.decoder_ptr, pSrc, iSrcLen, pDst, iDstStride, iDstLen, iWidth, iHeight, iColorFormat) }
125-
pub unsafe fn set_option(&self, eOptionId: DECODER_OPTION, pOption: *mut c_void) -> c_long { (self.set_option)(self.decoder_ptr, eOptionId, pOption) }
126-
pub unsafe fn get_option(&self, eOptionId: DECODER_OPTION, pOption: *mut c_void) -> c_long { (self.get_option)(self.decoder_ptr, eOptionId, pOption) }
116+
unsafe fn initialize(&self, pParam: *const SDecodingParam) -> c_long { unsafe { (self.initialize)(self.decoder_ptr, pParam) }}
117+
unsafe fn uninitialize(&self, ) -> c_long { unsafe { (self.uninitialize)(self.decoder_ptr) }}
118+
119+
pub unsafe fn decode_frame(&self, Src: *const c_uchar, iSrcLen: c_int, ppDst: *mut *mut c_uchar, pStride: *mut c_int, iWidth: *mut c_int, iHeight: *mut c_int) -> DECODING_STATE { unsafe { (self.decode_frame)(self.decoder_ptr, Src, iSrcLen, ppDst, pStride, iWidth, iHeight) }}
120+
pub unsafe fn decode_frame_no_delay(&self, pSrc: *const c_uchar, iSrcLen: c_int, ppDst: *mut *mut c_uchar, pDstInfo: *mut SBufferInfo) -> DECODING_STATE { unsafe { (self.decode_frame_no_delay)(self.decoder_ptr, pSrc, iSrcLen, ppDst, pDstInfo) }}
121+
pub unsafe fn decode_frame2(&self, pSrc: *const c_uchar, iSrcLen: c_int, ppDst: *mut *mut c_uchar, pDstInfo: *mut SBufferInfo) -> DECODING_STATE { unsafe { (self.decode_frame2)(self.decoder_ptr, pSrc, iSrcLen, ppDst, pDstInfo) }}
122+
pub unsafe fn flush_frame(&self, ppDst: *mut *mut c_uchar, pDstInfo: *mut SBufferInfo) -> DECODING_STATE { unsafe { (self.flush_frame)(self.decoder_ptr, ppDst, pDstInfo) }}
123+
pub unsafe fn decode_parser(&self, pSrc: *const c_uchar, iSrcLen: c_int, pDstInfo: *mut SParserBsInfo) -> DECODING_STATE { unsafe { (self.decode_parser)(self.decoder_ptr, pSrc, iSrcLen, pDstInfo) }}
124+
pub unsafe fn decode_frame_ex(&self, pSrc: *const c_uchar, iSrcLen: c_int, pDst: *mut c_uchar, iDstStride: c_int, iDstLen: *mut c_int, iWidth: *mut c_int, iHeight: *mut c_int, iColorFormat: *mut c_int) -> DECODING_STATE { unsafe { (self.decode_frame_ex)(self.decoder_ptr, pSrc, iSrcLen, pDst, iDstStride, iDstLen, iWidth, iHeight, iColorFormat) }}
125+
pub unsafe fn set_option(&self, eOptionId: DECODER_OPTION, pOption: *mut c_void) -> c_long { unsafe { (self.set_option)(self.decoder_ptr, eOptionId, pOption) }}
126+
pub unsafe fn get_option(&self, eOptionId: DECODER_OPTION, pOption: *mut c_void) -> c_long { unsafe { (self.get_option)(self.decoder_ptr, eOptionId, pOption) }}
127127
}
128128

129129
impl Drop for DecoderRawAPI {
@@ -379,7 +379,7 @@ impl Decoder {
379379
/// # Errors
380380
///
381381
/// The function returns an error if the bitstream was corrupted.
382-
pub fn flush_remaining(&mut self) -> Result<Vec<DecodedYUV>, Error> {
382+
pub fn flush_remaining(&'_ mut self) -> Result<Vec<DecodedYUV<'_>>, Error> {
383383
let mut frames = Vec::new();
384384

385385
for _ in 0..self.num_frames_in_buffer()? {
@@ -477,27 +477,29 @@ impl DecodedYUV<'_> {
477477
///
478478
/// This can soft-fail (return `None`) because we might still have gotten `null` pointers from
479479
/// OpenH264 despite it not having returned an error on decode.
480-
unsafe fn from_raw_open264_ptrs(dst: &[*mut u8; 3], buffer_info: &TagBufferInfo) -> Option<Self> {
481-
let info = buffer_info.UsrData.sSystemBuffer;
482-
let timestamp = Timestamp::from_millis(buffer_info.uiInBsTimeStamp); // TODO: Is this the right one?
483-
484-
// Apparently it is ok for `decode_frame_no_delay` to not return an error _and_ to return null buffers. In this case
485-
// the user should try to continue decoding.
486-
if dst[0].is_null() || dst[1].is_null() || dst[2].is_null() {
487-
None
488-
} else {
489-
// https://github.com/cisco/openh264/issues/2379
490-
let y = std::slice::from_raw_parts(dst[0], (info.iHeight * info.iStride[0]) as usize);
491-
let u = std::slice::from_raw_parts(dst[1], (info.iHeight * info.iStride[1] / 2) as usize);
492-
let v = std::slice::from_raw_parts(dst[2], (info.iHeight * info.iStride[1] / 2) as usize);
493-
494-
Some(Self {
495-
info,
496-
timestamp,
497-
y,
498-
u,
499-
v,
500-
})
480+
const unsafe fn from_raw_open264_ptrs(dst: &[*mut u8; 3], buffer_info: &TagBufferInfo) -> Option<Self> {
481+
unsafe {
482+
let info = buffer_info.UsrData.sSystemBuffer;
483+
let timestamp = Timestamp::from_millis(buffer_info.uiInBsTimeStamp); // TODO: Is this the right one?
484+
485+
// Apparently it is ok for `decode_frame_no_delay` to not return an error _and_ to return null buffers. In this case
486+
// the user should try to continue decoding.
487+
if dst[0].is_null() || dst[1].is_null() || dst[2].is_null() {
488+
None
489+
} else {
490+
// https://github.com/cisco/openh264/issues/2379
491+
let y = std::slice::from_raw_parts(dst[0], (info.iHeight * info.iStride[0]) as usize);
492+
let u = std::slice::from_raw_parts(dst[1], (info.iHeight * info.iStride[1] / 2) as usize);
493+
let v = std::slice::from_raw_parts(dst[2], (info.iHeight * info.iStride[1] / 2) as usize);
494+
495+
Some(Self {
496+
info,
497+
timestamp,
498+
y,
499+
u,
500+
v,
501+
})
502+
}
501503
}
502504
}
503505

0 commit comments

Comments
 (0)