MCPcopy Create free account
hub / github.com/RustCV/RustCV / initialize_mf

Function initialize_mf

rustcv-backend-msmf/src/device.rs:48–71  ·  view source on GitHub ↗

Initializes the Media Foundation and COM subsystem This function performs one-time initialization of the Windows Media Foundation and COM runtime. It uses reference counting to ensure proper lifecycle management. Multiple calls are safe; only the first call performs actual initialization. Uses compare_exchange for efficient lock-free initialization.

()

Source from the content-addressed store, hash-verified

46///
47/// Uses compare_exchange for efficient lock-free initialization.
48pub fn initialize_mf() -> Result<()> {
49 if INITIALIZED
50 .compare_exchange(false, true, Ordering::SeqCst, Ordering::Relaxed)
51 .is_ok()
52 {
53 // We won the race to initialize
54 unsafe {
55 if let Err(e) = CoInitializeEx(None, COINIT_APARTMENTTHREADED).ok() {
56 INITIALIZED.store(false, Ordering::Release);
57 return Err(CameraError::Io(std::io::Error::other(e.to_string())));
58 }
59
60 if let Err(e) = MFStartup(MF_API_VERSION, MFSTARTUP_NOSOCKET) {
61 // Clean up COM if MF startup fails
62 CoUninitialize();
63 INITIALIZED.store(false, Ordering::Release);
64 return Err(CameraError::Io(std::io::Error::other(e.to_string())));
65 }
66 }
67 }
68 // Increment reference count (use Release for synchronization with shutdown)
69 CAMERA_REFCNT.fetch_add(1, Ordering::Release);
70 Ok(())
71}
72
73/// Shuts down the Media Foundation subsystem
74///

Callers 2

list_devicesFunction · 0.85
openFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected