diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java index 1b054cc55525a..a2f596b51ee1d 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. - *
May only be called after {@link #prepare} in lieu of {@link #getSurface}. - * Frames rendered to the Surface before {@link #start} will be discarded.
+ *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.
* @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 02297fc7ba744..0044bed183d8d 100644 --- a/media/jni/android_media_MediaRecorder.cpp +++ b/media/jni/android_media_MediaRecorder.cpp @@ -29,6 +29,7 @@ #include