1b3db213eb55acb661e4b9ea40bcc00af4b76fab9Glenn Kasten/* 29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** 39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** Copyright 2006, The Android Open Source Project 49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** 59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License"); 69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** you may not use this file except in compliance with the License. 79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** You may obtain a copy of the License at 89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** 99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** http://www.apache.org/licenses/LICENSE-2.0 109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** 119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** Unless required by applicable law or agreed to in writing, software 129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** distributed under the License is distributed on an "AS IS" BASIS, 139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** See the License for the specific language governing permissions and 159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project** limitations under the License. 169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project*/ 179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 183a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent//#define LOG_NDEBUG 0 193a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent 20b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent#define LOG_TAG "AudioSystem-JNI" 21c81d31c3f801ba3d559a22c27b926ace38a7ab49Glenn Kasten#include <utils/Log.h> 229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 23c81d31c3f801ba3d559a22c27b926ace38a7ab49Glenn Kasten#include <jni.h> 24c81d31c3f801ba3d559a22c27b926ace38a7ab49Glenn Kasten#include <JNIHelp.h> 25ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe#include "core_jni_helpers.h" 269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <media/AudioSystem.h> 287f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent#include <media/AudioPolicy.h> 299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3034bb419e5946ab28112e9e27a4d1b3928d31e0e2Dima Zavin#include <system/audio.h> 31290029d19a9d314e925b73e19453ab0497602f80Dima Zavin#include <system/audio_policy.h> 32b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent#include "android_media_AudioFormat.h" 33b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent#include "android_media_AudioErrors.h" 3424fc2fb1c541e954b83fd31ea9f786a5e9b45501Dima Zavin 359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// ---------------------------------------------------------------------------- 369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectusing namespace android; 389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 39ed0079ddddd4070f3369b13b274222da2e69f4b9Glenn Kastenstatic const char* const kClassPathName = "android/media/AudioSystem"; 40ed0079ddddd4070f3369b13b274222da2e69f4b9Glenn Kasten 41b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jclass gArrayListClass; 42b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic struct { 43b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jmethodID add; 447f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jmethodID toArray; 45b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} gArrayListMethods; 46b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 47b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jclass gAudioHandleClass; 48b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jmethodID gAudioHandleCstor; 49b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic struct { 50b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mId; 51b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} gAudioHandleFields; 52b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 53b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jclass gAudioPortClass; 54b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jmethodID gAudioPortCstor; 55b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic struct { 56b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mHandle; 57b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mRole; 58b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mGains; 59b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mActiveConfig; 60b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent // other fields unused by JNI 61b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} gAudioPortFields; 62b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 63b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jclass gAudioPortConfigClass; 64b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jmethodID gAudioPortConfigCstor; 65b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic struct { 66b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mPort; 67b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mSamplingRate; 68b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mChannelMask; 69b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mFormat; 70b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mGain; 713a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent jfieldID mConfigMask; 72b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} gAudioPortConfigFields; 73b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 74b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jclass gAudioDevicePortClass; 75b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jmethodID gAudioDevicePortCstor; 76b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 77b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jclass gAudioDevicePortConfigClass; 78b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jmethodID gAudioDevicePortConfigCstor; 79b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 80b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jclass gAudioMixPortClass; 81b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jmethodID gAudioMixPortCstor; 82b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 83b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jclass gAudioMixPortConfigClass; 84b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jmethodID gAudioMixPortConfigCstor; 85b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 86b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jclass gAudioGainClass; 87b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jmethodID gAudioGainCstor; 88b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 89b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jclass gAudioGainConfigClass; 90b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jmethodID gAudioGainConfigCstor; 91b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic struct { 92b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mIndex; 93b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mMode; 94b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mChannelMask; 95b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mValues; 96b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mRampDurationMs; 97b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent // other fields unused by JNI 98b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} gAudioGainConfigFields; 99b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 100b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jclass gAudioPatchClass; 101b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jmethodID gAudioPatchCstor; 102b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic struct { 103b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jfieldID mHandle; 104b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent // other fields unused by JNI 105b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} gAudioPatchFields; 106b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1077f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentstatic jclass gAudioMixClass; 1087f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentstatic struct { 1097f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mRule; 1107f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mFormat; 1117f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mRouteFlags; 1124ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi jfieldID mDeviceType; 1134ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi jfieldID mDeviceAddress; 1147f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mMixType; 1155a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi jfieldID mCallbackFlags; 1167f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent} gAudioMixFields; 1177f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 1187f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentstatic jclass gAudioFormatClass; 1197f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentstatic struct { 1207f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mEncoding; 1217f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mSampleRate; 1227f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mChannelMask; 1237f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent // other fields unused by JNI 1247f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent} gAudioFormatFields; 1257f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 1267f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentstatic jclass gAudioMixingRuleClass; 1277f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentstatic struct { 1287f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mCriteria; 1297f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent // other fields unused by JNI 1307f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent} gAudioMixingRuleFields; 1317f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 132ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivistatic jclass gAudioMixMatchCriterionClass; 1337f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentstatic struct { 1347f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mAttr; 135ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi jfieldID mIntProp; 1367f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mRule; 137ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi} gAudioMixMatchCriterionFields; 1387f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 1397f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentstatic jclass gAudioAttributesClass; 1407f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentstatic struct { 1417f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mUsage; 1427f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jfieldID mSource; 1437f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent} gAudioAttributesFields; 1447f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 1457f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 146700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentstatic const char* const kEventHandlerClassPathName = 147700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent "android/media/AudioPortEventHandler"; 1482615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurentstatic struct { 1492615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent jfieldID mJniCallback; 1502615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent} gEventHandlerFields; 1512615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurentstatic struct { 1522615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent jmethodID postEventFromNative; 1532615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent} gAudioPortEventHandlerMethods; 1542615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent 1555a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivistatic struct { 1565a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi jmethodID postDynPolicyEventFromNative; 157d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi jmethodID postRecordConfigEventFromNative; 158d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi} gAudioPolicyEventHandlerMethods; 1595a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi 1602615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurentstatic Mutex gLock; 161b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectenum AudioError { 1639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project kAudioStatusOk = 0, 1649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project kAudioStatusError = 1, 1659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project kAudioStatusMediaServerDied = 100 1669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}; 1679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 168700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentenum { 169700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent AUDIOPORT_EVENT_PORT_LIST_UPDATED = 1, 170700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent AUDIOPORT_EVENT_PATCH_LIST_UPDATED = 2, 171700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent AUDIOPORT_EVENT_SERVICE_DIED = 3, 172700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent}; 173700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 174b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent#define MAX_PORT_GENERATION_SYNC_ATTEMPTS 5 175b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 176700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent// ---------------------------------------------------------------------------- 1775a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi// ref-counted object for audio port callbacks 178700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentclass JNIAudioPortCallback: public AudioSystem::AudioPortCallback 179700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent{ 180700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentpublic: 181700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent JNIAudioPortCallback(JNIEnv* env, jobject thiz, jobject weak_thiz); 182700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent ~JNIAudioPortCallback(); 183700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 184700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent virtual void onAudioPortListUpdate(); 185700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent virtual void onAudioPatchListUpdate(); 186700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent virtual void onServiceDied(); 187700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 188700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentprivate: 189700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent void sendEvent(int event); 190700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 1912615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent jclass mClass; // Reference to AudioPortEventHandler class 1922615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent jobject mObject; // Weak ref to AudioPortEventHandler Java object to call on 193700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent}; 194700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 195700e73471d85348b52ecf213c36bb24b93997ec7Eric LaurentJNIAudioPortCallback::JNIAudioPortCallback(JNIEnv* env, jobject thiz, jobject weak_thiz) 196700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent{ 197700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 1982615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent // Hold onto the AudioPortEventHandler class for use in calling the static method 199700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent // that posts events to the application thread. 200700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent jclass clazz = env->GetObjectClass(thiz); 201700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent if (clazz == NULL) { 202700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent ALOGE("Can't find class %s", kEventHandlerClassPathName); 203700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent return; 204700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent } 205700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent mClass = (jclass)env->NewGlobalRef(clazz); 206700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 2072615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent // We use a weak reference so the AudioPortEventHandler object can be garbage collected. 208700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent // The reference is only used as a proxy for callbacks. 209700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent mObject = env->NewGlobalRef(weak_thiz); 210700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent} 211700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 212700e73471d85348b52ecf213c36bb24b93997ec7Eric LaurentJNIAudioPortCallback::~JNIAudioPortCallback() 213700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent{ 214700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent // remove global references 215700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent JNIEnv *env = AndroidRuntime::getJNIEnv(); 216449c5887101047d187a55217ced6d8a5c98fb367Eric Laurent if (env == NULL) { 217449c5887101047d187a55217ced6d8a5c98fb367Eric Laurent return; 218449c5887101047d187a55217ced6d8a5c98fb367Eric Laurent } 219700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent env->DeleteGlobalRef(mObject); 220700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent env->DeleteGlobalRef(mClass); 221700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent} 222700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 223700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentvoid JNIAudioPortCallback::sendEvent(int event) 224700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent{ 225700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent JNIEnv *env = AndroidRuntime::getJNIEnv(); 226449c5887101047d187a55217ced6d8a5c98fb367Eric Laurent if (env == NULL) { 227449c5887101047d187a55217ced6d8a5c98fb367Eric Laurent return; 228449c5887101047d187a55217ced6d8a5c98fb367Eric Laurent } 2292615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent env->CallStaticVoidMethod(mClass, gAudioPortEventHandlerMethods.postEventFromNative, mObject, 230700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent event, 0, 0, NULL); 231700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent if (env->ExceptionCheck()) { 232700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent ALOGW("An exception occurred while notifying an event."); 233700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent env->ExceptionClear(); 234700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent } 235700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent} 236700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 237700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentvoid JNIAudioPortCallback::onAudioPortListUpdate() 238700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent{ 239700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent sendEvent(AUDIOPORT_EVENT_PORT_LIST_UPDATED); 240700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent} 241700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 242700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentvoid JNIAudioPortCallback::onAudioPatchListUpdate() 243700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent{ 244700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent sendEvent(AUDIOPORT_EVENT_PATCH_LIST_UPDATED); 245700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent} 246700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 247700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentvoid JNIAudioPortCallback::onServiceDied() 248700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent{ 249700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent sendEvent(AUDIOPORT_EVENT_SERVICE_DIED); 250700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent} 251700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 2522615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurentstatic sp<JNIAudioPortCallback> setJniCallback(JNIEnv* env, 2532615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent jobject thiz, 2542615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent const sp<JNIAudioPortCallback>& callback) 2552615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent{ 2562615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent Mutex::Autolock l(gLock); 2572615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent sp<JNIAudioPortCallback> old = 2582615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent (JNIAudioPortCallback*)env->GetLongField(thiz, gEventHandlerFields.mJniCallback); 2592615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent if (callback.get()) { 2602615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent callback->incStrong((void*)setJniCallback); 2612615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent } 2622615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent if (old != 0) { 2632615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent old->decStrong((void*)setJniCallback); 2642615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent } 2652615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent env->SetLongField(thiz, gEventHandlerFields.mJniCallback, (jlong)callback.get()); 2662615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent return old; 2672615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent} 2682615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent 2699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic int check_AudioSystem_Command(status_t status) 2709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{ 271dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent switch (status) { 272dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent case DEAD_OBJECT: 273dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent return kAudioStatusMediaServerDied; 274dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent case NO_ERROR: 2759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return kAudioStatusOk; 276dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent default: 277dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent break; 2789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 279dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent return kAudioStatusError; 2809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 2819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 282075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 2839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectandroid_media_AudioSystem_muteMicrophone(JNIEnv *env, jobject thiz, jboolean on) 2849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{ 285075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) check_AudioSystem_Command(AudioSystem::muteMicrophone(on)); 2869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 2879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jboolean 2899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectandroid_media_AudioSystem_isMicrophoneMuted(JNIEnv *env, jobject thiz) 2909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{ 2919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project bool state = false; 2929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project AudioSystem::isMicrophoneMuted(&state); 2939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return state; 2949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 2959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstatic jboolean 29725101b0b9a84571ead15b26e9f4cd9c4298d7823Eric Laurentandroid_media_AudioSystem_isStreamActive(JNIEnv *env, jobject thiz, jint stream, jint inPastMs) 2989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{ 2999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project bool state = false; 300bc1d77b6cbce23fbe25f7231651037ae195bc90eGlenn Kasten AudioSystem::isStreamActive((audio_stream_type_t) stream, &state, inPastMs); 3019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return state; 3029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 3039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 304d677054ca63f55abaa1c478ea3c50f6be665a979Jean-Michel Trivistatic jboolean 305679d5046f245ea8b39f9b5596195f3468808dd54Jean-Michel Triviandroid_media_AudioSystem_isStreamActiveRemotely(JNIEnv *env, jobject thiz, jint stream, 306679d5046f245ea8b39f9b5596195f3468808dd54Jean-Michel Trivi jint inPastMs) 307679d5046f245ea8b39f9b5596195f3468808dd54Jean-Michel Trivi{ 308679d5046f245ea8b39f9b5596195f3468808dd54Jean-Michel Trivi bool state = false; 309679d5046f245ea8b39f9b5596195f3468808dd54Jean-Michel Trivi AudioSystem::isStreamActiveRemotely((audio_stream_type_t) stream, &state, inPastMs); 310679d5046f245ea8b39f9b5596195f3468808dd54Jean-Michel Trivi return state; 311679d5046f245ea8b39f9b5596195f3468808dd54Jean-Michel Trivi} 312679d5046f245ea8b39f9b5596195f3468808dd54Jean-Michel Trivi 313679d5046f245ea8b39f9b5596195f3468808dd54Jean-Michel Trivistatic jboolean 314d677054ca63f55abaa1c478ea3c50f6be665a979Jean-Michel Triviandroid_media_AudioSystem_isSourceActive(JNIEnv *env, jobject thiz, jint source) 315d677054ca63f55abaa1c478ea3c50f6be665a979Jean-Michel Trivi{ 316d677054ca63f55abaa1c478ea3c50f6be665a979Jean-Michel Trivi bool state = false; 317d677054ca63f55abaa1c478ea3c50f6be665a979Jean-Michel Trivi AudioSystem::isSourceActive((audio_source_t) source, &state); 318d677054ca63f55abaa1c478ea3c50f6be665a979Jean-Michel Trivi return state; 319d677054ca63f55abaa1c478ea3c50f6be665a979Jean-Michel Trivi} 320d677054ca63f55abaa1c478ea3c50f6be665a979Jean-Michel Trivi 321075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 3228a21f5dd79e93aa4e4b08ab4f33b9255d7c06961Jean-Michel Triviandroid_media_AudioSystem_newAudioSessionId(JNIEnv *env, jobject thiz) 3238a21f5dd79e93aa4e4b08ab4f33b9255d7c06961Jean-Michel Trivi{ 324211d9052f265b4f41b6de74131482a7c77a5e005Glenn Kasten return AudioSystem::newAudioUniqueId(AUDIO_UNIQUE_ID_USE_SESSION); 3258a21f5dd79e93aa4e4b08ab4f33b9255d7c06961Jean-Michel Trivi} 3268a21f5dd79e93aa4e4b08ab4f33b9255d7c06961Jean-Michel Trivi 3278a21f5dd79e93aa4e4b08ab4f33b9255d7c06961Jean-Michel Trivistatic jint 328a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurentandroid_media_AudioSystem_setParameters(JNIEnv *env, jobject thiz, jstring keyValuePairs) 3299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{ 330a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent const jchar* c_keyValuePairs = env->GetStringCritical(keyValuePairs, 0); 331a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent String8 c_keyValuePairs8; 332a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent if (keyValuePairs) { 3336698749dd4d4d6513b26aa9071af290b956b68a7Dan Albert c_keyValuePairs8 = String8( 3346698749dd4d4d6513b26aa9071af290b956b68a7Dan Albert reinterpret_cast<const char16_t*>(c_keyValuePairs), 3356698749dd4d4d6513b26aa9071af290b956b68a7Dan Albert env->GetStringLength(keyValuePairs)); 336a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent env->ReleaseStringCritical(keyValuePairs, c_keyValuePairs); 337a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent } 338c94752a01a709e9f3914c40ebdd77face2d52cceGlenn Kasten int status = check_AudioSystem_Command(AudioSystem::setParameters(c_keyValuePairs8)); 339075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) status; 340a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent} 341a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent 342a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurentstatic jstring 343a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurentandroid_media_AudioSystem_getParameters(JNIEnv *env, jobject thiz, jstring keys) 344a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent{ 345a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent const jchar* c_keys = env->GetStringCritical(keys, 0); 346a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent String8 c_keys8; 347a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent if (keys) { 3486698749dd4d4d6513b26aa9071af290b956b68a7Dan Albert c_keys8 = String8(reinterpret_cast<const char16_t*>(c_keys), 3496698749dd4d4d6513b26aa9071af290b956b68a7Dan Albert env->GetStringLength(keys)); 350a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent env->ReleaseStringCritical(keys, c_keys); 351a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent } 352c94752a01a709e9f3914c40ebdd77face2d52cceGlenn Kasten return env->NewStringUTF(AudioSystem::getParameters(c_keys8).string()); 3539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 355ed0079ddddd4070f3369b13b274222da2e69f4b9Glenn Kastenstatic void 356ed0079ddddd4070f3369b13b274222da2e69f4b9Glenn Kastenandroid_media_AudioSystem_error_callback(status_t err) 3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{ 358539719a7af34be96743a4f408aedf6437f441bbfEric Laurent JNIEnv *env = AndroidRuntime::getJNIEnv(); 3590e7a4d9edcee63c6b770db9b6fe792abad5d7b53Eric Laurent if (env == NULL) { 3600e7a4d9edcee63c6b770db9b6fe792abad5d7b53Eric Laurent return; 3610e7a4d9edcee63c6b770db9b6fe792abad5d7b53Eric Laurent } 3620e7a4d9edcee63c6b770db9b6fe792abad5d7b53Eric Laurent 363ed0079ddddd4070f3369b13b274222da2e69f4b9Glenn Kasten jclass clazz = env->FindClass(kClassPathName); 3649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 365dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent env->CallStaticVoidMethod(clazz, env->GetStaticMethodID(clazz, 366dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent "errorCallbackFromNative","(I)V"), 367dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent check_AudioSystem_Command(err)); 368b637ccffd856ba911c1527077cec3abff39035f5Viorel Suman 369b637ccffd856ba911c1527077cec3abff39035f5Viorel Suman env->DeleteLocalRef(clazz); 3709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 3719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3725a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivistatic void 3735a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Triviandroid_media_AudioSystem_dyn_policy_callback(int event, String8 regId, int val) 3745a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi{ 3755a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi JNIEnv *env = AndroidRuntime::getJNIEnv(); 3765a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi if (env == NULL) { 3775a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi return; 3785a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi } 3795a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi 3805a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi jclass clazz = env->FindClass(kClassPathName); 3815a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi const char* zechars = regId.string(); 3825a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi jstring zestring = env->NewStringUTF(zechars); 3835a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi 384d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi env->CallStaticVoidMethod(clazz, gAudioPolicyEventHandlerMethods.postDynPolicyEventFromNative, 3855a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi event, zestring, val); 3865a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi 3875a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi env->ReleaseStringUTFChars(zestring, zechars); 3885a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi env->DeleteLocalRef(clazz); 389d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi} 390d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi 391d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivistatic void 39233b840444f5a481dd31e129079d3c0cf3acdf80eGlenn Kastenandroid_media_AudioSystem_recording_callback(int event, audio_session_t session, int source, 3938ab728093eed85c176822d58a0d2ba1f4ebbb362Jean-Michel Trivi const audio_config_base_t *clientConfig, const audio_config_base_t *deviceConfig, 3948ab728093eed85c176822d58a0d2ba1f4ebbb362Jean-Michel Trivi audio_patch_handle_t patchHandle) 395d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi{ 396d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi JNIEnv *env = AndroidRuntime::getJNIEnv(); 397d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi if (env == NULL) { 398d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi return; 399d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi } 40033fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi if (clientConfig == NULL || deviceConfig == NULL) { 40133fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi ALOGE("Unexpected null client/device configurations in recording callback"); 40233fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi return; 40333fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi } 4045a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi 40533fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi // create an array for 2*3 integers to store the record configurations (client + device) 4068ab728093eed85c176822d58a0d2ba1f4ebbb362Jean-Michel Trivi // plus 1 integer for the patch handle 4078ab728093eed85c176822d58a0d2ba1f4ebbb362Jean-Michel Trivi const int REC_PARAM_SIZE = 7; 4088ab728093eed85c176822d58a0d2ba1f4ebbb362Jean-Michel Trivi jintArray recParamArray = env->NewIntArray(REC_PARAM_SIZE); 40933fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi if (recParamArray == NULL) { 41033fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi ALOGE("recording callback: Couldn't allocate int array for configuration data"); 41133fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi return; 41233fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi } 4138ab728093eed85c176822d58a0d2ba1f4ebbb362Jean-Michel Trivi jint recParamData[REC_PARAM_SIZE]; 41433fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi recParamData[0] = (jint) audioFormatFromNative(clientConfig->format); 41533fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi // FIXME this doesn't support index-based masks 41633fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi recParamData[1] = (jint) inChannelMaskFromNative(clientConfig->channel_mask); 41733fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi recParamData[2] = (jint) clientConfig->sample_rate; 41833fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi recParamData[3] = (jint) audioFormatFromNative(deviceConfig->format); 41933fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi // FIXME this doesn't support index-based masks 42033fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi recParamData[4] = (jint) inChannelMaskFromNative(deviceConfig->channel_mask); 42133fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi recParamData[5] = (jint) deviceConfig->sample_rate; 4228ab728093eed85c176822d58a0d2ba1f4ebbb362Jean-Michel Trivi recParamData[6] = (jint) patchHandle; 4238ab728093eed85c176822d58a0d2ba1f4ebbb362Jean-Michel Trivi env->SetIntArrayRegion(recParamArray, 0, REC_PARAM_SIZE, recParamData); 42433fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi 42533fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi // callback into java 426d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi jclass clazz = env->FindClass(kClassPathName); 427d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi env->CallStaticVoidMethod(clazz, 428d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi gAudioPolicyEventHandlerMethods.postRecordConfigEventFromNative, 42933fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi event, session, source, recParamArray); 430d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi env->DeleteLocalRef(clazz); 43133fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi 43233fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi env->DeleteLocalRef(recParamArray); 4335a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi} 4345a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi 435075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 43610804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLeanandroid_media_AudioSystem_setDeviceConnectionState(JNIEnv *env, jobject thiz, jint device, jint state, jstring device_address, jstring device_name) 437a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent{ 438a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent const char *c_address = env->GetStringUTFChars(device_address, NULL); 43910804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean const char *c_name = env->GetStringUTFChars(device_name, NULL); 44024fc2fb1c541e954b83fd31ea9f786a5e9b45501Dima Zavin int status = check_AudioSystem_Command(AudioSystem::setDeviceConnectionState(static_cast <audio_devices_t>(device), 44124fc2fb1c541e954b83fd31ea9f786a5e9b45501Dima Zavin static_cast <audio_policy_dev_state_t>(state), 44210804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean c_address, c_name)); 443a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent env->ReleaseStringUTFChars(device_address, c_address); 44410804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean env->ReleaseStringUTFChars(device_name, c_name); 445075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) status; 446a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent} 447a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent 448075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 449a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurentandroid_media_AudioSystem_getDeviceConnectionState(JNIEnv *env, jobject thiz, jint device, jstring device_address) 450a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent{ 451a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent const char *c_address = env->GetStringUTFChars(device_address, NULL); 45224fc2fb1c541e954b83fd31ea9f786a5e9b45501Dima Zavin int state = static_cast <int>(AudioSystem::getDeviceConnectionState(static_cast <audio_devices_t>(device), 453a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent c_address)); 454a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent env->ReleaseStringUTFChars(device_address, c_address); 455075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) state; 456a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent} 457a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent 458075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 459a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurentandroid_media_AudioSystem_setPhoneState(JNIEnv *env, jobject thiz, jint state) 460a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent{ 461075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) check_AudioSystem_Command(AudioSystem::setPhoneState((audio_mode_t) state)); 462a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent} 463a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent 464075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 465a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurentandroid_media_AudioSystem_setForceUse(JNIEnv *env, jobject thiz, jint usage, jint config) 466a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent{ 467075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) check_AudioSystem_Command(AudioSystem::setForceUse(static_cast <audio_policy_force_use_t>(usage), 46824fc2fb1c541e954b83fd31ea9f786a5e9b45501Dima Zavin static_cast <audio_policy_forced_cfg_t>(config))); 469a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent} 470a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent 471075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 472a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurentandroid_media_AudioSystem_getForceUse(JNIEnv *env, jobject thiz, jint usage) 473a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent{ 474075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return static_cast <jint>(AudioSystem::getForceUse(static_cast <audio_policy_force_use_t>(usage))); 475a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent} 476a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent 477075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 478a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurentandroid_media_AudioSystem_initStreamVolume(JNIEnv *env, jobject thiz, jint stream, jint indexMin, jint indexMax) 479a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent{ 480075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) check_AudioSystem_Command(AudioSystem::initStreamVolume(static_cast <audio_stream_type_t>(stream), 481a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent indexMin, 482a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent indexMax)); 483a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent} 484a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent 485075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 4869bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurentandroid_media_AudioSystem_setStreamVolumeIndex(JNIEnv *env, 4879bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent jobject thiz, 4889bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent jint stream, 4899bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent jint index, 4909bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent jint device) 491a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent{ 492075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) check_AudioSystem_Command( 4939bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent AudioSystem::setStreamVolumeIndex(static_cast <audio_stream_type_t>(stream), 4949bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent index, 4959bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent (audio_devices_t)device)); 496a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent} 497a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent 498075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 4999bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurentandroid_media_AudioSystem_getStreamVolumeIndex(JNIEnv *env, 5009bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent jobject thiz, 5019bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent jint stream, 5029bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent jint device) 503a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent{ 504a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent int index; 5059bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent if (AudioSystem::getStreamVolumeIndex(static_cast <audio_stream_type_t>(stream), 5069bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent &index, 5079bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent (audio_devices_t)device) 5089bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent != NO_ERROR) { 509a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent index = -1; 510a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent } 511075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) index; 512a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent} 513a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent 514075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 515cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwoodandroid_media_AudioSystem_setMasterVolume(JNIEnv *env, jobject thiz, jfloat value) 516cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood{ 517075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) check_AudioSystem_Command(AudioSystem::setMasterVolume(value)); 518cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood} 519cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood 520cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwoodstatic jfloat 521cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwoodandroid_media_AudioSystem_getMasterVolume(JNIEnv *env, jobject thiz) 522cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood{ 523cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood float value; 524cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood if (AudioSystem::getMasterVolume(&value) != NO_ERROR) { 525cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood value = -1.0; 526cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood } 527cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood return value; 528cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood} 529cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood 530075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 531cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwoodandroid_media_AudioSystem_setMasterMute(JNIEnv *env, jobject thiz, jboolean mute) 532cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood{ 533075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) check_AudioSystem_Command(AudioSystem::setMasterMute(mute)); 534cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood} 535cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood 536c1bcdbb75877d99972f1cd13a9c40126822621bcVladimir Markostatic jboolean 537cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwoodandroid_media_AudioSystem_getMasterMute(JNIEnv *env, jobject thiz) 538cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood{ 539cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood bool mute; 540cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood if (AudioSystem::getMasterMute(&mute) != NO_ERROR) { 541cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood mute = false; 542cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood } 543cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood return mute; 544cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood} 545cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood 5468b4b97a14ad9b5b982d8fe92755efabec8ad0076Glenn Kastenstatic jint 547f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hungandroid_media_AudioSystem_setMasterMono(JNIEnv *env, jobject thiz, jboolean mono) 548f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung{ 549f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung return (jint) check_AudioSystem_Command(AudioSystem::setMasterMono(mono)); 550f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung} 551f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung 552f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hungstatic jboolean 553f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hungandroid_media_AudioSystem_getMasterMono(JNIEnv *env, jobject thiz) 554f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung{ 555f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung bool mono; 556f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung if (AudioSystem::getMasterMono(&mono) != NO_ERROR) { 557f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung mono = false; 558f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung } 559f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung return mono; 560f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung} 561f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung 562f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hungstatic jint 5638b4b97a14ad9b5b982d8fe92755efabec8ad0076Glenn Kastenandroid_media_AudioSystem_getDevicesForStream(JNIEnv *env, jobject thiz, jint stream) 5648b4b97a14ad9b5b982d8fe92755efabec8ad0076Glenn Kasten{ 56524fc2fb1c541e954b83fd31ea9f786a5e9b45501Dima Zavin return (jint) AudioSystem::getDevicesForStream(static_cast <audio_stream_type_t>(stream)); 5668b4b97a14ad9b5b982d8fe92755efabec8ad0076Glenn Kasten} 5678b4b97a14ad9b5b982d8fe92755efabec8ad0076Glenn Kasten 568c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kastenstatic jint 569c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kastenandroid_media_AudioSystem_getPrimaryOutputSamplingRate(JNIEnv *env, jobject clazz) 570c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kasten{ 571c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kasten return (jint) AudioSystem::getPrimaryOutputSamplingRate(); 572c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kasten} 573c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kasten 574c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kastenstatic jint 575c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kastenandroid_media_AudioSystem_getPrimaryOutputFrameCount(JNIEnv *env, jobject clazz) 576c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kasten{ 577c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kasten return (jint) AudioSystem::getPrimaryOutputFrameCount(); 578c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kasten} 579c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kasten 58061dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodmanstatic jint 58161dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodmanandroid_media_AudioSystem_getOutputLatency(JNIEnv *env, jobject clazz, jint stream) 58261dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodman{ 58361dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodman uint32_t afLatency; 58461dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodman if (AudioSystem::getOutputLatency(&afLatency, static_cast <audio_stream_type_t>(stream)) 58561dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodman != NO_ERROR) { 58661dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodman afLatency = -1; 58761dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodman } 58861dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodman return (jint) afLatency; 58961dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodman} 59061dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodman 591fd116ad1ab02f6060a0b2201f018317fa32e28b4Glenn Kastenstatic jint 592fd116ad1ab02f6060a0b2201f018317fa32e28b4Glenn Kastenandroid_media_AudioSystem_setLowRamDevice(JNIEnv *env, jobject clazz, jboolean isLowRamDevice) 593fd116ad1ab02f6060a0b2201f018317fa32e28b4Glenn Kasten{ 594fd116ad1ab02f6060a0b2201f018317fa32e28b4Glenn Kasten return (jint) AudioSystem::setLowRamDevice((bool) isLowRamDevice); 595fd116ad1ab02f6060a0b2201f018317fa32e28b4Glenn Kasten} 596fd116ad1ab02f6060a0b2201f018317fa32e28b4Glenn Kasten 597075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhatstatic jint 598dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurentandroid_media_AudioSystem_checkAudioFlinger(JNIEnv *env, jobject clazz) 599dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent{ 600075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat return (jint) check_AudioSystem_Command(AudioSystem::checkAudioFlinger()); 601dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent} 602dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent 603b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 604b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic bool useInChannelMask(audio_port_type_t type, audio_port_role_t role) 605b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent{ 606b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return ((type == AUDIO_PORT_TYPE_DEVICE) && (role == AUDIO_PORT_ROLE_SOURCE)) || 607b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ((type == AUDIO_PORT_TYPE_MIX) && (role == AUDIO_PORT_ROLE_SINK)); 608b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} 609b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 6103a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurentstatic void convertAudioGainConfigToNative(JNIEnv *env, 6113a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent struct audio_gain_config *nAudioGainConfig, 6123a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent const jobject jAudioGainConfig, 6133a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent bool useInMask) 6143a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent{ 6153a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent nAudioGainConfig->index = env->GetIntField(jAudioGainConfig, gAudioGainConfigFields.mIndex); 6163a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent nAudioGainConfig->mode = env->GetIntField(jAudioGainConfig, gAudioGainConfigFields.mMode); 6173a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent ALOGV("convertAudioGainConfigToNative got gain index %d", nAudioGainConfig->index); 6183a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent jint jMask = env->GetIntField(jAudioGainConfig, gAudioGainConfigFields.mChannelMask); 6193a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent audio_channel_mask_t nMask; 6203a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent if (useInMask) { 6213a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent nMask = inChannelMaskToNative(jMask); 6223a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent ALOGV("convertAudioGainConfigToNative IN mask java %x native %x", jMask, nMask); 6233a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent } else { 6243a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent nMask = outChannelMaskToNative(jMask); 6253a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent ALOGV("convertAudioGainConfigToNative OUT mask java %x native %x", jMask, nMask); 6263a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent } 6273a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent nAudioGainConfig->channel_mask = nMask; 6283a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent nAudioGainConfig->ramp_duration_ms = env->GetIntField(jAudioGainConfig, 6293a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent gAudioGainConfigFields.mRampDurationMs); 6303a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent jintArray jValues = (jintArray)env->GetObjectField(jAudioGainConfig, 6313a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent gAudioGainConfigFields.mValues); 6323a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent int *nValues = env->GetIntArrayElements(jValues, NULL); 6333a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent size_t size = env->GetArrayLength(jValues); 6343a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent memcpy(nAudioGainConfig->values, nValues, size * sizeof(int)); 6353a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent env->DeleteLocalRef(jValues); 6363a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent} 6373a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent 6383a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent 639b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jint convertAudioPortConfigToNative(JNIEnv *env, 640b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent struct audio_port_config *nAudioPortConfig, 6416368a7df1884031b6620493e096abe8510c05e24Eric Laurent const jobject jAudioPortConfig, 6426368a7df1884031b6620493e096abe8510c05e24Eric Laurent bool useConfigMask) 643b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent{ 644b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jAudioPort = env->GetObjectField(jAudioPortConfig, gAudioPortConfigFields.mPort); 645b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jHandle = env->GetObjectField(jAudioPort, gAudioPortFields.mHandle); 646b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->id = env->GetIntField(jHandle, gAudioHandleFields.mId); 647b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->role = (audio_port_role_t)env->GetIntField(jAudioPort, 648b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent gAudioPortFields.mRole); 649b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (env->IsInstanceOf(jAudioPort, gAudioDevicePortClass)) { 650b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->type = AUDIO_PORT_TYPE_DEVICE; 651b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else if (env->IsInstanceOf(jAudioPort, gAudioMixPortClass)) { 652b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->type = AUDIO_PORT_TYPE_MIX; 653b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 654b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jAudioPort); 655b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jHandle); 656b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_ERROR; 657b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 658b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigToNative handle %d role %d type %d", 659b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->id, nAudioPortConfig->role, nAudioPortConfig->type); 660b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 6616368a7df1884031b6620493e096abe8510c05e24Eric Laurent unsigned int configMask = 0; 6626368a7df1884031b6620493e096abe8510c05e24Eric Laurent 663b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->sample_rate = env->GetIntField(jAudioPortConfig, 664b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent gAudioPortConfigFields.mSamplingRate); 6656368a7df1884031b6620493e096abe8510c05e24Eric Laurent if (nAudioPortConfig->sample_rate != 0) { 6666368a7df1884031b6620493e096abe8510c05e24Eric Laurent configMask |= AUDIO_PORT_CONFIG_SAMPLE_RATE; 6676368a7df1884031b6620493e096abe8510c05e24Eric Laurent } 668b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 669b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent bool useInMask = useInChannelMask(nAudioPortConfig->type, nAudioPortConfig->role); 670b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent audio_channel_mask_t nMask; 671b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jint jMask = env->GetIntField(jAudioPortConfig, 672b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent gAudioPortConfigFields.mChannelMask); 673b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (useInMask) { 674b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nMask = inChannelMaskToNative(jMask); 675b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigToNative IN mask java %x native %x", jMask, nMask); 676b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 677b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nMask = outChannelMaskToNative(jMask); 678b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigToNative OUT mask java %x native %x", jMask, nMask); 679b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 680b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->channel_mask = nMask; 6816368a7df1884031b6620493e096abe8510c05e24Eric Laurent if (nAudioPortConfig->channel_mask != AUDIO_CHANNEL_NONE) { 6826368a7df1884031b6620493e096abe8510c05e24Eric Laurent configMask |= AUDIO_PORT_CONFIG_CHANNEL_MASK; 6836368a7df1884031b6620493e096abe8510c05e24Eric Laurent } 684b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 685b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jint jFormat = env->GetIntField(jAudioPortConfig, gAudioPortConfigFields.mFormat); 686b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent audio_format_t nFormat = audioFormatToNative(jFormat); 687b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigToNative format %d native %d", jFormat, nFormat); 688b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->format = nFormat; 6896368a7df1884031b6620493e096abe8510c05e24Eric Laurent if (nAudioPortConfig->format != AUDIO_FORMAT_DEFAULT && 6906368a7df1884031b6620493e096abe8510c05e24Eric Laurent nAudioPortConfig->format != AUDIO_FORMAT_INVALID) { 6916368a7df1884031b6620493e096abe8510c05e24Eric Laurent configMask |= AUDIO_PORT_CONFIG_FORMAT; 6926368a7df1884031b6620493e096abe8510c05e24Eric Laurent } 6936368a7df1884031b6620493e096abe8510c05e24Eric Laurent 694b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jGain = env->GetObjectField(jAudioPortConfig, gAudioPortConfigFields.mGain); 695b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jGain != NULL) { 6963a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent convertAudioGainConfigToNative(env, &nAudioPortConfig->gain, jGain, useInMask); 697b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jGain); 6986368a7df1884031b6620493e096abe8510c05e24Eric Laurent configMask |= AUDIO_PORT_CONFIG_GAIN; 699b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 700b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigToNative no gain"); 701b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->gain.index = -1; 702b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 7036368a7df1884031b6620493e096abe8510c05e24Eric Laurent if (useConfigMask) { 7046368a7df1884031b6620493e096abe8510c05e24Eric Laurent nAudioPortConfig->config_mask = env->GetIntField(jAudioPortConfig, 7056368a7df1884031b6620493e096abe8510c05e24Eric Laurent gAudioPortConfigFields.mConfigMask); 7066368a7df1884031b6620493e096abe8510c05e24Eric Laurent } else { 7076368a7df1884031b6620493e096abe8510c05e24Eric Laurent nAudioPortConfig->config_mask = configMask; 7086368a7df1884031b6620493e096abe8510c05e24Eric Laurent } 709b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jAudioPort); 710b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jHandle); 711b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_SUCCESS; 712b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} 713b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 714b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jint convertAudioPortConfigFromNative(JNIEnv *env, 715b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jAudioPort, 716b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject *jAudioPortConfig, 717b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent const struct audio_port_config *nAudioPortConfig) 718b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent{ 719b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jint jStatus = AUDIO_JAVA_SUCCESS; 720b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jAudioGainConfig = NULL; 721b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jAudioGain = NULL; 722b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jintArray jGainValues; 723b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent bool audioportCreated = false; 724b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 725b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative jAudioPort %p", jAudioPort); 726b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 727b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jAudioPort == NULL) { 728b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jHandle = env->NewObject(gAudioHandleClass, gAudioHandleCstor, 729b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->id); 730b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 731b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative handle %d is a %s", nAudioPortConfig->id, 732b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->type == AUDIO_PORT_TYPE_DEVICE ? "device" : "mix"); 733b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 734b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jHandle == NULL) { 735b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_ERROR; 736b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 737b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent // create dummy port and port config objects with just the correct handle 738b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent // and configuration data. The actual AudioPortConfig objects will be 739b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent // constructed by java code with correct class type (device, mix etc...) 740b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent // and reference to AudioPort instance in this client 741b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jAudioPort = env->NewObject(gAudioPortClass, gAudioPortCstor, 742f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean jHandle, // handle 743f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean 0, // role 744f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean NULL, // name 745f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean NULL, // samplingRates 746f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean NULL, // channelMasks 747f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean NULL, // channelIndexMasks 748f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean NULL, // formats 749f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean NULL); // gains 750b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jHandle); 751b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jAudioPort == NULL) { 752b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_ERROR; 753b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 754b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative jAudioPort created for handle %d", 755b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->id); 756b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 757b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent audioportCreated = true; 758b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 759b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 760b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent bool useInMask = useInChannelMask(nAudioPortConfig->type, nAudioPortConfig->role); 761b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 762b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent audio_channel_mask_t nMask; 763b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jint jMask; 764b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 765b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent int gainIndex = nAudioPortConfig->gain.index; 766b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (gainIndex >= 0) { 767b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative gain found with index %d mode %x", 768b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent gainIndex, nAudioPortConfig->gain.mode); 769b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (audioportCreated) { 770b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative creating gain"); 771b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jAudioGain = env->NewObject(gAudioGainClass, gAudioGainCstor, 772b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent gainIndex, 773b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 0, 774b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 0, 775b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 0, 776b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 0, 777b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 0, 778b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 0, 779b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 0, 780b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 0); 781b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jAudioGain == NULL) { 782b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative creating gain FAILED"); 783b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 784b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 785b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 786b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 787b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative reading gain from port"); 788b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobjectArray jGains = (jobjectArray)env->GetObjectField(jAudioPort, 789b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent gAudioPortFields.mGains); 790b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jGains == NULL) { 791b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative could not get gains from port"); 792b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 793b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 794b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 795b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jAudioGain = env->GetObjectArrayElement(jGains, gainIndex); 796b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jGains); 797b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jAudioGain == NULL) { 798b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative could not get gain at index %d", gainIndex); 799b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 800b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 801b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 802b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 8030078c7cc59082d32799b9097a81a0341fe98619dEric Laurent int numValues; 8040078c7cc59082d32799b9097a81a0341fe98619dEric Laurent if (useInMask) { 8050078c7cc59082d32799b9097a81a0341fe98619dEric Laurent numValues = audio_channel_count_from_in_mask(nAudioPortConfig->gain.channel_mask); 8060078c7cc59082d32799b9097a81a0341fe98619dEric Laurent } else { 8070078c7cc59082d32799b9097a81a0341fe98619dEric Laurent numValues = audio_channel_count_from_out_mask(nAudioPortConfig->gain.channel_mask); 8080078c7cc59082d32799b9097a81a0341fe98619dEric Laurent } 809b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jGainValues = env->NewIntArray(numValues); 810b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jGainValues == NULL) { 811b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative could not create gain values %d", numValues); 812b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 813b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 814b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 815b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->SetIntArrayRegion(jGainValues, 0, numValues, 816b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->gain.values); 817b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 818b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nMask = nAudioPortConfig->gain.channel_mask; 819b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (useInMask) { 820b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jMask = inChannelMaskFromNative(nMask); 821b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative IN mask java %x native %x", jMask, nMask); 822b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 823b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jMask = outChannelMaskFromNative(nMask); 824b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative OUT mask java %x native %x", jMask, nMask); 825b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 826b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 827b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jAudioGainConfig = env->NewObject(gAudioGainConfigClass, 828b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent gAudioGainConfigCstor, 829b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent gainIndex, 830b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jAudioGain, 831b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->gain.mode, 832b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jMask, 833b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jGainValues, 834b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->gain.ramp_duration_ms); 835b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jGainValues); 836b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jAudioGainConfig == NULL) { 837b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative could not create gain config"); 838b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 839b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 840b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 841b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 842b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jclass clazz; 843b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jmethodID methodID; 844b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (audioportCreated) { 845b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent clazz = gAudioPortConfigClass; 846b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent methodID = gAudioPortConfigCstor; 847b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative building a generic port config"); 848b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 849b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (env->IsInstanceOf(jAudioPort, gAudioDevicePortClass)) { 850b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent clazz = gAudioDevicePortConfigClass; 851b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent methodID = gAudioDevicePortConfigCstor; 852b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative building a device config"); 853b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else if (env->IsInstanceOf(jAudioPort, gAudioMixPortClass)) { 854b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent clazz = gAudioMixPortConfigClass; 855b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent methodID = gAudioMixPortConfigCstor; 856b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative building a mix config"); 857b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 858b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 859b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 860b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 861b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 862b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nMask = nAudioPortConfig->channel_mask; 863b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (useInMask) { 864b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jMask = inChannelMaskFromNative(nMask); 865b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative IN mask java %x native %x", jMask, nMask); 866b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 867b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jMask = outChannelMaskFromNative(nMask); 868b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative OUT mask java %x native %x", jMask, nMask); 869b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 870b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 871b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent *jAudioPortConfig = env->NewObject(clazz, methodID, 872b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jAudioPort, 873b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPortConfig->sample_rate, 874b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jMask, 875b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent audioFormatFromNative(nAudioPortConfig->format), 876b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jAudioGainConfig); 877b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (*jAudioPortConfig == NULL) { 878b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative could not create new port config"); 879b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 880b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 881b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative OK"); 882b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 883b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 884b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentexit: 885b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (audioportCreated) { 886b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jAudioPort); 887b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jAudioGain != NULL) { 888b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jAudioGain); 889b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 890b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 891b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jAudioGainConfig != NULL) { 892b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jAudioGainConfig); 893b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 894b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return jStatus; 895b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} 896b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 8974e5e9e9405dc626a03a653161644841102ad89f1Paul McLeanstatic bool hasFormat(int* formats, size_t size, int format) { 8984e5e9e9405dc626a03a653161644841102ad89f1Paul McLean for (size_t index = 0; index < size; index++) { 8994e5e9e9405dc626a03a653161644841102ad89f1Paul McLean if (formats[index] == format) { 9004e5e9e9405dc626a03a653161644841102ad89f1Paul McLean return true; // found 9014e5e9e9405dc626a03a653161644841102ad89f1Paul McLean } 9024e5e9e9405dc626a03a653161644841102ad89f1Paul McLean } 9034e5e9e9405dc626a03a653161644841102ad89f1Paul McLean return false; // not found 9044e5e9e9405dc626a03a653161644841102ad89f1Paul McLean} 9054e5e9e9405dc626a03a653161644841102ad89f1Paul McLean 906b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jint convertAudioPortFromNative(JNIEnv *env, 907b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject *jAudioPort, const struct audio_port *nAudioPort) 908b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent{ 909b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jint jStatus = (jint)AUDIO_JAVA_SUCCESS; 910b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jintArray jSamplingRates = NULL; 911b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jintArray jChannelMasks = NULL; 912f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean jintArray jChannelIndexMasks = NULL; 9134e5e9e9405dc626a03a653161644841102ad89f1Paul McLean int* cFormats = NULL; 914b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jintArray jFormats = NULL; 915b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobjectArray jGains = NULL; 916b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jHandle = NULL; 91710804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean jstring jDeviceName = NULL; 918b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent bool useInMask; 919f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean size_t numPositionMasks = 0; 920f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean size_t numIndexMasks = 0; 9212db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean size_t numUniqueFormats = 0; 9222db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean 92310804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean ALOGV("convertAudioPortFromNative id %d role %d type %d name %s", 92410804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean nAudioPort->id, nAudioPort->role, nAudioPort->type, nAudioPort->name); 925b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 926b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jSamplingRates = env->NewIntArray(nAudioPort->num_sample_rates); 927b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jSamplingRates == NULL) { 928b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 929b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 930b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 931b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (nAudioPort->num_sample_rates) { 932b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->SetIntArrayRegion(jSamplingRates, 0, nAudioPort->num_sample_rates, 933b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent (jint *)nAudioPort->sample_rates); 934b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 935b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 936f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean // count up how many masks are positional and indexed 937f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean for(size_t index = 0; index < nAudioPort->num_channel_masks; index++) { 938f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean const audio_channel_mask_t mask = nAudioPort->channel_masks[index]; 939f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean if (audio_channel_mask_get_representation(mask) == AUDIO_CHANNEL_REPRESENTATION_INDEX) { 940f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean numIndexMasks++; 941f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean } else { 942f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean numPositionMasks++; 943f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean } 944f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean } 945f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean 946f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean jChannelMasks = env->NewIntArray(numPositionMasks); 947b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jChannelMasks == NULL) { 948b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 949b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 950b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 951f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean jChannelIndexMasks = env->NewIntArray(numIndexMasks); 952f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean if (jChannelIndexMasks == NULL) { 953f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean jStatus = (jint)AUDIO_JAVA_ERROR; 954f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean goto exit; 955f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean } 956b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent useInMask = useInChannelMask(nAudioPort->type, nAudioPort->role); 957b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 958f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean // put the masks in the output arrays 959f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean for (size_t maskIndex = 0, posMaskIndex = 0, indexedMaskIndex = 0; 960f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean maskIndex < nAudioPort->num_channel_masks; maskIndex++) { 961f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean const audio_channel_mask_t mask = nAudioPort->channel_masks[maskIndex]; 962f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean if (audio_channel_mask_get_representation(mask) == AUDIO_CHANNEL_REPRESENTATION_INDEX) { 963f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean jint jMask = audio_channel_mask_get_bits(mask); 964f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean env->SetIntArrayRegion(jChannelIndexMasks, indexedMaskIndex++, 1, &jMask); 965b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 966f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean jint jMask = useInMask ? inChannelMaskFromNative(mask) 967f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean : outChannelMaskFromNative(mask); 968f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean env->SetIntArrayRegion(jChannelMasks, posMaskIndex++, 1, &jMask); 969b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 970b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 971b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 972f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean // formats 9732db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean if (nAudioPort->num_formats != 0) { 9742db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean cFormats = new int[nAudioPort->num_formats]; 9752db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean for (size_t index = 0; index < nAudioPort->num_formats; index++) { 9762db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean int format = audioFormatFromNative(nAudioPort->formats[index]); 9772db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean if (!hasFormat(cFormats, numUniqueFormats, format)) { 9782db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean cFormats[numUniqueFormats++] = format; 9792db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean } 9804e5e9e9405dc626a03a653161644841102ad89f1Paul McLean } 9814e5e9e9405dc626a03a653161644841102ad89f1Paul McLean } 9824e5e9e9405dc626a03a653161644841102ad89f1Paul McLean jFormats = env->NewIntArray(numUniqueFormats); 983b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jFormats == NULL) { 984b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 985b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 986b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 9872db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean if (numUniqueFormats != 0) { 9882db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean env->SetIntArrayRegion(jFormats, 0, numUniqueFormats, cFormats); 9892db94372749c4fcc9bd715f41e0b5c4045ee7c84Paul McLean } 990b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 991f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean // gains 992b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jGains = env->NewObjectArray(nAudioPort->num_gains, 993b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent gAudioGainClass, NULL); 994b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jGains == NULL) { 995b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 996b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 997b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 998f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean 999b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent for (size_t j = 0; j < nAudioPort->num_gains; j++) { 1000b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent audio_channel_mask_t nMask = nAudioPort->gains[j].channel_mask; 1001f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean jint jMask; 1002b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (useInMask) { 1003b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jMask = inChannelMaskFromNative(nMask); 1004b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative IN mask java %x native %x", jMask, nMask); 1005b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 1006b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jMask = outChannelMaskFromNative(nMask); 1007b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortConfigFromNative OUT mask java %x native %x", jMask, nMask); 1008b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1009b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1010b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jGain = env->NewObject(gAudioGainClass, gAudioGainCstor, 1011b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent j, 1012b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPort->gains[j].mode, 1013b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jMask, 1014b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPort->gains[j].min_value, 1015b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPort->gains[j].max_value, 1016b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPort->gains[j].default_value, 1017b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPort->gains[j].step_value, 1018b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPort->gains[j].min_ramp_ms, 1019b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPort->gains[j].max_ramp_ms); 1020b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jGain == NULL) { 1021b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 1022b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1023b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1024b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->SetObjectArrayElement(jGains, j, jGain); 1025b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jGain); 1026b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1027b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1028b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jHandle = env->NewObject(gAudioHandleClass, gAudioHandleCstor, 1029b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPort->id); 1030b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jHandle == NULL) { 1031b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 1032b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1033b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1034b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 103510804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean jDeviceName = env->NewStringUTF(nAudioPort->name); 103610804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean 1037b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (nAudioPort->type == AUDIO_PORT_TYPE_DEVICE) { 1038b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortFromNative is a device %08x", nAudioPort->ext.device.type); 1039b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jstring jAddress = env->NewStringUTF(nAudioPort->ext.device.address); 1040b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent *jAudioPort = env->NewObject(gAudioDevicePortClass, gAudioDevicePortCstor, 104110804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean jHandle, jDeviceName, 1042f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean jSamplingRates, jChannelMasks, jChannelIndexMasks, 1043f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean jFormats, jGains, 1044b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nAudioPort->ext.device.type, jAddress); 1045b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jAddress); 1046b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else if (nAudioPort->type == AUDIO_PORT_TYPE_MIX) { 1047b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("convertAudioPortFromNative is a mix"); 1048b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent *jAudioPort = env->NewObject(gAudioMixPortClass, gAudioMixPortCstor, 10494bcdba848449b33d7022de527c526943aff1f5fdEric Laurent jHandle, nAudioPort->ext.mix.handle, 10504bcdba848449b33d7022de527c526943aff1f5fdEric Laurent nAudioPort->role, jDeviceName, 1051f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean jSamplingRates, jChannelMasks, jChannelIndexMasks, 1052b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jFormats, jGains); 1053b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 1054b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGE("convertAudioPortFromNative unknown nAudioPort type %d", nAudioPort->type); 1055b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 1056b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1057b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1058b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (*jAudioPort == NULL) { 1059b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 1060b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1061b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1062b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1063b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jAudioPortConfig; 1064b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = convertAudioPortConfigFromNative(env, 1065b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent *jAudioPort, 1066b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &jAudioPortConfig, 1067b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &nAudioPort->active_config); 1068b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 1069b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return jStatus; 1070b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1071b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1072b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->SetObjectField(*jAudioPort, gAudioPortFields.mActiveConfig, jAudioPortConfig); 1073b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1074b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentexit: 107510804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean if (jDeviceName != NULL) { 107610804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean env->DeleteLocalRef(jDeviceName); 107710804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean } 1078b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jSamplingRates != NULL) { 1079b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSamplingRates); 1080b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1081b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jChannelMasks != NULL) { 1082b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jChannelMasks); 1083b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 10844e5e9e9405dc626a03a653161644841102ad89f1Paul McLean if (jChannelIndexMasks != NULL) { 10854e5e9e9405dc626a03a653161644841102ad89f1Paul McLean env->DeleteLocalRef(jChannelIndexMasks); 10864e5e9e9405dc626a03a653161644841102ad89f1Paul McLean } 10874e5e9e9405dc626a03a653161644841102ad89f1Paul McLean if (cFormats != NULL) { 10884e5e9e9405dc626a03a653161644841102ad89f1Paul McLean delete[] cFormats; 10894e5e9e9405dc626a03a653161644841102ad89f1Paul McLean } 1090b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jFormats != NULL) { 1091b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jFormats); 1092b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1093b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jGains != NULL) { 1094b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jGains); 1095b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1096b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jHandle != NULL) { 1097b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jHandle); 1098b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1099b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1100b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return jStatus; 1101b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} 1102b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1103b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1104b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jint 1105b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentandroid_media_AudioSystem_listAudioPorts(JNIEnv *env, jobject clazz, 1106b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jPorts, jintArray jGeneration) 1107b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent{ 1108b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("listAudioPorts"); 1109b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1110b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPorts == NULL) { 1111b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGE("listAudioPorts NULL AudioPort ArrayList"); 1112b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1113b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1114b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (!env->IsInstanceOf(jPorts, gArrayListClass)) { 1115b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGE("listAudioPorts not an arraylist"); 1116b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1117b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1118b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1119b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jGeneration == NULL || env->GetArrayLength(jGeneration) != 1) { 1120b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1121b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1122b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1123b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status_t status; 1124b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent unsigned int generation1; 1125b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent unsigned int generation; 1126b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent unsigned int numPorts; 1127b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jint *nGeneration; 1128b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent struct audio_port *nPorts = NULL; 1129b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent int attempts = MAX_PORT_GENERATION_SYNC_ATTEMPTS; 1130b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent jint jStatus; 1131b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1132b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent // get the port count and all the ports until they both return the same generation 1133b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent do { 1134b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (attempts-- < 0) { 1135b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status = TIMED_OUT; 1136b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent break; 1137b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1138b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1139b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent numPorts = 0; 1140b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status = AudioSystem::listAudioPorts(AUDIO_PORT_ROLE_NONE, 1141b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent AUDIO_PORT_TYPE_NONE, 1142b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &numPorts, 1143b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent NULL, 1144b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &generation1); 1145b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent if (status != NO_ERROR) { 1146b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGE_IF(status != NO_ERROR, "AudioSystem::listAudioPorts error %d", status); 1147b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent break; 1148b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1149b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent if (numPorts == 0) { 1150b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent jStatus = (jint)AUDIO_JAVA_SUCCESS; 1151b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent goto exit; 1152b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent } 1153b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPorts = (struct audio_port *)realloc(nPorts, numPorts * sizeof(struct audio_port)); 1154b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1155b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status = AudioSystem::listAudioPorts(AUDIO_PORT_ROLE_NONE, 1156b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent AUDIO_PORT_TYPE_NONE, 1157b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &numPorts, 1158b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPorts, 1159b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &generation); 1160b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("listAudioPorts AudioSystem::listAudioPorts numPorts %d generation %d generation1 %d", 1161b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent numPorts, generation, generation1); 1162b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } while (generation1 != generation && status == NO_ERROR); 1163b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1164b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent jStatus = nativeToJavaStatus(status); 1165b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 1166b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1167b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1168b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1169b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent for (size_t i = 0; i < numPorts; i++) { 1170b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jAudioPort; 1171b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = convertAudioPortFromNative(env, &jAudioPort, &nPorts[i]); 1172b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 1173b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1174b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1175b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->CallBooleanMethod(jPorts, gArrayListMethods.add, jAudioPort); 1176b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1177b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1178b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentexit: 1179b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent nGeneration = env->GetIntArrayElements(jGeneration, NULL); 1180b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent if (nGeneration == NULL) { 1181b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 1182b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent } else { 1183b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent nGeneration[0] = generation1; 1184b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent env->ReleaseIntArrayElements(jGeneration, nGeneration, 0); 1185b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent } 1186b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent free(nPorts); 1187b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return jStatus; 1188b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} 1189b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1190b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic int 1191b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentandroid_media_AudioSystem_createAudioPatch(JNIEnv *env, jobject clazz, 1192b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobjectArray jPatches, jobjectArray jSources, jobjectArray jSinks) 1193b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent{ 1194b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status_t status; 1195b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jint jStatus; 1196b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1197b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("createAudioPatch"); 1198b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPatches == NULL || jSources == NULL || jSinks == NULL) { 1199b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1200b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1201b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1202b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (env->GetArrayLength(jPatches) != 1) { 1203b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1204b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1205b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jint numSources = env->GetArrayLength(jSources); 1206b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (numSources == 0 || numSources > AUDIO_PATCH_PORTS_MAX) { 1207b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1208b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1209b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1210b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jint numSinks = env->GetArrayLength(jSinks); 1211b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (numSinks == 0 || numSinks > AUDIO_PATCH_PORTS_MAX) { 1212b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1213b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1214b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1215b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent audio_patch_handle_t handle = (audio_patch_handle_t)0; 1216b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jPatch = env->GetObjectArrayElement(jPatches, 0); 1217b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jPatchHandle = NULL; 1218b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPatch != NULL) { 1219b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (!env->IsInstanceOf(jPatch, gAudioPatchClass)) { 1220b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1221b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1222b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jPatchHandle = env->GetObjectField(jPatch, gAudioPatchFields.mHandle); 1223b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent handle = (audio_patch_handle_t)env->GetIntField(jPatchHandle, gAudioHandleFields.mId); 1224b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1225b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1226b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent struct audio_patch nPatch; 1227b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1228b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatch.id = handle; 1229b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatch.num_sources = 0; 1230b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatch.num_sinks = 0; 1231b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jSource = NULL; 1232b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jSink = NULL; 1233b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1234b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent for (jint i = 0; i < numSources; i++) { 1235b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jSource = env->GetObjectArrayElement(jSources, i); 1236b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (!env->IsInstanceOf(jSource, gAudioPortConfigClass)) { 1237b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_BAD_VALUE; 1238b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1239b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 12406368a7df1884031b6620493e096abe8510c05e24Eric Laurent jStatus = convertAudioPortConfigToNative(env, &nPatch.sources[i], jSource, false); 1241b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSource); 1242b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jSource = NULL; 1243b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 1244b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1245b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1246b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatch.num_sources++; 1247b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1248b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1249b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent for (jint i = 0; i < numSinks; i++) { 1250b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jSink = env->GetObjectArrayElement(jSinks, i); 1251b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (!env->IsInstanceOf(jSink, gAudioPortConfigClass)) { 1252b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_BAD_VALUE; 1253b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1254b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 12556368a7df1884031b6620493e096abe8510c05e24Eric Laurent jStatus = convertAudioPortConfigToNative(env, &nPatch.sinks[i], jSink, false); 1256b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSink); 1257b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jSink = NULL; 1258b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 1259b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1260b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1261b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatch.num_sinks++; 1262b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1263b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1264b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("AudioSystem::createAudioPatch"); 1265b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status = AudioSystem::createAudioPatch(&nPatch, &handle); 1266b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("AudioSystem::createAudioPatch() returned %d hande %d", status, handle); 1267b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1268b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = nativeToJavaStatus(status); 1269b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 1270b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1271b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1272b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1273b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPatchHandle == NULL) { 1274b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jPatchHandle = env->NewObject(gAudioHandleClass, gAudioHandleCstor, 1275b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent handle); 1276b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPatchHandle == NULL) { 1277b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 1278b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1279b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1280b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jPatch = env->NewObject(gAudioPatchClass, gAudioPatchCstor, jPatchHandle, jSources, jSinks); 1281b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPatch == NULL) { 1282b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = (jint)AUDIO_JAVA_ERROR; 1283b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1284b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1285b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->SetObjectArrayElement(jPatches, 0, jPatch); 1286b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } else { 1287b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->SetIntField(jPatchHandle, gAudioHandleFields.mId, handle); 1288b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1289b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1290b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentexit: 1291b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPatchHandle != NULL) { 1292b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jPatchHandle); 1293b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1294b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPatch != NULL) { 1295b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jPatch); 1296b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1297b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jSource != NULL) { 1298b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSource); 1299b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1300b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jSink != NULL) { 1301b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSink); 1302b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1303b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return jStatus; 1304b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} 1305b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 13060f0b4919667f418b249c497f5ad3e83fdf4437e5Andreas Gampestatic jint 1307b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentandroid_media_AudioSystem_releaseAudioPatch(JNIEnv *env, jobject clazz, 1308b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jPatch) 1309b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent{ 1310b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("releaseAudioPatch"); 1311b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPatch == NULL) { 1312b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1313b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1314b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1315b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent audio_patch_handle_t handle = (audio_patch_handle_t)0; 1316b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jPatchHandle = NULL; 1317b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (!env->IsInstanceOf(jPatch, gAudioPatchClass)) { 1318b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1319b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1320b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jPatchHandle = env->GetObjectField(jPatch, gAudioPatchFields.mHandle); 1321b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent handle = (audio_patch_handle_t)env->GetIntField(jPatchHandle, gAudioHandleFields.mId); 1322b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jPatchHandle); 1323b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1324b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("AudioSystem::releaseAudioPatch"); 1325b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status_t status = AudioSystem::releaseAudioPatch(handle); 1326b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("AudioSystem::releaseAudioPatch() returned %d", status); 1327b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jint jStatus = nativeToJavaStatus(status); 13280f0b4919667f418b249c497f5ad3e83fdf4437e5Andreas Gampe return jStatus; 1329b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} 1330b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1331b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentstatic jint 1332b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentandroid_media_AudioSystem_listAudioPatches(JNIEnv *env, jobject clazz, 1333b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jPatches, jintArray jGeneration) 1334b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent{ 1335b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("listAudioPatches"); 1336b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPatches == NULL) { 1337b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGE("listAudioPatches NULL AudioPatch ArrayList"); 1338b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1339b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1340b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (!env->IsInstanceOf(jPatches, gArrayListClass)) { 1341b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGE("listAudioPatches not an arraylist"); 1342b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1343b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1344b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1345b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jGeneration == NULL || env->GetArrayLength(jGeneration) != 1) { 1346b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 1347b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1348b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1349b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status_t status; 1350b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent unsigned int generation1; 1351b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent unsigned int generation; 1352b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent unsigned int numPatches; 1353b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jint *nGeneration; 1354b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent struct audio_patch *nPatches = NULL; 1355b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobjectArray jSources = NULL; 1356b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jSource = NULL; 1357b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobjectArray jSinks = NULL; 1358b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jSink = NULL; 1359b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject jPatch = NULL; 1360b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent int attempts = MAX_PORT_GENERATION_SYNC_ATTEMPTS; 1361b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent jint jStatus; 1362b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1363b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent // get the patch count and all the patches until they both return the same generation 1364b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent do { 1365b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (attempts-- < 0) { 1366b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status = TIMED_OUT; 1367b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent break; 1368b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1369b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1370b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent numPatches = 0; 1371b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status = AudioSystem::listAudioPatches(&numPatches, 1372b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent NULL, 1373b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &generation1); 1374b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent if (status != NO_ERROR) { 1375b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGE_IF(status != NO_ERROR, "listAudioPatches AudioSystem::listAudioPatches error %d", 1376b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status); 1377b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent break; 1378b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1379b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent if (numPatches == 0) { 1380b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent jStatus = (jint)AUDIO_JAVA_SUCCESS; 1381b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent goto exit; 1382b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent } 1383b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent 1384b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatches = (struct audio_patch *)realloc(nPatches, numPatches * sizeof(struct audio_patch)); 1385b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1386b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent status = AudioSystem::listAudioPatches(&numPatches, 1387b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatches, 1388b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &generation); 1389b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent ALOGV("listAudioPatches AudioSystem::listAudioPatches numPatches %d generation %d generation1 %d", 1390b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent numPatches, generation, generation1); 1391b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1392b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } while (generation1 != generation && status == NO_ERROR); 1393b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1394b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent jStatus = nativeToJavaStatus(status); 1395b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 1396b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1397b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1398b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1399b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent for (size_t i = 0; i < numPatches; i++) { 1400b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jobject patchHandle = env->NewObject(gAudioHandleClass, gAudioHandleCstor, 1401b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatches[i].id); 1402b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (patchHandle == NULL) { 1403b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = AUDIO_JAVA_ERROR; 1404b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1405b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 140646d8444631b4b1253a76bfcc78a29d26014d022fDan Albert ALOGV("listAudioPatches patch %zu num_sources %d num_sinks %d", 1407b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent i, nPatches[i].num_sources, nPatches[i].num_sinks); 1408b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1409b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->SetIntField(patchHandle, gAudioHandleFields.mId, nPatches[i].id); 1410b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1411b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent // load sources 1412b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jSources = env->NewObjectArray(nPatches[i].num_sources, 1413b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent gAudioPortConfigClass, NULL); 1414b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jSources == NULL) { 1415b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = AUDIO_JAVA_ERROR; 1416b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1417b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1418b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1419b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent for (size_t j = 0; j < nPatches[i].num_sources; j++) { 1420b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = convertAudioPortConfigFromNative(env, 1421b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent NULL, 1422b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &jSource, 1423b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &nPatches[i].sources[j]); 1424b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 1425b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1426b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1427b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->SetObjectArrayElement(jSources, j, jSource); 1428b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSource); 1429b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jSource = NULL; 143046d8444631b4b1253a76bfcc78a29d26014d022fDan Albert ALOGV("listAudioPatches patch %zu source %zu is a %s handle %d", 1431b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent i, j, 1432b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatches[i].sources[j].type == AUDIO_PORT_TYPE_DEVICE ? "device" : "mix", 1433b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatches[i].sources[j].id); 1434b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1435b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent // load sinks 1436b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jSinks = env->NewObjectArray(nPatches[i].num_sinks, 1437b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent gAudioPortConfigClass, NULL); 1438b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jSinks == NULL) { 1439b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = AUDIO_JAVA_ERROR; 1440b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1441b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1442b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1443b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent for (size_t j = 0; j < nPatches[i].num_sinks; j++) { 1444b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = convertAudioPortConfigFromNative(env, 1445b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent NULL, 1446b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &jSink, 1447b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent &nPatches[i].sinks[j]); 1448b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1449b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 1450b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1451b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1452b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->SetObjectArrayElement(jSinks, j, jSink); 1453b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSink); 1454b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jSink = NULL; 145546d8444631b4b1253a76bfcc78a29d26014d022fDan Albert ALOGV("listAudioPatches patch %zu sink %zu is a %s handle %d", 1456b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent i, j, 1457b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatches[i].sinks[j].type == AUDIO_PORT_TYPE_DEVICE ? "device" : "mix", 1458b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent nPatches[i].sinks[j].id); 1459b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1460b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1461b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jPatch = env->NewObject(gAudioPatchClass, gAudioPatchCstor, 1462b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent patchHandle, jSources, jSinks); 1463b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSources); 1464b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jSources = NULL; 1465b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSinks); 1466b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jSinks = NULL; 1467b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPatch == NULL) { 1468b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jStatus = AUDIO_JAVA_ERROR; 1469b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent goto exit; 1470b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1471b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->CallBooleanMethod(jPatches, gArrayListMethods.add, jPatch); 1472b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jPatch); 1473b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent jPatch = NULL; 1474b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1475b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1476b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurentexit: 1477b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent 1478b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent nGeneration = env->GetIntArrayElements(jGeneration, NULL); 1479b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent if (nGeneration == NULL) { 1480b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent jStatus = AUDIO_JAVA_ERROR; 1481b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent } else { 1482b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent nGeneration[0] = generation1; 1483b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent env->ReleaseIntArrayElements(jGeneration, nGeneration, 0); 1484b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent } 1485b36d104b8ffba24417c1b15b763bc8972c6e0d3dEric Laurent 1486b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jSources != NULL) { 1487b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSources); 1488b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1489b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jSource != NULL) { 1490b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSource); 1491b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1492b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jSinks != NULL) { 1493b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSinks); 1494b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1495b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jSink != NULL) { 1496b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jSink); 1497b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1498b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent if (jPatch != NULL) { 1499b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent env->DeleteLocalRef(jPatch); 1500b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent } 1501b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent free(nPatches); 1502b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent return jStatus; 1503b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent} 1504b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 15053a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurentstatic jint 15063a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurentandroid_media_AudioSystem_setAudioPortConfig(JNIEnv *env, jobject clazz, 15073a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent jobject jAudioPortConfig) 15083a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent{ 15093a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent ALOGV("setAudioPortConfig"); 15103a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent if (jAudioPortConfig == NULL) { 15113a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent return AUDIO_JAVA_BAD_VALUE; 15123a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent } 15133a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent if (!env->IsInstanceOf(jAudioPortConfig, gAudioPortConfigClass)) { 15143a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent return AUDIO_JAVA_BAD_VALUE; 15153a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent } 15163a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent struct audio_port_config nAudioPortConfig; 15176368a7df1884031b6620493e096abe8510c05e24Eric Laurent jint jStatus = convertAudioPortConfigToNative(env, &nAudioPortConfig, jAudioPortConfig, true); 15183a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 15193a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent return jStatus; 15203a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent } 15213a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent status_t status = AudioSystem::setAudioPortConfig(&nAudioPortConfig); 15223a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent ALOGV("AudioSystem::setAudioPortConfig() returned %d", status); 15233a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent jStatus = nativeToJavaStatus(status); 15243a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent return jStatus; 15253a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent} 15263a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent 1527700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentstatic void 1528700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentandroid_media_AudioSystem_eventHandlerSetup(JNIEnv *env, jobject thiz, jobject weak_this) 1529700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent{ 1530700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent ALOGV("eventHandlerSetup"); 1531700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 1532700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent sp<JNIAudioPortCallback> callback = new JNIAudioPortCallback(env, thiz, weak_this); 1533700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 15342615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent if (AudioSystem::addAudioPortCallback(callback) == NO_ERROR) { 15352615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent setJniCallback(env, thiz, callback); 15362615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent } 1537700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent} 1538700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 1539700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentstatic void 1540700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurentandroid_media_AudioSystem_eventHandlerFinalize(JNIEnv *env, jobject thiz) 1541700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent{ 1542700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent ALOGV("eventHandlerFinalize"); 1543700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 15442615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent sp<JNIAudioPortCallback> callback = setJniCallback(env, thiz, 0); 1545700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 15462615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent if (callback != 0) { 15472615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent AudioSystem::removeAudioPortCallback(callback); 15482615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent } 1549700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent} 1550700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 1551b634e1b6d6bda56128c354b1803b04b537e3799dEric Laurentstatic jint 1552b634e1b6d6bda56128c354b1803b04b537e3799dEric Laurentandroid_media_AudioSystem_getAudioHwSyncForSession(JNIEnv *env, jobject thiz, jint sessionId) 1553b634e1b6d6bda56128c354b1803b04b537e3799dEric Laurent{ 155433b840444f5a481dd31e129079d3c0cf3acdf80eGlenn Kasten return (jint) AudioSystem::getAudioHwSyncForSession((audio_session_t) sessionId); 1555b634e1b6d6bda56128c354b1803b04b537e3799dEric Laurent} 1556b634e1b6d6bda56128c354b1803b04b537e3799dEric Laurent 15575a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivistatic void 15585a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Triviandroid_media_AudioSystem_registerDynPolicyCallback(JNIEnv *env, jobject thiz) 15595a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi{ 15605a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi AudioSystem::setDynPolicyCallback(android_media_AudioSystem_dyn_policy_callback); 15615a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi} 15627f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 1563d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivistatic void 1564d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Triviandroid_media_AudioSystem_registerRecordingCallback(JNIEnv *env, jobject thiz) 1565d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi{ 1566d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi AudioSystem::setRecordConfigCallback(android_media_AudioSystem_recording_callback); 1567d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi} 1568d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi 15697f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 15707f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentstatic jint convertAudioMixToNative(JNIEnv *env, 15717f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent AudioMix *nAudioMix, 15727f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent const jobject jAudioMix) 15737f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent{ 15747f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent nAudioMix->mMixType = env->GetIntField(jAudioMix, gAudioMixFields.mMixType); 15757f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent nAudioMix->mRouteFlags = env->GetIntField(jAudioMix, gAudioMixFields.mRouteFlags); 15764ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi nAudioMix->mDeviceType = (audio_devices_t) 15774ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi env->GetIntField(jAudioMix, gAudioMixFields.mDeviceType); 15787f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 15794ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi jstring jDeviceAddress = (jstring)env->GetObjectField(jAudioMix, 15804ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi gAudioMixFields.mDeviceAddress); 15814ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi const char *nDeviceAddress = env->GetStringUTFChars(jDeviceAddress, NULL); 15824ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi nAudioMix->mDeviceAddress = String8(nDeviceAddress); 15834ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi env->ReleaseStringUTFChars(jDeviceAddress, nDeviceAddress); 15844ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi env->DeleteLocalRef(jDeviceAddress); 15857f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 15865a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi nAudioMix->mCbFlags = env->GetIntField(jAudioMix, gAudioMixFields.mCallbackFlags); 15875a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi 15887f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jobject jFormat = env->GetObjectField(jAudioMix, gAudioMixFields.mFormat); 15897f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent nAudioMix->mFormat.sample_rate = env->GetIntField(jFormat, 15907f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent gAudioFormatFields.mSampleRate); 15917f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent nAudioMix->mFormat.channel_mask = outChannelMaskToNative(env->GetIntField(jFormat, 15927f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent gAudioFormatFields.mChannelMask)); 15937f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent nAudioMix->mFormat.format = audioFormatToNative(env->GetIntField(jFormat, 15947f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent gAudioFormatFields.mEncoding)); 15957f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent env->DeleteLocalRef(jFormat); 15967f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 15977f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jobject jRule = env->GetObjectField(jAudioMix, gAudioMixFields.mRule); 15987f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jobject jRuleCriteria = env->GetObjectField(jRule, gAudioMixingRuleFields.mCriteria); 15997f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent env->DeleteLocalRef(jRule); 16007f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jobjectArray jCriteria = (jobjectArray)env->CallObjectMethod(jRuleCriteria, 16017f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent gArrayListMethods.toArray); 16027f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent env->DeleteLocalRef(jRuleCriteria); 16037f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16047f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jint numCriteria = env->GetArrayLength(jCriteria); 16057f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent if (numCriteria > MAX_CRITERIA_PER_MIX) { 16067f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent numCriteria = MAX_CRITERIA_PER_MIX; 16077f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent } 16087f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16097f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent for (jint i = 0; i < numCriteria; i++) { 1610ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi AudioMixMatchCriterion nCriterion; 16117f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16127f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jobject jCriterion = env->GetObjectArrayElement(jCriteria, i); 16137f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 1614ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi nCriterion.mRule = env->GetIntField(jCriterion, gAudioMixMatchCriterionFields.mRule); 16157f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 1616ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi const uint32_t match_rule = nCriterion.mRule & ~RULE_EXCLUSION_MASK; 1617ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi switch (match_rule) { 1618ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi case RULE_MATCH_UID: 1619ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi nCriterion.mValue.mUid = env->GetIntField(jCriterion, 1620ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi gAudioMixMatchCriterionFields.mIntProp); 1621ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi break; 1622ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi case RULE_MATCH_ATTRIBUTE_USAGE: 1623ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi case RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET: { 1624ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi jobject jAttributes = env->GetObjectField(jCriterion, gAudioMixMatchCriterionFields.mAttr); 1625ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi if (match_rule == RULE_MATCH_ATTRIBUTE_USAGE) { 1626ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi nCriterion.mValue.mUsage = (audio_usage_t)env->GetIntField(jAttributes, 1627ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi gAudioAttributesFields.mUsage); 1628ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi } else { 1629ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi nCriterion.mValue.mSource = (audio_source_t)env->GetIntField(jAttributes, 1630ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi gAudioAttributesFields.mSource); 1631ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi } 1632ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi env->DeleteLocalRef(jAttributes); 1633ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi } 1634ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi break; 16357f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent } 16367f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16377f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent nAudioMix->mCriteria.add(nCriterion); 16387f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent env->DeleteLocalRef(jCriterion); 16397f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent } 16407f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16417f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent env->DeleteLocalRef(jCriteria); 16427f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16437f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent return (jint)AUDIO_JAVA_SUCCESS; 16447f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent} 16457f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16467f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentstatic jint 16477f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentandroid_media_AudioSystem_registerPolicyMixes(JNIEnv *env, jobject clazz, 16487f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jobject jMixesList, jboolean registration) 16497f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent{ 16507f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent ALOGV("registerPolicyMixes"); 16517f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16527f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent if (jMixesList == NULL) { 16537f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 16547f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent } 16557f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent if (!env->IsInstanceOf(jMixesList, gArrayListClass)) { 16567f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent return (jint)AUDIO_JAVA_BAD_VALUE; 16577f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent } 16587f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jobjectArray jMixes = (jobjectArray)env->CallObjectMethod(jMixesList, 16597f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent gArrayListMethods.toArray); 16607f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jint numMixes = env->GetArrayLength(jMixes); 16617f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent if (numMixes > MAX_MIXES_PER_POLICY) { 16627f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent numMixes = MAX_MIXES_PER_POLICY; 16637f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent } 16647f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16657f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent status_t status; 16667f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jint jStatus; 16677f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jobject jAudioMix = NULL; 16687f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent Vector <AudioMix> mixes; 16697f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent for (jint i = 0; i < numMixes; i++) { 16707f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jAudioMix = env->GetObjectArrayElement(jMixes, i); 16717f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent if (!env->IsInstanceOf(jAudioMix, gAudioMixClass)) { 16727f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jStatus = (jint)AUDIO_JAVA_BAD_VALUE; 16737f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent goto exit; 16747f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent } 16757f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent AudioMix mix; 16767f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jStatus = convertAudioMixToNative(env, &mix, jAudioMix); 16777f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent env->DeleteLocalRef(jAudioMix); 16787f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jAudioMix = NULL; 16797f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 16807f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent goto exit; 16817f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent } 16827f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent mixes.add(mix); 16837f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent } 16847f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16857f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent ALOGV("AudioSystem::registerPolicyMixes numMixes %d registration %d", numMixes, registration); 16867f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent status = AudioSystem::registerPolicyMixes(mixes, registration); 16877f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent ALOGV("AudioSystem::registerPolicyMixes() returned %d", status); 16887f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16897f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent jStatus = nativeToJavaStatus(status); 16907f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent if (jStatus != AUDIO_JAVA_SUCCESS) { 16917f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent goto exit; 16927f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent } 16937f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 16947f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurentexit: 16957f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent if (jAudioMix != NULL) { 16967f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent env->DeleteLocalRef(jAudioMix); 16977f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent } 16987f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent return jStatus; 16997f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent} 17007f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 17010867bed9ddb3bea3d7c252791f8b62ae21ad3de5Eric Laurentstatic jint 17020867bed9ddb3bea3d7c252791f8b62ae21ad3de5Eric Laurentandroid_media_AudioSystem_systemReady(JNIEnv *env, jobject thiz) 17030867bed9ddb3bea3d7c252791f8b62ae21ad3de5Eric Laurent{ 17040867bed9ddb3bea3d7c252791f8b62ae21ad3de5Eric Laurent return nativeToJavaStatus(AudioSystem::systemReady()); 17050867bed9ddb3bea3d7c252791f8b62ae21ad3de5Eric Laurent} 17067f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 17077f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 17089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// ---------------------------------------------------------------------------- 17099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 171076f6a86de25e1bf74717e047e55fd44b089673f3Daniel Micaystatic const JNINativeMethod gMethods[] = { 1711a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent {"setParameters", "(Ljava/lang/String;)I", (void *)android_media_AudioSystem_setParameters}, 1712a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent {"getParameters", "(Ljava/lang/String;)Ljava/lang/String;", (void *)android_media_AudioSystem_getParameters}, 17139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project {"muteMicrophone", "(Z)I", (void *)android_media_AudioSystem_muteMicrophone}, 17149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project {"isMicrophoneMuted", "()Z", (void *)android_media_AudioSystem_isMicrophoneMuted}, 1715d677054ca63f55abaa1c478ea3c50f6be665a979Jean-Michel Trivi {"isStreamActive", "(II)Z", (void *)android_media_AudioSystem_isStreamActive}, 1716679d5046f245ea8b39f9b5596195f3468808dd54Jean-Michel Trivi {"isStreamActiveRemotely","(II)Z", (void *)android_media_AudioSystem_isStreamActiveRemotely}, 1717d677054ca63f55abaa1c478ea3c50f6be665a979Jean-Michel Trivi {"isSourceActive", "(I)Z", (void *)android_media_AudioSystem_isSourceActive}, 17188a21f5dd79e93aa4e4b08ab4f33b9255d7c06961Jean-Michel Trivi {"newAudioSessionId", "()I", (void *)android_media_AudioSystem_newAudioSessionId}, 171910804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean {"setDeviceConnectionState", "(IILjava/lang/String;Ljava/lang/String;)I", (void *)android_media_AudioSystem_setDeviceConnectionState}, 1720a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent {"getDeviceConnectionState", "(ILjava/lang/String;)I", (void *)android_media_AudioSystem_getDeviceConnectionState}, 1721a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent {"setPhoneState", "(I)I", (void *)android_media_AudioSystem_setPhoneState}, 1722a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent {"setForceUse", "(II)I", (void *)android_media_AudioSystem_setForceUse}, 1723a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent {"getForceUse", "(I)I", (void *)android_media_AudioSystem_getForceUse}, 1724a553c25b33c99b345cf1c8688f8df0ed8df14e5aEric Laurent {"initStreamVolume", "(III)I", (void *)android_media_AudioSystem_initStreamVolume}, 17259bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent {"setStreamVolumeIndex","(III)I", (void *)android_media_AudioSystem_setStreamVolumeIndex}, 17269bc8358ddaa01c3490f9709991989633a6a3dd42Eric Laurent {"getStreamVolumeIndex","(II)I", (void *)android_media_AudioSystem_getStreamVolumeIndex}, 1727cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood {"setMasterVolume", "(F)I", (void *)android_media_AudioSystem_setMasterVolume}, 1728cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood {"getMasterVolume", "()F", (void *)android_media_AudioSystem_getMasterVolume}, 1729cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood {"setMasterMute", "(Z)I", (void *)android_media_AudioSystem_setMasterMute}, 1730cbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762Mike Lockwood {"getMasterMute", "()Z", (void *)android_media_AudioSystem_getMasterMute}, 1731f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung {"setMasterMono", "(Z)I", (void *)android_media_AudioSystem_setMasterMono}, 1732f04b84d4c66ea377ec6fe2b36f3a0994f3e94ebaAndy Hung {"getMasterMono", "()Z", (void *)android_media_AudioSystem_getMasterMono}, 17338b4b97a14ad9b5b982d8fe92755efabec8ad0076Glenn Kasten {"getDevicesForStream", "(I)I", (void *)android_media_AudioSystem_getDevicesForStream}, 1734c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kasten {"getPrimaryOutputSamplingRate", "()I", (void *)android_media_AudioSystem_getPrimaryOutputSamplingRate}, 1735c6c4365ddb0213c548b055f257dc8077389224fbGlenn Kasten {"getPrimaryOutputFrameCount", "()I", (void *)android_media_AudioSystem_getPrimaryOutputFrameCount}, 173661dcdf3764b614c6f01e77cb4342d192e3101f8aOliver Woodman {"getOutputLatency", "(I)I", (void *)android_media_AudioSystem_getOutputLatency}, 1737fd116ad1ab02f6060a0b2201f018317fa32e28b4Glenn Kasten {"setLowRamDevice", "(Z)I", (void *)android_media_AudioSystem_setLowRamDevice}, 1738dfb881f96af7898151940a4bbc52e45e6043d38bEric Laurent {"checkAudioFlinger", "()I", (void *)android_media_AudioSystem_checkAudioFlinger}, 1739b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent {"listAudioPorts", "(Ljava/util/ArrayList;[I)I", 1740b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent (void *)android_media_AudioSystem_listAudioPorts}, 1741b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent {"createAudioPatch", "([Landroid/media/AudioPatch;[Landroid/media/AudioPortConfig;[Landroid/media/AudioPortConfig;)I", 1742b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent (void *)android_media_AudioSystem_createAudioPatch}, 1743b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent {"releaseAudioPatch", "(Landroid/media/AudioPatch;)I", 1744b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent (void *)android_media_AudioSystem_releaseAudioPatch}, 1745b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent {"listAudioPatches", "(Ljava/util/ArrayList;[I)I", 1746b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent (void *)android_media_AudioSystem_listAudioPatches}, 17473a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent {"setAudioPortConfig", "(Landroid/media/AudioPortConfig;)I", 17483a24199a0fe9479802ff6096d82cb3745efa1f1fEric Laurent (void *)android_media_AudioSystem_setAudioPortConfig}, 1749b634e1b6d6bda56128c354b1803b04b537e3799dEric Laurent {"getAudioHwSyncForSession", "(I)I", 1750b634e1b6d6bda56128c354b1803b04b537e3799dEric Laurent (void *)android_media_AudioSystem_getAudioHwSyncForSession}, 17517f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent {"registerPolicyMixes", "(Ljava/util/ArrayList;Z)I", 17527f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent (void *)android_media_AudioSystem_registerPolicyMixes}, 17535a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi {"native_register_dynamic_policy_callback", "()V", 17545a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi (void *)android_media_AudioSystem_registerDynPolicyCallback}, 1755d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi {"native_register_recording_callback", "()V", 1756d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi (void *)android_media_AudioSystem_registerRecordingCallback}, 17570867bed9ddb3bea3d7c252791f8b62ae21ad3de5Eric Laurent {"systemReady", "()I", (void *)android_media_AudioSystem_systemReady}, 17589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}; 17599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1760b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 176176f6a86de25e1bf74717e047e55fd44b089673f3Daniel Micaystatic const JNINativeMethod gEventHandlerMethods[] = { 1762700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent {"native_setup", 1763700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent "(Ljava/lang/Object;)V", 1764700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent (void *)android_media_AudioSystem_eventHandlerSetup}, 1765700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent {"native_finalize", 1766700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent "()V", 1767700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent (void *)android_media_AudioSystem_eventHandlerFinalize}, 1768700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent}; 1769700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 17709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectint register_android_media_AudioSystem(JNIEnv *env) 17719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{ 1772ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass arrayListClass = FindClassOrDie(env, "java/util/ArrayList"); 1773ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gArrayListClass = MakeGlobalRefOrDie(env, arrayListClass); 1774ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gArrayListMethods.add = GetMethodIDOrDie(env, arrayListClass, "add", "(Ljava/lang/Object;)Z"); 1775093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gArrayListMethods.toArray = GetMethodIDOrDie(env, arrayListClass, "toArray", "()[Ljava/lang/Object;"); 1776ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe 1777ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass audioHandleClass = FindClassOrDie(env, "android/media/AudioHandle"); 1778ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioHandleClass = MakeGlobalRefOrDie(env, audioHandleClass); 1779ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioHandleCstor = GetMethodIDOrDie(env, audioHandleClass, "<init>", "(I)V"); 1780ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioHandleFields.mId = GetFieldIDOrDie(env, audioHandleClass, "mId", "I"); 1781ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe 1782ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass audioPortClass = FindClassOrDie(env, "android/media/AudioPort"); 1783ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortClass = MakeGlobalRefOrDie(env, audioPortClass); 1784ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortCstor = GetMethodIDOrDie(env, audioPortClass, "<init>", 1785f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean "(Landroid/media/AudioHandle;ILjava/lang/String;[I[I[I[I[Landroid/media/AudioGain;)V"); 1786ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortFields.mHandle = GetFieldIDOrDie(env, audioPortClass, "mHandle", 1787b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent "Landroid/media/AudioHandle;"); 1788ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortFields.mRole = GetFieldIDOrDie(env, audioPortClass, "mRole", "I"); 1789ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortFields.mGains = GetFieldIDOrDie(env, audioPortClass, "mGains", 1790b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent "[Landroid/media/AudioGain;"); 1791ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortFields.mActiveConfig = GetFieldIDOrDie(env, audioPortClass, "mActiveConfig", 1792ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe "Landroid/media/AudioPortConfig;"); 1793ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe 1794ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass audioPortConfigClass = FindClassOrDie(env, "android/media/AudioPortConfig"); 1795ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortConfigClass = MakeGlobalRefOrDie(env, audioPortConfigClass); 1796ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortConfigCstor = GetMethodIDOrDie(env, audioPortConfigClass, "<init>", 1797ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe "(Landroid/media/AudioPort;IIILandroid/media/AudioGainConfig;)V"); 1798ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortConfigFields.mPort = GetFieldIDOrDie(env, audioPortConfigClass, "mPort", 1799b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent "Landroid/media/AudioPort;"); 1800ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortConfigFields.mSamplingRate = GetFieldIDOrDie(env, audioPortConfigClass, 1801b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent "mSamplingRate", "I"); 1802ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortConfigFields.mChannelMask = GetFieldIDOrDie(env, audioPortConfigClass, 1803b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent "mChannelMask", "I"); 1804ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortConfigFields.mFormat = GetFieldIDOrDie(env, audioPortConfigClass, "mFormat", "I"); 1805ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortConfigFields.mGain = GetFieldIDOrDie(env, audioPortConfigClass, "mGain", 1806b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent "Landroid/media/AudioGainConfig;"); 1807ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPortConfigFields.mConfigMask = GetFieldIDOrDie(env, audioPortConfigClass, "mConfigMask", 1808ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe "I"); 1809ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe 1810ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass audioDevicePortConfigClass = FindClassOrDie(env, "android/media/AudioDevicePortConfig"); 1811ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioDevicePortConfigClass = MakeGlobalRefOrDie(env, audioDevicePortConfigClass); 1812ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioDevicePortConfigCstor = GetMethodIDOrDie(env, audioDevicePortConfigClass, "<init>", 1813ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe "(Landroid/media/AudioDevicePort;IIILandroid/media/AudioGainConfig;)V"); 1814ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe 1815ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass audioMixPortConfigClass = FindClassOrDie(env, "android/media/AudioMixPortConfig"); 1816ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioMixPortConfigClass = MakeGlobalRefOrDie(env, audioMixPortConfigClass); 1817ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioMixPortConfigCstor = GetMethodIDOrDie(env, audioMixPortConfigClass, "<init>", 1818ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe "(Landroid/media/AudioMixPort;IIILandroid/media/AudioGainConfig;)V"); 1819ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe 1820ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass audioDevicePortClass = FindClassOrDie(env, "android/media/AudioDevicePort"); 1821ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioDevicePortClass = MakeGlobalRefOrDie(env, audioDevicePortClass); 1822ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioDevicePortCstor = GetMethodIDOrDie(env, audioDevicePortClass, "<init>", 1823f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean "(Landroid/media/AudioHandle;Ljava/lang/String;[I[I[I[I[Landroid/media/AudioGain;ILjava/lang/String;)V"); 1824ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe 1825ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass audioMixPortClass = FindClassOrDie(env, "android/media/AudioMixPort"); 1826ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioMixPortClass = MakeGlobalRefOrDie(env, audioMixPortClass); 1827ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioMixPortCstor = GetMethodIDOrDie(env, audioMixPortClass, "<init>", 1828f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean "(Landroid/media/AudioHandle;IILjava/lang/String;[I[I[I[I[Landroid/media/AudioGain;)V"); 1829ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe 1830ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass audioGainClass = FindClassOrDie(env, "android/media/AudioGain"); 1831ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioGainClass = MakeGlobalRefOrDie(env, audioGainClass); 1832ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioGainCstor = GetMethodIDOrDie(env, audioGainClass, "<init>", "(IIIIIIIII)V"); 1833ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe 1834ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass audioGainConfigClass = FindClassOrDie(env, "android/media/AudioGainConfig"); 1835ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioGainConfigClass = MakeGlobalRefOrDie(env, audioGainConfigClass); 1836ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioGainConfigCstor = GetMethodIDOrDie(env, audioGainConfigClass, "<init>", 1837b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent "(ILandroid/media/AudioGain;II[II)V"); 1838ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioGainConfigFields.mIndex = GetFieldIDOrDie(env, gAudioGainConfigClass, "mIndex", "I"); 1839ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioGainConfigFields.mMode = GetFieldIDOrDie(env, audioGainConfigClass, "mMode", "I"); 1840ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioGainConfigFields.mChannelMask = GetFieldIDOrDie(env, audioGainConfigClass, "mChannelMask", 1841b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent "I"); 1842ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioGainConfigFields.mValues = GetFieldIDOrDie(env, audioGainConfigClass, "mValues", "[I"); 1843ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioGainConfigFields.mRampDurationMs = GetFieldIDOrDie(env, audioGainConfigClass, 1844b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent "mRampDurationMs", "I"); 1845b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1846ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass audioPatchClass = FindClassOrDie(env, "android/media/AudioPatch"); 1847ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPatchClass = MakeGlobalRefOrDie(env, audioPatchClass); 1848ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPatchCstor = GetMethodIDOrDie(env, audioPatchClass, "<init>", 1849b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent"(Landroid/media/AudioHandle;[Landroid/media/AudioPortConfig;[Landroid/media/AudioPortConfig;)V"); 1850ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe gAudioPatchFields.mHandle = GetFieldIDOrDie(env, audioPatchClass, "mHandle", 1851b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent "Landroid/media/AudioHandle;"); 1852b69681c894c663e84f2826d9b0c832ceb9b45047Eric Laurent 1853ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe jclass eventHandlerClass = FindClassOrDie(env, kEventHandlerClassPathName); 18542615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent gAudioPortEventHandlerMethods.postEventFromNative = GetStaticMethodIDOrDie( 18552615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent env, eventHandlerClass, "postEventFromNative", 18562615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent "(Ljava/lang/Object;IIILjava/lang/Object;)V"); 18572615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent gEventHandlerFields.mJniCallback = GetFieldIDOrDie(env, 18582615afb1b0f597f38a07832b33df9bd888a0dce1Eric Laurent eventHandlerClass, "mJniCallback", "J"); 1859700e73471d85348b52ecf213c36bb24b93997ec7Eric Laurent 1860d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi gAudioPolicyEventHandlerMethods.postDynPolicyEventFromNative = 18615a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi GetStaticMethodIDOrDie(env, env->FindClass(kClassPathName), 18625a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi "dynamicPolicyCallbackFromNative", "(ILjava/lang/String;I)V"); 1863d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi gAudioPolicyEventHandlerMethods.postRecordConfigEventFromNative = 1864d3c71f075b139024e2bea39bbd75e3b976bfb7cbJean-Michel Trivi GetStaticMethodIDOrDie(env, env->FindClass(kClassPathName), 186533fd8169cdb7e7fa33885b6f892bc4f6df68959bJean-Michel Trivi "recordingCallbackFromNative", "(III[I)V"); 18665a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi 1867093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent jclass audioMixClass = FindClassOrDie(env, "android/media/audiopolicy/AudioMix"); 1868093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioMixClass = MakeGlobalRefOrDie(env, audioMixClass); 1869093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioMixFields.mRule = GetFieldIDOrDie(env, audioMixClass, "mRule", 18707f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent "Landroid/media/audiopolicy/AudioMixingRule;"); 1871093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioMixFields.mFormat = GetFieldIDOrDie(env, audioMixClass, "mFormat", 18727f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent "Landroid/media/AudioFormat;"); 1873093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioMixFields.mRouteFlags = GetFieldIDOrDie(env, audioMixClass, "mRouteFlags", "I"); 18744ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi gAudioMixFields.mDeviceType = GetFieldIDOrDie(env, audioMixClass, "mDeviceSystemType", "I"); 18754ad39885f2e6e79ae1faaa41ae240eeffcefd368Jean-Michel Trivi gAudioMixFields.mDeviceAddress = GetFieldIDOrDie(env, audioMixClass, "mDeviceAddress", 18767f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent "Ljava/lang/String;"); 1877093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioMixFields.mMixType = GetFieldIDOrDie(env, audioMixClass, "mMixType", "I"); 18785a56109d1f5c00404c8f0e4281b9ac1392d72886Jean-Michel Trivi gAudioMixFields.mCallbackFlags = GetFieldIDOrDie(env, audioMixClass, "mCallbackFlags", "I"); 18797f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 1880093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent jclass audioFormatClass = FindClassOrDie(env, "android/media/AudioFormat"); 1881093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioFormatClass = MakeGlobalRefOrDie(env, audioFormatClass); 1882093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioFormatFields.mEncoding = GetFieldIDOrDie(env, audioFormatClass, "mEncoding", "I"); 1883093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioFormatFields.mSampleRate = GetFieldIDOrDie(env, audioFormatClass, "mSampleRate", "I"); 1884093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioFormatFields.mChannelMask = GetFieldIDOrDie(env, audioFormatClass, "mChannelMask", "I"); 18857f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 1886093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent jclass audioMixingRuleClass = FindClassOrDie(env, "android/media/audiopolicy/AudioMixingRule"); 1887093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioMixingRuleClass = MakeGlobalRefOrDie(env, audioMixingRuleClass); 1888093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioMixingRuleFields.mCriteria = GetFieldIDOrDie(env, audioMixingRuleClass, "mCriteria", 18897f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent "Ljava/util/ArrayList;"); 18907f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 1891ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi jclass audioMixMatchCriterionClass = 1892ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi FindClassOrDie(env, "android/media/audiopolicy/AudioMixingRule$AudioMixMatchCriterion"); 1893ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi gAudioMixMatchCriterionClass = MakeGlobalRefOrDie(env,audioMixMatchCriterionClass); 1894ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi gAudioMixMatchCriterionFields.mAttr = GetFieldIDOrDie(env, audioMixMatchCriterionClass, "mAttr", 18957f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent "Landroid/media/AudioAttributes;"); 1896ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi gAudioMixMatchCriterionFields.mIntProp = GetFieldIDOrDie(env, audioMixMatchCriterionClass, "mIntProp", 1897ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi "I"); 1898ba6b4b400d850ba18fcb9d5bf9789d490f390accJean-Michel Trivi gAudioMixMatchCriterionFields.mRule = GetFieldIDOrDie(env, audioMixMatchCriterionClass, "mRule", 18997f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent "I"); 19007f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 1901093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent jclass audioAttributesClass = FindClassOrDie(env, "android/media/AudioAttributes"); 1902093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioAttributesClass = MakeGlobalRefOrDie(env, audioAttributesClass); 1903093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioAttributesFields.mUsage = GetFieldIDOrDie(env, audioAttributesClass, "mUsage", "I"); 1904093789755e5549bd8676d268a6f69b1d6db5026bEric Laurent gAudioAttributesFields.mSource = GetFieldIDOrDie(env, audioAttributesClass, "mSource", "I"); 19057f5eb9fe3c10d8d83ff0e2b0fc60a05c2e6d5b02Eric Laurent 19069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project AudioSystem::setErrorCallback(android_media_AudioSystem_error_callback); 190718db49a46259020387c40fff36d92edc1087a366Glenn Kasten 1908ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); 1909ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe return RegisterMethodsOrDie(env, kEventHandlerClassPathName, gEventHandlerMethods, 1910ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe NELEM(gEventHandlerMethods)); 19119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 1912