@@ -135,11 +135,23 @@ void AudioState::AddSendingStream(webrtc::AudioSendStream* stream,
135
135
UpdateAudioTransportWithSendingStreams ();
136
136
137
137
// Make sure recording is initialized; start recording if enabled.
138
- auto * adm = config_. audio_device_module . get ();
139
- if (recording_enabled_) {
138
+ if ( ShouldRecord ()) {
139
+ auto * adm = config_. audio_device_module . get ();
140
140
if (!adm->Recording ()) {
141
141
if (adm->InitRecording () == 0 ) {
142
- adm->StartRecording ();
142
+ if (recording_enabled_) {
143
+
144
+ // TODO: Verify if the following windows only logic is still required.
145
+ #if defined(WEBRTC_WIN)
146
+ if (adm->BuiltInAECIsAvailable () && !adm->Playing ()) {
147
+ if (!adm->PlayoutIsInitialized ()) {
148
+ adm->InitPlayout ();
149
+ }
150
+ adm->StartPlayout ();
151
+ }
152
+ #endif
153
+ adm->StartRecording ();
154
+ }
143
155
} else {
144
156
RTC_DLOG_F (LS_ERROR) << " Failed to initialize recording." ;
145
157
}
@@ -152,7 +164,8 @@ void AudioState::RemoveSendingStream(webrtc::AudioSendStream* stream) {
152
164
auto count = sending_streams_.erase (stream);
153
165
RTC_DCHECK_EQ (1 , count);
154
166
UpdateAudioTransportWithSendingStreams ();
155
- if (sending_streams_.empty ()) {
167
+
168
+ if (!ShouldRecord ()) {
156
169
config_.audio_device_module ->StopRecording ();
157
170
}
158
171
}
@@ -208,6 +221,39 @@ void AudioState::UpdateNullAudioPollerState() {
208
221
null_audio_poller_.Stop ();
209
222
}
210
223
}
224
+
225
+ void AudioState::OnMuteStreamChanged () {
226
+
227
+ auto * adm = config_.audio_device_module .get ();
228
+ bool should_record = ShouldRecord ();
229
+
230
+ if (should_record && !adm->Recording ()) {
231
+ if (adm->InitRecording () == 0 ) {
232
+ adm->StartRecording ();
233
+ }
234
+ } else if (!should_record && adm->Recording ()) {
235
+ adm->StopRecording ();
236
+ }
237
+ }
238
+
239
+ bool AudioState::ShouldRecord () {
240
+ // no streams to send
241
+ if (sending_streams_.empty ()) {
242
+ return false ;
243
+ }
244
+
245
+ int stream_count = sending_streams_.size ();
246
+
247
+ int muted_count = 0 ;
248
+ for (const auto & kv : sending_streams_) {
249
+ if (kv.first ->GetMuted ()) {
250
+ muted_count++;
251
+ }
252
+ }
253
+
254
+ return muted_count != stream_count;
255
+ }
256
+
211
257
} // namespace internal
212
258
213
259
scoped_refptr<AudioState> AudioState::Create (const AudioState::Config& config) {
0 commit comments