James Dong | c371a02 | 2011-04-06 12:16:07 -0700 | [diff] [blame] | 1 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2 | ** |
| 3 | ** Copyright 2007, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #define LOG_TAG "MediaPlayer-JNI" |
| 20 | #include "utils/Log.h" |
| 21 | |
| 22 | #include <media/mediaplayer.h> |
Lajos Molnar | b3d5fd2 | 2015-04-22 13:14:34 -0700 | [diff] [blame] | 23 | #include <media/AudioResamplerPublic.h> |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 24 | #include <media/IMediaHTTPService.h> |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 25 | #include <media/MediaPlayerInterface.h> |
Ray Essick | 0e0fee1 | 2017-01-25 18:01:56 -0800 | [diff] [blame] | 26 | #include <media/MediaAnalyticsItem.h> |
Dongwon Kang | efada569 | 2017-10-09 11:46:39 -0700 | [diff] [blame] | 27 | #include <media/stagefright/foundation/ByteUtils.h> // for FOURCC definition |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <stdio.h> |
| 29 | #include <assert.h> |
| 30 | #include <limits.h> |
| 31 | #include <unistd.h> |
| 32 | #include <fcntl.h> |
| 33 | #include <utils/threads.h> |
| 34 | #include "jni.h" |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 35 | #include <nativehelper/JNIHelp.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | #include "android_runtime/AndroidRuntime.h" |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 37 | #include "android_runtime/android_view_Surface.h" |
Ruben Brunk | 87eac99 | 2013-09-09 17:44:59 -0700 | [diff] [blame] | 38 | #include "android_runtime/Log.h" |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 39 | #include "utils/Errors.h" // for status_t |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 40 | #include "utils/KeyedVector.h" |
| 41 | #include "utils/String8.h" |
Chris Watkins | 4eaa293 | 2015-03-20 10:31:42 -0700 | [diff] [blame] | 42 | #include "android_media_MediaDataSource.h" |
Ray Essick | 0e0fee1 | 2017-01-25 18:01:56 -0800 | [diff] [blame] | 43 | #include "android_media_MediaMetricsJNI.h" |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 44 | #include "android_media_PlaybackParams.h" |
| 45 | #include "android_media_SyncParams.h" |
Andy Hung | 035d4ec | 2017-01-24 13:45:02 -0800 | [diff] [blame] | 46 | #include "android_media_VolumeShaper.h" |
James Dong | 79f407c | 2011-05-05 12:50:04 -0700 | [diff] [blame] | 47 | #include "android_media_Utils.h" |
| 48 | |
Jeff Sharkey | d84e1ce | 2012-03-06 18:26:19 -0800 | [diff] [blame] | 49 | #include "android_os_Parcel.h" |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 50 | #include "android_util_Binder.h" |
| 51 | #include <binder/Parcel.h> |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 52 | #include <gui/IGraphicBufferProducer.h> |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 53 | #include <gui/Surface.h> |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 54 | #include <binder/IPCThreadState.h> |
| 55 | #include <binder/IServiceManager.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 57 | #include "android_util_Binder.h" |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 58 | |
| 59 | // Modular DRM begin |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 60 | #define FIND_CLASS(var, className) \ |
| 61 | var = env->FindClass(className); \ |
| 62 | LOG_FATAL_IF(! (var), "Unable to find class " className); |
| 63 | |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 64 | #define GET_METHOD_ID(var, clazz, fieldName, fieldDescriptor) \ |
| 65 | var = env->GetMethodID(clazz, fieldName, fieldDescriptor); \ |
| 66 | LOG_FATAL_IF(! (var), "Unable to find method " fieldName); |
| 67 | |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 68 | struct StateExceptionFields { |
| 69 | jmethodID init; |
| 70 | jclass classId; |
| 71 | }; |
| 72 | |
Hassan Shojania | 06b25fb | 2017-02-06 21:09:42 -0800 | [diff] [blame] | 73 | static StateExceptionFields gStateExceptionFields; |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 74 | // Modular DRM end |
| 75 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | // ---------------------------------------------------------------------------- |
| 77 | |
| 78 | using namespace android; |
| 79 | |
Ivan Lozano | 330d876 | 2017-08-08 12:51:06 -0700 | [diff] [blame] | 80 | using media::VolumeShaper; |
| 81 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | // ---------------------------------------------------------------------------- |
| 83 | |
| 84 | struct fields_t { |
| 85 | jfieldID context; |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 86 | jfieldID surface_texture; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | |
| 88 | jmethodID post_event; |
Andreas Huber | d5f9fa5 | 2013-05-28 14:39:39 -0700 | [diff] [blame] | 89 | |
| 90 | jmethodID proxyConfigGetHost; |
| 91 | jmethodID proxyConfigGetPort; |
| 92 | jmethodID proxyConfigGetExclusionList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | }; |
| 94 | static fields_t fields; |
| 95 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 96 | static PlaybackParams::fields_t gPlaybackParamsFields; |
| 97 | static SyncParams::fields_t gSyncParamsFields; |
Andy Hung | 035d4ec | 2017-01-24 13:45:02 -0800 | [diff] [blame] | 98 | static VolumeShaperHelper::fields_t gVolumeShaperFields; |
Lajos Molnar | b3d5fd2 | 2015-04-22 13:14:34 -0700 | [diff] [blame] | 99 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | static Mutex sLock; |
| 101 | |
| 102 | // ---------------------------------------------------------------------------- |
| 103 | // ref-counted object for callbacks |
| 104 | class JNIMediaPlayerListener: public MediaPlayerListener |
| 105 | { |
| 106 | public: |
| 107 | JNIMediaPlayerListener(JNIEnv* env, jobject thiz, jobject weak_thiz); |
| 108 | ~JNIMediaPlayerListener(); |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 109 | virtual void notify(int msg, int ext1, int ext2, const Parcel *obj = NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | private: |
| 111 | JNIMediaPlayerListener(); |
| 112 | jclass mClass; // Reference to MediaPlayer class |
| 113 | jobject mObject; // Weak ref to MediaPlayer Java object to call on |
| 114 | }; |
| 115 | |
| 116 | JNIMediaPlayerListener::JNIMediaPlayerListener(JNIEnv* env, jobject thiz, jobject weak_thiz) |
| 117 | { |
| 118 | |
| 119 | // Hold onto the MediaPlayer class for use in calling the static method |
| 120 | // that posts events to the application thread. |
| 121 | jclass clazz = env->GetObjectClass(thiz); |
| 122 | if (clazz == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 123 | ALOGE("Can't find android/media/MediaPlayer"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | jniThrowException(env, "java/lang/Exception", NULL); |
| 125 | return; |
| 126 | } |
| 127 | mClass = (jclass)env->NewGlobalRef(clazz); |
| 128 | |
| 129 | // We use a weak reference so the MediaPlayer object can be garbage collected. |
| 130 | // The reference is only used as a proxy for callbacks. |
| 131 | mObject = env->NewGlobalRef(weak_thiz); |
| 132 | } |
| 133 | |
| 134 | JNIMediaPlayerListener::~JNIMediaPlayerListener() |
| 135 | { |
| 136 | // remove global references |
| 137 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 138 | env->DeleteGlobalRef(mObject); |
| 139 | env->DeleteGlobalRef(mClass); |
| 140 | } |
| 141 | |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 142 | void JNIMediaPlayerListener::notify(int msg, int ext1, int ext2, const Parcel *obj) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | { |
| 144 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 145 | if (obj && obj->dataSize() > 0) { |
Insun Kang | 333c099 | 2012-07-10 12:47:03 +0900 | [diff] [blame] | 146 | jobject jParcel = createJavaParcelObject(env); |
| 147 | if (jParcel != NULL) { |
| 148 | Parcel* nativeParcel = parcelForJavaObject(env, jParcel); |
Insun Kang | 8902097 | 2012-05-01 14:13:19 +0900 | [diff] [blame] | 149 | nativeParcel->setData(obj->data(), obj->dataSize()); |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 150 | env->CallStaticVoidMethod(mClass, fields.post_event, mObject, |
Insun Kang | 333c099 | 2012-07-10 12:47:03 +0900 | [diff] [blame] | 151 | msg, ext1, ext2, jParcel); |
Elliott Hughes | 99f7521 | 2013-11-13 15:10:40 -0800 | [diff] [blame] | 152 | env->DeleteLocalRef(jParcel); |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 153 | } |
| 154 | } else { |
| 155 | env->CallStaticVoidMethod(mClass, fields.post_event, mObject, |
| 156 | msg, ext1, ext2, NULL); |
| 157 | } |
Insun Kang | 8902097 | 2012-05-01 14:13:19 +0900 | [diff] [blame] | 158 | if (env->ExceptionCheck()) { |
| 159 | ALOGW("An exception occurred while notifying an event."); |
| 160 | LOGW_EX(env); |
| 161 | env->ExceptionClear(); |
| 162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | // ---------------------------------------------------------------------------- |
| 166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | static sp<MediaPlayer> getMediaPlayer(JNIEnv* env, jobject thiz) |
| 168 | { |
| 169 | Mutex::Autolock l(sLock); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 170 | MediaPlayer* const p = (MediaPlayer*)env->GetLongField(thiz, fields.context); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | return sp<MediaPlayer>(p); |
| 172 | } |
| 173 | |
| 174 | static sp<MediaPlayer> setMediaPlayer(JNIEnv* env, jobject thiz, const sp<MediaPlayer>& player) |
| 175 | { |
| 176 | Mutex::Autolock l(sLock); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 177 | sp<MediaPlayer> old = (MediaPlayer*)env->GetLongField(thiz, fields.context); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | if (player.get()) { |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 179 | player->incStrong((void*)setMediaPlayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | } |
| 181 | if (old != 0) { |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 182 | old->decStrong((void*)setMediaPlayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | } |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 184 | env->SetLongField(thiz, fields.context, (jlong)player.get()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | return old; |
| 186 | } |
| 187 | |
Nicolas Catania | 32f8277 | 2009-06-11 16:33:49 -0700 | [diff] [blame] | 188 | // If exception is NULL and opStatus is not OK, this method sends an error |
| 189 | // event to the client application; otherwise, if exception is not NULL and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | // opStatus is not OK, this method throws the given exception to the client |
| 191 | // application. |
| 192 | static void process_media_player_call(JNIEnv *env, jobject thiz, status_t opStatus, const char* exception, const char *message) |
| 193 | { |
| 194 | if (exception == NULL) { // Don't throw exception. Instead, send an event. |
| 195 | if (opStatus != (status_t) OK) { |
| 196 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 197 | if (mp != 0) mp->notify(MEDIA_ERROR, opStatus, 0); |
| 198 | } |
| 199 | } else { // Throw exception! |
| 200 | if ( opStatus == (status_t) INVALID_OPERATION ) { |
| 201 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 202 | } else if ( opStatus == (status_t) BAD_VALUE ) { |
| 203 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
Dave Burke | fc301b0 | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 204 | } else if ( opStatus == (status_t) PERMISSION_DENIED ) { |
| 205 | jniThrowException(env, "java/lang/SecurityException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | } else if ( opStatus != (status_t) OK ) { |
| 207 | if (strlen(message) > 230) { |
| 208 | // if the message is too long, don't bother displaying the status code |
| 209 | jniThrowException( env, exception, message); |
| 210 | } else { |
| 211 | char msg[256]; |
| 212 | // append the status code to the message |
| 213 | sprintf(msg, "%s: status=0x%X", message, opStatus); |
| 214 | jniThrowException( env, exception, msg); |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | static void |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 221 | android_media_MediaPlayer_setDataSourceAndHeaders( |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 222 | JNIEnv *env, jobject thiz, jobject httpServiceBinderObj, jstring path, |
James Dong | 17524dc | 2011-05-04 13:41:58 -0700 | [diff] [blame] | 223 | jobjectArray keys, jobjectArray values) { |
| 224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 226 | if (mp == NULL ) { |
| 227 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | if (path == NULL) { |
| 232 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
| 233 | return; |
| 234 | } |
| 235 | |
James Dong | c371a02 | 2011-04-06 12:16:07 -0700 | [diff] [blame] | 236 | const char *tmp = env->GetStringUTFChars(path, NULL); |
| 237 | if (tmp == NULL) { // Out of memory |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | return; |
| 239 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 240 | ALOGV("setDataSource: path %s", tmp); |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 241 | |
James Dong | c371a02 | 2011-04-06 12:16:07 -0700 | [diff] [blame] | 242 | String8 pathStr(tmp); |
| 243 | env->ReleaseStringUTFChars(path, tmp); |
| 244 | tmp = NULL; |
| 245 | |
James Dong | 17524dc | 2011-05-04 13:41:58 -0700 | [diff] [blame] | 246 | // We build a KeyedVector out of the key and val arrays |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 247 | KeyedVector<String8, String8> headersVector; |
James Dong | 79f407c | 2011-05-05 12:50:04 -0700 | [diff] [blame] | 248 | if (!ConvertKeyValueArraysToKeyedVector( |
| 249 | env, keys, values, &headersVector)) { |
| 250 | return; |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 253 | sp<IMediaHTTPService> httpService; |
| 254 | if (httpServiceBinderObj != NULL) { |
| 255 | sp<IBinder> binder = ibinderForJavaObject(env, httpServiceBinderObj); |
| 256 | httpService = interface_cast<IMediaHTTPService>(binder); |
| 257 | } |
| 258 | |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 259 | status_t opStatus = |
| 260 | mp->setDataSource( |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 261 | httpService, |
James Dong | c371a02 | 2011-04-06 12:16:07 -0700 | [diff] [blame] | 262 | pathStr, |
James Dong | 79f407c | 2011-05-05 12:50:04 -0700 | [diff] [blame] | 263 | headersVector.size() > 0? &headersVector : NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 265 | process_media_player_call( |
| 266 | env, thiz, opStatus, "java/io/IOException", |
| 267 | "setDataSource failed." ); |
| 268 | } |
| 269 | |
| 270 | static void |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | android_media_MediaPlayer_setDataSourceFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length) |
| 272 | { |
| 273 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 274 | if (mp == NULL ) { |
| 275 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | if (fileDescriptor == NULL) { |
| 280 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
| 281 | return; |
| 282 | } |
Elliott Hughes | a3804cf | 2011-04-11 16:50:19 -0700 | [diff] [blame] | 283 | int fd = jniGetFDFromFileDescriptor(env, fileDescriptor); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 284 | ALOGV("setDataSourceFD: fd %d", fd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | process_media_player_call( env, thiz, mp->setDataSource(fd, offset, length), "java/io/IOException", "setDataSourceFD failed." ); |
| 286 | } |
| 287 | |
Chris Watkins | 4eaa293 | 2015-03-20 10:31:42 -0700 | [diff] [blame] | 288 | static void |
| 289 | android_media_MediaPlayer_setDataSourceCallback(JNIEnv *env, jobject thiz, jobject dataSource) |
| 290 | { |
| 291 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 292 | if (mp == NULL ) { |
| 293 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | if (dataSource == NULL) { |
| 298 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
| 299 | return; |
| 300 | } |
| 301 | sp<IDataSource> callbackDataSource = new JMediaDataSource(env, dataSource); |
| 302 | process_media_player_call(env, thiz, mp->setDataSource(callbackDataSource), "java/lang/RuntimeException", "setDataSourceCallback failed." ); |
| 303 | } |
| 304 | |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 305 | static sp<IGraphicBufferProducer> |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 306 | getVideoSurfaceTexture(JNIEnv* env, jobject thiz) { |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 307 | IGraphicBufferProducer * const p = (IGraphicBufferProducer*)env->GetLongField(thiz, fields.surface_texture); |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 308 | return sp<IGraphicBufferProducer>(p); |
Dave Sparks | 8b0b174 | 2009-05-29 09:01:20 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | static void |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 312 | decVideoSurfaceRef(JNIEnv *env, jobject thiz) |
| 313 | { |
Gloria Wang | e828beb | 2011-09-15 15:28:43 -0700 | [diff] [blame] | 314 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 315 | if (mp == NULL) { |
| 316 | return; |
| 317 | } |
| 318 | |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 319 | sp<IGraphicBufferProducer> old_st = getVideoSurfaceTexture(env, thiz); |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 320 | if (old_st != NULL) { |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 321 | old_st->decStrong((void*)decVideoSurfaceRef); |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | static void |
James Dong | 43ef913 | 2011-08-12 11:33:27 -0700 | [diff] [blame] | 326 | setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface, jboolean mediaPlayerMustBeAlive) |
Dave Sparks | 8b0b174 | 2009-05-29 09:01:20 -0700 | [diff] [blame] | 327 | { |
| 328 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
James Dong | 43ef913 | 2011-08-12 11:33:27 -0700 | [diff] [blame] | 329 | if (mp == NULL) { |
| 330 | if (mediaPlayerMustBeAlive) { |
| 331 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 332 | } |
Dave Sparks | 8b0b174 | 2009-05-29 09:01:20 -0700 | [diff] [blame] | 333 | return; |
| 334 | } |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 335 | |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 336 | decVideoSurfaceRef(env, thiz); |
| 337 | |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 338 | sp<IGraphicBufferProducer> new_st; |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 339 | if (jsurface) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 340 | sp<Surface> surface(android_view_Surface_getSurface(env, jsurface)); |
Jamie Gennis | f76afc8 | 2011-10-14 19:06:55 -0700 | [diff] [blame] | 341 | if (surface != NULL) { |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 342 | new_st = surface->getIGraphicBufferProducer(); |
James Dong | 097922b | 2012-10-04 09:16:40 -0700 | [diff] [blame] | 343 | if (new_st == NULL) { |
| 344 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 345 | "The surface does not have a binding SurfaceTexture!"); |
| 346 | return; |
| 347 | } |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 348 | new_st->incStrong((void*)decVideoSurfaceRef); |
Jamie Gennis | f76afc8 | 2011-10-14 19:06:55 -0700 | [diff] [blame] | 349 | } else { |
| 350 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 351 | "The surface has been released"); |
| 352 | return; |
| 353 | } |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 354 | } |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 355 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 356 | env->SetLongField(thiz, fields.surface_texture, (jlong)new_st.get()); |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 357 | |
| 358 | // This will fail if the media player has not been initialized yet. This |
| 359 | // can be the case if setDisplay() on MediaPlayer.java has been called |
| 360 | // before setDataSource(). The redundant call to setVideoSurfaceTexture() |
| 361 | // in prepare/prepareAsync covers for this case. |
| 362 | mp->setVideoSurfaceTexture(new_st); |
Dave Sparks | 8b0b174 | 2009-05-29 09:01:20 -0700 | [diff] [blame] | 363 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | |
| 365 | static void |
James Dong | 43ef913 | 2011-08-12 11:33:27 -0700 | [diff] [blame] | 366 | android_media_MediaPlayer_setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface) |
| 367 | { |
| 368 | setVideoSurface(env, thiz, jsurface, true /* mediaPlayerMustBeAlive */); |
| 369 | } |
| 370 | |
| 371 | static void |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | android_media_MediaPlayer_prepare(JNIEnv *env, jobject thiz) |
| 373 | { |
| 374 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 375 | if (mp == NULL ) { |
| 376 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 377 | return; |
| 378 | } |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 379 | |
| 380 | // Handle the case where the display surface was set before the mp was |
| 381 | // initialized. We try again to make it stick. |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 382 | sp<IGraphicBufferProducer> st = getVideoSurfaceTexture(env, thiz); |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 383 | mp->setVideoSurfaceTexture(st); |
| 384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | process_media_player_call( env, thiz, mp->prepare(), "java/io/IOException", "Prepare failed." ); |
| 386 | } |
| 387 | |
| 388 | static void |
| 389 | android_media_MediaPlayer_prepareAsync(JNIEnv *env, jobject thiz) |
| 390 | { |
| 391 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 392 | if (mp == NULL ) { |
| 393 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 394 | return; |
| 395 | } |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 396 | |
| 397 | // Handle the case where the display surface was set before the mp was |
| 398 | // initialized. We try again to make it stick. |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 399 | sp<IGraphicBufferProducer> st = getVideoSurfaceTexture(env, thiz); |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 400 | mp->setVideoSurfaceTexture(st); |
| 401 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | process_media_player_call( env, thiz, mp->prepareAsync(), "java/io/IOException", "Prepare Async failed." ); |
| 403 | } |
| 404 | |
| 405 | static void |
| 406 | android_media_MediaPlayer_start(JNIEnv *env, jobject thiz) |
| 407 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 408 | ALOGV("start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 410 | if (mp == NULL ) { |
| 411 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 412 | return; |
| 413 | } |
| 414 | process_media_player_call( env, thiz, mp->start(), NULL, NULL ); |
| 415 | } |
| 416 | |
| 417 | static void |
| 418 | android_media_MediaPlayer_stop(JNIEnv *env, jobject thiz) |
| 419 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 420 | ALOGV("stop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 422 | if (mp == NULL ) { |
| 423 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 424 | return; |
| 425 | } |
Nicolas Catania | 32f8277 | 2009-06-11 16:33:49 -0700 | [diff] [blame] | 426 | process_media_player_call( env, thiz, mp->stop(), NULL, NULL ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | static void |
| 430 | android_media_MediaPlayer_pause(JNIEnv *env, jobject thiz) |
| 431 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 432 | ALOGV("pause"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 434 | if (mp == NULL ) { |
| 435 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 436 | return; |
| 437 | } |
| 438 | process_media_player_call( env, thiz, mp->pause(), NULL, NULL ); |
| 439 | } |
| 440 | |
| 441 | static jboolean |
| 442 | android_media_MediaPlayer_isPlaying(JNIEnv *env, jobject thiz) |
| 443 | { |
| 444 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 445 | if (mp == NULL ) { |
| 446 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 447 | return JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 449 | const jboolean is_playing = mp->isPlaying(); |
| 450 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 451 | ALOGV("isPlaying: %d", is_playing); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 452 | return is_playing; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | static void |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 456 | android_media_MediaPlayer_setPlaybackParams(JNIEnv *env, jobject thiz, jobject params) |
Wei Jia | d93fcf4 | 2015-02-09 16:05:53 -0800 | [diff] [blame] | 457 | { |
| 458 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 459 | if (mp == NULL) { |
| 460 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 461 | return; |
| 462 | } |
Lajos Molnar | b3d5fd2 | 2015-04-22 13:14:34 -0700 | [diff] [blame] | 463 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 464 | PlaybackParams pbp; |
| 465 | pbp.fillFromJobject(env, gPlaybackParamsFields, params); |
| 466 | ALOGV("setPlaybackParams: %d:%f %d:%f %d:%u %d:%u", |
| 467 | pbp.speedSet, pbp.audioRate.mSpeed, |
| 468 | pbp.pitchSet, pbp.audioRate.mPitch, |
| 469 | pbp.audioFallbackModeSet, pbp.audioRate.mFallbackMode, |
| 470 | pbp.audioStretchModeSet, pbp.audioRate.mStretchMode); |
Lajos Molnar | b3d5fd2 | 2015-04-22 13:14:34 -0700 | [diff] [blame] | 471 | |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 472 | AudioPlaybackRate rate; |
| 473 | status_t err = mp->getPlaybackSettings(&rate); |
| 474 | if (err == OK) { |
| 475 | bool updatedRate = false; |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 476 | if (pbp.speedSet) { |
| 477 | rate.mSpeed = pbp.audioRate.mSpeed; |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 478 | updatedRate = true; |
| 479 | } |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 480 | if (pbp.pitchSet) { |
| 481 | rate.mPitch = pbp.audioRate.mPitch; |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 482 | updatedRate = true; |
| 483 | } |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 484 | if (pbp.audioFallbackModeSet) { |
| 485 | rate.mFallbackMode = pbp.audioRate.mFallbackMode; |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 486 | updatedRate = true; |
| 487 | } |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 488 | if (pbp.audioStretchModeSet) { |
| 489 | rate.mStretchMode = pbp.audioRate.mStretchMode; |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 490 | updatedRate = true; |
| 491 | } |
| 492 | if (updatedRate) { |
| 493 | err = mp->setPlaybackSettings(rate); |
| 494 | } |
| 495 | } |
| 496 | process_media_player_call( |
| 497 | env, thiz, err, |
| 498 | "java/lang/IllegalStateException", "unexpected error"); |
Lajos Molnar | b3d5fd2 | 2015-04-22 13:14:34 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | static jobject |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 502 | android_media_MediaPlayer_getPlaybackParams(JNIEnv *env, jobject thiz) |
Lajos Molnar | b3d5fd2 | 2015-04-22 13:14:34 -0700 | [diff] [blame] | 503 | { |
| 504 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 505 | if (mp == NULL) { |
| 506 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 507 | return NULL; |
| 508 | } |
| 509 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 510 | PlaybackParams pbp; |
| 511 | AudioPlaybackRate &audioRate = pbp.audioRate; |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 512 | process_media_player_call( |
| 513 | env, thiz, mp->getPlaybackSettings(&audioRate), |
| 514 | "java/lang/IllegalStateException", "unexpected error"); |
Dongwon Kang | 4480127 | 2018-05-23 17:38:35 -0700 | [diff] [blame] | 515 | if (env->ExceptionCheck()) { |
| 516 | return nullptr; |
| 517 | } |
Lajos Molnar | b3d5fd2 | 2015-04-22 13:14:34 -0700 | [diff] [blame] | 518 | ALOGV("getPlaybackSettings: %f %f %d %d", |
| 519 | audioRate.mSpeed, audioRate.mPitch, audioRate.mFallbackMode, audioRate.mStretchMode); |
| 520 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 521 | pbp.speedSet = true; |
| 522 | pbp.pitchSet = true; |
| 523 | pbp.audioFallbackModeSet = true; |
| 524 | pbp.audioStretchModeSet = true; |
Lajos Molnar | b3d5fd2 | 2015-04-22 13:14:34 -0700 | [diff] [blame] | 525 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 526 | return pbp.asJobject(env, gPlaybackParamsFields); |
Wei Jia | d93fcf4 | 2015-02-09 16:05:53 -0800 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static void |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 530 | android_media_MediaPlayer_setSyncParams(JNIEnv *env, jobject thiz, jobject params) |
Lajos Molnar | c98f58e | 2015-04-22 19:28:53 -0700 | [diff] [blame] | 531 | { |
| 532 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 533 | if (mp == NULL) { |
| 534 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 535 | return; |
| 536 | } |
| 537 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 538 | SyncParams scp; |
| 539 | scp.fillFromJobject(env, gSyncParamsFields, params); |
| 540 | ALOGV("setSyncParams: %d:%d %d:%d %d:%f %d:%f", |
| 541 | scp.syncSourceSet, scp.sync.mSource, |
| 542 | scp.audioAdjustModeSet, scp.sync.mAudioAdjustMode, |
| 543 | scp.toleranceSet, scp.sync.mTolerance, |
| 544 | scp.frameRateSet, scp.frameRate); |
Lajos Molnar | c98f58e | 2015-04-22 19:28:53 -0700 | [diff] [blame] | 545 | |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 546 | AVSyncSettings avsync; |
| 547 | float videoFrameRate; |
| 548 | status_t err = mp->getSyncSettings(&avsync, &videoFrameRate); |
| 549 | if (err == OK) { |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 550 | bool updatedSync = scp.frameRateSet; |
| 551 | if (scp.syncSourceSet) { |
| 552 | avsync.mSource = scp.sync.mSource; |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 553 | updatedSync = true; |
| 554 | } |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 555 | if (scp.audioAdjustModeSet) { |
| 556 | avsync.mAudioAdjustMode = scp.sync.mAudioAdjustMode; |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 557 | updatedSync = true; |
| 558 | } |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 559 | if (scp.toleranceSet) { |
| 560 | avsync.mTolerance = scp.sync.mTolerance; |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 561 | updatedSync = true; |
| 562 | } |
| 563 | if (updatedSync) { |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 564 | err = mp->setSyncSettings(avsync, scp.frameRateSet ? scp.frameRate : -1.f); |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | process_media_player_call( |
| 568 | env, thiz, err, |
| 569 | "java/lang/IllegalStateException", "unexpected error"); |
Lajos Molnar | c98f58e | 2015-04-22 19:28:53 -0700 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static jobject |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 573 | android_media_MediaPlayer_getSyncParams(JNIEnv *env, jobject thiz) |
Lajos Molnar | c98f58e | 2015-04-22 19:28:53 -0700 | [diff] [blame] | 574 | { |
| 575 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 576 | if (mp == NULL) { |
| 577 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 578 | return NULL; |
| 579 | } |
| 580 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 581 | SyncParams scp; |
| 582 | scp.frameRate = -1.f; |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 583 | process_media_player_call( |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 584 | env, thiz, mp->getSyncSettings(&scp.sync, &scp.frameRate), |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 585 | "java/lang/IllegalStateException", "unexpected error"); |
Dongwon Kang | 4480127 | 2018-05-23 17:38:35 -0700 | [diff] [blame] | 586 | if (env->ExceptionCheck()) { |
| 587 | return nullptr; |
| 588 | } |
Lajos Molnar | c98f58e | 2015-04-22 19:28:53 -0700 | [diff] [blame] | 589 | |
Lajos Molnar | c98f58e | 2015-04-22 19:28:53 -0700 | [diff] [blame] | 590 | ALOGV("getSyncSettings: %d %d %f %f", |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 591 | scp.sync.mSource, scp.sync.mAudioAdjustMode, scp.sync.mTolerance, scp.frameRate); |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 592 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 593 | // sanity check params |
| 594 | if (scp.sync.mSource >= AVSYNC_SOURCE_MAX |
| 595 | || scp.sync.mAudioAdjustMode >= AVSYNC_AUDIO_ADJUST_MODE_MAX |
| 596 | || scp.sync.mTolerance < 0.f |
| 597 | || scp.sync.mTolerance >= AVSYNC_TOLERANCE_MAX) { |
Lajos Molnar | 05ebffe | 2015-04-29 20:41:19 -0700 | [diff] [blame] | 598 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 599 | return NULL; |
| 600 | } |
Lajos Molnar | c98f58e | 2015-04-22 19:28:53 -0700 | [diff] [blame] | 601 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 602 | scp.syncSourceSet = true; |
| 603 | scp.audioAdjustModeSet = true; |
| 604 | scp.toleranceSet = true; |
| 605 | scp.frameRateSet = scp.frameRate >= 0.f; |
Lajos Molnar | c98f58e | 2015-04-22 19:28:53 -0700 | [diff] [blame] | 606 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 607 | return scp.asJobject(env, gSyncParamsFields); |
Lajos Molnar | c98f58e | 2015-04-22 19:28:53 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | static void |
Wei Jia | bebeaf9 | 2017-04-19 16:22:10 -0700 | [diff] [blame] | 611 | android_media_MediaPlayer_seekTo(JNIEnv *env, jobject thiz, jlong msec, jint mode) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | { |
| 613 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 614 | if (mp == NULL ) { |
| 615 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 616 | return; |
| 617 | } |
Wei Jia | bebeaf9 | 2017-04-19 16:22:10 -0700 | [diff] [blame] | 618 | ALOGV("seekTo: %lld(msec), mode=%d", (long long)msec, mode); |
| 619 | process_media_player_call( env, thiz, mp->seekTo((int)msec, (MediaPlayerSeekMode)mode), NULL, NULL ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | } |
| 621 | |
Wei Jia | c02f09d | 2017-09-13 18:19:48 -0700 | [diff] [blame] | 622 | static void |
| 623 | android_media_MediaPlayer_notifyAt(JNIEnv *env, jobject thiz, jlong mediaTimeUs) |
| 624 | { |
| 625 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 626 | if (mp == NULL) { |
| 627 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 628 | return; |
| 629 | } |
| 630 | ALOGV("notifyAt: %lld", (long long)mediaTimeUs); |
| 631 | process_media_player_call( env, thiz, mp->notifyAt((int64_t)mediaTimeUs), NULL, NULL ); |
| 632 | } |
| 633 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 634 | static jint |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | android_media_MediaPlayer_getVideoWidth(JNIEnv *env, jobject thiz) |
| 636 | { |
| 637 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 638 | if (mp == NULL ) { |
| 639 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 640 | return 0; |
| 641 | } |
| 642 | int w; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 643 | if (0 != mp->getVideoWidth(&w)) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 644 | ALOGE("getVideoWidth failed"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 645 | w = 0; |
| 646 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 647 | ALOGV("getVideoWidth: %d", w); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 648 | return (jint) w; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | } |
| 650 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 651 | static jint |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 652 | android_media_MediaPlayer_getVideoHeight(JNIEnv *env, jobject thiz) |
| 653 | { |
| 654 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 655 | if (mp == NULL ) { |
| 656 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 657 | return 0; |
| 658 | } |
| 659 | int h; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 660 | if (0 != mp->getVideoHeight(&h)) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 661 | ALOGE("getVideoHeight failed"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 662 | h = 0; |
| 663 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 664 | ALOGV("getVideoHeight: %d", h); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 665 | return (jint) h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | } |
| 667 | |
Ray Essick | 0e0fee1 | 2017-01-25 18:01:56 -0800 | [diff] [blame] | 668 | static jobject |
Ray Essick | f2d0e40 | 2017-03-09 10:17:51 -0800 | [diff] [blame] | 669 | android_media_MediaPlayer_native_getMetrics(JNIEnv *env, jobject thiz) |
Ray Essick | 0e0fee1 | 2017-01-25 18:01:56 -0800 | [diff] [blame] | 670 | { |
| 671 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 672 | if (mp == NULL ) { |
| 673 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 674 | return 0; |
| 675 | } |
| 676 | |
| 677 | Parcel p; |
| 678 | int key = FOURCC('m','t','r','X'); |
| 679 | status_t status = mp->getParameter(key, &p); |
| 680 | if (status != OK) { |
| 681 | ALOGD("getMetrics() failed: %d", status); |
| 682 | return (jobject) NULL; |
| 683 | } |
| 684 | |
| 685 | MediaAnalyticsItem *item = new MediaAnalyticsItem; |
| 686 | item->readFromParcel(p); |
| 687 | jobject mybundle = MediaMetricsJNI::writeMetricsToBundle(env, item, NULL); |
| 688 | |
| 689 | // housekeeping |
| 690 | delete item; |
| 691 | item = NULL; |
| 692 | |
| 693 | return mybundle; |
| 694 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 696 | static jint |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | android_media_MediaPlayer_getCurrentPosition(JNIEnv *env, jobject thiz) |
| 698 | { |
| 699 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 700 | if (mp == NULL ) { |
| 701 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 702 | return 0; |
| 703 | } |
| 704 | int msec; |
| 705 | process_media_player_call( env, thiz, mp->getCurrentPosition(&msec), NULL, NULL ); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 706 | ALOGV("getCurrentPosition: %d (msec)", msec); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 707 | return (jint) msec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | } |
| 709 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 710 | static jint |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 711 | android_media_MediaPlayer_getDuration(JNIEnv *env, jobject thiz) |
| 712 | { |
| 713 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 714 | if (mp == NULL ) { |
| 715 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 716 | return 0; |
| 717 | } |
| 718 | int msec; |
| 719 | process_media_player_call( env, thiz, mp->getDuration(&msec), NULL, NULL ); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 720 | ALOGV("getDuration: %d (msec)", msec); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 721 | return (jint) msec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | static void |
| 725 | android_media_MediaPlayer_reset(JNIEnv *env, jobject thiz) |
| 726 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 727 | ALOGV("reset"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 729 | if (mp == NULL ) { |
| 730 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 731 | return; |
| 732 | } |
| 733 | process_media_player_call( env, thiz, mp->reset(), NULL, NULL ); |
| 734 | } |
| 735 | |
| 736 | static void |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 737 | android_media_MediaPlayer_setAudioStreamType(JNIEnv *env, jobject thiz, jint streamtype) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 739 | ALOGV("setAudioStreamType: %d", streamtype); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 741 | if (mp == NULL ) { |
| 742 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 743 | return; |
| 744 | } |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 745 | process_media_player_call( env, thiz, mp->setAudioStreamType((audio_stream_type_t) streamtype) , NULL, NULL ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 746 | } |
| 747 | |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 748 | static jint |
| 749 | android_media_MediaPlayer_getAudioStreamType(JNIEnv *env, jobject thiz) |
| 750 | { |
| 751 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 752 | if (mp == NULL ) { |
| 753 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 754 | return 0; |
| 755 | } |
| 756 | audio_stream_type_t streamtype; |
| 757 | process_media_player_call( env, thiz, mp->getAudioStreamType(&streamtype), NULL, NULL ); |
| 758 | ALOGV("getAudioStreamType: %d (streamtype)", streamtype); |
| 759 | return (jint) streamtype; |
| 760 | } |
| 761 | |
Jean-Michel Trivi | 8df982d | 2014-06-26 12:05:16 -0700 | [diff] [blame] | 762 | static jboolean |
| 763 | android_media_MediaPlayer_setParameter(JNIEnv *env, jobject thiz, jint key, jobject java_request) |
| 764 | { |
| 765 | ALOGV("setParameter: key %d", key); |
| 766 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 767 | if (mp == NULL ) { |
| 768 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 769 | return false; |
| 770 | } |
| 771 | |
| 772 | Parcel *request = parcelForJavaObject(env, java_request); |
| 773 | status_t err = mp->setParameter(key, *request); |
| 774 | if (err == OK) { |
| 775 | return true; |
| 776 | } else { |
| 777 | return false; |
| 778 | } |
| 779 | } |
| 780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | static void |
| 782 | android_media_MediaPlayer_setLooping(JNIEnv *env, jobject thiz, jboolean looping) |
| 783 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 784 | ALOGV("setLooping: %d", looping); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 786 | if (mp == NULL ) { |
| 787 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 788 | return; |
| 789 | } |
| 790 | process_media_player_call( env, thiz, mp->setLooping(looping), NULL, NULL ); |
| 791 | } |
| 792 | |
| 793 | static jboolean |
| 794 | android_media_MediaPlayer_isLooping(JNIEnv *env, jobject thiz) |
| 795 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 796 | ALOGV("isLooping"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 798 | if (mp == NULL ) { |
| 799 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 800 | return JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | } |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 802 | return mp->isLooping() ? JNI_TRUE : JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | static void |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 806 | android_media_MediaPlayer_setVolume(JNIEnv *env, jobject thiz, jfloat leftVolume, jfloat rightVolume) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | { |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 808 | ALOGV("setVolume: left %f right %f", (float) leftVolume, (float) rightVolume); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 810 | if (mp == NULL ) { |
| 811 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 812 | return; |
| 813 | } |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 814 | process_media_player_call( env, thiz, mp->setVolume((float) leftVolume, (float) rightVolume), NULL, NULL ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 817 | // Sends the request and reply parcels to the media player via the |
| 818 | // binder interface. |
| 819 | static jint |
| 820 | android_media_MediaPlayer_invoke(JNIEnv *env, jobject thiz, |
| 821 | jobject java_request, jobject java_reply) |
| 822 | { |
| 823 | sp<MediaPlayer> media_player = getMediaPlayer(env, thiz); |
| 824 | if (media_player == NULL ) { |
| 825 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
Nicolas Catania | b2c6939 | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 826 | return UNKNOWN_ERROR; |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 829 | Parcel *request = parcelForJavaObject(env, java_request); |
| 830 | Parcel *reply = parcelForJavaObject(env, java_reply); |
| 831 | |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 832 | // Don't use process_media_player_call which use the async loop to |
| 833 | // report errors, instead returns the status. |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 834 | return (jint) media_player->invoke(*request, reply); |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Nicolas Catania | b2c6939 | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 837 | // Sends the new filter to the client. |
| 838 | static jint |
| 839 | android_media_MediaPlayer_setMetadataFilter(JNIEnv *env, jobject thiz, jobject request) |
| 840 | { |
| 841 | sp<MediaPlayer> media_player = getMediaPlayer(env, thiz); |
| 842 | if (media_player == NULL ) { |
| 843 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 844 | return UNKNOWN_ERROR; |
| 845 | } |
| 846 | |
| 847 | Parcel *filter = parcelForJavaObject(env, request); |
| 848 | |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 849 | if (filter == NULL ) { |
| 850 | jniThrowException(env, "java/lang/RuntimeException", "Filter is null"); |
| 851 | return UNKNOWN_ERROR; |
| 852 | } |
| 853 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 854 | return (jint) media_player->setMetadataFilter(*filter); |
Nicolas Catania | b2c6939 | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 857 | static jboolean |
| 858 | android_media_MediaPlayer_getMetadata(JNIEnv *env, jobject thiz, jboolean update_only, |
| 859 | jboolean apply_filter, jobject reply) |
| 860 | { |
| 861 | sp<MediaPlayer> media_player = getMediaPlayer(env, thiz); |
| 862 | if (media_player == NULL ) { |
| 863 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 864 | return JNI_FALSE; |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | Parcel *metadata = parcelForJavaObject(env, reply); |
| 868 | |
| 869 | if (metadata == NULL ) { |
| 870 | jniThrowException(env, "java/lang/RuntimeException", "Reply parcel is null"); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 871 | return JNI_FALSE; |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | metadata->freeData(); |
| 875 | // On return metadata is positioned at the beginning of the |
| 876 | // metadata. Note however that the parcel actually starts with the |
| 877 | // return code so you should not rewind the parcel using |
| 878 | // setDataPosition(0). |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 879 | if (media_player->getMetadata(update_only, apply_filter, metadata) == OK) { |
| 880 | return JNI_TRUE; |
| 881 | } else { |
| 882 | return JNI_FALSE; |
| 883 | } |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 886 | // This function gets some field IDs, which in turn causes class initialization. |
| 887 | // It is called from a static block in MediaPlayer, which won't run until the |
| 888 | // first time an instance of this class is used. |
| 889 | static void |
| 890 | android_media_MediaPlayer_native_init(JNIEnv *env) |
| 891 | { |
| 892 | jclass clazz; |
| 893 | |
| 894 | clazz = env->FindClass("android/media/MediaPlayer"); |
| 895 | if (clazz == NULL) { |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 896 | return; |
| 897 | } |
| 898 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 899 | fields.context = env->GetFieldID(clazz, "mNativeContext", "J"); |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 900 | if (fields.context == NULL) { |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 901 | return; |
| 902 | } |
| 903 | |
| 904 | fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative", |
| 905 | "(Ljava/lang/Object;IIILjava/lang/Object;)V"); |
| 906 | if (fields.post_event == NULL) { |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 907 | return; |
| 908 | } |
| 909 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 910 | fields.surface_texture = env->GetFieldID(clazz, "mNativeSurfaceTexture", "J"); |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 911 | if (fields.surface_texture == NULL) { |
Glenn Kasten | cc562a3 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 912 | return; |
| 913 | } |
Andreas Huber | d5f9fa5 | 2013-05-28 14:39:39 -0700 | [diff] [blame] | 914 | |
Lajos Molnar | b3d5fd2 | 2015-04-22 13:14:34 -0700 | [diff] [blame] | 915 | env->DeleteLocalRef(clazz); |
| 916 | |
Selim Gurun | 5ba69be | 2014-05-07 15:04:40 -0700 | [diff] [blame] | 917 | clazz = env->FindClass("android/net/ProxyInfo"); |
Andreas Huber | d5f9fa5 | 2013-05-28 14:39:39 -0700 | [diff] [blame] | 918 | if (clazz == NULL) { |
| 919 | return; |
| 920 | } |
| 921 | |
| 922 | fields.proxyConfigGetHost = |
| 923 | env->GetMethodID(clazz, "getHost", "()Ljava/lang/String;"); |
| 924 | |
| 925 | fields.proxyConfigGetPort = |
| 926 | env->GetMethodID(clazz, "getPort", "()I"); |
| 927 | |
| 928 | fields.proxyConfigGetExclusionList = |
Selim Gurun | 5ba69be | 2014-05-07 15:04:40 -0700 | [diff] [blame] | 929 | env->GetMethodID(clazz, "getExclusionListAsString", "()Ljava/lang/String;"); |
Lajos Molnar | b3d5fd2 | 2015-04-22 13:14:34 -0700 | [diff] [blame] | 930 | |
| 931 | env->DeleteLocalRef(clazz); |
| 932 | |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 933 | // Modular DRM |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 934 | FIND_CLASS(clazz, "android/media/MediaDrm$MediaDrmStateException"); |
| 935 | if (clazz) { |
Hassan Shojania | 06b25fb | 2017-02-06 21:09:42 -0800 | [diff] [blame] | 936 | GET_METHOD_ID(gStateExceptionFields.init, clazz, "<init>", "(ILjava/lang/String;)V"); |
| 937 | gStateExceptionFields.classId = static_cast<jclass>(env->NewGlobalRef(clazz)); |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 938 | |
| 939 | env->DeleteLocalRef(clazz); |
| 940 | } else { |
Hassan Shojania | 06b25fb | 2017-02-06 21:09:42 -0800 | [diff] [blame] | 941 | ALOGE("JNI android_media_MediaPlayer_native_init couldn't " |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 942 | "get clazz android/media/MediaDrm$MediaDrmStateException"); |
| 943 | } |
| 944 | |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 945 | gPlaybackParamsFields.init(env); |
| 946 | gSyncParamsFields.init(env); |
Andy Hung | 035d4ec | 2017-01-24 13:45:02 -0800 | [diff] [blame] | 947 | gVolumeShaperFields.init(env); |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 948 | } |
Nicolas Catania | b2c6939 | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | static void |
| 951 | android_media_MediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this) |
| 952 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 953 | ALOGV("native_setup"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 954 | sp<MediaPlayer> mp = new MediaPlayer(); |
| 955 | if (mp == NULL) { |
| 956 | jniThrowException(env, "java/lang/RuntimeException", "Out of memory"); |
| 957 | return; |
| 958 | } |
| 959 | |
| 960 | // create new listener and give it to MediaPlayer |
| 961 | sp<JNIMediaPlayerListener> listener = new JNIMediaPlayerListener(env, thiz, weak_this); |
| 962 | mp->setListener(listener); |
| 963 | |
| 964 | // Stow our new C++ MediaPlayer in an opaque field in the Java object. |
| 965 | setMediaPlayer(env, thiz, mp); |
| 966 | } |
| 967 | |
| 968 | static void |
| 969 | android_media_MediaPlayer_release(JNIEnv *env, jobject thiz) |
| 970 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 971 | ALOGV("release"); |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 972 | decVideoSurfaceRef(env, thiz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 973 | sp<MediaPlayer> mp = setMediaPlayer(env, thiz, 0); |
| 974 | if (mp != NULL) { |
| 975 | // this prevents native callbacks after the object is released |
| 976 | mp->setListener(0); |
| 977 | mp->disconnect(); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | static void |
| 982 | android_media_MediaPlayer_native_finalize(JNIEnv *env, jobject thiz) |
| 983 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 984 | ALOGV("native_finalize"); |
Marco Nelissen | 8dc2084 | 2011-09-28 09:21:11 -0700 | [diff] [blame] | 985 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 986 | if (mp != NULL) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 987 | ALOGW("MediaPlayer finalized without being released"); |
Marco Nelissen | 8dc2084 | 2011-09-28 09:21:11 -0700 | [diff] [blame] | 988 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 989 | android_media_MediaPlayer_release(env, thiz); |
| 990 | } |
| 991 | |
Glenn Kasten | 33b8404 | 2016-03-08 12:02:55 -0800 | [diff] [blame] | 992 | static void android_media_MediaPlayer_set_audio_session_id(JNIEnv *env, jobject thiz, |
| 993 | jint sessionId) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 994 | ALOGV("set_session_id(): %d", sessionId); |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 995 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 996 | if (mp == NULL ) { |
| 997 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 998 | return; |
| 999 | } |
Glenn Kasten | 33b8404 | 2016-03-08 12:02:55 -0800 | [diff] [blame] | 1000 | process_media_player_call( env, thiz, mp->setAudioSessionId((audio_session_t) sessionId), NULL, |
| 1001 | NULL); |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | static jint android_media_MediaPlayer_get_audio_session_id(JNIEnv *env, jobject thiz) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1005 | ALOGV("get_session_id()"); |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 1006 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 1007 | if (mp == NULL ) { |
| 1008 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 1012 | return (jint) mp->getAudioSessionId(); |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1015 | static void |
| 1016 | android_media_MediaPlayer_setAuxEffectSendLevel(JNIEnv *env, jobject thiz, jfloat level) |
| 1017 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1018 | ALOGV("setAuxEffectSendLevel: level %f", level); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1019 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 1020 | if (mp == NULL ) { |
| 1021 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 1022 | return; |
| 1023 | } |
| 1024 | process_media_player_call( env, thiz, mp->setAuxEffectSendLevel(level), NULL, NULL ); |
| 1025 | } |
| 1026 | |
| 1027 | static void android_media_MediaPlayer_attachAuxEffect(JNIEnv *env, jobject thiz, jint effectId) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1028 | ALOGV("attachAuxEffect(): %d", effectId); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1029 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 1030 | if (mp == NULL ) { |
| 1031 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 1032 | return; |
| 1033 | } |
| 1034 | process_media_player_call( env, thiz, mp->attachAuxEffect(effectId), NULL, NULL ); |
| 1035 | } |
| 1036 | |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 1037 | static jint |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 1038 | android_media_MediaPlayer_pullBatteryData( |
| 1039 | JNIEnv *env, jobject /* thiz */, jobject java_reply) |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 1040 | { |
| 1041 | sp<IBinder> binder = defaultServiceManager()->getService(String16("media.player")); |
| 1042 | sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder); |
| 1043 | if (service.get() == NULL) { |
| 1044 | jniThrowException(env, "java/lang/RuntimeException", "cannot get MediaPlayerService"); |
| 1045 | return UNKNOWN_ERROR; |
| 1046 | } |
| 1047 | |
| 1048 | Parcel *reply = parcelForJavaObject(env, java_reply); |
| 1049 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 1050 | return (jint) service->pullBatteryData(reply); |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 1051 | } |
| 1052 | |
John Grossman | 720aa28 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 1053 | static jint |
| 1054 | android_media_MediaPlayer_setRetransmitEndpoint(JNIEnv *env, jobject thiz, |
| 1055 | jstring addrString, jint port) { |
| 1056 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 1057 | if (mp == NULL ) { |
| 1058 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 1059 | return INVALID_OPERATION; |
| 1060 | } |
| 1061 | |
| 1062 | const char *cAddrString = NULL; |
| 1063 | |
| 1064 | if (NULL != addrString) { |
| 1065 | cAddrString = env->GetStringUTFChars(addrString, NULL); |
| 1066 | if (cAddrString == NULL) { // Out of memory |
| 1067 | return NO_MEMORY; |
| 1068 | } |
| 1069 | } |
| 1070 | ALOGV("setRetransmitEndpoint: %s:%d", |
| 1071 | cAddrString ? cAddrString : "(null)", port); |
| 1072 | |
| 1073 | status_t ret; |
| 1074 | if (cAddrString && (port > 0xFFFF)) { |
| 1075 | ret = BAD_VALUE; |
| 1076 | } else { |
| 1077 | ret = mp->setRetransmitEndpoint(cAddrString, |
| 1078 | static_cast<uint16_t>(port)); |
| 1079 | } |
| 1080 | |
| 1081 | if (NULL != addrString) { |
| 1082 | env->ReleaseStringUTFChars(addrString, cAddrString); |
| 1083 | } |
| 1084 | |
| 1085 | if (ret == INVALID_OPERATION ) { |
| 1086 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 1087 | } |
| 1088 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 1089 | return (jint) ret; |
John Grossman | 720aa28 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
Marco Nelissen | 84b8320 | 2012-02-28 16:07:44 -0800 | [diff] [blame] | 1092 | static void |
| 1093 | android_media_MediaPlayer_setNextMediaPlayer(JNIEnv *env, jobject thiz, jobject java_player) |
| 1094 | { |
| 1095 | ALOGV("setNextMediaPlayer"); |
| 1096 | sp<MediaPlayer> thisplayer = getMediaPlayer(env, thiz); |
| 1097 | if (thisplayer == NULL) { |
| 1098 | jniThrowException(env, "java/lang/IllegalStateException", "This player not initialized"); |
| 1099 | return; |
| 1100 | } |
| 1101 | sp<MediaPlayer> nextplayer = (java_player == NULL) ? NULL : getMediaPlayer(env, java_player); |
| 1102 | if (nextplayer == NULL && java_player != NULL) { |
| 1103 | jniThrowException(env, "java/lang/IllegalStateException", "That player not initialized"); |
| 1104 | return; |
| 1105 | } |
| 1106 | |
| 1107 | if (nextplayer == thisplayer) { |
| 1108 | jniThrowException(env, "java/lang/IllegalArgumentException", "Next player can't be self"); |
| 1109 | return; |
| 1110 | } |
| 1111 | // tie the two players together |
| 1112 | process_media_player_call( |
| 1113 | env, thiz, thisplayer->setNextMediaPlayer(nextplayer), |
| 1114 | "java/lang/IllegalArgumentException", |
| 1115 | "setNextMediaPlayer failed." ); |
| 1116 | ; |
| 1117 | } |
| 1118 | |
Andy Hung | 035d4ec | 2017-01-24 13:45:02 -0800 | [diff] [blame] | 1119 | // Pass through the arguments to the MediaServer player implementation. |
| 1120 | static jint android_media_MediaPlayer_applyVolumeShaper(JNIEnv *env, jobject thiz, |
| 1121 | jobject jconfig, jobject joperation) { |
| 1122 | // NOTE: hard code here to prevent platform issues. Must match VolumeShaper.java |
| 1123 | const int VOLUME_SHAPER_INVALID_OPERATION = -38; |
| 1124 | |
| 1125 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 1126 | if (mp == nullptr) { |
| 1127 | return (jint)VOLUME_SHAPER_INVALID_OPERATION; |
| 1128 | } |
| 1129 | |
| 1130 | sp<VolumeShaper::Configuration> configuration; |
| 1131 | sp<VolumeShaper::Operation> operation; |
| 1132 | if (jconfig != nullptr) { |
| 1133 | configuration = VolumeShaperHelper::convertJobjectToConfiguration( |
| 1134 | env, gVolumeShaperFields, jconfig); |
| 1135 | ALOGV("applyVolumeShaper configuration: %s", configuration->toString().c_str()); |
| 1136 | } |
| 1137 | if (joperation != nullptr) { |
| 1138 | operation = VolumeShaperHelper::convertJobjectToOperation( |
| 1139 | env, gVolumeShaperFields, joperation); |
| 1140 | ALOGV("applyVolumeShaper operation: %s", operation->toString().c_str()); |
| 1141 | } |
| 1142 | VolumeShaper::Status status = mp->applyVolumeShaper(configuration, operation); |
| 1143 | if (status == INVALID_OPERATION) { |
| 1144 | status = VOLUME_SHAPER_INVALID_OPERATION; |
| 1145 | } |
| 1146 | return (jint)status; // if status < 0 an error, else a VolumeShaper id |
| 1147 | } |
| 1148 | |
| 1149 | // Pass through the arguments to the MediaServer player implementation. |
| 1150 | static jobject android_media_MediaPlayer_getVolumeShaperState(JNIEnv *env, jobject thiz, |
| 1151 | jint id) { |
| 1152 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 1153 | if (mp == nullptr) { |
| 1154 | return (jobject)nullptr; |
| 1155 | } |
| 1156 | |
| 1157 | sp<VolumeShaper::State> state = mp->getVolumeShaperState((int)id); |
| 1158 | if (state.get() == nullptr) { |
| 1159 | return (jobject)nullptr; |
| 1160 | } |
| 1161 | return VolumeShaperHelper::convertStateToJobject(env, gVolumeShaperFields, state); |
| 1162 | } |
| 1163 | |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 1164 | ///////////////////////////////////////////////////////////////////////////////////// |
| 1165 | // Modular DRM begin |
| 1166 | |
| 1167 | // TODO: investigate if these can be shared with their MediaDrm counterparts |
| 1168 | static void throwDrmStateException(JNIEnv *env, const char *msg, status_t err) |
| 1169 | { |
| 1170 | ALOGE("Illegal DRM state exception: %s (%d)", msg, err); |
| 1171 | |
Hassan Shojania | 06b25fb | 2017-02-06 21:09:42 -0800 | [diff] [blame] | 1172 | jobject exception = env->NewObject(gStateExceptionFields.classId, |
| 1173 | gStateExceptionFields.init, static_cast<int>(err), |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 1174 | env->NewStringUTF(msg)); |
| 1175 | env->Throw(static_cast<jthrowable>(exception)); |
| 1176 | } |
| 1177 | |
| 1178 | // TODO: investigate if these can be shared with their MediaDrm counterparts |
| 1179 | static bool throwDrmExceptionAsNecessary(JNIEnv *env, status_t err, const char *msg = NULL) |
| 1180 | { |
| 1181 | const char *drmMessage = "Unknown DRM Msg"; |
| 1182 | |
| 1183 | switch (err) { |
| 1184 | case ERROR_DRM_UNKNOWN: |
| 1185 | drmMessage = "General DRM error"; |
| 1186 | break; |
| 1187 | case ERROR_DRM_NO_LICENSE: |
| 1188 | drmMessage = "No license"; |
| 1189 | break; |
| 1190 | case ERROR_DRM_LICENSE_EXPIRED: |
| 1191 | drmMessage = "License expired"; |
| 1192 | break; |
| 1193 | case ERROR_DRM_SESSION_NOT_OPENED: |
| 1194 | drmMessage = "Session not opened"; |
| 1195 | break; |
| 1196 | case ERROR_DRM_DECRYPT_UNIT_NOT_INITIALIZED: |
| 1197 | drmMessage = "Not initialized"; |
| 1198 | break; |
| 1199 | case ERROR_DRM_DECRYPT: |
| 1200 | drmMessage = "Decrypt error"; |
| 1201 | break; |
| 1202 | case ERROR_DRM_CANNOT_HANDLE: |
| 1203 | drmMessage = "Unsupported scheme or data format"; |
| 1204 | break; |
| 1205 | case ERROR_DRM_TAMPER_DETECTED: |
| 1206 | drmMessage = "Invalid state"; |
| 1207 | break; |
| 1208 | default: |
| 1209 | break; |
| 1210 | } |
| 1211 | |
| 1212 | String8 vendorMessage; |
| 1213 | if (err >= ERROR_DRM_VENDOR_MIN && err <= ERROR_DRM_VENDOR_MAX) { |
| 1214 | vendorMessage = String8::format("DRM vendor-defined error: %d", err); |
| 1215 | drmMessage = vendorMessage.string(); |
| 1216 | } |
| 1217 | |
| 1218 | if (err == BAD_VALUE) { |
| 1219 | jniThrowException(env, "java/lang/IllegalArgumentException", msg); |
| 1220 | return true; |
| 1221 | } else if (err == ERROR_DRM_NOT_PROVISIONED) { |
| 1222 | jniThrowException(env, "android/media/NotProvisionedException", msg); |
| 1223 | return true; |
| 1224 | } else if (err == ERROR_DRM_RESOURCE_BUSY) { |
| 1225 | jniThrowException(env, "android/media/ResourceBusyException", msg); |
| 1226 | return true; |
| 1227 | } else if (err == ERROR_DRM_DEVICE_REVOKED) { |
| 1228 | jniThrowException(env, "android/media/DeniedByServerException", msg); |
| 1229 | return true; |
| 1230 | } else if (err == DEAD_OBJECT) { |
| 1231 | jniThrowException(env, "android/media/MediaDrmResetException", |
| 1232 | "mediaserver died"); |
| 1233 | return true; |
| 1234 | } else if (err != OK) { |
| 1235 | String8 errbuf; |
| 1236 | if (drmMessage != NULL) { |
| 1237 | if (msg == NULL) { |
| 1238 | msg = drmMessage; |
| 1239 | } else { |
| 1240 | errbuf = String8::format("%s: %s", msg, drmMessage); |
| 1241 | msg = errbuf.string(); |
| 1242 | } |
| 1243 | } |
| 1244 | throwDrmStateException(env, msg, err); |
| 1245 | return true; |
| 1246 | } |
| 1247 | return false; |
| 1248 | } |
| 1249 | |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 1250 | static Vector<uint8_t> JByteArrayToVector(JNIEnv *env, jbyteArray const &byteArray) |
| 1251 | { |
| 1252 | Vector<uint8_t> vector; |
| 1253 | size_t length = env->GetArrayLength(byteArray); |
| 1254 | vector.insertAt((size_t)0, length); |
| 1255 | env->GetByteArrayRegion(byteArray, 0, length, (jbyte *)vector.editArray()); |
| 1256 | return vector; |
| 1257 | } |
| 1258 | |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 1259 | static void android_media_MediaPlayer_prepareDrm(JNIEnv *env, jobject thiz, |
Hassan Shojania | 06b25fb | 2017-02-06 21:09:42 -0800 | [diff] [blame] | 1260 | jbyteArray uuidObj, jbyteArray drmSessionIdObj) |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 1261 | { |
| 1262 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 1263 | if (mp == NULL) { |
| 1264 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 1265 | return; |
| 1266 | } |
| 1267 | |
| 1268 | if (uuidObj == NULL) { |
| 1269 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
| 1270 | return; |
| 1271 | } |
| 1272 | |
| 1273 | Vector<uint8_t> uuid = JByteArrayToVector(env, uuidObj); |
| 1274 | |
| 1275 | if (uuid.size() != 16) { |
| 1276 | jniThrowException( |
| 1277 | env, |
| 1278 | "java/lang/IllegalArgumentException", |
| 1279 | "invalid UUID size, expected 16 bytes"); |
| 1280 | return; |
| 1281 | } |
| 1282 | |
Hassan Shojania | 06b25fb | 2017-02-06 21:09:42 -0800 | [diff] [blame] | 1283 | Vector<uint8_t> drmSessionId = JByteArrayToVector(env, drmSessionIdObj); |
| 1284 | |
| 1285 | if (drmSessionId.size() == 0) { |
| 1286 | jniThrowException( |
| 1287 | env, |
| 1288 | "java/lang/IllegalArgumentException", |
| 1289 | "empty drmSessionId"); |
| 1290 | return; |
| 1291 | } |
| 1292 | |
| 1293 | status_t err = mp->prepareDrm(uuid.array(), drmSessionId); |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 1294 | if (err != OK) { |
| 1295 | if (err == INVALID_OPERATION) { |
| 1296 | jniThrowException( |
| 1297 | env, |
| 1298 | "java/lang/IllegalStateException", |
Hassan Shojania | 06b25fb | 2017-02-06 21:09:42 -0800 | [diff] [blame] | 1299 | "The player must be in prepared state."); |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 1300 | } else if (err == ERROR_DRM_CANNOT_HANDLE) { |
| 1301 | jniThrowException( |
| 1302 | env, |
| 1303 | "android/media/UnsupportedSchemeException", |
| 1304 | "Failed to instantiate drm object."); |
| 1305 | } else { |
| 1306 | throwDrmExceptionAsNecessary(env, err, "Failed to prepare DRM scheme"); |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | static void android_media_MediaPlayer_releaseDrm(JNIEnv *env, jobject thiz) |
| 1312 | { |
| 1313 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 1314 | if (mp == NULL ) { |
| 1315 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 1316 | return; |
| 1317 | } |
| 1318 | |
| 1319 | status_t err = mp->releaseDrm(); |
| 1320 | if (err != OK) { |
| 1321 | if (err == INVALID_OPERATION) { |
| 1322 | jniThrowException( |
| 1323 | env, |
| 1324 | "java/lang/IllegalStateException", |
Hassan Shojania | 06b25fb | 2017-02-06 21:09:42 -0800 | [diff] [blame] | 1325 | "Can not release DRM in an active player state."); |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 1326 | } |
| 1327 | } |
| 1328 | } |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 1329 | // Modular DRM end |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | // ---------------------------------------------------------------------------- |
| 1331 | |
jiabin | 6e5a628 | 2017-10-06 09:34:23 -0700 | [diff] [blame] | 1332 | ///////////////////////////////////////////////////////////////////////////////////// |
| 1333 | // AudioRouting begin |
| 1334 | static jboolean android_media_MediaPlayer_setOutputDevice(JNIEnv *env, jobject thiz, jint device_id) |
| 1335 | { |
| 1336 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 1337 | if (mp == NULL) { |
| 1338 | return false; |
| 1339 | } |
| 1340 | return mp->setOutputDevice(device_id) == NO_ERROR; |
| 1341 | } |
| 1342 | |
| 1343 | static jint android_media_MediaPlayer_getRoutedDeviceId(JNIEnv *env, jobject thiz) |
| 1344 | { |
| 1345 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 1346 | if (mp == NULL) { |
| 1347 | return AUDIO_PORT_HANDLE_NONE; |
| 1348 | } |
| 1349 | return mp->getRoutedDeviceId(); |
| 1350 | } |
| 1351 | |
| 1352 | static void android_media_MediaPlayer_enableDeviceCallback( |
| 1353 | JNIEnv* env, jobject thiz, jboolean enabled) |
| 1354 | { |
| 1355 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 1356 | if (mp == NULL) { |
| 1357 | return; |
| 1358 | } |
| 1359 | |
| 1360 | status_t status = mp->enableAudioDeviceCallback(enabled); |
| 1361 | if (status != NO_ERROR) { |
| 1362 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 1363 | ALOGE("enable device callback failed: %d", status); |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | // AudioRouting end |
| 1368 | // ---------------------------------------------------------------------------- |
| 1369 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 1370 | static const JNINativeMethod gMethods[] = { |
James Dong | 17524dc | 2011-05-04 13:41:58 -0700 | [diff] [blame] | 1371 | { |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 1372 | "nativeSetDataSource", |
| 1373 | "(Landroid/os/IBinder;Ljava/lang/String;[Ljava/lang/String;" |
| 1374 | "[Ljava/lang/String;)V", |
James Dong | 17524dc | 2011-05-04 13:41:58 -0700 | [diff] [blame] | 1375 | (void *)android_media_MediaPlayer_setDataSourceAndHeaders |
| 1376 | }, |
| 1377 | |
Chris Watkins | 4eaa293 | 2015-03-20 10:31:42 -0700 | [diff] [blame] | 1378 | {"_setDataSource", "(Ljava/io/FileDescriptor;JJ)V", (void *)android_media_MediaPlayer_setDataSourceFD}, |
| 1379 | {"_setDataSource", "(Landroid/media/MediaDataSource;)V",(void *)android_media_MediaPlayer_setDataSourceCallback }, |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 1380 | {"_setVideoSurface", "(Landroid/view/Surface;)V", (void *)android_media_MediaPlayer_setVideoSurface}, |
Robert Shih | c42a96d | 2014-07-25 11:08:50 -0700 | [diff] [blame] | 1381 | {"_prepare", "()V", (void *)android_media_MediaPlayer_prepare}, |
Robert Shih | 07830aa | 2015-05-27 18:11:44 -0700 | [diff] [blame] | 1382 | {"prepareAsync", "()V", (void *)android_media_MediaPlayer_prepareAsync}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1383 | {"_start", "()V", (void *)android_media_MediaPlayer_start}, |
| 1384 | {"_stop", "()V", (void *)android_media_MediaPlayer_stop}, |
| 1385 | {"getVideoWidth", "()I", (void *)android_media_MediaPlayer_getVideoWidth}, |
| 1386 | {"getVideoHeight", "()I", (void *)android_media_MediaPlayer_getVideoHeight}, |
Ray Essick | 10353e3 | 2017-04-14 10:22:55 -0700 | [diff] [blame] | 1387 | {"native_getMetrics", "()Landroid/os/PersistableBundle;", (void *)android_media_MediaPlayer_native_getMetrics}, |
Wei Jia | 2d61e2b | 2015-05-08 15:23:28 -0700 | [diff] [blame] | 1388 | {"setPlaybackParams", "(Landroid/media/PlaybackParams;)V", (void *)android_media_MediaPlayer_setPlaybackParams}, |
| 1389 | {"getPlaybackParams", "()Landroid/media/PlaybackParams;", (void *)android_media_MediaPlayer_getPlaybackParams}, |
| 1390 | {"setSyncParams", "(Landroid/media/SyncParams;)V", (void *)android_media_MediaPlayer_setSyncParams}, |
| 1391 | {"getSyncParams", "()Landroid/media/SyncParams;", (void *)android_media_MediaPlayer_getSyncParams}, |
Wei Jia | bebeaf9 | 2017-04-19 16:22:10 -0700 | [diff] [blame] | 1392 | {"_seekTo", "(JI)V", (void *)android_media_MediaPlayer_seekTo}, |
Wei Jia | c02f09d | 2017-09-13 18:19:48 -0700 | [diff] [blame] | 1393 | {"_notifyAt", "(J)V", (void *)android_media_MediaPlayer_notifyAt}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | {"_pause", "()V", (void *)android_media_MediaPlayer_pause}, |
| 1395 | {"isPlaying", "()Z", (void *)android_media_MediaPlayer_isPlaying}, |
| 1396 | {"getCurrentPosition", "()I", (void *)android_media_MediaPlayer_getCurrentPosition}, |
| 1397 | {"getDuration", "()I", (void *)android_media_MediaPlayer_getDuration}, |
| 1398 | {"_release", "()V", (void *)android_media_MediaPlayer_release}, |
| 1399 | {"_reset", "()V", (void *)android_media_MediaPlayer_reset}, |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1400 | {"_setAudioStreamType", "(I)V", (void *)android_media_MediaPlayer_setAudioStreamType}, |
| 1401 | {"_getAudioStreamType", "()I", (void *)android_media_MediaPlayer_getAudioStreamType}, |
Jean-Michel Trivi | 8df982d | 2014-06-26 12:05:16 -0700 | [diff] [blame] | 1402 | {"setParameter", "(ILandroid/os/Parcel;)Z", (void *)android_media_MediaPlayer_setParameter}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1403 | {"setLooping", "(Z)V", (void *)android_media_MediaPlayer_setLooping}, |
| 1404 | {"isLooping", "()Z", (void *)android_media_MediaPlayer_isLooping}, |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1405 | {"_setVolume", "(FF)V", (void *)android_media_MediaPlayer_setVolume}, |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 1406 | {"native_invoke", "(Landroid/os/Parcel;Landroid/os/Parcel;)I",(void *)android_media_MediaPlayer_invoke}, |
Nicolas Catania | b2c6939 | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 1407 | {"native_setMetadataFilter", "(Landroid/os/Parcel;)I", (void *)android_media_MediaPlayer_setMetadataFilter}, |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 1408 | {"native_getMetadata", "(ZZLandroid/os/Parcel;)Z", (void *)android_media_MediaPlayer_getMetadata}, |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 1409 | {"native_init", "()V", (void *)android_media_MediaPlayer_native_init}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1410 | {"native_setup", "(Ljava/lang/Object;)V", (void *)android_media_MediaPlayer_native_setup}, |
| 1411 | {"native_finalize", "()V", (void *)android_media_MediaPlayer_native_finalize}, |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 1412 | {"getAudioSessionId", "()I", (void *)android_media_MediaPlayer_get_audio_session_id}, |
| 1413 | {"setAudioSessionId", "(I)V", (void *)android_media_MediaPlayer_set_audio_session_id}, |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1414 | {"_setAuxEffectSendLevel", "(F)V", (void *)android_media_MediaPlayer_setAuxEffectSendLevel}, |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 1415 | {"attachAuxEffect", "(I)V", (void *)android_media_MediaPlayer_attachAuxEffect}, |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 1416 | {"native_pullBatteryData", "(Landroid/os/Parcel;)I", (void *)android_media_MediaPlayer_pullBatteryData}, |
John Grossman | 720aa28 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 1417 | {"native_setRetransmitEndpoint", "(Ljava/lang/String;I)I", (void *)android_media_MediaPlayer_setRetransmitEndpoint}, |
Marco Nelissen | 84b8320 | 2012-02-28 16:07:44 -0800 | [diff] [blame] | 1418 | {"setNextMediaPlayer", "(Landroid/media/MediaPlayer;)V", (void *)android_media_MediaPlayer_setNextMediaPlayer}, |
Andy Hung | 035d4ec | 2017-01-24 13:45:02 -0800 | [diff] [blame] | 1419 | {"native_applyVolumeShaper", |
| 1420 | "(Landroid/media/VolumeShaper$Configuration;Landroid/media/VolumeShaper$Operation;)I", |
| 1421 | (void *)android_media_MediaPlayer_applyVolumeShaper}, |
| 1422 | {"native_getVolumeShaperState", |
| 1423 | "(I)Landroid/media/VolumeShaper$State;", |
| 1424 | (void *)android_media_MediaPlayer_getVolumeShaperState}, |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 1425 | // Modular DRM |
Hassan Shojania | 06b25fb | 2017-02-06 21:09:42 -0800 | [diff] [blame] | 1426 | { "_prepareDrm", "([B[B)V", (void *)android_media_MediaPlayer_prepareDrm }, |
Hassan Shojania | 0b52e95 | 2017-01-23 09:06:31 -0800 | [diff] [blame] | 1427 | { "_releaseDrm", "()V", (void *)android_media_MediaPlayer_releaseDrm }, |
jiabin | 6e5a628 | 2017-10-06 09:34:23 -0700 | [diff] [blame] | 1428 | |
| 1429 | // AudioRouting |
| 1430 | {"native_setOutputDevice", "(I)Z", (void *)android_media_MediaPlayer_setOutputDevice}, |
| 1431 | {"native_getRoutedDeviceId", "()I", (void *)android_media_MediaPlayer_getRoutedDeviceId}, |
| 1432 | {"native_enableDeviceCallback", "(Z)V", (void *)android_media_MediaPlayer_enableDeviceCallback}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | }; |
| 1434 | |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 1435 | // This function only registers the native methods |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1436 | static int register_android_media_MediaPlayer(JNIEnv *env) |
| 1437 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1438 | return AndroidRuntime::registerNativeMethods(env, |
| 1439 | "android/media/MediaPlayer", gMethods, NELEM(gMethods)); |
| 1440 | } |
Zhijun He | 212e78d | 2013-06-07 11:36:23 -0700 | [diff] [blame] | 1441 | extern int register_android_media_ImageReader(JNIEnv *env); |
Zhijun He | f6a09e5 | 2015-02-24 18:12:23 -0800 | [diff] [blame] | 1442 | extern int register_android_media_ImageWriter(JNIEnv *env); |
Andreas Huber | 8240d92 | 2012-04-04 14:06:32 -0700 | [diff] [blame] | 1443 | extern int register_android_media_Crypto(JNIEnv *env); |
Jeff Tinker | 8a0c80f | 2013-02-08 10:20:44 -0800 | [diff] [blame] | 1444 | extern int register_android_media_Drm(JNIEnv *env); |
Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 1445 | extern int register_android_media_Descrambler(JNIEnv *env); |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 1446 | extern int register_android_media_MediaCodec(JNIEnv *env); |
| 1447 | extern int register_android_media_MediaExtractor(JNIEnv *env); |
Andreas Huber | 5a04bf3 | 2012-03-29 16:41:38 -0700 | [diff] [blame] | 1448 | extern int register_android_media_MediaCodecList(JNIEnv *env); |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 1449 | extern int register_android_media_MediaHTTPConnection(JNIEnv *env); |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 1450 | extern int register_android_media_MediaMetadataRetriever(JNIEnv *env); |
ztenghui | 68ccf10 | 2013-02-13 14:07:02 -0800 | [diff] [blame] | 1451 | extern int register_android_media_MediaMuxer(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | extern int register_android_media_MediaRecorder(JNIEnv *env); |
| 1453 | extern int register_android_media_MediaScanner(JNIEnv *env); |
Wei Jia | 071a8b7 | 2015-03-09 16:38:25 -0700 | [diff] [blame] | 1454 | extern int register_android_media_MediaSync(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | extern int register_android_media_ResampleInputStream(JNIEnv *env); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1456 | extern int register_android_media_MediaProfiles(JNIEnv *env); |
Mike Lockwood | 0cd0136 | 2010-12-30 11:54:33 -0500 | [diff] [blame] | 1457 | extern int register_android_mtp_MtpDatabase(JNIEnv *env); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 1458 | extern int register_android_mtp_MtpDevice(JNIEnv *env); |
Mike Lockwood | 0cd0136 | 2010-12-30 11:54:33 -0500 | [diff] [blame] | 1459 | extern int register_android_mtp_MtpServer(JNIEnv *env); |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 1460 | |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 1461 | jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1462 | { |
| 1463 | JNIEnv* env = NULL; |
| 1464 | jint result = -1; |
| 1465 | |
| 1466 | if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1467 | ALOGE("ERROR: GetEnv failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | goto bail; |
| 1469 | } |
| 1470 | assert(env != NULL); |
| 1471 | |
Zhijun He | f6a09e5 | 2015-02-24 18:12:23 -0800 | [diff] [blame] | 1472 | if (register_android_media_ImageWriter(env) != JNI_OK) { |
| 1473 | ALOGE("ERROR: ImageWriter native registration failed"); |
| 1474 | goto bail; |
| 1475 | } |
| 1476 | |
Zhijun He | 212e78d | 2013-06-07 11:36:23 -0700 | [diff] [blame] | 1477 | if (register_android_media_ImageReader(env) < 0) { |
| 1478 | ALOGE("ERROR: ImageReader native registration failed"); |
| 1479 | goto bail; |
| 1480 | } |
| 1481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | if (register_android_media_MediaPlayer(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1483 | ALOGE("ERROR: MediaPlayer native registration failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1484 | goto bail; |
| 1485 | } |
| 1486 | |
| 1487 | if (register_android_media_MediaRecorder(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1488 | ALOGE("ERROR: MediaRecorder native registration failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | goto bail; |
| 1490 | } |
| 1491 | |
| 1492 | if (register_android_media_MediaScanner(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1493 | ALOGE("ERROR: MediaScanner native registration failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | goto bail; |
| 1495 | } |
| 1496 | |
| 1497 | if (register_android_media_MediaMetadataRetriever(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1498 | ALOGE("ERROR: MediaMetadataRetriever native registration failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1499 | goto bail; |
| 1500 | } |
| 1501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | if (register_android_media_ResampleInputStream(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1503 | ALOGE("ERROR: ResampleInputStream native registration failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1504 | goto bail; |
| 1505 | } |
| 1506 | |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1507 | if (register_android_media_MediaProfiles(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1508 | ALOGE("ERROR: MediaProfiles native registration failed"); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1509 | goto bail; |
| 1510 | } |
| 1511 | |
Mike Lockwood | 0cd0136 | 2010-12-30 11:54:33 -0500 | [diff] [blame] | 1512 | if (register_android_mtp_MtpDatabase(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1513 | ALOGE("ERROR: MtpDatabase native registration failed"); |
Mike Lockwood | d21eac9 | 2010-07-03 00:44:05 -0400 | [diff] [blame] | 1514 | goto bail; |
| 1515 | } |
| 1516 | |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 1517 | if (register_android_mtp_MtpDevice(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1518 | ALOGE("ERROR: MtpDevice native registration failed"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 1519 | goto bail; |
| 1520 | } |
| 1521 | |
Mike Lockwood | 0cd0136 | 2010-12-30 11:54:33 -0500 | [diff] [blame] | 1522 | if (register_android_mtp_MtpServer(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1523 | ALOGE("ERROR: MtpServer native registration failed"); |
Mike Lockwood | 81ea83d | 2010-06-30 17:49:41 -0400 | [diff] [blame] | 1524 | goto bail; |
| 1525 | } |
| 1526 | |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 1527 | if (register_android_media_MediaCodec(env) < 0) { |
| 1528 | ALOGE("ERROR: MediaCodec native registration failed"); |
| 1529 | goto bail; |
| 1530 | } |
| 1531 | |
Wei Jia | 071a8b7 | 2015-03-09 16:38:25 -0700 | [diff] [blame] | 1532 | if (register_android_media_MediaSync(env) < 0) { |
| 1533 | ALOGE("ERROR: MediaSync native registration failed"); |
| 1534 | goto bail; |
| 1535 | } |
| 1536 | |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 1537 | if (register_android_media_MediaExtractor(env) < 0) { |
| 1538 | ALOGE("ERROR: MediaCodec native registration failed"); |
| 1539 | goto bail; |
| 1540 | } |
| 1541 | |
ztenghui | 68ccf10 | 2013-02-13 14:07:02 -0800 | [diff] [blame] | 1542 | if (register_android_media_MediaMuxer(env) < 0) { |
| 1543 | ALOGE("ERROR: MediaMuxer native registration failed"); |
| 1544 | goto bail; |
| 1545 | } |
| 1546 | |
Andreas Huber | 5a04bf3 | 2012-03-29 16:41:38 -0700 | [diff] [blame] | 1547 | if (register_android_media_MediaCodecList(env) < 0) { |
| 1548 | ALOGE("ERROR: MediaCodec native registration failed"); |
| 1549 | goto bail; |
| 1550 | } |
| 1551 | |
Andreas Huber | 8240d92 | 2012-04-04 14:06:32 -0700 | [diff] [blame] | 1552 | if (register_android_media_Crypto(env) < 0) { |
| 1553 | ALOGE("ERROR: MediaCodec native registration failed"); |
| 1554 | goto bail; |
| 1555 | } |
| 1556 | |
Jeff Tinker | 8a0c80f | 2013-02-08 10:20:44 -0800 | [diff] [blame] | 1557 | if (register_android_media_Drm(env) < 0) { |
| 1558 | ALOGE("ERROR: MediaDrm native registration failed"); |
| 1559 | goto bail; |
| 1560 | } |
| 1561 | |
Chong Zhang | d5927ae | 2017-01-03 11:07:18 -0800 | [diff] [blame] | 1562 | if (register_android_media_Descrambler(env) < 0) { |
| 1563 | ALOGE("ERROR: MediaDescrambler native registration failed"); |
| 1564 | goto bail; |
| 1565 | } |
| 1566 | |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 1567 | if (register_android_media_MediaHTTPConnection(env) < 0) { |
| 1568 | ALOGE("ERROR: MediaHTTPConnection native registration failed"); |
| 1569 | goto bail; |
| 1570 | } |
| 1571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1572 | /* success -- return valid version number */ |
| 1573 | result = JNI_VERSION_1_4; |
| 1574 | |
| 1575 | bail: |
| 1576 | return result; |
| 1577 | } |
| 1578 | |
| 1579 | // KTHXBYE |