From 2bcda90c0234f67f210a96f195b355493ca7d1ff Mon Sep 17 00:00:00 2001 From: Jianhong Jiang Date: Mon, 8 Jun 2009 08:50:42 -0700 Subject: [PATCH] NJ-1409: (frameworks/base) Support new audio encoding types(AMR and AAC). --- include/media/mediarecorder.h | 38 +++++++++-- media/java/android/media/MediaRecorder.java | 76 +++++++++++++++++++-- media/jni/android_media_MediaRecorder.cpp | 33 +++++++-- media/libmedia/mediarecorder.cpp | 8 +-- 4 files changed, 136 insertions(+), 19 deletions(-) diff --git a/include/media/mediarecorder.h b/include/media/mediarecorder.h index aebe1918ca667..9b54ca9a32823 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 44f21c885e47d..be4b489eb0868 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 @@ -331,6 +389,16 @@ public class MediaRecorder public native void setVideoEncoder(int video_encoder) 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: *