diff options
| author | 2019-01-17 21:34:34 +0000 | |
|---|---|---|
| committer | 2019-01-17 21:34:34 +0000 | |
| commit | 5955f741e474a1421c0c36fbdaec7facd2503e7a (patch) | |
| tree | 7ee35c3c4bad710ecc602ed8585a453a05d95548 | |
| parent | e68ca5d536daf445cc074bd12b69abccbe408d24 (diff) | |
| parent | 525b4cab9a4e45e1366b788ef3ece81cbaf5ddd8 (diff) | |
Merge "Adding Audio HAL V5: Direction API"
| -rw-r--r-- | core/jni/android_media_AudioRecord.cpp | 41 | ||||
| -rw-r--r-- | media/java/android/media/AudioRecord.java | 34 | ||||
| -rw-r--r-- | media/java/android/media/MicrophoneDirection.java | 62 |
3 files changed, 135 insertions, 2 deletions
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp index 12a8343b4a5c..67c306413bb2 100644 --- a/core/jni/android_media_AudioRecord.cpp +++ b/core/jni/android_media_AudioRecord.cpp @@ -841,6 +841,43 @@ static jint android_media_AudioRecord_get_active_microphones(JNIEnv *env, return jStatus; } +static int android_media_AudioRecord_set_microphone_direction(JNIEnv *env, jobject thiz, + jint direction) { + sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz); + if (lpRecorder == NULL) { + jniThrowException(env, "java/lang/IllegalStateException", + "Unable to retrieve AudioRecord pointer for setMicrophoneDirection()"); + return (jint)AUDIO_JAVA_ERROR; + } + + jint jStatus = AUDIO_JAVA_SUCCESS; + status_t status = + lpRecorder->setMicrophoneDirection(static_cast<audio_microphone_direction_t>(direction)); + if (status != NO_ERROR) { + jStatus = nativeToJavaStatus(status); + } + + return jStatus; +} + +static int android_media_AudioRecord_set_microphone_field_dimension(JNIEnv *env, jobject thiz, + jfloat zoom) { + sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz); + if (lpRecorder == NULL) { + jniThrowException(env, "java/lang/IllegalStateException", + "Unable to retrieve AudioRecord pointer for setMicrophoneFieldDimension()"); + return (jint)AUDIO_JAVA_ERROR; + } + + jint jStatus = AUDIO_JAVA_SUCCESS; + status_t status = lpRecorder->setMicrophoneFieldDimension(zoom); + if (status != NO_ERROR) { + jStatus = nativeToJavaStatus(status); + } + + return jStatus; +} + // ---------------------------------------------------------------------------- static jint android_media_AudioRecord_get_port_id(JNIEnv *env, jobject thiz) { sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz); @@ -896,6 +933,10 @@ static const JNINativeMethod gMethods[] = { {"native_get_active_microphones", "(Ljava/util/ArrayList;)I", (void *)android_media_AudioRecord_get_active_microphones}, {"native_getPortId", "()I", (void *)android_media_AudioRecord_get_port_id}, + {"native_set_microphone_direction", "(I)I", + (void *)android_media_AudioRecord_set_microphone_direction}, + {"native_set_microphone_field_dimension", "(F)I", + (void *)android_media_AudioRecord_set_microphone_field_dimension}, }; // field names found in android/media/AudioRecord.java diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java index 33f81f1db69c..92afe7ede8f2 100644 --- a/media/java/android/media/AudioRecord.java +++ b/media/java/android/media/AudioRecord.java @@ -61,7 +61,8 @@ import java.util.concurrent.Executor; * been read yet. Data should be read from the audio hardware in chunks of sizes inferior to * the total recording buffer size. */ -public class AudioRecord implements AudioRouting, AudioRecordingMonitor, AudioRecordingMonitorClient +public class AudioRecord implements AudioRouting, MicrophoneDirection, + AudioRecordingMonitor, AudioRecordingMonitorClient { //--------------------------------------------------------- // Constants @@ -1657,7 +1658,6 @@ public class AudioRecord implements AudioRouting, AudioRecordingMonitor, AudioRe return activeMicrophones; } - //-------------------------------------------------------------------------- // Implementation of AudioRecordingMonitor interface //-------------------- @@ -1707,6 +1707,33 @@ public class AudioRecord implements AudioRouting, AudioRecordingMonitor, AudioRe return native_getPortId(); } + //-------------------------------------------------------------------------- + // MicrophoneDirection + //-------------------- + /** + * Specifies the logical microphone (for processing). + * + * @param direction Direction constant (MicrophoneDirection.MIC_DIRECTION_*) + * @return retval OK if the call is successful, an error code otherwise. + * @hide + */ + public int setMicrophoneDirection(int direction) { + return native_set_microphone_direction(direction); + } + + /** + * Specifies the zoom factor (i.e. the field dimension) for the selected microphone + * (for processing). The selected microphone is determined by the use-case for the stream. + * + * @param zoom the desired field dimension of microphone capture. Range is from -1 (wide angle), + * though 0 (no zoom) to 1 (maximum zoom). + * @return retval OK if the call is successful, an error code otherwise. + * @hide + */ + public int setMicrophoneFieldDimension(float zoom) { + return native_set_microphone_field_dimension(zoom); + } + //--------------------------------------------------------- // Interface definitions //-------------------- @@ -1860,6 +1887,9 @@ public class AudioRecord implements AudioRouting, AudioRecordingMonitor, AudioRe private native int native_getPortId(); + private native int native_set_microphone_direction(int direction); + private native int native_set_microphone_field_dimension(float zoom); + //--------------------------------------------------------- // Utility methods //------------------ diff --git a/media/java/android/media/MicrophoneDirection.java b/media/java/android/media/MicrophoneDirection.java new file mode 100644 index 000000000000..99201c0279bf --- /dev/null +++ b/media/java/android/media/MicrophoneDirection.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + +/** + * @hide + */ +public interface MicrophoneDirection { + /** + * @hide + */ + int MIC_DIRECTION_UNSPECIFIED = 0; + + /** + * @hide + */ + int MIC_DIRECTION_FRONT = 1; + + /** + * @hide + */ + int MIC_DIRECTION_BACK = 2; + + /** + * @hide + */ + int MIC_DIRECTION_EXTERNAL = 3; + + /** + * Specifies the logical microphone (for processing). + * + * @param direction Direction constant (MicrophoneDirection.MIC_DIRECTION_*) + * @return retval OK if the call is successful, an error code otherwise. + * @hide + */ + int setMicrophoneDirection(int direction); + + /** + * Specifies the zoom factor (i.e. the field dimension) for the selected microphone + * (for processing). The selected microphone is determined by the use-case for the stream. + * + * @param zoom the desired field dimension of microphone capture. Range is from -1 (wide angle), + * though 0 (no zoom) to 1 (maximum zoom). + * @return retval OK if the call is successful, an error code otherwise. + * @hide + */ + int setMicrophoneFieldDimension(float zoom); +} |