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

Commit cb424d49 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move JNI init for OpenSLES audio routing to system startup."

parents 6a5df002 b3ae6d94
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1450,8 +1450,8 @@ static const RegJNIRec gRegJNI[] = {
    REG_JNI(register_android_hardware_UsbDeviceConnection),
    REG_JNI(register_android_hardware_UsbRequest),
    REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
    REG_JNI(register_android_media_AudioRecord),
    REG_JNI(register_android_media_AudioSystem),
    REG_JNI(register_android_media_AudioRecord),
    REG_JNI(register_android_media_AudioTrack),
    REG_JNI(register_android_media_JetPlayer),
    REG_JNI(register_android_media_MicrophoneInfo),
+44 −1
Original line number Diff line number Diff line
@@ -175,6 +175,17 @@ static struct {
    jmethodID postRecordConfigEventFromNative;
} gAudioPolicyEventHandlerMethods;

//
// JNI Initialization for OpenSLES routing
//
jmethodID gMidAudioTrackRoutingProxy_ctor;
jmethodID gMidAudioTrackRoutingProxy_release;
jmethodID gMidAudioRecordRoutingProxy_ctor;
jmethodID gMidAudioRecordRoutingProxy_release;

jclass gClsAudioTrackRoutingProxy;
jclass gClsAudioRecordRoutingProxy;

static Mutex gLock;

enum AudioError {
@@ -2017,6 +2028,10 @@ android_media_AudioSystem_setSurroundFormatEnabled(JNIEnv *env, jobject thiz,
    return (jint)nativeToJavaStatus(status);
}

static jint android_media_AudioSystem_get_FCC_8(JNIEnv *env, jobject thiz) {
    return FCC_8;
}

// ----------------------------------------------------------------------------

static const JNINativeMethod gMethods[] = {
@@ -2079,7 +2094,6 @@ static const JNINativeMethod gMethods[] = {
    {"setSurroundFormatEnabled", "(IZ)I", (void *)android_media_AudioSystem_setSurroundFormatEnabled},
};


static const JNINativeMethod gEventHandlerMethods[] = {
    {"native_setup",
        "(Ljava/lang/Object;)V",
@@ -2089,8 +2103,15 @@ static const JNINativeMethod gEventHandlerMethods[] = {
        (void *)android_media_AudioSystem_eventHandlerFinalize},
};

static const JNINativeMethod gGetFCC8Methods[] = {
    {"native_get_FCC_8", "()I", (void *)android_media_AudioSystem_get_FCC_8},
};

int register_android_media_AudioSystem(JNIEnv *env)
{
    // This needs to be done before hooking up methods AudioTrackRoutingProxy (below)
    RegisterMethodsOrDie(env, kClassPathName, gGetFCC8Methods, NELEM(gGetFCC8Methods));

    jclass arrayListClass = FindClassOrDie(env, "java/util/ArrayList");
    gArrayListClass = MakeGlobalRefOrDie(env, arrayListClass);
    gArrayListMethods.add = GetMethodIDOrDie(env, arrayListClass, "add", "(Ljava/lang/Object;)Z");
@@ -2247,6 +2268,28 @@ int register_android_media_AudioSystem(JNIEnv *env)
    gAudioAttributesFields.mFormattedTags = GetFieldIDOrDie(env,
            audioAttributesClass, "mFormattedTags", "Ljava/lang/String;");

    // AudioTrackRoutingProxy methods
    gClsAudioTrackRoutingProxy =
            android::FindClassOrDie(env, "android/media/AudioTrackRoutingProxy");
    // make sure this reference doesn't get deleted
    gClsAudioTrackRoutingProxy = (jclass)env->NewGlobalRef(gClsAudioTrackRoutingProxy);

    gMidAudioTrackRoutingProxy_ctor =
            android::GetMethodIDOrDie(env, gClsAudioTrackRoutingProxy, "<init>", "(J)V");
    gMidAudioTrackRoutingProxy_release =
            android::GetMethodIDOrDie(env, gClsAudioTrackRoutingProxy, "native_release", "()V");

    // AudioRecordRoutingProxy
    gClsAudioRecordRoutingProxy =
            android::FindClassOrDie(env, "android/media/AudioRecordRoutingProxy");
    // make sure this reference doesn't get deleted
    gClsAudioRecordRoutingProxy = (jclass)env->NewGlobalRef(gClsAudioRecordRoutingProxy);

    gMidAudioRecordRoutingProxy_ctor =
            android::GetMethodIDOrDie(env, gClsAudioRecordRoutingProxy, "<init>", "(J)V");
    gMidAudioRecordRoutingProxy_release =
            android::GetMethodIDOrDie(env, gClsAudioRecordRoutingProxy, "native_release", "()V");

    AudioSystem::setErrorCallback(android_media_AudioSystem_error_callback);

    RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
+0 −5
Original line number Diff line number Diff line
@@ -1226,10 +1226,6 @@ static void android_media_AudioTrack_disableDeviceCallback(
    pJniStorage->mDeviceCallback.clear();
}

static jint android_media_AudioTrack_get_FCC_8(JNIEnv *env, jobject thiz) {
    return FCC_8;
}

// Pass through the arguments to the AudioFlinger track implementation.
static jint android_media_AudioTrack_apply_volume_shaper(JNIEnv *env, jobject thiz,
        jobject jconfig, jobject joperation) {
@@ -1351,7 +1347,6 @@ static const JNINativeMethod gMethods[] = {
    {"native_getRoutedDeviceId", "()I", (void *)android_media_AudioTrack_getRoutedDeviceId},
    {"native_enableDeviceCallback", "()V", (void *)android_media_AudioTrack_enableDeviceCallback},
    {"native_disableDeviceCallback", "()V", (void *)android_media_AudioTrack_disableDeviceCallback},
    {"native_get_FCC_8",     "()I",      (void *)android_media_AudioTrack_get_FCC_8},
    {"native_applyVolumeShaper",
            "(Landroid/media/VolumeShaper$Configuration;Landroid/media/VolumeShaper$Operation;)I",
                                         (void *)android_media_AudioTrack_apply_volume_shaper},
+6 −0
Original line number Diff line number Diff line
@@ -75,6 +75,12 @@ public class AudioSystem
     */
    public static final int NUM_STREAMS = 5;

    /** Maximum value for AudioTrack channel count
     * @hide public for MediaCode only, do not un-hide or change to a numeric literal
     */
    public static final int OUT_CHANNEL_COUNT_MAX = native_get_FCC_8();
    private static native int native_get_FCC_8();

    // Expose only the getter method publicly so we can change it in the future
    private static final int NUM_STREAM_TYPES = 11;
    @UnsupportedAppUsage
+5 −10
Original line number Diff line number Diff line
@@ -93,11 +93,6 @@ public class AudioTrack extends PlayerBase
     */
    private static final float GAIN_MAX = 1.0f;

    /** Maximum value for AudioTrack channel count
     * @hide public for MediaCode only, do not un-hide or change to a numeric literal
     */
    public static final int CHANNEL_COUNT_MAX = native_get_FCC_8();

    /** indicates AudioTrack state is stopped */
    public static final int PLAYSTATE_STOPPED = 1;  // matches SL_PLAYSTATE_STOPPED
    /** indicates AudioTrack state is paused */
@@ -1001,7 +996,8 @@ public class AudioTrack extends PlayerBase
    }

    // mask of all the positional channels supported, however the allowed combinations
    // are further restricted by the matching left/right rule and CHANNEL_COUNT_MAX
    // are further restricted by the matching left/right rule and
    // AudioSystem.OUT_CHANNEL_COUNT_MAX
    private static final int SUPPORTED_OUT_CHANNELS =
            AudioFormat.CHANNEL_OUT_FRONT_LEFT |
            AudioFormat.CHANNEL_OUT_FRONT_RIGHT |
@@ -1124,7 +1120,7 @@ public class AudioTrack extends PlayerBase
        mChannelIndexMask = channelIndexMask;
        if (mChannelIndexMask != 0) {
            // restrictive: indexMask could allow up to AUDIO_CHANNEL_BITS_LOG2
            final int indexMask = (1 << CHANNEL_COUNT_MAX) - 1;
            final int indexMask = (1 << AudioSystem.OUT_CHANNEL_COUNT_MAX) - 1;
            if ((channelIndexMask & ~indexMask) != 0) {
                throw new IllegalArgumentException("Unsupported channel index configuration "
                        + channelIndexMask);
@@ -1169,9 +1165,9 @@ public class AudioTrack extends PlayerBase
            return false;
        }
        final int channelCount = AudioFormat.channelCountFromOutChannelMask(channelConfig);
        if (channelCount > CHANNEL_COUNT_MAX) {
        if (channelCount > AudioSystem.OUT_CHANNEL_COUNT_MAX) {
            loge("Channel configuration contains too many channels " +
                    channelCount + ">" + CHANNEL_COUNT_MAX);
                    channelCount + ">" + AudioSystem.OUT_CHANNEL_COUNT_MAX);
            return false;
        }
        // check for unsupported multichannel combinations:
@@ -3418,7 +3414,6 @@ public class AudioTrack extends PlayerBase
    private native final int native_getRoutedDeviceId();
    private native final void native_enableDeviceCallback();
    private native final void native_disableDeviceCallback();
    static private native int native_get_FCC_8();

    private native int native_applyVolumeShaper(
            @NonNull VolumeShaper.Configuration configuration,
Loading