Update oboe to newest version. Fix support of input/output oboe streams
This commit is contained in:
parent
01c5ee600a
commit
bf766c1d5d
5 changed files with 38 additions and 21 deletions
|
|
@ -46,7 +46,8 @@ 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 = { git = "https://github.com/katyo/oboe-rs", rev = "ae2f4d863ea4fde7a30628e032f4011c60f75ea5", features = [ "java-interface" ] }
|
||||||
|
# oboe = { version = "0.2.1", features = [ "java-interface" ] }
|
||||||
ndk = "0.2"
|
ndk = "0.2"
|
||||||
ndk-glue = "0.2"
|
ndk-glue = "0.2"
|
||||||
jni = "0.17"
|
jni = "0.17"
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
Self::Input(stream) => stream
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.request_start()
|
.request_start()
|
||||||
.map_err(PlayStreamError::from)
|
.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 {
|
||||||
|
Self::Input(_) => Err(BackendSpecificError {
|
||||||
|
description: "Pause called on the input stream.".to_owned(),
|
||||||
|
}
|
||||||
|
.into()),
|
||||||
|
Self::Output(stream) => stream
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.request_pause()
|
.request_pause()
|
||||||
.map_err(PauseStreamError::from)
|
.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