Trait oboe::AudioStream
source · pub trait AudioStream: AudioStreamSafe {
// Required methods
fn close(&mut self) -> Status;
fn start_with_timeout(&mut self, timeout_nanoseconds: i64) -> Status;
fn stop_with_timeout(&mut self, timeout_nanoseconds: i64) -> Status;
fn request_start(&mut self) -> Status;
fn request_stop(&mut self) -> Status;
fn wait_for_state_change(
&mut self,
input_state: StreamState,
timeout_nanoseconds: i64
) -> Result<StreamState>;
fn wait_for_available_frames(
&mut self,
num_frames: i32,
timeout_nanoseconds: i64
) -> Result<i32>;
// Provided methods
fn open(&mut self) -> Status { ... }
fn start(&mut self) -> Status { ... }
fn stop(&mut self) -> Status { ... }
}
Expand description
Base trait for Oboe audio stream.
Required Methods§
sourcefn close(&mut self) -> Status
fn close(&mut self) -> Status
Close the stream and deallocate any resources from the open() call.
sourcefn start_with_timeout(&mut self, timeout_nanoseconds: i64) -> Status
fn start_with_timeout(&mut self, timeout_nanoseconds: i64) -> Status
Start the stream. This will block until the stream has been started, an error occurs
or timeout_nanoseconds
has been reached.
sourcefn stop_with_timeout(&mut self, timeout_nanoseconds: i64) -> Status
fn stop_with_timeout(&mut self, timeout_nanoseconds: i64) -> Status
Stop the stream. This will block until the stream has been stopped, an error occurs
or timeoutNanoseconds
has been reached.
sourcefn request_start(&mut self) -> Status
fn request_start(&mut self) -> Status
Start the stream asynchronously. Returns immediately (does not block). Equivalent to calling
start(0)
.
sourcefn request_stop(&mut self) -> Status
fn request_stop(&mut self) -> Status
Stop the stream asynchronously. Returns immediately (does not block). Equivalent to calling
stop(0)
.
sourcefn wait_for_state_change(
&mut self,
input_state: StreamState,
timeout_nanoseconds: i64
) -> Result<StreamState>
fn wait_for_state_change( &mut self, input_state: StreamState, timeout_nanoseconds: i64 ) -> Result<StreamState>
Wait until the stream’s current state no longer matches the input state. The input state is passed to avoid race conditions caused by the state changing between calls.
Note that generally applications do not need to call this. It is considered an advanced technique and is mostly used for testing.
const TIMEOUT_NANOS: i64 = 500 * NANOS_PER_MILLISECOND; // arbitrary 1/2 second
let mut current_state = stream.get_state();
loop {
if let Ok(next_state) = stream.wait_for_state_change(current_state, TIMEOUT_NANOS) {
if next_state != StreamState::Paused {
current_state = next_state;
continue;
}
}
break;
}
If the state does not change within the timeout period then it will
return Error::Timeout
. This is true even if timeout_nanoseconds is zero.
sourcefn wait_for_available_frames(
&mut self,
num_frames: i32,
timeout_nanoseconds: i64
) -> Result<i32>
fn wait_for_available_frames( &mut self, num_frames: i32, timeout_nanoseconds: i64 ) -> Result<i32>
Wait until the stream has a minimum amount of data available in its buffer. This can be used with an EXCLUSIVE MMAP input stream to avoid reading data too close to the DSP write position, which may cause glitches.
Provided Methods§
sourcefn open(&mut self) -> Status
fn open(&mut self) -> Status
Open a stream based on the current settings.
Note that we do not recommend re-opening a stream that has been closed. TODO Should we prevent re-opening?