OSDN Git Service

Camera app update due to CameraProfile and CamcorderProfile API changes
authorJames Dong <jdong@google.com>
Wed, 31 Mar 2010 21:39:23 +0000 (14:39 -0700)
committerJames Dong <jdong@google.com>
Thu, 1 Apr 2010 06:07:35 +0000 (23:07 -0700)
Also, make the quality level mapping from String to numeric number less
fragile.

Dependency: https://android-git.corp.google.com/g/#change,47310

bug - 2553862

Change-Id: I50606a16bd9d377f5002bc784a9dcc7b9f8c1486

src/com/android/camera/Camera.java
src/com/android/camera/CameraSettings.java
src/com/android/camera/VideoCamera.java

index 74d4547..b4e5517 100644 (file)
@@ -85,6 +85,7 @@ import java.util.ArrayList;
 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,
@@ -1764,7 +1765,7 @@ 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.
@@ -2129,22 +2130,6 @@ public class Camera extends NoSearchActivity implements View.OnClickListener,
         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,
@@ -2212,3 +2197,31 @@ class FocusRectangle extends View {
         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());
+    }
+}
index d80ac0b..9641def 100644 (file)
@@ -61,7 +61,7 @@ public class CameraSettings {
     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
 
index 548f8ae..21430b6 100644 (file)
@@ -521,13 +521,13 @@ public class VideoCamera extends NoSearchActivity
                     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
@@ -877,7 +877,7 @@ public class VideoCamera extends NoSearchActivity
         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.
@@ -894,19 +894,6 @@ public class VideoCamera extends NoSearchActivity
             }
         }
 
-        // 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.
@@ -1353,8 +1340,8 @@ public class VideoCamera extends NoSearchActivity
     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(
@@ -1415,8 +1402,8 @@ public class VideoCamera extends NoSearchActivity
     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();