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

Commit 46fc7d65 authored by Nipun Kwatra's avatar Nipun Kwatra Committed by Android (Google) Code Review
Browse files

Merge "Added setAuxiliaryOutputFile to MediaRecorder and JNI"

parents dc5f5bd2 b33a5aea
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ public:
    virtual	status_t		setAudioEncoder(int ae) = 0;
    virtual	status_t		setOutputFile(const char* path) = 0;
    virtual	status_t		setOutputFile(int fd, int64_t offset, int64_t length) = 0;
    virtual	status_t		setOutputFileAuxiliary(int fd) = 0;
    virtual	status_t		setVideoSize(int width, int height) = 0;
    virtual	status_t		setVideoFrameRate(int frames_per_second) = 0;
    virtual     status_t                setParameters(const String8& params) = 0;
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ struct MediaRecorderBase {
    virtual status_t setPreviewSurface(const sp<Surface>& surface) = 0;
    virtual status_t setOutputFile(const char *path) = 0;
    virtual status_t setOutputFile(int fd, int64_t offset, int64_t length) = 0;
    virtual status_t setOutputFileAuxiliary(int fd) {return INVALID_OPERATION;}
    virtual status_t setParameters(const String8& params) = 0;
    virtual status_t setListener(const sp<IMediaRecorderClient>& listener) = 0;
    virtual status_t prepare() = 0;
+2 −0
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@ public:
    status_t    setAudioEncoder(int ae);
    status_t    setOutputFile(const char* path);
    status_t    setOutputFile(int fd, int64_t offset, int64_t length);
    status_t    setOutputFileAuxiliary(int fd);
    status_t    setVideoSize(int width, int height);
    status_t    setVideoFrameRate(int frames_per_second);
    status_t    setParameters(const String8& params);
@@ -196,6 +197,7 @@ private:
    bool                        mIsAudioEncoderSet;
    bool                        mIsVideoEncoderSet;
    bool                        mIsOutputFileSet;
    bool                        mIsAuxiliaryOutputFileSet;
    Mutex                       mLock;
    Mutex                       mNotifyLock;
};
+53 −0
Original line number Diff line number Diff line
@@ -72,6 +72,9 @@ public class MediaRecorder

    private String mPath;
    private FileDescriptor mFd;
    private boolean mPrepareAuxiliaryFile = false;
    private String mPathAux;
    private FileDescriptor mFdAux;
    private EventHandler mEventHandler;
    private OnErrorListener mOnErrorListener;
    private OnInfoListener mOnInfoListener;
@@ -479,6 +482,38 @@ public class MediaRecorder
        setParameter(String.format("video-param-encoder-level=%d", encoderLevel));
    }

    /**
     * Pass in the file descriptor of the auxiliary file to be written. Call this after
     * setOutputFormat() but before prepare().
     *
     * @param fd an open file descriptor to be written into.
     * @throws IllegalStateException if it is called before
     * setOutputFormat() or after prepare()
     * @hide
     */
    public void setAuxiliaryOutputFile(FileDescriptor fd) throws IllegalStateException
    {
        mPrepareAuxiliaryFile = true;
        mPathAux = null;
        mFdAux = fd;
    }

    /**
     * Sets the path of the auxiliary output file to be produced. Call this after
     * setOutputFormat() but before prepare().
     *
     * @param path The pathname to use.
     * @throws IllegalStateException if it is called before
     * setOutputFormat() or after prepare()
     * @hide
     */
    public void setAuxiliaryOutputFile(String path) throws IllegalStateException
    {
        mPrepareAuxiliaryFile = true;
        mFdAux = null;
        mPathAux = path;
    }

    /**
     * Pass in the file descriptor of the file to be written. Call this after
     * setOutputFormat() but before prepare().
@@ -510,6 +545,8 @@ public class MediaRecorder
    // native implementation
    private native void _setOutputFile(FileDescriptor fd, long offset, long length)
        throws IllegalStateException, IOException;
    private native void _setOutputFileAux(FileDescriptor fd)
        throws IllegalStateException, IOException;
    private native void _prepare() throws IllegalStateException, IOException;

    /**
@@ -535,6 +572,22 @@ public class MediaRecorder
        } else {
            throw new IOException("No valid output file");
        }

        if (mPrepareAuxiliaryFile) {
            if (mPathAux != null) {
                FileOutputStream fos = new FileOutputStream(mPathAux);
                try {
                    _setOutputFileAux(fos.getFD());
                } finally {
                    fos.close();
                }
            } else if (mFdAux != null) {
                _setOutputFileAux(mFdAux);
            } else {
                throw new IOException("No valid output file");
            }
        }

        _prepare();
    }

+15 −0
Original line number Diff line number Diff line
@@ -259,6 +259,20 @@ android_media_MediaRecorder_setOutputFileFD(JNIEnv *env, jobject thiz, jobject f
    process_media_recorder_call(env, opStatus, "java/io/IOException", "setOutputFile failed.");
}

static void
android_media_MediaRecorder_setOutputFileAuxFD(JNIEnv *env, jobject thiz, jobject fileDescriptor)
{
    LOGV("setOutputFile");
    if (fileDescriptor == NULL) {
        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
        return;
    }
    int fd = getParcelFileDescriptorFD(env, fileDescriptor);
    sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
    status_t opStatus = mr->setOutputFileAuxiliary(fd);
    process_media_recorder_call(env, opStatus, "java/io/IOException", "setOutputFile failed.");
}

static void
android_media_MediaRecorder_setVideoSize(JNIEnv *env, jobject thiz, jint width, jint height)
{
@@ -466,6 +480,7 @@ static JNINativeMethod gMethods[] = {
    {"setAudioEncoder",      "(I)V",                            (void *)android_media_MediaRecorder_setAudioEncoder},
    {"setParameter",         "(Ljava/lang/String;)V",           (void *)android_media_MediaRecorder_setParameter},
    {"_setOutputFile",       "(Ljava/io/FileDescriptor;JJ)V",   (void *)android_media_MediaRecorder_setOutputFileFD},
    {"_setOutputFileAux",    "(Ljava/io/FileDescriptor;)V",     (void *)android_media_MediaRecorder_setOutputFileAuxFD},
    {"setVideoSize",         "(II)V",                           (void *)android_media_MediaRecorder_setVideoSize},
    {"setVideoFrameRate",    "(I)V",                            (void *)android_media_MediaRecorder_setVideoFrameRate},
    {"setMaxDuration",       "(I)V",                            (void *)android_media_MediaRecorder_setMaxDuration},
Loading