Adds periodic volume-level logging for Android.
The goal of this change is to log the volume level for the current audio stream so we can keep track of what volume the user selects during a call. BUG=b/30376577 R=magjed@webrtc.org Review URL: https://codereview.webrtc.org/2182043005 . Cr-Commit-Position: refs/heads/master@{#13555}
This commit is contained in:
parent
a0db81f83a
commit
c62ff86023
@ -22,6 +22,8 @@ import android.os.Build;
|
|||||||
import org.webrtc.Logging;
|
import org.webrtc.Logging;
|
||||||
|
|
||||||
import java.lang.Math;
|
import java.lang.Math;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
// WebRtcAudioManager handles tasks that uses android.media.AudioManager.
|
// WebRtcAudioManager handles tasks that uses android.media.AudioManager.
|
||||||
// At construction, storeAudioParameters() is called and it retrieves
|
// At construction, storeAudioParameters() is called and it retrieves
|
||||||
@ -32,8 +34,6 @@ import java.lang.Math;
|
|||||||
// dispose(). This class can also be used without calling init() if the user
|
// dispose(). This class can also be used without calling init() if the user
|
||||||
// prefers to set up the audio environment separately. However, it is
|
// prefers to set up the audio environment separately. However, it is
|
||||||
// recommended to always use AudioManager.MODE_IN_COMMUNICATION.
|
// recommended to always use AudioManager.MODE_IN_COMMUNICATION.
|
||||||
// This class also adds support for output volume control of the
|
|
||||||
// STREAM_VOICE_CALL-type stream.
|
|
||||||
public class WebRtcAudioManager {
|
public class WebRtcAudioManager {
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
@ -69,6 +69,62 @@ public class WebRtcAudioManager {
|
|||||||
"MODE_IN_COMMUNICATION",
|
"MODE_IN_COMMUNICATION",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Private utility class that periodically checks and logs the volume level
|
||||||
|
// of the audio stream that is currently controlled by the volume control.
|
||||||
|
// A timer triggers logs once every 10 seconds and the timer's associated
|
||||||
|
// thread is named "WebRtcVolumeLevelLoggerThread".
|
||||||
|
private static class VolumeLogger {
|
||||||
|
private static final String THREAD_NAME = "WebRtcVolumeLevelLoggerThread";
|
||||||
|
private static final int TIMER_PERIOD_IN_SECONDS = 10;
|
||||||
|
|
||||||
|
private final AudioManager audioManager;
|
||||||
|
private Timer timer;
|
||||||
|
|
||||||
|
public VolumeLogger(AudioManager audioManager) {
|
||||||
|
this.audioManager = audioManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
timer = new Timer(THREAD_NAME);
|
||||||
|
timer.schedule(new LogVolumeTask(
|
||||||
|
audioManager.getStreamMaxVolume(AudioManager.STREAM_RING),
|
||||||
|
audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL)),
|
||||||
|
0, TIMER_PERIOD_IN_SECONDS * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class LogVolumeTask extends TimerTask {
|
||||||
|
private final int maxRingVolume;
|
||||||
|
private final int maxVoiceCallVolume;
|
||||||
|
|
||||||
|
LogVolumeTask(int maxRingVolume, int maxVoiceCallVolume) {
|
||||||
|
this.maxRingVolume = maxRingVolume;
|
||||||
|
this.maxVoiceCallVolume = maxVoiceCallVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
final int mode = audioManager.getMode();
|
||||||
|
if (mode == AudioManager.MODE_RINGTONE) {
|
||||||
|
Logging.d(TAG, "STREAM_RING stream volume: "
|
||||||
|
+ audioManager.getStreamVolume(AudioManager.STREAM_RING)
|
||||||
|
+ " (max=" + maxRingVolume + ")");
|
||||||
|
} else if (mode == AudioManager.MODE_IN_COMMUNICATION) {
|
||||||
|
Logging.d(TAG, "VOICE_CALL stream volume: "
|
||||||
|
+ audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)
|
||||||
|
+ " (max=" + maxVoiceCallVolume + ")");
|
||||||
|
} else {
|
||||||
|
Logging.w(TAG, "Invalid audio mode: " + AUDIO_MODES[mode]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stop() {
|
||||||
|
if (timer != null) {
|
||||||
|
timer.cancel();
|
||||||
|
timer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final long nativeAudioManager;
|
private final long nativeAudioManager;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final AudioManager audioManager;
|
private final AudioManager audioManager;
|
||||||
@ -87,6 +143,8 @@ public class WebRtcAudioManager {
|
|||||||
private int outputBufferSize;
|
private int outputBufferSize;
|
||||||
private int inputBufferSize;
|
private int inputBufferSize;
|
||||||
|
|
||||||
|
private final VolumeLogger volumeLogger;
|
||||||
|
|
||||||
WebRtcAudioManager(Context context, long nativeAudioManager) {
|
WebRtcAudioManager(Context context, long nativeAudioManager) {
|
||||||
Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo());
|
Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo());
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -96,6 +154,7 @@ public class WebRtcAudioManager {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
WebRtcAudioUtils.logDeviceInfo(TAG);
|
WebRtcAudioUtils.logDeviceInfo(TAG);
|
||||||
}
|
}
|
||||||
|
volumeLogger = new VolumeLogger(audioManager);
|
||||||
storeAudioParameters();
|
storeAudioParameters();
|
||||||
nativeCacheAudioParameters(
|
nativeCacheAudioParameters(
|
||||||
sampleRate, channels, hardwareAEC, hardwareAGC, hardwareNS,
|
sampleRate, channels, hardwareAEC, hardwareAGC, hardwareNS,
|
||||||
@ -110,6 +169,7 @@ public class WebRtcAudioManager {
|
|||||||
}
|
}
|
||||||
Logging.d(TAG, "audio mode is: " + AUDIO_MODES[audioManager.getMode()]);
|
Logging.d(TAG, "audio mode is: " + AUDIO_MODES[audioManager.getMode()]);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
volumeLogger.start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +178,7 @@ public class WebRtcAudioManager {
|
|||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
volumeLogger.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCommunicationModeEnabled() {
|
private boolean isCommunicationModeEnabled() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user