@@ -11,14 +11,14 @@ use std::vec::IntoIter as VecIntoIter;
1111
1212extern crate ndk;
1313
14- use convert:: { now_stream_instant, stream_instant } ;
14+ use convert:: { input_stream_instant , now_stream_instant, output_stream_instant } ;
1515use java_interface:: { AudioDeviceInfo , AudioManager } ;
1616
1717use crate :: traits:: { DeviceTrait , HostTrait , StreamTrait } ;
1818use crate :: {
1919 BackendSpecificError , BufferSize , BuildStreamError , Data , DefaultStreamConfigError ,
2020 DeviceDescription , DeviceDescriptionBuilder , DeviceDirection , DeviceId , DeviceIdError ,
21- DeviceNameError , DeviceType , DevicesError , InputCallbackInfo , InputStreamTimestamp ,
21+ DeviceNameError , DeviceType , DevicesError , FrameCount , InputCallbackInfo , InputStreamTimestamp ,
2222 InterfaceType , OutputCallbackInfo , OutputStreamTimestamp , PauseStreamError , PlayStreamError ,
2323 SampleFormat , StreamConfig , StreamError , SupportedBufferSize , SupportedStreamConfig ,
2424 SupportedStreamConfigRange , SupportedStreamConfigsError ,
@@ -199,13 +199,9 @@ impl HostTrait for Host {
199199}
200200
201201fn buffer_size_range ( ) -> SupportedBufferSize {
202- if let Ok ( min_buffer_size) = AudioManager :: get_frames_per_buffer ( ) {
203- SupportedBufferSize :: Range {
204- min : min_buffer_size as u32 ,
205- max : i32:: MAX as u32 ,
206- }
207- } else {
208- SupportedBufferSize :: Unknown
202+ SupportedBufferSize :: Range {
203+ min : 1 ,
204+ max : i32:: MAX as FrameCount ,
209205 }
210206}
211207
@@ -296,8 +292,8 @@ fn configure_for_device(
296292 if let BufferSize :: Fixed ( size) = config. buffer_size {
297293 // For fixed sizes, the user explicitly wants control over the callback size.
298294 builder = builder
299- . frames_per_data_callback ( size as i32 )
300- . buffer_capacity_in_frames ( 2 * size as i32 ) ;
295+ . frames_per_data_callback ( size. min ( i32 :: MAX as FrameCount ) as i32 )
296+ . buffer_capacity_in_frames ( size . saturating_mul ( 2 ) . min ( i32 :: MAX as FrameCount ) as i32 ) ;
301297 }
302298
303299 builder
@@ -317,12 +313,13 @@ where
317313{
318314 let builder = configure_for_device ( builder, device, config) ;
319315 let channel_count = config. channels as i32 ;
316+ let sample_rate = config. sample_rate ;
320317 let stream = builder
321318 . data_callback ( Box :: new ( move |stream, data, num_frames| {
322319 let cb_info = InputCallbackInfo {
323320 timestamp : InputStreamTimestamp {
324321 callback : now_stream_instant ( ) ,
325- capture : stream_instant ( stream) ,
322+ capture : input_stream_instant ( stream, sample_rate ) ,
326323 } ,
327324 } ;
328325 ( data_callback) (
@@ -366,6 +363,7 @@ where
366363{
367364 let builder = configure_for_device ( builder, device, config) ;
368365 let channel_count = config. channels as i32 ;
366+ let sample_rate = config. sample_rate ;
369367 let tune_dynamically = config. buffer_size == BufferSize :: Default ;
370368
371369 let tuning = Arc :: new ( BufferTuningState :: default ( ) ) ;
@@ -377,7 +375,7 @@ where
377375 let cb_info = OutputCallbackInfo {
378376 timestamp : OutputStreamTimestamp {
379377 callback : now_stream_instant ( ) ,
380- playback : stream_instant ( stream) ,
378+ playback : output_stream_instant ( stream, sample_rate ) ,
381379 } ,
382380 } ;
383381 ( data_callback) (
0 commit comments