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> |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 23 | #include <media/IMediaHTTPService.h> |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 24 | #include <media/MediaPlayerInterface.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <assert.h> |
| 27 | #include <limits.h> |
| 28 | #include <unistd.h> |
| 29 | #include <fcntl.h> |
| 30 | #include <utils/threads.h> |
| 31 | #include "jni.h" |
| 32 | #include "JNIHelp.h" |
| 33 | #include "android_runtime/AndroidRuntime.h" |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 34 | #include "android_runtime/android_view_Surface.h" |
Ruben Brunk | 87eac99 | 2013-09-09 17:44:59 -0700 | [diff] [blame] | 35 | #include "android_runtime/Log.h" |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 36 | #include "utils/Errors.h" // for status_t |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 37 | #include "utils/KeyedVector.h" |
| 38 | #include "utils/String8.h" |
James Dong | 79f407c | 2011-05-05 12:50:04 -0700 | [diff] [blame] | 39 | #include "android_media_Utils.h" |
| 40 | |
Jeff Sharkey | d84e1ce | 2012-03-06 18:26:19 -0800 | [diff] [blame] | 41 | #include "android_os_Parcel.h" |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 42 | #include "android_util_Binder.h" |
| 43 | #include <binder/Parcel.h> |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 44 | #include <gui/IGraphicBufferProducer.h> |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 45 | #include <gui/Surface.h> |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 46 | #include <binder/IPCThreadState.h> |
| 47 | #include <binder/IServiceManager.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 49 | #include "android_util_Binder.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | // ---------------------------------------------------------------------------- |
| 51 | |
| 52 | using namespace android; |
| 53 | |
| 54 | // ---------------------------------------------------------------------------- |
| 55 | |
| 56 | struct fields_t { |
| 57 | jfieldID context; |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 58 | jfieldID surface_texture; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
| 60 | jmethodID post_event; |
Andreas Huber | d5f9fa5 | 2013-05-28 14:39:39 -0700 | [diff] [blame] | 61 | |
| 62 | jmethodID proxyConfigGetHost; |
| 63 | jmethodID proxyConfigGetPort; |
| 64 | jmethodID proxyConfigGetExclusionList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | }; |
| 66 | static fields_t fields; |
| 67 | |
| 68 | static Mutex sLock; |
| 69 | |
| 70 | // ---------------------------------------------------------------------------- |
| 71 | // ref-counted object for callbacks |
| 72 | class JNIMediaPlayerListener: public MediaPlayerListener |
| 73 | { |
| 74 | public: |
| 75 | JNIMediaPlayerListener(JNIEnv* env, jobject thiz, jobject weak_thiz); |
| 76 | ~JNIMediaPlayerListener(); |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 77 | 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] | 78 | private: |
| 79 | JNIMediaPlayerListener(); |
| 80 | jclass mClass; // Reference to MediaPlayer class |
| 81 | jobject mObject; // Weak ref to MediaPlayer Java object to call on |
| 82 | }; |
| 83 | |
| 84 | JNIMediaPlayerListener::JNIMediaPlayerListener(JNIEnv* env, jobject thiz, jobject weak_thiz) |
| 85 | { |
| 86 | |
| 87 | // Hold onto the MediaPlayer class for use in calling the static method |
| 88 | // that posts events to the application thread. |
| 89 | jclass clazz = env->GetObjectClass(thiz); |
| 90 | if (clazz == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 91 | ALOGE("Can't find android/media/MediaPlayer"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | jniThrowException(env, "java/lang/Exception", NULL); |
| 93 | return; |
| 94 | } |
| 95 | mClass = (jclass)env->NewGlobalRef(clazz); |
| 96 | |
| 97 | // We use a weak reference so the MediaPlayer object can be garbage collected. |
| 98 | // The reference is only used as a proxy for callbacks. |
| 99 | mObject = env->NewGlobalRef(weak_thiz); |
| 100 | } |
| 101 | |
| 102 | JNIMediaPlayerListener::~JNIMediaPlayerListener() |
| 103 | { |
| 104 | // remove global references |
| 105 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 106 | env->DeleteGlobalRef(mObject); |
| 107 | env->DeleteGlobalRef(mClass); |
| 108 | } |
| 109 | |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 110 | 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] | 111 | { |
| 112 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 113 | if (obj && obj->dataSize() > 0) { |
Insun Kang | 333c099 | 2012-07-10 12:47:03 +0900 | [diff] [blame] | 114 | jobject jParcel = createJavaParcelObject(env); |
| 115 | if (jParcel != NULL) { |
| 116 | Parcel* nativeParcel = parcelForJavaObject(env, jParcel); |
Insun Kang | 8902097 | 2012-05-01 14:13:19 +0900 | [diff] [blame] | 117 | nativeParcel->setData(obj->data(), obj->dataSize()); |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 118 | env->CallStaticVoidMethod(mClass, fields.post_event, mObject, |
Insun Kang | 333c099 | 2012-07-10 12:47:03 +0900 | [diff] [blame] | 119 | msg, ext1, ext2, jParcel); |
Elliott Hughes | 99f7521 | 2013-11-13 15:10:40 -0800 | [diff] [blame] | 120 | env->DeleteLocalRef(jParcel); |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 121 | } |
| 122 | } else { |
| 123 | env->CallStaticVoidMethod(mClass, fields.post_event, mObject, |
| 124 | msg, ext1, ext2, NULL); |
| 125 | } |
Insun Kang | 8902097 | 2012-05-01 14:13:19 +0900 | [diff] [blame] | 126 | if (env->ExceptionCheck()) { |
| 127 | ALOGW("An exception occurred while notifying an event."); |
| 128 | LOGW_EX(env); |
| 129 | env->ExceptionClear(); |
| 130 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | // ---------------------------------------------------------------------------- |
| 134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | static sp<MediaPlayer> getMediaPlayer(JNIEnv* env, jobject thiz) |
| 136 | { |
| 137 | Mutex::Autolock l(sLock); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 138 | MediaPlayer* const p = (MediaPlayer*)env->GetLongField(thiz, fields.context); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | return sp<MediaPlayer>(p); |
| 140 | } |
| 141 | |
| 142 | static sp<MediaPlayer> setMediaPlayer(JNIEnv* env, jobject thiz, const sp<MediaPlayer>& player) |
| 143 | { |
| 144 | Mutex::Autolock l(sLock); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 145 | sp<MediaPlayer> old = (MediaPlayer*)env->GetLongField(thiz, fields.context); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | if (player.get()) { |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 147 | player->incStrong((void*)setMediaPlayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | } |
| 149 | if (old != 0) { |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 150 | old->decStrong((void*)setMediaPlayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | } |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 152 | env->SetLongField(thiz, fields.context, (jlong)player.get()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | return old; |
| 154 | } |
| 155 | |
Nicolas Catania | 32f8277 | 2009-06-11 16:33:49 -0700 | [diff] [blame] | 156 | // If exception is NULL and opStatus is not OK, this method sends an error |
| 157 | // 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] | 158 | // opStatus is not OK, this method throws the given exception to the client |
| 159 | // application. |
| 160 | static void process_media_player_call(JNIEnv *env, jobject thiz, status_t opStatus, const char* exception, const char *message) |
| 161 | { |
| 162 | if (exception == NULL) { // Don't throw exception. Instead, send an event. |
| 163 | if (opStatus != (status_t) OK) { |
| 164 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 165 | if (mp != 0) mp->notify(MEDIA_ERROR, opStatus, 0); |
| 166 | } |
| 167 | } else { // Throw exception! |
| 168 | if ( opStatus == (status_t) INVALID_OPERATION ) { |
| 169 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
Dave Burke | fc301b0 | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 170 | } else if ( opStatus == (status_t) PERMISSION_DENIED ) { |
| 171 | jniThrowException(env, "java/lang/SecurityException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | } else if ( opStatus != (status_t) OK ) { |
| 173 | if (strlen(message) > 230) { |
| 174 | // if the message is too long, don't bother displaying the status code |
| 175 | jniThrowException( env, exception, message); |
| 176 | } else { |
| 177 | char msg[256]; |
| 178 | // append the status code to the message |
| 179 | sprintf(msg, "%s: status=0x%X", message, opStatus); |
| 180 | jniThrowException( env, exception, msg); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | static void |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 187 | android_media_MediaPlayer_setDataSourceAndHeaders( |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 188 | JNIEnv *env, jobject thiz, jobject httpServiceBinderObj, jstring path, |
James Dong | 17524dc | 2011-05-04 13:41:58 -0700 | [diff] [blame] | 189 | jobjectArray keys, jobjectArray values) { |
| 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 192 | if (mp == NULL ) { |
| 193 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 194 | return; |
| 195 | } |
| 196 | |
| 197 | if (path == NULL) { |
| 198 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
| 199 | return; |
| 200 | } |
| 201 | |
James Dong | c371a02 | 2011-04-06 12:16:07 -0700 | [diff] [blame] | 202 | const char *tmp = env->GetStringUTFChars(path, NULL); |
| 203 | if (tmp == NULL) { // Out of memory |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | return; |
| 205 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 206 | ALOGV("setDataSource: path %s", tmp); |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 207 | |
James Dong | c371a02 | 2011-04-06 12:16:07 -0700 | [diff] [blame] | 208 | String8 pathStr(tmp); |
| 209 | env->ReleaseStringUTFChars(path, tmp); |
| 210 | tmp = NULL; |
| 211 | |
James Dong | 17524dc | 2011-05-04 13:41:58 -0700 | [diff] [blame] | 212 | // We build a KeyedVector out of the key and val arrays |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 213 | KeyedVector<String8, String8> headersVector; |
James Dong | 79f407c | 2011-05-05 12:50:04 -0700 | [diff] [blame] | 214 | if (!ConvertKeyValueArraysToKeyedVector( |
| 215 | env, keys, values, &headersVector)) { |
| 216 | return; |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 219 | sp<IMediaHTTPService> httpService; |
| 220 | if (httpServiceBinderObj != NULL) { |
| 221 | sp<IBinder> binder = ibinderForJavaObject(env, httpServiceBinderObj); |
| 222 | httpService = interface_cast<IMediaHTTPService>(binder); |
| 223 | } |
| 224 | |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 225 | status_t opStatus = |
| 226 | mp->setDataSource( |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 227 | httpService, |
James Dong | c371a02 | 2011-04-06 12:16:07 -0700 | [diff] [blame] | 228 | pathStr, |
James Dong | 79f407c | 2011-05-05 12:50:04 -0700 | [diff] [blame] | 229 | headersVector.size() > 0? &headersVector : NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 231 | process_media_player_call( |
| 232 | env, thiz, opStatus, "java/io/IOException", |
| 233 | "setDataSource failed." ); |
| 234 | } |
| 235 | |
| 236 | static void |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | android_media_MediaPlayer_setDataSourceFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length) |
| 238 | { |
| 239 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 240 | if (mp == NULL ) { |
| 241 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 242 | return; |
| 243 | } |
| 244 | |
| 245 | if (fileDescriptor == NULL) { |
| 246 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
| 247 | return; |
| 248 | } |
Elliott Hughes | a3804cf | 2011-04-11 16:50:19 -0700 | [diff] [blame] | 249 | int fd = jniGetFDFromFileDescriptor(env, fileDescriptor); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 250 | ALOGV("setDataSourceFD: fd %d", fd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | process_media_player_call( env, thiz, mp->setDataSource(fd, offset, length), "java/io/IOException", "setDataSourceFD failed." ); |
| 252 | } |
| 253 | |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 254 | static sp<IGraphicBufferProducer> |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 255 | getVideoSurfaceTexture(JNIEnv* env, jobject thiz) { |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 256 | IGraphicBufferProducer * const p = (IGraphicBufferProducer*)env->GetLongField(thiz, fields.surface_texture); |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 257 | return sp<IGraphicBufferProducer>(p); |
Dave Sparks | 8b0b174 | 2009-05-29 09:01:20 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static void |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 261 | decVideoSurfaceRef(JNIEnv *env, jobject thiz) |
| 262 | { |
Gloria Wang | e828beb | 2011-09-15 15:28:43 -0700 | [diff] [blame] | 263 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 264 | if (mp == NULL) { |
| 265 | return; |
| 266 | } |
| 267 | |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 268 | sp<IGraphicBufferProducer> old_st = getVideoSurfaceTexture(env, thiz); |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 269 | if (old_st != NULL) { |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 270 | old_st->decStrong((void*)decVideoSurfaceRef); |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
| 274 | static void |
James Dong | 43ef913 | 2011-08-12 11:33:27 -0700 | [diff] [blame] | 275 | setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface, jboolean mediaPlayerMustBeAlive) |
Dave Sparks | 8b0b174 | 2009-05-29 09:01:20 -0700 | [diff] [blame] | 276 | { |
| 277 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
James Dong | 43ef913 | 2011-08-12 11:33:27 -0700 | [diff] [blame] | 278 | if (mp == NULL) { |
| 279 | if (mediaPlayerMustBeAlive) { |
| 280 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 281 | } |
Dave Sparks | 8b0b174 | 2009-05-29 09:01:20 -0700 | [diff] [blame] | 282 | return; |
| 283 | } |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 284 | |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 285 | decVideoSurfaceRef(env, thiz); |
| 286 | |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 287 | sp<IGraphicBufferProducer> new_st; |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 288 | if (jsurface) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 289 | sp<Surface> surface(android_view_Surface_getSurface(env, jsurface)); |
Jamie Gennis | f76afc8 | 2011-10-14 19:06:55 -0700 | [diff] [blame] | 290 | if (surface != NULL) { |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 291 | new_st = surface->getIGraphicBufferProducer(); |
James Dong | 097922b | 2012-10-04 09:16:40 -0700 | [diff] [blame] | 292 | if (new_st == NULL) { |
| 293 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 294 | "The surface does not have a binding SurfaceTexture!"); |
| 295 | return; |
| 296 | } |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 297 | new_st->incStrong((void*)decVideoSurfaceRef); |
Jamie Gennis | f76afc8 | 2011-10-14 19:06:55 -0700 | [diff] [blame] | 298 | } else { |
| 299 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 300 | "The surface has been released"); |
| 301 | return; |
| 302 | } |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 303 | } |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 304 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 305 | env->SetLongField(thiz, fields.surface_texture, (jlong)new_st.get()); |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 306 | |
| 307 | // This will fail if the media player has not been initialized yet. This |
| 308 | // can be the case if setDisplay() on MediaPlayer.java has been called |
| 309 | // before setDataSource(). The redundant call to setVideoSurfaceTexture() |
| 310 | // in prepare/prepareAsync covers for this case. |
| 311 | mp->setVideoSurfaceTexture(new_st); |
Dave Sparks | 8b0b174 | 2009-05-29 09:01:20 -0700 | [diff] [blame] | 312 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | |
| 314 | static void |
James Dong | 43ef913 | 2011-08-12 11:33:27 -0700 | [diff] [blame] | 315 | android_media_MediaPlayer_setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface) |
| 316 | { |
| 317 | setVideoSurface(env, thiz, jsurface, true /* mediaPlayerMustBeAlive */); |
| 318 | } |
| 319 | |
| 320 | static void |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | android_media_MediaPlayer_prepare(JNIEnv *env, jobject thiz) |
| 322 | { |
| 323 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 324 | if (mp == NULL ) { |
| 325 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 326 | return; |
| 327 | } |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 328 | |
| 329 | // Handle the case where the display surface was set before the mp was |
| 330 | // initialized. We try again to make it stick. |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 331 | sp<IGraphicBufferProducer> st = getVideoSurfaceTexture(env, thiz); |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 332 | mp->setVideoSurfaceTexture(st); |
| 333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | process_media_player_call( env, thiz, mp->prepare(), "java/io/IOException", "Prepare failed." ); |
| 335 | } |
| 336 | |
| 337 | static void |
| 338 | android_media_MediaPlayer_prepareAsync(JNIEnv *env, jobject thiz) |
| 339 | { |
| 340 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 341 | if (mp == NULL ) { |
| 342 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 343 | return; |
| 344 | } |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 345 | |
| 346 | // Handle the case where the display surface was set before the mp was |
| 347 | // initialized. We try again to make it stick. |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 348 | sp<IGraphicBufferProducer> st = getVideoSurfaceTexture(env, thiz); |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 349 | mp->setVideoSurfaceTexture(st); |
| 350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | process_media_player_call( env, thiz, mp->prepareAsync(), "java/io/IOException", "Prepare Async failed." ); |
| 352 | } |
| 353 | |
| 354 | static void |
| 355 | android_media_MediaPlayer_start(JNIEnv *env, jobject thiz) |
| 356 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 357 | ALOGV("start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 359 | if (mp == NULL ) { |
| 360 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 361 | return; |
| 362 | } |
| 363 | process_media_player_call( env, thiz, mp->start(), NULL, NULL ); |
| 364 | } |
| 365 | |
| 366 | static void |
| 367 | android_media_MediaPlayer_stop(JNIEnv *env, jobject thiz) |
| 368 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 369 | ALOGV("stop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 371 | if (mp == NULL ) { |
| 372 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 373 | return; |
| 374 | } |
Nicolas Catania | 32f8277 | 2009-06-11 16:33:49 -0700 | [diff] [blame] | 375 | 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] | 376 | } |
| 377 | |
| 378 | static void |
| 379 | android_media_MediaPlayer_pause(JNIEnv *env, jobject thiz) |
| 380 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 381 | ALOGV("pause"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 383 | if (mp == NULL ) { |
| 384 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 385 | return; |
| 386 | } |
| 387 | process_media_player_call( env, thiz, mp->pause(), NULL, NULL ); |
| 388 | } |
| 389 | |
| 390 | static jboolean |
| 391 | android_media_MediaPlayer_isPlaying(JNIEnv *env, jobject thiz) |
| 392 | { |
| 393 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 394 | if (mp == NULL ) { |
| 395 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 396 | return JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 398 | const jboolean is_playing = mp->isPlaying(); |
| 399 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 400 | ALOGV("isPlaying: %d", is_playing); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 401 | return is_playing; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static void |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 405 | android_media_MediaPlayer_seekTo(JNIEnv *env, jobject thiz, jint msec) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | { |
| 407 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 408 | if (mp == NULL ) { |
| 409 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 410 | return; |
| 411 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 412 | ALOGV("seekTo: %d(msec)", msec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | process_media_player_call( env, thiz, mp->seekTo(msec), NULL, NULL ); |
| 414 | } |
| 415 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 416 | static jint |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | android_media_MediaPlayer_getVideoWidth(JNIEnv *env, jobject thiz) |
| 418 | { |
| 419 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 420 | if (mp == NULL ) { |
| 421 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 422 | return 0; |
| 423 | } |
| 424 | int w; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 425 | if (0 != mp->getVideoWidth(&w)) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 426 | ALOGE("getVideoWidth failed"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 427 | w = 0; |
| 428 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 429 | ALOGV("getVideoWidth: %d", w); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 430 | return (jint) w; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 433 | static jint |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | android_media_MediaPlayer_getVideoHeight(JNIEnv *env, jobject thiz) |
| 435 | { |
| 436 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 437 | if (mp == NULL ) { |
| 438 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 439 | return 0; |
| 440 | } |
| 441 | int h; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 442 | if (0 != mp->getVideoHeight(&h)) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 443 | ALOGE("getVideoHeight failed"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 444 | h = 0; |
| 445 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 446 | ALOGV("getVideoHeight: %d", h); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 447 | return (jint) h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 451 | static jint |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | android_media_MediaPlayer_getCurrentPosition(JNIEnv *env, jobject thiz) |
| 453 | { |
| 454 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 455 | if (mp == NULL ) { |
| 456 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 457 | return 0; |
| 458 | } |
| 459 | int msec; |
| 460 | process_media_player_call( env, thiz, mp->getCurrentPosition(&msec), NULL, NULL ); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 461 | ALOGV("getCurrentPosition: %d (msec)", msec); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 462 | return (jint) msec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | } |
| 464 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 465 | static jint |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | android_media_MediaPlayer_getDuration(JNIEnv *env, jobject thiz) |
| 467 | { |
| 468 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 469 | if (mp == NULL ) { |
| 470 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 471 | return 0; |
| 472 | } |
| 473 | int msec; |
| 474 | process_media_player_call( env, thiz, mp->getDuration(&msec), NULL, NULL ); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 475 | ALOGV("getDuration: %d (msec)", msec); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 476 | return (jint) msec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | static void |
| 480 | android_media_MediaPlayer_reset(JNIEnv *env, jobject thiz) |
| 481 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 482 | ALOGV("reset"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 483 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 484 | if (mp == NULL ) { |
| 485 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 486 | return; |
| 487 | } |
| 488 | process_media_player_call( env, thiz, mp->reset(), NULL, NULL ); |
| 489 | } |
| 490 | |
| 491 | static void |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 492 | 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] | 493 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 494 | ALOGV("setAudioStreamType: %d", streamtype); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 496 | if (mp == NULL ) { |
| 497 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 498 | return; |
| 499 | } |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 500 | 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] | 501 | } |
| 502 | |
| 503 | static void |
| 504 | android_media_MediaPlayer_setLooping(JNIEnv *env, jobject thiz, jboolean looping) |
| 505 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 506 | ALOGV("setLooping: %d", looping); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 508 | if (mp == NULL ) { |
| 509 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 510 | return; |
| 511 | } |
| 512 | process_media_player_call( env, thiz, mp->setLooping(looping), NULL, NULL ); |
| 513 | } |
| 514 | |
| 515 | static jboolean |
| 516 | android_media_MediaPlayer_isLooping(JNIEnv *env, jobject thiz) |
| 517 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 518 | ALOGV("isLooping"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 520 | if (mp == NULL ) { |
| 521 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 522 | return JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | } |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 524 | return mp->isLooping() ? JNI_TRUE : JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | static void |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 528 | 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] | 529 | { |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 530 | 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] | 531 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 532 | if (mp == NULL ) { |
| 533 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 534 | return; |
| 535 | } |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 536 | 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] | 537 | } |
| 538 | |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 539 | // Sends the request and reply parcels to the media player via the |
| 540 | // binder interface. |
| 541 | static jint |
| 542 | android_media_MediaPlayer_invoke(JNIEnv *env, jobject thiz, |
| 543 | jobject java_request, jobject java_reply) |
| 544 | { |
| 545 | sp<MediaPlayer> media_player = getMediaPlayer(env, thiz); |
| 546 | if (media_player == NULL ) { |
| 547 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
Nicolas Catania | b2c6939 | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 548 | return UNKNOWN_ERROR; |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 551 | Parcel *request = parcelForJavaObject(env, java_request); |
| 552 | Parcel *reply = parcelForJavaObject(env, java_reply); |
| 553 | |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 554 | // Don't use process_media_player_call which use the async loop to |
| 555 | // report errors, instead returns the status. |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 556 | return (jint) media_player->invoke(*request, reply); |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Nicolas Catania | b2c6939 | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 559 | // Sends the new filter to the client. |
| 560 | static jint |
| 561 | android_media_MediaPlayer_setMetadataFilter(JNIEnv *env, jobject thiz, jobject request) |
| 562 | { |
| 563 | sp<MediaPlayer> media_player = getMediaPlayer(env, thiz); |
| 564 | if (media_player == NULL ) { |
| 565 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 566 | return UNKNOWN_ERROR; |
| 567 | } |
| 568 | |
| 569 | Parcel *filter = parcelForJavaObject(env, request); |
| 570 | |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 571 | if (filter == NULL ) { |
| 572 | jniThrowException(env, "java/lang/RuntimeException", "Filter is null"); |
| 573 | return UNKNOWN_ERROR; |
| 574 | } |
| 575 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 576 | return (jint) media_player->setMetadataFilter(*filter); |
Nicolas Catania | b2c6939 | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 579 | static jboolean |
| 580 | android_media_MediaPlayer_getMetadata(JNIEnv *env, jobject thiz, jboolean update_only, |
| 581 | jboolean apply_filter, jobject reply) |
| 582 | { |
| 583 | sp<MediaPlayer> media_player = getMediaPlayer(env, thiz); |
| 584 | if (media_player == NULL ) { |
| 585 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 586 | return JNI_FALSE; |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | Parcel *metadata = parcelForJavaObject(env, reply); |
| 590 | |
| 591 | if (metadata == NULL ) { |
| 592 | jniThrowException(env, "java/lang/RuntimeException", "Reply parcel is null"); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 593 | return JNI_FALSE; |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | metadata->freeData(); |
| 597 | // On return metadata is positioned at the beginning of the |
| 598 | // metadata. Note however that the parcel actually starts with the |
| 599 | // return code so you should not rewind the parcel using |
| 600 | // setDataPosition(0). |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 601 | if (media_player->getMetadata(update_only, apply_filter, metadata) == OK) { |
| 602 | return JNI_TRUE; |
| 603 | } else { |
| 604 | return JNI_FALSE; |
| 605 | } |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 608 | // This function gets some field IDs, which in turn causes class initialization. |
| 609 | // It is called from a static block in MediaPlayer, which won't run until the |
| 610 | // first time an instance of this class is used. |
| 611 | static void |
| 612 | android_media_MediaPlayer_native_init(JNIEnv *env) |
| 613 | { |
| 614 | jclass clazz; |
| 615 | |
| 616 | clazz = env->FindClass("android/media/MediaPlayer"); |
| 617 | if (clazz == NULL) { |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 618 | return; |
| 619 | } |
| 620 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 621 | fields.context = env->GetFieldID(clazz, "mNativeContext", "J"); |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 622 | if (fields.context == NULL) { |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 623 | return; |
| 624 | } |
| 625 | |
| 626 | fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative", |
| 627 | "(Ljava/lang/Object;IIILjava/lang/Object;)V"); |
| 628 | if (fields.post_event == NULL) { |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 629 | return; |
| 630 | } |
| 631 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 632 | fields.surface_texture = env->GetFieldID(clazz, "mNativeSurfaceTexture", "J"); |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 633 | if (fields.surface_texture == NULL) { |
Glenn Kasten | cc562a3 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 634 | return; |
| 635 | } |
Andreas Huber | d5f9fa5 | 2013-05-28 14:39:39 -0700 | [diff] [blame] | 636 | |
| 637 | clazz = env->FindClass("android/net/ProxyProperties"); |
| 638 | if (clazz == NULL) { |
| 639 | return; |
| 640 | } |
| 641 | |
| 642 | fields.proxyConfigGetHost = |
| 643 | env->GetMethodID(clazz, "getHost", "()Ljava/lang/String;"); |
| 644 | |
| 645 | fields.proxyConfigGetPort = |
| 646 | env->GetMethodID(clazz, "getPort", "()I"); |
| 647 | |
| 648 | fields.proxyConfigGetExclusionList = |
| 649 | env->GetMethodID(clazz, "getExclusionList", "()Ljava/lang/String;"); |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 650 | } |
Nicolas Catania | b2c6939 | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 652 | static void |
| 653 | android_media_MediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this) |
| 654 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 655 | ALOGV("native_setup"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | sp<MediaPlayer> mp = new MediaPlayer(); |
| 657 | if (mp == NULL) { |
| 658 | jniThrowException(env, "java/lang/RuntimeException", "Out of memory"); |
| 659 | return; |
| 660 | } |
| 661 | |
| 662 | // create new listener and give it to MediaPlayer |
| 663 | sp<JNIMediaPlayerListener> listener = new JNIMediaPlayerListener(env, thiz, weak_this); |
| 664 | mp->setListener(listener); |
| 665 | |
| 666 | // Stow our new C++ MediaPlayer in an opaque field in the Java object. |
| 667 | setMediaPlayer(env, thiz, mp); |
| 668 | } |
| 669 | |
| 670 | static void |
| 671 | android_media_MediaPlayer_release(JNIEnv *env, jobject thiz) |
| 672 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 673 | ALOGV("release"); |
Gloria Wang | d59310d | 2011-09-14 13:59:45 -0700 | [diff] [blame] | 674 | decVideoSurfaceRef(env, thiz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | sp<MediaPlayer> mp = setMediaPlayer(env, thiz, 0); |
| 676 | if (mp != NULL) { |
| 677 | // this prevents native callbacks after the object is released |
| 678 | mp->setListener(0); |
| 679 | mp->disconnect(); |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | static void |
| 684 | android_media_MediaPlayer_native_finalize(JNIEnv *env, jobject thiz) |
| 685 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 686 | ALOGV("native_finalize"); |
Marco Nelissen | 8dc2084 | 2011-09-28 09:21:11 -0700 | [diff] [blame] | 687 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 688 | if (mp != NULL) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 689 | ALOGW("MediaPlayer finalized without being released"); |
Marco Nelissen | 8dc2084 | 2011-09-28 09:21:11 -0700 | [diff] [blame] | 690 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | android_media_MediaPlayer_release(env, thiz); |
| 692 | } |
| 693 | |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 694 | static void android_media_MediaPlayer_set_audio_session_id(JNIEnv *env, jobject thiz, jint sessionId) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 695 | ALOGV("set_session_id(): %d", sessionId); |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 696 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 697 | if (mp == NULL ) { |
| 698 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 699 | return; |
| 700 | } |
| 701 | process_media_player_call( env, thiz, mp->setAudioSessionId(sessionId), NULL, NULL ); |
| 702 | } |
| 703 | |
| 704 | 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] | 705 | ALOGV("get_session_id()"); |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 706 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 707 | if (mp == NULL ) { |
| 708 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 709 | return 0; |
| 710 | } |
| 711 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 712 | return (jint) mp->getAudioSessionId(); |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 715 | static void |
| 716 | android_media_MediaPlayer_setAuxEffectSendLevel(JNIEnv *env, jobject thiz, jfloat level) |
| 717 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 718 | ALOGV("setAuxEffectSendLevel: level %f", level); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 719 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 720 | if (mp == NULL ) { |
| 721 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 722 | return; |
| 723 | } |
| 724 | process_media_player_call( env, thiz, mp->setAuxEffectSendLevel(level), NULL, NULL ); |
| 725 | } |
| 726 | |
| 727 | static void android_media_MediaPlayer_attachAuxEffect(JNIEnv *env, jobject thiz, jint effectId) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 728 | ALOGV("attachAuxEffect(): %d", effectId); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 729 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 730 | if (mp == NULL ) { |
| 731 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 732 | return; |
| 733 | } |
| 734 | process_media_player_call( env, thiz, mp->attachAuxEffect(effectId), NULL, NULL ); |
| 735 | } |
| 736 | |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 737 | static jint |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 738 | android_media_MediaPlayer_pullBatteryData( |
| 739 | JNIEnv *env, jobject /* thiz */, jobject java_reply) |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 740 | { |
| 741 | sp<IBinder> binder = defaultServiceManager()->getService(String16("media.player")); |
| 742 | sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder); |
| 743 | if (service.get() == NULL) { |
| 744 | jniThrowException(env, "java/lang/RuntimeException", "cannot get MediaPlayerService"); |
| 745 | return UNKNOWN_ERROR; |
| 746 | } |
| 747 | |
| 748 | Parcel *reply = parcelForJavaObject(env, java_reply); |
| 749 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 750 | return (jint) service->pullBatteryData(reply); |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 751 | } |
| 752 | |
John Grossman | 720aa28 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 753 | static jint |
| 754 | android_media_MediaPlayer_setRetransmitEndpoint(JNIEnv *env, jobject thiz, |
| 755 | jstring addrString, jint port) { |
| 756 | sp<MediaPlayer> mp = getMediaPlayer(env, thiz); |
| 757 | if (mp == NULL ) { |
| 758 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 759 | return INVALID_OPERATION; |
| 760 | } |
| 761 | |
| 762 | const char *cAddrString = NULL; |
| 763 | |
| 764 | if (NULL != addrString) { |
| 765 | cAddrString = env->GetStringUTFChars(addrString, NULL); |
| 766 | if (cAddrString == NULL) { // Out of memory |
| 767 | return NO_MEMORY; |
| 768 | } |
| 769 | } |
| 770 | ALOGV("setRetransmitEndpoint: %s:%d", |
| 771 | cAddrString ? cAddrString : "(null)", port); |
| 772 | |
| 773 | status_t ret; |
| 774 | if (cAddrString && (port > 0xFFFF)) { |
| 775 | ret = BAD_VALUE; |
| 776 | } else { |
| 777 | ret = mp->setRetransmitEndpoint(cAddrString, |
| 778 | static_cast<uint16_t>(port)); |
| 779 | } |
| 780 | |
| 781 | if (NULL != addrString) { |
| 782 | env->ReleaseStringUTFChars(addrString, cAddrString); |
| 783 | } |
| 784 | |
| 785 | if (ret == INVALID_OPERATION ) { |
| 786 | jniThrowException(env, "java/lang/IllegalStateException", NULL); |
| 787 | } |
| 788 | |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 789 | return (jint) ret; |
John Grossman | 720aa28 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 790 | } |
| 791 | |
Marco Nelissen | 84b8320 | 2012-02-28 16:07:44 -0800 | [diff] [blame] | 792 | static void |
| 793 | android_media_MediaPlayer_setNextMediaPlayer(JNIEnv *env, jobject thiz, jobject java_player) |
| 794 | { |
| 795 | ALOGV("setNextMediaPlayer"); |
| 796 | sp<MediaPlayer> thisplayer = getMediaPlayer(env, thiz); |
| 797 | if (thisplayer == NULL) { |
| 798 | jniThrowException(env, "java/lang/IllegalStateException", "This player not initialized"); |
| 799 | return; |
| 800 | } |
| 801 | sp<MediaPlayer> nextplayer = (java_player == NULL) ? NULL : getMediaPlayer(env, java_player); |
| 802 | if (nextplayer == NULL && java_player != NULL) { |
| 803 | jniThrowException(env, "java/lang/IllegalStateException", "That player not initialized"); |
| 804 | return; |
| 805 | } |
| 806 | |
| 807 | if (nextplayer == thisplayer) { |
| 808 | jniThrowException(env, "java/lang/IllegalArgumentException", "Next player can't be self"); |
| 809 | return; |
| 810 | } |
| 811 | // tie the two players together |
| 812 | process_media_player_call( |
| 813 | env, thiz, thisplayer->setNextMediaPlayer(nextplayer), |
| 814 | "java/lang/IllegalArgumentException", |
| 815 | "setNextMediaPlayer failed." ); |
| 816 | ; |
| 817 | } |
| 818 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | // ---------------------------------------------------------------------------- |
| 820 | |
| 821 | static JNINativeMethod gMethods[] = { |
James Dong | 17524dc | 2011-05-04 13:41:58 -0700 | [diff] [blame] | 822 | { |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 823 | "nativeSetDataSource", |
| 824 | "(Landroid/os/IBinder;Ljava/lang/String;[Ljava/lang/String;" |
| 825 | "[Ljava/lang/String;)V", |
James Dong | 17524dc | 2011-05-04 13:41:58 -0700 | [diff] [blame] | 826 | (void *)android_media_MediaPlayer_setDataSourceAndHeaders |
| 827 | }, |
| 828 | |
Andreas Huber | d5f9fa5 | 2013-05-28 14:39:39 -0700 | [diff] [blame] | 829 | {"_setDataSource", "(Ljava/io/FileDescriptor;JJ)V", (void *)android_media_MediaPlayer_setDataSourceFD}, |
Ted Bonkenburg | 1ee6011 | 2011-07-26 09:51:18 -0700 | [diff] [blame] | 830 | {"_setVideoSurface", "(Landroid/view/Surface;)V", (void *)android_media_MediaPlayer_setVideoSurface}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | {"prepare", "()V", (void *)android_media_MediaPlayer_prepare}, |
| 832 | {"prepareAsync", "()V", (void *)android_media_MediaPlayer_prepareAsync}, |
| 833 | {"_start", "()V", (void *)android_media_MediaPlayer_start}, |
| 834 | {"_stop", "()V", (void *)android_media_MediaPlayer_stop}, |
| 835 | {"getVideoWidth", "()I", (void *)android_media_MediaPlayer_getVideoWidth}, |
| 836 | {"getVideoHeight", "()I", (void *)android_media_MediaPlayer_getVideoHeight}, |
| 837 | {"seekTo", "(I)V", (void *)android_media_MediaPlayer_seekTo}, |
| 838 | {"_pause", "()V", (void *)android_media_MediaPlayer_pause}, |
| 839 | {"isPlaying", "()Z", (void *)android_media_MediaPlayer_isPlaying}, |
| 840 | {"getCurrentPosition", "()I", (void *)android_media_MediaPlayer_getCurrentPosition}, |
| 841 | {"getDuration", "()I", (void *)android_media_MediaPlayer_getDuration}, |
| 842 | {"_release", "()V", (void *)android_media_MediaPlayer_release}, |
| 843 | {"_reset", "()V", (void *)android_media_MediaPlayer_reset}, |
| 844 | {"setAudioStreamType", "(I)V", (void *)android_media_MediaPlayer_setAudioStreamType}, |
| 845 | {"setLooping", "(Z)V", (void *)android_media_MediaPlayer_setLooping}, |
| 846 | {"isLooping", "()Z", (void *)android_media_MediaPlayer_isLooping}, |
| 847 | {"setVolume", "(FF)V", (void *)android_media_MediaPlayer_setVolume}, |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 848 | {"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] | 849 | {"native_setMetadataFilter", "(Landroid/os/Parcel;)I", (void *)android_media_MediaPlayer_setMetadataFilter}, |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 850 | {"native_getMetadata", "(ZZLandroid/os/Parcel;)Z", (void *)android_media_MediaPlayer_getMetadata}, |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 851 | {"native_init", "()V", (void *)android_media_MediaPlayer_native_init}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | {"native_setup", "(Ljava/lang/Object;)V", (void *)android_media_MediaPlayer_native_setup}, |
| 853 | {"native_finalize", "()V", (void *)android_media_MediaPlayer_native_finalize}, |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 854 | {"getAudioSessionId", "()I", (void *)android_media_MediaPlayer_get_audio_session_id}, |
| 855 | {"setAudioSessionId", "(I)V", (void *)android_media_MediaPlayer_set_audio_session_id}, |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 856 | {"setAuxEffectSendLevel", "(F)V", (void *)android_media_MediaPlayer_setAuxEffectSendLevel}, |
| 857 | {"attachAuxEffect", "(I)V", (void *)android_media_MediaPlayer_attachAuxEffect}, |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 858 | {"native_pullBatteryData", "(Landroid/os/Parcel;)I", (void *)android_media_MediaPlayer_pullBatteryData}, |
John Grossman | 720aa28 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 859 | {"native_setRetransmitEndpoint", "(Ljava/lang/String;I)I", (void *)android_media_MediaPlayer_setRetransmitEndpoint}, |
Marco Nelissen | 84b8320 | 2012-02-28 16:07:44 -0800 | [diff] [blame] | 860 | {"setNextMediaPlayer", "(Landroid/media/MediaPlayer;)V", (void *)android_media_MediaPlayer_setNextMediaPlayer}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | }; |
| 862 | |
| 863 | static const char* const kClassPathName = "android/media/MediaPlayer"; |
| 864 | |
Marco Nelissen | 4935d05 | 2009-08-03 11:12:58 -0700 | [diff] [blame] | 865 | // This function only registers the native methods |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | static int register_android_media_MediaPlayer(JNIEnv *env) |
| 867 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | return AndroidRuntime::registerNativeMethods(env, |
| 869 | "android/media/MediaPlayer", gMethods, NELEM(gMethods)); |
| 870 | } |
| 871 | |
Zhijun He | 212e78d | 2013-06-07 11:36:23 -0700 | [diff] [blame] | 872 | extern int register_android_media_ImageReader(JNIEnv *env); |
Andreas Huber | 8240d92 | 2012-04-04 14:06:32 -0700 | [diff] [blame] | 873 | extern int register_android_media_Crypto(JNIEnv *env); |
Jeff Tinker | 8a0c80f | 2013-02-08 10:20:44 -0800 | [diff] [blame] | 874 | extern int register_android_media_Drm(JNIEnv *env); |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 875 | extern int register_android_media_MediaCodec(JNIEnv *env); |
| 876 | extern int register_android_media_MediaExtractor(JNIEnv *env); |
Andreas Huber | 5a04bf3 | 2012-03-29 16:41:38 -0700 | [diff] [blame] | 877 | extern int register_android_media_MediaCodecList(JNIEnv *env); |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 878 | extern int register_android_media_MediaHTTPConnection(JNIEnv *env); |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 879 | extern int register_android_media_MediaMetadataRetriever(JNIEnv *env); |
ztenghui | 68ccf10 | 2013-02-13 14:07:02 -0800 | [diff] [blame] | 880 | extern int register_android_media_MediaMuxer(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 881 | extern int register_android_media_MediaRecorder(JNIEnv *env); |
| 882 | extern int register_android_media_MediaScanner(JNIEnv *env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | extern int register_android_media_ResampleInputStream(JNIEnv *env); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 884 | extern int register_android_media_MediaProfiles(JNIEnv *env); |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 885 | extern int register_android_media_AmrInputStream(JNIEnv *env); |
Mike Lockwood | 0cd0136 | 2010-12-30 11:54:33 -0500 | [diff] [blame] | 886 | extern int register_android_mtp_MtpDatabase(JNIEnv *env); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 887 | extern int register_android_mtp_MtpDevice(JNIEnv *env); |
Mike Lockwood | 0cd0136 | 2010-12-30 11:54:33 -0500 | [diff] [blame] | 888 | extern int register_android_mtp_MtpServer(JNIEnv *env); |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 889 | |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 890 | jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 891 | { |
| 892 | JNIEnv* env = NULL; |
| 893 | jint result = -1; |
| 894 | |
| 895 | if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 896 | ALOGE("ERROR: GetEnv failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | goto bail; |
| 898 | } |
| 899 | assert(env != NULL); |
| 900 | |
Zhijun He | 212e78d | 2013-06-07 11:36:23 -0700 | [diff] [blame] | 901 | if (register_android_media_ImageReader(env) < 0) { |
| 902 | ALOGE("ERROR: ImageReader native registration failed"); |
| 903 | goto bail; |
| 904 | } |
| 905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | if (register_android_media_MediaPlayer(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 907 | ALOGE("ERROR: MediaPlayer native registration failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 908 | goto bail; |
| 909 | } |
| 910 | |
| 911 | if (register_android_media_MediaRecorder(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 912 | ALOGE("ERROR: MediaRecorder native registration failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | goto bail; |
| 914 | } |
| 915 | |
| 916 | if (register_android_media_MediaScanner(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 917 | ALOGE("ERROR: MediaScanner native registration failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | goto bail; |
| 919 | } |
| 920 | |
| 921 | if (register_android_media_MediaMetadataRetriever(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 922 | ALOGE("ERROR: MediaMetadataRetriever native registration failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | goto bail; |
| 924 | } |
| 925 | |
| 926 | if (register_android_media_AmrInputStream(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 927 | ALOGE("ERROR: AmrInputStream native registration failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | goto bail; |
| 929 | } |
| 930 | |
| 931 | if (register_android_media_ResampleInputStream(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 932 | ALOGE("ERROR: ResampleInputStream native registration failed\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | goto bail; |
| 934 | } |
| 935 | |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 936 | if (register_android_media_MediaProfiles(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 937 | ALOGE("ERROR: MediaProfiles native registration failed"); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 938 | goto bail; |
| 939 | } |
| 940 | |
Mike Lockwood | 0cd0136 | 2010-12-30 11:54:33 -0500 | [diff] [blame] | 941 | if (register_android_mtp_MtpDatabase(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 942 | ALOGE("ERROR: MtpDatabase native registration failed"); |
Mike Lockwood | d21eac9 | 2010-07-03 00:44:05 -0400 | [diff] [blame] | 943 | goto bail; |
| 944 | } |
| 945 | |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 946 | if (register_android_mtp_MtpDevice(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 947 | ALOGE("ERROR: MtpDevice native registration failed"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 948 | goto bail; |
| 949 | } |
| 950 | |
Mike Lockwood | 0cd0136 | 2010-12-30 11:54:33 -0500 | [diff] [blame] | 951 | if (register_android_mtp_MtpServer(env) < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 952 | ALOGE("ERROR: MtpServer native registration failed"); |
Mike Lockwood | 81ea83d | 2010-06-30 17:49:41 -0400 | [diff] [blame] | 953 | goto bail; |
| 954 | } |
| 955 | |
Andreas Huber | 88572f7 | 2012-02-21 11:47:18 -0800 | [diff] [blame] | 956 | if (register_android_media_MediaCodec(env) < 0) { |
| 957 | ALOGE("ERROR: MediaCodec native registration failed"); |
| 958 | goto bail; |
| 959 | } |
| 960 | |
| 961 | if (register_android_media_MediaExtractor(env) < 0) { |
| 962 | ALOGE("ERROR: MediaCodec native registration failed"); |
| 963 | goto bail; |
| 964 | } |
| 965 | |
ztenghui | 68ccf10 | 2013-02-13 14:07:02 -0800 | [diff] [blame] | 966 | if (register_android_media_MediaMuxer(env) < 0) { |
| 967 | ALOGE("ERROR: MediaMuxer native registration failed"); |
| 968 | goto bail; |
| 969 | } |
| 970 | |
Andreas Huber | 5a04bf3 | 2012-03-29 16:41:38 -0700 | [diff] [blame] | 971 | if (register_android_media_MediaCodecList(env) < 0) { |
| 972 | ALOGE("ERROR: MediaCodec native registration failed"); |
| 973 | goto bail; |
| 974 | } |
| 975 | |
Andreas Huber | 8240d92 | 2012-04-04 14:06:32 -0700 | [diff] [blame] | 976 | if (register_android_media_Crypto(env) < 0) { |
| 977 | ALOGE("ERROR: MediaCodec native registration failed"); |
| 978 | goto bail; |
| 979 | } |
| 980 | |
Jeff Tinker | 8a0c80f | 2013-02-08 10:20:44 -0800 | [diff] [blame] | 981 | if (register_android_media_Drm(env) < 0) { |
| 982 | ALOGE("ERROR: MediaDrm native registration failed"); |
| 983 | goto bail; |
| 984 | } |
| 985 | |
Andreas Huber | d2506a5 | 2014-01-29 10:32:46 -0800 | [diff] [blame] | 986 | if (register_android_media_MediaHTTPConnection(env) < 0) { |
| 987 | ALOGE("ERROR: MediaHTTPConnection native registration failed"); |
| 988 | goto bail; |
| 989 | } |
| 990 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | /* success -- return valid version number */ |
| 992 | result = JNI_VERSION_1_4; |
| 993 | |
| 994 | bail: |
| 995 | return result; |
| 996 | } |
| 997 | |
| 998 | // KTHXBYE |