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

Commit 32ed0738 authored by Steve Kondik's avatar Steve Kondik
Browse files

MediaRecorder: Add pause interface

- add pause in java level
- add pause in jni level

CRs-Fixed: 587051

Add 2 APIs (suspend/resume) in MediaPlayer

- API:suspend() will just pause the player and release all the decoders
  to replace release() which will release the whole player
- API:resume() will just init the decoders again,
  then start() will be called to start to play the streaming

Change-Id: Ia0c38bd827f21261b2bd87c04778e86362003344
parent 3fe8894f
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -3454,6 +3454,23 @@ public class MediaPlayer implements SubtitleController.Listener
                mode == VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
    }

    /** @hide
    */
    public boolean suspend() {
        stayAwake(false);
        return _suspend();
    }

    private native boolean _suspend();

    /** @hide
    */
    public boolean resume() {
        return _resume();
    }

    private native boolean _resume();

    /** @hide */
    static class TimeProvider implements MediaPlayer.OnSeekCompleteListener,
            MediaTimeProvider {
+1 −6
Original line number Diff line number Diff line
@@ -807,14 +807,9 @@ public class MediaRecorder
     */
    public native void start() throws IllegalStateException;


    /** @hide
    */
    public void pause() throws IllegalStateException
    {
        setParameter("pause=1");
    }

    public native void pause() throws IllegalStateException;

    /**
     * Stops recording. Call this after start(). Once recording is stopped,
+0 −3
Original line number Diff line number Diff line
@@ -52,8 +52,6 @@ LOCAL_REQUIRED_MODULES := \
LOCAL_STATIC_LIBRARIES := \
    libstagefright_amrnbenc

LOCAL_WHOLE_STATIC_LIBRARIES := libavmediaextentions

LOCAL_C_INCLUDES += \
    external/libexif/ \
    external/tremor/Tremor \
@@ -65,7 +63,6 @@ LOCAL_C_INCLUDES += \
    frameworks/av/media/libstagefright/codecs/amrnb/common \
    frameworks/av/media/libstagefright/codecs/amrnb/common/include \
    frameworks/av/media/mtp \
    frameworks/av/media/libavextensions \
    frameworks/native/include/media/openmax \
    $(call include-path-for, libhardware)/hardware \
    system/media/camera/include \
+34 −0
Original line number Diff line number Diff line
@@ -1191,6 +1191,38 @@ android_media_MediaPlayer_setNextMediaPlayer(JNIEnv *env, jobject thiz, jobject
    ;
}

static jboolean
android_media_MediaPlayer_suspend(JNIEnv *env, jobject thiz)
{
    sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
    if (mp == NULL) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return false;
    }

    if (mp->suspend() != OK) {
        return false;
    }

    return true;
}

static jboolean
android_media_MediaPlayer_resume(JNIEnv *env, jobject thiz)
{
    sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
    if (mp == NULL) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return false;
    }

    if (mp->resume() != OK) {
        return false;
    }

    return true;
}

// ----------------------------------------------------------------------------

static JNINativeMethod gMethods[] = {
@@ -1240,6 +1272,8 @@ static JNINativeMethod gMethods[] = {
    {"native_pullBatteryData", "(Landroid/os/Parcel;)I",        (void *)android_media_MediaPlayer_pullBatteryData},
    {"native_setRetransmitEndpoint", "(Ljava/lang/String;I)I",  (void *)android_media_MediaPlayer_setRetransmitEndpoint},
    {"setNextMediaPlayer",  "(Landroid/media/MediaPlayer;)V",   (void *)android_media_MediaPlayer_setNextMediaPlayer},
    {"_suspend",             "()Z",                             (void *)android_media_MediaPlayer_suspend},
    {"_resume",              "()Z",                             (void *)android_media_MediaPlayer_resume},
};

// This function only registers the native methods
+11 −2
Original line number Diff line number Diff line
@@ -40,8 +40,8 @@

#include <system/audio.h>
#include <android_runtime/android_view_Surface.h>
#include <media/AVMediaExtensions.h>
#include "SeempLog.h"

// ----------------------------------------------------------------------------

using namespace android;
@@ -394,6 +394,14 @@ android_media_MediaRecorder_start(JNIEnv *env, jobject thiz)
    process_media_recorder_call(env, mr->start(), "java/lang/RuntimeException", "start failed.");
}

static void
android_media_MediaRecorder_pause(JNIEnv *env, jobject thiz)
{
    ALOGV("pause");
    sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
    process_media_recorder_call(env, mr->pause(), "java/lang/RuntimeException", "pause failed.");
}

static void
android_media_MediaRecorder_stop(JNIEnv *env, jobject thiz)
{
@@ -465,7 +473,7 @@ android_media_MediaRecorder_native_setup(JNIEnv *env, jobject thiz, jobject weak

    ScopedUtfChars opPackageNameStr(env, opPackageName);

    sp<MediaRecorder> mr = AVMediaUtils::get()->createMediaRecorder(String16(opPackageNameStr.c_str()));
    sp<MediaRecorder> mr = new MediaRecorder(String16(opPackageNameStr.c_str()));
    if (mr == NULL) {
        jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
        return;
@@ -531,6 +539,7 @@ static JNINativeMethod gMethods[] = {
    {"getSurface",           "()Landroid/view/Surface;",        (void *)android_media_MediaRecorder_getSurface},
    {"getMaxAmplitude",      "()I",                             (void *)android_media_MediaRecorder_native_getMaxAmplitude},
    {"start",                "()V",                             (void *)android_media_MediaRecorder_start},
    {"pause",                "()V",                             (void *)android_media_MediaRecorder_pause},
    {"stop",                 "()V",                             (void *)android_media_MediaRecorder_stop},
    {"native_reset",         "()V",                             (void *)android_media_MediaRecorder_native_reset},
    {"release",              "()V",                             (void *)android_media_MediaRecorder_release},