Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1228e72b authored by Chong Zhang's avatar Chong Zhang Committed by Android Git Automerger
Browse files

am 03359161: MediaRecorder: implement persistent input surface APIs

* commit '03359161':
  MediaRecorder: implement persistent input surface APIs
parents 2cfcaf48 03359161
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.media;

import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.app.ActivityThread;
import android.app.Application;
@@ -142,21 +143,27 @@ 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
+22 −0
Original line number Diff line number Diff line
@@ -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