Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5955f741 authored by Paul Mclean's avatar Paul Mclean Committed by Android (Google) Code Review
Browse files

Merge "Adding Audio HAL V5: Direction API"

parents e68ca5d5 525b4cab
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -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
+32 −2
Original line number Diff line number Diff line
@@ -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
    //------------------
+62 −0
Original line number Diff line number Diff line
/*
 * 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);
}