From 1021141d16a6afc0e6018c436c5340356a0bf1f0 Mon Sep 17 00:00:00 2001 From: Viktor Lazarev Date: Thu, 29 Aug 2019 08:29:48 +0200 Subject: [PATCH] Fix "build_input/output_stream_inner" methods --- src/host/wasapi/device.rs | 70 ++++++++++++++------------------------- 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/src/host/wasapi/device.rs b/src/host/wasapi/device.rs index d7e162f..1848bc9 100644 --- a/src/host/wasapi/device.rs +++ b/src/host/wasapi/device.rs @@ -626,7 +626,7 @@ impl Device { pub(crate) fn build_input_stream_inner( &self, format: &Format, - ) -> Result + ) -> Result { unsafe { // Making sure that COM is initialized. @@ -754,39 +754,28 @@ impl Device { &mut *capture_client }; - let new_stream_id = StreamId(self.next_stream_id.fetch_add(1, Ordering::Relaxed)); - if new_stream_id.0 == usize::max_value() { - return Err(BuildStreamError::StreamIdOverflow); - } - // Once we built the `StreamInner`, we add a command that will be picked up by the // `run()` method and added to the `RunContext`. - { - let client_flow = AudioClientFlow::Capture { - capture_client, - }; - let inner = StreamInner { - id: new_stream_id.clone(), - audio_client, - client_flow, - event, - playing: false, - max_frames_in_buffer, - bytes_per_frame: waveformatex.nBlockAlign, - sample_format: format.data_type, - }; - - self.push_command(Command::NewStream(inner)); + let client_flow = AudioClientFlow::Capture { + capture_client, }; - Ok(new_stream_id) + Ok( StreamInner { + audio_client, + client_flow, + event, + playing: false, + max_frames_in_buffer, + bytes_per_frame: waveformatex.nBlockAlign, + sample_format: format.data_type, + }) } } pub(crate) fn build_output_stream_inner( &self, format: &Format, - ) -> Result + ) -> Result { unsafe { // Making sure that COM is initialized. @@ -915,32 +904,21 @@ impl Device { &mut *render_client }; - let new_stream_id = StreamId(self.next_stream_id.fetch_add(1, Ordering::Relaxed)); - if new_stream_id.0 == usize::max_value() { - return Err(BuildStreamError::StreamIdOverflow); - } - // Once we built the `StreamInner`, we add a command that will be picked up by the // `run()` method and added to the `RunContext`. - { - let client_flow = AudioClientFlow::Render { - render_client, - }; - let inner = StreamInner { - id: new_stream_id.clone(), - audio_client, - client_flow, - event, - playing: false, - max_frames_in_buffer, - bytes_per_frame: waveformatex.nBlockAlign, - sample_format: format.data_type, - }; - - self.push_command(Command::NewStream(inner)); + let client_flow = AudioClientFlow::Render { + render_client, }; - Ok(new_stream_id) + Ok(StreamInner { + audio_client, + client_flow, + event, + playing: false, + max_frames_in_buffer, + bytes_per_frame: waveformatex.nBlockAlign, + sample_format: format.data_type, + }) } } }