Skip to content

Commit

Permalink
Organise all the FFI stuff into cubeb-sys crate.
Browse files Browse the repository at this point in the history
  • Loading branch information
djg committed Feb 13, 2018
1 parent 211c7e4 commit 23f6c0f
Show file tree
Hide file tree
Showing 22 changed files with 658 additions and 119 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "libcubeb-sys/libcubeb"]
path = cubeb-api/libcubeb-sys/libcubeb
[submodule "cubeb-sys/libcubeb"]
path = cubeb-sys/libcubeb
url = https://github.com/kinetiknz/cubeb
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
members = [
"cubeb-core",
"cubeb-api",
"cubeb-backend"
"cubeb-backend",
"cubeb-sys"
]
1 change: 0 additions & 1 deletion cubeb-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ appveyor = { repository = "djg/cubeb-rs" }

[dependencies]
cubeb-core = { path = "../cubeb-core" }
libcubeb-sys = { path = "libcubeb-sys" }
105 changes: 0 additions & 105 deletions cubeb-api/libcubeb-sys/lib.rs

This file was deleted.

1 change: 0 additions & 1 deletion cubeb-api/libcubeb-sys/libcubeb
Submodule libcubeb deleted from 4c18a8
11 changes: 2 additions & 9 deletions cubeb-api/libcubeb-sys/Cargo.toml → cubeb-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libcubeb-sys"
version = "0.1.0"
name = "cubeb-sys"
version = "0.4.0"
authors = ["Dan Glastonbury <dglastonbury@mozilla.com>"]
repository = "https://github.com/djg/cubeb-rs"
license = "ISC"
Expand All @@ -9,13 +9,6 @@ description = "Native bindings to the cubeb library"
links = "cubeb"
build = "build.rs"

[lib]
name = "libcubeb_sys"
path = "lib.rs"

[dependencies]
cubeb-core = { path = "../../cubeb-core" }

[build-dependencies]
pkg-config = "0.3"
cmake = "0.1.2"
Expand Down
5 changes: 5 additions & 0 deletions cubeb-api/libcubeb-sys/build.rs → cubeb-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright © 2018 Mozilla Foundation
//
// This program is made available under an ISC-style license. See the
// accompanying file LICENSE for details.

extern crate cmake;
extern crate gcc;
extern crate pkg_config;
Expand Down
1 change: 1 addition & 0 deletions cubeb-sys/libcubeb
Submodule libcubeb added at 5f59ea
20 changes: 20 additions & 0 deletions cubeb-sys/src/callbacks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright © 2017-2018 Mozilla Foundation
//
// This program is made available under an ISC-style license. See the
// accompanying file LICENSE for details.

use context::cubeb;
use std::os::raw::{c_long, c_void};
use stream::{cubeb_state, cubeb_stream};

pub type cubeb_data_callback = Option<
unsafe extern fn(*mut cubeb_stream, *mut c_void, *const c_void, *mut c_void, c_long)
-> c_long,
>;
pub type cubeb_state_callback = Option<
unsafe extern fn(*mut cubeb_stream, *mut c_void, cubeb_state),
>;
pub type cubeb_device_changed_callback = Option<unsafe extern fn(*mut c_void)>;
pub type cubeb_device_collection_changed_callback = Option<
unsafe extern fn(*mut cubeb, *mut c_void),
>;
78 changes: 78 additions & 0 deletions cubeb-sys/src/channel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright © 2017-2018 Mozilla Foundation
//
// This program is made available under an ISC-style license. See the
// accompanying file LICENSE for details.

use std::{fmt, mem};
use std::os::raw::{c_int, c_uint};

cubeb_enum! {
pub enum cubeb_channel : c_int {
CHANNEL_INVALID = -1,
CHANNEL_MONO = 0,
CHANNEL_LEFT,
CHANNEL_RIGHT,
CHANNEL_CENTER,
CHANNEL_LS,
CHANNEL_RS,
CHANNEL_RLS,
CHANNEL_RCENTER,
CHANNEL_RRS,
CHANNEL_LFE,
CHANNEL_UNMAPPED,
CHANNEL_MAX = 256,
}
}

