blob: fbe53402c67342a20ca0c47e3006ef345a8becc2 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2**
3** Copyright 2008, 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 "MediaMetadataRetrieverJNI"
20
21#include <assert.h>
22#include <utils/Log.h>
23#include <utils/threads.h>
Derek Sollenbergereece0dd2014-02-27 14:31:29 -050024#include <SkBitmap.h>
Andreas Huberd2506a52014-01-29 10:32:46 -080025#include <media/IMediaHTTPService.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026#include <media/mediametadataretriever.h>
Elliott Hughes95d3f862014-06-10 16:53:31 -070027#include <media/mediascanner.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028#include <private/media/VideoFrame.h>
29
30#include "jni.h"
31#include "JNIHelp.h"
32#include "android_runtime/AndroidRuntime.h"
James Dong79f407c2011-05-05 12:50:04 -070033#include "android_media_Utils.h"
Andreas Huberd2506a52014-01-29 10:32:46 -080034#include "android_util_Binder.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
36
37using namespace android;
38
39struct fields_t {
40 jfieldID context;
James Dongc371a022011-04-06 12:16:07 -070041 jclass bitmapClazz; // Must be a global ref
James Dong0e4b5352010-12-19 13:05:33 -080042 jfieldID nativeBitmap;
James Dong53ebc722010-11-08 16:04:27 -080043 jmethodID createBitmapMethod;
James Dong9f2cde32011-03-18 17:55:06 -070044 jmethodID createScaledBitmapMethod;
James Dongc371a022011-04-06 12:16:07 -070045 jclass configClazz; // Must be a global ref
James Dong0e4b5352010-12-19 13:05:33 -080046 jmethodID createConfigMethod;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047};
48
49static fields_t fields;
50static Mutex sLock;
Marco Nelissen4935d052009-08-03 11:12:58 -070051static const char* const kClassPathName = "android/media/MediaMetadataRetriever";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
53static void process_media_retriever_call(JNIEnv *env, status_t opStatus, const char* exception, const char *message)
54{
55 if (opStatus == (status_t) INVALID_OPERATION) {
56 jniThrowException(env, "java/lang/IllegalStateException", NULL);
57 } else if (opStatus != (status_t) OK) {
58 if (strlen(message) > 230) {
59 // If the message is too long, don't bother displaying the status code.
60 jniThrowException( env, exception, message);
61 } else {
62 char msg[256];
63 // Append the status code to the message.
64 sprintf(msg, "%s: status = 0x%X", message, opStatus);
65 jniThrowException( env, exception, msg);
66 }
67 }
68}
69
70static MediaMetadataRetriever* getRetriever(JNIEnv* env, jobject thiz)
71{
72 // No lock is needed, since it is called internally by other methods that are protected
Ashok Bhat075e9a12014-01-06 13:45:09 +000073 MediaMetadataRetriever* retriever = (MediaMetadataRetriever*) env->GetLongField(thiz, fields.context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 return retriever;
75}
76
Ashok Bhat075e9a12014-01-06 13:45:09 +000077static void setRetriever(JNIEnv* env, jobject thiz, MediaMetadataRetriever* retriever)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078{
79 // No lock is needed, since it is called internally by other methods that are protected
Ashok Bhat075e9a12014-01-06 13:45:09 +000080 MediaMetadataRetriever *old = (MediaMetadataRetriever*) env->GetLongField(thiz, fields.context);
81 env->SetLongField(thiz, fields.context, (jlong) retriever);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082}
83
Andreas Huber5b7ced62011-03-21 10:25:44 -070084static void
85android_media_MediaMetadataRetriever_setDataSourceAndHeaders(
Andreas Huberd2506a52014-01-29 10:32:46 -080086 JNIEnv *env, jobject thiz, jobject httpServiceBinderObj, jstring path,
James Dong17524dc2011-05-04 13:41:58 -070087 jobjectArray keys, jobjectArray values) {
88
Steve Block71f2cf12011-10-20 11:56:00 +010089 ALOGV("setDataSource");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 MediaMetadataRetriever* retriever = getRetriever(env, thiz);
91 if (retriever == 0) {
Andreas Huber5b7ced62011-03-21 10:25:44 -070092 jniThrowException(
93 env,
94 "java/lang/IllegalStateException", "No retriever available");
95
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 return;
97 }
98
Andreas Huber5b7ced62011-03-21 10:25:44 -070099 if (!path) {
100 jniThrowException(
101 env, "java/lang/IllegalArgumentException", "Null pointer");
102
103 return;
104 }
105
106 const char *tmp = env->GetStringUTFChars(path, NULL);
Andreas Huber5bb357f2011-03-21 11:55:01 -0700107 if (!tmp) { // OutOfMemoryError exception already thrown
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 return;
109 }
110
Andreas Huber5bb357f2011-03-21 11:55:01 -0700111 String8 pathStr(tmp);
Andreas Huber5b7ced62011-03-21 10:25:44 -0700112 env->ReleaseStringUTFChars(path, tmp);
113 tmp = NULL;
114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 // Don't let somebody trick us in to reading some random block of memory
Andreas Huber5b7ced62011-03-21 10:25:44 -0700116 if (strncmp("mem://", pathStr.string(), 6) == 0) {
117 jniThrowException(
118 env, "java/lang/IllegalArgumentException", "Invalid pathname");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 return;
120 }
121
Andreas Huber5b7ced62011-03-21 10:25:44 -0700122 // We build a similar KeyedVector out of it.
123 KeyedVector<String8, String8> headersVector;
James Dong79f407c2011-05-05 12:50:04 -0700124 if (!ConvertKeyValueArraysToKeyedVector(
125 env, keys, values, &headersVector)) {
126 return;
Andreas Huber5b7ced62011-03-21 10:25:44 -0700127 }
Andreas Huberd2506a52014-01-29 10:32:46 -0800128
129 sp<IMediaHTTPService> httpService;
130 if (httpServiceBinderObj != NULL) {
131 sp<IBinder> binder = ibinderForJavaObject(env, httpServiceBinderObj);
132 httpService = interface_cast<IMediaHTTPService>(binder);
133 }
134
Andreas Huber5b7ced62011-03-21 10:25:44 -0700135 process_media_retriever_call(
136 env,
137 retriever->setDataSource(
Andreas Huberd2506a52014-01-29 10:32:46 -0800138 httpService,
139 pathStr.string(),
140 headersVector.size() > 0 ? &headersVector : NULL),
Andreas Huber5b7ced62011-03-21 10:25:44 -0700141
142 "java/lang/RuntimeException",
143 "setDataSource failed");
144}
145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146static void android_media_MediaMetadataRetriever_setDataSourceFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length)
147{
Steve Block71f2cf12011-10-20 11:56:00 +0100148 ALOGV("setDataSource");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 MediaMetadataRetriever* retriever = getRetriever(env, thiz);
150 if (retriever == 0) {
151 jniThrowException(env, "java/lang/IllegalStateException", "No retriever available");
152 return;
153 }
154 if (!fileDescriptor) {
155 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
156 return;
157 }
Elliott Hughesa3804cf2011-04-11 16:50:19 -0700158 int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 if (offset < 0 || length < 0 || fd < 0) {
160 if (offset < 0) {
Ashok Bhat075e9a12014-01-06 13:45:09 +0000161 ALOGE("negative offset (%lld)", (long long)offset);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 }
163 if (length < 0) {
Ashok Bhat075e9a12014-01-06 13:45:09 +0000164 ALOGE("negative length (%lld)", (long long)length);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 }
166 if (fd < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000167 ALOGE("invalid file descriptor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 }
169 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
170 return;
171 }
172 process_media_retriever_call(env, retriever->setDataSource(fd, offset, length), "java/lang/RuntimeException", "setDataSource failed");
173}
174
Carl Shapiroae12a502011-01-20 23:13:09 -0800175template<typename T>
176static void rotate0(T* dst, const T* src, size_t width, size_t height)
177{
178 memcpy(dst, src, width * height * sizeof(T));
179}
180
181template<typename T>
182static void rotate90(T* dst, const T* src, size_t width, size_t height)
183{
184 for (size_t i = 0; i < height; ++i) {
185 for (size_t j = 0; j < width; ++j) {
186 dst[j * height + height - 1 - i] = src[i * width + j];
187 }
188 }
189}
190
191template<typename T>
192static void rotate180(T* dst, const T* src, size_t width, size_t height)
193{
194 for (size_t i = 0; i < height; ++i) {
195 for (size_t j = 0; j < width; ++j) {
196 dst[(height - 1 - i) * width + width - 1 - j] = src[i * width + j];
197 }
198 }
199}
200
201template<typename T>
202static void rotate270(T* dst, const T* src, size_t width, size_t height)
203{
204 for (size_t i = 0; i < height; ++i) {
205 for (size_t j = 0; j < width; ++j) {
206 dst[(width - 1 - j) * height + i] = src[i * width + j];
207 }
208 }
209}
210
211template<typename T>
212static void rotate(T *dst, const T *src, size_t width, size_t height, int angle)
213{
214 switch (angle) {
215 case 0:
216 rotate0(dst, src, width, height);
217 break;
218 case 90:
219 rotate90(dst, src, width, height);
220 break;
221 case 180:
222 rotate180(dst, src, width, height);
223 break;
224 case 270:
225 rotate270(dst, src, width, height);
226 break;
227 }
228}
229
James Dongfaf09ba2010-12-02 17:42:08 -0800230static jobject android_media_MediaMetadataRetriever_getFrameAtTime(JNIEnv *env, jobject thiz, jlong timeUs, jint option)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231{
Steve Block71f2cf12011-10-20 11:56:00 +0100232 ALOGV("getFrameAtTime: %lld us option: %d", timeUs, option);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 MediaMetadataRetriever* retriever = getRetriever(env, thiz);
234 if (retriever == 0) {
235 jniThrowException(env, "java/lang/IllegalStateException", "No retriever available");
236 return NULL;
237 }
238
239 // Call native method to retrieve a video frame
240 VideoFrame *videoFrame = NULL;
James Dongfaf09ba2010-12-02 17:42:08 -0800241 sp<IMemory> frameMemory = retriever->getFrameAtTime(timeUs, option);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 if (frameMemory != 0) { // cast the shared structure to a VideoFrame object
243 videoFrame = static_cast<VideoFrame *>(frameMemory->pointer());
244 }
245 if (videoFrame == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000246 ALOGE("getFrameAtTime: videoFrame is a NULL pointer");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 return NULL;
248 }
249
Steve Block71f2cf12011-10-20 11:56:00 +0100250 ALOGV("Dimension = %dx%d and bytes = %d",
James Dong0e4b5352010-12-19 13:05:33 -0800251 videoFrame->mDisplayWidth,
252 videoFrame->mDisplayHeight,
253 videoFrame->mSize);
254
James Dong0e4b5352010-12-19 13:05:33 -0800255 jobject config = env->CallStaticObjectMethod(
256 fields.configClazz,
257 fields.createConfigMethod,
258 SkBitmap::kRGB_565_Config);
259
Ashok Bhat58fad0b2014-03-04 21:13:52 +0000260 uint32_t width, height;
James Dong9f2cde32011-03-18 17:55:06 -0700261 bool swapWidthAndHeight = false;
Carl Shapiroae12a502011-01-20 23:13:09 -0800262 if (videoFrame->mRotationAngle == 90 || videoFrame->mRotationAngle == 270) {
James Dong9f2cde32011-03-18 17:55:06 -0700263 width = videoFrame->mHeight;
264 height = videoFrame->mWidth;
265 swapWidthAndHeight = true;
Carl Shapiroae12a502011-01-20 23:13:09 -0800266 } else {
James Dong9f2cde32011-03-18 17:55:06 -0700267 width = videoFrame->mWidth;
268 height = videoFrame->mHeight;
Carl Shapiroae12a502011-01-20 23:13:09 -0800269 }
270
James Dong0e4b5352010-12-19 13:05:33 -0800271 jobject jBitmap = env->CallStaticObjectMethod(
272 fields.bitmapClazz,
273 fields.createBitmapMethod,
Carl Shapiroae12a502011-01-20 23:13:09 -0800274 width,
275 height,
James Dong0e4b5352010-12-19 13:05:33 -0800276 config);
wang, biaoc847a482012-10-30 15:35:01 +0800277 if (jBitmap == NULL) {
278 if (env->ExceptionCheck()) {
279 env->ExceptionClear();
280 }
281 ALOGE("getFrameAtTime: create Bitmap failed!");
282 return NULL;
283 }
Carl Shapiroae12a502011-01-20 23:13:09 -0800284
James Dong0e4b5352010-12-19 13:05:33 -0800285 SkBitmap *bitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000286 (SkBitmap *) env->GetLongField(jBitmap, fields.nativeBitmap);
James Dong0e4b5352010-12-19 13:05:33 -0800287
288 bitmap->lockPixels();
Carl Shapiroae12a502011-01-20 23:13:09 -0800289 rotate((uint16_t*)bitmap->getPixels(),
290 (uint16_t*)((char*)videoFrame + sizeof(VideoFrame)),
James Dong9f2cde32011-03-18 17:55:06 -0700291 videoFrame->mWidth,
292 videoFrame->mHeight,
Carl Shapiroae12a502011-01-20 23:13:09 -0800293 videoFrame->mRotationAngle);
James Dong0e4b5352010-12-19 13:05:33 -0800294 bitmap->unlockPixels();
295
James Dong9f2cde32011-03-18 17:55:06 -0700296 if (videoFrame->mDisplayWidth != videoFrame->mWidth ||
297 videoFrame->mDisplayHeight != videoFrame->mHeight) {
Ashok Bhat58fad0b2014-03-04 21:13:52 +0000298 uint32_t displayWidth = videoFrame->mDisplayWidth;
299 uint32_t displayHeight = videoFrame->mDisplayHeight;
James Dong9f2cde32011-03-18 17:55:06 -0700300 if (swapWidthAndHeight) {
301 displayWidth = videoFrame->mDisplayHeight;
302 displayHeight = videoFrame->mDisplayWidth;
303 }
Steve Block71f2cf12011-10-20 11:56:00 +0100304 ALOGV("Bitmap dimension is scaled from %dx%d to %dx%d",
James Dong9f2cde32011-03-18 17:55:06 -0700305 width, height, displayWidth, displayHeight);
306 jobject scaledBitmap = env->CallStaticObjectMethod(fields.bitmapClazz,
307 fields.createScaledBitmapMethod,
308 jBitmap,
309 displayWidth,
310 displayHeight,
311 true);
312 return scaledBitmap;
313 }
314
James Dong0e4b5352010-12-19 13:05:33 -0800315 return jBitmap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316}
317
James Dongdf9b3492011-01-04 15:03:48 -0800318static jbyteArray android_media_MediaMetadataRetriever_getEmbeddedPicture(
319 JNIEnv *env, jobject thiz, jint pictureType)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320{
Steve Block71f2cf12011-10-20 11:56:00 +0100321 ALOGV("getEmbeddedPicture: %d", pictureType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 MediaMetadataRetriever* retriever = getRetriever(env, thiz);
323 if (retriever == 0) {
324 jniThrowException(env, "java/lang/IllegalStateException", "No retriever available");
325 return NULL;
326 }
327 MediaAlbumArt* mediaAlbumArt = NULL;
James Dongdf9b3492011-01-04 15:03:48 -0800328
329 // FIXME:
330 // Use pictureType to retrieve the intended embedded picture and also change
331 // the method name to getEmbeddedPicture().
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 sp<IMemory> albumArtMemory = retriever->extractAlbumArt();
333 if (albumArtMemory != 0) { // cast the shared structure to a MediaAlbumArt object
334 mediaAlbumArt = static_cast<MediaAlbumArt *>(albumArtMemory->pointer());
335 }
336 if (mediaAlbumArt == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000337 ALOGE("getEmbeddedPicture: Call to getEmbeddedPicture failed.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 return NULL;
339 }
340
Elliott Hughes95d3f862014-06-10 16:53:31 -0700341 jbyteArray array = env->NewByteArray(mediaAlbumArt->size());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 if (!array) { // OutOfMemoryError exception has already been thrown.
Steve Block3762c312012-01-06 19:20:56 +0000343 ALOGE("getEmbeddedPicture: OutOfMemoryError is thrown.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 } else {
Elliott Hughes95d3f862014-06-10 16:53:31 -0700345 const jbyte* data =
346 reinterpret_cast<const jbyte*>(mediaAlbumArt->data());
347 env->SetByteArrayRegion(array, 0, mediaAlbumArt->size(), data);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 }
349
350 // No need to delete mediaAlbumArt here
351 return array;
352}
353
354static jobject android_media_MediaMetadataRetriever_extractMetadata(JNIEnv *env, jobject thiz, jint keyCode)
355{
Steve Block71f2cf12011-10-20 11:56:00 +0100356 ALOGV("extractMetadata");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 MediaMetadataRetriever* retriever = getRetriever(env, thiz);
358 if (retriever == 0) {
359 jniThrowException(env, "java/lang/IllegalStateException", "No retriever available");
360 return NULL;
361 }
362 const char* value = retriever->extractMetadata(keyCode);
363 if (!value) {
Steve Block71f2cf12011-10-20 11:56:00 +0100364 ALOGV("extractMetadata: Metadata is not found");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 return NULL;
366 }
Steve Block71f2cf12011-10-20 11:56:00 +0100367 ALOGV("extractMetadata: value (%s) for keyCode(%d)", value, keyCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 return env->NewStringUTF(value);
369}
370
371static void android_media_MediaMetadataRetriever_release(JNIEnv *env, jobject thiz)
372{
Steve Block71f2cf12011-10-20 11:56:00 +0100373 ALOGV("release");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 Mutex::Autolock lock(sLock);
375 MediaMetadataRetriever* retriever = getRetriever(env, thiz);
376 delete retriever;
Ashok Bhat075e9a12014-01-06 13:45:09 +0000377 setRetriever(env, thiz, (MediaMetadataRetriever*) 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378}
379
380static void android_media_MediaMetadataRetriever_native_finalize(JNIEnv *env, jobject thiz)
381{
Steve Block71f2cf12011-10-20 11:56:00 +0100382 ALOGV("native_finalize");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 // No lock is needed, since android_media_MediaMetadataRetriever_release() is protected
384 android_media_MediaMetadataRetriever_release(env, thiz);
385}
386
Marco Nelissen4935d052009-08-03 11:12:58 -0700387// This function gets a field ID, which in turn causes class initialization.
388// It is called from a static block in MediaMetadataRetriever, which won't run until the
389// first time an instance of this class is used.
390static void android_media_MediaMetadataRetriever_native_init(JNIEnv *env)
391{
392 jclass clazz = env->FindClass(kClassPathName);
393 if (clazz == NULL) {
Marco Nelissen4935d052009-08-03 11:12:58 -0700394 return;
395 }
396
Ashok Bhat075e9a12014-01-06 13:45:09 +0000397 fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
Marco Nelissen4935d052009-08-03 11:12:58 -0700398 if (fields.context == NULL) {
Marco Nelissen4935d052009-08-03 11:12:58 -0700399 return;
400 }
401
Brian Carlstrom46e18c112011-04-05 22:44:45 -0700402 jclass bitmapClazz = env->FindClass("android/graphics/Bitmap");
403 if (bitmapClazz == NULL) {
404 return;
405 }
406 fields.bitmapClazz = (jclass) env->NewGlobalRef(bitmapClazz);
Marco Nelissen4935d052009-08-03 11:12:58 -0700407 if (fields.bitmapClazz == NULL) {
Marco Nelissen4935d052009-08-03 11:12:58 -0700408 return;
409 }
James Dong0e4b5352010-12-19 13:05:33 -0800410 fields.createBitmapMethod =
411 env->GetStaticMethodID(fields.bitmapClazz, "createBitmap",
412 "(IILandroid/graphics/Bitmap$Config;)"
413 "Landroid/graphics/Bitmap;");
414 if (fields.createBitmapMethod == NULL) {
James Dong0e4b5352010-12-19 13:05:33 -0800415 return;
416 }
James Dong9f2cde32011-03-18 17:55:06 -0700417 fields.createScaledBitmapMethod =
418 env->GetStaticMethodID(fields.bitmapClazz, "createScaledBitmap",
419 "(Landroid/graphics/Bitmap;IIZ)"
420 "Landroid/graphics/Bitmap;");
421 if (fields.createScaledBitmapMethod == NULL) {
James Dong9f2cde32011-03-18 17:55:06 -0700422 return;
423 }
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000424 fields.nativeBitmap = env->GetFieldID(fields.bitmapClazz, "mNativeBitmap", "J");
James Dong0e4b5352010-12-19 13:05:33 -0800425 if (fields.nativeBitmap == NULL) {
Brian Carlstrom46e18c112011-04-05 22:44:45 -0700426 return;
James Dong0e4b5352010-12-19 13:05:33 -0800427 }
428
Brian Carlstrom46e18c112011-04-05 22:44:45 -0700429 jclass configClazz = env->FindClass("android/graphics/Bitmap$Config");
430 if (configClazz == NULL) {
431 return;
432 }
433 fields.configClazz = (jclass) env->NewGlobalRef(configClazz);
James Dong0e4b5352010-12-19 13:05:33 -0800434 if (fields.configClazz == NULL) {
James Dong0e4b5352010-12-19 13:05:33 -0800435 return;
436 }
437 fields.createConfigMethod =
438 env->GetStaticMethodID(fields.configClazz, "nativeToConfig",
439 "(I)Landroid/graphics/Bitmap$Config;");
440 if (fields.createConfigMethod == NULL) {
James Dong0e4b5352010-12-19 13:05:33 -0800441 return;
442 }
Marco Nelissen4935d052009-08-03 11:12:58 -0700443}
444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445static void android_media_MediaMetadataRetriever_native_setup(JNIEnv *env, jobject thiz)
446{
Steve Block71f2cf12011-10-20 11:56:00 +0100447 ALOGV("native_setup");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 MediaMetadataRetriever* retriever = new MediaMetadataRetriever();
449 if (retriever == 0) {
450 jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
451 return;
452 }
Ashok Bhat075e9a12014-01-06 13:45:09 +0000453 setRetriever(env, thiz, retriever);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454}
455
456// JNI mapping between Java methods and native methods
457static JNINativeMethod nativeMethods[] = {
James Dong17524dc2011-05-04 13:41:58 -0700458 {
459 "_setDataSource",
Andreas Huberd2506a52014-01-29 10:32:46 -0800460 "(Landroid/os/IBinder;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)V",
James Dong17524dc2011-05-04 13:41:58 -0700461 (void *)android_media_MediaMetadataRetriever_setDataSourceAndHeaders
462 },
463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 {"setDataSource", "(Ljava/io/FileDescriptor;JJ)V", (void *)android_media_MediaMetadataRetriever_setDataSourceFD},
James Dongfaf09ba2010-12-02 17:42:08 -0800465 {"_getFrameAtTime", "(JI)Landroid/graphics/Bitmap;", (void *)android_media_MediaMetadataRetriever_getFrameAtTime},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 {"extractMetadata", "(I)Ljava/lang/String;", (void *)android_media_MediaMetadataRetriever_extractMetadata},
James Dongdf9b3492011-01-04 15:03:48 -0800467 {"getEmbeddedPicture", "(I)[B", (void *)android_media_MediaMetadataRetriever_getEmbeddedPicture},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 {"release", "()V", (void *)android_media_MediaMetadataRetriever_release},
469 {"native_finalize", "()V", (void *)android_media_MediaMetadataRetriever_native_finalize},
470 {"native_setup", "()V", (void *)android_media_MediaMetadataRetriever_native_setup},
Marco Nelissen4935d052009-08-03 11:12:58 -0700471 {"native_init", "()V", (void *)android_media_MediaMetadataRetriever_native_init},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472};
473
Marco Nelissen4935d052009-08-03 11:12:58 -0700474// This function only registers the native methods, and is called from
475// JNI_OnLoad in android_media_MediaPlayer.cpp
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476int register_android_media_MediaMetadataRetriever(JNIEnv *env)
477{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 return AndroidRuntime::registerNativeMethods
Marco Nelissen4935d052009-08-03 11:12:58 -0700479 (env, kClassPathName, nativeMethods, NELEM(nativeMethods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480}