From a0e090ff5a2f2f5cfea874cc720e778412e81776 Mon Sep 17 00:00:00 2001 From: Ranveer Aggarwal Date: Thu, 4 Aug 2022 16:20:56 +0000 Subject: [PATCH] Added an API to disable VolumeLogger on Android. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib16c9e02fe18e1d6628f2192a21c53515753bcde Bug: webrtc:14321 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/270621 Reviewed-by: Xavier Lepaul‎ Commit-Queue: Xavier Lepaul‎ Cr-Commit-Position: refs/heads/main@{#37693} --- .../org/webrtc/audio/JavaAudioDeviceModule.java | 13 +++++++++++-- .../java/org/webrtc/audio/WebRtcAudioTrack.java | 15 ++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/sdk/android/api/org/webrtc/audio/JavaAudioDeviceModule.java b/sdk/android/api/org/webrtc/audio/JavaAudioDeviceModule.java index ae5858a704..d3d57602a8 100644 --- a/sdk/android/api/org/webrtc/audio/JavaAudioDeviceModule.java +++ b/sdk/android/api/org/webrtc/audio/JavaAudioDeviceModule.java @@ -50,6 +50,7 @@ public class JavaAudioDeviceModule implements AudioDeviceModule { private boolean useStereoOutput; private AudioAttributes audioAttributes; private boolean useLowLatency; + private boolean enableVolumeLogger; private Builder(Context context) { this.context = context; @@ -57,6 +58,7 @@ public class JavaAudioDeviceModule implements AudioDeviceModule { this.inputSampleRate = WebRtcAudioManager.getSampleRate(audioManager); this.outputSampleRate = WebRtcAudioManager.getSampleRate(audioManager); this.useLowLatency = false; + this.enableVolumeLogger = true; } public Builder setScheduler(ScheduledExecutorService scheduler) { @@ -213,6 +215,12 @@ public class JavaAudioDeviceModule implements AudioDeviceModule { return this; } + /** Disables the volume logger on the audio output track. */ + public Builder setEnableVolumeLogger(boolean enableVolumeLogger) { + this.enableVolumeLogger = enableVolumeLogger; + return this; + } + /** * Construct an AudioDeviceModule based on the supplied arguments. The caller takes ownership * and is responsible for calling release(). @@ -248,8 +256,9 @@ public class JavaAudioDeviceModule implements AudioDeviceModule { final WebRtcAudioRecord audioInput = new WebRtcAudioRecord(context, executor, audioManager, audioSource, audioFormat, audioRecordErrorCallback, audioRecordStateCallback, samplesReadyCallback, useHardwareAcousticEchoCanceler, useHardwareNoiseSuppressor); - final WebRtcAudioTrack audioOutput = new WebRtcAudioTrack(context, audioManager, - audioAttributes, audioTrackErrorCallback, audioTrackStateCallback, useLowLatency); + final WebRtcAudioTrack audioOutput = + new WebRtcAudioTrack(context, audioManager, audioAttributes, audioTrackErrorCallback, + audioTrackStateCallback, useLowLatency, enableVolumeLogger); return new JavaAudioDeviceModule(context, audioManager, audioInput, audioOutput, inputSampleRate, outputSampleRate, useStereoInput, useStereoOutput); } diff --git a/sdk/android/src/java/org/webrtc/audio/WebRtcAudioTrack.java b/sdk/android/src/java/org/webrtc/audio/WebRtcAudioTrack.java index f0cfd73caf..2b34e34013 100644 --- a/sdk/android/src/java/org/webrtc/audio/WebRtcAudioTrack.java +++ b/sdk/android/src/java/org/webrtc/audio/WebRtcAudioTrack.java @@ -154,19 +154,20 @@ class WebRtcAudioTrack { @CalledByNative WebRtcAudioTrack(Context context, AudioManager audioManager) { this(context, audioManager, null /* audioAttributes */, null /* errorCallback */, - null /* stateCallback */, false /* useLowLatency */); + null /* stateCallback */, false /* useLowLatency */, true /* enableVolumeLogger */); } WebRtcAudioTrack(Context context, AudioManager audioManager, @Nullable AudioAttributes audioAttributes, @Nullable AudioTrackErrorCallback errorCallback, - @Nullable AudioTrackStateCallback stateCallback, boolean useLowLatency) { + @Nullable AudioTrackStateCallback stateCallback, boolean useLowLatency, + boolean enableVolumeLogger) { threadChecker.detachThread(); this.context = context; this.audioManager = audioManager; this.audioAttributes = audioAttributes; this.errorCallback = errorCallback; this.stateCallback = stateCallback; - this.volumeLogger = new VolumeLogger(audioManager); + this.volumeLogger = enableVolumeLogger ? new VolumeLogger(audioManager) : null; this.useLowLatency = useLowLatency; Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo()); } @@ -266,7 +267,9 @@ class WebRtcAudioTrack { @CalledByNative private boolean startPlayout() { threadChecker.checkIsOnValidThread(); - volumeLogger.start(); + if (volumeLogger != null) { + volumeLogger.start(); + } Logging.d(TAG, "startPlayout"); assertTrue(audioTrack != null); assertTrue(audioThread == null); @@ -298,7 +301,9 @@ class WebRtcAudioTrack { @CalledByNative private boolean stopPlayout() { threadChecker.checkIsOnValidThread(); - volumeLogger.stop(); + if (volumeLogger != null) { + volumeLogger.stop(); + } Logging.d(TAG, "stopPlayout"); assertTrue(audioThread != null); logUnderrunCount();