From 666f44ca2d21b00055b5452bf362c940ba7dd57b Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 17 Oct 2022 14:20:58 -0400 Subject: [PATCH] fix for macos usize / u64 type mismatches (#140) * fix for macos pixelbuffer dimension types * size_t_is_usize * update core-media * lint fix * simplification --- macos/core-media/build.rs | 2 ++ macos/core-media/src/format_description.rs | 2 +- macos/core-media/src/sample_buffer.rs | 1 - macos/core-video/build.rs | 2 ++ macos/core-video/src/pixel_buffer.rs | 10 +++++----- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/macos/core-media/build.rs b/macos/core-media/build.rs index af7c851c..48d9971b 100644 --- a/macos/core-media/build.rs +++ b/macos/core-media/build.rs @@ -19,6 +19,8 @@ fn main() { .whitelist_function("CMSampleBuffer.+") .whitelist_var("kCFAllocator.+") .whitelist_var("kCMVideoCodecType_.+") + // See: https://github.com/rust-lang/rust-bindgen/issues/1671 + .size_t_is_usize(true) .generate() .expect("unable to generate bindings"); diff --git a/macos/core-media/src/format_description.rs b/macos/core-media/src/format_description.rs index e1f8aea8..904a97a2 100644 --- a/macos/core-media/src/format_description.rs +++ b/macos/core-media/src/format_description.rs @@ -74,7 +74,7 @@ impl VideoFormatDescription { unsafe { let mut ret = std::ptr::null(); let pointers: Vec<_> = parameter_sets.iter().map(|&ps| ps.as_ptr()).collect(); - let sizes: Vec<_> = parameter_sets.iter().map(|ps| ps.len() as u64).collect(); + let sizes: Vec<_> = parameter_sets.iter().map(|ps| ps.len()).collect(); result( sys::CMVideoFormatDescriptionCreateFromH264ParameterSets( std::ptr::null_mut(), diff --git a/macos/core-media/src/sample_buffer.rs b/macos/core-media/src/sample_buffer.rs index 0176455f..b90d55a5 100644 --- a/macos/core-media/src/sample_buffer.rs +++ b/macos/core-media/src/sample_buffer.rs @@ -12,7 +12,6 @@ impl SampleBuffer { sample_sizes: Option<&[usize]>, ) -> Result { let mut ret = std::ptr::null_mut(); - let sample_sizes = sample_sizes.map(|v| v.iter().map(|&ss| ss as u64).collect::>()); result( unsafe { sys::CMSampleBufferCreate( diff --git a/macos/core-video/build.rs b/macos/core-video/build.rs index d4a87614..3c96c762 100644 --- a/macos/core-video/build.rs +++ b/macos/core-video/build.rs @@ -17,6 +17,8 @@ fn main() { .whitelist_function("CVImageBuffer.+") .whitelist_function("CVPixelBuffer.+") .whitelist_var("kCVPixelBufferLock_ReadOnly") + // See: https://github.com/rust-lang/rust-bindgen/issues/1671 + .size_t_is_usize(true) .generate() .expect("unable to generate bindings"); diff --git a/macos/core-video/src/pixel_buffer.rs b/macos/core-video/src/pixel_buffer.rs index a997aa73..f54bed1e 100644 --- a/macos/core-video/src/pixel_buffer.rs +++ b/macos/core-video/src/pixel_buffer.rs @@ -27,9 +27,9 @@ impl PixelBuffer { let mut plane_bytes_per_row = vec![]; for p in planes.into_iter() { plane_ptrs.push(p.data as *mut c_void); - plane_widths.push(p.width as u64); - plane_heights.push(p.height as u64); - plane_bytes_per_row.push(p.bytes_per_row as u64); + plane_widths.push(p.width as usize); + plane_heights.push(p.height as usize); + plane_bytes_per_row.push(p.bytes_per_row as usize); } let mut ret = std::ptr::null_mut(); @@ -60,11 +60,11 @@ impl PixelBuffer { unsafe { sys::CVPixelBufferGetPixelFormatType(self.0) } } - pub fn width(&self) -> u64 { + pub fn width(&self) -> usize { unsafe { sys::CVPixelBufferGetWidth(self.0) } } - pub fn height(&self) -> u64 { + pub fn height(&self) -> usize { unsafe { sys::CVPixelBufferGetHeight(self.0) } }