
This CL adds a stand-alone Android AudioDeviceModule in the sdk/android folder. It's forked from modules/audio_device/android/ and then simplified for the Android case. The stand-alone Android ADM is available both in the native_api and also under a field trial in the Java API. Bug: webrtc:7452 Change-Id: If6e558026bd0ccb52f56d78ac833339a5789d300 Reviewed-on: https://webrtc-review.googlesource.com/60541 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22517}
98 lines
3.6 KiB
Java
98 lines
3.6 KiB
Java
/*
|
|
* Copyright 2018 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.audio;
|
|
|
|
import org.webrtc.audio.WebRtcAudioManager;
|
|
import org.webrtc.audio.WebRtcAudioRecord;
|
|
import org.webrtc.audio.WebRtcAudioTrack;
|
|
import org.webrtc.audio.WebRtcAudioUtils;
|
|
|
|
/**
|
|
* Public API for Java audio methods.
|
|
*
|
|
* <p>Note: This class is still under development and may change without notice.
|
|
*/
|
|
public class AudioDeviceModule {
|
|
public AudioDeviceModule() {}
|
|
|
|
/* AudioManager */
|
|
public static void setBlacklistDeviceForOpenSLESUsage(boolean enable) {
|
|
WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(enable);
|
|
}
|
|
|
|
public static void setStereoInput(boolean enable) {
|
|
WebRtcAudioManager.setStereoInput(enable);
|
|
}
|
|
|
|
/* AudioRecord */
|
|
// Audio recording error handler functions.
|
|
public enum AudioRecordStartErrorCode {
|
|
AUDIO_RECORD_START_EXCEPTION,
|
|
AUDIO_RECORD_START_STATE_MISMATCH,
|
|
}
|
|
|
|
public static interface AudioRecordErrorCallback {
|
|
void onWebRtcAudioRecordInitError(String errorMessage);
|
|
void onWebRtcAudioRecordStartError(AudioRecordStartErrorCode errorCode, String errorMessage);
|
|
void onWebRtcAudioRecordError(String errorMessage);
|
|
}
|
|
|
|
public static void setErrorCallback(AudioRecordErrorCallback errorCallback) {
|
|
WebRtcAudioRecord.setErrorCallback(errorCallback);
|
|
}
|
|
|
|
/* AudioTrack */
|
|
// Audio playout/track error handler functions.
|
|
public enum AudioTrackStartErrorCode {
|
|
AUDIO_TRACK_START_EXCEPTION,
|
|
AUDIO_TRACK_START_STATE_MISMATCH,
|
|
}
|
|
public static interface AudioTrackErrorCallback {
|
|
void onWebRtcAudioTrackInitError(String errorMessage);
|
|
void onWebRtcAudioTrackStartError(AudioTrackStartErrorCode errorCode, String errorMessage);
|
|
void onWebRtcAudioTrackError(String errorMessage);
|
|
}
|
|
|
|
public static void setErrorCallback(AudioTrackErrorCallback errorCallback) {
|
|
WebRtcAudioTrack.setErrorCallback(errorCallback);
|
|
}
|
|
|
|
/* AudioUtils */
|
|
public static void setWebRtcBasedAcousticEchoCanceler(boolean enable) {
|
|
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(enable);
|
|
}
|
|
|
|
public static void setWebRtcBasedNoiseSuppressor(boolean enable) {
|
|
WebRtcAudioUtils.setWebRtcBasedNoiseSuppressor(enable);
|
|
}
|
|
|
|
// Returns true if the device supports an audio effect (AEC or NS).
|
|
// Four conditions must be fulfilled if functions are to return true:
|
|
// 1) the platform must support the built-in (HW) effect,
|
|
// 2) explicit use (override) of a WebRTC based version must not be set,
|
|
// 3) the device must not be blacklisted for use of the effect, and
|
|
// 4) the UUID of the effect must be approved (some UUIDs can be excluded).
|
|
public static boolean isAcousticEchoCancelerSupported() {
|
|
return WebRtcAudioEffects.canUseAcousticEchoCanceler();
|
|
}
|
|
public static boolean isNoiseSuppressorSupported() {
|
|
return WebRtcAudioEffects.canUseNoiseSuppressor();
|
|
}
|
|
|
|
// Call this method if the default handling of querying the native sample
|
|
// rate shall be overridden. Can be useful on some devices where the
|
|
// available Android APIs are known to return invalid results.
|
|
// TODO(bugs.webrtc.org/8491): Remove NoSynchronizedMethodCheck suppression.
|
|
public static void setDefaultSampleRateHz(int sampleRateHz) {
|
|
WebRtcAudioUtils.setDefaultSampleRateHz(sampleRateHz);
|
|
}
|
|
}
|