MediaRecorder: implement persistent input surface APIs

Bug: 19127604
Bug: 19489395

Change-Id: Ic8e151b97ea6b85fc65f724d3e68e1cb6b500866
This commit is contained in:
Chong Zhang
2015-05-01 12:50:30 -07:00
parent 1d82220a0e
commit 0335916173
2 changed files with 35 additions and 6 deletions

View File

@@ -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

View File

@@ -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