Skip to content

Commit

Permalink
MSYS2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHayton committed Jul 30, 2024
1 parent 8a782fe commit 5838bb3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ jobs:
- name: Install alsa-tools (ubuntu only)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install alsa-tools
- name: Set MSVC target (windows only)
- name: "Activate MSYS2 on Windows"
if: matrix.os == 'windows-latest'
run: bash ./scripts/set-windows-msvc.sh
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: true
install: >-
clang
- name: Build example
working-directory: examples/${{ matrix.example }}
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ jobs:
- name: Install alsa-tools (ubuntu only)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y alsa-tools libasound2-dev libudev-dev
- name: Set MSVC target (windows only)
- name: "Activate MSYS2 on Windows"
if: matrix.os == 'windows-latest'
run: bash ./scripts/set-windows-msvc.sh
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: true
install: >-
clang
- name: Cargo build main project (Default features)
run: cargo build
Expand Down
40 changes: 26 additions & 14 deletions jaenokhwa-bindings-windows/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,18 @@ pub mod wmf {

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

for (activate_ptr) in query_activate_pointers().iter() {
device_list.push(activate_to_descriptors(&activate_ptr)?);
match query_activate_pointers() {
Ok(activate_list) => {
for activate_ptr in activate_list {
match activate_to_descriptors(&activate_ptr) {
Ok(descriptor) => device_list.push(descriptor),
Err(why) => return Err(why),
}
}
}
Err(why) => return Err(why),
}

Ok(device_list)
}

Expand Down Expand Up @@ -443,6 +451,7 @@ pub mod wmf {
};

let source_reader_attr = {
#[allow(clippy::manual_let_else)]
let attr = match {
let mut attr: Option<IMFAttributes> = None;

Expand Down Expand Up @@ -680,13 +689,13 @@ pub mod wmf {
&mut flag,
) {
return Err(NokhwaError::GetPropertyError {
property: format!("{:?}: {} - Range", control_id, control),
property: format!("{control_id:?}: {control} - Range"),
error: why.to_string(),
});
}
if let Err(why) = video_proc_amp.Get(id, &mut value, &mut flag) {
return Err(NokhwaError::GetPropertyError {
property: format!("{:?}: {} - Value", control_id, control),
property: format!("{control_id:?}: {control} - Value"),
error: why.to_string(),
});
}
Expand All @@ -708,13 +717,13 @@ pub mod wmf {
&mut flag,
) {
return Err(NokhwaError::GetPropertyError {
property: format!("{:?}: {} - Range", control_id, control),
property: format!("{control_id:?}: {control} - Range"),
error: why.to_string(),
});
}
if let Err(why) = video_proc_amp.Get(id, &mut value, &mut flag) {
return Err(NokhwaError::GetPropertyError {
property: format!("{:?}: {} - Value", control_id, control),
property: format!("{control_id:?}: {control} - Value"),
error: why.to_string(),
});
}
Expand All @@ -736,13 +745,13 @@ pub mod wmf {
&mut flag,
) {
return Err(NokhwaError::GetPropertyError {
property: format!("{:?}: {} - Range", control_id, control),
property: format!("{control_id:?}: {control} - Range"),
error: why.to_string(),
});
}
if let Err(why) = camera_control.Get(id, &mut value, &mut flag) {
return Err(NokhwaError::GetPropertyError {
property: format!("{:?}: {} - Value", control_id, control),
property: format!("{control_id:?}: {control} - Value"),
error: why.to_string(),
});
}
Expand All @@ -763,13 +772,13 @@ pub mod wmf {
&mut flag,
) {
return Err(NokhwaError::GetPropertyError {
property: format!("{:?}: {} - Range", control_id, control),
property: format!("{control_id:?}: {control} - Range"),
error: why.to_string(),
});
}
if let Err(why) = camera_control.Get(id, &mut value, &mut flag) {
return Err(NokhwaError::GetPropertyError {
property: format!("{:?}: {} - Value", control_id, control),
property: format!("{control_id:?}: {control} - Value"),
error: why.to_string(),
});
}
Expand Down Expand Up @@ -853,7 +862,7 @@ pub mod wmf {
ControlValueSetter::Boolean(b) => i32::from(b),
v => {
return Err(NokhwaError::StructureError {
structure: format!("ControlValueSetter {}", v),
structure: format!("ControlValueSetter {v}"),
error: "invalid value type".to_string(),
})
}
Expand Down Expand Up @@ -959,6 +968,9 @@ pub mod wmf {
self.device_format
}

// Set the format of the camera
// # Panics
// If the format is not supported by the camera
pub fn set_format(&mut self, format: CameraFormat) -> Result<(), NokhwaError> {
// convert to media_type
let media_type: IMFMediaType = match unsafe { MFCreateMediaType() } {
Expand Down Expand Up @@ -1001,7 +1013,7 @@ pub mod wmf {
if let Err(why) = unsafe { media_type.SetGUID(&MF_MT_SUBTYPE, &guid.unwrap()) } {
return Err(NokhwaError::SetPropertyError {
property: "MF_MT_SUBTYPE".to_string(),
value: format!("{:?}", guid),
value: format!("{guid:?}"),
error: why.to_string(),
});
}
Expand Down Expand Up @@ -1162,7 +1174,7 @@ pub mod wmf {
CAMERA_REFCNT.store(CAMERA_REFCNT.load(Ordering::SeqCst) - 1, Ordering::SeqCst);
}
if CAMERA_REFCNT.load(Ordering::SeqCst) == 0 {
#[allow(clippy::let_underscore_drop)]
#[allow(let_underscore_drop)]
let _ = de_initialize_mf();
}
}
Expand Down
11 changes: 0 additions & 11 deletions scripts/set-windows-msvc.sh

This file was deleted.

0 comments on commit 5838bb3

Please sign in to comment.