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

Commit 98d4ca62 authored by Andy Hung's avatar Andy Hung
Browse files

Add channel index mask to AudioRecord

Change-Id: I5d2504d3a7af6611d3ffa9a4c2d3665a2cf97fef
parent 263b4c97
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -145,8 +145,7 @@ static sp<AudioRecord> setAudioRecord(JNIEnv* env, jobject thiz, const sp<AudioR
// ----------------------------------------------------------------------------
static jint
android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
        jobject jaa, jint sampleRateInHertz, jint channelMask,
                // Java channel masks map directly to the native definition
        jobject jaa, jint sampleRateInHertz, jint channelMask, jint channelIndexMask,
        jint audioFormat, jint buffSizeInBytes, jintArray jSession)
{
    //ALOGV(">> Entering android_media_AudioRecord_setup");
@@ -158,6 +157,15 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
        return (jint) AUDIO_JAVA_ERROR;
    }

    // channel index mask takes priority over channel position masks.
    if (channelIndexMask) {
        // Java channel index masks need the representation bits set.
        channelMask = audio_channel_mask_from_representation_and_bits(
                AUDIO_CHANNEL_REPRESENTATION_INDEX,
                channelIndexMask);
    }
    // Java channel position masks map directly to the native definition

    if (!audio_is_input_channel(channelMask)) {
        ALOGE("Error creating AudioRecord: channel mask %#x is not valid.", channelMask);
        return (jint) AUDIORECORD_ERROR_SETUP_INVALIDCHANNELMASK;
@@ -583,7 +591,7 @@ static JNINativeMethod gMethods[] = {
    // name,               signature,  funcPtr
    {"native_start",         "(II)I",    (void *)android_media_AudioRecord_start},
    {"native_stop",          "()V",    (void *)android_media_AudioRecord_stop},
    {"native_setup",         "(Ljava/lang/Object;Ljava/lang/Object;IIII[I)I",
    {"native_setup",         "(Ljava/lang/Object;Ljava/lang/Object;IIIII[I)I",
                                       (void *)android_media_AudioRecord_setup},
    {"native_finalize",      "()V",    (void *)android_media_AudioRecord_finalize},
    {"native_release",       "()V",    (void *)android_media_AudioRecord_release},
+19 −9
Original line number Diff line number Diff line
@@ -166,9 +166,13 @@ public class AudioRecord
     */
    private int mChannelCount;
    /**
     * The audio channel mask
     * The audio channel position mask
     */
    private int mChannelMask;
    /**
     * The audio channel index mask
     */
    private int mChannelIndexMask;
    /**
     * The encoding of the audio samples.
     * @see AudioFormat#ENCODING_PCM_8BIT
@@ -344,14 +348,19 @@ public class AudioRecord

        audioParamCheck(attributes.getCapturePreset(), rate, encoding);

        int channelMask = AudioFormat.CHANNEL_IN_DEFAULT;
        if ((format.getPropertySetMask()
                & AudioFormat.AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_MASK) != 0)
        {
            channelMask = format.getChannelMask();
                & AudioFormat.AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_INDEX_MASK) != 0) {
            mChannelIndexMask = format.getChannelIndexMask();
            mChannelCount = format.getChannelCount();
        }
        if ((format.getPropertySetMask()
                & AudioFormat.AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_MASK) != 0) {
            mChannelMask = getChannelMaskFromLegacyConfig(format.getChannelMask(), false);
            mChannelCount = format.getChannelCount();
        } else if (mChannelIndexMask == 0) {
            mChannelMask = getChannelMaskFromLegacyConfig(AudioFormat.CHANNEL_IN_DEFAULT, false);
            mChannelCount =  AudioFormat.channelCountFromInChannelMask(mChannelMask);
        }
        mChannelCount = AudioFormat.channelCountFromInChannelMask(channelMask);
        mChannelMask = getChannelMaskFromLegacyConfig(channelMask, false);

        audioBuffSizeCheck(bufferSizeInBytes);

@@ -360,7 +369,8 @@ public class AudioRecord
        //TODO: update native initialization when information about hardware init failure
        //      due to capture device already open is available.
        int initResult = native_setup( new WeakReference<AudioRecord>(this),
                mAudioAttributes, mSampleRate, mChannelMask, mAudioFormat, mNativeBufferSizeInBytes,
                mAudioAttributes, mSampleRate, mChannelMask, mChannelIndexMask,
                mAudioFormat, mNativeBufferSizeInBytes,
                session);
        if (initResult != SUCCESS) {
            loge("Error code "+initResult+" when initializing native AudioRecord object.");
@@ -1269,7 +1279,7 @@ public class AudioRecord

    private native final int native_setup(Object audiorecord_this,
            Object /*AudioAttributes*/ attributes,
            int sampleRate, int channelMask, int audioFormat,
            int sampleRate, int channelMask, int channelIndexMask, int audioFormat,
            int buffSizeInBytes, int[] sessionId);

    // TODO remove: implementation calls directly into implementation of native_release()