Merge change 1548 into donut

* changes:
  NJ-1409: (frameworks/base) Support new audio encoding types(AMR and AAC).
This commit is contained in:
Android (Google) Code Review
2009-06-08 15:58:21 -07:00
4 changed files with 136 additions and 19 deletions

View File

@@ -30,7 +30,7 @@ class ICamera;
typedef void (*media_completion_f)(status_t status, void *cookie); typedef void (*media_completion_f)(status_t status, void *cookie);
/* Do not change these values without updating their counterparts /* 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 { enum audio_source {
AUDIO_SOURCE_DEFAULT = 0, AUDIO_SOURCE_DEFAULT = 0,
@@ -38,26 +38,47 @@ enum audio_source {
AUDIO_SOURCE_VOICE_UPLINK = 2, AUDIO_SOURCE_VOICE_UPLINK = 2,
AUDIO_SOURCE_VOICE_DOWNLINK = 3, AUDIO_SOURCE_VOICE_DOWNLINK = 3,
AUDIO_SOURCE_VOICE_CALL = 4, 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 { enum video_source {
VIDEO_SOURCE_DEFAULT = 0, VIDEO_SOURCE_DEFAULT = 0,
VIDEO_SOURCE_CAMERA = 1, 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 { enum output_format {
OUTPUT_FORMAT_DEFAULT = 0, OUTPUT_FORMAT_DEFAULT = 0,
OUTPUT_FORMAT_THREE_GPP, OUTPUT_FORMAT_THREE_GPP = 1,
OUTPUT_FORMAT_MPEG_4, OUTPUT_FORMAT_MPEG_4 = 2,
OUTPUT_FORMAT_RAW_AMR,
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 OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
}; };
enum audio_encoder { enum audio_encoder {
AUDIO_ENCODER_DEFAULT = 0, AUDIO_ENCODER_DEFAULT = 0,
AUDIO_ENCODER_AMR_NB = 1, 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 { enum video_encoder {
@@ -65,8 +86,11 @@ enum video_encoder {
VIDEO_ENCODER_H263 = 1, VIDEO_ENCODER_H263 = 1,
VIDEO_ENCODER_H264 = 2, VIDEO_ENCODER_H264 = 2,
VIDEO_ENCODER_MPEG_4_SP = 3, 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 // Maximum frames per second is 24
#define MEDIA_RECORDER_MAX_FRAME_RATE 24 #define MEDIA_RECORDER_MAX_FRAME_RATE 24

View File

@@ -164,8 +164,19 @@ public class MediaRecorder
public static final int THREE_GPP = 1; public static final int THREE_GPP = 1;
/** MPEG4 media file format*/ /** MPEG4 media file format*/
public static final int MPEG_4 = 2; 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; 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; public static final int DEFAULT = 0;
/** AMR (Narrowband) audio codec */ /** AMR (Narrowband) audio codec */
public static final int AMR_NB = 1; 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; 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 * 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 * called, the output file will not contain an audio track. The source needs
@@ -331,6 +389,16 @@ public class MediaRecorder
public native void setVideoEncoder(int video_encoder) public native void setVideoEncoder(int video_encoder)
throws IllegalStateException; 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 * Pass in the file descriptor of the file to be written. Call this after
* setOutputFormat() but before prepare(). * setOutputFormat() but before prepare().

View File

@@ -165,7 +165,7 @@ static void
android_media_MediaRecorder_setVideoSource(JNIEnv *env, jobject thiz, jint vs) android_media_MediaRecorder_setVideoSource(JNIEnv *env, jobject thiz, jint vs)
{ {
LOGV("setVideoSource(%d)", 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"); jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid video source");
return; return;
} }
@@ -177,10 +177,11 @@ static void
android_media_MediaRecorder_setAudioSource(JNIEnv *env, jobject thiz, jint as) android_media_MediaRecorder_setAudioSource(JNIEnv *env, jobject thiz, jint as)
{ {
LOGV("setAudioSource(%d)", 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"); jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid audio source");
return; return;
} }
sp<MediaRecorder> mr = getMediaRecorder(env, thiz); sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
process_media_recorder_call(env, mr->setAudioSource(as), "java/lang/RuntimeException", "setAudioSource failed."); 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) android_media_MediaRecorder_setVideoEncoder(JNIEnv *env, jobject thiz, jint ve)
{ {
LOGV("setVideoEncoder(%d)", 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"); jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid video encoder");
return; return;
} }
@@ -213,7 +214,7 @@ static void
android_media_MediaRecorder_setAudioEncoder(JNIEnv *env, jobject thiz, jint ae) android_media_MediaRecorder_setAudioEncoder(JNIEnv *env, jobject thiz, jint ae)
{ {
LOGV("setAudioEncoder(%d)", 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"); jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid audio encoder");
return; return;
} }
@@ -221,6 +222,29 @@ android_media_MediaRecorder_setAudioEncoder(JNIEnv *env, jobject thiz, jint ae)
process_media_recorder_call(env, mr->setAudioEncoder(ae), "java/lang/RuntimeException", "setAudioEncoder failed."); process_media_recorder_call(env, mr->setAudioEncoder(ae), "java/lang/RuntimeException", "setAudioEncoder failed.");
} }
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 static void
android_media_MediaRecorder_setOutputFileFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length) android_media_MediaRecorder_setOutputFileFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length)
{ {
@@ -384,6 +408,7 @@ static JNINativeMethod gMethods[] = {
{"setOutputFormat", "(I)V", (void *)android_media_MediaRecorder_setOutputFormat}, {"setOutputFormat", "(I)V", (void *)android_media_MediaRecorder_setOutputFormat},
{"setVideoEncoder", "(I)V", (void *)android_media_MediaRecorder_setVideoEncoder}, {"setVideoEncoder", "(I)V", (void *)android_media_MediaRecorder_setVideoEncoder},
{"setAudioEncoder", "(I)V", (void *)android_media_MediaRecorder_setAudioEncoder}, {"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}, {"_setOutputFile", "(Ljava/io/FileDescriptor;JJ)V", (void *)android_media_MediaRecorder_setOutputFileFD},
{"setVideoSize", "(II)V", (void *)android_media_MediaRecorder_setVideoSize}, {"setVideoSize", "(II)V", (void *)android_media_MediaRecorder_setVideoSize},
{"setVideoFrameRate", "(I)V", (void *)android_media_MediaRecorder_setVideoFrameRate}, {"setVideoFrameRate", "(I)V", (void *)android_media_MediaRecorder_setVideoFrameRate},

View File

@@ -180,7 +180,7 @@ status_t MediaRecorder::setOutputFormat(int of)
LOGE("setOutputFormat called in an invalid state: %d", mCurrentState); LOGE("setOutputFormat called in an invalid state: %d", mCurrentState);
return INVALID_OPERATION; 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); LOGE("output format (%d) is meant for audio recording only and incompatible with video recording", of);
return INVALID_OPERATION; return INVALID_OPERATION;
} }