1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use windows::Win32::{System::Com::{CoInitializeEx, CoUninitialize, COINIT}, Foundation::{CloseHandle, HANDLE}};

pub(crate) mod capture_stream;
mod capturable_content;
mod audio_capture_stream;
pub(crate) mod frame;

pub(crate) struct AutoHandle(pub HANDLE);
impl Drop for AutoHandle {
    fn drop(&mut self) {
        unsafe { let _ = CloseHandle(self.0); }
    }
}

pub(crate) struct AutoCom(Option<COINIT>);

impl AutoCom {
    fn new(coinit: COINIT) -> Self {
        let inner = unsafe {
            if CoInitializeEx(None, coinit).is_ok() {
                Some(coinit)
            } else {
                None
            }
        };
        Self(inner)
    }

    fn no_init() -> Self {
        Self(None)
    }
}

impl Drop for AutoCom {
    fn drop(&mut self) {
        if let Some(_coinit) = self.0.take() {
            unsafe { CoUninitialize() };
        }
    }
}


pub(crate) use capturable_content::WindowsCapturableApplication as ImplCapturableApplication;
pub(crate) use capturable_content::WindowsCapturableDisplay as ImplCapturableDisplay;
pub(crate) use capturable_content::WindowsCapturableWindow as ImplCapturableWindow;
pub(crate) use capturable_content::WindowsCapturableContent as ImplCapturableContent;
pub(crate) use capturable_content::WindowsCapturableContentFilter as ImplCapturableContentFilter;

pub(crate) use capture_stream::WindowsCaptureStream as ImplCaptureStream;
pub(crate) use capture_stream::WindowsCaptureConfig as ImplCaptureConfig;
pub(crate) use capture_stream::WindowsAudioCaptureConfig as ImplAudioCaptureConfig;
pub(crate) use capture_stream::WindowsCaptureAccessToken as ImplCaptureAccessToken;

pub(crate) use frame::WindowsVideoFrame as ImplVideoFrame;
pub(crate) use frame::WindowsAudioFrame as ImplAudioFrame;

pub use capture_stream::WindowsCaptureConfigExt;

/// Windows-specific extensions to capturable windows
pub use capturable_content::WindowsCapturableWindowExt;
/// Windows-specific extensions to capturable content filters
pub use capturable_content::WindowsCapturableContentFilterExt;
/// Re-exported from the `windows` crate
pub use capturable_content::HWND;