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

Unified Diff: media/base/android/java/src/org/chromium/media/AudioRecordInput.java

Issue 99033003: Enable platform echo cancellation through the AudioRecord path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add PlatformEffects, unittests and clean up. Created 7 years 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: media/base/android/java/src/org/chromium/media/AudioRecordInput.java
diff --git a/media/base/android/java/src/org/chromium/media/AudioRecordInput.java b/media/base/android/java/src/org/chromium/media/AudioRecordInput.java
index 0752731f80200d6a13f1d0124da84a81d3d9e2ec..cf6273d21d5d85cee0619bd531a51450c4134efd 100644
--- a/media/base/android/java/src/org/chromium/media/AudioRecordInput.java
+++ b/media/base/android/java/src/org/chromium/media/AudioRecordInput.java
@@ -5,6 +5,9 @@
package org.chromium.media;
import android.content.Context;
+import android.media.audiofx.AcousticEchoCanceler;
+import android.media.audiofx.AudioEffect;
+import android.media.audiofx.AudioEffect.Descriptor;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder.AudioSource;
@@ -14,6 +17,7 @@ import java.nio.ByteBuffer;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
+import org.chromium.media.AudioManagerAndroid;
// Owned by its native counterpart declared in audio_record_input.h. Refer to
// that class for general comments.
@@ -30,9 +34,11 @@ class AudioRecordInput {
private final int mChannels;
private final int mBitsPerSample;
private final int mHardwareDelayBytes;
+ private final boolean mUsePlatformAEC;
private ByteBuffer mBuffer;
private AudioRecord mAudioRecord;
private AudioRecordThread mAudioRecordThread;
+ private AcousticEchoCanceler mAEC;
private class AudioRecordThread extends Thread {
// The "volatile" synchronization technique is discussed here:
@@ -88,28 +94,26 @@ class AudioRecordInput {
@CalledByNative
private static AudioRecordInput createAudioRecordInput(long nativeAudioRecordInputStream,
- int sampleRate, int channels, int bitsPerSample, int bytesPerBuffer) {
+ int sampleRate, int channels, int bitsPerSample, int bytesPerBuffer,
+ boolean usePlatformAEC) {
return new AudioRecordInput(nativeAudioRecordInputStream, sampleRate, channels,
- bitsPerSample, bytesPerBuffer);
+ bitsPerSample, bytesPerBuffer, usePlatformAEC);
}
private AudioRecordInput(long nativeAudioRecordInputStream, int sampleRate, int channels,
- int bitsPerSample, int bytesPerBuffer) {
+ int bitsPerSample, int bytesPerBuffer, boolean usePlatformAEC) {
mNativeAudioRecordInputStream = nativeAudioRecordInputStream;
mSampleRate = sampleRate;
mChannels = channels;
mBitsPerSample = bitsPerSample;
mHardwareDelayBytes = HARDWARE_DELAY_MS * sampleRate / 1000 * bitsPerSample / 8;
+ mUsePlatformAEC = usePlatformAEC;
// We use a direct buffer so that the native class can have access to
// the underlying memory address. This avoids the need to copy from a
// jbyteArray to native memory. More discussion of this here:
// http://developer.android.com/training/articles/perf-jni.html
- try {
- mBuffer = ByteBuffer.allocateDirect(bytesPerBuffer);
- } catch (IllegalArgumentException e) {
- Log.wtf(TAG, "allocateDirect failure", e);
- }
+ mBuffer = ByteBuffer.allocateDirect(bytesPerBuffer);
// Rather than passing the ByteBuffer with every OnData call (requiring
// the potentially expensive GetDirectBufferAddress) we simply have the
// the native class cache the address to the memory once.
@@ -170,6 +174,26 @@ class AudioRecordInput {
return false;
}
+ if (AcousticEchoCanceler.isAvailable()) {
+ mAEC = AcousticEchoCanceler.create(mAudioRecord.getAudioSessionId());
+ if (mAEC == null) {
+ Log.wtf(TAG, "AcousticEchoCanceler.create failed");
+ }
+ try {
+ Descriptor descriptor = mAEC.getDescriptor();
+ Log.d(TAG, "AcousticEchoCanceler " +
+ "name: " + descriptor.name + ", " +
+ "implementor: " + descriptor.implementor + ", " +
+ "uuid: " + descriptor.uuid);
+ } catch (IllegalStateException e) {
+ Log.w(TAG, "getDescriptor failed", e);
+ // Not fatal.
+ }
+ int ret = mAEC.setEnabled(mUsePlatformAEC);
+ if (ret != AudioEffect.SUCCESS) {
+ Log.wtf(TAG, "setEnabled error: " + ret);
+ }
+ }
return true;
}
@@ -207,6 +231,11 @@ class AudioRecordInput {
// open() was not called.
return;
}
+
+ if (mAEC != null) {
+ mAEC.release();
+ mAEC = null;
+ }
mAudioRecord.release();
mAudioRecord = null;
}

Powered by Google App Engine
This is Rietveld 408576698