Skip to content

Commit

Permalink
fix for macos usize / u64 type mismatches (#140)
Browse files Browse the repository at this point in the history
* fix for macos pixelbuffer dimension types

* size_t_is_usize

* update core-media

* lint fix

* simplification
  • Loading branch information
ccbrown authored Oct 17, 2022
1 parent 87a1158 commit 666f44c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions macos/core-media/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion macos/core-media/src/format_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 0 additions & 1 deletion macos/core-media/src/sample_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ impl SampleBuffer {
sample_sizes: Option<&[usize]>,
) -> Result<Self, OSStatus> {
let mut ret = std::ptr::null_mut();
let sample_sizes = sample_sizes.map(|v| v.iter().map(|&ss| ss as u64).collect::<Vec<_>>());
result(
unsafe {
sys::CMSampleBufferCreate(
Expand Down
2 changes: 2 additions & 0 deletions macos/core-video/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
10 changes: 5 additions & 5 deletions macos/core-video/src/pixel_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) }
}

Expand Down

0 comments on commit 666f44c

Please sign in to comment.