From 6d92cf2dfe17bc8fbf39cf5193de341e27347b7d Mon Sep 17 00:00:00 2001 From: l1npengtul Date: Sat, 3 Sep 2022 21:47:11 +0900 Subject: [PATCH] fix windows --- nokhwa-bindings-windows/src/lib.rs | 103 ++++++++++++++--------------- nokhwa-core/src/types.rs | 6 ++ 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/nokhwa-bindings-windows/src/lib.rs b/nokhwa-bindings-windows/src/lib.rs index c87790b..b92da3e 100644 --- a/nokhwa-bindings-windows/src/lib.rs +++ b/nokhwa-bindings-windows/src/lib.rs @@ -38,29 +38,6 @@ use std::{ }; use thiserror::Error; -#[allow(clippy::module_name_repetitions)] -#[derive(Error, Debug, Clone)] -pub enum BindingError { - #[error("Failed to initialize Media Foundation: {0}")] - InitializeError(String), - #[error("Failed to de-initialize Media Foundation: {0}")] - DeInitializeError(String), - #[error("Failed to set GUID {0} to {1}: {2}")] - GUIDSetError(String, String, String), - #[error("Failed to Read GUID {0}: {1}")] - GUIDReadError(String, String), - #[error("Attribute Error: {0}")] - AttributeError(String), - #[error("Failed to enumerate: {0}")] - EnumerateError(String), - #[error("Failed to open device {0}: {1}")] - DeviceOpenFailError(String, String), - #[error("Failed to read frame: {0}")] - ReadFrameError(String), - #[error("Not Implemented!")] - NotImplementedError, -} - #[cfg(all(windows, not(feature = "docs-only")))] pub mod wmf { use nokhwa_core::error::NokhwaError; @@ -1250,37 +1227,38 @@ pub mod wmf { #[allow(clippy::missing_errors_doc)] #[allow(clippy::unused_self)] pub mod wmf { - use crate::{ - BindingError, MFCameraFormat, MFControl, MediaFoundationControls, - MediaFoundationDeviceDescriptor, + use nokhwa_core::error::NokhwaError; + use nokhwa_core::types::{ + CameraControl, CameraFormat, CameraIndex, CameraInfo, ControlValueSetter, + KnownCameraControl, }; use std::borrow::Cow; - pub fn initialize_mf() -> Result<(), BindingError> { + pub fn initialize_mf() -> Result<(), NokhwaError> { Err(BindingError::NotImplementedError) } - pub fn de_initialize_mf() -> Result<(), BindingError> { + pub fn de_initialize_mf() -> Result<(), NokhwaError> { Err(BindingError::NotImplementedError) } - pub fn query_msmf() -> Result>, BindingError> { + pub fn query_msmf() -> Result, NokhwaError> { Err(BindingError::NotImplementedError) } - struct Empty(); + struct Empty; pub struct MediaFoundationDevice<'a> { phantom: &'a Empty, } impl<'a> MediaFoundationDevice<'a> { - pub fn new(_: usize, _: MFCameraFormat) -> Result { - Ok(MediaFoundationDevice { phantom: &Empty() }) + pub fn new(_index: CameraIndex) -> Result { + Ok(MediaFoundationDevice { phantom: &Empty }) } - pub fn index(&self) -> usize { - usize::MAX + pub fn index(&self) -> &CameraIndex { + &CameraIndex::default() } pub fn name(&self) -> String { @@ -1291,44 +1269,61 @@ pub mod wmf { "".to_string() } - pub fn compatible_format_list(&mut self) -> Result, BindingError> { - Err(BindingError::NotImplementedError) + pub fn compatible_format_list(&mut self) -> Result, NokhwaError> { + Err(NokhwaError::NotImplementedError( + "Only on Windows".to_string(), + )) } - pub fn control( - &self, - _control: MediaFoundationControls, - ) -> Result { - Err(BindingError::NotImplementedError) + pub fn control(&self, _control: KnownCameraControl) -> Result { + Err(NokhwaError::NotImplementedError( + "Only on Windows".to_string(), + )) } - pub fn set_control(&mut self, _control: MFControl) -> Result<(), BindingError> { - Err(BindingError::NotImplementedError) + pub fn set_control( + &mut self, + _control: KnownCameraControl, + _value: ControlValueSetter, + ) -> Result<(), NokhwaError> { + Err(NokhwaError::NotImplementedError( + "Only on Windows".to_string(), + )) } - pub fn format(&self) -> MFCameraFormat { - MFCameraFormat::default() + pub fn format_refreshed(&mut self) -> Result { + Err(NokhwaError::NotImplementedError( + "Only on Windows".to_string(), + )) } - pub fn set_format(&mut self, _format: MFCameraFormat) -> Result<(), BindingError> { - Err(BindingError::NotImplementedError) + pub fn format(&self) -> CameraFormat { + CameraFormat::default() + } + + pub fn set_format(&mut self, _format: CameraFormat) -> Result<(), NokhwaError> { + Err(NokhwaError::NotImplementedError( + "Only on Windows".to_string(), + )) } pub fn is_stream_open(&self) -> bool { false } - pub fn start_stream(&mut self) -> Result<(), BindingError> { - Err(BindingError::NotImplementedError) + pub fn start_stream(&mut self) -> Result<(), NokhwaError> { + Err(NokhwaError::NotImplementedError( + "Only on Windows".to_string(), + )) } - pub fn raw_bytes(&mut self) -> Result, BindingError> { - Err(BindingError::NotImplementedError) + pub fn raw_bytes(&mut self) -> Result, NokhwaError> { + Err(NokhwaError::NotImplementedError( + "Only on Windows".to_string(), + )) } - pub fn stop_stream(&mut self) { - self.phantom = &Empty(); - } + pub fn stop_stream(&mut self) {} } impl<'a> Drop for MediaFoundationDevice<'a> { diff --git a/nokhwa-core/src/types.rs b/nokhwa-core/src/types.rs index f6803f4..d7c6e11 100644 --- a/nokhwa-core/src/types.rs +++ b/nokhwa-core/src/types.rs @@ -151,6 +151,12 @@ impl Display for CameraIndex { } } +impl Default for CameraIndex { + fn default() -> Self { + CameraIndex::Index(0) + } +} + impl AsRef for CameraIndex { fn as_ref(&self) -> &str { self.to_string().as_str()