1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <assert.h>
18 #include <fcntl.h>
19 #include <inttypes.h>
20 #include <limits.h>
21 #include <stdio.h>
22 #include <unistd.h>
23
24 //#define LOG_NDEBUG 0
25 #define LOG_TAG "MediaRecorderJNI"
26 #include <utils/Log.h>
27
28 #include <gui/Surface.h>
29 #include <camera/Camera.h>
30 #include <media/mediarecorder.h>
31 #include <media/stagefright/PersistentSurface.h>
32 #include <utils/threads.h>
33
34 #include <ScopedUtfChars.h>
35
36 #include "jni.h"
37 #include "JNIHelp.h"
38 #include "android_runtime/AndroidRuntime.h"
39
40 #include <system/audio.h>
41 #include <android_runtime/android_view_Surface.h>
42
43 // ----------------------------------------------------------------------------
44
45 using namespace android;
46
47 // ----------------------------------------------------------------------------
48
49 // helper function to extract a native Camera object from a Camera Java object
50 extern sp<Camera> get_native_camera(JNIEnv *env, jobject thiz, struct JNICameraContext** context);
51 extern sp<PersistentSurface>
52 android_media_MediaCodec_getPersistentInputSurface(JNIEnv* env, jobject object);
53
54 struct fields_t {
55 jfieldID context;
56 jfieldID surface;
57
58 jmethodID post_event;
59 };
60 static fields_t fields;
61
62 static Mutex sLock;
63
64 // ----------------------------------------------------------------------------
65 // ref-counted object for callbacks
66 class JNIMediaRecorderListener: public MediaRecorderListener
67 {
68 public:
69 JNIMediaRecorderListener(JNIEnv* env, jobject thiz, jobject weak_thiz);
70 ~JNIMediaRecorderListener();
71 void notify(int msg, int ext1, int ext2);
72 private:
73 JNIMediaRecorderListener();
74 jclass mClass; // Reference to MediaRecorder class
75 jobject mObject; // Weak ref to MediaRecorder Java object to call on
76 };
77
JNIMediaRecorderListener(JNIEnv * env,jobject thiz,jobject weak_thiz)78 JNIMediaRecorderListener::JNIMediaRecorderListener(JNIEnv* env, jobject thiz, jobject weak_thiz)
79 {
80
81 // Hold onto the MediaRecorder class for use in calling the static method
82 // that posts events to the application thread.
83 jclass clazz = env->GetObjectClass(thiz);
84 if (clazz == NULL) {
85 ALOGE("Can't find android/media/MediaRecorder");
86 jniThrowException(env, "java/lang/Exception", NULL);
87 return;
88 }
89 mClass = (jclass)env->NewGlobalRef(clazz);
90
91 // We use a weak reference so the MediaRecorder object can be garbage collected.
92 // The reference is only used as a proxy for callbacks.
93 mObject = env->NewGlobalRef(weak_thiz);
94 }
95
~JNIMediaRecorderListener()96 JNIMediaRecorderListener::~JNIMediaRecorderListener()
97 {
98 // remove global references
99 JNIEnv *env = AndroidRuntime::getJNIEnv();
100 env->DeleteGlobalRef(mObject);
101 env->DeleteGlobalRef(mClass);
102 }
103
notify(int msg,int ext1,int ext2)104 void JNIMediaRecorderListener::notify(int msg, int ext1, int ext2)
105 {
106 ALOGV("JNIMediaRecorderListener::notify");
107
108 JNIEnv *env = AndroidRuntime::getJNIEnv();
109 env->CallStaticVoidMethod(mClass, fields.post_event, mObject, msg, ext1, ext2, NULL);
110 }
111
112 // ----------------------------------------------------------------------------
113
get_surface(JNIEnv * env,jobject clazz)114 static sp<Surface> get_surface(JNIEnv* env, jobject clazz)
115 {
116 ALOGV("get_surface");
117 return android_view_Surface_getSurface(env, clazz);
118 }
119
get_persistentSurface(JNIEnv * env,jobject object)120 static sp<PersistentSurface> get_persistentSurface(JNIEnv* env, jobject object)
121 {
122 ALOGV("get_persistentSurface");
123 return android_media_MediaCodec_getPersistentInputSurface(env, object);
124 }
125
126 // Returns true if it throws an exception.
process_media_recorder_call(JNIEnv * env,status_t opStatus,const char * exception,const char * message)127 static bool process_media_recorder_call(JNIEnv *env, status_t opStatus, const char* exception, const char* message)
128 {
129 ALOGV("process_media_recorder_call");
130 if (opStatus == (status_t)INVALID_OPERATION) {
131 jniThrowException(env, "java/lang/IllegalStateException", NULL);
132 return true;
133 } else if (opStatus != (status_t)OK) {
134 jniThrowException(env, exception, message);
135 return true;
136 }
137 return false;
138 }
139
getMediaRecorder(JNIEnv * env,jobject thiz)140 static sp<MediaRecorder> getMediaRecorder(JNIEnv* env, jobject thiz)
141 {
142 Mutex::Autolock l(sLock);
143 MediaRecorder* const p = (MediaRecorder*)env->GetLongField(thiz, fields.context);
144 return sp<MediaRecorder>(p);
145 }
146
setMediaRecorder(JNIEnv * env,jobject thiz,const sp<MediaRecorder> & recorder)147 static sp<MediaRecorder> setMediaRecorder(JNIEnv* env, jobject thiz, const sp<MediaRecorder>& recorder)
148 {
149 Mutex::Autolock l(sLock);
150 sp<MediaRecorder> old = (MediaRecorder*)env->GetLongField(thiz, fields.context);
151 if (recorder.get()) {
152 recorder->incStrong(thiz);
153 }
154 if (old != 0) {
155 old->decStrong(thiz);
156 }
157 env->SetLongField(thiz, fields.context, (jlong)recorder.get());
158 return old;
159 }
160
161
android_media_MediaRecorder_setCamera(JNIEnv * env,jobject thiz,jobject camera)162 static void android_media_MediaRecorder_setCamera(JNIEnv* env, jobject thiz, jobject camera)
163 {
164 // we should not pass a null camera to get_native_camera() call.
165 if (camera == NULL) {
166 jniThrowNullPointerException(env, "camera object is a NULL pointer");
167 return;
168 }
169 sp<Camera> c = get_native_camera(env, camera, NULL);
170 if (c == NULL) {
171 // get_native_camera will throw an exception in this case
172 return;
173 }
174 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
175 process_media_recorder_call(env, mr->setCamera(c->remote(), c->getRecordingProxy()),
176 "java/lang/RuntimeException", "setCamera failed.");
177 }
178
179 static void
android_media_MediaRecorder_setVideoSource(JNIEnv * env,jobject thiz,jint vs)180 android_media_MediaRecorder_setVideoSource(JNIEnv *env, jobject thiz, jint vs)
181 {
182 ALOGV("setVideoSource(%d)", vs);
183 if (vs < VIDEO_SOURCE_DEFAULT || vs >= VIDEO_SOURCE_LIST_END) {
184 jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid video source");
185 return;
186 }
187 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
188 process_media_recorder_call(env, mr->setVideoSource(vs), "java/lang/RuntimeException", "setVideoSource failed.");
189 }
190
191 static void
android_media_MediaRecorder_setAudioSource(JNIEnv * env,jobject thiz,jint as)192 android_media_MediaRecorder_setAudioSource(JNIEnv *env, jobject thiz, jint as)
193 {
194 ALOGV("setAudioSource(%d)", as);
195 if (as < AUDIO_SOURCE_DEFAULT ||
196 (as >= AUDIO_SOURCE_CNT && as != AUDIO_SOURCE_FM_TUNER)) {
197 jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid audio source");
198 return;
199 }
200
201 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
202 process_media_recorder_call(env, mr->setAudioSource(as), "java/lang/RuntimeException", "setAudioSource failed.");
203 }
204
205 static void
android_media_MediaRecorder_setOutputFormat(JNIEnv * env,jobject thiz,jint of)206 android_media_MediaRecorder_setOutputFormat(JNIEnv *env, jobject thiz, jint of)
207 {
208 ALOGV("setOutputFormat(%d)", of);
209 if (of < OUTPUT_FORMAT_DEFAULT || of >= OUTPUT_FORMAT_LIST_END) {
210 jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid output format");
211 return;
212 }
213 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
214 process_media_recorder_call(env, mr->setOutputFormat(of), "java/lang/RuntimeException", "setOutputFormat failed.");
215 }
216
217 static void
android_media_MediaRecorder_setVideoEncoder(JNIEnv * env,jobject thiz,jint ve)218 android_media_MediaRecorder_setVideoEncoder(JNIEnv *env, jobject thiz, jint ve)
219 {
220 ALOGV("setVideoEncoder(%d)", ve);
221 if (ve < VIDEO_ENCODER_DEFAULT || ve >= VIDEO_ENCODER_LIST_END) {
222 jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid video encoder");
223 return;
224 }
225 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
226 process_media_recorder_call(env, mr->setVideoEncoder(ve), "java/lang/RuntimeException", "setVideoEncoder failed.");
227 }
228
229 static void
android_media_MediaRecorder_setAudioEncoder(JNIEnv * env,jobject thiz,jint ae)230 android_media_MediaRecorder_setAudioEncoder(JNIEnv *env, jobject thiz, jint ae)
231 {
232 ALOGV("setAudioEncoder(%d)", ae);
233 if (ae < AUDIO_ENCODER_DEFAULT || ae >= AUDIO_ENCODER_LIST_END) {
234 jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid audio encoder");
235 return;
236 }
237 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
238 process_media_recorder_call(env, mr->setAudioEncoder(ae), "java/lang/RuntimeException", "setAudioEncoder failed.");
239 }
240
241 static void
android_media_MediaRecorder_setParameter(JNIEnv * env,jobject thiz,jstring params)242 android_media_MediaRecorder_setParameter(JNIEnv *env, jobject thiz, jstring params)
243 {
244 ALOGV("setParameter()");
245 if (params == NULL)
246 {
247 ALOGE("Invalid or empty params string. This parameter will be ignored.");
248 return;
249 }
250
251 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
252
253 const char* params8 = env->GetStringUTFChars(params, NULL);
254 if (params8 == NULL)
255 {
256 ALOGE("Failed to covert jstring to String8. This parameter will be ignored.");
257 return;
258 }
259
260 process_media_recorder_call(env, mr->setParameters(String8(params8)), "java/lang/RuntimeException", "setParameter failed.");
261 env->ReleaseStringUTFChars(params,params8);
262 }
263
264 static void
android_media_MediaRecorder_setOutputFileFD(JNIEnv * env,jobject thiz,jobject fileDescriptor,jlong offset,jlong length)265 android_media_MediaRecorder_setOutputFileFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length)
266 {
267 ALOGV("setOutputFile");
268 if (fileDescriptor == NULL) {
269 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
270 return;
271 }
272 int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
273 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
274 status_t opStatus = mr->setOutputFile(fd, offset, length);
275 process_media_recorder_call(env, opStatus, "java/io/IOException", "setOutputFile failed.");
276 }
277
278 static void
android_media_MediaRecorder_setVideoSize(JNIEnv * env,jobject thiz,jint width,jint height)279 android_media_MediaRecorder_setVideoSize(JNIEnv *env, jobject thiz, jint width, jint height)
280 {
281 ALOGV("setVideoSize(%d, %d)", width, height);
282 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
283
284 if (width <= 0 || height <= 0) {
285 jniThrowException(env, "java/lang/IllegalArgumentException", "invalid video size");
286 return;
287 }
288 process_media_recorder_call(env, mr->setVideoSize(width, height), "java/lang/RuntimeException", "setVideoSize failed.");
289 }
290
291 static void
android_media_MediaRecorder_setVideoFrameRate(JNIEnv * env,jobject thiz,jint rate)292 android_media_MediaRecorder_setVideoFrameRate(JNIEnv *env, jobject thiz, jint rate)
293 {
294 ALOGV("setVideoFrameRate(%d)", rate);
295 if (rate <= 0) {
296 jniThrowException(env, "java/lang/IllegalArgumentException", "invalid frame rate");
297 return;
298 }
299 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
300 process_media_recorder_call(env, mr->setVideoFrameRate(rate), "java/lang/RuntimeException", "setVideoFrameRate failed.");
301 }
302
303 static void
android_media_MediaRecorder_setMaxDuration(JNIEnv * env,jobject thiz,jint max_duration_ms)304 android_media_MediaRecorder_setMaxDuration(JNIEnv *env, jobject thiz, jint max_duration_ms)
305 {
306 ALOGV("setMaxDuration(%d)", max_duration_ms);
307 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
308
309 char params[64];
310 sprintf(params, "max-duration=%d", max_duration_ms);
311
312 process_media_recorder_call(env, mr->setParameters(String8(params)), "java/lang/RuntimeException", "setMaxDuration failed.");
313 }
314
315 static void
android_media_MediaRecorder_setMaxFileSize(JNIEnv * env,jobject thiz,jlong max_filesize_bytes)316 android_media_MediaRecorder_setMaxFileSize(
317 JNIEnv *env, jobject thiz, jlong max_filesize_bytes)
318 {
319 ALOGV("setMaxFileSize(%lld)", (long long)max_filesize_bytes);
320 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
321
322 char params[64];
323 sprintf(params, "max-filesize=%" PRId64, max_filesize_bytes);
324
325 process_media_recorder_call(env, mr->setParameters(String8(params)), "java/lang/RuntimeException", "setMaxFileSize failed.");
326 }
327
328 static void
android_media_MediaRecorder_prepare(JNIEnv * env,jobject thiz)329 android_media_MediaRecorder_prepare(JNIEnv *env, jobject thiz)
330 {
331 ALOGV("prepare");
332 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
333
334 jobject surface = env->GetObjectField(thiz, fields.surface);
335 if (surface != NULL) {
336 const sp<Surface> native_surface = get_surface(env, surface);
337
338 // The application may misbehave and
339 // the preview surface becomes unavailable
340 if (native_surface.get() == 0) {
341 ALOGE("Application lost the surface");
342 jniThrowException(env, "java/io/IOException", "invalid preview surface");
343 return;
344 }
345
346 ALOGI("prepare: surface=%p", native_surface.get());
347 if (process_media_recorder_call(env, mr->setPreviewSurface(native_surface->getIGraphicBufferProducer()), "java/lang/RuntimeException", "setPreviewSurface failed.")) {
348 return;
349 }
350 }
351 process_media_recorder_call(env, mr->prepare(), "java/io/IOException", "prepare failed.");
352 }
353
354 static jint
android_media_MediaRecorder_native_getMaxAmplitude(JNIEnv * env,jobject thiz)355 android_media_MediaRecorder_native_getMaxAmplitude(JNIEnv *env, jobject thiz)
356 {
357 ALOGV("getMaxAmplitude");
358 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
359 int result = 0;
360 process_media_recorder_call(env, mr->getMaxAmplitude(&result), "java/lang/RuntimeException", "getMaxAmplitude failed.");
361 return (jint) result;
362 }
363
364 static jobject
android_media_MediaRecorder_getSurface(JNIEnv * env,jobject thiz)365 android_media_MediaRecorder_getSurface(JNIEnv *env, jobject thiz)
366 {
367 ALOGV("getSurface");
368 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
369
370 sp<IGraphicBufferProducer> bufferProducer = mr->querySurfaceMediaSourceFromMediaServer();
371 if (bufferProducer == NULL) {
372 jniThrowException(
373 env,
374 "java/lang/IllegalStateException",
375 "failed to get surface");
376 return NULL;
377 }
378
379 // Wrap the IGBP in a Java-language Surface.
380 return android_view_Surface_createFromIGraphicBufferProducer(env,
381 bufferProducer);
382 }
383
384 static void
android_media_MediaRecorder_start(JNIEnv * env,jobject thiz)385 android_media_MediaRecorder_start(JNIEnv *env, jobject thiz)
386 {
387 ALOGV("start");
388 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
389 process_media_recorder_call(env, mr->start(), "java/lang/RuntimeException", "start failed.");
390 }
391
392 static void
android_media_MediaRecorder_stop(JNIEnv * env,jobject thiz)393 android_media_MediaRecorder_stop(JNIEnv *env, jobject thiz)
394 {
395 ALOGV("stop");
396 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
397 process_media_recorder_call(env, mr->stop(), "java/lang/RuntimeException", "stop failed.");
398 }
399
400 static void
android_media_MediaRecorder_pause(JNIEnv * env,jobject thiz)401 android_media_MediaRecorder_pause(JNIEnv *env, jobject thiz)
402 {
403 ALOGV("pause");
404 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
405 process_media_recorder_call(env, mr->pause(), "java/lang/RuntimeException", "pause failed.");
406 }
407
408 static void
android_media_MediaRecorder_resume(JNIEnv * env,jobject thiz)409 android_media_MediaRecorder_resume(JNIEnv *env, jobject thiz)
410 {
411 ALOGV("resume");
412 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
413 process_media_recorder_call(env, mr->resume(), "java/lang/RuntimeException", "resume failed.");
414 }
415
416 static void
android_media_MediaRecorder_native_reset(JNIEnv * env,jobject thiz)417 android_media_MediaRecorder_native_reset(JNIEnv *env, jobject thiz)
418 {
419 ALOGV("native_reset");
420 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
421 process_media_recorder_call(env, mr->reset(), "java/lang/RuntimeException", "native_reset failed.");
422 }
423
424 static void
android_media_MediaRecorder_release(JNIEnv * env,jobject thiz)425 android_media_MediaRecorder_release(JNIEnv *env, jobject thiz)
426 {
427 ALOGV("release");
428 sp<MediaRecorder> mr = setMediaRecorder(env, thiz, 0);
429 if (mr != NULL) {
430 mr->setListener(NULL);
431 mr->release();
432 }
433 }
434
435 // This function gets some field IDs, which in turn causes class initialization.
436 // It is called from a static block in MediaRecorder, which won't run until the
437 // first time an instance of this class is used.
438 static void
android_media_MediaRecorder_native_init(JNIEnv * env)439 android_media_MediaRecorder_native_init(JNIEnv *env)
440 {
441 jclass clazz;
442
443 clazz = env->FindClass("android/media/MediaRecorder");
444 if (clazz == NULL) {
445 return;
446 }
447
448 fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
449 if (fields.context == NULL) {
450 return;
451 }
452
453 fields.surface = env->GetFieldID(clazz, "mSurface", "Landroid/view/Surface;");
454 if (fields.surface == NULL) {
455 return;
456 }
457
458 jclass surface = env->FindClass("android/view/Surface");
459 if (surface == NULL) {
460 return;
461 }
462
463 fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
464 "(Ljava/lang/Object;IIILjava/lang/Object;)V");
465 if (fields.post_event == NULL) {
466 return;
467 }
468 }
469
470
471 static void
android_media_MediaRecorder_native_setup(JNIEnv * env,jobject thiz,jobject weak_this,jstring packageName,jstring opPackageName)472 android_media_MediaRecorder_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
473 jstring packageName, jstring opPackageName)
474 {
475 ALOGV("setup");
476
477 ScopedUtfChars opPackageNameStr(env, opPackageName);
478
479 sp<MediaRecorder> mr = new MediaRecorder(String16(opPackageNameStr.c_str()));
480 if (mr == NULL) {
481 jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
482 return;
483 }
484 if (mr->initCheck() != NO_ERROR) {
485 jniThrowException(env, "java/lang/RuntimeException", "Unable to initialize media recorder");
486 return;
487 }
488
489 // create new listener and give it to MediaRecorder
490 sp<JNIMediaRecorderListener> listener = new JNIMediaRecorderListener(env, thiz, weak_this);
491 mr->setListener(listener);
492
493 // Convert client name jstring to String16
494 const char16_t *rawClientName = reinterpret_cast<const char16_t*>(
495 env->GetStringChars(packageName, NULL));
496 jsize rawClientNameLen = env->GetStringLength(packageName);
497 String16 clientName(rawClientName, rawClientNameLen);
498 env->ReleaseStringChars(packageName,
499 reinterpret_cast<const jchar*>(rawClientName));
500
501 // pass client package name for permissions tracking
502 mr->setClientName(clientName);
503
504 setMediaRecorder(env, thiz, mr);
505 }
506
507 static void
android_media_MediaRecorder_native_finalize(JNIEnv * env,jobject thiz)508 android_media_MediaRecorder_native_finalize(JNIEnv *env, jobject thiz)
509 {
510 ALOGV("finalize");
511 android_media_MediaRecorder_release(env, thiz);
512 }
513
android_media_MediaRecorder_setInputSurface(JNIEnv * env,jobject thiz,jobject object)514 void android_media_MediaRecorder_setInputSurface(
515 JNIEnv* env, jobject thiz, jobject object) {
516 ALOGV("android_media_MediaRecorder_setInputSurface");
517
518 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
519
520 sp<PersistentSurface> persistentSurface = get_persistentSurface(env, object);
521
522 process_media_recorder_call(env, mr->setInputSurface(persistentSurface),
523 "java/lang/IllegalArgumentException", "native_setInputSurface failed.");
524 }
525
526 // ----------------------------------------------------------------------------
527
528 static const JNINativeMethod gMethods[] = {
529 {"setCamera", "(Landroid/hardware/Camera;)V", (void *)android_media_MediaRecorder_setCamera},
530 {"setVideoSource", "(I)V", (void *)android_media_MediaRecorder_setVideoSource},
531 {"setAudioSource", "(I)V", (void *)android_media_MediaRecorder_setAudioSource},
532 {"setOutputFormat", "(I)V", (void *)android_media_MediaRecorder_setOutputFormat},
533 {"setVideoEncoder", "(I)V", (void *)android_media_MediaRecorder_setVideoEncoder},
534 {"setAudioEncoder", "(I)V", (void *)android_media_MediaRecorder_setAudioEncoder},
535 {"setParameter", "(Ljava/lang/String;)V", (void *)android_media_MediaRecorder_setParameter},
536 {"_setOutputFile", "(Ljava/io/FileDescriptor;JJ)V", (void *)android_media_MediaRecorder_setOutputFileFD},
537 {"setVideoSize", "(II)V", (void *)android_media_MediaRecorder_setVideoSize},
538 {"setVideoFrameRate", "(I)V", (void *)android_media_MediaRecorder_setVideoFrameRate},
539 {"setMaxDuration", "(I)V", (void *)android_media_MediaRecorder_setMaxDuration},
540 {"setMaxFileSize", "(J)V", (void *)android_media_MediaRecorder_setMaxFileSize},
541 {"_prepare", "()V", (void *)android_media_MediaRecorder_prepare},
542 {"getSurface", "()Landroid/view/Surface;", (void *)android_media_MediaRecorder_getSurface},
543 {"getMaxAmplitude", "()I", (void *)android_media_MediaRecorder_native_getMaxAmplitude},
544 {"start", "()V", (void *)android_media_MediaRecorder_start},
545 {"stop", "()V", (void *)android_media_MediaRecorder_stop},
546 {"pause", "()V", (void *)android_media_MediaRecorder_pause},
547 {"resume", "()V", (void *)android_media_MediaRecorder_resume},
548 {"native_reset", "()V", (void *)android_media_MediaRecorder_native_reset},
549 {"release", "()V", (void *)android_media_MediaRecorder_release},
550 {"native_init", "()V", (void *)android_media_MediaRecorder_native_init},
551 {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V",
552 (void *)android_media_MediaRecorder_native_setup},
553 {"native_finalize", "()V", (void *)android_media_MediaRecorder_native_finalize},
554 {"native_setInputSurface", "(Landroid/view/Surface;)V", (void *)android_media_MediaRecorder_setInputSurface },
555 };
556
557 // This function only registers the native methods, and is called from
558 // JNI_OnLoad in android_media_MediaPlayer.cpp
register_android_media_MediaRecorder(JNIEnv * env)559 int register_android_media_MediaRecorder(JNIEnv *env)
560 {
561 return AndroidRuntime::registerNativeMethods(env,
562 "android/media/MediaRecorder", gMethods, NELEM(gMethods));
563 }
564