Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions crates/camera-directshow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
use std::{
cell::RefCell,
ffi::{OsString, c_void},
mem::ManuallyDrop,
mem::{ManuallyDrop, MaybeUninit},
ops::Deref,
os::windows::ffi::OsStringExt,
ptr::{self, null, null_mut},
time::{Duration, Instant},
};
use tracing::trace;
use tracing::{trace, warn};
use windows::{
Win32::{
Foundation::*,
Expand Down Expand Up @@ -275,7 +275,7 @@ impl IPropertyBagExt for IPropertyBag {
}

pub struct VideoInputDeviceIterator {
enum_moniker: IEnumMoniker,
enum_moniker: Option<IEnumMoniker>,
moniker: [Option<IMoniker>; 1],
}

Expand All @@ -296,7 +296,13 @@ impl VideoInputDeviceIterator {
0,
)?;

enum_moniker.expect("enum_moniker is None after create succeeded!")
if enum_moniker.is_none() {
warn!("VideoInputDeviceIterator::new produced no enum moniker");
}

// CreateClassEnumerator can return S_FALSE which is treated as success,
// so we can't assume this exists
enum_moniker
};

Ok(Self {
Expand All @@ -310,7 +316,11 @@ impl Iterator for VideoInputDeviceIterator {
type Item = VideoInputDevice;

fn next(&mut self) -> Option<Self::Item> {
while unsafe { self.enum_moniker.Next(&mut self.moniker, None) } == S_OK {
let Some(enum_moniker) = &mut self.enum_moniker else {
return None;
};

while unsafe { enum_moniker.Next(&mut self.moniker, None) } == S_OK {
if let Some(device) = self.moniker[0]
.take()
.and_then(|moniker| VideoInputDevice::new(moniker).ok())
Expand Down Expand Up @@ -528,7 +538,9 @@ impl AMMediaType {
}

pub fn into_inner(mut self) -> AM_MEDIA_TYPE {
let inner = std::mem::replace(&mut self.0, unsafe { std::mem::uninitialized() });
// SAFETY: Getting the inner value without triggering Drop
#[expect(invalid_value)]
let inner = std::mem::replace(&mut self.0, unsafe { MaybeUninit::uninit().assume_init() });
std::mem::forget(self);
inner
}
Expand Down
Loading