Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "cubeb-sys/libcubeb"]
path = cubeb-sys/libcubeb
url = https://github.com/kinetiknz/cubeb
url = https://github.com/mozilla/cubeb
10 changes: 5 additions & 5 deletions cubeb-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[package]
name = "cubeb"
version = "0.10.0"
version = "0.10.1"
authors = ["Dan Glastonbury <dglastonbury@mozilla.com>"]
license = "ISC"
readme = "README.md"
keywords = ["cubeb"]
repository = "https://github.com/djg/cubeb-rs"
homepage = "https://github.com/djg/cubeb-rs"
repository = "https://github.com/mozilla/cubeb-rs"
homepage = "https://github.com/mozilla/cubeb-rs"
description = """
Bindings to libcubeb for interacting with system audio from rust.
"""
categories = ["api-bindings"]

[badges]
circle-ci = { repository = "djg/cubeb-rs" }
circle-ci = { repository = "mozilla/cubeb-rs" }

[features]
gecko-in-tree = ["cubeb-core/gecko-in-tree"]

[dependencies]
cubeb-core = { path = "../cubeb-core", version = "0.10.0" }
cubeb-core = { path = "../cubeb-core", version = "0.10.1" }
10 changes: 5 additions & 5 deletions cubeb-backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[package]
name = "cubeb-backend"
version = "0.10.0"
version = "0.10.1"
authors = ["Dan Glastonbury <dglastonbury@mozilla.com>"]
license = "ISC"
keywords = ["cubeb"]
repository = "https://github.com/djg/cubeb-rs"
homepage = "https://github.com/djg/cubeb-rs"
repository = "https://github.com/mozilla/cubeb-rs"
homepage = "https://github.com/mozilla/cubeb-rs"
description = """
Bindings to libcubeb internals to facilitate implementing cubeb backends in rust.
"""
categories = ["api-bindings"]

[badges]
circle-ci = { repository = "djg/cubeb-rs" }
circle-ci = { repository = "mozilla/cubeb-rs" }

[features]
gecko-in-tree = ["cubeb-core/gecko-in-tree"]

[dependencies]
cubeb-core = { path = "../cubeb-core", version = "0.10.0" }
cubeb-core = { path = "../cubeb-core", version = "0.10.1" }
2 changes: 1 addition & 1 deletion cubeb-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate cubeb_core;

pub mod capi;
#[macro_use]
mod log;
pub mod log;
mod ops;
mod traits;

Expand Down
101 changes: 64 additions & 37 deletions cubeb-backend/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,98 @@
// This program is made available under an ISC-style license. See the
// accompanying file LICENSE for details.

/// Annotates input buffer string with logging information.
/// Returns result as a ffi::CStr for use with native cubeb logging functions.
pub fn cubeb_log_internal_buf_fmt<'a>(
buf: &'a mut [u8; 1024],
file: &str,
line: u32,
msg: &str,
) -> &'a std::ffi::CStr {
use std::io::Write;
let filename = std::path::Path::new(file)
.file_name()
.unwrap()
.to_str()
.unwrap();
// 2 for ':', 1 for ' ', 1 for '\n', and 1 for converting `line!()` to number of digits
let len = filename.len() + ((line as f32).log10().trunc() as usize) + msg.len() + 5;
debug_assert!(len < buf.len(), "log will be truncated");
let _ = writeln!(&mut buf[..], "{}:{}: {}", filename, line, msg);
let last = std::cmp::min(len, buf.len() - 1);
buf[last] = 0;
let cstr = unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(&buf[..=last]) };
cstr
}

