Loading core/jni/android_media_AudioSystem.cpp +31 −20 Original line number Original line Diff line number Diff line Loading @@ -1127,6 +1127,7 @@ android_media_AudioSystem_listAudioPorts(JNIEnv *env, jobject clazz, jint *nGeneration; jint *nGeneration; struct audio_port *nPorts = NULL; struct audio_port *nPorts = NULL; int attempts = MAX_PORT_GENERATION_SYNC_ATTEMPTS; int attempts = MAX_PORT_GENERATION_SYNC_ATTEMPTS; jint jStatus; // get the port count and all the ports until they both return the same generation // get the port count and all the ports until they both return the same generation do { do { Loading @@ -1141,10 +1142,14 @@ android_media_AudioSystem_listAudioPorts(JNIEnv *env, jobject clazz, &numPorts, &numPorts, NULL, NULL, &generation1); &generation1); if (status != NO_ERROR || numPorts == 0) { if (status != NO_ERROR) { ALOGE_IF(status != NO_ERROR, "AudioSystem::listAudioPorts error %d", status); ALOGE_IF(status != NO_ERROR, "AudioSystem::listAudioPorts error %d", status); break; break; } } if (numPorts == 0) { jStatus = (jint)AUDIO_JAVA_SUCCESS; goto exit; } nPorts = (struct audio_port *)realloc(nPorts, numPorts * sizeof(struct audio_port)); nPorts = (struct audio_port *)realloc(nPorts, numPorts * sizeof(struct audio_port)); status = AudioSystem::listAudioPorts(AUDIO_PORT_ROLE_NONE, status = AudioSystem::listAudioPorts(AUDIO_PORT_ROLE_NONE, Loading @@ -1156,19 +1161,11 @@ android_media_AudioSystem_listAudioPorts(JNIEnv *env, jobject clazz, numPorts, generation, generation1); numPorts, generation, generation1); } while (generation1 != generation && status == NO_ERROR); } while (generation1 != generation && status == NO_ERROR); jint jStatus = nativeToJavaStatus(status); jStatus = nativeToJavaStatus(status); if (jStatus != AUDIO_JAVA_SUCCESS) { if (jStatus != AUDIO_JAVA_SUCCESS) { goto exit; goto exit; } } nGeneration = env->GetIntArrayElements(jGeneration, NULL); if (nGeneration == NULL) { jStatus = (jint)AUDIO_JAVA_ERROR; goto exit; } nGeneration[0] = generation1; env->ReleaseIntArrayElements(jGeneration, nGeneration, 0); for (size_t i = 0; i < numPorts; i++) { for (size_t i = 0; i < numPorts; i++) { jobject jAudioPort; jobject jAudioPort; jStatus = convertAudioPortFromNative(env, &jAudioPort, &nPorts[i]); jStatus = convertAudioPortFromNative(env, &jAudioPort, &nPorts[i]); Loading @@ -1179,6 +1176,13 @@ android_media_AudioSystem_listAudioPorts(JNIEnv *env, jobject clazz, } } exit: exit: nGeneration = env->GetIntArrayElements(jGeneration, NULL); if (nGeneration == NULL) { jStatus = (jint)AUDIO_JAVA_ERROR; } else { nGeneration[0] = generation1; env->ReleaseIntArrayElements(jGeneration, nGeneration, 0); } free(nPorts); free(nPorts); return jStatus; return jStatus; } } Loading Loading @@ -1354,6 +1358,7 @@ android_media_AudioSystem_listAudioPatches(JNIEnv *env, jobject clazz, jobject jSink = NULL; jobject jSink = NULL; jobject jPatch = NULL; jobject jPatch = NULL; int attempts = MAX_PORT_GENERATION_SYNC_ATTEMPTS; int attempts = MAX_PORT_GENERATION_SYNC_ATTEMPTS; jint jStatus; // get the patch count and all the patches until they both return the same generation // get the patch count and all the patches until they both return the same generation do { do { Loading @@ -1366,11 +1371,16 @@ android_media_AudioSystem_listAudioPatches(JNIEnv *env, jobject clazz, status = AudioSystem::listAudioPatches(&numPatches, status = AudioSystem::listAudioPatches(&numPatches, NULL, NULL, &generation1); &generation1); if (status != NO_ERROR || numPatches == 0) { if (status != NO_ERROR) { ALOGE_IF(status != NO_ERROR, "listAudioPatches AudioSystem::listAudioPatches error %d", ALOGE_IF(status != NO_ERROR, "listAudioPatches AudioSystem::listAudioPatches error %d", status); status); break; break; } } if (numPatches == 0) { jStatus = (jint)AUDIO_JAVA_SUCCESS; goto exit; } nPatches = (struct audio_patch *)realloc(nPatches, numPatches * sizeof(struct audio_patch)); nPatches = (struct audio_patch *)realloc(nPatches, numPatches * sizeof(struct audio_patch)); status = AudioSystem::listAudioPatches(&numPatches, status = AudioSystem::listAudioPatches(&numPatches, Loading @@ -1381,19 +1391,11 @@ android_media_AudioSystem_listAudioPatches(JNIEnv *env, jobject clazz, } while (generation1 != generation && status == NO_ERROR); } while (generation1 != generation && status == NO_ERROR); jint jStatus = nativeToJavaStatus(status); jStatus = nativeToJavaStatus(status); if (jStatus != AUDIO_JAVA_SUCCESS) { if (jStatus != AUDIO_JAVA_SUCCESS) { goto exit; goto exit; } } nGeneration = env->GetIntArrayElements(jGeneration, NULL); if (nGeneration == NULL) { jStatus = AUDIO_JAVA_ERROR; goto exit; } nGeneration[0] = generation1; env->ReleaseIntArrayElements(jGeneration, nGeneration, 0); for (size_t i = 0; i < numPatches; i++) { for (size_t i = 0; i < numPatches; i++) { jobject patchHandle = env->NewObject(gAudioHandleClass, gAudioHandleCstor, jobject patchHandle = env->NewObject(gAudioHandleClass, gAudioHandleCstor, nPatches[i].id); nPatches[i].id); Loading Loading @@ -1472,6 +1474,15 @@ android_media_AudioSystem_listAudioPatches(JNIEnv *env, jobject clazz, } } exit: exit: nGeneration = env->GetIntArrayElements(jGeneration, NULL); if (nGeneration == NULL) { jStatus = AUDIO_JAVA_ERROR; } else { nGeneration[0] = generation1; env->ReleaseIntArrayElements(jGeneration, nGeneration, 0); } if (jSources != NULL) { if (jSources != NULL) { env->DeleteLocalRef(jSources); env->DeleteLocalRef(jSources); } } Loading Loading
core/jni/android_media_AudioSystem.cpp +31 −20 Original line number Original line Diff line number Diff line Loading @@ -1127,6 +1127,7 @@ android_media_AudioSystem_listAudioPorts(JNIEnv *env, jobject clazz, jint *nGeneration; jint *nGeneration; struct audio_port *nPorts = NULL; struct audio_port *nPorts = NULL; int attempts = MAX_PORT_GENERATION_SYNC_ATTEMPTS; int attempts = MAX_PORT_GENERATION_SYNC_ATTEMPTS; jint jStatus; // get the port count and all the ports until they both return the same generation // get the port count and all the ports until they both return the same generation do { do { Loading @@ -1141,10 +1142,14 @@ android_media_AudioSystem_listAudioPorts(JNIEnv *env, jobject clazz, &numPorts, &numPorts, NULL, NULL, &generation1); &generation1); if (status != NO_ERROR || numPorts == 0) { if (status != NO_ERROR) { ALOGE_IF(status != NO_ERROR, "AudioSystem::listAudioPorts error %d", status); ALOGE_IF(status != NO_ERROR, "AudioSystem::listAudioPorts error %d", status); break; break; } } if (numPorts == 0) { jStatus = (jint)AUDIO_JAVA_SUCCESS; goto exit; } nPorts = (struct audio_port *)realloc(nPorts, numPorts * sizeof(struct audio_port)); nPorts = (struct audio_port *)realloc(nPorts, numPorts * sizeof(struct audio_port)); status = AudioSystem::listAudioPorts(AUDIO_PORT_ROLE_NONE, status = AudioSystem::listAudioPorts(AUDIO_PORT_ROLE_NONE, Loading @@ -1156,19 +1161,11 @@ android_media_AudioSystem_listAudioPorts(JNIEnv *env, jobject clazz, numPorts, generation, generation1); numPorts, generation, generation1); } while (generation1 != generation && status == NO_ERROR); } while (generation1 != generation && status == NO_ERROR); jint jStatus = nativeToJavaStatus(status); jStatus = nativeToJavaStatus(status); if (jStatus != AUDIO_JAVA_SUCCESS) { if (jStatus != AUDIO_JAVA_SUCCESS) { goto exit; goto exit; } } nGeneration = env->GetIntArrayElements(jGeneration, NULL); if (nGeneration == NULL) { jStatus = (jint)AUDIO_JAVA_ERROR; goto exit; } nGeneration[0] = generation1; env->ReleaseIntArrayElements(jGeneration, nGeneration, 0); for (size_t i = 0; i < numPorts; i++) { for (size_t i = 0; i < numPorts; i++) { jobject jAudioPort; jobject jAudioPort; jStatus = convertAudioPortFromNative(env, &jAudioPort, &nPorts[i]); jStatus = convertAudioPortFromNative(env, &jAudioPort, &nPorts[i]); Loading @@ -1179,6 +1176,13 @@ android_media_AudioSystem_listAudioPorts(JNIEnv *env, jobject clazz, } } exit: exit: nGeneration = env->GetIntArrayElements(jGeneration, NULL); if (nGeneration == NULL) { jStatus = (jint)AUDIO_JAVA_ERROR; } else { nGeneration[0] = generation1; env->ReleaseIntArrayElements(jGeneration, nGeneration, 0); } free(nPorts); free(nPorts); return jStatus; return jStatus; } } Loading Loading @@ -1354,6 +1358,7 @@ android_media_AudioSystem_listAudioPatches(JNIEnv *env, jobject clazz, jobject jSink = NULL; jobject jSink = NULL; jobject jPatch = NULL; jobject jPatch = NULL; int attempts = MAX_PORT_GENERATION_SYNC_ATTEMPTS; int attempts = MAX_PORT_GENERATION_SYNC_ATTEMPTS; jint jStatus; // get the patch count and all the patches until they both return the same generation // get the patch count and all the patches until they both return the same generation do { do { Loading @@ -1366,11 +1371,16 @@ android_media_AudioSystem_listAudioPatches(JNIEnv *env, jobject clazz, status = AudioSystem::listAudioPatches(&numPatches, status = AudioSystem::listAudioPatches(&numPatches, NULL, NULL, &generation1); &generation1); if (status != NO_ERROR || numPatches == 0) { if (status != NO_ERROR) { ALOGE_IF(status != NO_ERROR, "listAudioPatches AudioSystem::listAudioPatches error %d", ALOGE_IF(status != NO_ERROR, "listAudioPatches AudioSystem::listAudioPatches error %d", status); status); break; break; } } if (numPatches == 0) { jStatus = (jint)AUDIO_JAVA_SUCCESS; goto exit; } nPatches = (struct audio_patch *)realloc(nPatches, numPatches * sizeof(struct audio_patch)); nPatches = (struct audio_patch *)realloc(nPatches, numPatches * sizeof(struct audio_patch)); status = AudioSystem::listAudioPatches(&numPatches, status = AudioSystem::listAudioPatches(&numPatches, Loading @@ -1381,19 +1391,11 @@ android_media_AudioSystem_listAudioPatches(JNIEnv *env, jobject clazz, } while (generation1 != generation && status == NO_ERROR); } while (generation1 != generation && status == NO_ERROR); jint jStatus = nativeToJavaStatus(status); jStatus = nativeToJavaStatus(status); if (jStatus != AUDIO_JAVA_SUCCESS) { if (jStatus != AUDIO_JAVA_SUCCESS) { goto exit; goto exit; } } nGeneration = env->GetIntArrayElements(jGeneration, NULL); if (nGeneration == NULL) { jStatus = AUDIO_JAVA_ERROR; goto exit; } nGeneration[0] = generation1; env->ReleaseIntArrayElements(jGeneration, nGeneration, 0); for (size_t i = 0; i < numPatches; i++) { for (size_t i = 0; i < numPatches; i++) { jobject patchHandle = env->NewObject(gAudioHandleClass, gAudioHandleCstor, jobject patchHandle = env->NewObject(gAudioHandleClass, gAudioHandleCstor, nPatches[i].id); nPatches[i].id); Loading Loading @@ -1472,6 +1474,15 @@ android_media_AudioSystem_listAudioPatches(JNIEnv *env, jobject clazz, } } exit: exit: nGeneration = env->GetIntArrayElements(jGeneration, NULL); if (nGeneration == NULL) { jStatus = AUDIO_JAVA_ERROR; } else { nGeneration[0] = generation1; env->ReleaseIntArrayElements(jGeneration, nGeneration, 0); } if (jSources != NULL) { if (jSources != NULL) { env->DeleteLocalRef(jSources); env->DeleteLocalRef(jSources); } } Loading