summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--media/java/android/media/MediaRecorder.java19
-rw-r--r--media/jni/android_media_MediaRecorder.cpp22
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