import java.util.Collections;
import java.util.Date;
import java.util.List;
+import java.util.HashMap;
/** The Camera activity which can preview and take pictures. */
public class Camera extends NoSearchActivity implements View.OnClickListener,
String jpegQuality = mPreferences.getString(
CameraSettings.KEY_JPEG_QUALITY,
getString(R.string.pref_camera_jpegquality_default));
- mParameters.setJpegQuality(getQualityNumber(jpegQuality));
+ mParameters.setJpegQuality(JpegEncodingQualityMappings.getQualityNumber(jpegQuality));
// For the following settings, we need to check if the settings are
// still supported by latest driver, if not, ignore the settings.
mHandler.sendEmptyMessageDelayed(CLEAR_SCREEN_DELAY, SCREEN_DELAY);
}
- private static String[] mQualityStrings = {"superfine", "fine", "normal"};
- private static int[] mQualityNumbers = CameraProfile.getImageEncodingQualityLevels();
- private static int DEFAULT_QUALITY = 85;
-
- // Translate from a quality string to a quality number using the system
- // properties.
- private static int getQualityNumber(String jpegQuality) {
- // Find the index of the input string
- int index = Util.indexOf(mQualityStrings, jpegQuality);
-
- if (index == -1 || index > mQualityNumbers.length - 1) {
- return DEFAULT_QUALITY;
- }
- return mQualityNumbers[index];
- }
-
private class MyHeadUpDisplayListener implements HeadUpDisplay.Listener {
// The callback functions here will be called from the GLThread. So,
setBackgroundDrawable(null);
}
}
+
+/*
+ * Provide a mapping for Jpeg encoding quality levels
+ * from String representation to numeric representation.
+ */
+class JpegEncodingQualityMappings {
+ private static final String TAG = "JpegEncodingQualityMappings";
+ private static final int DEFAULT_QUALITY = 85;
+ private static HashMap<String, Integer> mHashMap =
+ new HashMap<String, Integer>();
+
+ static {
+ mHashMap.put("normal", CameraProfile.QUALITY_LOW);
+ mHashMap.put("fine", CameraProfile.QUALITY_MEDIUM);
+ mHashMap.put("superfine", CameraProfile.QUALITY_HIGH);
+ };
+
+ // Retrieve and return the Jpeg encoding quality number
+ // for the given quality level.
+ public static int getQualityNumber(String jpegQuality) {
+ Integer quality = mHashMap.get(jpegQuality);
+ if (quality == null) {
+ Log.w(TAG, "Unknown Jpeg quality: " + jpegQuality);
+ return DEFAULT_QUALITY;
+ }
+ return CameraProfile.getJpegEncodingQualityParameter(quality.intValue());
+ }
+}
public static final int CURRENT_VERSION = 4;
// max video duration in seconds for mms and youtube.
- private static final int MMS_VIDEO_DURATION = CamcorderProfile.getMmsRecordingDurationInSeconds();
+ private static final int MMS_VIDEO_DURATION = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW).duration;
private static final int YOUTUBE_VIDEO_DURATION = 10 * 60; // 10 mins
private static final int DEFAULT_VIDEO_DURATION = 30 * 60; // 10 mins
CameraSettings.getVidoeDurationInMillis(quality);
}
mProfile = CamcorderProfile.get(videoQualityHigh
- ? CamcorderProfile.Quality.HIGH
- : CamcorderProfile.Quality.LOW);
+ ? CamcorderProfile.QUALITY_HIGH
+ : CamcorderProfile.QUALITY_LOW);
}
private void resizeForPreviewAspectRatio() {
mPreviewFrameLayout.setAspectRatio(
- (double) mProfile.mVideoFrameWidth / mProfile.mVideoFrameHeight);
+ (double) mProfile.videoFrameWidth / mProfile.videoFrameHeight);
}
@Override
mMediaRecorder.setCamera(mCameraDevice);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
- mMediaRecorder.setOutputFormat(mProfile.mFileFormat);
+ mMediaRecorder.setProfile(mProfile);
mMediaRecorder.setMaxDuration(mMaxVideoDurationInMs);
// Set output file.
}
}
- // Use the same frame rate for both, since internally
- // if the frame rate is too large, it can cause camera to become
- // unstable. We need to fix the MediaRecorder to disable the support
- // of setting frame rate for now.
- mMediaRecorder.setVideoFrameRate(mProfile.mVideoFrameRate);
- mMediaRecorder.setVideoSize(
- mProfile.mVideoFrameWidth, mProfile.mVideoFrameHeight);
- mMediaRecorder.setVideoEncodingBitRate(mProfile.mVideoBitRate);
- mMediaRecorder.setAudioEncodingBitRate(mProfile.mAudioBitRate);
- mMediaRecorder.setAudioChannels(mProfile.mAudioChannels);
- mMediaRecorder.setAudioSamplingRate(mProfile.mAudioSampleRate);
- mMediaRecorder.setVideoEncoder(mProfile.mVideoCodec);
- mMediaRecorder.setAudioEncoder(mProfile.mAudioCodec);
mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
// Set maximum file size.
private void setCameraParameters() {
mParameters = mCameraDevice.getParameters();
- mParameters.setPreviewSize(mProfile.mVideoFrameWidth, mProfile.mVideoFrameHeight);
- mParameters.setPreviewFrameRate(mProfile.mVideoFrameRate);
+ mParameters.setPreviewSize(mProfile.videoFrameWidth, mProfile.videoFrameHeight);
+ mParameters.setPreviewFrameRate(mProfile.videoFrameRate);
// Set flash mode.
String flashMode = mPreferences.getString(
private void resetCameraParameters() {
// We need to restart the preview if preview size is changed.
Size size = mParameters.getPreviewSize();
- if (size.width != mProfile.mVideoFrameWidth
- || size.height != mProfile.mVideoFrameHeight) {
+ if (size.width != mProfile.videoFrameWidth
+ || size.height != mProfile.videoFrameHeight) {
// It is assumed media recorder is released before
// onSharedPreferenceChanged, so we can close the camera here.
closeCamera();