Skip to content

Commit 616b69b

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 587ed38 commit 616b69b

File tree

9 files changed

+539
-507
lines changed

9 files changed

+539
-507
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: 21 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,25 @@ void AudioState::UpdateNullAudioPollerState() {
216215
null_audio_poller_.Stop();
217216
}
218217
}
218+
219+
bool AudioState::ShouldRecord() {
220+
// no streams to send
221+
if (sending_streams_.empty()) {
222+
return false;
223+
}
224+
225+
int stream_count = sending_streams_.size();
226+
227+
int muted_count = 0;
228+
for (const auto& kv : sending_streams_) {
229+
if (kv.first->GetMuted()) {
230+
muted_count++;
231+
}
232+
}
233+
234+
return muted_count != stream_count;
235+
}
236+
219237
} // namespace internal
220238

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

audio/audio_state.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class AudioState : public webrtc::AudioState {
6464
void UpdateAudioTransportWithSendingStreams();
6565
void UpdateNullAudioPollerState() RTC_RUN_ON(&thread_checker_);
6666

67+
// Returns true when at least 1 stream exists and all streams are not muted.
68+
bool ShouldRecord();
69+
6770
SequenceChecker thread_checker_;
6871
SequenceChecker process_thread_checker_{SequenceChecker::kDetached};
6972
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;

0 commit comments

Comments
 (0)