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

Commit 2d6de4c3 authored by Paul McLean's avatar Paul McLean
Browse files

Explicit routing in AudioRecord

Change-Id: Ib3af1041d9f7bbccefd6b86cd3c35baf742be861
parent 5b230c51
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14919,6 +14919,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();
@@ -14932,6 +14933,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
@@ -16129,6 +16129,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();
@@ -16142,6 +16143,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
@@ -576,6 +576,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;
}

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@@ -608,6 +615,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
@@ -1174,6 +1174,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
    //--------------------
@@ -1304,6 +1337,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
@@ -2028,28 +2028,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;