diff --git a/api/current.xml b/api/current.xml
index 34a0e00befe1e..53f5178c78f61 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -82509,163 +82509,151 @@
deprecated="not deprecated"
visibility="public"
>
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
Each profile specifies the following set of parameters:
*
- * - The file output format, @see android.media.MediaRecorder.OutputFormat
- *
- Video codec format, @see android.media.MediaRecorder.VideoEncoder
+ *
- The file output format
+ *
- Video codec format
*
- Video bit rate in bits per second
*
- Video frame rate in frames per second
*
- Video frame width and height,
- *
- Audio codec format, @see android.media.MediaRecorder.AudioEncoder
+ *
- Audio codec format
*
- Audio bit rate in bits per second,
*
- Audio sample rate
*
- Number of audio channels for recording.
@@ -37,98 +39,95 @@ package android.media;
*/
public class CamcorderProfile
{
- private final int mDuration; // Recording duration in seconds
-
/**
- * The Quality class represents the quality level of each CamcorderProfile.
+ * The output from camcorder recording sessions can have different quality levels.
*
- * The output from recording sessions with high quality level usually may have
- * larger output bit rate, better video and/or audio recording quality, and
- * laerger video frame resolution and higher audio sampling rate, etc, than those
- * with low quality level.
+ * Currently, we define two quality levels: high quality and low quality.
+ * A camcorder recording session with high quality level usually has higher output bit
+ * rate, better video and/or audio recording quality, larger video frame
+ * resolution and higher audio sampling rate, etc, than those with low quality
+ * level.
+ *
+ * Do not change these values/ordinals without updating their counterpart
+ * in include/media/MediaProfiles.h!
*/
- public enum Quality {
- /* Do not change these values/ordinals without updating their counterpart
- * in include/media/MediaProfiles.h!
- */
- HIGH,
- LOW
- };
+ public static final int QUALITY_LOW = 0;
+ public static final int QUALITY_HIGH = 1;
/**
- * Returns the recording duration in seconds for LOW quality CamcorderProfile
- * used by the MMS application.
+ * Default recording duration in seconds before the session is terminated.
+ * This is useful for applications like MMS has limited file size requirement.
*/
- public static final int getMmsRecordingDurationInSeconds() {
- return get(Quality.LOW).mDuration;
- }
+ public int duration;
/**
* The quality level of the camcorder profile
- * @see android.media.CamcorderProfile.Quality
*/
- public final Quality mQuality;
+ public int quality;
/**
* The file output format of the camcorder profile
* @see android.media.MediaRecorder.OutputFormat
*/
- public final int mFileFormat;
+ public int fileFormat;
/**
* The video encoder being used for the video track
* @see android.media.MediaRecorder.VideoEncoder
*/
- public final int mVideoCodec;
+ public int videoCodec;
/**
* The target video output bit rate in bits per second
*/
- public final int mVideoBitRate;
+ public int videoBitRate;
/**
* The target video frame rate in frames per second
*/
- public final int mVideoFrameRate;
+ public int videoFrameRate;
/**
* The target video frame width in pixels
*/
- public final int mVideoFrameWidth;
+ public int videoFrameWidth;
/**
* The target video frame height in pixels
*/
- public final int mVideoFrameHeight;
+ public int videoFrameHeight;
/**
* The audio encoder being used for the audio track.
* @see android.media.MediaRecorder.AudioEncoder
*/
- public final int mAudioCodec;
+ public int audioCodec;
/**
* The target audio output bit rate in bits per second
*/
- public final int mAudioBitRate;
+ public int audioBitRate;
/**
* The audio sampling rate used for the audio track
*/
- public final int mAudioSampleRate;
+ public int audioSampleRate;
/**
* The number of audio channels used for the audio track
*/
- public final int mAudioChannels;
+ public int audioChannels;
/**
- * Returns the camcorder profile for the given quality.
+ * Returns the camcorder profile for the given quality level.
* @param quality the target quality level for the camcorder profile
- * @see android.media.CamcorderProfile.Quality
*/
- public static CamcorderProfile get(Quality quality) {
- return native_get_camcorder_profile(quality.ordinal());
+ public static CamcorderProfile get(int quality) {
+ if (quality < QUALITY_LOW || quality > QUALITY_HIGH) {
+ String errMessage = "Unsupported quality level: " + quality;
+ throw new IllegalArgumentException(errMessage);
+ }
+ return native_get_camcorder_profile(quality);
}
static {
@@ -150,18 +149,18 @@ public class CamcorderProfile
int audioSampleRate,
int audioChannels) {
- mDuration = duration;
- mQuality = Quality.values()[quality];
- mFileFormat = fileFormat;
- mVideoCodec = videoCodec;
- mVideoBitRate = videoBitRate;
- mVideoFrameRate = videoFrameRate;
- mVideoFrameWidth = videoWidth;
- mVideoFrameHeight = videoHeight;
- mAudioCodec = audioCodec;
- mAudioBitRate = audioBitRate;
- mAudioSampleRate = audioSampleRate;
- mAudioChannels = audioChannels;
+ this.duration = duration;
+ this.quality = quality;
+ this.fileFormat = fileFormat;
+ this.videoCodec = videoCodec;
+ this.videoBitRate = videoBitRate;
+ this.videoFrameRate = videoFrameRate;
+ this.videoFrameWidth = videoWidth;
+ this.videoFrameHeight = videoHeight;
+ this.audioCodec = audioCodec;
+ this.audioBitRate = audioBitRate;
+ this.audioSampleRate = audioSampleRate;
+ this.audioChannels = audioChannels;
}
// Methods implemented by JNI
diff --git a/media/java/android/media/CameraProfile.java b/media/java/android/media/CameraProfile.java
index f1616ccdfc1e3..f8d393512502d 100644
--- a/media/java/android/media/CameraProfile.java
+++ b/media/java/android/media/CameraProfile.java
@@ -16,6 +16,8 @@
package android.media;
+import java.util.Arrays;
+
/**
* The CameraProfile class is used to retrieve the pre-defined still image
* capture (jpeg) quality levels (0-100) used for low, medium, and high
@@ -25,23 +27,52 @@ package android.media;
public class CameraProfile
{
/**
- * Returns a list of the pre-defined still image capture (jpeg) quality levels
- * used for low, medium and high quality settings in the Camera application.
+ * Define three quality levels for JPEG image encoding.
*/
- public static int[] getImageEncodingQualityLevels() {
- int nLevels = native_get_num_image_encoding_quality_levels();
- if (nLevels == 0) return null;
+ /*
+ * Don't change the values for these constants unless getImageEncodingQualityLevels()
+ * method is also changed accordingly.
+ */
+ public static final int QUALITY_LOW = 0;
+ public static final int QUALITY_MEDIUM = 1;
+ public static final int QUALITY_HIGH = 2;
- int[] levels = new int[nLevels];
- for (int i = 0; i < nLevels; ++i) {
- levels[i] = native_get_image_encoding_quality_level(i);
+ /*
+ * Cache the Jpeg encoding quality parameters
+ */
+ private static final int[] sJpegEncodingQualityParameters;
+
+ /**
+ * Returns a pre-defined still image capture (jpeg) quality level
+ * used for the given quality level in the Camera application.
+ *
+ * @param quality The target quality level
+ */
+ public static int getJpegEncodingQualityParameter(int quality) {
+ if (quality < QUALITY_LOW || quality > QUALITY_HIGH) {
+ throw new IllegalArgumentException("Unsupported quality level: " + quality);
}
- return levels;
+ return sJpegEncodingQualityParameters[quality];
}
static {
System.loadLibrary("media_jni");
native_init();
+ sJpegEncodingQualityParameters = getImageEncodingQualityLevels();
+ }
+
+ private static int[] getImageEncodingQualityLevels() {
+ int nLevels = native_get_num_image_encoding_quality_levels();
+ if (nLevels != QUALITY_HIGH + 1) {
+ throw new RuntimeException("Unexpected Jpeg encoding quality levels " + nLevels);
+ }
+
+ int[] levels = new int[nLevels];
+ for (int i = 0; i < nLevels; ++i) {
+ levels[i] = native_get_image_encoding_quality_level(i);
+ }
+ Arrays.sort(levels); // Lower quality level ALWAYS comes before higher one
+ return levels;
}
// Methods implemented by JNI
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index 5988d342426c1..47a8cfc1c07b3 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -16,6 +16,7 @@
package android.media;
+import android.media.CamcorderProfile;
import android.hardware.Camera;
import android.os.Handler;
import android.os.Looper;
@@ -258,6 +259,25 @@ public class MediaRecorder
public native void setVideoSource(int video_source)
throws IllegalStateException;
+ /**
+ * Uses the settings from a CamcorderProfile object for recording. This method should
+ * be called after the video AND audio sources are set, and before setOutputFile().
+ *
+ * @param profile the CamcorderProfile to use
+ * @see android.media.CamcorderProfile
+ */
+ public void setProfile(CamcorderProfile profile) {
+ setOutputFormat(profile.fileFormat);
+ setVideoFrameRate(profile.videoFrameRate);
+ setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
+ setVideoEncodingBitRate(profile.videoBitRate);
+ setAudioEncodingBitRate(profile.audioBitRate);
+ setAudioChannels(profile.audioChannels);
+ setAudioSamplingRate(profile.audioSampleRate);
+ setVideoEncoder(profile.videoCodec);
+ setAudioEncoder(profile.audioCodec);
+ }
+
/**
* Sets the format of the output file produced during recording. Call this
* after setAudioSource()/setVideoSource() but before prepare().