summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/media/mediarecorder.h38
-rw-r--r--media/java/android/media/MediaRecorder.java76
-rw-r--r--media/jni/android_media_MediaRecorder.cpp33
-rw-r--r--media/libmedia/mediarecorder.cpp8
4 files changed, 136 insertions, 19 deletions
diff --git a/include/media/mediarecorder.h b/include/media/mediarecorder.h
index aebe191..9b54ca9 100644
--- a/include/media/mediarecorder.h
+++ b/include/media/mediarecorder.h
@@ -30,7 +30,7 @@ class ICamera;
typedef void (*media_completion_f)(status_t status, void *cookie);
/* Do not change these values without updating their counterparts
- * in java/android/android/media/MediaRecorder.java!
+ * in media/java/android/media/MediaRecorder.java!
*/
enum audio_source {
AUDIO_SOURCE_DEFAULT = 0,
@@ -38,26 +38,47 @@ enum audio_source {
AUDIO_SOURCE_VOICE_UPLINK = 2,
AUDIO_SOURCE_VOICE_DOWNLINK = 3,
AUDIO_SOURCE_VOICE_CALL = 4,
- AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_CALL
+ AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_CALL,
+
+ AUDIO_SOURCE_LIST_END // must be last - used to validate audio source type
};
enum video_source {
VIDEO_SOURCE_DEFAULT = 0,
VIDEO_SOURCE_CAMERA = 1,
+
+ VIDEO_SOURCE_LIST_END // must be last - used to validate audio source type
};
-//Please update java/android/android/media/MediaRecorder.java if the following is updated.
+//Please update media/java/android/media/MediaRecorder.java if the following is updated.
enum output_format {
OUTPUT_FORMAT_DEFAULT = 0,
- OUTPUT_FORMAT_THREE_GPP,
- OUTPUT_FORMAT_MPEG_4,
- OUTPUT_FORMAT_RAW_AMR,
+ OUTPUT_FORMAT_THREE_GPP = 1,
+ OUTPUT_FORMAT_MPEG_4 = 2,
+
+
+ OUTPUT_FORMAT_AUDIO_ONLY_START = 3, // Used in validating the output format. Should be the
+ // at the start of the audio only output formats.
+
+ /* These are audio only file formats */
+ OUTPUT_FORMAT_RAW_AMR = 3, //to be backward compatible
+ OUTPUT_FORMAT_AMR_NB = 3,
+ OUTPUT_FORMAT_AMR_WB = 4,
+ OUTPUT_FORMAT_AAC_ADIF = 5,
+ OUTPUT_FORMAT_AAC_ADTS = 6,
+
OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
};
enum audio_encoder {
AUDIO_ENCODER_DEFAULT = 0,
AUDIO_ENCODER_AMR_NB = 1,
+ AUDIO_ENCODER_AMR_WB = 2,
+ AUDIO_ENCODER_AAC = 3,
+ AUDIO_ENCODER_AAC_PLUS = 4,
+ AUDIO_ENCODER_EAAC_PLUS = 5,
+
+ AUDIO_ENCODER_LIST_END // must be the last - used to validate the audio encoder type
};
enum video_encoder {
@@ -65,8 +86,11 @@ enum video_encoder {
VIDEO_ENCODER_H263 = 1,
VIDEO_ENCODER_H264 = 2,
VIDEO_ENCODER_MPEG_4_SP = 3,
+
+ VIDEO_ENCODER_LIST_END // must be the last - used to validate the video encoder type
};
+
// Maximum frames per second is 24
#define MEDIA_RECORDER_MAX_FRAME_RATE 24
@@ -105,7 +129,7 @@ enum media_recorder_error_type {
// The codes are distributed as follow:
// 0xx: Reserved
// 8xx: General info/warning
-//
+//
enum media_recorder_info_type {
MEDIA_RECORDER_INFO_UNKNOWN = 1,
MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800,
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index 44f21c8..be4b489 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -164,8 +164,19 @@ public class MediaRecorder
public static final int THREE_GPP = 1;
/** MPEG4 media file format*/
public static final int MPEG_4 = 2;
- /** Raw AMR file format */
+
+ /** The following formats are audio only .aac or .amr formats **/
+ /** @deprecated Deprecated in favor of AMR_NB */
+ /** @todo change link when AMR_NB is exposed. Deprecated in favor of {@link MediaRecorder.OutputFormat#AMR_NB} */
public static final int RAW_AMR = 3;
+ /** @hide AMR NB file format */
+ public static final int AMR_NB = 3;
+ /** @hide AMR WB file format */
+ public static final int AMR_WB = 4;
+ /** @hide AAC ADIF file format */
+ public static final int AAC_ADIF = 5;
+ /** @hide AAC ADTS file format */
+ public static final int AAC_ADTS = 6;
};
/**
@@ -180,7 +191,14 @@ public class MediaRecorder
public static final int DEFAULT = 0;
/** AMR (Narrowband) audio codec */
public static final int AMR_NB = 1;
- //public static final AAC = 2; currently unsupported
+ /** @hide AMR (Wideband) audio codec */
+ public static final int AMR_WB = 2;
+ /** @hide AAC audio codec */
+ public static final int AAC = 3;
+ /** @hide enhanced AAC audio codec */
+ public static final int AAC_PLUS = 4;
+ /** @hide enhanced AAC plus audio codec */
+ public static final int EAAC_PLUS = 5;
}
/**
@@ -198,6 +216,46 @@ public class MediaRecorder
public static final int MPEG_4_SP = 3;
}
+
+ /**
+ * @hide Defines the audio sampling rate. This must be set before
+ * setAudioEncoder() or it will be ignored.
+ * This parameter is used with
+ * {@link MediaRecorder#setParameters(String)}.
+ */
+ public final class AudioParamSamplingRate {
+ /* Do not change these values without updating their counterparts
+ * in include/media/mediarecorder.h!
+ */
+ private AudioParamSamplingRate() {}
+ public static final String AUDIO_PARAM_SAMPLING_RATE_KEY = "audio-param-sampling-rate=";
+ }
+
+ /**
+ * @hide Defines the audio number of channels. This must be set before
+ * setAudioEncoder() or it will be ignored.
+ * This parameter is used with
+ * {@link MediaRecorder#setParameters(String)}.
+ */
+ public final class AudioParamChannels {
+ /* Do not change these values without updating their counterparts
+ * in include/media/mediarecorder.h!
+ */
+ private AudioParamChannels() {}
+ public static final String AUDIO_PARAM_NUMBER_OF_CHANNELS = "audio-param-number-of-channels=";
+ }
+
+ /**
+ * @hide Defines the audio encoding bitrate. This must be set before
+ * setAudioEncoder() or it will be ignored.
+ * This parameter is used with
+ * {@link MediaRecorder#setParameters(String)}.
+ */
+ public final class AudioParamEncodingBitrate{
+ private AudioParamEncodingBitrate() {}
+ public static final String AUDIO_PARAM_ENCODING_BITRATE = "audio-param-encoding-bitrate=";
+ }
+
/**
* Sets the audio source to be used for recording. If this method is not
* called, the output file will not contain an audio track. The source needs
@@ -332,6 +390,16 @@ public class MediaRecorder
throws IllegalStateException;
/**
+ * @hide Sets a parameter in the author engine.
+ *
+ * @param params the parameter to set.
+ * @see android.media.MediaRecorder.AudioParamSamplingRate
+ * @see android.media.MediaRecorder.AudioParamChannels
+ * @see android.media.MediaRecorder.AudioParamEncodingBitrate
+ */
+ public native void setParameters(String params);
+
+ /**
* Pass in the file descriptor of the file to be written. Call this after
* setOutputFormat() but before prepare().
*
@@ -448,7 +516,7 @@ public class MediaRecorder
{
/**
* Called when an error occurs while recording.
- *
+ *
* @param mr the MediaRecorder that encountered the error
* @param what the type of error that has occurred:
* <ul>
@@ -494,7 +562,7 @@ public class MediaRecorder
{
/**
* Called when an error occurs while recording.
- *
+ *
* @param mr the MediaRecorder that encountered the error
* @param what the type of error that has occurred:
* <ul>
diff --git a/media/jni/android_media_MediaRecorder.cpp b/media/jni/android_media_MediaRecorder.cpp
index 7561af1..7bfeb83 100644
--- a/media/jni/android_media_MediaRecorder.cpp
+++ b/media/jni/android_media_MediaRecorder.cpp
@@ -165,7 +165,7 @@ static void
android_media_MediaRecorder_setVideoSource(JNIEnv *env, jobject thiz, jint vs)
{
LOGV("setVideoSource(%d)", vs);
- if (vs < VIDEO_SOURCE_DEFAULT || vs > VIDEO_SOURCE_CAMERA) {
+ if (vs < VIDEO_SOURCE_DEFAULT || vs >= VIDEO_SOURCE_LIST_END) {
jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid video source");
return;
}
@@ -177,10 +177,11 @@ static void
android_media_MediaRecorder_setAudioSource(JNIEnv *env, jobject thiz, jint as)
{
LOGV("setAudioSource(%d)", as);
- if (as < AUDIO_SOURCE_DEFAULT || as > AUDIO_SOURCE_MAX) {
+ if (as < AUDIO_SOURCE_DEFAULT || as >= AUDIO_SOURCE_LIST_END) {
jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid audio source");
return;
}
+
sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
process_media_recorder_call(env, mr->setAudioSource(as), "java/lang/RuntimeException", "setAudioSource failed.");
}
@@ -201,7 +202,7 @@ static void
android_media_MediaRecorder_setVideoEncoder(JNIEnv *env, jobject thiz, jint ve)
{
LOGV("setVideoEncoder(%d)", ve);
- if (ve < VIDEO_ENCODER_DEFAULT || ve > VIDEO_ENCODER_MPEG_4_SP) {
+ if (ve < VIDEO_ENCODER_DEFAULT || ve >= VIDEO_ENCODER_LIST_END) {
jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid video encoder");
return;
}
@@ -213,7 +214,7 @@ static void
android_media_MediaRecorder_setAudioEncoder(JNIEnv *env, jobject thiz, jint ae)
{
LOGV("setAudioEncoder(%d)", ae);
- if (ae < AUDIO_ENCODER_DEFAULT || ae > AUDIO_ENCODER_AMR_NB) {
+ if (ae < AUDIO_ENCODER_DEFAULT || ae >= AUDIO_ENCODER_LIST_END) {
jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid audio encoder");
return;
}
@@ -222,6 +223,29 @@ android_media_MediaRecorder_setAudioEncoder(JNIEnv *env, jobject thiz, jint ae)
}
static void
+android_media_MediaRecorder_setParameters(JNIEnv *env, jobject thiz, jstring params)
+{
+ LOGV("setParameters()");
+ if (params == NULL)
+ {
+ LOGE("Invalid or empty params string. This parameter will be ignored.");
+ return;
+ }
+
+ sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
+
+ const char* params8 = env->GetStringUTFChars(params, NULL);
+ if (params8 == NULL)
+ {
+ LOGE("Failed to covert jstring to String8. This parameter will be ignored.");
+ return;
+ }
+
+ process_media_recorder_call(env, mr->setParameters(String8(params8)), "java/lang/RuntimeException", "setParameter failed.");
+ env->ReleaseStringUTFChars(params,params8);
+}
+
+static void
android_media_MediaRecorder_setOutputFileFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length)
{
LOGV("setOutputFile");
@@ -384,6 +408,7 @@ static JNINativeMethod gMethods[] = {
{"setOutputFormat", "(I)V", (void *)android_media_MediaRecorder_setOutputFormat},
{"setVideoEncoder", "(I)V", (void *)android_media_MediaRecorder_setVideoEncoder},
{"setAudioEncoder", "(I)V", (void *)android_media_MediaRecorder_setAudioEncoder},
+ {"setParameters", "(Ljava/lang/String;)V", (void *)android_media_MediaRecorder_setParameters},
{"_setOutputFile", "(Ljava/io/FileDescriptor;JJ)V", (void *)android_media_MediaRecorder_setOutputFileFD},
{"setVideoSize", "(II)V", (void *)android_media_MediaRecorder_setVideoSize},
{"setVideoFrameRate", "(I)V", (void *)android_media_MediaRecorder_setVideoFrameRate},
diff --git a/media/libmedia/mediarecorder.cpp b/media/libmedia/mediarecorder.cpp
index 6b26faf..5093f0e 100644
--- a/media/libmedia/mediarecorder.cpp
+++ b/media/libmedia/mediarecorder.cpp
@@ -180,7 +180,7 @@ status_t MediaRecorder::setOutputFormat(int of)
LOGE("setOutputFormat called in an invalid state: %d", mCurrentState);
return INVALID_OPERATION;
}
- if (mIsVideoSourceSet && of >= OUTPUT_FORMAT_RAW_AMR) {
+ if (mIsVideoSourceSet && of >= OUTPUT_FORMAT_AUDIO_ONLY_START) { //first non-video output format
LOGE("output format (%d) is meant for audio recording only and incompatible with video recording", of);
return INVALID_OPERATION;
}
@@ -345,7 +345,7 @@ status_t MediaRecorder::setVideoFrameRate(int frames_per_second)
}
if (!mIsVideoSourceSet) {
LOGE("try to set video frame rate without setting video source first");
- return INVALID_OPERATION;
+ return INVALID_OPERATION;
}
status_t ret = mMediaRecorder->setVideoFrameRate(frames_per_second);
@@ -475,7 +475,7 @@ status_t MediaRecorder::stop()
mCurrentState = MEDIA_RECORDER_ERROR;
return ret;
}
-
+
// FIXME:
// stop and reset are semantically different.
// We treat them the same for now, and will change this in the future.
@@ -492,7 +492,7 @@ status_t MediaRecorder::reset()
LOGE("media recorder is not initialized yet");
return INVALID_OPERATION;
}
-
+
doCleanUp();
status_t ret = UNKNOWN_ERROR;
switch(mCurrentState) {