Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ jobs:
run: sudo apt-get install --no-install-recommends -y libasound2-dev
- name: Build
run: cargo check --verbose --all
- name: Build no-std
run: cargo check --no-default-features --verbose --all
# - name: Run tests
# run: cargo test --verbose --all
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ anyhow = "1.0"
[badges]
is-it-maintained-issue-resolution = { repository = "diwic/alsa-rs" }
is-it-maintained-open-issues = { repository = "diwic/alsa-rs" }

[features]
default = ["std"]
std = []
10 changes: 6 additions & 4 deletions src/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
use libc::{c_int, c_char};
use super::error::*;
use crate::alsa;
use std::ffi::CStr;
use core::ffi::CStr;
use ::alloc::string::String;

/// An ALSA sound card, uniquely identified by its index.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -33,12 +34,12 @@ impl Card {
acheck!(snd_card_get_index(s.as_ptr())).map(Card)
}
pub fn get_name(&self) -> Result<String> {
let mut c: *mut c_char = ::std::ptr::null_mut();
let mut c: *mut c_char = ::core::ptr::null_mut();
acheck!(snd_card_get_name(self.0, &mut c))
.and_then(|_| from_alloc("snd_card_get_name", c))
}
pub fn get_longname(&self) -> Result<String> {
let mut c: *mut c_char = ::std::ptr::null_mut();
let mut c: *mut c_char = ::core::ptr::null_mut();
acheck!(snd_card_get_longname(self.0, &mut c))
.and_then(|_| from_alloc("snd_card_get_longname", c))
}
Expand All @@ -48,7 +49,8 @@ impl Card {

#[test]
fn print_cards() {
extern crate std;
for a in Iter::new().map(|a| a.unwrap()) {
println!("Card #{}: {} ({})", a.get_index(), a.get_name().unwrap(), a.get_longname().unwrap())
std::println!("Card #{}: {} ({})", a.get_index(), a.get_name().unwrap(), a.get_longname().unwrap())
}
}
15 changes: 9 additions & 6 deletions src/chmap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::alsa;
use std::{fmt, mem, slice};
use core::{fmt, mem, slice};
use super::error::*;
use ::alloc::vec::Vec;
use ::alloc::vec;

alsa_enum!(
/// [SND_CHMAP_TYPE_xxx](http://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.html) constants
Expand Down Expand Up @@ -136,8 +138,9 @@ impl Iterator for ChmapsQuery {

#[test]
fn chmap_for_first_pcm() {
extern crate std;
use super::*;
use std::ffi::CString;
use ::alloc::ffi::CString;
use crate::device_name::HintIter;

use crate::Output;
Expand All @@ -146,18 +149,18 @@ fn chmap_for_first_pcm() {

let i = HintIter::new(None, &*CString::new("pcm").unwrap()).unwrap();
for p in i.map(|n| n.name.unwrap()) {
println!("Chmaps for {:?}:", p);
std::println!("Chmaps for {:?}:", p);
match PCM::open(&CString::new(p).unwrap(), Direction::Playback, false) {
Ok(a) => for c in a.query_chmaps() {
println!(" {:?}, {}", c.0, c.1);
std::println!(" {:?}, {}", c.0, c.1);
},
Err(a) => println!(" {}", a) // It's okay to have entries in the name hint array that can't be opened
Err(a) => std::println!(" {}", a) // It's okay to have entries in the name hint array that can't be opened
}
}

output.borrow_mut().buffer_string(|buf| {
let str = CString::new(buf).unwrap();
println!("Errors:\n{}", str.to_str().unwrap());
std::println!("Errors:\n{}", str.to_str().unwrap());
});

}
7 changes: 4 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::{alsa};
use super::error::*;
use super::Output;
use std::ptr;
use core::ptr;

pub fn update() -> Result<bool> {
acheck!(snd_config_update()).map(|x| x != 0)
Expand Down Expand Up @@ -36,8 +36,9 @@ impl Config {

#[test]
fn config_save() {
extern crate std;
let c = update_ref().unwrap();
let mut outp = Output::buffer_open().unwrap();
c.save(&mut outp).unwrap();
println!("== Config save ==\n{}", outp);
}
std::println!("== Config save ==\n{}", outp);
}
14 changes: 8 additions & 6 deletions src/ctl_int.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

use crate::alsa;
use super::pcm::Info;
use std::ffi::{CStr, CString};
use core::ffi::CStr;
use ::alloc::ffi::CString;
use super::Direction;
use super::error::*;
use super::mixer::MilliBel;
use super::Round;
use std::{ptr, mem, fmt, cmp};
use core::{ptr, mem, fmt, cmp};
use crate::{Card, poll};
use std::cell::UnsafeCell;
use core::cell::UnsafeCell;
use libc::{c_uint, c_void, size_t, c_long, c_int, pollfd, c_short};

/// We prefer not to allocate for every ElemId, ElemInfo or ElemValue.
Expand Down Expand Up @@ -60,7 +61,7 @@ impl Ctl {
}

pub fn from_card(c: &Card, nonblock: bool) -> Result<Ctl> {
let s = format!("hw:{}", c.get_index());
let s = ::alloc::format!("hw:{}", c.get_index());
Ctl::open(&CString::new(s).unwrap(), nonblock)
}

Expand Down Expand Up @@ -294,7 +295,7 @@ impl ElemValue {

pub fn get_bytes(&self) -> Option<&[u8]> {
if self.etype != ElemType::Bytes { None }
else { Some( unsafe { ::std::slice::from_raw_parts(
else { Some( unsafe { ::core::slice::from_raw_parts(
alsa::snd_ctl_elem_value_get_bytes(self.ptr) as *const u8, self.count as usize) } ) }
}

Expand Down Expand Up @@ -546,6 +547,7 @@ impl EventMask {

#[test]
fn print_sizeof() {
extern crate std;
let elemid = unsafe { alsa::snd_ctl_elem_id_sizeof() } as usize;
let elemvalue = unsafe { alsa::snd_ctl_elem_value_sizeof() } as usize;
let eleminfo = unsafe { alsa::snd_ctl_elem_info_sizeof() } as usize;
Expand All @@ -554,5 +556,5 @@ fn print_sizeof() {
// assert!(elemvalue <= ELEM_VALUE_SIZE);
// assert!(eleminfo <= ELEM_INFO_SIZE);

println!("Elem id: {}, Elem value: {}, Elem info: {}", elemid, elemvalue, eleminfo);
std::println!("Elem id: {}, Elem value: {}, Elem info: {}", elemid, elemvalue, eleminfo);
}
13 changes: 8 additions & 5 deletions src/device_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! Print all devices found in various categories.
//!
//! ```
//! use std::ffi::CString;
//! use ::alloc::ffi::CString;
//! use alsa::device_name::HintIter;
//!
//! for t in &["pcm", "ctl", "rawmidi", "timer", "seq", "hwdep"] {
Expand All @@ -14,12 +14,14 @@
//! }
//! ```

use std::ptr;
use core::ptr;
use libc::{c_void, c_int};
use crate::alsa;
use super::{Card, Direction};
use super::error::*;
use std::ffi::{CStr, CString};
use core::ffi::CStr;
use ::alloc::ffi::CString;
use ::alloc::string::String;

/// [snd_device_name_hint](http://www.alsa-project.org/alsa-doc/alsa-lib/group___control.html) wrapper
pub struct HintIter(*mut *mut c_void, isize);
Expand Down Expand Up @@ -82,9 +84,10 @@ impl Hint {

#[test]
fn print_hints() {
extern crate std;
for t in &["pcm", "ctl", "rawmidi", "timer", "seq", "hwdep"] {
println!("{} devices:", t);
std::println!("{} devices:", t);
let i = HintIter::new(None, &*CString::new(*t).unwrap()).unwrap();
for a in i { println!(" {:?}", a) }
for a in i { std::println!(" {:?}", a) }
}
}
Loading