From ee8ee2f10366f760f238b13165ebfc0175141773 Mon Sep 17 00:00:00 2001 From: henrika Date: Thu, 26 Sep 2019 16:00:58 +0200 Subject: [PATCH] Avoids update of WebRTC.Audio.SourceMatchesRecordingSession for Android < N Before this change we always logged false in WebRTC.Audio.SourceMatchesRecordingSession even when a test had not been executed (happens e.g. for Android < N). This issue is now fixed and we only update WebRTC.Audio.SourceMatchesRecordingSession if a valid test has been performed. No-Try: True TBR: glaznev Bug: webrtc:10971 Change-Id: I907197476f00b812c67bb71e8fdcd6f297cfbdee Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/154563 Commit-Queue: Henrik Andreassson Reviewed-by: Henrik Andreassson Cr-Commit-Position: refs/heads/master@{#29324} --- .../org/webrtc/audio/WebRtcAudioRecord.java | 15 +++++++++++---- .../src/jni/audio_device/audio_record_jni.cc | 18 +++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/sdk/android/src/java/org/webrtc/audio/WebRtcAudioRecord.java b/sdk/android/src/java/org/webrtc/audio/WebRtcAudioRecord.java index 8136bca0f8..42570d80e4 100644 --- a/sdk/android/src/java/org/webrtc/audio/WebRtcAudioRecord.java +++ b/sdk/android/src/java/org/webrtc/audio/WebRtcAudioRecord.java @@ -93,7 +93,7 @@ class WebRtcAudioRecord { private volatile boolean microphoneMute; private boolean audioSourceMatchesRecordingSession; - private boolean audioConfigHasBeenVerified; + private boolean isAudioConfigVerified; private byte[] emptyBytes; private final @Nullable AudioRecordErrorCallback errorCallback; @@ -221,13 +221,20 @@ class WebRtcAudioRecord { return isNoiseSuppressorSupported; } + // Returns true if a valid call to verifyAudioConfig() has been done. Should always be + // checked before using the returned value of isAudioSourceMatchingRecordingSession(). @CalledByNative + boolean isAudioConfigVerified() { + return isAudioConfigVerified; + } + // Returns true if verifyAudioConfig() succeeds. This value is set after a specific delay when // startRecording() has been called. Hence, should preferably be called in combination with - // stopRecording() to ensure that it has been set properly. |audioConfigHasBeenChecked| is + // stopRecording() to ensure that it has been set properly. |isAudioConfigVerified| is // enabled in WebRtcAudioRecord to ensure that the returned value is valid. + @CalledByNative boolean isAudioSourceMatchingRecordingSession() { - if (!audioConfigHasBeenVerified) { + if (!isAudioConfigVerified) { Logging.w(TAG, "Audio configuration has not yet been verified"); return false; } @@ -434,7 +441,7 @@ class WebRtcAudioRecord { audioSourceMatchesRecordingSession = verifyAudioConfig(audioRecord.getAudioSource(), audioRecord.getAudioSessionId(), audioRecord.getFormat(), audioRecord.getRoutedDevice(), configs); - audioConfigHasBeenVerified = true; + isAudioConfigVerified = true; } } return numActiveRecordingSessions; diff --git a/sdk/android/src/jni/audio_device/audio_record_jni.cc b/sdk/android/src/jni/audio_device/audio_record_jni.cc index 5e39be9f6d..15c290c2ee 100644 --- a/sdk/android/src/jni/audio_device/audio_record_jni.cc +++ b/sdk/android/src/jni/audio_device/audio_record_jni.cc @@ -158,13 +158,17 @@ int32_t AudioRecordJni::StopRecording() { if (!initialized_ || !recording_) { return 0; } - const bool session_was_ok = - Java_WebRtcAudioRecord_isAudioSourceMatchingRecordingSession( - env_, j_audio_record_); - RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.SourceMatchesRecordingSession", - session_was_ok); - RTC_LOG(INFO) << "HISTOGRAM(WebRTC.Audio.SourceMatchesRecordingSession): " - << session_was_ok; + // Check if the audio source matched the activated recording session but only + // if a valid results exists to avoid invalid statistics. + if (Java_WebRtcAudioRecord_isAudioConfigVerified(env_, j_audio_record_)) { + const bool session_was_ok = + Java_WebRtcAudioRecord_isAudioSourceMatchingRecordingSession( + env_, j_audio_record_); + RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.SourceMatchesRecordingSession", + session_was_ok); + RTC_LOG(INFO) << "HISTOGRAM(WebRTC.Audio.SourceMatchesRecordingSession): " + << session_was_ok; + } if (!Java_WebRtcAudioRecord_stopRecording(env_, j_audio_record_)) { RTC_LOG(LS_ERROR) << "StopRecording failed"; return -1;