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

Commit 83cc994b authored by Chong Zhang's avatar Chong Zhang
Browse files

MediaRecorder: add getSurface() api and SURFACE video source

Bug: 12305192
Change-Id: If833c5ac8a738ffa284307e0435b5cbd1b7379b1
parent 23ab74de
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -13188,6 +13188,7 @@ package android.media {
    ctor public MediaRecorder();
    method public static final int getAudioSourceMax();
    method public int getMaxAmplitude() throws java.lang.IllegalStateException;
    method public android.view.Surface getSurface();
    method public void prepare() throws java.io.IOException, java.lang.IllegalStateException;
    method public void release();
    method public void reset();
@@ -13272,6 +13273,7 @@ package android.media {
  public final class MediaRecorder.VideoSource {
    field public static final int CAMERA = 1; // 0x1
    field public static final int DEFAULT = 0; // 0x0
    field public static final int SURFACE = 2; // 0x2
  }
  public class MediaRouter {
+28 −3
Original line number Diff line number Diff line
@@ -123,6 +123,18 @@ public class MediaRecorder
     */
    public native void setCamera(Camera c);

    /**
     * Gets the surface to record from when using SURFACE video source.
     * <p>
     * Should only be called after prepare(). Frames rendered before start()
     * will be discarded.
     * </p>
     * @throws IllegalStateException if it is called before prepare(), after
     * stop() or is called when VideoSource is not set to SURFACE.
     * @see android.media.MediaRecorder.VideoSource
     */
    public native Surface getSurface();

    /**
     * Sets a Surface to show a preview of recorded media (video). Calls this
     * before prepare() to make sure that the desirable preview display is
@@ -225,10 +237,23 @@ public class MediaRecorder
       */
        private VideoSource() {}
        public static final int DEFAULT = 0;
        /** Camera video source */
        /** Camera video source
         * <p>
         * Using android.hardware.Camera as video source.
         * </p>
         */
        public static final int CAMERA = 1;
        /** @hide */
        public static final int GRALLOC_BUFFER = 2;
        /** Surface video source
         * <p>
         * Using a Surface as video source.
         * </p><p>
         * This flag must be used when recording from an
         * android.hardware.camera2.CameraDevice source.
         * </p><p>
         * When using this video source type, use {@link MediaRecorder#getSurface()}
         * to retrieve the surface created by MediaRecorder.
         */
        public static final int SURFACE = 2;
    }

    /**
+21 −0
Original line number Diff line number Diff line
@@ -344,6 +344,26 @@ android_media_MediaRecorder_native_getMaxAmplitude(JNIEnv *env, jobject thiz)
    return result;
}

static jobject
android_media_MediaRecorder_getSurface(JNIEnv *env, jobject thiz)
{
    ALOGV("getSurface");
    sp<MediaRecorder> mr = getMediaRecorder(env, thiz);

    sp<IGraphicBufferProducer> bufferProducer = mr->querySurfaceMediaSourceFromMediaServer();
    if (bufferProducer == NULL) {
        jniThrowException(
                env,
                "java/lang/IllegalStateException",
                "failed to get surface");
        return NULL;
    }

    // Wrap the IGBP in a Java-language Surface.
    return android_view_Surface_createFromIGraphicBufferProducer(env,
            bufferProducer);
}

static void
android_media_MediaRecorder_start(JNIEnv *env, jobject thiz)
{
@@ -470,6 +490,7 @@ static JNINativeMethod gMethods[] = {
    {"setMaxDuration",       "(I)V",                            (void *)android_media_MediaRecorder_setMaxDuration},
    {"setMaxFileSize",       "(J)V",                            (void *)android_media_MediaRecorder_setMaxFileSize},
    {"_prepare",             "()V",                             (void *)android_media_MediaRecorder_prepare},
    {"getSurface",           "()Landroid/view/Surface;",        (void *)android_media_MediaRecorder_getSurface},
    {"getMaxAmplitude",      "()I",                             (void *)android_media_MediaRecorder_native_getMaxAmplitude},
    {"start",                "()V",                             (void *)android_media_MediaRecorder_start},
    {"stop",                 "()V",                             (void *)android_media_MediaRecorder_stop},