Skip to content

Commit 53aa1dd

Browse files
kanatcloudwebrtchiroshihoriedavidzhao
authored andcommitted
Audio Device Optimization (#29)
* Audio Device Optimization allow listen-only mode in AudioUnit, adjust when category changes (#2) release mic when category changes (#5) Change defaults to iOS defaults (#7) Sync audio session config (#8) feat: support bypass voice processing for iOS. (#15) Remove MacBookPro audio pan right code (#22) fix: Fix can't open mic alone when built-in AEC is enabled. (#29) feat: add audio device changes detect for windows. (#41) fix Linux compile (#47) AudioUnit: Don't rely on category switch for mic indicator to turn off (#52) Stop recording on mute (turn off mic indicator) (#55) Cherry pick audio selection from m97 release (#35) [Mac] Allow audio device selection (#21) RTCAudioDeviceModule.outputDevice / inputDevice getter and setter (#80) Co-authored-by: Hiroshi Horie <[email protected]> Co-authored-by: David Zhao <[email protected]> * fix compilation errors --------- Co-authored-by: CloudWebRTC <[email protected]> Co-authored-by: Hiroshi Horie <[email protected]> Co-authored-by: David Zhao <[email protected]>
1 parent 716d9af commit 53aa1dd

File tree

10 files changed

+56
-6
lines changed

10 files changed

+56
-6
lines changed

audio/audio_send_stream.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ void AudioSendStream::SetMuted(bool muted) {
400400
channel_send_->SetInputMute(muted);
401401
}
402402

403+
bool AudioSendStream::GetMuted() {
404+
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
405+
return channel_send_->InputMute();
406+
}
407+
403408
webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const {
404409
return GetStats(true);
405410
}

audio/audio_send_stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class AudioSendStream final : public webrtc::AudioSendStream,
8888
int payload_frequency,
8989
int event,
9090
int duration_ms) override;
91+
bool GetMuted() override;
9192
void SetMuted(bool muted) override;
9293
webrtc::AudioSendStream::Stats GetStats() const override;
9394
webrtc::AudioSendStream::Stats GetStats(

audio/audio_state.cc

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ void AudioState::AddSendingStream(webrtc::AudioSendStream* stream,
149149
#endif
150150
adm->StartRecording();
151151
}
152-
} else {
153-
RTC_DLOG_F(LS_ERROR) << "Failed to initialize recording.";
154152
}
155153
}
156154
}
@@ -160,7 +158,8 @@ void AudioState::RemoveSendingStream(webrtc::AudioSendStream* stream) {
160158
auto count = sending_streams_.erase(stream);
161159
RTC_DCHECK_EQ(1, count);
162160
UpdateAudioTransportWithSendingStreams();
163-
if (sending_streams_.empty()) {
161+
162+
if (!ShouldRecord()) {
164163
config_.audio_device_module->StopRecording();
165164
}
166165
}
@@ -216,6 +215,39 @@ void AudioState::UpdateNullAudioPollerState() {
216215
null_audio_poller_.Stop();
217216
}
218217
}
218+
219+
void AudioState::OnMuteStreamChanged() {
220+
221+
auto* adm = config_.audio_device_module.get();
222+
bool should_record = ShouldRecord();
223+
224+
if (should_record && !adm->Recording()) {
225+
if (adm->InitRecording() == 0) {
226+
adm->StartRecording();
227+
}
228+
} else if (!should_record && adm->Recording()) {
229+
adm->StopRecording();
230+
}
231+
}
232+
233+
bool AudioState::ShouldRecord() {
234+
// no streams to send
235+
if (sending_streams_.empty()) {
236+
return false;
237+
}
238+
239+
int stream_count = sending_streams_.size();
240+
241+
int muted_count = 0;
242+
for (const auto& kv : sending_streams_) {
243+
if (kv.first->GetMuted()) {
244+
muted_count++;
245+
}
246+
}
247+
248+
return muted_count != stream_count;
249+
}
250+
219251
} // namespace internal
220252

221253
scoped_refptr<AudioState> AudioState::Create(const AudioState::Config& config) {

audio/audio_state.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class AudioState : public webrtc::AudioState {
4747

4848
void SetStereoChannelSwapping(bool enable) override;
4949

50+
void OnMuteStreamChanged() override;
51+
5052
AudioDeviceModule* audio_device_module() {
5153
RTC_DCHECK(config_.audio_device_module);
5254
return config_.audio_device_module.get();
@@ -64,6 +66,9 @@ class AudioState : public webrtc::AudioState {
6466
void UpdateAudioTransportWithSendingStreams();
6567
void UpdateNullAudioPollerState() RTC_RUN_ON(&thread_checker_);
6668

69+
// Returns true when at least 1 stream exists and all streams are not muted.
70+
bool ShouldRecord();
71+
6772
SequenceChecker thread_checker_;
6873
SequenceChecker process_thread_checker_{SequenceChecker::kDetached};
6974
const webrtc::AudioState::Config config_;

audio/channel_send.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class ChannelSend : public ChannelSendInterface,
163163
// Muting, Volume and Level.
164164
void SetInputMute(bool enable) override;
165165

166+
bool InputMute() const override;
167+
166168
// Stats.
167169
ANAStats GetANAStatistics() const override;
168170

@@ -235,8 +237,6 @@ class ChannelSend : public ChannelSendInterface,
235237
size_t payloadSize,
236238
int64_t absolute_capture_timestamp_ms) override;
237239

238-
bool InputMute() const;
239-
240240
int32_t SendRtpAudio(AudioFrameType frameType,
241241
uint8_t payloadType,
242242
uint32_t rtp_timestamp_without_offset,

audio/channel_send.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class ChannelSendInterface {
8989
virtual bool SendTelephoneEventOutband(int event, int duration_ms) = 0;
9090
virtual void OnBitrateAllocation(BitrateAllocationUpdate update) = 0;
9191
virtual int GetTargetBitrate() const = 0;
92+
93+
virtual bool InputMute() const = 0;
9294
virtual void SetInputMute(bool muted) = 0;
9395

9496
virtual void ProcessAndEncodeAudio(

call/audio_send_stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class AudioSendStream : public AudioSender {
193193
int event,
194194
int duration_ms) = 0;
195195

196+
virtual bool GetMuted() = 0;
196197
virtual void SetMuted(bool muted) = 0;
197198

198199
virtual Stats GetStats() const = 0;

media/engine/webrtc_voice_engine.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,9 @@ bool WebRtcVoiceSendChannel::MuteStream(uint32_t ssrc, bool muted) {
17571757
}
17581758
}
17591759

1760+
// Notify the AudioState that the mute state has updated.
1761+
engine_->audio_state()->OnMuteStreamChanged();
1762+
17601763
return true;
17611764
}
17621765

media/engine/webrtc_voice_engine.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ class WebRtcVoiceEngine final : public VoiceEngineInterface {
143143

144144
webrtc::AudioDeviceModule* adm();
145145
webrtc::AudioProcessing* apm() const;
146-
webrtc::AudioState* audio_state();
147146

148147
SequenceChecker signal_thread_checker_{SequenceChecker::kDetached};
149148
SequenceChecker worker_thread_checker_{SequenceChecker::kDetached};

sdk/objc/native/src/audio/audio_device_ios.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ class AudioDeviceIOS : public AudioDeviceGeneric,
286286

287287
bool recording_is_initialized_;
288288

289+
bool recording_is_initialized_;
290+
289291
// Set to 1 when recording is active and 0 otherwise.
290292
std::atomic<int> recording_;
291293

0 commit comments

Comments
 (0)