aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioUtils.java
diff options
context:
space:
mode:
authorhenrika@webrtc.org <henrika@webrtc.org>2015-02-23 11:54:05 +0000
committerhenrika@webrtc.org <henrika@webrtc.org>2015-02-23 11:54:41 +0000
commit962c62475e31ccb5b1315bf646138652e273d0f5 (patch)
treeec61ea00e6fa11a02c00ec059262381b2f05afe1 /webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioUtils.java
parent2ad3bb17a7e0e83ae802ef62933325bce8041966 (diff)
downloadwebrtc-962c62475e31ccb5b1315bf646138652e273d0f5.tar.gz
Refactoring WebRTC Java/JNI audio track in C++ and Java.
This CL is part II in a major refactoring effort. See https://webrtc-codereview.appspot.com/33969004 for part I. - Removes unused code and old WEBRTC logging macros - Now uses optimal sample rate and buffer size in Java AudioTrack (used hard-coded sample rate before) - Makes code more inline with the implementation in Chrome - Adds helper methods for JNI handling to improve readability - Changes the threading model (high-prio audio thread now lives in Java-land and C++ only works as proxy) - Simplified the delay estimate - Adds basic thread checks - Removes all locks in C++ land - Removes all locks in Java - Improves construction/destruction - Additional cleanup Tested using AppRTCDemo and WebRTCDemo APKs on N6, N5, N7, Samsung Galaxy S4 and Samsung Galaxy S4 mini (which uses 44.1kHz as native sample rate). BUG=NONE R=magjed@webrtc.org, perkj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/39169004 Cr-Commit-Position: refs/heads/master@{#8460} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8460 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioUtils.java')
-rw-r--r--webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioUtils.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioUtils.java b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioUtils.java
new file mode 100644
index 0000000000..6821726ee6
--- /dev/null
+++ b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioUtils.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+package org.webrtc.voiceengine;
+
+import java.lang.Thread;
+
+import android.media.AudioManager;
+import android.os.Build;
+import android.util.Log;
+
+public final class WebRtcAudioUtils {
+ // Use 44.1kHz as the default sampling rate.
+ private static final int SAMPLE_RATE_HZ = 44100;
+
+ public static boolean runningOnJellyBeanOrHigher() {
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
+ }
+
+ public static boolean runningOnJellyBeanMR1OrHigher() {
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1;
+ }
+
+ /** Helper method for building a string of thread information.*/
+ public static String getThreadInfo() {
+ return "@[name=" + Thread.currentThread().getName()
+ + ", id=" + Thread.currentThread().getId() + "]";
+ }
+
+ /** Information about the current build, taken from system properties. */
+ public static void logDeviceInfo(String tag) {
+ Log.d(tag, "Android SDK: " + Build.VERSION.SDK_INT + ", "
+ + "Release: " + Build.VERSION.RELEASE + ", "
+ + "Brand: " + Build.BRAND + ", "
+ + "Device: " + Build.DEVICE + ", "
+ + "Id: " + Build.ID + ", "
+ + "Hardware: " + Build.HARDWARE + ", "
+ + "Manufacturer: " + Build.MANUFACTURER + ", "
+ + "Model: " + Build.MODEL + ", "
+ + "Product: " + Build.PRODUCT);
+ }
+
+ /**
+ * Returns the native or optimal output sample rate for this device's
+ * primary output stream. Unit is in Hz.
+ */
+ public static int GetNativeSampleRate(AudioManager audioManager) {
+ if (!WebRtcAudioUtils.runningOnJellyBeanMR1OrHigher()) {
+ return SAMPLE_RATE_HZ;
+ }
+ String sampleRateString = audioManager.getProperty(
+ AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
+ return (sampleRateString == null) ?
+ SAMPLE_RATE_HZ : Integer.parseInt(sampleRateString);
+ }
+}