diff options
| author | 2015-05-02 02:37:53 +0000 | |
|---|---|---|
| committer | 2015-05-02 02:37:53 +0000 | |
| commit | 970be8a6eb3f1b35dee85fb26b8a49976795bfb6 (patch) | |
| tree | 259bb9a001d3f90e6270af0f5a352e81011c08b5 | |
| parent | 0e3758333de98de24b8cbb2f05fc1b53e182aa9e (diff) | |
| parent | 1228e72b47d5d1b1ae7c80976c6264ba3b3d2214 (diff) | |
am 1228e72b: am 03359161: MediaRecorder: implement persistent input surface APIs
* commit '1228e72b47d5d1b1ae7c80976c6264ba3b3d2214':
MediaRecorder: implement persistent input surface APIs
| -rw-r--r-- | media/java/android/media/MediaRecorder.java | 19 | ||||
| -rw-r--r-- | media/jni/android_media_MediaRecorder.cpp | 22 |
2 files changed, 35 insertions, 6 deletions
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java index 1b054cc55525..a2f596b51ee1 100644 --- a/media/java/android/media/MediaRecorder.java +++ b/media/java/android/media/MediaRecorder.java @@ -16,6 +16,7 @@ package android.media; +import android.annotation.NonNull; import android.annotation.SystemApi; import android.app.ActivityThread; import android.app.Application; @@ -142,22 +143,28 @@ public class MediaRecorder /** * Configures the recorder to use a persistent surface when using SURFACE video source. - * <p> May only be called after {@link #prepare} in lieu of {@link #getSurface}. - * Frames rendered to the Surface before {@link #start} will be discarded.</p> + * <p> May only be called before {@link #prepare}. If called, {@link #getSurface} should + * not be used and will throw IllegalStateException. Frames rendered to the Surface + * before {@link #start} will be discarded.</p> * @param surface a persistent input surface created by * {@link MediaCodec#createPersistentInputSurface} - * @throws IllegalStateException if it is called before {@link #prepare}, after - * {@link #stop}, or is called when VideoSource is not set to SURFACE. + * @throws IllegalStateException if it is called after {@link #prepare} and before + * {@link #stop}. * @throws IllegalArgumentException if the surface was not created by * {@link MediaCodec#createPersistentInputSurface}. * @see MediaCodec#createPersistentInputSurface * @see MediaRecorder.VideoSource */ - public void usePersistentSurface(Surface surface) { - throw new IllegalArgumentException("not implemented"); + public void usePersistentSurface(@NonNull Surface surface) { + if (!(surface instanceof MediaCodec.PersistentSurface)) { + throw new IllegalArgumentException("not a PersistentSurface"); + } + native_usePersistentSurface(surface); } + private native final void native_usePersistentSurface(@NonNull Surface surface); + /** * Sets a Surface to show a preview of recorded media (video). Calls this * before prepare() to make sure that the desirable preview display is diff --git a/media/jni/android_media_MediaRecorder.cpp b/media/jni/android_media_MediaRecorder.cpp index 02297fc7ba74..0044bed183d8 100644 --- a/media/jni/android_media_MediaRecorder.cpp +++ b/media/jni/android_media_MediaRecorder.cpp @@ -29,6 +29,7 @@ #include <camera/ICameraService.h> #include <camera/Camera.h> #include <media/mediarecorder.h> +#include <media/stagefright/PersistentSurface.h> #include <utils/threads.h> #include <ScopedUtfChars.h> @@ -48,6 +49,8 @@ using namespace android; // helper function to extract a native Camera object from a Camera Java object extern sp<Camera> get_native_camera(JNIEnv *env, jobject thiz, struct JNICameraContext** context); +extern sp<PersistentSurface> +android_media_MediaCodec_getPersistentInputSurface(JNIEnv* env, jobject object); struct fields_t { jfieldID context; @@ -115,6 +118,12 @@ static sp<Surface> get_surface(JNIEnv* env, jobject clazz) return android_view_Surface_getSurface(env, clazz); } +static sp<PersistentSurface> get_persistentSurface(JNIEnv* env, jobject object) +{ + ALOGV("get_persistentSurface"); + return android_media_MediaCodec_getPersistentInputSurface(env, object); +} + // Returns true if it throws an exception. static bool process_media_recorder_call(JNIEnv *env, status_t opStatus, const char* exception, const char* message) { @@ -487,6 +496,18 @@ android_media_MediaRecorder_native_finalize(JNIEnv *env, jobject thiz) android_media_MediaRecorder_release(env, thiz); } +void android_media_MediaRecorder_usePersistentSurface( + JNIEnv* env, jobject thiz, jobject object) { + ALOGV("android_media_MediaRecorder_usePersistentSurface"); + + sp<MediaRecorder> mr = getMediaRecorder(env, thiz); + + sp<PersistentSurface> persistentSurface = get_persistentSurface(env, object); + + process_media_recorder_call(env, mr->usePersistentSurface(persistentSurface), + "java/lang/IllegalArgumentException", "native_usePersistentSurface failed."); +} + // ---------------------------------------------------------------------------- static JNINativeMethod gMethods[] = { @@ -513,6 +534,7 @@ static JNINativeMethod gMethods[] = { {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V", (void *)android_media_MediaRecorder_native_setup}, {"native_finalize", "()V", (void *)android_media_MediaRecorder_native_finalize}, + {"native_usePersistentSurface", "(Landroid/view/Surface;)V", (void *)android_media_MediaRecorder_usePersistentSurface }, }; // This function only registers the native methods, and is called from |