@@ -98,14 +98,26 @@ void AudioState::AddSendingStream(webrtc::AudioSendStream* stream,
98
98
UpdateAudioTransportWithSendingStreams ();
99
99
100
100
// Make sure recording is initialized; start recording if enabled.
101
- auto * adm = config_.audio_device_module .get ();
102
- if (!adm->Recording ()) {
103
- if (adm->InitRecording () == 0 ) {
104
- if (recording_enabled_) {
105
- adm->StartRecording ();
101
+ if (ShouldRecord ()) {
102
+ auto * adm = config_.audio_device_module .get ();
103
+ if (!adm->Recording ()) {
104
+ if (adm->InitRecording () == 0 ) {
105
+ if (recording_enabled_) {
106
+
107
+ // TODO: Verify if the following windows only logic is still required.
108
+ #if defined(WEBRTC_WIN)
109
+ if (adm->BuiltInAECIsAvailable () && !adm->Playing ()) {
110
+ if (!adm->PlayoutIsInitialized ()) {
111
+ adm->InitPlayout ();
112
+ }
113
+ adm->StartPlayout ();
114
+ }
115
+ #endif
116
+ adm->StartRecording ();
117
+ }
118
+ } else {
119
+ RTC_DLOG_F (LS_ERROR) << " Failed to initialize recording." ;
106
120
}
107
- } else {
108
- RTC_DLOG_F (LS_ERROR) << " Failed to initialize recording." ;
109
121
}
110
122
}
111
123
}
@@ -115,7 +127,8 @@ void AudioState::RemoveSendingStream(webrtc::AudioSendStream* stream) {
115
127
auto count = sending_streams_.erase (stream);
116
128
RTC_DCHECK_EQ (1 , count);
117
129
UpdateAudioTransportWithSendingStreams ();
118
- if (sending_streams_.empty ()) {
130
+
131
+ if (!ShouldRecord ()) {
119
132
config_.audio_device_module ->StopRecording ();
120
133
}
121
134
}
@@ -143,7 +156,7 @@ void AudioState::SetRecording(bool enabled) {
143
156
if (recording_enabled_ != enabled) {
144
157
recording_enabled_ = enabled;
145
158
if (enabled) {
146
- if (!sending_streams_. empty ()) {
159
+ if (ShouldRecord ()) {
147
160
config_.audio_device_module ->StartRecording ();
148
161
}
149
162
} else {
@@ -203,6 +216,39 @@ void AudioState::UpdateNullAudioPollerState() {
203
216
null_audio_poller_.Stop ();
204
217
}
205
218
}
219
+
220
+ void AudioState::OnMuteStreamChanged () {
221
+
222
+ auto * adm = config_.audio_device_module .get ();
223
+ bool should_record = ShouldRecord ();
224
+
225
+ if (should_record && !adm->Recording ()) {
226
+ if (adm->InitRecording () == 0 ) {
227
+ adm->StartRecording ();
228
+ }
229
+ } else if (!should_record && adm->Recording ()) {
230
+ adm->StopRecording ();
231
+ }
232
+ }
233
+
234
+ bool AudioState::ShouldRecord () {
235
+ // no streams to send
236
+ if (sending_streams_.empty ()) {
237
+ return false ;
238
+ }
239
+
240
+ int stream_count = sending_streams_.size ();
241
+
242
+ int muted_count = 0 ;
243
+ for (const auto & kv : sending_streams_) {
244
+ if (kv.first ->GetMuted ()) {
245
+ muted_count++;
246
+ }
247
+ }
248
+
249
+ return muted_count != stream_count;
250
+ }
251
+
206
252
} // namespace internal
207
253
208
254
rtc::scoped_refptr<AudioState> AudioState::Create (
0 commit comments