Merge pull request #491 from creator-rs/master
Add Android APK build CI and Release version 0.13.0
This commit is contained in:
commit
2220f58491
8 changed files with 85 additions and 30 deletions
16
.github/workflows/cpal.yml
vendored
16
.github/workflows/cpal.yml
vendored
|
|
@ -3,6 +3,7 @@ name: cpal
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
clippy-test:
|
clippy-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
@ -224,3 +225,18 @@ jobs:
|
||||||
run: cargo check --example feedback --target armv7-linux-androideabi --verbose
|
run: cargo check --example feedback --target armv7-linux-androideabi --verbose
|
||||||
- name: Check record_wav
|
- name: Check record_wav
|
||||||
run: cargo check --example record_wav --target armv7-linux-androideabi --verbose
|
run: cargo check --example record_wav --target armv7-linux-androideabi --verbose
|
||||||
|
|
||||||
|
android-apk-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install Android targets
|
||||||
|
run: |
|
||||||
|
rustup target add armv7-linux-androideabi
|
||||||
|
rustup target add aarch64-linux-android
|
||||||
|
rustup target add i686-linux-android
|
||||||
|
rustup target add x86_64-linux-android
|
||||||
|
- name: Install Cargo APK
|
||||||
|
run: cargo install cargo-apk
|
||||||
|
- name: Build APK
|
||||||
|
run: cargo apk build --example beep
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
# Version 0.13.0 (2020-10-28)
|
||||||
|
|
||||||
|
- Add Android support via `oboe-rs`.
|
||||||
|
- Add Android APK build an CI job.
|
||||||
|
|
||||||
# Version 0.12.1 (2020-07-23)
|
# Version 0.12.1 (2020-07-23)
|
||||||
|
|
||||||
- Bugfix release to get the asio feature working again.
|
- Bugfix release to get the asio feature working again.
|
||||||
|
|
|
||||||
25
Cargo.toml
25
Cargo.toml
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "cpal"
|
name = "cpal"
|
||||||
version = "0.12.1"
|
version = "0.13.0"
|
||||||
authors = ["The CPAL contributors", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
|
authors = ["The CPAL contributors", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
|
||||||
description = "Low-level cross-platform audio I/O library in pure Rust."
|
description = "Low-level cross-platform audio I/O library in pure Rust."
|
||||||
repository = "https://github.com/rustaudio/cpal"
|
repository = "https://github.com/rustaudio/cpal"
|
||||||
|
|
@ -11,7 +11,6 @@ keywords = ["audio", "sound"]
|
||||||
[features]
|
[features]
|
||||||
asio = ["asio-sys", "num-traits"] # Only available on Windows. See README for setup instructions.
|
asio = ["asio-sys", "num-traits"] # Only available on Windows. See README for setup instructions.
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
thiserror = "1.0.2"
|
thiserror = "1.0.2"
|
||||||
|
|
||||||
|
|
@ -47,7 +46,27 @@ js-sys = { version = "0.3.35" }
|
||||||
web-sys = { version = "0.3.35", features = [ "AudioContext", "AudioContextOptions", "AudioBuffer", "AudioBufferSourceNode", "AudioNode", "AudioDestinationNode", "Window", "AudioContextState"] }
|
web-sys = { version = "0.3.35", features = [ "AudioContext", "AudioContextOptions", "AudioBuffer", "AudioBufferSourceNode", "AudioNode", "AudioDestinationNode", "Window", "AudioContextState"] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "android")'.dependencies]
|
[target.'cfg(target_os = "android")'.dependencies]
|
||||||
oboe = { version = "0.2.1", features = [ "java-interface" ] }
|
oboe = { version = "0.3.0", features = [ "java-interface" ] }
|
||||||
ndk = "0.2"
|
ndk = "0.2"
|
||||||
ndk-glue = "0.2"
|
ndk-glue = "0.2"
|
||||||
jni = "0.17"
|
jni = "0.17"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "beep"
|
||||||
|
path = "examples/beep.rs"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "enumerate"
|
||||||
|
path = "examples/enumerate.rs"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "feedback"
|
||||||
|
path = "examples/feedback.rs"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "record_wav"
|
||||||
|
path = "examples/record_wav.rs"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ extern crate cpal;
|
||||||
|
|
||||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
|
|
||||||
fn main() -> Result<(), anyhow::Error> {
|
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "full"))]
|
||||||
|
fn main() {
|
||||||
// Conditionally compile with jack if the feature is specified.
|
// Conditionally compile with jack if the feature is specified.
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"),
|
any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"),
|
||||||
|
|
@ -34,15 +35,13 @@ fn main() -> Result<(), anyhow::Error> {
|
||||||
let device = host
|
let device = host
|
||||||
.default_output_device()
|
.default_output_device()
|
||||||
.expect("failed to find a default output device");
|
.expect("failed to find a default output device");
|
||||||
let config = device.default_output_config()?;
|
let config = device.default_output_config().unwrap();
|
||||||
|
|
||||||
match config.sample_format() {
|
match config.sample_format() {
|
||||||
cpal::SampleFormat::F32 => run::<f32>(&device, &config.into())?,
|
cpal::SampleFormat::F32 => run::<f32>(&device, &config.into()).unwrap(),
|
||||||
cpal::SampleFormat::I16 => run::<i16>(&device, &config.into())?,
|
cpal::SampleFormat::I16 => run::<i16>(&device, &config.into()).unwrap(),
|
||||||
cpal::SampleFormat::U16 => run::<u16>(&device, &config.into())?,
|
cpal::SampleFormat::U16 => run::<u16>(&device, &config.into()).unwrap(),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run<T>(device: &cpal::Device, config: &cpal::StreamConfig) -> Result<(), anyhow::Error>
|
fn run<T>(device: &cpal::Device, config: &cpal::StreamConfig) -> Result<(), anyhow::Error>
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ pub fn to_stream_instant(duration: Duration) -> StreamInstant {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stream_instant<T: oboe::AudioStream + ?Sized>(stream: &mut T) -> StreamInstant {
|
pub fn stream_instant<T: oboe::AudioStreamSafe + ?Sized>(stream: &mut T) -> StreamInstant {
|
||||||
const CLOCK_MONOTONIC: i32 = 1;
|
const CLOCK_MONOTONIC: i32 = 1;
|
||||||
let ts = stream
|
let ts = stream
|
||||||
.get_timestamp(CLOCK_MONOTONIC)
|
.get_timestamp(CLOCK_MONOTONIC)
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ impl<I, C> CpalInputCallback<I, C> {
|
||||||
|
|
||||||
fn make_callback_info(
|
fn make_callback_info(
|
||||||
&self,
|
&self,
|
||||||
audio_stream: &mut dyn oboe::AudioInputStream,
|
audio_stream: &mut dyn oboe::AudioInputStreamSafe,
|
||||||
) -> InputCallbackInfo {
|
) -> InputCallbackInfo {
|
||||||
InputCallbackInfo {
|
InputCallbackInfo {
|
||||||
timestamp: InputStreamTimestamp {
|
timestamp: InputStreamTimestamp {
|
||||||
|
|
@ -50,7 +50,7 @@ where
|
||||||
|
|
||||||
fn on_audio_ready(
|
fn on_audio_ready(
|
||||||
&mut self,
|
&mut self,
|
||||||
audio_stream: &mut dyn oboe::AudioInputStream,
|
audio_stream: &mut dyn oboe::AudioInputStreamSafe,
|
||||||
audio_data: &[<<Self as oboe::AudioInputCallback>::FrameType as oboe::IsFrameType>::Type],
|
audio_data: &[<<Self as oboe::AudioInputCallback>::FrameType as oboe::IsFrameType>::Type],
|
||||||
) -> oboe::DataCallbackResult {
|
) -> oboe::DataCallbackResult {
|
||||||
let cb_info = self.make_callback_info(audio_stream);
|
let cb_info = self.make_callback_info(audio_stream);
|
||||||
|
|
@ -74,7 +74,7 @@ where
|
||||||
|
|
||||||
fn on_error_before_close(
|
fn on_error_before_close(
|
||||||
&mut self,
|
&mut self,
|
||||||
_audio_stream: &mut dyn oboe::AudioInputStream,
|
_audio_stream: &mut dyn oboe::AudioInputStreamSafe,
|
||||||
error: oboe::Error,
|
error: oboe::Error,
|
||||||
) {
|
) {
|
||||||
(self.error_cb)(StreamError::from(error))
|
(self.error_cb)(StreamError::from(error))
|
||||||
|
|
@ -82,7 +82,7 @@ where
|
||||||
|
|
||||||
fn on_error_after_close(
|
fn on_error_after_close(
|
||||||
&mut self,
|
&mut self,
|
||||||
_audio_stream: &mut dyn oboe::AudioInputStream,
|
_audio_stream: &mut dyn oboe::AudioInputStreamSafe,
|
||||||
error: oboe::Error,
|
error: oboe::Error,
|
||||||
) {
|
) {
|
||||||
(self.error_cb)(StreamError::from(error))
|
(self.error_cb)(StreamError::from(error))
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ mod output_callback;
|
||||||
|
|
||||||
use self::android_media::{get_audio_record_min_buffer_size, get_audio_track_min_buffer_size};
|
use self::android_media::{get_audio_record_min_buffer_size, get_audio_track_min_buffer_size};
|
||||||
use self::input_callback::CpalInputCallback;
|
use self::input_callback::CpalInputCallback;
|
||||||
|
use self::oboe::{AudioInputStream, AudioOutputStream};
|
||||||
use self::output_callback::CpalOutputCallback;
|
use self::output_callback::CpalOutputCallback;
|
||||||
|
|
||||||
// Android Java API supports up to 8 channels, but oboe API
|
// Android Java API supports up to 8 channels, but oboe API
|
||||||
|
|
@ -36,7 +37,10 @@ const SAMPLE_RATES: [i32; 13] = [
|
||||||
|
|
||||||
pub struct Host;
|
pub struct Host;
|
||||||
pub struct Device(Option<oboe::AudioDeviceInfo>);
|
pub struct Device(Option<oboe::AudioDeviceInfo>);
|
||||||
pub struct Stream(Box<RefCell<dyn oboe::AudioStream>>);
|
pub enum Stream {
|
||||||
|
Input(Box<RefCell<dyn AudioInputStream>>),
|
||||||
|
Output(Box<RefCell<dyn AudioOutputStream>>),
|
||||||
|
}
|
||||||
pub type SupportedInputConfigs = VecIntoIter<SupportedStreamConfigRange>;
|
pub type SupportedInputConfigs = VecIntoIter<SupportedStreamConfigRange>;
|
||||||
pub type SupportedOutputConfigs = VecIntoIter<SupportedStreamConfigRange>;
|
pub type SupportedOutputConfigs = VecIntoIter<SupportedStreamConfigRange>;
|
||||||
pub type Devices = VecIntoIter<Device>;
|
pub type Devices = VecIntoIter<Device>;
|
||||||
|
|
@ -242,7 +246,7 @@ where
|
||||||
error_callback,
|
error_callback,
|
||||||
))
|
))
|
||||||
.open_stream()?;
|
.open_stream()?;
|
||||||
Ok(Stream(Box::new(RefCell::new(stream))))
|
Ok(Stream::Input(Box::new(RefCell::new(stream))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_output_stream<D, E, C, T>(
|
fn build_output_stream<D, E, C, T>(
|
||||||
|
|
@ -266,7 +270,7 @@ where
|
||||||
error_callback,
|
error_callback,
|
||||||
))
|
))
|
||||||
.open_stream()?;
|
.open_stream()?;
|
||||||
Ok(Stream(Box::new(RefCell::new(stream))))
|
Ok(Stream::Output(Box::new(RefCell::new(stream))))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeviceTrait for Device {
|
impl DeviceTrait for Device {
|
||||||
|
|
@ -472,16 +476,28 @@ impl DeviceTrait for Device {
|
||||||
|
|
||||||
impl StreamTrait for Stream {
|
impl StreamTrait for Stream {
|
||||||
fn play(&self) -> Result<(), PlayStreamError> {
|
fn play(&self) -> Result<(), PlayStreamError> {
|
||||||
self.0
|
match self {
|
||||||
.borrow_mut()
|
Self::Input(stream) => stream
|
||||||
.request_start()
|
.borrow_mut()
|
||||||
.map_err(PlayStreamError::from)
|
.request_start()
|
||||||
|
.map_err(PlayStreamError::from),
|
||||||
|
Self::Output(stream) => stream
|
||||||
|
.borrow_mut()
|
||||||
|
.request_start()
|
||||||
|
.map_err(PlayStreamError::from),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pause(&self) -> Result<(), PauseStreamError> {
|
fn pause(&self) -> Result<(), PauseStreamError> {
|
||||||
self.0
|
match self {
|
||||||
.borrow_mut()
|
Self::Input(_) => Err(BackendSpecificError {
|
||||||
.request_pause()
|
description: "Pause called on the input stream.".to_owned(),
|
||||||
.map_err(PauseStreamError::from)
|
}
|
||||||
|
.into()),
|
||||||
|
Self::Output(stream) => stream
|
||||||
|
.borrow_mut()
|
||||||
|
.request_pause()
|
||||||
|
.map_err(PauseStreamError::from),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ impl<I, C> CpalOutputCallback<I, C> {
|
||||||
|
|
||||||
fn make_callback_info(
|
fn make_callback_info(
|
||||||
&self,
|
&self,
|
||||||
audio_stream: &mut dyn oboe::AudioOutputStream,
|
audio_stream: &mut dyn oboe::AudioOutputStreamSafe,
|
||||||
) -> OutputCallbackInfo {
|
) -> OutputCallbackInfo {
|
||||||
OutputCallbackInfo {
|
OutputCallbackInfo {
|
||||||
timestamp: OutputStreamTimestamp {
|
timestamp: OutputStreamTimestamp {
|
||||||
|
|
@ -50,7 +50,7 @@ where
|
||||||
|
|
||||||
fn on_audio_ready(
|
fn on_audio_ready(
|
||||||
&mut self,
|
&mut self,
|
||||||
audio_stream: &mut dyn oboe::AudioOutputStream,
|
audio_stream: &mut dyn oboe::AudioOutputStreamSafe,
|
||||||
audio_data: &mut [<<Self as oboe::AudioOutputCallback>::FrameType as oboe::IsFrameType>::Type],
|
audio_data: &mut [<<Self as oboe::AudioOutputCallback>::FrameType as oboe::IsFrameType>::Type],
|
||||||
) -> oboe::DataCallbackResult {
|
) -> oboe::DataCallbackResult {
|
||||||
let cb_info = self.make_callback_info(audio_stream);
|
let cb_info = self.make_callback_info(audio_stream);
|
||||||
|
|
@ -74,7 +74,7 @@ where
|
||||||
|
|
||||||
fn on_error_before_close(
|
fn on_error_before_close(
|
||||||
&mut self,
|
&mut self,
|
||||||
_audio_stream: &mut dyn oboe::AudioOutputStream,
|
_audio_stream: &mut dyn oboe::AudioOutputStreamSafe,
|
||||||
error: oboe::Error,
|
error: oboe::Error,
|
||||||
) {
|
) {
|
||||||
(self.error_cb)(StreamError::from(error))
|
(self.error_cb)(StreamError::from(error))
|
||||||
|
|
@ -82,7 +82,7 @@ where
|
||||||
|
|
||||||
fn on_error_after_close(
|
fn on_error_after_close(
|
||||||
&mut self,
|
&mut self,
|
||||||
_audio_stream: &mut dyn oboe::AudioOutputStream,
|
_audio_stream: &mut dyn oboe::AudioOutputStreamSafe,
|
||||||
error: oboe::Error,
|
error: oboe::Error,
|
||||||
) {
|
) {
|
||||||
(self.error_cb)(StreamError::from(error))
|
(self.error_cb)(StreamError::from(error))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue