Merge "Added setAuxiliaryOutputFile to MediaRecorder and JNI"
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -43,6 +43,7 @@ enum {
|
||||
SET_AUDIO_ENCODER,
|
||||
SET_OUTPUT_FILE_PATH,
|
||||
SET_OUTPUT_FILE_FD,
|
||||
SET_OUTPUT_FILE_AUXILIARY_FD,
|
||||
SET_VIDEO_SIZE,
|
||||
SET_VIDEO_FRAMERATE,
|
||||
SET_PARAMETERS,
|
||||
@@ -159,6 +160,15 @@ public:
|
||||
return reply.readInt32();
|
||||
}
|
||||
|
||||
status_t setOutputFileAuxiliary(int fd) {
|
||||
LOGV("setOutputFileAuxiliary(%d)", fd);
|
||||
Parcel data, reply;
|
||||
data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
|
||||
data.writeFileDescriptor(fd);
|
||||
remote()->transact(SET_OUTPUT_FILE_AUXILIARY_FD, data, &reply);
|
||||
return reply.readInt32();
|
||||
}
|
||||
|
||||
status_t setVideoSize(int width, int height)
|
||||
{
|
||||
LOGV("setVideoSize(%dx%d)", width, height);
|
||||
@@ -377,6 +387,13 @@ status_t BnMediaRecorder::onTransact(
|
||||
::close(fd);
|
||||
return NO_ERROR;
|
||||
} break;
|
||||
case SET_OUTPUT_FILE_AUXILIARY_FD: {
|
||||
LOGV("SET_OUTPUT_FILE_AUXILIARY_FD");
|
||||
CHECK_INTERFACE(IMediaRecorder, data, reply);
|
||||
int fd = dup(data.readFileDescriptor());
|
||||
reply->writeInt32(setOutputFileAuxiliary(fd));
|
||||
return NO_ERROR;
|
||||
} break;
|
||||
case SET_VIDEO_SIZE: {
|
||||
LOGV("SET_VIDEO_SIZE");
|
||||
CHECK_INTERFACE(IMediaRecorder, data, reply);
|
||||
|
||||
@@ -308,6 +308,32 @@ status_t MediaRecorder::setOutputFile(int fd, int64_t offset, int64_t length)
|
||||
return ret;
|
||||
}
|
||||
|
||||
status_t MediaRecorder::setOutputFileAuxiliary(int fd)
|
||||
{
|
||||
LOGV("setOutputFileAuxiliary(%d)", fd);
|
||||
if(mMediaRecorder == NULL) {
|
||||
LOGE("media recorder is not initialized yet");
|
||||
return INVALID_OPERATION;
|
||||
}
|
||||
if (mIsAuxiliaryOutputFileSet) {
|
||||
LOGE("output file has already been set");
|
||||
return INVALID_OPERATION;
|
||||
}
|
||||
if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
|
||||
LOGE("setOutputFile called in an invalid state(%d)", mCurrentState);
|
||||
return INVALID_OPERATION;
|
||||
}
|
||||
|
||||
status_t ret = mMediaRecorder->setOutputFileAuxiliary(fd);
|
||||
if (OK != ret) {
|
||||
LOGV("setOutputFileAuxiliary failed: %d", ret);
|
||||
mCurrentState = MEDIA_RECORDER_ERROR;
|
||||
return ret;
|
||||
}
|
||||
mIsAuxiliaryOutputFileSet = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
status_t MediaRecorder::setVideoSize(int width, int height)
|
||||
{
|
||||
LOGV("setVideoSize(%d, %d)", width, height);
|
||||
@@ -571,6 +597,7 @@ void MediaRecorder::doCleanUp()
|
||||
mIsAudioEncoderSet = false;
|
||||
mIsVideoEncoderSet = false;
|
||||
mIsOutputFileSet = false;
|
||||
mIsAuxiliaryOutputFileSet = false;
|
||||
}
|
||||
|
||||
// Release should be OK in any state
|
||||
|
||||
@@ -164,6 +164,17 @@ status_t MediaRecorderClient::setOutputFile(int fd, int64_t offset, int64_t leng
|
||||
return mRecorder->setOutputFile(fd, offset, length);
|
||||
}
|
||||
|
||||
status_t MediaRecorderClient::setOutputFileAuxiliary(int fd)
|
||||
{
|
||||
LOGV("setOutputFileAuxiliary(%d)", fd);
|
||||
Mutex::Autolock lock(mLock);
|
||||
if (mRecorder == NULL) {
|
||||
LOGE("recorder is not initialized");
|
||||
return NO_INIT;
|
||||
}
|
||||
return mRecorder->setOutputFileAuxiliary(fd);
|
||||
}
|
||||
|
||||
status_t MediaRecorderClient::setVideoSize(int width, int height)
|
||||
{
|
||||
LOGV("setVideoSize(%dx%d)", width, height);
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
virtual status_t setAudioEncoder(int ae);
|
||||
virtual status_t setOutputFile(const char* path);
|
||||
virtual status_t setOutputFile(int fd, int64_t offset, int64_t length);
|
||||
virtual status_t setOutputFileAuxiliary(int fd);
|
||||
virtual status_t setVideoSize(int width, int height);
|
||||
virtual status_t setVideoFrameRate(int frames_per_second);
|
||||
virtual status_t setParameters(const String8& params);
|
||||
|
||||
Reference in New Issue
Block a user