commit 4f96e54e31562d9b5fa8b354ea2760b6ceebf71d Author: Pierre Krieger Date: Thu Dec 11 14:22:55 2014 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..21db315 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +/Cargo.lock +.cargo/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..22761ba --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +language: rust diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..dcecce0 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] + +name = "cpal" +version = "0.0.1" +authors = ["Pierre Krieger "] +description = "Cross-platform audio playing library in pure Rust." + +[dependencies.winapi] +git = "https://github.com/tomaka/winapi-rs" +branch = "mmdeviceapi" +features = ["ole32"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..7930d5d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# CPAL - Cross-platform audio library + +Audio player in pure Rust. diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..e376725 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,7 @@ + +#[cfg(all(not(windows)))] +use this_platform_is_not_supported; + +#[cfg(windows)] +#[path="wasapi/mod.rs"] +mod cpal_impl; diff --git a/src/wasapi/mod.rs b/src/wasapi/mod.rs new file mode 100644 index 0000000..3a85cf3 --- /dev/null +++ b/src/wasapi/mod.rs @@ -0,0 +1,53 @@ +extern crate libc; +extern crate winapi; + +#[link(name = "uuid")] +extern "C" { + static CLSID_MMDeviceEnumerator: winapi::CLSID; + static IID_IMMDeviceEnumerator: winapi::IID; +} + +fn create() -> Result<(), String> { + unsafe { + + try!(check_result(winapi::CoInitializeEx(::std::ptr::null_mut(), 0))); + + let enumerator = { + let mut enumerator: *mut winapi::IMMDeviceEnumerator = ::std::mem::uninitialized(); + + let hresult = winapi::CoCreateInstance(&CLSID_MMDeviceEnumerator, + ::std::ptr::null_mut(), winapi::CLSCTX_ALL, + &IID_IMMDeviceEnumerator, + ::std::mem::transmute(&mut enumerator)); + + try!(check_result(hresult)); + enumerator.as_mut().unwrap() + }; + + // getting the default end-point + let device = { + let mut device: *mut winapi::IMMDevice = ::std::mem::uninitialized(); + let f = enumerator.lpVtbl.as_ref().unwrap().GetDefaultAudioEndpoint; + let hresult = f(enumerator, winapi::EDataFlow::eRender, winapi::ERole::eConsole, + ::std::mem::transmute(&mut device)); + try!(check_result(hresult)); + device.as_mut().unwrap() + }; + + // activating + let audio_client = { + //let mut audio_client: *mut winapi::IAudioClient = ::std::mem::uninitialized(); + let f = device.lpVtbl.as_ref().unwrap().Activate; + //let hresult = f(IID_IAudioClient, winapi::CLSCTX_ALL, ::std::ptr::null_mut(), + // ::std::mem::transmute(&mut audio_client)); + //try!(check_result(hresult)); + }; + }; + + Ok(()) +} + +fn check_result(result: winapi::HRESULT) -> Result<(), String> { + // TODO: + Ok(()) +}