#[macro_export]
macro_rules! cubeb_log_internal {
($level: expr, $msg: expr) => {
#[allow(unused_unsafe)]
unsafe {
if $level <= $crate::ffi::g_cubeb_log_level.into() {
cubeb_log_internal!(__INTERNAL__ $msg);
}
}
($log_callback: expr, $level: expr, $fmt: expr, $($arg: expr),+) => {
cubeb_log_internal!($log_callback, $level, format!($fmt, $($arg),*));
};
($level: expr, $fmt: expr, $($arg: expr),+) => {
($log_callback: expr, $level: expr, $msg: expr) => {
#[allow(unused_unsafe)]
unsafe {
if $level <= $crate::ffi::g_cubeb_log_level.into() {
cubeb_log_internal!(__INTERNAL__ format!($fmt, $($arg),*));
if let Some(log_callback) = $log_callback {
let mut buf = [0u8; 1024];
log_callback(
$crate::log::cubeb_log_internal_buf_fmt(&mut buf, file!(), line!(), &$msg)
.as_ptr(),
);
}
}
}
};
(__INTERNAL__ $msg: expr) => {
if let Some(log_callback) = $crate::ffi::g_cubeb_log_callback {
use std::io::Write;
}

let mut buf = [0 as u8; 1024];
let filename = std::path::Path::new(file!())
.file_name()
.unwrap()
.to_str()
.unwrap();
// 2 for ':', 1 for ' ', 1 for '\n', and 1 for converting `line!()` to number of digits
let len = filename.len() + ((line!() as f32).log10().trunc() as usize) + $msg.len() + 5;
debug_assert!(len < buf.len(), "log will be truncated");
let _ = write!(&mut buf[..], "{}:{}: {}\n", filename, line!(), $msg);
let last = std::cmp::min(len, buf.len() - 1);
buf[last] = 0;
let cstr = unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(&buf[..=last]) };
log_callback(cstr.as_ptr());
}
}
#[macro_export]
macro_rules! cubeb_log {
($($arg: expr),+) => (cubeb_log_internal!($crate::ffi::g_cubeb_log_callback, $crate::LogLevel::Normal, $($arg),+));
}

#[macro_export]
macro_rules! cubeb_logv {
($msg: expr) => (cubeb_log_internal!($crate::LogLevel::Verbose, $msg));
($fmt: expr, $($arg: expr),+) => (cubeb_log_internal!($crate::LogLevel::Verbose, $fmt, $($arg),*));
($($arg: expr),+) => (cubeb_log_internal!($crate::ffi::g_cubeb_log_callback, $crate::LogLevel::Verbose, $($arg),+));
}

#[macro_export]
macro_rules! cubeb_log {
($msg: expr) => (cubeb_log_internal!($crate::LogLevel::Normal, $msg));
($fmt: expr, $($arg: expr),+) => (cubeb_log_internal!($crate::LogLevel::Normal, $fmt, $($arg),*));
macro_rules! cubeb_alog {
($($arg: expr),+) => (cubeb_log_internal!($crate::ffi::cubeb_async_log.into(), $crate::LogLevel::Normal, $($arg),+));
}

#[macro_export]
macro_rules! cubeb_alogv {
($($arg: expr),+) => (cubeb_log_internal!($crate::ffi::cubeb_async_log.into(), $crate::LogLevel::Verbose, $($arg),+));
}

#[cfg(test)]
mod tests {
#[test]
fn test_normal_logging() {
cubeb_log!("This is log at normal level");
fn test_normal_logging_sync() {
cubeb_log!("This is synchronous log output at normal level");
cubeb_log!("{} Formatted log", 1);
cubeb_log!("{} Formatted {} log {}", 1, 2, 3);
}

#[test]
fn test_verbose_logging() {
cubeb_logv!("This is a log at verbose level");
fn test_verbose_logging_sync() {
cubeb_logv!("This is synchronous log output at verbose level");
cubeb_logv!("{} Formatted log", 1);
cubeb_logv!("{} Formatted {} log {}", 1, 2, 3);
}

#[test]
fn test_normal_logging_async() {
cubeb_alog!("This is asynchronous log output at normal level");
cubeb_alog!("{} Formatted log", 1);
cubeb_alog!("{} Formatted {} log {}", 1, 2, 3);
}

#[test]
fn test_verbose_logging_async() {
cubeb_alogv!("This is asynchronous log output at verbose level");
cubeb_alogv!("{} Formatted log", 1);
cubeb_alogv!("{} Formatted {} log {}", 1, 2, 3);
}
}
10 changes: 5 additions & 5 deletions cubeb-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[package]
name = "cubeb-core"
version = "0.10.0"
version = "0.10.1"
authors = ["Dan Glastonbury <dglastonbury@mozilla.com>"]
license = "ISC"
keywords = ["cubeb"]
repository = "https://github.com/djg/cubeb-rs"
homepage = "https://github.com/djg/cubeb-rs"
repository = "https://github.com/mozilla/cubeb-rs"
homepage = "https://github.com/mozilla/cubeb-rs"
description = """
Common types and definitions for cubeb rust and C bindings. Not intended for direct use.
"""
categories = ["api-bindings"]

[badges]
circle-ci = { repository = "djg/cubeb-rs" }
circle-ci = { repository = "mozilla/cubeb-rs" }

[features]
gecko-in-tree = ["cubeb-sys/gecko-in-tree"]

[dependencies]
bitflags = "1.2.0"
cubeb-sys = { path = "../cubeb-sys", version = "0.10.0" }
cubeb-sys = { path = "../cubeb-sys", version = "0.10.1" }
6 changes: 3 additions & 3 deletions cubeb-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "cubeb-sys"
version = "0.10.0"
version = "0.10.1"
authors = ["Dan Glastonbury <dglastonbury@mozilla.com>"]
repository = "https://github.com/djg/cubeb-rs"
repository = "https://github.com/mozilla/cubeb-rs"
license = "ISC"
description = "Native bindings to the cubeb library"

links = "cubeb"
build = "build.rs"

[badges]
circle-ci = { repository = "djg/cubeb-rs" }
circle-ci = { repository = "mozilla/cubeb-rs" }

[features]
gecko-in-tree = []
Expand Down
1 change: 1 addition & 0 deletions cubeb-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn main() {
let _ = pkg_config::find_library("alsa");
let _ = pkg_config::find_library("libpulse");
let _ = pkg_config::find_library("jack");
let _ = pkg_config::find_library("speexdsp");
if android {
println!("cargo:rustc-link-lib=dylib=OpenSLES");
}
Expand Down
5 changes: 4 additions & 1 deletion cubeb-sys/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This program is made available under an ISC-style license. See the
// accompanying file LICENSE for details.

use std::os::raw::{c_char, c_int};
use std::os::raw::{c_char, c_int, c_void};

cubeb_enum! {
pub enum cubeb_log_level {
Expand All @@ -23,4 +23,7 @@ extern "C" {

pub static g_cubeb_log_level: cubeb_log_level;
pub static g_cubeb_log_callback: cubeb_log_callback;

pub fn cubeb_async_log_reset_threads(_: c_void) -> c_void;
pub fn cubeb_async_log(msg: *const c_char, ...) -> c_void;
}
3 changes: 2 additions & 1 deletion systest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ fn main() {
// Include the header files where the C APIs are defined
cfg.header("cubeb.h")
.header("cubeb_mixer.h")
.header("cubeb_resampler.h");
.header("cubeb_resampler.h")
.header("cubeb_log.h");

// Include the directory where the header files are defined
cfg.include(root.join("include"))
Expand Down