Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java

Issue 1412673008: Introduces Android API level linting, fixes all current API lint errors. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Correcting xml paths Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java
diff --git a/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java
index 0602e44c2376ba0daa0359ed506d1ab67bab09fa..11eb51383d80730bf552adf543d5083c518f27ce 100644
--- a/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java
+++ b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java
@@ -13,6 +13,7 @@ package org.webrtc.voiceengine;
import java.lang.Thread;
import java.nio.ByteBuffer;
+import android.annotation.TargetApi;
import android.content.Context;
import android.media.AudioFormat;
import android.media.AudioManager;
@@ -90,13 +91,9 @@ class WebRtcAudioTrack {
assertTrue(sizeInBytes <= byteBuffer.remaining());
int bytesWritten = 0;
if (WebRtcAudioUtils.runningOnLollipopOrHigher()) {
- bytesWritten = audioTrack.write(byteBuffer,
- sizeInBytes,
- AudioTrack.WRITE_BLOCKING);
+ bytesWritten = writeOnLollipop(audioTrack, byteBuffer, sizeInBytes);
} else {
- bytesWritten = audioTrack.write(byteBuffer.array(),
- byteBuffer.arrayOffset(),
- sizeInBytes);
+ bytesWritten = writePreLollipop(audioTrack, byteBuffer, sizeInBytes);
}
if (bytesWritten != sizeInBytes) {
Logging.e(TAG, "AudioTrack.write failed: " + bytesWritten);
@@ -123,6 +120,15 @@ class WebRtcAudioTrack {
audioTrack.flush();
}
+ @TargetApi(21)
+ private int writeOnLollipop(AudioTrack audioTrack, ByteBuffer byteBuffer, int sizeInBytes) {
+ return audioTrack.write(byteBuffer, sizeInBytes, AudioTrack.WRITE_BLOCKING);
+ }
+
+ private int writePreLollipop(AudioTrack audioTrack, ByteBuffer byteBuffer, int sizeInBytes) {
+ return audioTrack.write(byteBuffer.array(), byteBuffer.arrayOffset(), sizeInBytes);
+ }
+
public void joinThread() {
keepAlive = false;
while (isAlive()) {
@@ -224,16 +230,21 @@ class WebRtcAudioTrack {
private boolean setStreamVolume(int volume) {
Logging.d(TAG, "setStreamVolume(" + volume + ")");
assertTrue(audioManager != null);
- if (WebRtcAudioUtils.runningOnLollipopOrHigher()) {
- if (audioManager.isVolumeFixed()) {
- Logging.e(TAG, "The device implements a fixed volume policy.");
- return false;
- }
+ if (isVolumeFixed()) {
+ Logging.e(TAG, "The device implements a fixed volume policy.");
+ return false;
}
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, volume, 0);
return true;
}
+ @TargetApi(21)
+ private boolean isVolumeFixed() {
+ if (!WebRtcAudioUtils.runningOnLollipopOrHigher())
+ return false;
+ return audioManager.isVolumeFixed();
+ }
+
/** Get current volume level for a phone call audio stream. */
private int getStreamVolume() {
Logging.d(TAG, "getStreamVolume");

Powered by Google App Engine
This is Rietveld 408576698