@@ -76,6 +76,8 @@ impl System {
76
76
77
77
match handle. take ( ) . unwrap ( ) . join ( ) {
78
78
Ok ( Ok ( new_stream) ) => {
79
+ log:: info!( "Output stream active" ) ;
80
+
79
81
self . stream_state = StreamState :: Active ( new_stream) ;
80
82
self . shared . device_lost . store ( false , Ordering :: Relaxed ) ;
81
83
}
@@ -88,10 +90,13 @@ impl System {
88
90
Err ( panic_data) => {
89
91
log:: error!( "Panic during audio stream creation!" ) ;
90
92
self . stream_state = StreamState :: InitFailure ;
93
+ self . try_update_provider_config ( ) ;
91
94
92
95
std:: panic:: resume_unwind ( panic_data) ;
93
96
}
94
97
}
98
+
99
+ self . try_update_provider_config ( ) ;
95
100
}
96
101
97
102
StreamState :: InitFailure => { }
@@ -107,6 +112,8 @@ impl System {
107
112
108
113
if let Some ( mut provider) = provider. into ( ) {
109
114
let configuration = self . stream_state . as_active_stream ( ) . map ( |active_stream| active_stream. configuration ) ;
115
+
116
+ log:: info!( "Setting initial provider configuration: {configuration:?}" ) ;
110
117
provider. on_configuration_changed ( configuration) ;
111
118
112
119
* shared_provider = Some ( Box :: new ( provider) ) ;
@@ -117,6 +124,18 @@ impl System {
117
124
118
125
Ok ( ( ) )
119
126
}
127
+
128
+ fn try_update_provider_config ( & mut self ) {
129
+ if let Ok ( mut guard) = self . shared . provider . lock ( )
130
+ && let Some ( provider) = & mut * guard
131
+ {
132
+ let configuration = self . stream_state . as_active_stream ( )
133
+ . map ( |active_stream| active_stream. configuration ) ;
134
+
135
+ log:: info!( "Update provider configuration: {configuration:?}" ) ;
136
+ provider. on_configuration_changed ( configuration) ;
137
+ }
138
+ }
120
139
}
121
140
122
141
#[ derive( Debug , Copy , Clone ) ]
@@ -145,18 +164,7 @@ struct SharedState {
145
164
fn start_stream_build ( shared : Arc < SharedState > ) -> JoinHandle < anyhow:: Result < ActiveStream > > {
146
165
std:: thread:: spawn ( move || {
147
166
let host = cpal:: default_host ( ) ;
148
- let result = build_output_stream ( & host, shared. clone ( ) ) ;
149
-
150
- let new_configuration = result. as_ref ( ) . ok ( ) . map ( |stream| stream. configuration ) ;
151
-
152
- // If there's a provider, notify of the configuration change
153
- if let Ok ( mut guard) = shared. provider . lock ( )
154
- && let Some ( provider) = & mut * guard
155
- {
156
- provider. on_configuration_changed ( new_configuration) ;
157
- }
158
-
159
- result
167
+ build_output_stream ( & host, shared. clone ( ) )
160
168
} )
161
169
}
162
170
0 commit comments