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:
parent
608d23adc6
commit
bcf962c447
14 changed files with 104 additions and 83 deletions
|
|
@ -1,9 +1,10 @@
|
|||
//! The suite of traits allowing CPAL to abstract over hosts, devices, event loops and stream IDs.
|
||||
|
||||
use {
|
||||
BuildStreamError, Data, DefaultStreamConfigError, DeviceNameError, DevicesError, InputDevices,
|
||||
OutputDevices, PauseStreamError, PlayStreamError, Sample, SampleFormat, StreamConfig,
|
||||
StreamError, SupportedStreamConfig, SupportedStreamConfigRange, SupportedStreamConfigsError,
|
||||
BuildStreamError, Data, DefaultStreamConfigError, DeviceNameError, DevicesError,
|
||||
InputCallbackInfo, InputDevices, OutputCallbackInfo, OutputDevices, PauseStreamError,
|
||||
PlayStreamError, Sample, SampleFormat, StreamConfig, StreamError, SupportedStreamConfig,
|
||||
SupportedStreamConfigRange, SupportedStreamConfigsError,
|
||||
};
|
||||
|
||||
/// A **Host** provides access to the available audio devices on the system.
|
||||
|
|
@ -122,16 +123,17 @@ pub trait DeviceTrait {
|
|||
) -> Result<Self::Stream, BuildStreamError>
|
||||
where
|
||||
T: Sample,
|
||||
D: FnMut(&[T]) + Send + 'static,
|
||||
D: FnMut(&[T], &InputCallbackInfo) + Send + 'static,
|
||||
E: FnMut(StreamError) + Send + 'static,
|
||||
{
|
||||
self.build_input_stream_raw(
|
||||
config,
|
||||
T::FORMAT,
|
||||
move |data| {
|
||||
move |data, info| {
|
||||
data_callback(
|
||||
data.as_slice()
|
||||
.expect("host supplied incorrect sample type"),
|
||||
info,
|
||||
)
|
||||
},
|
||||
error_callback,
|
||||
|
|
@ -147,16 +149,17 @@ pub trait DeviceTrait {
|
|||
) -> Result<Self::Stream, BuildStreamError>
|
||||
where
|
||||
T: Sample,
|
||||
D: FnMut(&mut [T]) + Send + 'static,
|
||||
D: FnMut(&mut [T], &OutputCallbackInfo) + Send + 'static,
|
||||
E: FnMut(StreamError) + Send + 'static,
|
||||
{
|
||||
self.build_output_stream_raw(
|
||||
config,
|
||||
T::FORMAT,
|
||||
move |data| {
|
||||
move |data, info| {
|
||||
data_callback(
|
||||
data.as_slice_mut()
|
||||
.expect("host supplied incorrect sample type"),
|
||||
info,
|
||||
)
|
||||
},
|
||||
error_callback,
|
||||
|
|
@ -172,7 +175,7 @@ pub trait DeviceTrait {
|
|||
error_callback: E,
|
||||
) -> Result<Self::Stream, BuildStreamError>
|
||||
where
|
||||
D: FnMut(&Data) + Send + 'static,
|
||||
D: FnMut(&Data, &InputCallbackInfo) + Send + 'static,
|
||||
E: FnMut(StreamError) + Send + 'static;
|
||||
|
||||
/// Create a dynamically typed output stream.
|
||||
|
|
@ -184,7 +187,7 @@ pub trait DeviceTrait {
|
|||
error_callback: E,
|
||||
) -> Result<Self::Stream, BuildStreamError>
|
||||
where
|
||||
D: FnMut(&mut Data) + Send + 'static,
|
||||
D: FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static,
|
||||
E: FnMut(StreamError) + Send + 'static;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue