Skip to content

Commit 7454824

Browse files
cloudwebrtchiroshihoriedavidzhaodavidliu
committed
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) Allow custom audio processing by exposing AudioProcessingModule (#85) Expose audio sample buffers for Android (#89) feat: add external audio processor for android. (#103) android: make audio output attributes modifiable (#118) Fix external audio processor sample rate calculation (#108) Expose remote audio sample buffers on RTCAudioTrack (#84) Fix memory leak when creating audio CMSampleBuffer #86 Co-authored-by: Hiroshi Horie <[email protected]> Co-authored-by: David Zhao <[email protected]> Co-authored-by: davidliu <[email protected]>
1 parent b6c65fc commit 7454824

File tree

71 files changed

+2946
-215
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2946
-215
lines changed

audio/audio_send_stream.cc

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

418+
bool AudioSendStream::GetMuted() {
419+
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
420+
return channel_send_->InputMute();
421+
}
422+
418423
webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const {
419424
return GetStats(true);
420425
}

audio/audio_send_stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class AudioSendStream final : public webrtc::AudioSendStream,
9494
int payload_frequency,
9595
int event,
9696
int duration_ms) override;
97+
bool GetMuted() override;
9798
void SetMuted(bool muted) override;
9899
webrtc::AudioSendStream::Stats GetStats() const override;
99100
webrtc::AudioSendStream::Stats GetStats(

audio/audio_state.cc

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,26 @@ void AudioState::AddSendingStream(webrtc::AudioSendStream* stream,
9898
UpdateAudioTransportWithSendingStreams();
9999

100100
// 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.";
106120
}
107-
} else {
108-
RTC_DLOG_F(LS_ERROR) << "Failed to initialize recording.";
109121
}
110122
}
111123
}
@@ -115,7 +127,8 @@ void AudioState::RemoveSendingStream(webrtc::AudioSendStream* stream) {
115127
auto count = sending_streams_.erase(stream);
116128
RTC_DCHECK_EQ(1, count);
117129
UpdateAudioTransportWithSendingStreams();
118-
if (sending_streams_.empty()) {
130+
131+
if (!ShouldRecord()) {
119132
config_.audio_device_module->StopRecording();
120133
}
121134
}
@@ -143,7 +156,7 @@ void AudioState::SetRecording(bool enabled) {
143156
if (recording_enabled_ != enabled) {
144157
recording_enabled_ = enabled;
145158
if (enabled) {
146-
if (!sending_streams_.empty()) {
159+
if (ShouldRecord()) {
147160
config_.audio_device_module->StartRecording();
148161
}
149162
} else {
@@ -203,6 +216,39 @@ void AudioState::UpdateNullAudioPollerState() {
203216
null_audio_poller_.Stop();
204217
}
205218
}
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+
206252
} // namespace internal
207253

208254
rtc::scoped_refptr<AudioState> AudioState::Create(

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
@@ -100,6 +100,8 @@ class ChannelSend : public ChannelSendInterface,
100100
// Muting, Volume and Level.
101101
void SetInputMute(bool enable) override;
102102

103+
bool InputMute() const override;
104+
103105
// Stats.
104106
ANAStats GetANAStatistics() const override;
105107

@@ -163,8 +165,6 @@ class ChannelSend : public ChannelSendInterface,
163165
size_t payloadSize,
164166
int64_t absolute_capture_timestamp_ms) override;
165167

166-
bool InputMute() const;
167-
168168
int32_t SendRtpAudio(AudioFrameType frameType,
169169
uint8_t payloadType,
170170
uint32_t rtp_timestamp_without_offset,

audio/channel_send.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class ChannelSendInterface {
8383
virtual bool SendTelephoneEventOutband(int event, int duration_ms) = 0;
8484
virtual void OnBitrateAllocation(BitrateAllocationUpdate update) = 0;
8585
virtual int GetTargetBitrate() const = 0;
86+
87+
virtual bool InputMute() const = 0;
8688
virtual void SetInputMute(bool muted) = 0;
8789

8890
virtual void ProcessAndEncodeAudio(

call/audio_send_stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class AudioSendStream : public AudioSender {
190190
int event,
191191
int duration_ms) = 0;
192192

193+
virtual bool GetMuted() = 0;
193194
virtual void SetMuted(bool muted) = 0;
194195

195196
virtual Stats GetStats() const = 0;

call/audio_state.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class AudioState : public rtc::RefCountInterface {
5959

6060
virtual void SetStereoChannelSwapping(bool enable) = 0;
6161

62+
// Notify the AudioState that a stream updated it's mute state.
63+
virtual void OnMuteStreamChanged() = 0;
64+
6265
static rtc::scoped_refptr<AudioState> Create(
6366
const AudioState::Config& config);
6467

media/engine/webrtc_voice_engine.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class WebRtcVoiceEngine final : public VoiceEngineInterface {
132132

133133
absl::optional<webrtc::AudioDeviceModule::Stats> GetAudioDeviceStats()
134134
override;
135+
// Moved to public so WebRtcVoiceMediaChannel can access it.
136+
webrtc::AudioState* audio_state();
135137

136138
private:
137139
// Every option that is "set" will be applied. Every option not "set" will be
@@ -145,7 +147,6 @@ class WebRtcVoiceEngine final : public VoiceEngineInterface {
145147

146148
webrtc::AudioDeviceModule* adm();
147149
webrtc::AudioProcessing* apm() const;
148-
webrtc::AudioState* audio_state();
149150

150151
std::vector<AudioCodec> CollectCodecs(
151152
const std::vector<webrtc::AudioCodecSpec>& specs) const;

modules/audio_device/audio_device_data_observer.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ class ADMWrapper : public AudioDeviceModule, public AudioTransport {
307307
}
308308
#endif // WEBRTC_IOS
309309

310+
int32_t SetAudioDeviceSink(AudioDeviceSink* sink) const override {
311+
return impl_->SetAudioDeviceSink(sink);
312+
}
313+
310314
protected:
311315
rtc::scoped_refptr<AudioDeviceModule> impl_;
312316
AudioDeviceDataObserver* legacy_observer_ = nullptr;

0 commit comments

Comments
 (0)