The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | //#define LOG_NDEBUG 0 |
| 17 | |
| 18 | #define LOG_TAG "AudioTrack-JNI" |
| 19 | |
Wei Jia | 071a8b7 | 2015-03-09 16:38:25 -0700 | [diff] [blame] | 20 | #include "android_media_AudioTrack.h" |
| 21 | |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 22 | #include <nativehelper/JNIHelp.h> |
| 23 | #include <nativehelper/JniConstants.h> |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 24 | #include "core_jni_helpers.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 26 | #include <nativehelper/ScopedBytes.h> |
Jean-Michel Trivi | 7ca0452 | 2014-02-07 09:39:34 -0800 | [diff] [blame] | 27 | |
Glenn Kasten | c81d31c | 2012-03-13 14:46:23 -0700 | [diff] [blame] | 28 | #include <utils/Log.h> |
| 29 | #include <media/AudioSystem.h> |
| 30 | #include <media/AudioTrack.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 32 | #include <binder/MemoryHeapBase.h> |
| 33 | #include <binder/MemoryBase.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
Glenn Kasten | fe834d3 | 2014-01-08 14:49:08 -0800 | [diff] [blame] | 35 | #include "android_media_AudioFormat.h" |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 36 | #include "android_media_AudioErrors.h" |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 37 | #include "android_media_PlaybackParams.h" |
Eric Laurent | 4bcdba8 | 2015-05-01 11:37:49 -0700 | [diff] [blame] | 38 | #include "android_media_DeviceCallback.h" |
Andy Hung | 035d4ec | 2017-01-24 13:45:02 -0800 | [diff] [blame] | 39 | #include "android_media_VolumeShaper.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
Ben Wagner | 85ea32b | 2016-03-16 17:10:42 -0400 | [diff] [blame] | 41 | #include <cinttypes> |
| 42 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | // ---------------------------------------------------------------------------- |
| 44 | |
| 45 | using namespace android; |
| 46 | |
Ivan Lozano | 330d876 | 2017-08-08 12:51:06 -0700 | [diff] [blame] | 47 | using ::android::media::VolumeShaper; |
| 48 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | // ---------------------------------------------------------------------------- |
| 50 | static const char* const kClassPathName = "android/media/AudioTrack"; |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 51 | static const char* const kAudioAttributesClassPathName = "android/media/AudioAttributes"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 53 | struct audio_track_fields_t { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | // these fields provide access from C++ to the... |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | jmethodID postNativeEventInJava; //... event post callback method |
Eric Laurent | 83b3685 | 2009-07-28 07:49:22 -0700 | [diff] [blame] | 56 | jfieldID nativeTrackInJavaObj; // stores in Java the native AudioTrack object |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | jfieldID jniData; // stores in Java additional resources used by the native AudioTrack |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 58 | jfieldID fieldStreamType; // ... mStreamType field in the AudioTrack Java object |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | }; |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 60 | struct audio_attributes_fields_t { |
Jean-Michel Trivi | 701d6ff | 2014-07-16 07:51:22 -0700 | [diff] [blame] | 61 | jfieldID fieldUsage; // AudioAttributes.mUsage |
| 62 | jfieldID fieldContentType; // AudioAttributes.mContentType |
| 63 | jfieldID fieldFlags; // AudioAttributes.mFlags |
| 64 | jfieldID fieldFormattedTags;// AudioAttributes.mFormattedTags |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 65 | }; |
| 66 | static audio_track_fields_t javaAudioTrackFields; |
| 67 | static audio_attributes_fields_t javaAudioAttrFields; |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 68 | static PlaybackParams::fields_t gPlaybackParamsFields; |
Andy Hung | 035d4ec | 2017-01-24 13:45:02 -0800 | [diff] [blame] | 69 | static VolumeShaperHelper::fields_t gVolumeShaperFields; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | |
| 71 | struct audiotrack_callback_cookie { |
| 72 | jclass audioTrack_class; |
| 73 | jobject audioTrack_ref; |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 74 | bool busy; |
| 75 | Condition cond; |
Jean-Michel Trivi | 980d38f | 2018-01-08 15:43:35 -0800 | [diff] [blame] | 76 | bool isOffload; |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 77 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | |
Glenn Kasten | 3d301cb | 2012-01-16 14:46:54 -0800 | [diff] [blame] | 79 | // keep these values in sync with AudioTrack.java |
| 80 | #define MODE_STATIC 0 |
| 81 | #define MODE_STREAM 1 |
| 82 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | // ---------------------------------------------------------------------------- |
| 84 | class AudioTrackJniStorage { |
| 85 | public: |
| 86 | sp<MemoryHeapBase> mMemHeap; |
| 87 | sp<MemoryBase> mMemBase; |
| 88 | audiotrack_callback_cookie mCallbackData; |
Eric Laurent | 4bcdba8 | 2015-05-01 11:37:49 -0700 | [diff] [blame] | 89 | sp<JNIDeviceCallback> mDeviceCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | |
| 91 | AudioTrackJniStorage() { |
Jean-Michel Trivi | 8a14968 | 2009-07-15 18:31:11 -0700 | [diff] [blame] | 92 | mCallbackData.audioTrack_class = 0; |
| 93 | mCallbackData.audioTrack_ref = 0; |
Jean-Michel Trivi | 980d38f | 2018-01-08 15:43:35 -0800 | [diff] [blame] | 94 | mCallbackData.isOffload = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | ~AudioTrackJniStorage() { |
| 98 | mMemBase.clear(); |
| 99 | mMemHeap.clear(); |
| 100 | } |
| 101 | |
| 102 | bool allocSharedMem(int sizeInBytes) { |
| 103 | mMemHeap = new MemoryHeapBase(sizeInBytes, 0, "AudioTrack Heap Base"); |
| 104 | if (mMemHeap->getHeapID() < 0) { |
| 105 | return false; |
| 106 | } |
| 107 | mMemBase = new MemoryBase(mMemHeap, 0, sizeInBytes); |
| 108 | return true; |
| 109 | } |
| 110 | }; |
| 111 | |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 112 | static Mutex sLock; |
| 113 | static SortedVector <audiotrack_callback_cookie *> sAudioTrackCallBackCookies; |
| 114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | // ---------------------------------------------------------------------------- |
| 116 | #define DEFAULT_OUTPUT_SAMPLE_RATE 44100 |
| 117 | |
Chih-Hung Hsieh | 0ca16ef | 2016-05-19 15:14:54 -0700 | [diff] [blame] | 118 | #define AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM (-16) |
| 119 | #define AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK (-17) |
| 120 | #define AUDIOTRACK_ERROR_SETUP_INVALIDFORMAT (-18) |
| 121 | #define AUDIOTRACK_ERROR_SETUP_INVALIDSTREAMTYPE (-19) |
| 122 | #define AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED (-20) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | // ---------------------------------------------------------------------------- |
Glenn Kasten | e46a86f | 2011-06-01 15:20:35 -0700 | [diff] [blame] | 125 | static void audioCallback(int event, void* user, void *info) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 126 | |
| 127 | audiotrack_callback_cookie *callbackInfo = (audiotrack_callback_cookie *)user; |
| 128 | { |
| 129 | Mutex::Autolock l(sLock); |
| 130 | if (sAudioTrackCallBackCookies.indexOf(callbackInfo) < 0) { |
| 131 | return; |
| 132 | } |
| 133 | callbackInfo->busy = true; |
| 134 | } |
| 135 | |
Glenn Kasten | 5b1576c | 2013-07-18 16:58:19 -0700 | [diff] [blame] | 136 | switch (event) { |
Jean-Michel Trivi | 980d38f | 2018-01-08 15:43:35 -0800 | [diff] [blame] | 137 | // Offload only events |
| 138 | case AudioTrack::EVENT_STREAM_END: |
| 139 | case AudioTrack::EVENT_MORE_DATA: |
| 140 | // a.k.a. tear down |
| 141 | case AudioTrack::EVENT_NEW_IAUDIOTRACK: |
| 142 | if (callbackInfo->isOffload) { |
| 143 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 144 | if (user != NULL && env != NULL) { |
| 145 | env->CallStaticVoidMethod( |
| 146 | callbackInfo->audioTrack_class, |
| 147 | javaAudioTrackFields.postNativeEventInJava, |
| 148 | callbackInfo->audioTrack_ref, event, 0,0, NULL); |
| 149 | if (env->ExceptionCheck()) { |
| 150 | env->ExceptionDescribe(); |
| 151 | env->ExceptionClear(); |
| 152 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | } |
Glenn Kasten | 5b1576c | 2013-07-18 16:58:19 -0700 | [diff] [blame] | 154 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | |
Jean-Michel Trivi | 980d38f | 2018-01-08 15:43:35 -0800 | [diff] [blame] | 156 | // PCM and offload events |
| 157 | case AudioTrack::EVENT_MARKER: |
Glenn Kasten | 5b1576c | 2013-07-18 16:58:19 -0700 | [diff] [blame] | 158 | case AudioTrack::EVENT_NEW_POS: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
Glenn Kasten | a667ff3 | 2013-07-22 07:36:34 -0700 | [diff] [blame] | 160 | if (user != NULL && env != NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | env->CallStaticVoidMethod( |
Jean-Michel Trivi | 980d38f | 2018-01-08 15:43:35 -0800 | [diff] [blame] | 162 | callbackInfo->audioTrack_class, |
| 163 | javaAudioTrackFields.postNativeEventInJava, |
| 164 | callbackInfo->audioTrack_ref, event, 0,0, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | if (env->ExceptionCheck()) { |
| 166 | env->ExceptionDescribe(); |
| 167 | env->ExceptionClear(); |
| 168 | } |
| 169 | } |
Glenn Kasten | 5b1576c | 2013-07-18 16:58:19 -0700 | [diff] [blame] | 170 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | } |
Glenn Kasten | 5b1576c | 2013-07-18 16:58:19 -0700 | [diff] [blame] | 172 | |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 173 | { |
| 174 | Mutex::Autolock l(sLock); |
| 175 | callbackInfo->busy = false; |
| 176 | callbackInfo->cond.broadcast(); |
| 177 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | |
| 181 | // ---------------------------------------------------------------------------- |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 182 | static sp<AudioTrack> getAudioTrack(JNIEnv* env, jobject thiz) |
| 183 | { |
| 184 | Mutex::Autolock l(sLock); |
| 185 | AudioTrack* const at = |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 186 | (AudioTrack*)env->GetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj); |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 187 | return sp<AudioTrack>(at); |
| 188 | } |
| 189 | |
| 190 | static sp<AudioTrack> setAudioTrack(JNIEnv* env, jobject thiz, const sp<AudioTrack>& at) |
| 191 | { |
| 192 | Mutex::Autolock l(sLock); |
| 193 | sp<AudioTrack> old = |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 194 | (AudioTrack*)env->GetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj); |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 195 | if (at.get()) { |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 196 | at->incStrong((void*)setAudioTrack); |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 197 | } |
| 198 | if (old != 0) { |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 199 | old->decStrong((void*)setAudioTrack); |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 200 | } |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 201 | env->SetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj, (jlong)at.get()); |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 202 | return old; |
| 203 | } |
Wei Jia | 071a8b7 | 2015-03-09 16:38:25 -0700 | [diff] [blame] | 204 | |
| 205 | // ---------------------------------------------------------------------------- |
| 206 | sp<AudioTrack> android_media_AudioTrack_getAudioTrack(JNIEnv* env, jobject audioTrackObj) { |
| 207 | return getAudioTrack(env, audioTrackObj); |
| 208 | } |
| 209 | |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 210 | // ---------------------------------------------------------------------------- |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 211 | static jint |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 212 | android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject weak_this, jobject jaa, |
Glenn Kasten | 1cbf9b3 | 2016-02-02 12:04:09 -0800 | [diff] [blame] | 213 | jintArray jSampleRate, jint channelPositionMask, jint channelIndexMask, |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 214 | jint audioFormat, jint buffSizeInBytes, jint memoryMode, jintArray jSession, |
Jean-Michel Trivi | 980d38f | 2018-01-08 15:43:35 -0800 | [diff] [blame] | 215 | jlong nativeAudioTrack, jboolean offload) { |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 216 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 217 | ALOGV("sampleRates=%p, channel mask=%x, index mask=%x, audioFormat(Java)=%d, buffSize=%d" |
Ben Wagner | 85ea32b | 2016-03-16 17:10:42 -0400 | [diff] [blame] | 218 | "nativeAudioTrack=0x%" PRIX64, |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 219 | jSampleRate, channelPositionMask, channelIndexMask, audioFormat, buffSizeInBytes, |
| 220 | nativeAudioTrack); |
Glenn Kasten | 1cbf9b3 | 2016-02-02 12:04:09 -0800 | [diff] [blame] | 221 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 222 | sp<AudioTrack> lpTrack = 0; |
Eric Laurent | 2fb43ef | 2010-09-24 12:03:36 -0700 | [diff] [blame] | 223 | |
| 224 | if (jSession == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 225 | ALOGE("Error creating AudioTrack: invalid session ID pointer"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 226 | return (jint) AUDIO_JAVA_ERROR; |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Eric Laurent | 2fb43ef | 2010-09-24 12:03:36 -0700 | [diff] [blame] | 229 | jint* nSession = (jint *) env->GetPrimitiveArrayCritical(jSession, NULL); |
| 230 | if (nSession == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 231 | ALOGE("Error creating AudioTrack: Error retrieving session id pointer"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 232 | return (jint) AUDIO_JAVA_ERROR; |
Eric Laurent | 2fb43ef | 2010-09-24 12:03:36 -0700 | [diff] [blame] | 233 | } |
Glenn Kasten | 33b8404 | 2016-03-08 12:02:55 -0800 | [diff] [blame] | 234 | audio_session_t sessionId = (audio_session_t) nSession[0]; |
Eric Laurent | 2fb43ef | 2010-09-24 12:03:36 -0700 | [diff] [blame] | 235 | env->ReleasePrimitiveArrayCritical(jSession, nSession, 0); |
| 236 | nSession = NULL; |
| 237 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 238 | AudioTrackJniStorage* lpJniStorage = NULL; |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 239 | |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 240 | audio_attributes_t *paa = NULL; |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 241 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 242 | jclass clazz = env->GetObjectClass(thiz); |
| 243 | if (clazz == NULL) { |
| 244 | ALOGE("Can't find %s when setting up callback.", kClassPathName); |
| 245 | return (jint) AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED; |
| 246 | } |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 247 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 248 | // if we pass in an existing *Native* AudioTrack, we don't need to create/initialize one. |
| 249 | if (nativeAudioTrack == 0) { |
| 250 | if (jaa == 0) { |
| 251 | ALOGE("Error creating AudioTrack: invalid audio attributes"); |
| 252 | return (jint) AUDIO_JAVA_ERROR; |
| 253 | } |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 254 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 255 | if (jSampleRate == 0) { |
| 256 | ALOGE("Error creating AudioTrack: invalid sample rates"); |
| 257 | return (jint) AUDIO_JAVA_ERROR; |
| 258 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 260 | int* sampleRates = env->GetIntArrayElements(jSampleRate, NULL); |
| 261 | int sampleRateInHertz = sampleRates[0]; |
| 262 | env->ReleaseIntArrayElements(jSampleRate, sampleRates, JNI_ABORT); |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 263 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 264 | // Invalid channel representations are caught by !audio_is_output_channel() below. |
| 265 | audio_channel_mask_t nativeChannelMask = nativeChannelMaskFromJavaChannelMasks( |
| 266 | channelPositionMask, channelIndexMask); |
| 267 | if (!audio_is_output_channel(nativeChannelMask)) { |
| 268 | ALOGE("Error creating AudioTrack: invalid native channel mask %#x.", nativeChannelMask); |
| 269 | return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK; |
| 270 | } |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 271 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 272 | uint32_t channelCount = audio_channel_count_from_out_mask(nativeChannelMask); |
| 273 | |
| 274 | // check the format. |
| 275 | // This function was called from Java, so we compare the format against the Java constants |
| 276 | audio_format_t format = audioFormatToNative(audioFormat); |
| 277 | if (format == AUDIO_FORMAT_INVALID) { |
| 278 | ALOGE("Error creating AudioTrack: unsupported audio format %d.", audioFormat); |
| 279 | return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDFORMAT; |
| 280 | } |
| 281 | |
| 282 | // compute the frame count |
| 283 | size_t frameCount; |
| 284 | if (audio_is_linear_pcm(format)) { |
| 285 | const size_t bytesPerSample = audio_bytes_per_sample(format); |
| 286 | frameCount = buffSizeInBytes / (channelCount * bytesPerSample); |
| 287 | } else { |
| 288 | frameCount = buffSizeInBytes; |
| 289 | } |
| 290 | |
| 291 | // create the native AudioTrack object |
| 292 | lpTrack = new AudioTrack(); |
| 293 | |
| 294 | // read the AudioAttributes values |
| 295 | paa = (audio_attributes_t *) calloc(1, sizeof(audio_attributes_t)); |
| 296 | const jstring jtags = |
| 297 | (jstring) env->GetObjectField(jaa, javaAudioAttrFields.fieldFormattedTags); |
| 298 | const char* tags = env->GetStringUTFChars(jtags, NULL); |
| 299 | // copying array size -1, char array for tags was calloc'd, no need to NULL-terminate it |
| 300 | strncpy(paa->tags, tags, AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); |
| 301 | env->ReleaseStringUTFChars(jtags, tags); |
| 302 | paa->usage = (audio_usage_t) env->GetIntField(jaa, javaAudioAttrFields.fieldUsage); |
| 303 | paa->content_type = |
| 304 | (audio_content_type_t) env->GetIntField(jaa, javaAudioAttrFields.fieldContentType); |
| 305 | paa->flags = env->GetIntField(jaa, javaAudioAttrFields.fieldFlags); |
| 306 | |
| 307 | ALOGV("AudioTrack_setup for usage=%d content=%d flags=0x%#x tags=%s", |
| 308 | paa->usage, paa->content_type, paa->flags, paa->tags); |
| 309 | |
| 310 | // initialize the callback information: |
| 311 | // this data will be passed with every AudioTrack callback |
| 312 | lpJniStorage = new AudioTrackJniStorage(); |
| 313 | lpJniStorage->mCallbackData.audioTrack_class = (jclass)env->NewGlobalRef(clazz); |
| 314 | // we use a weak reference so the AudioTrack object can be garbage collected. |
| 315 | lpJniStorage->mCallbackData.audioTrack_ref = env->NewGlobalRef(weak_this); |
Jean-Michel Trivi | 980d38f | 2018-01-08 15:43:35 -0800 | [diff] [blame] | 316 | lpJniStorage->mCallbackData.isOffload = offload; |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 317 | lpJniStorage->mCallbackData.busy = false; |
| 318 | |
Jean-Michel Trivi | 980d38f | 2018-01-08 15:43:35 -0800 | [diff] [blame] | 319 | audio_offload_info_t offloadInfo; |
| 320 | if (offload) { |
| 321 | offloadInfo = AUDIO_INFO_INITIALIZER; |
| 322 | offloadInfo.format = format; |
| 323 | offloadInfo.sample_rate = sampleRateInHertz; |
| 324 | offloadInfo.channel_mask = nativeChannelMask; |
| 325 | offloadInfo.has_video = false; |
| 326 | offloadInfo.stream_type = AUDIO_STREAM_MUSIC; //required for offload |
| 327 | } |
| 328 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 329 | // initialize the native AudioTrack object |
| 330 | status_t status = NO_ERROR; |
| 331 | switch (memoryMode) { |
| 332 | case MODE_STREAM: |
| 333 | |
| 334 | status = lpTrack->set( |
| 335 | AUDIO_STREAM_DEFAULT,// stream type, but more info conveyed in paa (last argument) |
| 336 | sampleRateInHertz, |
| 337 | format,// word length, PCM |
| 338 | nativeChannelMask, |
| 339 | frameCount, |
| 340 | AUDIO_OUTPUT_FLAG_NONE, |
| 341 | audioCallback, &(lpJniStorage->mCallbackData),//callback, callback data (user) |
| 342 | 0,// notificationFrames == 0 since not using EVENT_MORE_DATA to feed the AudioTrack |
| 343 | 0,// shared mem |
| 344 | true,// thread can call Java |
| 345 | sessionId,// audio session ID |
| 346 | AudioTrack::TRANSFER_SYNC, |
Jean-Michel Trivi | 980d38f | 2018-01-08 15:43:35 -0800 | [diff] [blame] | 347 | offload ? &offloadInfo : NULL, |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 348 | -1, -1, // default uid, pid values |
| 349 | paa); |
| 350 | break; |
| 351 | |
| 352 | case MODE_STATIC: |
| 353 | // AudioTrack is using shared memory |
| 354 | |
| 355 | if (!lpJniStorage->allocSharedMem(buffSizeInBytes)) { |
| 356 | ALOGE("Error creating AudioTrack in static mode: error creating mem heap base"); |
| 357 | goto native_init_failure; |
| 358 | } |
| 359 | |
| 360 | status = lpTrack->set( |
| 361 | AUDIO_STREAM_DEFAULT,// stream type, but more info conveyed in paa (last argument) |
| 362 | sampleRateInHertz, |
| 363 | format,// word length, PCM |
| 364 | nativeChannelMask, |
| 365 | frameCount, |
| 366 | AUDIO_OUTPUT_FLAG_NONE, |
| 367 | audioCallback, &(lpJniStorage->mCallbackData),//callback, callback data (user)); |
| 368 | 0,// notificationFrames == 0 since not using EVENT_MORE_DATA to feed the AudioTrack |
| 369 | lpJniStorage->mMemBase,// shared mem |
| 370 | true,// thread can call Java |
| 371 | sessionId,// audio session ID |
| 372 | AudioTrack::TRANSFER_SHARED, |
| 373 | NULL, // default offloadInfo |
| 374 | -1, -1, // default uid, pid values |
| 375 | paa); |
| 376 | break; |
| 377 | |
| 378 | default: |
| 379 | ALOGE("Unknown mode %d", memoryMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | goto native_init_failure; |
| 381 | } |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 382 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 383 | if (status != NO_ERROR) { |
| 384 | ALOGE("Error %d initializing AudioTrack", status); |
| 385 | goto native_init_failure; |
| 386 | } |
| 387 | } else { // end if (nativeAudioTrack == 0) |
| 388 | lpTrack = (AudioTrack*)nativeAudioTrack; |
| 389 | // TODO: We need to find out which members of the Java AudioTrack might |
| 390 | // need to be initialized from the Native AudioTrack |
| 391 | // these are directly returned from getters: |
| 392 | // mSampleRate |
| 393 | // mAudioFormat |
| 394 | // mStreamType |
| 395 | // mChannelConfiguration |
| 396 | // mChannelCount |
| 397 | // mState (?) |
| 398 | // mPlayState (?) |
| 399 | // these may be used internally (Java AudioTrack.audioParamCheck(): |
| 400 | // mChannelMask |
| 401 | // mChannelIndexMask |
| 402 | // mDataLoadMode |
Glenn Kasten | 3d301cb | 2012-01-16 14:46:54 -0800 | [diff] [blame] | 403 | |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 404 | // initialize the callback information: |
| 405 | // this data will be passed with every AudioTrack callback |
| 406 | lpJniStorage = new AudioTrackJniStorage(); |
| 407 | lpJniStorage->mCallbackData.audioTrack_class = (jclass)env->NewGlobalRef(clazz); |
| 408 | // we use a weak reference so the AudioTrack object can be garbage collected. |
| 409 | lpJniStorage->mCallbackData.audioTrack_ref = env->NewGlobalRef(weak_this); |
| 410 | lpJniStorage->mCallbackData.busy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | } |
| 412 | |
Eric Laurent | 2fb43ef | 2010-09-24 12:03:36 -0700 | [diff] [blame] | 413 | nSession = (jint *) env->GetPrimitiveArrayCritical(jSession, NULL); |
| 414 | if (nSession == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 415 | ALOGE("Error creating AudioTrack: Error retrieving session id pointer"); |
Eric Laurent | 2fb43ef | 2010-09-24 12:03:36 -0700 | [diff] [blame] | 416 | goto native_init_failure; |
| 417 | } |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 418 | // read the audio session ID back from AudioTrack in case we create a new session |
| 419 | nSession[0] = lpTrack->getSessionId(); |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 420 | env->ReleasePrimitiveArrayCritical(jSession, nSession, 0); |
| 421 | nSession = NULL; |
| 422 | |
Glenn Kasten | 1cbf9b3 | 2016-02-02 12:04:09 -0800 | [diff] [blame] | 423 | { |
| 424 | const jint elements[1] = { (jint) lpTrack->getSampleRate() }; |
| 425 | env->SetIntArrayRegion(jSampleRate, 0, 1, elements); |
| 426 | } |
| 427 | |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 428 | { // scope for the lock |
| 429 | Mutex::Autolock l(sLock); |
| 430 | sAudioTrackCallBackCookies.add(&lpJniStorage->mCallbackData); |
| 431 | } |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 432 | // save our newly created C++ AudioTrack in the "nativeTrackInJavaObj" field |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | // of the Java object (in mNativeTrackInJavaObj) |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 434 | setAudioTrack(env, thiz, lpTrack); |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | // save the JNI resources so we can free them later |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 437 | //ALOGV("storing lpJniStorage: %x\n", (long)lpJniStorage); |
| 438 | env->SetLongField(thiz, javaAudioTrackFields.jniData, (jlong)lpJniStorage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 440 | // since we had audio attributes, the stream type was derived from them during the |
| 441 | // creation of the native AudioTrack: push the same value to the Java object |
| 442 | env->SetIntField(thiz, javaAudioTrackFields.fieldStreamType, (jint) lpTrack->streamType()); |
Paul McLean | 9b09e53 | 2016-01-26 14:43:35 -0700 | [diff] [blame] | 443 | if (paa != NULL) { |
| 444 | // audio attributes were copied in AudioTrack creation |
| 445 | free(paa); |
| 446 | paa = NULL; |
| 447 | } |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 448 | |
| 449 | |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 450 | return (jint) AUDIO_JAVA_SUCCESS; |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | // failures: |
| 453 | native_init_failure: |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 454 | if (paa != NULL) { |
| 455 | free(paa); |
| 456 | } |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 457 | if (nSession != NULL) { |
| 458 | env->ReleasePrimitiveArrayCritical(jSession, nSession, 0); |
| 459 | } |
Jean-Michel Trivi | 8a14968 | 2009-07-15 18:31:11 -0700 | [diff] [blame] | 460 | env->DeleteGlobalRef(lpJniStorage->mCallbackData.audioTrack_class); |
| 461 | env->DeleteGlobalRef(lpJniStorage->mCallbackData.audioTrack_ref); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | delete lpJniStorage; |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 463 | env->SetLongField(thiz, javaAudioTrackFields.jniData, 0); |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 464 | |
Glenn Kasten | 14d226a | 2015-05-18 13:53:39 -0700 | [diff] [blame] | 465 | // lpTrack goes out of scope, so reference count drops to zero |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 466 | return (jint) AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | } |
| 468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | // ---------------------------------------------------------------------------- |
| 470 | static void |
| 471 | android_media_AudioTrack_start(JNIEnv *env, jobject thiz) |
| 472 | { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 473 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 474 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | jniThrowException(env, "java/lang/IllegalStateException", |
| 476 | "Unable to retrieve AudioTrack pointer for start()"); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 477 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | } |
Jean-Michel Trivi | 21dc037 | 2009-05-08 16:06:34 -0700 | [diff] [blame] | 479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | lpTrack->start(); |
| 481 | } |
| 482 | |
| 483 | |
| 484 | // ---------------------------------------------------------------------------- |
| 485 | static void |
| 486 | android_media_AudioTrack_stop(JNIEnv *env, jobject thiz) |
| 487 | { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 488 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 489 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | jniThrowException(env, "java/lang/IllegalStateException", |
| 491 | "Unable to retrieve AudioTrack pointer for stop()"); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 492 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | lpTrack->stop(); |
| 496 | } |
| 497 | |
| 498 | |
| 499 | // ---------------------------------------------------------------------------- |
| 500 | static void |
| 501 | android_media_AudioTrack_pause(JNIEnv *env, jobject thiz) |
| 502 | { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 503 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 504 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | jniThrowException(env, "java/lang/IllegalStateException", |
| 506 | "Unable to retrieve AudioTrack pointer for pause()"); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 507 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | lpTrack->pause(); |
| 511 | } |
| 512 | |
| 513 | |
| 514 | // ---------------------------------------------------------------------------- |
| 515 | static void |
| 516 | android_media_AudioTrack_flush(JNIEnv *env, jobject thiz) |
| 517 | { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 518 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 519 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | jniThrowException(env, "java/lang/IllegalStateException", |
| 521 | "Unable to retrieve AudioTrack pointer for flush()"); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 522 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | lpTrack->flush(); |
| 526 | } |
| 527 | |
| 528 | // ---------------------------------------------------------------------------- |
| 529 | static void |
| 530 | android_media_AudioTrack_set_volume(JNIEnv *env, jobject thiz, jfloat leftVol, jfloat rightVol ) |
| 531 | { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 532 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 533 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | jniThrowException(env, "java/lang/IllegalStateException", |
| 535 | "Unable to retrieve AudioTrack pointer for setVolume()"); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 536 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | lpTrack->setVolume(leftVol, rightVol); |
| 540 | } |
| 541 | |
| 542 | // ---------------------------------------------------------------------------- |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 543 | |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 544 | #define CALLBACK_COND_WAIT_TIMEOUT_MS 1000 |
Jean-Michel Trivi | eac8438 | 2014-02-04 14:50:40 -0800 | [diff] [blame] | 545 | static void android_media_AudioTrack_release(JNIEnv *env, jobject thiz) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 546 | sp<AudioTrack> lpTrack = setAudioTrack(env, thiz, 0); |
| 547 | if (lpTrack == NULL) { |
| 548 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | } |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 550 | //ALOGV("deleting lpTrack: %x\n", (int)lpTrack); |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | // delete the JNI data |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 553 | AudioTrackJniStorage* pJniStorage = (AudioTrackJniStorage *)env->GetLongField( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | thiz, javaAudioTrackFields.jniData); |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 555 | // reset the native resources in the Java object so any attempt to access |
| 556 | // them after a call to release fails. |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 557 | env->SetLongField(thiz, javaAudioTrackFields.jniData, 0); |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | if (pJniStorage) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 560 | Mutex::Autolock l(sLock); |
| 561 | audiotrack_callback_cookie *lpCookie = &pJniStorage->mCallbackData; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 562 | //ALOGV("deleting pJniStorage: %x\n", (int)pJniStorage); |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 563 | while (lpCookie->busy) { |
| 564 | if (lpCookie->cond.waitRelative(sLock, |
| 565 | milliseconds(CALLBACK_COND_WAIT_TIMEOUT_MS)) != |
| 566 | NO_ERROR) { |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | sAudioTrackCallBackCookies.remove(lpCookie); |
| 571 | // delete global refs created in native_setup |
| 572 | env->DeleteGlobalRef(lpCookie->audioTrack_class); |
| 573 | env->DeleteGlobalRef(lpCookie->audioTrack_ref); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | delete pJniStorage; |
| 575 | } |
| 576 | } |
| 577 | |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 578 | |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 579 | // ---------------------------------------------------------------------------- |
Jean-Michel Trivi | eac8438 | 2014-02-04 14:50:40 -0800 | [diff] [blame] | 580 | static void android_media_AudioTrack_finalize(JNIEnv *env, jobject thiz) { |
| 581 | //ALOGV("android_media_AudioTrack_finalize jobject: %x\n", (int)thiz); |
| 582 | android_media_AudioTrack_release(env, thiz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | } |
| 584 | |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 585 | // overloaded JNI array helper functions (same as in android_media_AudioRecord) |
| 586 | static inline |
| 587 | jbyte *envGetArrayElements(JNIEnv *env, jbyteArray array, jboolean *isCopy) { |
| 588 | return env->GetByteArrayElements(array, isCopy); |
| 589 | } |
| 590 | |
| 591 | static inline |
| 592 | void envReleaseArrayElements(JNIEnv *env, jbyteArray array, jbyte *elems, jint mode) { |
| 593 | env->ReleaseByteArrayElements(array, elems, mode); |
| 594 | } |
| 595 | |
| 596 | static inline |
| 597 | jshort *envGetArrayElements(JNIEnv *env, jshortArray array, jboolean *isCopy) { |
| 598 | return env->GetShortArrayElements(array, isCopy); |
| 599 | } |
| 600 | |
| 601 | static inline |
| 602 | void envReleaseArrayElements(JNIEnv *env, jshortArray array, jshort *elems, jint mode) { |
| 603 | env->ReleaseShortArrayElements(array, elems, mode); |
| 604 | } |
| 605 | |
| 606 | static inline |
| 607 | jfloat *envGetArrayElements(JNIEnv *env, jfloatArray array, jboolean *isCopy) { |
| 608 | return env->GetFloatArrayElements(array, isCopy); |
| 609 | } |
| 610 | |
| 611 | static inline |
| 612 | void envReleaseArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems, jint mode) { |
| 613 | env->ReleaseFloatArrayElements(array, elems, mode); |
| 614 | } |
| 615 | |
Eric Laurent | 219de73 | 2016-05-23 12:41:50 -0700 | [diff] [blame] | 616 | static inline |
| 617 | jint interpretWriteSizeError(ssize_t writeSize) { |
| 618 | if (writeSize == WOULD_BLOCK) { |
| 619 | return (jint)0; |
| 620 | } else if (writeSize == NO_INIT) { |
| 621 | return AUDIO_JAVA_DEAD_OBJECT; |
| 622 | } else { |
| 623 | ALOGE("Error %zd during AudioTrack native read", writeSize); |
| 624 | return nativeToJavaStatus(writeSize); |
| 625 | } |
| 626 | } |
| 627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | // ---------------------------------------------------------------------------- |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 629 | template <typename T> |
| 630 | static jint writeToTrack(const sp<AudioTrack>& track, jint audioFormat, const T *data, |
| 631 | jint offsetInSamples, jint sizeInSamples, bool blocking) { |
Jean-Michel Trivi | 21dc037 | 2009-05-08 16:06:34 -0700 | [diff] [blame] | 632 | // give the data to the native AudioTrack object (the data starts at the offset) |
| 633 | ssize_t written = 0; |
| 634 | // regular write() or copy the data to the AudioTrack's shared memory? |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 635 | size_t sizeInBytes = sizeInSamples * sizeof(T); |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 636 | if (track->sharedBuffer() == 0) { |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 637 | written = track->write(data + offsetInSamples, sizeInBytes, blocking); |
Glenn Kasten | 9b53db3 | 2013-07-10 14:13:39 -0700 | [diff] [blame] | 638 | // for compatibility with earlier behavior of write(), return 0 in this case |
| 639 | if (written == (ssize_t) WOULD_BLOCK) { |
| 640 | written = 0; |
| 641 | } |
Jean-Michel Trivi | 21dc037 | 2009-05-08 16:06:34 -0700 | [diff] [blame] | 642 | } else { |
Andy Hung | 2c0e17c | 2015-01-12 15:07:14 -0800 | [diff] [blame] | 643 | // writing to shared memory, check for capacity |
| 644 | if ((size_t)sizeInBytes > track->sharedBuffer()->size()) { |
| 645 | sizeInBytes = track->sharedBuffer()->size(); |
Jean-Michel Trivi | 21dc037 | 2009-05-08 16:06:34 -0700 | [diff] [blame] | 646 | } |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 647 | memcpy(track->sharedBuffer()->pointer(), data + offsetInSamples, sizeInBytes); |
Andy Hung | 2c0e17c | 2015-01-12 15:07:14 -0800 | [diff] [blame] | 648 | written = sizeInBytes; |
Jean-Michel Trivi | 21dc037 | 2009-05-08 16:06:34 -0700 | [diff] [blame] | 649 | } |
Eric Laurent | 219de73 | 2016-05-23 12:41:50 -0700 | [diff] [blame] | 650 | if (written >= 0) { |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 651 | return written / sizeof(T); |
| 652 | } |
Eric Laurent | 219de73 | 2016-05-23 12:41:50 -0700 | [diff] [blame] | 653 | return interpretWriteSizeError(written); |
Jean-Michel Trivi | 21dc037 | 2009-05-08 16:06:34 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | // ---------------------------------------------------------------------------- |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 657 | template <typename T> |
| 658 | static jint android_media_AudioTrack_writeArray(JNIEnv *env, jobject thiz, |
| 659 | T javaAudioData, |
| 660 | jint offsetInSamples, jint sizeInSamples, |
| 661 | jint javaAudioFormat, |
| 662 | jboolean isWriteBlocking) { |
| 663 | //ALOGV("android_media_AudioTrack_writeArray(offset=%d, sizeInSamples=%d) called", |
| 664 | // offsetInSamples, sizeInSamples); |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 665 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | if (lpTrack == NULL) { |
| 667 | jniThrowException(env, "java/lang/IllegalStateException", |
| 668 | "Unable to retrieve AudioTrack pointer for write()"); |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 669 | return (jint)AUDIO_JAVA_INVALID_OPERATION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | } |
| 671 | |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 672 | if (javaAudioData == NULL) { |
| 673 | ALOGE("NULL java array of audio data to play"); |
| 674 | return (jint)AUDIO_JAVA_BAD_VALUE; |
| 675 | } |
| 676 | |
Eric Laurent | 421ddc0 | 2011-03-07 14:52:59 -0800 | [diff] [blame] | 677 | // NOTE: We may use GetPrimitiveArrayCritical() when the JNI implementation changes in such |
| 678 | // a way that it becomes much more efficient. When doing so, we will have to prevent the |
| 679 | // AudioSystem callback to be called while in critical section (in case of media server |
| 680 | // process crash for instance) |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 681 | |
| 682 | // get the pointer for the audio data from the java array |
| 683 | auto cAudioData = envGetArrayElements(env, javaAudioData, NULL); |
| 684 | if (cAudioData == NULL) { |
| 685 | ALOGE("Error retrieving source of audio data to play"); |
| 686 | return (jint)AUDIO_JAVA_BAD_VALUE; // out of memory or no data to load |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | } |
| 688 | |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 689 | jint samplesWritten = writeToTrack(lpTrack, javaAudioFormat, cAudioData, |
| 690 | offsetInSamples, sizeInSamples, isWriteBlocking == JNI_TRUE /* blocking */); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 692 | envReleaseArrayElements(env, javaAudioData, cAudioData, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 694 | //ALOGV("write wrote %d (tried %d) samples in the native AudioTrack with offset %d", |
| 695 | // (int)samplesWritten, (int)(sizeInSamples), (int)offsetInSamples); |
| 696 | return samplesWritten; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | } |
| 698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | // ---------------------------------------------------------------------------- |
Jean-Michel Trivi | 7ca0452 | 2014-02-07 09:39:34 -0800 | [diff] [blame] | 700 | static jint android_media_AudioTrack_write_native_bytes(JNIEnv *env, jobject thiz, |
Jean-Michel Trivi | 5d21f67 | 2014-03-20 17:02:31 -0700 | [diff] [blame] | 701 | jbyteArray javaBytes, jint byteOffset, jint sizeInBytes, |
Jean-Michel Trivi | 7ca0452 | 2014-02-07 09:39:34 -0800 | [diff] [blame] | 702 | jint javaAudioFormat, jboolean isWriteBlocking) { |
| 703 | //ALOGV("android_media_AudioTrack_write_native_bytes(offset=%d, sizeInBytes=%d) called", |
| 704 | // offsetInBytes, sizeInBytes); |
| 705 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 706 | if (lpTrack == NULL) { |
| 707 | jniThrowException(env, "java/lang/IllegalStateException", |
| 708 | "Unable to retrieve AudioTrack pointer for write()"); |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 709 | return (jint)AUDIO_JAVA_INVALID_OPERATION; |
Jean-Michel Trivi | 7ca0452 | 2014-02-07 09:39:34 -0800 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | ScopedBytesRO bytes(env, javaBytes); |
| 713 | if (bytes.get() == NULL) { |
| 714 | ALOGE("Error retrieving source of audio data to play, can't play"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 715 | return (jint)AUDIO_JAVA_BAD_VALUE; |
Jean-Michel Trivi | 7ca0452 | 2014-02-07 09:39:34 -0800 | [diff] [blame] | 716 | } |
| 717 | |
Jean-Michel Trivi | 5d21f67 | 2014-03-20 17:02:31 -0700 | [diff] [blame] | 718 | jint written = writeToTrack(lpTrack, javaAudioFormat, bytes.get(), byteOffset, |
Jean-Michel Trivi | 7ca0452 | 2014-02-07 09:39:34 -0800 | [diff] [blame] | 719 | sizeInBytes, isWriteBlocking == JNI_TRUE /* blocking */); |
| 720 | |
| 721 | return written; |
| 722 | } |
| 723 | |
| 724 | // ---------------------------------------------------------------------------- |
Phil Burk | 10a33e4 | 2016-01-08 12:40:41 -0800 | [diff] [blame] | 725 | static jint android_media_AudioTrack_get_buffer_size_frames(JNIEnv *env, jobject thiz) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 726 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 727 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | jniThrowException(env, "java/lang/IllegalStateException", |
Phil Burk | 10a33e4 | 2016-01-08 12:40:41 -0800 | [diff] [blame] | 729 | "Unable to retrieve AudioTrack pointer for getBufferSizeInFrames()"); |
| 730 | return (jint)AUDIO_JAVA_ERROR; |
| 731 | } |
| 732 | |
| 733 | ssize_t result = lpTrack->getBufferSizeInFrames(); |
| 734 | if (result < 0) { |
Ben Wagner | 85ea32b | 2016-03-16 17:10:42 -0400 | [diff] [blame] | 735 | jniThrowExceptionFmt(env, "java/lang/IllegalStateException", |
| 736 | "Internal error detected in getBufferSizeInFrames() = %zd", result); |
Phil Burk | 10a33e4 | 2016-01-08 12:40:41 -0800 | [diff] [blame] | 737 | return (jint)AUDIO_JAVA_ERROR; |
| 738 | } |
| 739 | return (jint)result; |
| 740 | } |
| 741 | |
| 742 | // ---------------------------------------------------------------------------- |
| 743 | static jint android_media_AudioTrack_set_buffer_size_frames(JNIEnv *env, |
| 744 | jobject thiz, jint bufferSizeInFrames) { |
| 745 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 746 | if (lpTrack == NULL) { |
| 747 | jniThrowException(env, "java/lang/IllegalStateException", |
| 748 | "Unable to retrieve AudioTrack pointer for setBufferSizeInFrames()"); |
| 749 | return (jint)AUDIO_JAVA_ERROR; |
| 750 | } |
| 751 | // Value will be coerced into the valid range. |
| 752 | // But internal values are unsigned, size_t, so we need to clip |
| 753 | // against zero here where it is signed. |
| 754 | if (bufferSizeInFrames < 0) { |
| 755 | bufferSizeInFrames = 0; |
| 756 | } |
| 757 | ssize_t result = lpTrack->setBufferSizeInFrames(bufferSizeInFrames); |
| 758 | if (result < 0) { |
Ben Wagner | 85ea32b | 2016-03-16 17:10:42 -0400 | [diff] [blame] | 759 | jniThrowExceptionFmt(env, "java/lang/IllegalStateException", |
| 760 | "Internal error detected in setBufferSizeInFrames() = %zd", result); |
Phil Burk | 10a33e4 | 2016-01-08 12:40:41 -0800 | [diff] [blame] | 761 | return (jint)AUDIO_JAVA_ERROR; |
| 762 | } |
| 763 | return (jint)result; |
| 764 | } |
| 765 | |
| 766 | // ---------------------------------------------------------------------------- |
| 767 | static jint android_media_AudioTrack_get_buffer_capacity_frames(JNIEnv *env, jobject thiz) { |
| 768 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 769 | if (lpTrack == NULL) { |
| 770 | jniThrowException(env, "java/lang/IllegalStateException", |
| 771 | "Unable to retrieve AudioTrack pointer for getBufferCapacityInFrames()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 772 | return (jint)AUDIO_JAVA_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 773 | } |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 774 | |
| 775 | return lpTrack->frameCount(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | } |
| 777 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | // ---------------------------------------------------------------------------- |
Eric Laurent | 88e209d | 2009-07-07 07:10:45 -0700 | [diff] [blame] | 779 | static jint android_media_AudioTrack_set_playback_rate(JNIEnv *env, jobject thiz, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | jint sampleRateInHz) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 781 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 782 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | jniThrowException(env, "java/lang/IllegalStateException", |
| 784 | "Unable to retrieve AudioTrack pointer for setSampleRate()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 785 | return (jint)AUDIO_JAVA_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | } |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 787 | return nativeToJavaStatus(lpTrack->setSampleRate(sampleRateInHz)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | |
| 791 | // ---------------------------------------------------------------------------- |
| 792 | static jint android_media_AudioTrack_get_playback_rate(JNIEnv *env, jobject thiz) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 793 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 794 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | jniThrowException(env, "java/lang/IllegalStateException", |
| 796 | "Unable to retrieve AudioTrack pointer for getSampleRate()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 797 | return (jint)AUDIO_JAVA_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | } |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 799 | return (jint) lpTrack->getSampleRate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | |
| 803 | // ---------------------------------------------------------------------------- |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 804 | static void android_media_AudioTrack_set_playback_params(JNIEnv *env, jobject thiz, |
| 805 | jobject params) { |
Andy Hung | 263b4c9 | 2015-04-16 11:16:29 -0700 | [diff] [blame] | 806 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 807 | if (lpTrack == NULL) { |
| 808 | jniThrowException(env, "java/lang/IllegalStateException", |
| 809 | "AudioTrack not initialized"); |
| 810 | return; |
| 811 | } |
| 812 | |
Andy Hung | 973b885 | 2015-05-13 15:15:25 -0700 | [diff] [blame] | 813 | PlaybackParams pbp; |
| 814 | pbp.fillFromJobject(env, gPlaybackParamsFields, params); |
Andy Hung | fe48e0d | 2015-04-27 18:14:02 -0700 | [diff] [blame] | 815 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 816 | ALOGV("setPlaybackParams: %d:%f %d:%f %d:%u %d:%u", |
Andy Hung | 973b885 | 2015-05-13 15:15:25 -0700 | [diff] [blame] | 817 | pbp.speedSet, pbp.audioRate.mSpeed, |
| 818 | pbp.pitchSet, pbp.audioRate.mPitch, |
| 819 | pbp.audioFallbackModeSet, pbp.audioRate.mFallbackMode, |
| 820 | pbp.audioStretchModeSet, pbp.audioRate.mStretchMode); |
Andy Hung | fe48e0d | 2015-04-27 18:14:02 -0700 | [diff] [blame] | 821 | |
Andy Hung | 973b885 | 2015-05-13 15:15:25 -0700 | [diff] [blame] | 822 | // to simulate partially set params, we do a read-modify-write. |
| 823 | // TODO: pass in the valid set mask into AudioTrack. |
| 824 | AudioPlaybackRate rate = lpTrack->getPlaybackRate(); |
| 825 | bool updatedRate = false; |
| 826 | if (pbp.speedSet) { |
| 827 | rate.mSpeed = pbp.audioRate.mSpeed; |
| 828 | updatedRate = true; |
| 829 | } |
| 830 | if (pbp.pitchSet) { |
| 831 | rate.mPitch = pbp.audioRate.mPitch; |
| 832 | updatedRate = true; |
| 833 | } |
| 834 | if (pbp.audioFallbackModeSet) { |
| 835 | rate.mFallbackMode = pbp.audioRate.mFallbackMode; |
| 836 | updatedRate = true; |
| 837 | } |
| 838 | if (pbp.audioStretchModeSet) { |
| 839 | rate.mStretchMode = pbp.audioRate.mStretchMode; |
| 840 | updatedRate = true; |
| 841 | } |
| 842 | if (updatedRate) { |
| 843 | if (lpTrack->setPlaybackRate(rate) != OK) { |
| 844 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 845 | "arguments out of range"); |
| 846 | } |
Andy Hung | 263b4c9 | 2015-04-16 11:16:29 -0700 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | |
| 850 | |
| 851 | // ---------------------------------------------------------------------------- |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 852 | static jobject android_media_AudioTrack_get_playback_params(JNIEnv *env, jobject thiz, |
| 853 | jobject params) { |
Andy Hung | 263b4c9 | 2015-04-16 11:16:29 -0700 | [diff] [blame] | 854 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 855 | if (lpTrack == NULL) { |
| 856 | jniThrowException(env, "java/lang/IllegalStateException", |
| 857 | "AudioTrack not initialized"); |
Andy Hung | fe48e0d | 2015-04-27 18:14:02 -0700 | [diff] [blame] | 858 | return NULL; |
Andy Hung | 263b4c9 | 2015-04-16 11:16:29 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 861 | PlaybackParams pbs; |
Andy Hung | fe48e0d | 2015-04-27 18:14:02 -0700 | [diff] [blame] | 862 | pbs.audioRate = lpTrack->getPlaybackRate(); |
| 863 | pbs.speedSet = true; |
| 864 | pbs.pitchSet = true; |
| 865 | pbs.audioFallbackModeSet = true; |
| 866 | pbs.audioStretchModeSet = true; |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 867 | return pbs.asJobject(env, gPlaybackParamsFields); |
Andy Hung | 263b4c9 | 2015-04-16 11:16:29 -0700 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | |
| 871 | // ---------------------------------------------------------------------------- |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 872 | static jint android_media_AudioTrack_set_marker_pos(JNIEnv *env, jobject thiz, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 873 | jint markerPos) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 874 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 875 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | jniThrowException(env, "java/lang/IllegalStateException", |
| 877 | "Unable to retrieve AudioTrack pointer for setMarkerPosition()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 878 | return (jint)AUDIO_JAVA_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | } |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 880 | return nativeToJavaStatus( lpTrack->setMarkerPosition(markerPos) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | |
| 884 | // ---------------------------------------------------------------------------- |
| 885 | static jint android_media_AudioTrack_get_marker_pos(JNIEnv *env, jobject thiz) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 886 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 887 | uint32_t markerPos = 0; |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 888 | |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 889 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | jniThrowException(env, "java/lang/IllegalStateException", |
| 891 | "Unable to retrieve AudioTrack pointer for getMarkerPosition()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 892 | return (jint)AUDIO_JAVA_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | } |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 894 | lpTrack->getMarkerPosition(&markerPos); |
| 895 | return (jint)markerPos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | |
| 899 | // ---------------------------------------------------------------------------- |
| 900 | static jint android_media_AudioTrack_set_pos_update_period(JNIEnv *env, jobject thiz, |
| 901 | jint period) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 902 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 903 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 904 | jniThrowException(env, "java/lang/IllegalStateException", |
| 905 | "Unable to retrieve AudioTrack pointer for setPositionUpdatePeriod()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 906 | return (jint)AUDIO_JAVA_ERROR; |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 907 | } |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 908 | return nativeToJavaStatus( lpTrack->setPositionUpdatePeriod(period) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | |
| 912 | // ---------------------------------------------------------------------------- |
| 913 | static jint android_media_AudioTrack_get_pos_update_period(JNIEnv *env, jobject thiz) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 914 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | uint32_t period = 0; |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 916 | |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 917 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | jniThrowException(env, "java/lang/IllegalStateException", |
| 919 | "Unable to retrieve AudioTrack pointer for getPositionUpdatePeriod()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 920 | return (jint)AUDIO_JAVA_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | } |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 922 | lpTrack->getPositionUpdatePeriod(&period); |
| 923 | return (jint)period; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | |
| 927 | // ---------------------------------------------------------------------------- |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 928 | static jint android_media_AudioTrack_set_position(JNIEnv *env, jobject thiz, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | jint position) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 930 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 931 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | jniThrowException(env, "java/lang/IllegalStateException", |
| 933 | "Unable to retrieve AudioTrack pointer for setPosition()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 934 | return (jint)AUDIO_JAVA_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | } |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 936 | return nativeToJavaStatus( lpTrack->setPosition(position) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | |
| 940 | // ---------------------------------------------------------------------------- |
| 941 | static jint android_media_AudioTrack_get_position(JNIEnv *env, jobject thiz) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 942 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | uint32_t position = 0; |
Glenn Kasten | 18db49a | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 944 | |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 945 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 946 | jniThrowException(env, "java/lang/IllegalStateException", |
| 947 | "Unable to retrieve AudioTrack pointer for getPosition()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 948 | return (jint)AUDIO_JAVA_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | } |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 950 | lpTrack->getPosition(&position); |
| 951 | return (jint)position; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | |
| 955 | // ---------------------------------------------------------------------------- |
Oliver Woodman | 61dcdf3 | 2013-06-26 12:43:36 +0100 | [diff] [blame] | 956 | static jint android_media_AudioTrack_get_latency(JNIEnv *env, jobject thiz) { |
| 957 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 958 | |
| 959 | if (lpTrack == NULL) { |
| 960 | jniThrowException(env, "java/lang/IllegalStateException", |
| 961 | "Unable to retrieve AudioTrack pointer for latency()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 962 | return (jint)AUDIO_JAVA_ERROR; |
Oliver Woodman | 61dcdf3 | 2013-06-26 12:43:36 +0100 | [diff] [blame] | 963 | } |
| 964 | return (jint)lpTrack->latency(); |
| 965 | } |
| 966 | |
Phil Burk | 03f61bb | 2016-01-17 21:49:58 +0000 | [diff] [blame] | 967 | // ---------------------------------------------------------------------------- |
| 968 | static jint android_media_AudioTrack_get_underrun_count(JNIEnv *env, jobject thiz) { |
| 969 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 970 | |
| 971 | if (lpTrack == NULL) { |
| 972 | jniThrowException(env, "java/lang/IllegalStateException", |
| 973 | "Unable to retrieve AudioTrack pointer for getUnderrunCount()"); |
| 974 | return (jint)AUDIO_JAVA_ERROR; |
| 975 | } |
| 976 | return (jint)lpTrack->getUnderrunCount(); |
| 977 | } |
Oliver Woodman | 61dcdf3 | 2013-06-26 12:43:36 +0100 | [diff] [blame] | 978 | |
| 979 | // ---------------------------------------------------------------------------- |
Andy Hung | ebc2c14 | 2017-01-12 19:20:29 -0800 | [diff] [blame] | 980 | static jint android_media_AudioTrack_get_flags(JNIEnv *env, jobject thiz) { |
| 981 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 982 | |
| 983 | if (lpTrack == NULL) { |
| 984 | jniThrowException(env, "java/lang/IllegalStateException", |
| 985 | "Unable to retrieve AudioTrack pointer for getFlags()"); |
| 986 | return (jint)AUDIO_JAVA_ERROR; |
| 987 | } |
| 988 | return (jint)lpTrack->getFlags(); |
| 989 | } |
| 990 | |
| 991 | // ---------------------------------------------------------------------------- |
Glenn Kasten | 948c2e6 | 2013-09-04 13:51:29 -0700 | [diff] [blame] | 992 | static jint android_media_AudioTrack_get_timestamp(JNIEnv *env, jobject thiz, jlongArray jTimestamp) { |
| 993 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 994 | |
| 995 | if (lpTrack == NULL) { |
| 996 | ALOGE("Unable to retrieve AudioTrack pointer for getTimestamp()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 997 | return (jint)AUDIO_JAVA_ERROR; |
Glenn Kasten | 948c2e6 | 2013-09-04 13:51:29 -0700 | [diff] [blame] | 998 | } |
| 999 | AudioTimestamp timestamp; |
| 1000 | status_t status = lpTrack->getTimestamp(timestamp); |
| 1001 | if (status == OK) { |
| 1002 | jlong* nTimestamp = (jlong *) env->GetPrimitiveArrayCritical(jTimestamp, NULL); |
| 1003 | if (nTimestamp == NULL) { |
| 1004 | ALOGE("Unable to get array for getTimestamp()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 1005 | return (jint)AUDIO_JAVA_ERROR; |
Glenn Kasten | 948c2e6 | 2013-09-04 13:51:29 -0700 | [diff] [blame] | 1006 | } |
| 1007 | nTimestamp[0] = (jlong) timestamp.mPosition; |
| 1008 | nTimestamp[1] = (jlong) ((timestamp.mTime.tv_sec * 1000000000LL) + timestamp.mTime.tv_nsec); |
| 1009 | env->ReleasePrimitiveArrayCritical(jTimestamp, nTimestamp, 0); |
| 1010 | } |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 1011 | return (jint) nativeToJavaStatus(status); |
Glenn Kasten | 948c2e6 | 2013-09-04 13:51:29 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | |
| 1015 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1016 | static jint android_media_AudioTrack_set_loop(JNIEnv *env, jobject thiz, |
| 1017 | jint loopStart, jint loopEnd, jint loopCount) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 1018 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 1019 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1020 | jniThrowException(env, "java/lang/IllegalStateException", |
| 1021 | "Unable to retrieve AudioTrack pointer for setLoop()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 1022 | return (jint)AUDIO_JAVA_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | } |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 1024 | return nativeToJavaStatus( lpTrack->setLoop(loopStart, loopEnd, loopCount) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | // ---------------------------------------------------------------------------- |
| 1029 | static jint android_media_AudioTrack_reload(JNIEnv *env, jobject thiz) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 1030 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 1031 | if (lpTrack == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | jniThrowException(env, "java/lang/IllegalStateException", |
| 1033 | "Unable to retrieve AudioTrack pointer for reload()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 1034 | return (jint)AUDIO_JAVA_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | } |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 1036 | return nativeToJavaStatus( lpTrack->reload() ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | |
| 1040 | // ---------------------------------------------------------------------------- |
| 1041 | static jint android_media_AudioTrack_get_output_sample_rate(JNIEnv *env, jobject thiz, |
| 1042 | jint javaStreamType) { |
Glenn Kasten | 85fbc87 | 2012-11-14 13:21:09 -0800 | [diff] [blame] | 1043 | uint32_t afSamplingRate; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | // convert the stream type from Java to native value |
Jean-Michel Trivi | eac8438 | 2014-02-04 14:50:40 -0800 | [diff] [blame] | 1045 | // FIXME: code duplication with android_media_AudioTrack_setup() |
Dima Zavin | 24fc2fb | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1046 | audio_stream_type_t nativeStreamType; |
Glenn Kasten | 29a0909 | 2012-01-16 14:37:12 -0800 | [diff] [blame] | 1047 | switch (javaStreamType) { |
| 1048 | case AUDIO_STREAM_VOICE_CALL: |
| 1049 | case AUDIO_STREAM_SYSTEM: |
| 1050 | case AUDIO_STREAM_RING: |
| 1051 | case AUDIO_STREAM_MUSIC: |
| 1052 | case AUDIO_STREAM_ALARM: |
| 1053 | case AUDIO_STREAM_NOTIFICATION: |
| 1054 | case AUDIO_STREAM_BLUETOOTH_SCO: |
| 1055 | case AUDIO_STREAM_DTMF: |
| 1056 | nativeStreamType = (audio_stream_type_t) javaStreamType; |
| 1057 | break; |
| 1058 | default: |
Dima Zavin | 24fc2fb | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1059 | nativeStreamType = AUDIO_STREAM_DEFAULT; |
Glenn Kasten | 29a0909 | 2012-01-16 14:37:12 -0800 | [diff] [blame] | 1060 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1061 | } |
| 1062 | |
Glenn Kasten | 8f81d08 | 2012-11-28 14:37:48 -0800 | [diff] [blame] | 1063 | status_t status = AudioSystem::getOutputSamplingRate(&afSamplingRate, nativeStreamType); |
| 1064 | if (status != NO_ERROR) { |
| 1065 | ALOGE("Error %d in AudioSystem::getOutputSamplingRate() for stream type %d " |
| 1066 | "in AudioTrack JNI", status, nativeStreamType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | return DEFAULT_OUTPUT_SAMPLE_RATE; |
| 1068 | } else { |
| 1069 | return afSamplingRate; |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | |
| 1074 | // ---------------------------------------------------------------------------- |
| 1075 | // returns the minimum required size for the successful creation of a streaming AudioTrack |
| 1076 | // returns -1 if there was an error querying the hardware. |
| 1077 | static jint android_media_AudioTrack_get_min_buff_size(JNIEnv *env, jobject thiz, |
Glenn Kasten | 5b8fd44 | 2013-11-14 09:44:14 -0800 | [diff] [blame] | 1078 | jint sampleRateInHertz, jint channelCount, jint audioFormat) { |
Chia-chi Yeh | c330807 | 2010-08-19 17:14:36 +0800 | [diff] [blame] | 1079 | |
Glenn Kasten | 659a971 | 2014-01-08 11:38:33 -0800 | [diff] [blame] | 1080 | size_t frameCount; |
| 1081 | const status_t status = AudioTrack::getMinFrameCount(&frameCount, AUDIO_STREAM_DEFAULT, |
| 1082 | sampleRateInHertz); |
| 1083 | if (status != NO_ERROR) { |
| 1084 | ALOGE("AudioTrack::getMinFrameCount() for sample rate %d failed with status %d", |
| 1085 | sampleRateInHertz, status); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | return -1; |
| 1087 | } |
Glenn Kasten | fe834d3 | 2014-01-08 14:49:08 -0800 | [diff] [blame] | 1088 | const audio_format_t format = audioFormatToNative(audioFormat); |
Phil Burk | 43f4b27 | 2016-01-27 15:35:20 -0800 | [diff] [blame] | 1089 | if (audio_has_proportional_frames(format)) { |
Eric Laurent | ff0d9f0 | 2014-06-09 17:23:02 -0700 | [diff] [blame] | 1090 | const size_t bytesPerSample = audio_bytes_per_sample(format); |
| 1091 | return frameCount * channelCount * bytesPerSample; |
| 1092 | } else { |
| 1093 | return frameCount; |
| 1094 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1097 | // ---------------------------------------------------------------------------- |
Glenn Kasten | 3009f0b | 2014-03-28 16:02:26 -0700 | [diff] [blame] | 1098 | static jint |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1099 | android_media_AudioTrack_setAuxEffectSendLevel(JNIEnv *env, jobject thiz, jfloat level ) |
| 1100 | { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 1101 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1102 | if (lpTrack == NULL ) { |
| 1103 | jniThrowException(env, "java/lang/IllegalStateException", |
| 1104 | "Unable to retrieve AudioTrack pointer for setAuxEffectSendLevel()"); |
Glenn Kasten | 3009f0b | 2014-03-28 16:02:26 -0700 | [diff] [blame] | 1105 | return -1; |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Glenn Kasten | 3009f0b | 2014-03-28 16:02:26 -0700 | [diff] [blame] | 1108 | status_t status = lpTrack->setAuxEffectSendLevel(level); |
| 1109 | if (status != NO_ERROR) { |
| 1110 | ALOGE("AudioTrack::setAuxEffectSendLevel() for level %g failed with status %d", |
| 1111 | level, status); |
| 1112 | } |
| 1113 | return (jint) status; |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | // ---------------------------------------------------------------------------- |
| 1117 | static jint android_media_AudioTrack_attachAuxEffect(JNIEnv *env, jobject thiz, |
| 1118 | jint effectId) { |
Eric Laurent | 532bc1c | 2012-04-20 12:45:03 -0700 | [diff] [blame] | 1119 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 1120 | if (lpTrack == NULL) { |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1121 | jniThrowException(env, "java/lang/IllegalStateException", |
| 1122 | "Unable to retrieve AudioTrack pointer for attachAuxEffect()"); |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 1123 | return (jint)AUDIO_JAVA_ERROR; |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1124 | } |
Eric Laurent | bc11a69 | 2014-05-16 12:19:25 -0700 | [diff] [blame] | 1125 | return nativeToJavaStatus( lpTrack->attachAuxEffect(effectId) ); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1126 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1127 | |
Paul McLean | 88e1d86 | 2015-04-06 16:36:51 -0700 | [diff] [blame] | 1128 | static jboolean android_media_AudioTrack_setOutputDevice( |
| 1129 | JNIEnv *env, jobject thiz, jint device_id) { |
| 1130 | |
| 1131 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
Paul McLean | cef696e | 2015-05-21 08:51:18 -0700 | [diff] [blame] | 1132 | if (lpTrack == 0) { |
| 1133 | return false; |
| 1134 | } |
Paul McLean | 88e1d86 | 2015-04-06 16:36:51 -0700 | [diff] [blame] | 1135 | return lpTrack->setOutputDevice(device_id) == NO_ERROR; |
| 1136 | } |
| 1137 | |
Eric Laurent | 4bcdba8 | 2015-05-01 11:37:49 -0700 | [diff] [blame] | 1138 | static jint android_media_AudioTrack_getRoutedDeviceId( |
| 1139 | JNIEnv *env, jobject thiz) { |
| 1140 | |
| 1141 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 1142 | if (lpTrack == NULL) { |
| 1143 | return 0; |
| 1144 | } |
| 1145 | return (jint)lpTrack->getRoutedDeviceId(); |
| 1146 | } |
| 1147 | |
| 1148 | static void android_media_AudioTrack_enableDeviceCallback( |
| 1149 | JNIEnv *env, jobject thiz) { |
| 1150 | |
| 1151 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 1152 | if (lpTrack == NULL) { |
| 1153 | return; |
| 1154 | } |
| 1155 | AudioTrackJniStorage* pJniStorage = (AudioTrackJniStorage *)env->GetLongField( |
| 1156 | thiz, javaAudioTrackFields.jniData); |
| 1157 | if (pJniStorage == NULL || pJniStorage->mDeviceCallback != 0) { |
| 1158 | return; |
| 1159 | } |
| 1160 | pJniStorage->mDeviceCallback = |
| 1161 | new JNIDeviceCallback(env, thiz, pJniStorage->mCallbackData.audioTrack_ref, |
| 1162 | javaAudioTrackFields.postNativeEventInJava); |
| 1163 | lpTrack->addAudioDeviceCallback(pJniStorage->mDeviceCallback); |
| 1164 | } |
| 1165 | |
| 1166 | static void android_media_AudioTrack_disableDeviceCallback( |
| 1167 | JNIEnv *env, jobject thiz) { |
| 1168 | |
| 1169 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 1170 | if (lpTrack == NULL) { |
| 1171 | return; |
| 1172 | } |
| 1173 | AudioTrackJniStorage* pJniStorage = (AudioTrackJniStorage *)env->GetLongField( |
| 1174 | thiz, javaAudioTrackFields.jniData); |
| 1175 | if (pJniStorage == NULL || pJniStorage->mDeviceCallback == 0) { |
| 1176 | return; |
| 1177 | } |
| 1178 | lpTrack->removeAudioDeviceCallback(pJniStorage->mDeviceCallback); |
| 1179 | pJniStorage->mDeviceCallback.clear(); |
| 1180 | } |
| 1181 | |
Glenn Kasten | bd2c3d6 | 2015-12-14 12:21:03 -0800 | [diff] [blame] | 1182 | static jint android_media_AudioTrack_get_FCC_8(JNIEnv *env, jobject thiz) { |
| 1183 | return FCC_8; |
| 1184 | } |
| 1185 | |
Andy Hung | 035d4ec | 2017-01-24 13:45:02 -0800 | [diff] [blame] | 1186 | // Pass through the arguments to the AudioFlinger track implementation. |
| 1187 | static jint android_media_AudioTrack_apply_volume_shaper(JNIEnv *env, jobject thiz, |
| 1188 | jobject jconfig, jobject joperation) { |
| 1189 | // NOTE: hard code here to prevent platform issues. Must match VolumeShaper.java |
| 1190 | const int VOLUME_SHAPER_INVALID_OPERATION = -38; |
| 1191 | |
| 1192 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 1193 | if (lpTrack == nullptr) { |
| 1194 | return (jint)VOLUME_SHAPER_INVALID_OPERATION; |
| 1195 | } |
| 1196 | |
| 1197 | sp<VolumeShaper::Configuration> configuration; |
| 1198 | sp<VolumeShaper::Operation> operation; |
| 1199 | if (jconfig != nullptr) { |
| 1200 | configuration = VolumeShaperHelper::convertJobjectToConfiguration( |
| 1201 | env, gVolumeShaperFields, jconfig); |
| 1202 | ALOGV("applyVolumeShaper configuration: %s", configuration->toString().c_str()); |
| 1203 | } |
| 1204 | if (joperation != nullptr) { |
| 1205 | operation = VolumeShaperHelper::convertJobjectToOperation( |
| 1206 | env, gVolumeShaperFields, joperation); |
| 1207 | ALOGV("applyVolumeShaper operation: %s", operation->toString().c_str()); |
| 1208 | } |
| 1209 | VolumeShaper::Status status = lpTrack->applyVolumeShaper(configuration, operation); |
| 1210 | if (status == INVALID_OPERATION) { |
| 1211 | status = VOLUME_SHAPER_INVALID_OPERATION; |
| 1212 | } |
| 1213 | return (jint)status; // if status < 0 an error, else a VolumeShaper id |
| 1214 | } |
| 1215 | |
| 1216 | // Pass through the arguments to the AudioFlinger track implementation. |
| 1217 | static jobject android_media_AudioTrack_get_volume_shaper_state(JNIEnv *env, jobject thiz, |
| 1218 | jint id) { |
| 1219 | sp<AudioTrack> lpTrack = getAudioTrack(env, thiz); |
| 1220 | if (lpTrack == nullptr) { |
| 1221 | return (jobject)nullptr; |
| 1222 | } |
| 1223 | |
| 1224 | sp<VolumeShaper::State> state = lpTrack->getVolumeShaperState((int)id); |
| 1225 | if (state.get() == nullptr) { |
| 1226 | return (jobject)nullptr; |
| 1227 | } |
| 1228 | return VolumeShaperHelper::convertStateToJobject(env, gVolumeShaperFields, state); |
| 1229 | } |
Eric Laurent | 4bcdba8 | 2015-05-01 11:37:49 -0700 | [diff] [blame] | 1230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | // ---------------------------------------------------------------------------- |
| 1232 | // ---------------------------------------------------------------------------- |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 1233 | static const JNINativeMethod gMethods[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1234 | // name, signature, funcPtr |
| 1235 | {"native_start", "()V", (void *)android_media_AudioTrack_start}, |
| 1236 | {"native_stop", "()V", (void *)android_media_AudioTrack_stop}, |
| 1237 | {"native_pause", "()V", (void *)android_media_AudioTrack_pause}, |
| 1238 | {"native_flush", "()V", (void *)android_media_AudioTrack_flush}, |
Jean-Michel Trivi | 980d38f | 2018-01-08 15:43:35 -0800 | [diff] [blame] | 1239 | {"native_setup", "(Ljava/lang/Object;Ljava/lang/Object;[IIIIII[IJZ)I", |
Jean-Michel Trivi | eac8438 | 2014-02-04 14:50:40 -0800 | [diff] [blame] | 1240 | (void *)android_media_AudioTrack_setup}, |
| 1241 | {"native_finalize", "()V", (void *)android_media_AudioTrack_finalize}, |
| 1242 | {"native_release", "()V", (void *)android_media_AudioTrack_release}, |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 1243 | {"native_write_byte", "([BIIIZ)I",(void *)android_media_AudioTrack_writeArray<jbyteArray>}, |
Jean-Michel Trivi | 7ca0452 | 2014-02-07 09:39:34 -0800 | [diff] [blame] | 1244 | {"native_write_native_bytes", |
Jean-Michel Trivi | 5d21f67 | 2014-03-20 17:02:31 -0700 | [diff] [blame] | 1245 | "(Ljava/lang/Object;IIIZ)I", |
Jean-Michel Trivi | 7ca0452 | 2014-02-07 09:39:34 -0800 | [diff] [blame] | 1246 | (void *)android_media_AudioTrack_write_native_bytes}, |
Andy Hung | 4aacc90 | 2015-04-14 15:01:29 -0700 | [diff] [blame] | 1247 | {"native_write_short", "([SIIIZ)I",(void *)android_media_AudioTrack_writeArray<jshortArray>}, |
| 1248 | {"native_write_float", "([FIIIZ)I",(void *)android_media_AudioTrack_writeArray<jfloatArray>}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | {"native_setVolume", "(FF)V", (void *)android_media_AudioTrack_set_volume}, |
Phil Burk | 10a33e4 | 2016-01-08 12:40:41 -0800 | [diff] [blame] | 1250 | {"native_get_buffer_size_frames", |
| 1251 | "()I", (void *)android_media_AudioTrack_get_buffer_size_frames}, |
| 1252 | {"native_set_buffer_size_frames", |
| 1253 | "(I)I", (void *)android_media_AudioTrack_set_buffer_size_frames}, |
| 1254 | {"native_get_buffer_capacity_frames", |
| 1255 | "()I", (void *)android_media_AudioTrack_get_buffer_capacity_frames}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | {"native_set_playback_rate", |
Eric Laurent | 88e209d | 2009-07-07 07:10:45 -0700 | [diff] [blame] | 1257 | "(I)I", (void *)android_media_AudioTrack_set_playback_rate}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | {"native_get_playback_rate", |
| 1259 | "()I", (void *)android_media_AudioTrack_get_playback_rate}, |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 1260 | {"native_set_playback_params", |
| 1261 | "(Landroid/media/PlaybackParams;)V", |
| 1262 | (void *)android_media_AudioTrack_set_playback_params}, |
| 1263 | {"native_get_playback_params", |
| 1264 | "()Landroid/media/PlaybackParams;", |
| 1265 | (void *)android_media_AudioTrack_get_playback_params}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | {"native_set_marker_pos","(I)I", (void *)android_media_AudioTrack_set_marker_pos}, |
| 1267 | {"native_get_marker_pos","()I", (void *)android_media_AudioTrack_get_marker_pos}, |
| 1268 | {"native_set_pos_update_period", |
| 1269 | "(I)I", (void *)android_media_AudioTrack_set_pos_update_period}, |
| 1270 | {"native_get_pos_update_period", |
| 1271 | "()I", (void *)android_media_AudioTrack_get_pos_update_period}, |
| 1272 | {"native_set_position", "(I)I", (void *)android_media_AudioTrack_set_position}, |
| 1273 | {"native_get_position", "()I", (void *)android_media_AudioTrack_get_position}, |
Oliver Woodman | 61dcdf3 | 2013-06-26 12:43:36 +0100 | [diff] [blame] | 1274 | {"native_get_latency", "()I", (void *)android_media_AudioTrack_get_latency}, |
Phil Burk | 03f61bb | 2016-01-17 21:49:58 +0000 | [diff] [blame] | 1275 | {"native_get_underrun_count", "()I", (void *)android_media_AudioTrack_get_underrun_count}, |
Andy Hung | ebc2c14 | 2017-01-12 19:20:29 -0800 | [diff] [blame] | 1276 | {"native_get_flags", "()I", (void *)android_media_AudioTrack_get_flags}, |
Glenn Kasten | 948c2e6 | 2013-09-04 13:51:29 -0700 | [diff] [blame] | 1277 | {"native_get_timestamp", "([J)I", (void *)android_media_AudioTrack_get_timestamp}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | {"native_set_loop", "(III)I", (void *)android_media_AudioTrack_set_loop}, |
| 1279 | {"native_reload_static", "()I", (void *)android_media_AudioTrack_reload}, |
| 1280 | {"native_get_output_sample_rate", |
| 1281 | "(I)I", (void *)android_media_AudioTrack_get_output_sample_rate}, |
| 1282 | {"native_get_min_buff_size", |
| 1283 | "(III)I", (void *)android_media_AudioTrack_get_min_buff_size}, |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1284 | {"native_setAuxEffectSendLevel", |
Glenn Kasten | 3009f0b | 2014-03-28 16:02:26 -0700 | [diff] [blame] | 1285 | "(F)I", (void *)android_media_AudioTrack_setAuxEffectSendLevel}, |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1286 | {"native_attachAuxEffect", |
| 1287 | "(I)I", (void *)android_media_AudioTrack_attachAuxEffect}, |
Paul McLean | 88e1d86 | 2015-04-06 16:36:51 -0700 | [diff] [blame] | 1288 | {"native_setOutputDevice", "(I)Z", |
| 1289 | (void *)android_media_AudioTrack_setOutputDevice}, |
Eric Laurent | 4bcdba8 | 2015-05-01 11:37:49 -0700 | [diff] [blame] | 1290 | {"native_getRoutedDeviceId", "()I", (void *)android_media_AudioTrack_getRoutedDeviceId}, |
| 1291 | {"native_enableDeviceCallback", "()V", (void *)android_media_AudioTrack_enableDeviceCallback}, |
| 1292 | {"native_disableDeviceCallback", "()V", (void *)android_media_AudioTrack_disableDeviceCallback}, |
Glenn Kasten | 25d3c7c | 2016-01-07 10:59:35 -0800 | [diff] [blame] | 1293 | {"native_get_FCC_8", "()I", (void *)android_media_AudioTrack_get_FCC_8}, |
Andy Hung | 035d4ec | 2017-01-24 13:45:02 -0800 | [diff] [blame] | 1294 | {"native_applyVolumeShaper", |
| 1295 | "(Landroid/media/VolumeShaper$Configuration;Landroid/media/VolumeShaper$Operation;)I", |
| 1296 | (void *)android_media_AudioTrack_apply_volume_shaper}, |
| 1297 | {"native_getVolumeShaperState", |
| 1298 | "(I)Landroid/media/VolumeShaper$State;", |
| 1299 | (void *)android_media_AudioTrack_get_volume_shaper_state}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1300 | }; |
| 1301 | |
| 1302 | |
| 1303 | // field names found in android/media/AudioTrack.java |
| 1304 | #define JAVA_POSTEVENT_CALLBACK_NAME "postEventFromNative" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1305 | #define JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME "mNativeTrackInJavaObj" |
| 1306 | #define JAVA_JNIDATA_FIELD_NAME "mJniData" |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 1307 | #define JAVA_STREAMTYPE_FIELD_NAME "mStreamType" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | // ---------------------------------------------------------------------------- |
| 1310 | // preconditions: |
| 1311 | // theClass is valid |
| 1312 | bool android_media_getIntConstantFromClass(JNIEnv* pEnv, jclass theClass, const char* className, |
| 1313 | const char* constName, int* constVal) { |
| 1314 | jfieldID javaConst = NULL; |
| 1315 | javaConst = pEnv->GetStaticFieldID(theClass, constName, "I"); |
| 1316 | if (javaConst != NULL) { |
| 1317 | *constVal = pEnv->GetStaticIntField(theClass, javaConst); |
| 1318 | return true; |
| 1319 | } else { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1320 | ALOGE("Can't find %s.%s", className, constName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | return false; |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | |
| 1326 | // ---------------------------------------------------------------------------- |
| 1327 | int register_android_media_AudioTrack(JNIEnv *env) |
| 1328 | { |
Glenn Kasten | 931fde4 | 2016-01-07 15:59:38 -0800 | [diff] [blame] | 1329 | // must be first |
| 1330 | int res = RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); |
| 1331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1332 | javaAudioTrackFields.nativeTrackInJavaObj = NULL; |
| 1333 | javaAudioTrackFields.postNativeEventInJava = NULL; |
| 1334 | |
| 1335 | // Get the AudioTrack class |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1336 | jclass audioTrackClass = FindClassOrDie(env, kClassPathName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1337 | |
| 1338 | // Get the postEvent method |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1339 | javaAudioTrackFields.postNativeEventInJava = GetStaticMethodIDOrDie(env, |
| 1340 | audioTrackClass, JAVA_POSTEVENT_CALLBACK_NAME, |
| 1341 | "(Ljava/lang/Object;IIILjava/lang/Object;)V"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1342 | |
| 1343 | // Get the variables fields |
| 1344 | // nativeTrackInJavaObj |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1345 | javaAudioTrackFields.nativeTrackInJavaObj = GetFieldIDOrDie(env, |
| 1346 | audioTrackClass, JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "J"); |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 1347 | // jniData |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1348 | javaAudioTrackFields.jniData = GetFieldIDOrDie(env, |
| 1349 | audioTrackClass, JAVA_JNIDATA_FIELD_NAME, "J"); |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 1350 | // fieldStreamType |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1351 | javaAudioTrackFields.fieldStreamType = GetFieldIDOrDie(env, |
| 1352 | audioTrackClass, JAVA_STREAMTYPE_FIELD_NAME, "I"); |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 1353 | |
Andy Hung | fe48e0d | 2015-04-27 18:14:02 -0700 | [diff] [blame] | 1354 | env->DeleteLocalRef(audioTrackClass); |
| 1355 | |
Jean-Michel Trivi | a1d80e3 | 2014-06-18 08:18:41 -0700 | [diff] [blame] | 1356 | // Get the AudioAttributes class and fields |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1357 | jclass audioAttrClass = FindClassOrDie(env, kAudioAttributesClassPathName); |
| 1358 | javaAudioAttrFields.fieldUsage = GetFieldIDOrDie(env, audioAttrClass, "mUsage", "I"); |
| 1359 | javaAudioAttrFields.fieldContentType = GetFieldIDOrDie(env, |
| 1360 | audioAttrClass, "mContentType", "I"); |
| 1361 | javaAudioAttrFields.fieldFlags = GetFieldIDOrDie(env, audioAttrClass, "mFlags", "I"); |
| 1362 | javaAudioAttrFields.fieldFormattedTags = GetFieldIDOrDie(env, |
| 1363 | audioAttrClass, "mFormattedTags", "Ljava/lang/String;"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1364 | |
Andy Hung | fe48e0d | 2015-04-27 18:14:02 -0700 | [diff] [blame] | 1365 | env->DeleteLocalRef(audioAttrClass); |
| 1366 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 1367 | // initialize PlaybackParams field info |
| 1368 | gPlaybackParamsFields.init(env); |
Andy Hung | fe48e0d | 2015-04-27 18:14:02 -0700 | [diff] [blame] | 1369 | |
Andy Hung | 035d4ec | 2017-01-24 13:45:02 -0800 | [diff] [blame] | 1370 | gVolumeShaperFields.init(env); |
Glenn Kasten | 931fde4 | 2016-01-07 15:59:38 -0800 | [diff] [blame] | 1371 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | |
| 1375 | // ---------------------------------------------------------------------------- |