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

Commit ec4097b0 authored by Paul McLean's avatar Paul McLean Committed by Android (Google) Code Review
Browse files

Merge "Explicit routing in AudioRecord"

parents 3acf4f5c 2d6de4c3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14933,6 +14933,7 @@ package android.media {
    method public int getNativeFrameCount() throws java.lang.IllegalStateException;
    method public int getNotificationMarkerPosition();
    method public int getPositionNotificationPeriod();
    method public android.media.AudioDeviceInfo getPreferredInputDevice();
    method public int getRecordingState();
    method public int getSampleRate();
    method public int getState();
@@ -14946,6 +14947,7 @@ package android.media {
    method public void release();
    method public int setNotificationMarkerPosition(int);
    method public int setPositionNotificationPeriod(int);
    method public boolean setPreferredInputDevice(android.media.AudioDeviceInfo);
    method public void setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener);
    method public void setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener, android.os.Handler);
    method public void startRecording() throws java.lang.IllegalStateException;
+2 −0
Original line number Diff line number Diff line
@@ -16144,6 +16144,7 @@ package android.media {
    method public int getNativeFrameCount() throws java.lang.IllegalStateException;
    method public int getNotificationMarkerPosition();
    method public int getPositionNotificationPeriod();
    method public android.media.AudioDeviceInfo getPreferredInputDevice();
    method public int getRecordingState();
    method public int getSampleRate();
    method public int getState();
@@ -16157,6 +16158,7 @@ package android.media {
    method public void release();
    method public int setNotificationMarkerPosition(int);
    method public int setPositionNotificationPeriod(int);
    method public boolean setPreferredInputDevice(android.media.AudioDeviceInfo);
    method public void setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener);
    method public void setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener, android.os.Handler);
    method public void startRecording() throws java.lang.IllegalStateException;
+8 −0
Original line number Diff line number Diff line
@@ -584,6 +584,13 @@ static jint android_media_AudioRecord_get_min_buff_size(JNIEnv *env, jobject th
    return frameCount * channelCount * audio_bytes_per_sample(format);
}

static jboolean android_media_AudioRecord_setInputDevice(
        JNIEnv *env,  jobject thiz, jint device_id) {

//    sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz);
//    return lpRecorder->setInputDevice(device_id) == NO_ERROR;
    return false;
}

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@@ -616,6 +623,7 @@ static JNINativeMethod gMethods[] = {
                             "()I",    (void *)android_media_AudioRecord_get_pos_update_period},
    {"native_get_min_buff_size",
                             "(III)I",   (void *)android_media_AudioRecord_get_min_buff_size},
    {"native_setInputDevice", "(I)Z", (void *)android_media_AudioRecord_setInputDevice},
};

// field names found in android/media/AudioRecord.java
+35 −0
Original line number Diff line number Diff line
@@ -1184,6 +1184,39 @@ public class AudioRecord
    }


    //--------------------------------------------------------------------------
    // Explicit Routing
    //--------------------
    private AudioDeviceInfo mPreferredDevice = null;

    /**
     * Specifies an audio device (via an {@link AudioDeviceInfo} object) to route
     * the input to this AudioRecord.
     * @param deviceSpec The {@link AudioDeviceInfo} specifying the audio source.
     *  If deviceSpec is null, default routing is restored.
     * @return true if successful, false if the specified {@link AudioDeviceInfo} is non-null and
     * does not correspond to a valid audio input device.
     */
    public boolean setPreferredInputDevice(AudioDeviceInfo deviceInfo) {
        // Do some validation....
        if (deviceInfo != null && !deviceInfo.isSource()) {
            return false;
        }

        mPreferredDevice = deviceInfo;
        int preferredDeviceId = mPreferredDevice != null ? deviceInfo.getId() : 0;

        return native_setInputDevice(preferredDeviceId);
    }

    /**
     * Returns the selected input specified by {@link #setPreferredInputDevice}. Note that this
     * is not guarenteed to correspond to the actual device being used for recording.
     */
    public AudioDeviceInfo getPreferredInputDevice() {
        return mPreferredDevice;
    }

    //---------------------------------------------------------
    // Interface definitions
    //--------------------
@@ -1314,6 +1347,8 @@ public class AudioRecord
    static private native final int native_get_min_buff_size(
            int sampleRateInHz, int channelCount, int audioFormat);

    private native final boolean native_setInputDevice(int deviceId);


    //---------------------------------------------------------
    // Utility methods
+8 −8
Original line number Diff line number Diff line
@@ -2082,28 +2082,28 @@ public class AudioTrack
    private AudioDeviceInfo mPreferredDevice = null;

    /**
     * Specifies an audio device (via and {@link AudioDeviceInfo} object) to route
     * Specifies an audio device (via an {@link AudioDeviceInfo} object) to route
     * the output from this AudioTrack.
     * @param deviceSpec The {@link AudioDeviceInfo} specifying the physical audio device.
     * @param deviceSpec The {@link AudioDeviceInfo} specifying the audio sink.
     *  If deviceSpec is null, default routing is restored.
     * @return true if succesful, false if the specified {@link AudioDeviceInfo} is non-null and
     * does not correspond to a valid audio output device.
     */
    public boolean setPreferredOutputDevice(AudioDeviceInfo deviceSpec) {
    public boolean setPreferredOutputDevice(AudioDeviceInfo deviceInfo) {
        // Do some validation....
        if (deviceSpec != null && !deviceSpec.isSink()) {
        if (deviceInfo != null && !deviceInfo.isSink()) {
            return false;
        }

        mPreferredDevice = deviceSpec;
        int routingDeviceId = mPreferredDevice != null ? deviceSpec.getId() : 0;
        mPreferredDevice = deviceInfo;
        int preferredDeviceId = mPreferredDevice != null ? deviceInfo.getId() : 0;

        return native_setOutputDevice(routingDeviceId);
        return native_setOutputDevice(preferredDeviceId);
    }

    /**
     * Returns the selected output specified by {@link #setPreferredOutputDevice}. Note that this
     * is not guarenteed to correspond to the actual device being used for playback.
     * is not guaranteed to correspond to the actual device being used for playback.
     */
    public AudioDeviceInfo getPreferredOutputDevice() {
        return mPreferredDevice;