@@ -71,6 +71,25 @@ void AudioState::SetPlayout(bool enabled) {
71
71
UpdateNullAudioPollerState ();
72
72
}
73
73
74
+ void AudioState::SetRecording (bool enabled) {
75
+ RTC_LOG (LS_INFO) << " SetRecording(" << enabled << " )" ;
76
+ RTC_DCHECK_RUN_ON (&thread_checker_);
77
+ auto * adm = config_.audio_device_module .get ();
78
+ if (enabled) {
79
+ if (ShouldRecord ()) {
80
+ if (!adm->Recording ()) {
81
+ if (adm->InitRecording () == 0 ) {
82
+ adm->StartRecording ();
83
+ }
84
+ }
85
+ }
86
+ } else {
87
+ // Disable recording.
88
+ adm->StopRecording ();
89
+ }
90
+ recording_enabled_ = enabled;
91
+ }
92
+
74
93
void AudioState::AddReceivingStream (
75
94
webrtc::AudioReceiveStreamInterface* stream) {
76
95
RTC_DCHECK_RUN_ON (&thread_checker_);
@@ -106,25 +125,6 @@ void AudioState::RemoveReceivingStream(
106
125
UpdateNullAudioPollerState ();
107
126
}
108
127
109
- void AudioState::SetRecording (bool enabled) {
110
- RTC_LOG (LS_INFO) << " SetRecording(" << enabled << " )" ;
111
- RTC_DCHECK_RUN_ON (&thread_checker_);
112
- auto * adm = config_.audio_device_module .get ();
113
- if (enabled) {
114
- if (!sending_streams_.empty ()) {
115
- if (!adm->Recording ()) {
116
- if (adm->InitRecording () == 0 ) {
117
- adm->StartRecording ();
118
- }
119
- }
120
- }
121
- } else {
122
- // Disable recording.
123
- adm->StopRecording ();
124
- }
125
- recording_enabled_ = enabled;
126
- }
127
-
128
128
void AudioState::AddSendingStream (webrtc::AudioSendStream* stream,
129
129
int sample_rate_hz,
130
130
size_t num_channels) {
@@ -135,13 +135,13 @@ 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_) {
140
- if (!adm-> Recording () ) {
141
- if (adm->InitRecording () == 0 ) {
142
- adm->StartRecording ();
143
- } else {
144
- RTC_DLOG_F (LS_ERROR) << " Failed to initialize recording. " ;
138
+ if ( ShouldRecord ()) {
139
+ auto * adm = config_. audio_device_module . get ();
140
+ if (recording_enabled_ ) {
141
+ if (! adm->Recording () ) {
142
+ if ( adm->InitRecording () == 0 ) {
143
+ adm-> StartRecording ();
144
+ }
145
145
}
146
146
}
147
147
}
@@ -152,7 +152,8 @@ void AudioState::RemoveSendingStream(webrtc::AudioSendStream* stream) {
152
152
auto count = sending_streams_.erase (stream);
153
153
RTC_DCHECK_EQ (1 , count);
154
154
UpdateAudioTransportWithSendingStreams ();
155
- if (sending_streams_.empty ()) {
155
+
156
+ if (!ShouldRecord ()) {
156
157
config_.audio_device_module ->StopRecording ();
157
158
}
158
159
}
@@ -208,6 +209,39 @@ void AudioState::UpdateNullAudioPollerState() {
208
209
null_audio_poller_.Stop ();
209
210
}
210
211
}
212
+
213
+ void AudioState::OnMuteStreamChanged () {
214
+
215
+ auto * adm = config_.audio_device_module .get ();
216
+ bool should_record = ShouldRecord ();
217
+
218
+ if (should_record && !adm->Recording ()) {
219
+ if (adm->InitRecording () == 0 ) {
220
+ adm->StartRecording ();
221
+ }
222
+ } else if (!should_record && adm->Recording ()) {
223
+ adm->StopRecording ();
224
+ }
225
+ }
226
+
227
+ bool AudioState::ShouldRecord () {
228
+ // no streams to send
229
+ if (sending_streams_.empty ()) {
230
+ return false ;
231
+ }
232
+
233
+ int stream_count = sending_streams_.size ();
234
+
235
+ int muted_count = 0 ;
236
+ for (const auto & kv : sending_streams_) {
237
+ if (kv.first ->GetMuted ()) {
238
+ muted_count++;
239
+ }
240
+ }
241
+
242
+ return muted_count != stream_count;
243
+ }
244
+
211
245
} // namespace internal
212
246
213
247
scoped_refptr<AudioState> AudioState::Create (const AudioState::Config& config) {
0 commit comments