cubeb_enum! {
pub enum cubeb_channel_layout {
CUBEB_LAYOUT_UNDEFINED,

CUBEB_LAYOUT_DUAL_MONO,
CUBEB_LAYOUT_DUAL_MONO_LFE,
CUBEB_LAYOUT_MONO,
CUBEB_LAYOUT_MONO_LFE,
CUBEB_LAYOUT_STEREO,
CUBEB_LAYOUT_STEREO_LFE,
CUBEB_LAYOUT_3F,
CUBEB_LAYOUT_3F_LFE,
CUBEB_LAYOUT_2F1,
CUBEB_LAYOUT_2F1_LFE,
CUBEB_LAYOUT_3F1,
CUBEB_LAYOUT_3F1_LFE,
CUBEB_LAYOUT_2F2,
CUBEB_LAYOUT_2F2_LFE,
CUBEB_LAYOUT_3F2,
CUBEB_LAYOUT_3F2_LFE,
CUBEB_LAYOUT_3F3R_LFE,
CUBEB_LAYOUT_3F4_LFE,
CUBEB_LAYOUT_MAX,
}
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct cubeb_channel_map {
pub channels: c_uint,
pub map: [cubeb_channel; CHANNEL_MAX as usize],
}

impl Default for cubeb_channel_map {
fn default() -> Self { unsafe { mem::zeroed() } }
}

// Explicit Debug impl to work around bug in ctest
impl fmt::Debug for cubeb_channel_map {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("cubeb_channel_map")
.field("channels", &self.channels)
.field("map", &self.map.iter().take(self.channels as usize))
.finish()
}
}

extern {
pub fn cubeb_channel_map_to_layout(
channel_map: *const cubeb_channel_map,
) -> cubeb_channel_layout;
}
49 changes: 49 additions & 0 deletions cubeb-sys/src/context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright © 2017-2018 Mozilla Foundation
//
// This program is made available under an ISC-style license. See the
// accompanying file LICENSE for details.

use callbacks::{cubeb_data_callback, cubeb_state_callback};
use channel::cubeb_channel_layout;
use device::cubeb_devid;
use std::os::raw::{c_char, c_int, c_uint, c_void};
use stream::{cubeb_stream, cubeb_stream_params};

pub enum cubeb {}

extern {
pub fn cubeb_init(
context: *mut *mut cubeb,
context_name: *const c_char,
backend_name: *const c_char,
) -> c_int;
pub fn cubeb_get_backend_id(context: *mut cubeb) -> *const c_char;
pub fn cubeb_get_max_channel_count(
context: *mut cubeb,
max_channels: *mut c_uint,
) -> c_int;
pub fn cubeb_get_min_latency(
context: *mut cubeb,
params: *mut cubeb_stream_params,
latency_frames: *mut c_uint,
) -> c_int;
pub fn cubeb_get_preferred_sample_rate(context: *mut cubeb, rate: *mut c_uint) -> c_int;
pub fn cubeb_get_preferred_channel_layout(
context: *mut cubeb,
layout: *mut cubeb_channel_layout,
) -> c_int;
pub fn cubeb_destroy(context: *mut cubeb);
pub fn cubeb_stream_init(
context: *mut cubeb,
stream: *mut *mut cubeb_stream,
stream_name: *const c_char,
input_device: cubeb_devid,
input_stream_params: *mut cubeb_stream_params,
output_device: cubeb_devid,
output_stream_params: *mut cubeb_stream_params,
latency_frames: c_uint,
data_callback: cubeb_data_callback,
state_callback: cubeb_state_callback,
user_ptr: *mut c_void,
) -> c_int;
}
Loading

0 comments on commit 23f6c0f

Please sign in to comment.