Add a CallbackInfo argument to the stream data callback

I began on an implementation of the timestamp API described in #363 but
quickly realised that it might be best to land the API for providing
extra information to the user's callback first.

This PR adds two new types: `InputCallbackInfo` and `OutputCallbackInfo`.
These types are delivered to the user's data callback as a new, second
argument.

While these types are currently empty, the intention is for these types
to provide information relevant to the current request for or delivery
of data. This includes:

- Timestamp information #363.
- Flags related to the state of the stream (e.g buffer
  underflow/overflow).

In order to maintain flexibility to avoid breaking things, I figure we
can keep the fields of these types private and provide methods for
retrieving this info.

@Ralith, @ishitatsuyuki does this seem OK to you?
This commit is contained in:
mitchmindtree 2020-04-16 14:50:36 +02:00
parent 608d23adc6
commit bcf962c447
14 changed files with 104 additions and 83 deletions

View file

@ -4,19 +4,14 @@ extern crate num_traits;
use self::num_traits::PrimInt;
use super::parking_lot::Mutex;
use super::Device;
use crate::{
BackendSpecificError, BuildStreamError, Data, InputCallbackInfo, OutputCallbackInfo,
PauseStreamError, PlayStreamError, Sample, SampleFormat, StreamConfig, StreamError,
SupportedStreamConfig,
};
use std;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use BackendSpecificError;
use BuildStreamError;
use Data;
use PauseStreamError;
use PlayStreamError;
use Sample;
use SampleFormat;
use StreamConfig;
use StreamError;
use SupportedStreamConfig;
/// Sample types whose constant silent value is known.
trait Silence {
@ -66,7 +61,7 @@ impl Device {
_error_callback: E,
) -> Result<Stream, BuildStreamError>
where
D: FnMut(&Data) + Send + 'static,
D: FnMut(&Data, &InputCallbackInfo) + Send + 'static,
E: FnMut(StreamError) + Send + 'static,
{
let stream_type = self.driver.input_data_type().map_err(build_stream_err)?;
@ -133,7 +128,8 @@ impl Device {
let data = interleaved.as_mut_ptr() as *mut ();
let len = interleaved.len();
let data = Data::from_parts(data, len, B::FORMAT);
callback(&data);
let info = InputCallbackInfo {};
callback(&data, &info);
}
match (&stream_type, sample_format) {
@ -233,7 +229,7 @@ impl Device {
_error_callback: E,
) -> Result<Stream, BuildStreamError>
where
D: FnMut(&mut Data) + Send + 'static,
D: FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static,
E: FnMut(StreamError) + Send + 'static,
{
let stream_type = self.driver.output_data_type().map_err(build_stream_err)?;
@ -315,6 +311,7 @@ impl Device {
let data = interleaved.as_mut_ptr() as *mut ();
let len = interleaved.len();
let mut data = Data::from_parts(data, len, A::FORMAT);
let info = OutputCallbackInfo {};
callback(&mut data);
// 2. Silence ASIO channels if necessary.