Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose new unsafe audio dump API to rust. #89

Merged
merged 6 commits into from
Apr 22, 2024
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
18 changes: 16 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-2019, macos-10.15]
os: [ubuntu-20.04, windows-2019, macos-14]
rust: [stable]
experimental: [false]
include:
Expand All @@ -19,7 +19,7 @@ jobs:
- os: windows-2019
rust: nightly
experimental: true
- os: macos-10.15
- os: macos-14
rust: nightly
experimental: true

Expand All @@ -44,6 +44,20 @@ jobs:
shell: bash
run: rustup run ${{ matrix.rust }} cargo build --all

- name: Setup Audio
if: ${{ matrix.os == 'macos-14' }}
run: |
brew install switchaudio-osx
brew install blackhole-2ch
SwitchAudioSource -s "BlackHole 2ch" -t input
SwitchAudioSource -s "BlackHole 2ch" -t output

- name: Grant microphone access
if: ${{ matrix.os == 'macos-14' }}
env:
tcc_extra_columns: ${{ matrix.os == 'macos-14' && ',NULL,NULL,''UNUSED'',1687786159' || '' }}
run: sqlite3 $HOME/Library/Application\ Support/com.apple.TCC/TCC.db "INSERT OR IGNORE INTO access VALUES ('kTCCServiceMicrophone','/usr/local/opt/runner/provisioner/provisioner',1,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,1687786159${{ env.tcc_extra_columns }});"

- name: Test
shell: bash
run: rustup run ${{ matrix.rust }} cargo test --all
Expand Down
2 changes: 1 addition & 1 deletion cubeb-api/src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait Sample: Send + Copy {

impl Sample for i16 {
fn from_float(x: f32) -> i16 {
(x * f32::from(i16::max_value())) as i16
(x * f32::from(i16::MAX)) as i16
}
}

Expand Down
2 changes: 1 addition & 1 deletion cubeb-backend/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait ContextOps {
collection: &DeviceCollectionRef,
) -> Result<()>;
fn device_collection_destroy(&mut self, collection: &mut DeviceCollectionRef) -> Result<()>;
#[cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments))]
#[allow(clippy::too_many_arguments)]
fn stream_init(
&mut self,
stream_name: Option<&CStr>,
Expand Down
2 changes: 1 addition & 1 deletion cubeb-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ gecko-in-tree = ["cubeb-sys/gecko-in-tree"]

[dependencies]
bitflags = "1.2.0"
cubeb-sys = { path = "../cubeb-sys", version = "0.12.0" }
cubeb-sys = { path = "../cubeb-sys" }
1 change: 0 additions & 1 deletion cubeb-core/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use ffi;
use {ChannelLayout, SampleFormat, StreamParams, StreamPrefs};

///
#[derive(Debug)]
pub struct StreamParamsBuilder(ffi::cubeb_stream_params);

Expand Down
2 changes: 1 addition & 1 deletion cubeb-core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl ContextRef {
///
/// This function is unsafe because it dereferences the given `data_callback`, `state_callback`, and `user_ptr` pointers.
/// The caller should ensure those pointers are valid.
#[cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments))]
#[allow(clippy::too_many_arguments)]
pub unsafe fn stream_init(
&self,
stream_name: Option<&CStr>,
Expand Down
35 changes: 35 additions & 0 deletions cubeb-sys/src/audio_dump.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2017-2023 Mozilla Foundation
//
// 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, c_void};
use stream::cubeb_stream_params;

pub enum cubeb_audio_dump_stream {}
pub enum cubeb_audio_dump_session {}
pub type cubeb_audio_dump_stream_t = *mut cubeb_audio_dump_stream;
pub type cubeb_audio_dump_session_t = *mut cubeb_audio_dump_session;

extern "C" {
pub fn cubeb_audio_dump_init(session: *mut cubeb_audio_dump_session_t) -> c_int;
pub fn cubeb_audio_dump_shutdown(session: cubeb_audio_dump_session_t) -> c_int;
pub fn cubeb_audio_dump_stream_init(
session: cubeb_audio_dump_session_t,
stream: *mut cubeb_audio_dump_stream_t,
stream_params: cubeb_stream_params,
name: *const c_char,
) -> c_int;
pub fn cubeb_audio_dump_stream_shutdown(
session: cubeb_audio_dump_session_t,
stream: cubeb_audio_dump_stream_t,
) -> c_int;
pub fn cubeb_audio_dump_start(session: cubeb_audio_dump_session_t) -> c_int;
pub fn cubeb_audio_dump_stop(session: cubeb_audio_dump_session_t) -> c_int;
pub fn cubeb_audio_dump_write(
stream: cubeb_audio_dump_stream_t,
audio_samples: *mut c_void,
count: u32,
) -> c_int;

}
2 changes: 2 additions & 0 deletions cubeb-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#[macro_use]
mod macros;

mod audio_dump;
mod callbacks;
mod channel;
mod context;
Expand All @@ -19,6 +20,7 @@ mod mixer;
mod resampler;
mod stream;

pub use audio_dump::*;
pub use callbacks::*;
pub use channel::*;
pub use context::*;
Expand Down
3 changes: 2 additions & 1 deletion systest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ fn main() {
cfg.header("cubeb.h")
.header("cubeb_mixer.h")
.header("cubeb_resampler.h")
.header("cubeb_log.h");
.header("cubeb_log.h")
.header("cubeb_audio_dump.h");

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