Skip to content

Commit

Permalink
Windows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHayton committed Jul 30, 2024
1 parent ca8dcfa commit f43b802
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 48 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ ffmpeg-sys-next = { git = "https://github.com/AlexHayton/rust-ffmpeg-sys.git" }
four-cc = { git = "https://github.com/AlexHayton/four-cc.git" }
core-video = { git = "https://github.com/AlexHayton/core-video-rs.git" }
av-foundation = { git = "https://github.com/AlexHayton/av-foundation-rs.git" }
rust-ffmpeg-sys = { git = "https://github.com/WilliamVenner/rust-ffmpeg-sys.git", branch = "mingw-build-ffmpeg" }

[dependencies.jaenokhwa-core]
version = "0.1.0"
Expand Down
60 changes: 13 additions & 47 deletions jaenokhwa-bindings-windows/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,7 @@ pub mod wmf {
Ok(device_list)
}

fn activate_to_descriptors(
index: CameraIndex,
imf_activate: &IMFActivate,
) -> Result<CameraInfo, NokhwaError> {
fn activate_to_descriptors(imf_activate: &IMFActivate) -> Result<CameraInfo, NokhwaError> {
let mut pwstr_name = PWSTR(&mut 0_u16);
let mut len_pwstrname = 0;
let mut pwstr_symlink = PWSTR(&mut 0_u16);
Expand Down Expand Up @@ -350,21 +347,20 @@ pub mod wmf {
};

Ok(CameraInfo::new(
&symlink,
&name,
"",
"",
"MediaFoundation Camera",
&symlink,
index,
"",
))
}

pub fn query_media_foundation_descriptors() -> Result<Vec<CameraInfo>, NokhwaError> {
let mut device_list = vec![];

for (index, activate_ptr) in query_activate_pointers()?.into_iter().enumerate() {
device_list.push(activate_to_descriptors(
CameraIndex::Index(index as u32),
&activate_ptr,
)?);
for (activate_ptr) in query_activate_pointers().iter() {

Check failure on line 362 in jaenokhwa-bindings-windows/src/lib.rs

View workflow job for this annotation

GitHub Actions / compile_and_check (windows-latest)

unnecessary parentheses around pattern

Check failure on line 362 in jaenokhwa-bindings-windows/src/lib.rs

View workflow job for this annotation

GitHub Actions / compile_examples (capture, windows-latest)

unnecessary parentheses around pattern

Check failure on line 362 in jaenokhwa-bindings-windows/src/lib.rs

View workflow job for this annotation

GitHub Actions / compile_examples (convert-to-rgb, windows-latest)

unnecessary parentheses around pattern

Check failure on line 362 in jaenokhwa-bindings-windows/src/lib.rs

View workflow job for this annotation

GitHub Actions / compile_examples (threaded-capture, windows-latest)

unnecessary parentheses around pattern
device_list.push(activate_to_descriptors(&activate_ptr)?);

Check failure on line 363 in jaenokhwa-bindings-windows/src/lib.rs

View workflow job for this annotation

GitHub Actions / compile_and_check (windows-latest)

mismatched types

Check failure on line 363 in jaenokhwa-bindings-windows/src/lib.rs

View workflow job for this annotation

GitHub Actions / compile_examples (capture, windows-latest)

mismatched types

Check failure on line 363 in jaenokhwa-bindings-windows/src/lib.rs

View workflow job for this annotation

GitHub Actions / compile_examples (convert-to-rgb, windows-latest)

mismatched types

Check failure on line 363 in jaenokhwa-bindings-windows/src/lib.rs

View workflow job for this annotation

GitHub Actions / compile_examples (threaded-capture, windows-latest)

mismatched types
}
Ok(device_list)
}
Expand Down Expand Up @@ -428,7 +424,7 @@ pub mod wmf {
Some(activate) => {
match unsafe { activate.ActivateObject::<IMFMediaSource>() } {
Ok(media_source) => {
(media_source, activate_to_descriptors(index, &activate)?)
(media_source, activate_to_descriptors(&activate)?)
}
Err(why) => {
return Err(NokhwaError::OpenDeviceError(
Expand Down Expand Up @@ -506,57 +502,27 @@ pub mod wmf {
let devicelist = query_media_foundation_descriptors()?;
let mut id_eq = None;

for mfdev in devicelist {
if mfdev.misc() == s {
id_eq = Some(mfdev.index().as_index()?);
for (position, mfdevice) in devicelist.iter().enumerate() {
if mfdevice.unique_id() == s {
id_eq = Some(CameraIndex::Index(position as u32));
break;
}
}

match id_eq {
Some(index) => Self::new(CameraIndex::Index(index)),
Some(index) => Self::new(index),
None => Err(NokhwaError::OpenDeviceError(s, "Not Found".to_string())),
}
}
}
}
//
// pub fn with_string(unique_id: &[u16]) -> Result<Self, NokhwaError> {
// let devicelist = query_media_foundation_descriptors()?;
// let mut id_eq = None;
//
// for mfdev in devicelist {
// if (mfdev.symlink() as &[u16]) == unique_id {
// id_eq = Some(mfdev.index().as_index()?);
// break;
// }
// }
//
// match id_eq {
// Some(index) => Self::new(index),
// None => {
// return Err(BindingError::DeviceOpenFailError(
// std::str::from_utf8(
// &unique_id.iter().map(|x| *x as u8).collect::<Vec<u8>>(),
// )
// .unwrap_or("")
// .to_string(),
// "Not Found".to_string(),
// ))
// }
// }
// }

pub fn index(&self) -> &CameraIndex {
self.device_specifier.index()
}

pub fn name(&self) -> String {
self.device_specifier.name()
}

pub fn symlink(&self) -> String {
self.device_specifier.misc()
self.device_specifier.unique_id()
}

pub fn compatible_format_list(&mut self) -> Result<Vec<CameraFormat>, NokhwaError> {
Expand Down

0 comments on commit f43b802

Please sign in to comment.