Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.camera; |
| 18 | |
| 19 | import android.annotation.TargetApi; |
| 20 | import android.app.Activity; |
| 21 | import android.content.ActivityNotFoundException; |
| 22 | import android.content.BroadcastReceiver; |
| 23 | import android.content.ContentResolver; |
| 24 | import android.content.ContentValues; |
| 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 28 | import android.graphics.Bitmap; |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 29 | import android.graphics.Point; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 30 | import android.graphics.SurfaceTexture; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 31 | import android.location.Location; |
Marco Nelissen | 20694b2 | 2013-10-29 15:27:24 -0700 | [diff] [blame] | 32 | import android.media.AudioManager; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 33 | import android.media.CamcorderProfile; |
| 34 | import android.media.CameraProfile; |
| 35 | import android.media.MediaRecorder; |
| 36 | import android.net.Uri; |
| 37 | import android.os.Build; |
| 38 | import android.os.Bundle; |
| 39 | import android.os.Handler; |
Spike Sprague | 3c3b31d | 2014-09-08 10:43:04 -0700 | [diff] [blame] | 40 | import android.os.Looper; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 41 | import android.os.Message; |
| 42 | import android.os.ParcelFileDescriptor; |
| 43 | import android.os.SystemClock; |
| 44 | import android.provider.MediaStore; |
Ruben Brunk | 1600796 | 2013-04-19 15:27:57 -0700 | [diff] [blame] | 45 | import android.provider.MediaStore.MediaColumns; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 46 | import android.provider.MediaStore.Video; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 47 | import android.view.KeyEvent; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 48 | import android.view.View; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 49 | import android.widget.Toast; |
| 50 | |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 51 | import com.android.camera.app.AppController; |
Spike Sprague | 39f8a76 | 2014-01-13 14:22:18 -0800 | [diff] [blame] | 52 | import com.android.camera.app.CameraAppUI; |
Kevin Gabayan | ffbc43c | 2013-12-09 11:41:50 -0800 | [diff] [blame] | 53 | import com.android.camera.app.LocationManager; |
Angus Kong | fd4fc0e | 2013-11-07 15:38:09 -0800 | [diff] [blame] | 54 | import com.android.camera.app.MediaSaver; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 55 | import com.android.camera.app.MemoryManager; |
| 56 | import com.android.camera.app.MemoryManager.MemoryListener; |
Senpo Hu | 0bdc4b5 | 2014-11-17 22:56:31 -0800 | [diff] [blame] | 57 | import com.android.camera.app.OrientationManager; |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame] | 58 | import com.android.camera.debug.Log; |
ztenghui | a16e7b5 | 2013-08-23 11:47:56 -0700 | [diff] [blame] | 59 | import com.android.camera.exif.ExifInterface; |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 60 | import com.android.camera.hardware.HardwareSpec; |
| 61 | import com.android.camera.hardware.HardwareSpecImpl; |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 62 | import com.android.camera.module.ModuleController; |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 63 | import com.android.camera.settings.Keys; |
Erin Dahlgren | bd3da26 | 2013-12-02 11:48:13 -0800 | [diff] [blame] | 64 | import com.android.camera.settings.SettingsManager; |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 65 | import com.android.camera.settings.SettingsUtil; |
Andy Huibers | b7c7d9a | 2014-06-18 22:26:14 -0700 | [diff] [blame] | 66 | import com.android.camera.ui.TouchCoordinate; |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 67 | import com.android.camera.util.ApiHelper; |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 68 | import com.android.camera.util.CameraUtil; |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 69 | import com.android.camera.util.UsageStatistics; |
| 70 | import com.android.camera2.R; |
Sol Boucher | 5a34496 | 2014-06-17 14:05:08 -0700 | [diff] [blame] | 71 | import com.android.ex.camera2.portability.CameraAgent; |
| 72 | import com.android.ex.camera2.portability.CameraAgent.CameraPictureCallback; |
| 73 | import com.android.ex.camera2.portability.CameraAgent.CameraProxy; |
Sascha Haeberling | f15d63e | 2014-07-21 11:31:13 -0700 | [diff] [blame] | 74 | import com.android.ex.camera2.portability.CameraCapabilities; |
Sol Boucher | 43e1813 | 2014-06-19 15:03:18 -0700 | [diff] [blame] | 75 | import com.android.ex.camera2.portability.CameraDeviceInfo.Characteristics; |
Sol Boucher | 5a34496 | 2014-06-17 14:05:08 -0700 | [diff] [blame] | 76 | import com.android.ex.camera2.portability.CameraSettings; |
| 77 | import com.android.ex.camera2.portability.Size; |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 78 | import com.google.common.logging.eventprotos; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 79 | |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 80 | import java.io.File; |
| 81 | import java.io.IOException; |
| 82 | import java.text.SimpleDateFormat; |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 83 | import java.util.ArrayList; |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 84 | import java.util.Date; |
| 85 | import java.util.Iterator; |
| 86 | import java.util.List; |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 87 | import java.util.Set; |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 88 | |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 89 | public class VideoModule extends CameraModule |
Senpo Hu | 0bdc4b5 | 2014-11-17 22:56:31 -0800 | [diff] [blame] | 90 | implements FocusOverlayManager.Listener, MediaRecorder.OnErrorListener, |
| 91 | MediaRecorder.OnInfoListener, MemoryListener, |
| 92 | OrientationManager.OnOrientationChangeListener, VideoController { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 93 | |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 94 | private static final String VIDEO_MODULE_STRING_ID = "VideoModule"; |
| 95 | |
| 96 | private static final Log.Tag TAG = new Log.Tag(VIDEO_MODULE_STRING_ID); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 97 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 98 | // Messages defined for the UI thread handler. |
| 99 | private static final int MSG_CHECK_DISPLAY_ROTATION = 4; |
| 100 | private static final int MSG_UPDATE_RECORD_TIME = 5; |
| 101 | private static final int MSG_ENABLE_SHUTTER_BUTTON = 6; |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 102 | private static final int MSG_SWITCH_CAMERA = 8; |
| 103 | private static final int MSG_SWITCH_CAMERA_START_ANIMATION = 9; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 104 | |
| 105 | private static final long SHUTTER_BUTTON_TIMEOUT = 500L; // 500ms |
| 106 | |
| 107 | /** |
| 108 | * An unpublished intent flag requesting to start recording straight away |
| 109 | * and return as soon as recording is stopped. |
| 110 | * TODO: consider publishing by moving into MediaStore. |
| 111 | */ |
| 112 | private static final String EXTRA_QUICK_CAPTURE = |
| 113 | "android.intent.extra.quickCapture"; |
| 114 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 115 | // module fields |
| 116 | private CameraActivity mActivity; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 117 | private boolean mPaused; |
Spike Sprague | 51c877c | 2014-02-18 11:14:12 -0800 | [diff] [blame] | 118 | |
| 119 | // if, during and intent capture, the activity is paused (e.g. when app switching or reviewing a |
| 120 | // shot video), we don't want the bottom bar intent ui to reset to the capture button |
| 121 | private boolean mDontResetIntentUiOnResume; |
| 122 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 123 | private int mCameraId; |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 124 | private CameraSettings mCameraSettings; |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 125 | private CameraCapabilities mCameraCapabilities; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 126 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 127 | private boolean mIsInReviewMode; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 128 | private boolean mSnapshotInProgress = false; |
| 129 | |
Angus Kong | 395ee2d | 2013-07-15 12:42:41 -0700 | [diff] [blame] | 130 | // Preference must be read before starting preview. We check this before starting |
| 131 | // preview. |
| 132 | private boolean mPreferenceRead; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 133 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 134 | private boolean mIsVideoCaptureIntent; |
| 135 | private boolean mQuickCapture; |
| 136 | |
| 137 | private MediaRecorder mMediaRecorder; |
Sascha Haeberling | 92217bd | 2014-12-11 12:20:43 -0800 | [diff] [blame] | 138 | /** Manager used to mute sounds and vibrations during video recording. */ |
| 139 | private AudioManager mAudioManager; |
| 140 | /* |
| 141 | * The ringer mode that was set when video recording started. We use this to |
| 142 | * reset the mode once video recording has stopped. |
| 143 | */ |
| 144 | private int mOriginalRingerMode; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 145 | |
| 146 | private boolean mSwitchingCamera; |
| 147 | private boolean mMediaRecorderRecording = false; |
| 148 | private long mRecordingStartTime; |
| 149 | private boolean mRecordingTimeCountsDown = false; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 150 | private long mOnResumeTime; |
| 151 | // The video file that the hardware camera is about to record into |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 152 | // (or is recording into. |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 153 | private String mVideoFilename; |
| 154 | private ParcelFileDescriptor mVideoFileDescriptor; |
| 155 | |
| 156 | // The video file that has already been recorded, and that is being |
| 157 | // examined by the user. |
| 158 | private String mCurrentVideoFilename; |
| 159 | private Uri mCurrentVideoUri; |
ztenghui | 70bd024 | 2013-10-14 11:15:44 -0700 | [diff] [blame] | 160 | private boolean mCurrentVideoUriFromMediaSaved; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 161 | private ContentValues mCurrentVideoValues; |
| 162 | |
| 163 | private CamcorderProfile mProfile; |
| 164 | |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 165 | // The video duration limit. 0 means no limit. |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 166 | private int mMaxVideoDurationInMs; |
| 167 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 168 | boolean mPreviewing = false; // True if preview is started. |
| 169 | // The display rotation in degrees. This is only valid when mPreviewing is |
| 170 | // true. |
| 171 | private int mDisplayRotation; |
| 172 | private int mCameraDisplayOrientation; |
Doris Liu | 2b906b8 | 2013-12-10 16:34:08 -0800 | [diff] [blame] | 173 | private AppController mAppController; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 174 | |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 175 | private int mDesiredPreviewWidth; |
| 176 | private int mDesiredPreviewHeight; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 177 | private ContentResolver mContentResolver; |
| 178 | |
| 179 | private LocationManager mLocationManager; |
| 180 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 181 | private int mPendingSwitchCameraId; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 182 | private final Handler mHandler = new MainHandler(); |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 183 | private VideoUI mUI; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 184 | private CameraProxy mCameraDevice; |
| 185 | |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 186 | private float mZoomValue; // The current zoom ratio. |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 187 | |
Angus Kong | fd4fc0e | 2013-11-07 15:38:09 -0800 | [diff] [blame] | 188 | private final MediaSaver.OnMediaSavedListener mOnVideoSavedListener = |
| 189 | new MediaSaver.OnMediaSavedListener() { |
Angus Kong | 83a99ae | 2013-04-17 15:37:07 -0700 | [diff] [blame] | 190 | @Override |
| 191 | public void onMediaSaved(Uri uri) { |
| 192 | if (uri != null) { |
Doris Liu | 2a7f44c | 2013-08-12 15:18:53 -0700 | [diff] [blame] | 193 | mCurrentVideoUri = uri; |
ztenghui | 70bd024 | 2013-10-14 11:15:44 -0700 | [diff] [blame] | 194 | mCurrentVideoUriFromMediaSaved = true; |
Doris Liu | 2a7f44c | 2013-08-12 15:18:53 -0700 | [diff] [blame] | 195 | onVideoSaved(); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 196 | mActivity.notifyNewMedia(uri); |
Angus Kong | 83a99ae | 2013-04-17 15:37:07 -0700 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | }; |
| 200 | |
Angus Kong | fd4fc0e | 2013-11-07 15:38:09 -0800 | [diff] [blame] | 201 | private final MediaSaver.OnMediaSavedListener mOnPhotoSavedListener = |
| 202 | new MediaSaver.OnMediaSavedListener() { |
Angus Kong | 86d3631 | 2013-01-31 18:22:44 -0800 | [diff] [blame] | 203 | @Override |
| 204 | public void onMediaSaved(Uri uri) { |
| 205 | if (uri != null) { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 206 | mActivity.notifyNewMedia(uri); |
Angus Kong | 86d3631 | 2013-01-31 18:22:44 -0800 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | }; |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 210 | private FocusOverlayManager mFocusManager; |
| 211 | private boolean mMirror; |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 212 | private boolean mFocusAreaSupported; |
| 213 | private boolean mMeteringAreaSupported; |
| 214 | |
Sol Boucher | 5a34496 | 2014-06-17 14:05:08 -0700 | [diff] [blame] | 215 | private final CameraAgent.CameraAFCallback mAutoFocusCallback = |
| 216 | new CameraAgent.CameraAFCallback() { |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 217 | @Override |
| 218 | public void onAutoFocus(boolean focused, CameraProxy camera) { |
| 219 | if (mPaused) { |
| 220 | return; |
| 221 | } |
| 222 | mFocusManager.onAutoFocus(focused, false); |
| 223 | } |
| 224 | }; |
| 225 | |
| 226 | private final Object mAutoFocusMoveCallback = |
| 227 | ApiHelper.HAS_AUTO_FOCUS_MOVE_CALLBACK |
Sol Boucher | 5a34496 | 2014-06-17 14:05:08 -0700 | [diff] [blame] | 228 | ? new CameraAgent.CameraAFMoveCallback() { |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 229 | @Override |
| 230 | public void onAutoFocusMoving(boolean moving, CameraProxy camera) { |
Andy Huibers | c0fe0b6 | 2014-08-25 22:25:49 -0700 | [diff] [blame] | 231 | // mFocusManager.onAutoFocusMoving(moving) not called because UI |
| 232 | // not compatible with vertical video hint UI. |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 233 | } |
| 234 | } : null; |
Angus Kong | 86d3631 | 2013-01-31 18:22:44 -0800 | [diff] [blame] | 235 | |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 236 | /** |
| 237 | * This Handler is used to post message back onto the main thread of the |
| 238 | * application. |
| 239 | */ |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 240 | private class MainHandler extends Handler { |
| 241 | @Override |
| 242 | public void handleMessage(Message msg) { |
| 243 | switch (msg.what) { |
| 244 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 245 | case MSG_ENABLE_SHUTTER_BUTTON: |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 246 | mAppController.setShutterEnabled(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 247 | break; |
| 248 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 249 | case MSG_UPDATE_RECORD_TIME: { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 250 | updateRecordingTime(); |
| 251 | break; |
| 252 | } |
| 253 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 254 | case MSG_CHECK_DISPLAY_ROTATION: { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 255 | // Restart the preview if display rotation has changed. |
| 256 | // Sometimes this happens when the device is held upside |
| 257 | // down and camera app is opened. Rotation animation will |
| 258 | // take some time and the rotation value we have got may be |
| 259 | // wrong. Framework does not have a callback for this now. |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 260 | if ((CameraUtil.getDisplayRotation(mActivity) != mDisplayRotation) |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 261 | && !mMediaRecorderRecording && !mSwitchingCamera) { |
| 262 | startPreview(); |
| 263 | } |
| 264 | if (SystemClock.uptimeMillis() - mOnResumeTime < 5000) { |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 265 | mHandler.sendEmptyMessageDelayed(MSG_CHECK_DISPLAY_ROTATION, 100); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 266 | } |
| 267 | break; |
| 268 | } |
| 269 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 270 | case MSG_SWITCH_CAMERA: { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 271 | switchCamera(); |
| 272 | break; |
| 273 | } |
| 274 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 275 | case MSG_SWITCH_CAMERA_START_ANIMATION: { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 276 | //TODO: |
| 277 | //((CameraScreenNail) mActivity.mCameraScreenNail).animateSwitchCamera(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 278 | |
| 279 | // Enable all camera controls. |
| 280 | mSwitchingCamera = false; |
| 281 | break; |
| 282 | } |
| 283 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 284 | default: |
| 285 | Log.v(TAG, "Unhandled message: " + msg.what); |
| 286 | break; |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | private BroadcastReceiver mReceiver = null; |
| 292 | |
| 293 | private class MyBroadcastReceiver extends BroadcastReceiver { |
| 294 | @Override |
| 295 | public void onReceive(Context context, Intent intent) { |
| 296 | String action = intent.getAction(); |
| 297 | if (action.equals(Intent.ACTION_MEDIA_EJECT)) { |
| 298 | stopVideoRecording(); |
| 299 | } else if (action.equals(Intent.ACTION_MEDIA_SCANNER_STARTED)) { |
| 300 | Toast.makeText(mActivity, |
| 301 | mActivity.getResources().getString(R.string.wait), Toast.LENGTH_LONG).show(); |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
Spike Sprague | 41f6800 | 2014-01-24 16:59:25 -0800 | [diff] [blame] | 306 | private int mShutterIconId; |
| 307 | |
| 308 | |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 309 | /** |
| 310 | * Construct a new video module. |
| 311 | */ |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 312 | public VideoModule(AppController app) { |
| 313 | super(app); |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Spike Sprague | 159e6e9 | 2014-05-27 18:26:30 -0700 | [diff] [blame] | 316 | @Override |
| 317 | public String getPeekAccessibilityString() { |
| 318 | return mAppController.getAndroidContext() |
| 319 | .getResources().getString(R.string.video_accessibility_peek); |
| 320 | } |
| 321 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 322 | private String createName(long dateTaken) { |
| 323 | Date date = new Date(dateTaken); |
| 324 | SimpleDateFormat dateFormat = new SimpleDateFormat( |
| 325 | mActivity.getString(R.string.video_file_name_format)); |
| 326 | |
| 327 | return dateFormat.format(date); |
| 328 | } |
| 329 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 330 | @Override |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 331 | public String getModuleStringIdentifier() { |
| 332 | return VIDEO_MODULE_STRING_ID; |
| 333 | } |
| 334 | |
| 335 | @Override |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 336 | public void init(CameraActivity activity, boolean isSecureCamera, boolean isCaptureIntent) { |
| 337 | mActivity = activity; |
| 338 | // TODO: Need to look at the controller interface to see if we can get |
| 339 | // rid of passing in the activity directly. |
| 340 | mAppController = mActivity; |
Sascha Haeberling | 92217bd | 2014-12-11 12:20:43 -0800 | [diff] [blame] | 341 | mAudioManager = (AudioManager) mActivity.getSystemService(Context.AUDIO_SERVICE); |
Spike Sprague | 3f67379 | 2014-04-14 16:16:27 -0700 | [diff] [blame] | 342 | |
Spike Sprague | 48a3806 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 343 | mActivity.updateStorageSpaceAndHint(null); |
Spike Sprague | 3f67379 | 2014-04-14 16:16:27 -0700 | [diff] [blame] | 344 | |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 345 | mUI = new VideoUI(mActivity, this, mActivity.getModuleLayoutRoot()); |
| 346 | mActivity.setPreviewStatusListener(mUI); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 347 | |
Erin Dahlgren | bd3da26 | 2013-12-02 11:48:13 -0800 | [diff] [blame] | 348 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 349 | mCameraId = settingsManager.getInteger(mAppController.getModuleScope(), |
| 350 | Keys.KEY_CAMERA_ID); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 351 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 352 | /* |
| 353 | * To reduce startup time, we start the preview in another thread. |
| 354 | * We make sure the preview is started at the end of onCreate. |
| 355 | */ |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 356 | requestCamera(mCameraId); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 357 | |
| 358 | mContentResolver = mActivity.getContentResolver(); |
| 359 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 360 | // Surface texture is from camera screen nail and startPreview needs it. |
| 361 | // This must be done before startPreview. |
| 362 | mIsVideoCaptureIntent = isVideoCaptureIntent(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 363 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 364 | mQuickCapture = mActivity.getIntent().getBooleanExtra(EXTRA_QUICK_CAPTURE, false); |
Erin Dahlgren | 21c21a6 | 2013-11-19 16:37:38 -0800 | [diff] [blame] | 365 | mLocationManager = mActivity.getLocationManager(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 366 | |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 367 | mUI.setOrientationIndicator(0, false); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 368 | setDisplayOrientation(); |
| 369 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 370 | mPendingSwitchCameraId = -1; |
Spike Sprague | 41f6800 | 2014-01-24 16:59:25 -0800 | [diff] [blame] | 371 | |
| 372 | mShutterIconId = CameraUtil.getCameraShutterIconId( |
| 373 | mAppController.getCurrentModuleIndex(), mAppController.getAndroidContext()); |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Erin Dahlgren | 4efa8b5 | 2013-12-17 18:31:35 -0800 | [diff] [blame] | 376 | @Override |
| 377 | public boolean isUsingBottomBar() { |
| 378 | return true; |
| 379 | } |
| 380 | |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 381 | private void initializeControlByIntent() { |
| 382 | if (isVideoCaptureIntent()) { |
Spike Sprague | 51c877c | 2014-02-18 11:14:12 -0800 | [diff] [blame] | 383 | if (!mDontResetIntentUiOnResume) { |
| 384 | mActivity.getCameraAppUI().transitionToIntentCaptureLayout(); |
| 385 | } |
| 386 | // reset the flag |
| 387 | mDontResetIntentUiOnResume = false; |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 391 | @Override |
| 392 | public void onSingleTapUp(View view, int x, int y) { |
Doris Liu | 057b21a | 2014-04-25 17:35:27 -0700 | [diff] [blame] | 393 | if (mPaused || mCameraDevice == null) { |
| 394 | return; |
| 395 | } |
| 396 | if (mMediaRecorderRecording) { |
| 397 | if (!mSnapshotInProgress) { |
| 398 | takeASnapshot(); |
| 399 | } |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 400 | return; |
| 401 | } |
| 402 | // Check if metering area or focus area is supported. |
| 403 | if (!mFocusAreaSupported && !mMeteringAreaSupported) { |
| 404 | return; |
| 405 | } |
| 406 | // Tap to focus. |
| 407 | mFocusManager.onSingleTapUp(x, y); |
Doris Liu | 3860574 | 2013-08-13 15:01:52 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | private void takeASnapshot() { |
Sascha Haeberling | a514b14 | 2013-08-13 16:10:01 -0700 | [diff] [blame] | 411 | // Only take snapshots if video snapshot is supported by device |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 412 | if(!mCameraCapabilities.supports(CameraCapabilities.Feature.VIDEO_SNAPSHOT)) { |
Doris Liu | 4683673 | 2014-04-29 18:15:55 -0700 | [diff] [blame] | 413 | Log.w(TAG, "Cannot take a video snapshot - not supported by hardware"); |
| 414 | return; |
| 415 | } |
| 416 | if (!mIsVideoCaptureIntent) { |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 417 | if (!mMediaRecorderRecording || mPaused || mSnapshotInProgress |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 418 | || !mAppController.isShutterEnabled() || mCameraDevice == null) { |
Doris Liu | 3860574 | 2013-08-13 15:01:52 -0700 | [diff] [blame] | 419 | return; |
| 420 | } |
| 421 | |
Doris Liu | 3860574 | 2013-08-13 15:01:52 -0700 | [diff] [blame] | 422 | Location loc = mLocationManager.getCurrentLocation(); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 423 | CameraUtil.setGpsParameters(mCameraSettings, loc); |
| 424 | mCameraDevice.applySettings(mCameraSettings); |
Doris Liu | 3860574 | 2013-08-13 15:01:52 -0700 | [diff] [blame] | 425 | |
Doris Liu | 057b21a | 2014-04-25 17:35:27 -0700 | [diff] [blame] | 426 | Log.i(TAG, "Video snapshot start"); |
Doris Liu | 3860574 | 2013-08-13 15:01:52 -0700 | [diff] [blame] | 427 | mCameraDevice.takePicture(mHandler, |
| 428 | null, null, null, new JpegPictureCallback(loc)); |
| 429 | showVideoSnapshotUI(true); |
| 430 | mSnapshotInProgress = true; |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 431 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 434 | private void updateAutoFocusMoveCallback() { |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 435 | if (mPaused || mCameraDevice == null) { |
Sascha Haeberling | 8793eff | 2014-01-15 16:33:59 -0800 | [diff] [blame] | 436 | return; |
| 437 | } |
| 438 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 439 | if (mCameraSettings.getCurrentFocusMode() == CameraCapabilities.FocusMode.CONTINUOUS_PICTURE) { |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 440 | mCameraDevice.setAutoFocusMoveCallback(mHandler, |
Sol Boucher | 5a34496 | 2014-06-17 14:05:08 -0700 | [diff] [blame] | 441 | (CameraAgent.CameraAFMoveCallback) mAutoFocusMoveCallback); |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 442 | } else { |
| 443 | mCameraDevice.setAutoFocusMoveCallback(null, null); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | /** |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 448 | * @return Whether the currently active camera is front-facing. |
| 449 | */ |
| 450 | private boolean isCameraFrontFacing() { |
Sol Boucher | 43e1813 | 2014-06-19 15:03:18 -0700 | [diff] [blame] | 451 | return mAppController.getCameraProvider().getCharacteristics(mCameraId) |
| 452 | .isFacingFront(); |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * @return Whether the currently active camera is back-facing. |
| 457 | */ |
| 458 | private boolean isCameraBackFacing() { |
| 459 | return mAppController.getCameraProvider().getCharacteristics(mCameraId) |
| 460 | .isFacingBack(); |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | /** |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 464 | * The focus manager gets initialized after camera is available. |
| 465 | */ |
| 466 | private void initializeFocusManager() { |
| 467 | // Create FocusManager object. startPreview needs it. |
| 468 | // if mFocusManager not null, reuse it |
| 469 | // otherwise create a new instance |
| 470 | if (mFocusManager != null) { |
| 471 | mFocusManager.removeMessages(); |
| 472 | } else { |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 473 | mMirror = isCameraFrontFacing(); |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 474 | String[] defaultFocusModesStrings = mActivity.getResources().getStringArray( |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 475 | R.array.pref_camera_focusmode_default_array); |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 476 | CameraCapabilities.Stringifier stringifier = mCameraCapabilities.getStringifier(); |
Sascha Haeberling | ee36c5f | 2014-07-29 17:05:43 -0700 | [diff] [blame] | 477 | ArrayList<CameraCapabilities.FocusMode> defaultFocusModes = |
| 478 | new ArrayList<CameraCapabilities.FocusMode>(); |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 479 | for (String modeString : defaultFocusModesStrings) { |
| 480 | CameraCapabilities.FocusMode mode = stringifier.focusModeFromString(modeString); |
| 481 | if (mode != null) { |
| 482 | defaultFocusModes.add(mode); |
| 483 | } |
| 484 | } |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 485 | mFocusManager = new FocusOverlayManager(mAppController, |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 486 | defaultFocusModes, mCameraCapabilities, this, mMirror, |
Paul Rohde | 987ee64 | 2014-12-05 12:17:15 -0800 | [diff] [blame] | 487 | mActivity.getMainLooper(), mUI.getFocusRing()); |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 488 | } |
| 489 | mAppController.addPreviewAreaSizeChangedListener(mFocusManager); |
| 490 | } |
| 491 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 492 | @Override |
Senpo Hu | 0bdc4b5 | 2014-11-17 22:56:31 -0800 | [diff] [blame] | 493 | public void onOrientationChanged(OrientationManager orientationManager, |
| 494 | OrientationManager.DeviceOrientation deviceOrientation) { |
| 495 | mUI.onOrientationChanged(orientationManager, deviceOrientation); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 496 | } |
| 497 | |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 498 | private final ButtonManager.ButtonCallback mFlashCallback = |
Erin Dahlgren | fce8a0b | 2013-12-12 17:36:32 -0800 | [diff] [blame] | 499 | new ButtonManager.ButtonCallback() { |
| 500 | @Override |
| 501 | public void onStateChanged(int state) { |
| 502 | // Update flash parameters. |
| 503 | enableTorchMode(true); |
| 504 | } |
| 505 | }; |
| 506 | |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 507 | private final ButtonManager.ButtonCallback mCameraCallback = |
Erin Dahlgren | 18e2ef6 | 2013-12-05 14:53:38 -0800 | [diff] [blame] | 508 | new ButtonManager.ButtonCallback() { |
| 509 | @Override |
| 510 | public void onStateChanged(int state) { |
Angus Kong | 97e282a | 2014-03-04 18:44:49 -0800 | [diff] [blame] | 511 | if (mPaused || mAppController.getCameraProvider().waitingForCamera()) { |
Erin Dahlgren | 18e2ef6 | 2013-12-05 14:53:38 -0800 | [diff] [blame] | 512 | return; |
| 513 | } |
| 514 | mPendingSwitchCameraId = state; |
| 515 | Log.d(TAG, "Start to copy texture."); |
| 516 | |
| 517 | // Disable all camera controls. |
| 518 | mSwitchingCamera = true; |
| 519 | switchCamera(); |
| 520 | } |
| 521 | }; |
| 522 | |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 523 | private final View.OnClickListener mCancelCallback = new View.OnClickListener() { |
| 524 | @Override |
| 525 | public void onClick(View v) { |
| 526 | onReviewCancelClicked(v); |
| 527 | } |
| 528 | }; |
| 529 | |
| 530 | private final View.OnClickListener mDoneCallback = new View.OnClickListener() { |
| 531 | @Override |
| 532 | public void onClick(View v) { |
| 533 | onReviewDoneClicked(v); |
| 534 | } |
| 535 | }; |
| 536 | private final View.OnClickListener mReviewCallback = new View.OnClickListener() { |
| 537 | @Override |
| 538 | public void onClick(View v) { |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 539 | onReviewPlayClicked(v); |
| 540 | } |
| 541 | }; |
| 542 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 543 | @Override |
Erin Dahlgren | 1ca516f | 2014-03-28 12:44:04 -0700 | [diff] [blame] | 544 | public void hardResetSettings(SettingsManager settingsManager) { |
| 545 | // VideoModule does not need to hard reset any settings. |
| 546 | } |
| 547 | |
| 548 | @Override |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 549 | public HardwareSpec getHardwareSpec() { |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 550 | return (mCameraSettings != null ? |
| 551 | new HardwareSpecImpl(getCameraProvider(), mCameraCapabilities) : null); |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | @Override |
| 555 | public CameraAppUI.BottomBarUISpec getBottomBarSpec() { |
| 556 | CameraAppUI.BottomBarUISpec bottomBarSpec = new CameraAppUI.BottomBarUISpec(); |
| 557 | |
| 558 | bottomBarSpec.enableCamera = true; |
| 559 | bottomBarSpec.cameraCallback = mCameraCallback; |
| 560 | bottomBarSpec.enableTorchFlash = true; |
| 561 | bottomBarSpec.flashCallback = mFlashCallback; |
| 562 | bottomBarSpec.hideHdr = true; |
Spike Sprague | ab3adde | 2014-03-10 12:19:08 -0700 | [diff] [blame] | 563 | bottomBarSpec.enableGridLines = true; |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 564 | |
| 565 | if (isVideoCaptureIntent()) { |
| 566 | bottomBarSpec.showCancel = true; |
| 567 | bottomBarSpec.cancelCallback = mCancelCallback; |
| 568 | bottomBarSpec.showDone = true; |
| 569 | bottomBarSpec.doneCallback = mDoneCallback; |
| 570 | bottomBarSpec.showReview = true; |
| 571 | bottomBarSpec.reviewCallback = mReviewCallback; |
| 572 | } |
| 573 | |
| 574 | return bottomBarSpec; |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | @Override |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 578 | public void onCameraAvailable(CameraProxy cameraProxy) { |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 579 | if (cameraProxy == null) { |
| 580 | Log.w(TAG, "onCameraAvailable returns a null CameraProxy object"); |
| 581 | return; |
| 582 | } |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 583 | mCameraDevice = cameraProxy; |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 584 | mCameraCapabilities = mCameraDevice.getCapabilities(); |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 585 | mCameraSettings = mCameraDevice.getSettings(); |
| 586 | mFocusAreaSupported = mCameraCapabilities.supports(CameraCapabilities.Feature.FOCUS_AREA); |
| 587 | mMeteringAreaSupported = |
| 588 | mCameraCapabilities.supports(CameraCapabilities.Feature.METERING_AREA); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 589 | readVideoPreferences(); |
I-Jong Lin | 4ed861a | 2014-10-10 16:34:34 -0700 | [diff] [blame] | 590 | updateDesiredPreviewSize(); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 591 | resizeForPreviewAspectRatio(); |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 592 | initializeFocusManager(); |
Doris Liu | 5dd85a1 | 2014-04-15 11:45:55 -0700 | [diff] [blame] | 593 | // TODO: Having focus overlay manager caching the parameters is prone to error, |
| 594 | // we should consider passing the parameters to focus overlay to ensure the |
| 595 | // parameters are up to date. |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 596 | mFocusManager.updateCapabilities(mCameraCapabilities); |
Doris Liu | 5a36754 | 2014-01-17 17:21:42 -0800 | [diff] [blame] | 597 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 598 | startPreview(); |
| 599 | initializeVideoSnapshot(); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 600 | mUI.initializeZoom(mCameraSettings, mCameraCapabilities); |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 601 | initializeControlByIntent(); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 602 | } |
| 603 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 604 | private void startPlayVideoActivity() { |
| 605 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 606 | intent.setDataAndType(mCurrentVideoUri, convertOutputFormatToMimeType(mProfile.fileFormat)); |
| 607 | try { |
Senpo Hu | be70731 | 2014-09-10 14:43:16 -0700 | [diff] [blame] | 608 | mActivity.launchActivityByIntent(intent); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 609 | } catch (ActivityNotFoundException ex) { |
| 610 | Log.e(TAG, "Couldn't view video " + mCurrentVideoUri, ex); |
| 611 | } |
| 612 | } |
| 613 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 614 | @Override |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 615 | public void onReviewPlayClicked(View v) { |
| 616 | startPlayVideoActivity(); |
| 617 | } |
| 618 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 619 | @Override |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 620 | public void onReviewDoneClicked(View v) { |
Doris Liu | 69ef5ea | 2013-05-07 13:48:10 -0700 | [diff] [blame] | 621 | mIsInReviewMode = false; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 622 | doReturnToCaller(true); |
| 623 | } |
| 624 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 625 | @Override |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 626 | public void onReviewCancelClicked(View v) { |
ztenghui | af3a197 | 2013-09-17 16:51:15 -0700 | [diff] [blame] | 627 | // TODO: It should be better to not even insert the URI at all before we |
| 628 | // confirm done in review, which means we need to handle temporary video |
| 629 | // files in a quite different way than we currently had. |
ztenghui | 70bd024 | 2013-10-14 11:15:44 -0700 | [diff] [blame] | 630 | // Make sure we don't delete the Uri sent from the video capture intent. |
| 631 | if (mCurrentVideoUriFromMediaSaved) { |
ztenghui | dfe5b15 | 2013-10-08 17:07:15 -0700 | [diff] [blame] | 632 | mContentResolver.delete(mCurrentVideoUri, null, null); |
| 633 | } |
ztenghui | 638bf9a | 2013-10-09 10:52:33 -0700 | [diff] [blame] | 634 | mIsInReviewMode = false; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 635 | doReturnToCaller(false); |
| 636 | } |
| 637 | |
Doris Liu | 69ef5ea | 2013-05-07 13:48:10 -0700 | [diff] [blame] | 638 | @Override |
| 639 | public boolean isInReviewMode() { |
| 640 | return mIsInReviewMode; |
| 641 | } |
| 642 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 643 | private void onStopVideoRecording() { |
Sascha Haeberling | 8793eff | 2014-01-15 16:33:59 -0800 | [diff] [blame] | 644 | mAppController.getCameraAppUI().setSwipeEnabled(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 645 | boolean recordFail = stopVideoRecording(); |
| 646 | if (mIsVideoCaptureIntent) { |
Doris Liu | 3973deb | 2013-08-21 13:42:22 -0700 | [diff] [blame] | 647 | if (mQuickCapture) { |
| 648 | doReturnToCaller(!recordFail); |
| 649 | } else if (!recordFail) { |
| 650 | showCaptureResult(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 651 | } |
| 652 | } else if (!recordFail){ |
| 653 | // Start capture animation. |
| 654 | if (!mPaused && ApiHelper.HAS_SURFACE_TEXTURE_RECORDING) { |
| 655 | // The capture animation is disabled on ICS because we use SurfaceView |
| 656 | // for preview during recording. When the recording is done, we switch |
| 657 | // back to use SurfaceTexture for preview and we need to stop then start |
| 658 | // the preview. This will cause the preview flicker since the preview |
| 659 | // will not be continuous for a short period of time. |
Senpo Hu | 427a915 | 2014-11-19 17:11:46 -0800 | [diff] [blame] | 660 | mAppController.startFlashAnimation(false); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | } |
| 664 | |
Doris Liu | 2a7f44c | 2013-08-12 15:18:53 -0700 | [diff] [blame] | 665 | public void onVideoSaved() { |
| 666 | if (mIsVideoCaptureIntent) { |
| 667 | showCaptureResult(); |
| 668 | } |
| 669 | } |
| 670 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 671 | public void onProtectiveCurtainClick(View v) { |
| 672 | // Consume clicks |
| 673 | } |
| 674 | |
| 675 | @Override |
| 676 | public void onShutterButtonClick() { |
Sascha Haeberling | 8793eff | 2014-01-15 16:33:59 -0800 | [diff] [blame] | 677 | if (mSwitchingCamera) { |
| 678 | return; |
| 679 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 680 | boolean stop = mMediaRecorderRecording; |
| 681 | |
| 682 | if (stop) { |
Spike Sprague | c19d97b | 2014-09-22 14:53:04 -0700 | [diff] [blame] | 683 | // CameraAppUI mishandles mode option enable/disable |
| 684 | // for video, override that |
| 685 | mAppController.getCameraAppUI().enableModeOptions(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 686 | onStopVideoRecording(); |
| 687 | } else { |
Spike Sprague | c19d97b | 2014-09-22 14:53:04 -0700 | [diff] [blame] | 688 | // CameraAppUI mishandles mode option enable/disable |
| 689 | // for video, override that |
| 690 | mAppController.getCameraAppUI().disableModeOptions(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 691 | startVideoRecording(); |
| 692 | } |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 693 | mAppController.setShutterEnabled(false); |
Senpo Hu | 36e045a | 2014-09-29 18:49:10 -0700 | [diff] [blame] | 694 | if (mCameraSettings != null) { |
| 695 | mFocusManager.onShutterUp(mCameraSettings.getCurrentFocusMode()); |
| 696 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 697 | |
| 698 | // Keep the shutter button disabled when in video capture intent |
| 699 | // mode and recording is stopped. It'll be re-enabled when |
| 700 | // re-take button is clicked. |
| 701 | if (!(mIsVideoCaptureIntent && stop)) { |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 702 | mHandler.sendEmptyMessageDelayed(MSG_ENABLE_SHUTTER_BUTTON, SHUTTER_BUTTON_TIMEOUT); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
| 706 | @Override |
Andy Huibers | b7c7d9a | 2014-06-18 22:26:14 -0700 | [diff] [blame] | 707 | public void onShutterCoordinate(TouchCoordinate coord) { |
| 708 | // Do nothing. |
| 709 | } |
| 710 | |
| 711 | @Override |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 712 | public void onShutterButtonFocus(boolean pressed) { |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 713 | // TODO: Remove this when old camera controls are removed from the UI. |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | private void readVideoPreferences() { |
| 717 | // The preference stores values from ListPreference and is thus string type for all values. |
| 718 | // We need to convert it to int manually. |
Erin Dahlgren | bd3da26 | 2013-12-02 11:48:13 -0800 | [diff] [blame] | 719 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 720 | String videoQualityKey = isCameraFrontFacing() ? Keys.KEY_VIDEO_QUALITY_FRONT |
| 721 | : Keys.KEY_VIDEO_QUALITY_BACK; |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 722 | String videoQuality = settingsManager |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 723 | .getString(SettingsManager.SCOPE_GLOBAL, videoQualityKey); |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 724 | int quality = SettingsUtil.getVideoQuality(videoQuality, mCameraId); |
| 725 | Log.d(TAG, "Selected video quality for '" + videoQuality + "' is " + quality); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 726 | |
| 727 | // Set video quality. |
| 728 | Intent intent = mActivity.getIntent(); |
| 729 | if (intent.hasExtra(MediaStore.EXTRA_VIDEO_QUALITY)) { |
| 730 | int extraVideoQuality = |
| 731 | intent.getIntExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); |
| 732 | if (extraVideoQuality > 0) { |
| 733 | quality = CamcorderProfile.QUALITY_HIGH; |
| 734 | } else { // 0 is mms. |
| 735 | quality = CamcorderProfile.QUALITY_LOW; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | // Set video duration limit. The limit is read from the preference, |
| 740 | // unless it is specified in the intent. |
| 741 | if (intent.hasExtra(MediaStore.EXTRA_DURATION_LIMIT)) { |
| 742 | int seconds = |
| 743 | intent.getIntExtra(MediaStore.EXTRA_DURATION_LIMIT, 0); |
| 744 | mMaxVideoDurationInMs = 1000 * seconds; |
| 745 | } else { |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 746 | mMaxVideoDurationInMs = SettingsUtil.getMaxVideoDuration(mActivity |
Sascha Haeberling | 4044ab7 | 2014-04-02 16:25:03 -0700 | [diff] [blame] | 747 | .getAndroidContext()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Andy Huibers | 329e101 | 2014-02-04 08:03:35 -0800 | [diff] [blame] | 750 | // If quality is not supported, request QUALITY_HIGH which is always supported. |
| 751 | if (CamcorderProfile.hasProfile(mCameraId, quality) == false) { |
| 752 | quality = CamcorderProfile.QUALITY_HIGH; |
| 753 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 754 | mProfile = CamcorderProfile.get(mCameraId, quality); |
Angus Kong | 395ee2d | 2013-07-15 12:42:41 -0700 | [diff] [blame] | 755 | mPreferenceRead = true; |
I-Jong Lin | 4ed861a | 2014-10-10 16:34:34 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /** |
| 759 | * Calculates and sets local class variables for Desired Preview sizes. |
| 760 | * This function should be called after every change in preview camera |
| 761 | * resolution and/or before the preview starts. Note that these values still |
| 762 | * need to be pushed to the CameraSettings to actually change the preview |
| 763 | * resolution. Does nothing when camera pointer is null. |
| 764 | */ |
| 765 | private void updateDesiredPreviewSize() { |
ztenghui | ef01a31 | 2013-10-14 15:25:16 -0700 | [diff] [blame] | 766 | if (mCameraDevice == null) { |
| 767 | return; |
| 768 | } |
I-Jong Lin | 4ed861a | 2014-10-10 16:34:34 -0700 | [diff] [blame] | 769 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 770 | mCameraSettings = mCameraDevice.getSettings(); |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 771 | Point desiredPreviewSize = getDesiredPreviewSize(mAppController.getAndroidContext(), |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 772 | mCameraSettings, mCameraCapabilities, mProfile, mUI.getPreviewScreenSize()); |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 773 | mDesiredPreviewWidth = desiredPreviewSize.x; |
| 774 | mDesiredPreviewHeight = desiredPreviewSize.y; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 775 | mUI.setPreviewSize(mDesiredPreviewWidth, mDesiredPreviewHeight); |
I-Jong Lin | 4ed861a | 2014-10-10 16:34:34 -0700 | [diff] [blame] | 776 | Log.v(TAG, "Updated DesiredPreview=" + mDesiredPreviewWidth + "x" |
| 777 | + mDesiredPreviewHeight); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 778 | } |
| 779 | |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 780 | /** |
| 781 | * Calculates the preview size and stores it in mDesiredPreviewWidth and |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 782 | * mDesiredPreviewHeight. |
| 783 | * |
| 784 | * <p>This function checks {@link |
| 785 | * com.android.camera.cameradevice.CameraCapabilities#getPreferredPreviewSizeForVideo()} |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 786 | * but also considers the current preview area size on screen and make sure |
| 787 | * the final preview size will not be smaller than 1/2 of the current |
I-Jong Lin | 4ed861a | 2014-10-10 16:34:34 -0700 | [diff] [blame] | 788 | * on screen preview area in terms of their short sides. This function has |
| 789 | * highest priority of WYSIWYG, 1:1 matching as its best match, even if |
| 790 | * there's a larger preview that meets the condition above. </p> |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 791 | * |
| 792 | * @return The preferred preview size or {@code null} if the camera is not |
| 793 | * opened yet. |
| 794 | */ |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 795 | private static Point getDesiredPreviewSize(Context context, CameraSettings settings, |
| 796 | CameraCapabilities capabilities, CamcorderProfile profile, Point previewScreenSize) { |
| 797 | if (capabilities.getSupportedVideoSizes() == null) { |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 798 | // Driver doesn't support separate outputs for preview and video. |
| 799 | return new Point(profile.videoFrameWidth, profile.videoFrameHeight); |
| 800 | } |
| 801 | |
| 802 | final int previewScreenShortSide = (previewScreenSize.x < previewScreenSize.y ? |
| 803 | previewScreenSize.x : previewScreenSize.y); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 804 | List<Size> sizes = capabilities.getSupportedPreviewSizes(); |
| 805 | Size preferred = capabilities.getPreferredPreviewSizeForVideo(); |
Angus Kong | 00b7b10 | 2014-04-24 15:46:52 -0700 | [diff] [blame] | 806 | final int preferredPreviewSizeShortSide = (preferred.width() < preferred.height() ? |
| 807 | preferred.width() : preferred.height()); |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 808 | if (preferredPreviewSizeShortSide * 2 < previewScreenShortSide) { |
Angus Kong | 6342466 | 2014-04-23 10:47:47 -0700 | [diff] [blame] | 809 | preferred = new Size(profile.videoFrameWidth, profile.videoFrameHeight); |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 810 | } |
Angus Kong | 00b7b10 | 2014-04-24 15:46:52 -0700 | [diff] [blame] | 811 | int product = preferred.width() * preferred.height(); |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 812 | Iterator<Size> it = sizes.iterator(); |
| 813 | // Remove the preview sizes that are not preferred. |
| 814 | while (it.hasNext()) { |
| 815 | Size size = it.next(); |
Angus Kong | 00b7b10 | 2014-04-24 15:46:52 -0700 | [diff] [blame] | 816 | if (size.width() * size.height() > product) { |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 817 | it.remove(); |
| 818 | } |
| 819 | } |
I-Jong Lin | 4ed861a | 2014-10-10 16:34:34 -0700 | [diff] [blame] | 820 | |
| 821 | // Take highest priority for WYSIWYG when the preview exactly matches |
| 822 | // video frame size. The variable sizes is assumed to be filtered |
| 823 | // for sizes beyond the UI size. |
| 824 | for (Size size : sizes) { |
| 825 | if (size.width() == profile.videoFrameWidth |
| 826 | && size.height() == profile.videoFrameHeight) { |
| 827 | Log.v(TAG, "Selected =" + size.width() + "x" + size.height() |
| 828 | + " on WYSIWYG Priority"); |
| 829 | return new Point(profile.videoFrameWidth, profile.videoFrameHeight); |
| 830 | } |
| 831 | } |
| 832 | |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 833 | Size optimalSize = CameraUtil.getOptimalPreviewSize(context, sizes, |
| 834 | (double) profile.videoFrameWidth / profile.videoFrameHeight); |
Angus Kong | 00b7b10 | 2014-04-24 15:46:52 -0700 | [diff] [blame] | 835 | return new Point(optimalSize.width(), optimalSize.height()); |
Angus Kong | 5f8c30e | 2014-03-06 17:15:08 -0800 | [diff] [blame] | 836 | } |
| 837 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 838 | private void resizeForPreviewAspectRatio() { |
Doris Liu | e038c16 | 2013-12-13 23:06:11 -0800 | [diff] [blame] | 839 | mUI.setAspectRatio((float) mProfile.videoFrameWidth / mProfile.videoFrameHeight); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 840 | } |
| 841 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 842 | private void installIntentFilter() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 843 | // install an intent filter to receive SD card related events. |
| 844 | IntentFilter intentFilter = |
| 845 | new IntentFilter(Intent.ACTION_MEDIA_EJECT); |
| 846 | intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED); |
| 847 | intentFilter.addDataScheme("file"); |
| 848 | mReceiver = new MyBroadcastReceiver(); |
| 849 | mActivity.registerReceiver(mReceiver, intentFilter); |
| 850 | } |
| 851 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 852 | private void setDisplayOrientation() { |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 853 | mDisplayRotation = CameraUtil.getDisplayRotation(mActivity); |
Sol Boucher | 43e1813 | 2014-06-19 15:03:18 -0700 | [diff] [blame] | 854 | Characteristics info = |
| 855 | mActivity.getCameraProvider().getCharacteristics(mCameraId); |
Sol Boucher | 73ec985 | 2014-07-24 23:59:21 -0700 | [diff] [blame] | 856 | mCameraDisplayOrientation = info.getPreviewOrientation(mDisplayRotation); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 857 | // Change the camera display orientation |
| 858 | if (mCameraDevice != null) { |
Sol Boucher | 73ec985 | 2014-07-24 23:59:21 -0700 | [diff] [blame] | 859 | mCameraDevice.setDisplayOrientation(mDisplayRotation); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 860 | } |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 861 | if (mFocusManager != null) { |
| 862 | mFocusManager.setDisplayOrientation(mCameraDisplayOrientation); |
| 863 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | @Override |
| 867 | public void updateCameraOrientation() { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 868 | if (mMediaRecorderRecording) { |
| 869 | return; |
| 870 | } |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 871 | if (mDisplayRotation != CameraUtil.getDisplayRotation(mActivity)) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 872 | setDisplayOrientation(); |
| 873 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 874 | } |
| 875 | |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 876 | @Override |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 877 | public void updatePreviewAspectRatio(float aspectRatio) { |
| 878 | mAppController.updatePreviewAspectRatio(aspectRatio); |
| 879 | } |
| 880 | |
Andy Huibers | 203abe5 | 2014-05-19 13:59:01 -0700 | [diff] [blame] | 881 | /** |
| 882 | * Returns current Zoom value, with 1.0 as the value for no zoom. |
| 883 | */ |
| 884 | private float currentZoomValue() { |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 885 | return mCameraSettings.getCurrentZoomRatio(); |
Andy Huibers | 203abe5 | 2014-05-19 13:59:01 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 888 | @Override |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 889 | public void onZoomChanged(float ratio) { |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 890 | // Not useful to change zoom value when the activity is paused. |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 891 | if (mPaused) { |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 892 | return; |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 893 | } |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 894 | mZoomValue = ratio; |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 895 | if (mCameraSettings == null || mCameraDevice == null) { |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 896 | return; |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 897 | } |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 898 | // Set zoom parameters asynchronously |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 899 | mCameraSettings.setZoomRatio(mZoomValue); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 900 | mCameraDevice.applySettings(mCameraSettings); |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 901 | } |
Angus Kong | 395ee2d | 2013-07-15 12:42:41 -0700 | [diff] [blame] | 902 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 903 | private void startPreview() { |
Alan Newberger | d41766f | 2014-04-09 18:25:34 -0700 | [diff] [blame] | 904 | Log.i(TAG, "startPreview"); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 905 | |
Erin Dahlgren | d8de077 | 2014-02-03 10:12:27 -0800 | [diff] [blame] | 906 | SurfaceTexture surfaceTexture = mActivity.getCameraAppUI().getSurfaceTexture(); |
ztenghui | ef01a31 | 2013-10-14 15:25:16 -0700 | [diff] [blame] | 907 | if (!mPreferenceRead || surfaceTexture == null || mPaused == true || |
| 908 | mCameraDevice == null) { |
| 909 | return; |
| 910 | } |
Angus Kong | 395ee2d | 2013-07-15 12:42:41 -0700 | [diff] [blame] | 911 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 912 | if (mPreviewing == true) { |
| 913 | stopPreview(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 914 | } |
| 915 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 916 | setDisplayOrientation(); |
Sol Boucher | 73ec985 | 2014-07-24 23:59:21 -0700 | [diff] [blame] | 917 | mCameraDevice.setDisplayOrientation(mDisplayRotation); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 918 | setCameraParameters(); |
| 919 | |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 920 | if (mFocusManager != null) { |
| 921 | // If the focus mode is continuous autofocus, call cancelAutoFocus |
| 922 | // to resume it because it may have been paused by autoFocus call. |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 923 | CameraCapabilities.FocusMode focusMode = |
| 924 | mFocusManager.getFocusMode(mCameraSettings.getCurrentFocusMode()); |
| 925 | if (focusMode == CameraCapabilities.FocusMode.CONTINUOUS_PICTURE) { |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 926 | mCameraDevice.cancelAutoFocus(); |
| 927 | } |
| 928 | } |
Doris Liu | 5a36754 | 2014-01-17 17:21:42 -0800 | [diff] [blame] | 929 | |
| 930 | // This is to notify app controller that preview will start next, so app |
| 931 | // controller can set preview callbacks if needed. This has to happen before |
| 932 | // preview is started as a workaround of the framework issue related to preview |
| 933 | // callbacks that causes preview stretch and crash. (More details see b/12210027 |
Alan Newberger | fb172ac | 2014-08-21 14:42:36 -0700 | [diff] [blame] | 934 | // and b/12591410. Don't apply this to L, see b/16649297. |
| 935 | if (!ApiHelper.isLOrHigher()) { |
| 936 | Log.v(TAG, "calling onPreviewReadyToStart to set one shot callback"); |
| 937 | mAppController.onPreviewReadyToStart(); |
| 938 | } else { |
| 939 | Log.v(TAG, "on L, no one shot callback necessary"); |
| 940 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 941 | try { |
Doris Liu | 3973deb | 2013-08-21 13:42:22 -0700 | [diff] [blame] | 942 | mCameraDevice.setPreviewTexture(surfaceTexture); |
Spike Sprague | 3c3b31d | 2014-09-08 10:43:04 -0700 | [diff] [blame] | 943 | mCameraDevice.startPreviewWithCallback(new Handler(Looper.getMainLooper()), |
| 944 | new CameraAgent.CameraStartPreviewCallback() { |
| 945 | @Override |
| 946 | public void onPreviewStarted() { |
| 947 | VideoModule.this.onPreviewStarted(); |
| 948 | } |
| 949 | }); |
Doris Liu | 3973deb | 2013-08-21 13:42:22 -0700 | [diff] [blame] | 950 | mPreviewing = true; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 951 | } catch (Throwable ex) { |
| 952 | closeCamera(); |
| 953 | throw new RuntimeException("startPreview failed", ex); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 954 | } |
Michael Kolb | b1aeb39 | 2013-03-11 12:37:40 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | private void onPreviewStarted() { |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 958 | mAppController.setShutterEnabled(true); |
Doris Liu | 2b906b8 | 2013-12-10 16:34:08 -0800 | [diff] [blame] | 959 | mAppController.onPreviewStarted(); |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 960 | if (mFocusManager != null) { |
| 961 | mFocusManager.onPreviewStarted(); |
| 962 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 963 | } |
| 964 | |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 965 | @Override |
Sameer Padala | db81ce6 | 2014-03-21 15:33:56 -0700 | [diff] [blame] | 966 | public void onPreviewInitialDataReceived() { |
Sameer Padala | db81ce6 | 2014-03-21 15:33:56 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | @Override |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 970 | public void stopPreview() { |
Senpo Hu | 36e045a | 2014-09-29 18:49:10 -0700 | [diff] [blame] | 971 | if (!mPreviewing) { |
| 972 | Log.v(TAG, "Skip stopPreview since it's not mPreviewing"); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 973 | return; |
| 974 | } |
Senpo Hu | 36e045a | 2014-09-29 18:49:10 -0700 | [diff] [blame] | 975 | if (mCameraDevice == null) { |
| 976 | Log.v(TAG, "Skip stopPreview since mCameraDevice is null"); |
| 977 | return; |
| 978 | } |
| 979 | |
| 980 | Log.v(TAG, "stopPreview"); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 981 | mCameraDevice.stopPreview(); |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 982 | if (mFocusManager != null) { |
| 983 | mFocusManager.onPreviewStopped(); |
| 984 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 985 | mPreviewing = false; |
| 986 | } |
| 987 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 988 | private void closeCamera() { |
Alan Newberger | d41766f | 2014-04-09 18:25:34 -0700 | [diff] [blame] | 989 | Log.i(TAG, "closeCamera"); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 990 | if (mCameraDevice == null) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 991 | Log.d(TAG, "already stopped."); |
| 992 | return; |
| 993 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 994 | mCameraDevice.setZoomChangeListener(null); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 995 | mActivity.getCameraProvider().releaseCamera(mCameraDevice.getCameraId()); |
Angus Kong | 395ee2d | 2013-07-15 12:42:41 -0700 | [diff] [blame] | 996 | mCameraDevice = null; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 997 | mPreviewing = false; |
| 998 | mSnapshotInProgress = false; |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 999 | if (mFocusManager != null) { |
| 1000 | mFocusManager.onCameraReleased(); |
| 1001 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1002 | } |
| 1003 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1004 | @Override |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1005 | public boolean onBackPressed() { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 1006 | if (mPaused) { |
| 1007 | return true; |
| 1008 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1009 | if (mMediaRecorderRecording) { |
| 1010 | onStopVideoRecording(); |
| 1011 | return true; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1012 | } else { |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 1013 | return false; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | @Override |
| 1018 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 1019 | // Do not handle any key if the activity is paused. |
| 1020 | if (mPaused) { |
| 1021 | return true; |
| 1022 | } |
| 1023 | |
| 1024 | switch (keyCode) { |
| 1025 | case KeyEvent.KEYCODE_CAMERA: |
| 1026 | if (event.getRepeatCount() == 0) { |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 1027 | onShutterButtonClick(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1028 | return true; |
| 1029 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1030 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 1031 | if (event.getRepeatCount() == 0) { |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 1032 | onShutterButtonClick(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1033 | return true; |
| 1034 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1035 | case KeyEvent.KEYCODE_MENU: |
Erin Dahlgren | 15691af | 2014-03-14 14:10:57 -0700 | [diff] [blame] | 1036 | // Consume menu button presses during capture. |
| 1037 | return mMediaRecorderRecording; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1038 | } |
| 1039 | return false; |
| 1040 | } |
| 1041 | |
| 1042 | @Override |
| 1043 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 1044 | switch (keyCode) { |
| 1045 | case KeyEvent.KEYCODE_CAMERA: |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 1046 | onShutterButtonClick(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1047 | return true; |
Erin Dahlgren | 15691af | 2014-03-14 14:10:57 -0700 | [diff] [blame] | 1048 | case KeyEvent.KEYCODE_MENU: |
| 1049 | // Consume menu button presses during capture. |
| 1050 | return mMediaRecorderRecording; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1051 | } |
| 1052 | return false; |
| 1053 | } |
| 1054 | |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 1055 | @Override |
| 1056 | public boolean isVideoCaptureIntent() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1057 | String action = mActivity.getIntent().getAction(); |
| 1058 | return (MediaStore.ACTION_VIDEO_CAPTURE.equals(action)); |
| 1059 | } |
| 1060 | |
| 1061 | private void doReturnToCaller(boolean valid) { |
| 1062 | Intent resultIntent = new Intent(); |
| 1063 | int resultCode; |
| 1064 | if (valid) { |
| 1065 | resultCode = Activity.RESULT_OK; |
| 1066 | resultIntent.setData(mCurrentVideoUri); |
Nicolas Prevot | 44917f6 | 2014-09-09 20:35:56 +0100 | [diff] [blame] | 1067 | resultIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1068 | } else { |
| 1069 | resultCode = Activity.RESULT_CANCELED; |
| 1070 | } |
| 1071 | mActivity.setResultEx(resultCode, resultIntent); |
| 1072 | mActivity.finish(); |
| 1073 | } |
| 1074 | |
| 1075 | private void cleanupEmptyFile() { |
| 1076 | if (mVideoFilename != null) { |
| 1077 | File f = new File(mVideoFilename); |
| 1078 | if (f.length() == 0 && f.delete()) { |
| 1079 | Log.v(TAG, "Empty video file deleted: " + mVideoFilename); |
| 1080 | mVideoFilename = null; |
| 1081 | } |
| 1082 | } |
| 1083 | } |
| 1084 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1085 | // Prepares media recorder. |
| 1086 | private void initializeRecorder() { |
Senpo Hu | 2d3475a | 2014-09-28 04:30:15 -0700 | [diff] [blame] | 1087 | Log.i(TAG, "initializeRecorder: " + Thread.currentThread()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1088 | // If the mCameraDevice is null, then this activity is going to finish |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 1089 | if (mCameraDevice == null) { |
| 1090 | return; |
| 1091 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1092 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1093 | Intent intent = mActivity.getIntent(); |
| 1094 | Bundle myExtras = intent.getExtras(); |
| 1095 | |
| 1096 | long requestedSizeLimit = 0; |
| 1097 | closeVideoFileDescriptor(); |
ztenghui | 70bd024 | 2013-10-14 11:15:44 -0700 | [diff] [blame] | 1098 | mCurrentVideoUriFromMediaSaved = false; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1099 | if (mIsVideoCaptureIntent && myExtras != null) { |
| 1100 | Uri saveUri = (Uri) myExtras.getParcelable(MediaStore.EXTRA_OUTPUT); |
| 1101 | if (saveUri != null) { |
| 1102 | try { |
| 1103 | mVideoFileDescriptor = |
| 1104 | mContentResolver.openFileDescriptor(saveUri, "rw"); |
| 1105 | mCurrentVideoUri = saveUri; |
| 1106 | } catch (java.io.FileNotFoundException ex) { |
| 1107 | // invalid uri |
| 1108 | Log.e(TAG, ex.toString()); |
| 1109 | } |
| 1110 | } |
| 1111 | requestedSizeLimit = myExtras.getLong(MediaStore.EXTRA_SIZE_LIMIT); |
| 1112 | } |
| 1113 | mMediaRecorder = new MediaRecorder(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1114 | // Unlock the camera object before passing it to media recorder. |
Senpo Hu | 2d3475a | 2014-09-28 04:30:15 -0700 | [diff] [blame] | 1115 | mCameraDevice.unlock(); |
| 1116 | mMediaRecorder.setCamera(mCameraDevice.getCamera()); |
Sascha Haeberling | f15d63e | 2014-07-21 11:31:13 -0700 | [diff] [blame] | 1117 | mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1118 | mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); |
| 1119 | mMediaRecorder.setProfile(mProfile); |
Michael Kolb | f954236 | 2013-05-30 07:45:41 -0700 | [diff] [blame] | 1120 | mMediaRecorder.setVideoSize(mProfile.videoFrameWidth, mProfile.videoFrameHeight); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1121 | mMediaRecorder.setMaxDuration(mMaxVideoDurationInMs); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1122 | |
| 1123 | setRecordLocation(); |
| 1124 | |
| 1125 | // Set output file. |
| 1126 | // Try Uri in the intent first. If it doesn't exist, use our own |
| 1127 | // instead. |
| 1128 | if (mVideoFileDescriptor != null) { |
| 1129 | mMediaRecorder.setOutputFile(mVideoFileDescriptor.getFileDescriptor()); |
| 1130 | } else { |
| 1131 | generateVideoFilename(mProfile.fileFormat); |
| 1132 | mMediaRecorder.setOutputFile(mVideoFilename); |
| 1133 | } |
| 1134 | |
| 1135 | // Set maximum file size. |
Angus Kong | 2dcc0a9 | 2013-09-25 13:00:08 -0700 | [diff] [blame] | 1136 | long maxFileSize = mActivity.getStorageSpaceBytes() - Storage.LOW_STORAGE_THRESHOLD_BYTES; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1137 | if (requestedSizeLimit > 0 && requestedSizeLimit < maxFileSize) { |
| 1138 | maxFileSize = requestedSizeLimit; |
| 1139 | } |
| 1140 | |
| 1141 | try { |
| 1142 | mMediaRecorder.setMaxFileSize(maxFileSize); |
| 1143 | } catch (RuntimeException exception) { |
| 1144 | // We are going to ignore failure of setMaxFileSize here, as |
| 1145 | // a) The composer selected may simply not support it, or |
| 1146 | // b) The underlying media framework may not handle 64-bit range |
| 1147 | // on the size restriction. |
| 1148 | } |
| 1149 | |
Senpo Hu | 0bdc4b5 | 2014-11-17 22:56:31 -0800 | [diff] [blame] | 1150 | int sensorOrientation = |
| 1151 | mActivity.getCameraProvider().getCharacteristics(mCameraId).getSensorOrientation(); |
| 1152 | int deviceOrientation = |
| 1153 | mAppController.getOrientationManager().getDeviceOrientation().getDegrees(); |
| 1154 | int rotation = CameraUtil.getImageRotation( |
| 1155 | sensorOrientation, deviceOrientation, isCameraFrontFacing()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1156 | mMediaRecorder.setOrientationHint(rotation); |
| 1157 | |
| 1158 | try { |
| 1159 | mMediaRecorder.prepare(); |
| 1160 | } catch (IOException e) { |
| 1161 | Log.e(TAG, "prepare failed for " + mVideoFilename, e); |
| 1162 | releaseMediaRecorder(); |
| 1163 | throw new RuntimeException(e); |
| 1164 | } |
| 1165 | |
| 1166 | mMediaRecorder.setOnErrorListener(this); |
| 1167 | mMediaRecorder.setOnInfoListener(this); |
| 1168 | } |
| 1169 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1170 | private static void setCaptureRate(MediaRecorder recorder, double fps) { |
| 1171 | recorder.setCaptureRate(fps); |
| 1172 | } |
| 1173 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1174 | private void setRecordLocation() { |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 1175 | Location loc = mLocationManager.getCurrentLocation(); |
| 1176 | if (loc != null) { |
| 1177 | mMediaRecorder.setLocation((float) loc.getLatitude(), |
| 1178 | (float) loc.getLongitude()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1179 | } |
| 1180 | } |
| 1181 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1182 | private void releaseMediaRecorder() { |
Alan Newberger | d41766f | 2014-04-09 18:25:34 -0700 | [diff] [blame] | 1183 | Log.i(TAG, "Releasing media recorder."); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1184 | if (mMediaRecorder != null) { |
| 1185 | cleanupEmptyFile(); |
| 1186 | mMediaRecorder.reset(); |
| 1187 | mMediaRecorder.release(); |
| 1188 | mMediaRecorder = null; |
| 1189 | } |
| 1190 | mVideoFilename = null; |
| 1191 | } |
| 1192 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1193 | private void generateVideoFilename(int outputFileFormat) { |
| 1194 | long dateTaken = System.currentTimeMillis(); |
| 1195 | String title = createName(dateTaken); |
| 1196 | // Used when emailing. |
| 1197 | String filename = title + convertOutputFormatToFileExt(outputFileFormat); |
| 1198 | String mime = convertOutputFormatToMimeType(outputFileFormat); |
| 1199 | String path = Storage.DIRECTORY + '/' + filename; |
| 1200 | String tmpPath = path + ".tmp"; |
Ruben Brunk | 1600796 | 2013-04-19 15:27:57 -0700 | [diff] [blame] | 1201 | mCurrentVideoValues = new ContentValues(9); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1202 | mCurrentVideoValues.put(Video.Media.TITLE, title); |
| 1203 | mCurrentVideoValues.put(Video.Media.DISPLAY_NAME, filename); |
| 1204 | mCurrentVideoValues.put(Video.Media.DATE_TAKEN, dateTaken); |
Ruben Brunk | 1600796 | 2013-04-19 15:27:57 -0700 | [diff] [blame] | 1205 | mCurrentVideoValues.put(MediaColumns.DATE_MODIFIED, dateTaken / 1000); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1206 | mCurrentVideoValues.put(Video.Media.MIME_TYPE, mime); |
| 1207 | mCurrentVideoValues.put(Video.Media.DATA, path); |
Sam Judd | de3e9ab | 2014-03-17 13:07:22 -0700 | [diff] [blame] | 1208 | mCurrentVideoValues.put(Video.Media.WIDTH, mProfile.videoFrameWidth); |
| 1209 | mCurrentVideoValues.put(Video.Media.HEIGHT, mProfile.videoFrameHeight); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1210 | mCurrentVideoValues.put(Video.Media.RESOLUTION, |
| 1211 | Integer.toString(mProfile.videoFrameWidth) + "x" + |
| 1212 | Integer.toString(mProfile.videoFrameHeight)); |
| 1213 | Location loc = mLocationManager.getCurrentLocation(); |
| 1214 | if (loc != null) { |
| 1215 | mCurrentVideoValues.put(Video.Media.LATITUDE, loc.getLatitude()); |
| 1216 | mCurrentVideoValues.put(Video.Media.LONGITUDE, loc.getLongitude()); |
| 1217 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1218 | mVideoFilename = tmpPath; |
| 1219 | Log.v(TAG, "New video filename: " + mVideoFilename); |
| 1220 | } |
| 1221 | |
Andy Huibers | 203abe5 | 2014-05-19 13:59:01 -0700 | [diff] [blame] | 1222 | private void logVideoCapture(long duration) { |
| 1223 | String flashSetting = mActivity.getSettingsManager() |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 1224 | .getString(mAppController.getCameraScope(), |
| 1225 | Keys.KEY_VIDEOCAMERA_FLASH_MODE); |
| 1226 | boolean gridLinesOn = Keys.areGridLinesOn(mActivity.getSettingsManager()); |
Andy Huibers | 203abe5 | 2014-05-19 13:59:01 -0700 | [diff] [blame] | 1227 | int width = (Integer) mCurrentVideoValues.get(Video.Media.WIDTH); |
| 1228 | int height = (Integer) mCurrentVideoValues.get(Video.Media.HEIGHT); |
| 1229 | long size = new File(mCurrentVideoFilename).length(); |
| 1230 | String name = new File(mCurrentVideoValues.getAsString(Video.Media.DATA)).getName(); |
| 1231 | UsageStatistics.instance().videoCaptureDoneEvent(name, duration, isCameraFrontFacing(), |
| 1232 | currentZoomValue(), width, height, size, flashSetting, gridLinesOn); |
| 1233 | } |
| 1234 | |
Angus Kong | 83a99ae | 2013-04-17 15:37:07 -0700 | [diff] [blame] | 1235 | private void saveVideo() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1236 | if (mVideoFileDescriptor == null) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1237 | long duration = SystemClock.uptimeMillis() - mRecordingStartTime; |
| 1238 | if (duration > 0) { |
Spike Sprague | d020fbf | 2014-07-16 15:47:32 -0700 | [diff] [blame] | 1239 | // |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1240 | } else { |
| 1241 | Log.w(TAG, "Video duration <= 0 : " + duration); |
| 1242 | } |
Andy Huibers | 203abe5 | 2014-05-19 13:59:01 -0700 | [diff] [blame] | 1243 | mCurrentVideoValues.put(Video.Media.SIZE, new File(mCurrentVideoFilename).length()); |
| 1244 | mCurrentVideoValues.put(Video.Media.DURATION, duration); |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 1245 | getServices().getMediaSaver().addVideo(mCurrentVideoFilename, |
Andy Huibers | 203abe5 | 2014-05-19 13:59:01 -0700 | [diff] [blame] | 1246 | mCurrentVideoValues, mOnVideoSavedListener, mContentResolver); |
| 1247 | logVideoCapture(duration); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1248 | } |
| 1249 | mCurrentVideoValues = null; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | private void deleteVideoFile(String fileName) { |
| 1253 | Log.v(TAG, "Deleting video " + fileName); |
| 1254 | File f = new File(fileName); |
| 1255 | if (!f.delete()) { |
| 1256 | Log.v(TAG, "Could not delete " + fileName); |
| 1257 | } |
| 1258 | } |
| 1259 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1260 | // from MediaRecorder.OnErrorListener |
| 1261 | @Override |
| 1262 | public void onError(MediaRecorder mr, int what, int extra) { |
| 1263 | Log.e(TAG, "MediaRecorder error. what=" + what + ". extra=" + extra); |
| 1264 | if (what == MediaRecorder.MEDIA_RECORDER_ERROR_UNKNOWN) { |
| 1265 | // We may have run out of space on the sdcard. |
| 1266 | stopVideoRecording(); |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1267 | mActivity.updateStorageSpaceAndHint(null); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | // from MediaRecorder.OnInfoListener |
| 1272 | @Override |
| 1273 | public void onInfo(MediaRecorder mr, int what, int extra) { |
| 1274 | if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 1275 | if (mMediaRecorderRecording) { |
| 1276 | onStopVideoRecording(); |
| 1277 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1278 | } else if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 1279 | if (mMediaRecorderRecording) { |
| 1280 | onStopVideoRecording(); |
| 1281 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1282 | |
| 1283 | // Show the toast. |
| 1284 | Toast.makeText(mActivity, R.string.video_reach_size_limit, |
| 1285 | Toast.LENGTH_LONG).show(); |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | /* |
| 1290 | * Make sure we're not recording music playing in the background, ask the |
| 1291 | * MediaPlaybackService to pause playback. |
| 1292 | */ |
Sascha Haeberling | 92217bd | 2014-12-11 12:20:43 -0800 | [diff] [blame] | 1293 | private void silenceSoundsAndVibrations() { |
| 1294 | // Get the audio focus which causes other music players to stop. |
| 1295 | mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, |
| 1296 | AudioManager.AUDIOFOCUS_GAIN); |
| 1297 | // Store current ringer mode so we can set it once video recording is |
| 1298 | // finished. |
| 1299 | mOriginalRingerMode = mAudioManager.getRingerMode(); |
| 1300 | // Make sure no system sounds and vibrations happen during video |
| 1301 | // recording. |
| 1302 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); |
| 1303 | } |
| 1304 | |
| 1305 | private void restoreRingerMode() { |
| 1306 | // First check if ringer mode was changed during the recording. If not, |
| 1307 | // re-set the mode that was set before video recording started. |
| 1308 | if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { |
| 1309 | mAudioManager.setRingerMode(mOriginalRingerMode); |
| 1310 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | // For testing. |
| 1314 | public boolean isRecording() { |
| 1315 | return mMediaRecorderRecording; |
| 1316 | } |
| 1317 | |
| 1318 | private void startVideoRecording() { |
Senpo Hu | 2d3475a | 2014-09-28 04:30:15 -0700 | [diff] [blame] | 1319 | Log.i(TAG, "startVideoRecording: " + Thread.currentThread()); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1320 | mUI.cancelAnimations(); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1321 | mUI.setSwipingEnabled(false); |
Paul Rohde | 987ee64 | 2014-12-05 12:17:15 -0800 | [diff] [blame] | 1322 | mUI.hidePassiveFocusIndicator(); |
Doris Liu | d6487c9 | 2014-02-28 10:35:45 -0800 | [diff] [blame] | 1323 | mUI.showVideoRecordingHints(false); |
Senpo Hu | 427a915 | 2014-11-19 17:11:46 -0800 | [diff] [blame] | 1324 | mAppController.getCameraAppUI().hideCaptureIndicator(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1325 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1326 | mActivity.updateStorageSpaceAndHint(new CameraActivity.OnStorageUpdateDoneListener() { |
| 1327 | @Override |
| 1328 | public void onStorageUpdateDone(long bytes) { |
| 1329 | if (bytes <= Storage.LOW_STORAGE_THRESHOLD_BYTES) { |
| 1330 | Log.w(TAG, "Storage issue, ignore the start request"); |
| 1331 | } else { |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 1332 | if (mCameraDevice == null) { |
| 1333 | Log.v(TAG, "in storage callback after camera closed"); |
| 1334 | return; |
| 1335 | } |
Alan Newberger | 26b224d | 2014-08-26 18:18:48 -0700 | [diff] [blame] | 1336 | if (mPaused == true) { |
| 1337 | Log.v(TAG, "in storage callback after module paused"); |
| 1338 | return; |
| 1339 | } |
Senpo Hu | 2d3475a | 2014-09-28 04:30:15 -0700 | [diff] [blame] | 1340 | |
| 1341 | // Monkey is so fast so it could trigger startVideoRecording twice. To prevent |
| 1342 | // app crash (b/17313985), do nothing here for the second storage-checking |
| 1343 | // callback because recording is already started. |
| 1344 | if (mMediaRecorderRecording) { |
| 1345 | Log.v(TAG, "in storage callback after recording started"); |
| 1346 | return; |
| 1347 | } |
| 1348 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1349 | mCurrentVideoUri = null; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1350 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1351 | initializeRecorder(); |
| 1352 | if (mMediaRecorder == null) { |
| 1353 | Log.e(TAG, "Fail to initialize media recorder"); |
| 1354 | return; |
| 1355 | } |
Doris Liu | 3973deb | 2013-08-21 13:42:22 -0700 | [diff] [blame] | 1356 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1357 | try { |
| 1358 | mMediaRecorder.start(); // Recording is now started |
| 1359 | } catch (RuntimeException e) { |
| 1360 | Log.e(TAG, "Could not start media recorder. ", e); |
| 1361 | releaseMediaRecorder(); |
| 1362 | // If start fails, frameworks will not lock the camera for us. |
| 1363 | mCameraDevice.lock(); |
| 1364 | return; |
| 1365 | } |
Sascha Haeberling | 367d138 | 2014-12-11 14:15:04 -0800 | [diff] [blame] | 1366 | // Make sure we stop playing sounds and disable the |
| 1367 | // vibrations during video recording. |
| 1368 | silenceSoundsAndVibrations(); |
| 1369 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1370 | mAppController.getCameraAppUI().setSwipeEnabled(false); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1371 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1372 | // The parameters might have been altered by MediaRecorder already. |
| 1373 | // We need to force mCameraDevice to refresh before getting it. |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1374 | mCameraDevice.refreshSettings(); |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1375 | // The parameters may have been changed by MediaRecorder upon starting |
| 1376 | // recording. We need to alter the parameters if we support camcorder |
| 1377 | // zoom. To reduce latency when setting the parameters during zoom, we |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1378 | // update the settings here once. |
| 1379 | mCameraSettings = mCameraDevice.getSettings(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1380 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1381 | mMediaRecorderRecording = true; |
| 1382 | mActivity.lockOrientation(); |
| 1383 | mRecordingStartTime = SystemClock.uptimeMillis(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1384 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1385 | // A special case of mode options closing: during capture it should |
| 1386 | // not be possible to change mode state. |
| 1387 | mAppController.getCameraAppUI().hideModeOptions(); |
| 1388 | mAppController.getCameraAppUI().animateBottomBarToVideoStop(R.drawable.ic_stop); |
| 1389 | mUI.showRecordingUI(true); |
Doris Liu | 4df9158 | 2014-03-21 18:33:57 -0700 | [diff] [blame] | 1390 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1391 | setFocusParameters(); |
Senpo Hu | 1118631 | 2014-08-08 13:42:13 -0700 | [diff] [blame] | 1392 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1393 | updateRecordingTime(); |
| 1394 | mActivity.enableKeepScreenOn(true); |
| 1395 | } |
| 1396 | } |
| 1397 | }); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1398 | } |
| 1399 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1400 | private Bitmap getVideoThumbnail() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1401 | Bitmap bitmap = null; |
| 1402 | if (mVideoFileDescriptor != null) { |
| 1403 | bitmap = Thumbnail.createVideoThumbnailBitmap(mVideoFileDescriptor.getFileDescriptor(), |
Doris Liu | 3c2fca3 | 2013-02-13 18:28:03 -0800 | [diff] [blame] | 1404 | mDesiredPreviewWidth); |
Doris Liu | 2a7f44c | 2013-08-12 15:18:53 -0700 | [diff] [blame] | 1405 | } else if (mCurrentVideoUri != null) { |
| 1406 | try { |
| 1407 | mVideoFileDescriptor = mContentResolver.openFileDescriptor(mCurrentVideoUri, "r"); |
| 1408 | bitmap = Thumbnail.createVideoThumbnailBitmap( |
| 1409 | mVideoFileDescriptor.getFileDescriptor(), mDesiredPreviewWidth); |
| 1410 | } catch (java.io.FileNotFoundException ex) { |
| 1411 | // invalid uri |
| 1412 | Log.e(TAG, ex.toString()); |
| 1413 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1414 | } |
Doris Liu | 3973deb | 2013-08-21 13:42:22 -0700 | [diff] [blame] | 1415 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1416 | if (bitmap != null) { |
| 1417 | // MetadataRetriever already rotates the thumbnail. We should rotate |
| 1418 | // it to match the UI orientation (and mirror if it is front-facing camera). |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 1419 | bitmap = CameraUtil.rotateAndMirror(bitmap, 0, isCameraFrontFacing()); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1420 | } |
| 1421 | return bitmap; |
| 1422 | } |
| 1423 | |
| 1424 | private void showCaptureResult() { |
| 1425 | mIsInReviewMode = true; |
| 1426 | Bitmap bitmap = getVideoThumbnail(); |
| 1427 | if (bitmap != null) { |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 1428 | mUI.showReviewImage(bitmap); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1429 | } |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 1430 | mUI.showReviewControls(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1431 | } |
| 1432 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1433 | private boolean stopVideoRecording() { |
Senpo Hu | 2d3475a | 2014-09-28 04:30:15 -0700 | [diff] [blame] | 1434 | // Do nothing if camera device is still capturing photo. Monkey test can trigger app crashes |
| 1435 | // (b/17313985) without this check. Crash could also be reproduced by continuously tapping |
| 1436 | // on shutter button and preview with two fingers. |
| 1437 | if (mSnapshotInProgress) { |
Senpo Hu | 36e045a | 2014-09-29 18:49:10 -0700 | [diff] [blame] | 1438 | Log.v(TAG, "Skip stopVideoRecording since snapshot in progress"); |
Senpo Hu | 2d3475a | 2014-09-28 04:30:15 -0700 | [diff] [blame] | 1439 | return true; |
| 1440 | } |
Senpo Hu | 36e045a | 2014-09-29 18:49:10 -0700 | [diff] [blame] | 1441 | Log.v(TAG, "stopVideoRecording"); |
Senpo Hu | 2d3475a | 2014-09-28 04:30:15 -0700 | [diff] [blame] | 1442 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1443 | mUI.setSwipingEnabled(true); |
Paul Rohde | 987ee64 | 2014-12-05 12:17:15 -0800 | [diff] [blame] | 1444 | mUI.showPassiveFocusIndicator(); |
Doris Liu | d6487c9 | 2014-02-28 10:35:45 -0800 | [diff] [blame] | 1445 | mUI.showVideoRecordingHints(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1446 | |
| 1447 | boolean fail = false; |
| 1448 | if (mMediaRecorderRecording) { |
| 1449 | boolean shouldAddToMediaStoreNow = false; |
| 1450 | |
| 1451 | try { |
Doris Liu | 3973deb | 2013-08-21 13:42:22 -0700 | [diff] [blame] | 1452 | mMediaRecorder.setOnErrorListener(null); |
| 1453 | mMediaRecorder.setOnInfoListener(null); |
| 1454 | mMediaRecorder.stop(); |
| 1455 | shouldAddToMediaStoreNow = true; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1456 | mCurrentVideoFilename = mVideoFilename; |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1457 | Log.v(TAG, "stopVideoRecording: current video filename: " + mCurrentVideoFilename); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1458 | } catch (RuntimeException e) { |
| 1459 | Log.e(TAG, "stop fail", e); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 1460 | if (mVideoFilename != null) { |
| 1461 | deleteVideoFile(mVideoFilename); |
| 1462 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1463 | fail = true; |
| 1464 | } |
Sascha Haeberling | 92217bd | 2014-12-11 12:20:43 -0800 | [diff] [blame] | 1465 | restoreRingerMode(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1466 | mMediaRecorderRecording = false; |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 1467 | mActivity.unlockOrientation(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1468 | |
| 1469 | // If the activity is paused, this means activity is interrupted |
| 1470 | // during recording. Release the camera as soon as possible because |
| 1471 | // face unlock or other applications may need to use the camera. |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1472 | if (mPaused) { |
Senpo Hu | 36e045a | 2014-09-29 18:49:10 -0700 | [diff] [blame] | 1473 | // b/16300704: Monkey is fast so it could pause the module while recording. |
| 1474 | // stopPreview should definitely be called before switching off. |
| 1475 | stopPreview(); |
Doris Liu | 3973deb | 2013-08-21 13:42:22 -0700 | [diff] [blame] | 1476 | closeCamera(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1477 | } |
| 1478 | |
Doris Liu | fe6596c | 2013-10-08 11:03:37 -0700 | [diff] [blame] | 1479 | mUI.showRecordingUI(false); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1480 | // The orientation was fixed during video recording. Now make it |
| 1481 | // reflect the device orientation as video recording is stopped. |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 1482 | mUI.setOrientationIndicator(0, true); |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1483 | mActivity.enableKeepScreenOn(false); |
Doris Liu | 2a7f44c | 2013-08-12 15:18:53 -0700 | [diff] [blame] | 1484 | if (shouldAddToMediaStoreNow && !fail) { |
| 1485 | if (mVideoFileDescriptor == null) { |
| 1486 | saveVideo(); |
| 1487 | } else if (mIsVideoCaptureIntent) { |
| 1488 | // if no file save is needed, we can show the post capture UI now |
| 1489 | showCaptureResult(); |
| 1490 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1491 | } |
| 1492 | } |
Doris Liu | 3973deb | 2013-08-21 13:42:22 -0700 | [diff] [blame] | 1493 | // release media recorder |
| 1494 | releaseMediaRecorder(); |
Doris Liu | 4df9158 | 2014-03-21 18:33:57 -0700 | [diff] [blame] | 1495 | |
| 1496 | mAppController.getCameraAppUI().showModeOptions(); |
| 1497 | mAppController.getCameraAppUI().animateBottomBarToFullSize(mShutterIconId); |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 1498 | if (!mPaused && mCameraDevice != null) { |
Doris Liu | 1143ebd | 2014-01-24 14:11:50 -0800 | [diff] [blame] | 1499 | setFocusParameters(); |
Doris Liu | 3973deb | 2013-08-21 13:42:22 -0700 | [diff] [blame] | 1500 | mCameraDevice.lock(); |
| 1501 | if (!ApiHelper.HAS_SURFACE_TEXTURE_RECORDING) { |
| 1502 | stopPreview(); |
Doris Liu | 3973deb | 2013-08-21 13:42:22 -0700 | [diff] [blame] | 1503 | // Switch back to use SurfaceTexture for preview. |
| 1504 | startPreview(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1505 | } |
Angus Kong | 62753ae | 2014-02-10 10:53:54 -0800 | [diff] [blame] | 1506 | // Update the parameters here because the parameters might have been altered |
| 1507 | // by MediaRecorder. |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1508 | mCameraSettings = mCameraDevice.getSettings(); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 1509 | } |
Spike Sprague | 3f67379 | 2014-04-14 16:16:27 -0700 | [diff] [blame] | 1510 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1511 | // Check this in advance of each shot so we don't add to shutter |
| 1512 | // latency. It's true that someone else could write to the SD card |
| 1513 | // in the mean time and fill it, but that could have happened |
| 1514 | // between the shutter press and saving the file too. |
| 1515 | mActivity.updateStorageSpaceAndHint(null); |
Spike Sprague | 3f67379 | 2014-04-14 16:16:27 -0700 | [diff] [blame] | 1516 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1517 | return fail; |
| 1518 | } |
| 1519 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1520 | private static String millisecondToTimeString(long milliSeconds, boolean displayCentiSeconds) { |
| 1521 | long seconds = milliSeconds / 1000; // round down to compute seconds |
| 1522 | long minutes = seconds / 60; |
| 1523 | long hours = minutes / 60; |
| 1524 | long remainderMinutes = minutes - (hours * 60); |
| 1525 | long remainderSeconds = seconds - (minutes * 60); |
| 1526 | |
| 1527 | StringBuilder timeStringBuilder = new StringBuilder(); |
| 1528 | |
| 1529 | // Hours |
| 1530 | if (hours > 0) { |
| 1531 | if (hours < 10) { |
| 1532 | timeStringBuilder.append('0'); |
| 1533 | } |
| 1534 | timeStringBuilder.append(hours); |
| 1535 | |
| 1536 | timeStringBuilder.append(':'); |
| 1537 | } |
| 1538 | |
| 1539 | // Minutes |
| 1540 | if (remainderMinutes < 10) { |
| 1541 | timeStringBuilder.append('0'); |
| 1542 | } |
| 1543 | timeStringBuilder.append(remainderMinutes); |
| 1544 | timeStringBuilder.append(':'); |
| 1545 | |
| 1546 | // Seconds |
| 1547 | if (remainderSeconds < 10) { |
| 1548 | timeStringBuilder.append('0'); |
| 1549 | } |
| 1550 | timeStringBuilder.append(remainderSeconds); |
| 1551 | |
| 1552 | // Centi seconds |
| 1553 | if (displayCentiSeconds) { |
| 1554 | timeStringBuilder.append('.'); |
| 1555 | long remainderCentiSeconds = (milliSeconds - seconds * 1000) / 10; |
| 1556 | if (remainderCentiSeconds < 10) { |
| 1557 | timeStringBuilder.append('0'); |
| 1558 | } |
| 1559 | timeStringBuilder.append(remainderCentiSeconds); |
| 1560 | } |
| 1561 | |
| 1562 | return timeStringBuilder.toString(); |
| 1563 | } |
| 1564 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1565 | private void updateRecordingTime() { |
| 1566 | if (!mMediaRecorderRecording) { |
| 1567 | return; |
| 1568 | } |
| 1569 | long now = SystemClock.uptimeMillis(); |
| 1570 | long delta = now - mRecordingStartTime; |
| 1571 | |
| 1572 | // Starting a minute before reaching the max duration |
| 1573 | // limit, we'll countdown the remaining time instead. |
| 1574 | boolean countdownRemainingTime = (mMaxVideoDurationInMs != 0 |
| 1575 | && delta >= mMaxVideoDurationInMs - 60000); |
| 1576 | |
| 1577 | long deltaAdjusted = delta; |
| 1578 | if (countdownRemainingTime) { |
| 1579 | deltaAdjusted = Math.max(0, mMaxVideoDurationInMs - deltaAdjusted) + 999; |
| 1580 | } |
| 1581 | String text; |
| 1582 | |
| 1583 | long targetNextUpdateDelay; |
Spike Sprague | d020fbf | 2014-07-16 15:47:32 -0700 | [diff] [blame] | 1584 | |
| 1585 | text = millisecondToTimeString(deltaAdjusted, false); |
| 1586 | targetNextUpdateDelay = 1000; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1587 | |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 1588 | mUI.setRecordingTime(text); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1589 | |
| 1590 | if (mRecordingTimeCountsDown != countdownRemainingTime) { |
| 1591 | // Avoid setting the color on every update, do it only |
| 1592 | // when it needs changing. |
| 1593 | mRecordingTimeCountsDown = countdownRemainingTime; |
| 1594 | |
Spike Sprague | d020fbf | 2014-07-16 15:47:32 -0700 | [diff] [blame] | 1595 | int color = mActivity.getResources().getColor(R.color.recording_time_remaining_text); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1596 | |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 1597 | mUI.setRecordingTimeTextColor(color); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | long actualNextUpdateDelay = targetNextUpdateDelay - (delta % targetNextUpdateDelay); |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1601 | mHandler.sendEmptyMessageDelayed(MSG_UPDATE_RECORD_TIME, actualNextUpdateDelay); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | private static boolean isSupported(String value, List<String> supported) { |
| 1605 | return supported == null ? false : supported.indexOf(value) >= 0; |
| 1606 | } |
| 1607 | |
| 1608 | @SuppressWarnings("deprecation") |
| 1609 | private void setCameraParameters() { |
Erin Dahlgren | bd3da26 | 2013-12-02 11:48:13 -0800 | [diff] [blame] | 1610 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
| 1611 | |
I-Jong Lin | 4ed861a | 2014-10-10 16:34:34 -0700 | [diff] [blame] | 1612 | // Update Desired Preview size in case video camera resolution has changed. |
| 1613 | updateDesiredPreviewSize(); |
| 1614 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1615 | mCameraSettings.setPreviewSize(new Size(mDesiredPreviewWidth, mDesiredPreviewHeight)); |
Andy Huibers | 6dcf90c | 2014-04-14 13:53:12 -0700 | [diff] [blame] | 1616 | // This is required for Samsung SGH-I337 and probably other Samsung S4 versions |
| 1617 | if (Build.BRAND.toLowerCase().contains("samsung")) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1618 | mCameraSettings.setSetting("video-size", |
| 1619 | mProfile.videoFrameWidth + "x" + mProfile.videoFrameHeight); |
Andy Huibers | 6dcf90c | 2014-04-14 13:53:12 -0700 | [diff] [blame] | 1620 | } |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1621 | int[] fpsRange = |
| 1622 | CameraUtil.getMaxPreviewFpsRange(mCameraCapabilities.getSupportedPreviewFpsRange()); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1623 | if (fpsRange.length > 0) { |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 1624 | mCameraSettings.setPreviewFpsRange(fpsRange[0], fpsRange[1]); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1625 | } else { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1626 | mCameraSettings.setPreviewFrameRate(mProfile.videoFrameRate); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1627 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1628 | |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 1629 | enableTorchMode(Keys.isCameraBackFacing(settingsManager, mAppController.getModuleScope())); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1630 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1631 | // Set zoom. |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 1632 | if (mCameraCapabilities.supports(CameraCapabilities.Feature.ZOOM)) { |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 1633 | mCameraSettings.setZoomRatio(mZoomValue); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1634 | } |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1635 | updateFocusParameters(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1636 | |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 1637 | mCameraSettings.setRecordingHintEnabled(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1638 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1639 | if (mCameraCapabilities.supports(CameraCapabilities.Feature.VIDEO_STABILIZATION)) { |
| 1640 | mCameraSettings.setVideoStabilization(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1641 | } |
| 1642 | |
| 1643 | // Set picture size. |
| 1644 | // The logic here is different from the logic in still-mode camera. |
| 1645 | // There we determine the preview size based on the picture size, but |
| 1646 | // here we determine the picture size based on the preview size. |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1647 | List<Size> supported = mCameraCapabilities.getSupportedPhotoSizes(); |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 1648 | Size optimalSize = CameraUtil.getOptimalVideoSnapshotPictureSize(supported, |
I-Jong Lin | 4ed861a | 2014-10-10 16:34:34 -0700 | [diff] [blame] | 1649 | mDesiredPreviewWidth, mDesiredPreviewHeight); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1650 | Size original = new Size(mCameraSettings.getCurrentPhotoSize()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1651 | if (!original.equals(optimalSize)) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1652 | mCameraSettings.setPhotoSize(optimalSize); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1653 | } |
Angus Kong | 00b7b10 | 2014-04-24 15:46:52 -0700 | [diff] [blame] | 1654 | Log.d(TAG, "Video snapshot size is " + optimalSize); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1655 | |
| 1656 | // Set JPEG quality. |
| 1657 | int jpegQuality = CameraProfile.getJpegEncodingQualityParameter(mCameraId, |
| 1658 | CameraProfile.QUALITY_HIGH); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1659 | mCameraSettings.setPhotoJpegCompressionQuality(jpegQuality); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1660 | |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 1661 | if (mCameraDevice != null) { |
| 1662 | mCameraDevice.applySettings(mCameraSettings); |
| 1663 | // Nexus 5 through KitKat 4.4.2 requires a second call to |
| 1664 | // .setParameters() for frame rate settings to take effect. |
| 1665 | mCameraDevice.applySettings(mCameraSettings); |
| 1666 | } |
Sascha Haeberling | f8b877c | 2013-09-09 17:32:48 -0700 | [diff] [blame] | 1667 | |
| 1668 | // Update UI based on the new parameters. |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1669 | mUI.updateOnScreenIndicators(mCameraSettings); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1670 | } |
| 1671 | |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1672 | private void updateFocusParameters() { |
| 1673 | // Set continuous autofocus. During recording, we use "continuous-video" |
| 1674 | // auto focus mode to ensure smooth focusing. Whereas during preview (i.e. |
| 1675 | // before recording starts) we use "continuous-picture" auto focus mode |
| 1676 | // for faster but slightly jittery focusing. |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1677 | Set<CameraCapabilities.FocusMode> supportedFocus = mCameraCapabilities |
| 1678 | .getSupportedFocusModes(); |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1679 | if (mMediaRecorderRecording) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1680 | if (mCameraCapabilities.supports(CameraCapabilities.FocusMode.CONTINUOUS_VIDEO)) { |
| 1681 | mCameraSettings.setFocusMode(CameraCapabilities.FocusMode.CONTINUOUS_VIDEO); |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 1682 | mFocusManager.overrideFocusMode(CameraCapabilities.FocusMode.CONTINUOUS_VIDEO); |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1683 | } else { |
| 1684 | mFocusManager.overrideFocusMode(null); |
| 1685 | } |
| 1686 | } else { |
Senpo Hu | 1118631 | 2014-08-08 13:42:13 -0700 | [diff] [blame] | 1687 | // FIXME(b/16984793): This is broken. For some reasons, CONTINUOUS_PICTURE is not on |
| 1688 | // when preview starts. |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1689 | mFocusManager.overrideFocusMode(null); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1690 | if (mCameraCapabilities.supports(CameraCapabilities.FocusMode.CONTINUOUS_PICTURE)) { |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 1691 | mCameraSettings.setFocusMode( |
| 1692 | mFocusManager.getFocusMode(mCameraSettings.getCurrentFocusMode())); |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1693 | if (mFocusAreaSupported) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1694 | mCameraSettings.setFocusAreas(mFocusManager.getFocusAreas()); |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1695 | } |
| 1696 | } |
| 1697 | } |
| 1698 | updateAutoFocusMoveCallback(); |
| 1699 | } |
| 1700 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1701 | @Override |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1702 | public void resume() { |
Spike Sprague | 51c877c | 2014-02-18 11:14:12 -0800 | [diff] [blame] | 1703 | if (isVideoCaptureIntent()) { |
| 1704 | mDontResetIntentUiOnResume = mPaused; |
| 1705 | } |
| 1706 | |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1707 | mPaused = false; |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1708 | installIntentFilter(); |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 1709 | mAppController.setShutterEnabled(false); |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 1710 | mZoomValue = 1.0f; |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1711 | |
Senpo Hu | 0bdc4b5 | 2014-11-17 22:56:31 -0800 | [diff] [blame] | 1712 | OrientationManager orientationManager = mAppController.getOrientationManager(); |
| 1713 | orientationManager.addOnOrientationChangeListener(this); |
| 1714 | mUI.onOrientationChanged(orientationManager, orientationManager.getDeviceOrientation()); |
| 1715 | |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1716 | showVideoSnapshotUI(false); |
| 1717 | |
| 1718 | if (!mPreviewing) { |
| 1719 | requestCamera(mCameraId); |
| 1720 | } else { |
| 1721 | // preview already started |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 1722 | mAppController.setShutterEnabled(true); |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1723 | } |
| 1724 | |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1725 | if (mFocusManager != null) { |
| 1726 | // If camera is not open when resume is called, focus manager will not |
| 1727 | // be initialized yet, in which case it will start listening to |
| 1728 | // preview area size change later in the initialization. |
| 1729 | mAppController.addPreviewAreaSizeChangedListener(mFocusManager); |
| 1730 | } |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 1731 | |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1732 | if (mPreviewing) { |
| 1733 | mOnResumeTime = SystemClock.uptimeMillis(); |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1734 | mHandler.sendEmptyMessageDelayed(MSG_CHECK_DISPLAY_ROTATION, 100); |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1735 | } |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1736 | getServices().getMemoryManager().addListener(this); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | @Override |
| 1740 | public void pause() { |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1741 | mPaused = true; |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1742 | |
Senpo Hu | 0bdc4b5 | 2014-11-17 22:56:31 -0800 | [diff] [blame] | 1743 | mAppController.getOrientationManager().removeOnOrientationChangeListener(this); |
| 1744 | |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1745 | if (mFocusManager != null) { |
| 1746 | // If camera is not open when resume is called, focus manager will not |
| 1747 | // be initialized yet, in which case it will start listening to |
| 1748 | // preview area size change later in the initialization. |
| 1749 | mAppController.removePreviewAreaSizeChangedListener(mFocusManager); |
| 1750 | mFocusManager.removeMessages(); |
| 1751 | } |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1752 | if (mMediaRecorderRecording) { |
| 1753 | // Camera will be released in onStopVideoRecording. |
| 1754 | onStopVideoRecording(); |
| 1755 | } else { |
| 1756 | stopPreview(); |
| 1757 | closeCamera(); |
| 1758 | releaseMediaRecorder(); |
| 1759 | } |
| 1760 | |
| 1761 | closeVideoFileDescriptor(); |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1762 | |
| 1763 | if (mReceiver != null) { |
| 1764 | mActivity.unregisterReceiver(mReceiver); |
| 1765 | mReceiver = null; |
| 1766 | } |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1767 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1768 | mHandler.removeMessages(MSG_CHECK_DISPLAY_ROTATION); |
| 1769 | mHandler.removeMessages(MSG_SWITCH_CAMERA); |
| 1770 | mHandler.removeMessages(MSG_SWITCH_CAMERA_START_ANIMATION); |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1771 | mPendingSwitchCameraId = -1; |
| 1772 | mSwitchingCamera = false; |
| 1773 | mPreferenceRead = false; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1774 | getServices().getMemoryManager().removeListener(this); |
Alan Newberger | 7351415 | 2014-09-10 15:03:27 -0700 | [diff] [blame] | 1775 | mUI.onPause(); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | @Override |
| 1779 | public void destroy() { |
| 1780 | |
| 1781 | } |
| 1782 | |
| 1783 | @Override |
Angus Kong | 2f0e4a3 | 2013-12-03 10:02:35 -0800 | [diff] [blame] | 1784 | public void onLayoutOrientationChanged(boolean isLandscape) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1785 | setDisplayOrientation(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1786 | } |
| 1787 | |
Erin Dahlgren | a07e94c | 2013-12-04 18:44:08 -0800 | [diff] [blame] | 1788 | // TODO: integrate this into the SettingsManager listeners. |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1789 | public void onSharedPreferenceChanged() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1790 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | private void switchCamera() { |
Sascha Haeberling | f8b877c | 2013-09-09 17:32:48 -0700 | [diff] [blame] | 1794 | if (mPaused) { |
| 1795 | return; |
| 1796 | } |
Erin Dahlgren | bd3da26 | 2013-12-02 11:48:13 -0800 | [diff] [blame] | 1797 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1798 | |
| 1799 | Log.d(TAG, "Start to switch camera."); |
| 1800 | mCameraId = mPendingSwitchCameraId; |
| 1801 | mPendingSwitchCameraId = -1; |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 1802 | settingsManager.set(mAppController.getModuleScope(), |
| 1803 | Keys.KEY_CAMERA_ID, mCameraId); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1804 | |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1805 | if (mFocusManager != null) { |
| 1806 | mFocusManager.removeMessages(); |
| 1807 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1808 | closeCamera(); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1809 | requestCamera(mCameraId); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1810 | |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 1811 | mMirror = isCameraFrontFacing(); |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1812 | if (mFocusManager != null) { |
| 1813 | mFocusManager.setMirror(mMirror); |
| 1814 | } |
| 1815 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1816 | // From onResume |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 1817 | mZoomValue = 1.0f; |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 1818 | mUI.setOrientationIndicator(0, false); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1819 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1820 | // Start switch camera animation. Post a message because |
| 1821 | // onFrameAvailable from the old camera may already exist. |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1822 | mHandler.sendEmptyMessage(MSG_SWITCH_CAMERA_START_ANIMATION); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1823 | mUI.updateOnScreenIndicators(mCameraSettings); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1824 | } |
| 1825 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1826 | private void initializeVideoSnapshot() { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1827 | if (mCameraSettings == null) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 1828 | return; |
| 1829 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | void showVideoSnapshotUI(boolean enabled) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1833 | if (mCameraSettings == null) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 1834 | return; |
| 1835 | } |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 1836 | if (mCameraCapabilities.supports(CameraCapabilities.Feature.VIDEO_SNAPSHOT) && |
| 1837 | !mIsVideoCaptureIntent) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1838 | if (enabled) { |
Senpo Hu | 427a915 | 2014-11-19 17:11:46 -0800 | [diff] [blame] | 1839 | mAppController.startFlashAnimation(false); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1840 | } else { |
Doris Liu | 6827ce2 | 2013-03-12 19:24:28 -0700 | [diff] [blame] | 1841 | mUI.showPreviewBorder(enabled); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1842 | } |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 1843 | mAppController.setShutterEnabled(!enabled); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1844 | } |
| 1845 | } |
| 1846 | |
Erin Dahlgren | fce8a0b | 2013-12-12 17:36:32 -0800 | [diff] [blame] | 1847 | /** |
| 1848 | * Used to update the flash mode. Video mode can turn on the flash as torch |
| 1849 | * mode, which we would like to turn on and off when we switching in and |
| 1850 | * out to the preview. |
| 1851 | * |
| 1852 | * @param enable Whether torch mode can be enabled. |
| 1853 | */ |
| 1854 | private void enableTorchMode(boolean enable) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1855 | if (mCameraSettings.getCurrentFlashMode() == null) { |
Erin Dahlgren | fce8a0b | 2013-12-12 17:36:32 -0800 | [diff] [blame] | 1856 | return; |
| 1857 | } |
| 1858 | |
Erin Dahlgren | bd3da26 | 2013-12-02 11:48:13 -0800 | [diff] [blame] | 1859 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
| 1860 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1861 | CameraCapabilities.Stringifier stringifier = mCameraCapabilities.getStringifier(); |
| 1862 | CameraCapabilities.FlashMode flashMode; |
Erin Dahlgren | fce8a0b | 2013-12-12 17:36:32 -0800 | [diff] [blame] | 1863 | if (enable) { |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 1864 | flashMode = stringifier |
| 1865 | .flashModeFromString(settingsManager.getString(mAppController.getCameraScope(), |
| 1866 | Keys.KEY_VIDEOCAMERA_FLASH_MODE)); |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 1867 | } else { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1868 | flashMode = CameraCapabilities.FlashMode.OFF; |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 1869 | } |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1870 | if (mCameraCapabilities.supports(flashMode)) { |
| 1871 | mCameraSettings.setFlashMode(flashMode); |
| 1872 | } |
| 1873 | /* TODO: Find out how to deal with the following code piece: |
| 1874 | else { |
| 1875 | flashMode = mCameraSettings.getCurrentFlashMode(); |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 1876 | if (flashMode == null) { |
| 1877 | flashMode = mActivity.getString( |
| 1878 | R.string.pref_camera_flashmode_no_flash); |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 1879 | mParameters.setFlashMode(flashMode); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1880 | } |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1881 | }*/ |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 1882 | if (mCameraDevice != null) { |
| 1883 | mCameraDevice.applySettings(mCameraSettings); |
| 1884 | } |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1885 | mUI.updateOnScreenIndicators(mCameraSettings); |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1888 | @Override |
Sascha Haeberling | 8c1a922 | 2014-02-25 09:38:06 -0800 | [diff] [blame] | 1889 | public void onPreviewVisibilityChanged(int visibility) { |
Erin Dahlgren | fce8a0b | 2013-12-12 17:36:32 -0800 | [diff] [blame] | 1890 | if (mPreviewing) { |
Sascha Haeberling | 8c1a922 | 2014-02-25 09:38:06 -0800 | [diff] [blame] | 1891 | enableTorchMode(visibility == ModuleController.VISIBILITY_VISIBLE); |
Erin Dahlgren | fce8a0b | 2013-12-12 17:36:32 -0800 | [diff] [blame] | 1892 | } |
Erin Dahlgren | 3044d8c | 2013-10-10 18:23:45 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 1895 | private final class JpegPictureCallback implements CameraPictureCallback { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1896 | Location mLocation; |
| 1897 | |
| 1898 | public JpegPictureCallback(Location loc) { |
| 1899 | mLocation = loc; |
| 1900 | } |
| 1901 | |
| 1902 | @Override |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 1903 | public void onPictureTaken(byte [] jpegData, CameraProxy camera) { |
Doris Liu | 057b21a | 2014-04-25 17:35:27 -0700 | [diff] [blame] | 1904 | Log.i(TAG, "Video snapshot taken."); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1905 | mSnapshotInProgress = false; |
| 1906 | showVideoSnapshotUI(false); |
| 1907 | storeImage(jpegData, mLocation); |
| 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | private void storeImage(final byte[] data, Location loc) { |
| 1912 | long dateTaken = System.currentTimeMillis(); |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 1913 | String title = CameraUtil.createJpegName(dateTaken); |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 1914 | ExifInterface exif = Exif.getExif(data); |
| 1915 | int orientation = Exif.getOrientation(exif); |
Doris Liu | 6df2d96 | 2013-08-20 16:31:29 -0700 | [diff] [blame] | 1916 | |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 1917 | String flashSetting = mActivity.getSettingsManager() |
| 1918 | .getString(mAppController.getCameraScope(), Keys.KEY_VIDEOCAMERA_FLASH_MODE); |
| 1919 | Boolean gridLinesOn = Keys.areGridLinesOn(mActivity.getSettingsManager()); |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1920 | UsageStatistics.instance().photoCaptureDoneEvent( |
| 1921 | eventprotos.NavigationChange.Mode.VIDEO_STILL, title + ".jpeg", exif, |
Andy Huibers | b7c7d9a | 2014-06-18 22:26:14 -0700 | [diff] [blame] | 1922 | isCameraFrontFacing(), false, currentZoomValue(), flashSetting, gridLinesOn, |
| 1923 | null, null, null); |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1924 | |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 1925 | getServices().getMediaSaver().addImage( |
Doris Liu | 6df2d96 | 2013-08-20 16:31:29 -0700 | [diff] [blame] | 1926 | data, title, dateTaken, loc, orientation, |
Angus Kong | 83a99ae | 2013-04-17 15:37:07 -0700 | [diff] [blame] | 1927 | exif, mOnPhotoSavedListener, mContentResolver); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1928 | } |
| 1929 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1930 | private String convertOutputFormatToMimeType(int outputFileFormat) { |
| 1931 | if (outputFileFormat == MediaRecorder.OutputFormat.MPEG_4) { |
| 1932 | return "video/mp4"; |
| 1933 | } |
| 1934 | return "video/3gpp"; |
| 1935 | } |
| 1936 | |
| 1937 | private String convertOutputFormatToFileExt(int outputFileFormat) { |
| 1938 | if (outputFileFormat == MediaRecorder.OutputFormat.MPEG_4) { |
| 1939 | return ".mp4"; |
| 1940 | } |
| 1941 | return ".3gp"; |
| 1942 | } |
| 1943 | |
| 1944 | private void closeVideoFileDescriptor() { |
| 1945 | if (mVideoFileDescriptor != null) { |
| 1946 | try { |
| 1947 | mVideoFileDescriptor.close(); |
| 1948 | } catch (IOException e) { |
| 1949 | Log.e(TAG, "Fail to close fd", e); |
| 1950 | } |
| 1951 | mVideoFileDescriptor = null; |
| 1952 | } |
| 1953 | } |
| 1954 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1955 | @Override |
Angus Kong | 395ee2d | 2013-07-15 12:42:41 -0700 | [diff] [blame] | 1956 | public void onPreviewUIReady() { |
| 1957 | startPreview(); |
| 1958 | } |
| 1959 | |
| 1960 | @Override |
| 1961 | public void onPreviewUIDestroyed() { |
| 1962 | stopPreview(); |
| 1963 | } |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1964 | |
| 1965 | private void requestCamera(int id) { |
| 1966 | mActivity.getCameraProvider().requestCamera(id); |
| 1967 | } |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1968 | |
| 1969 | @Override |
| 1970 | public void onMemoryStateChanged(int state) { |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 1971 | mAppController.setShutterEnabled(state == MemoryManager.STATE_OK); |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | @Override |
| 1975 | public void onLowMemory() { |
| 1976 | // Not much we can do in the video module. |
| 1977 | } |
| 1978 | |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1979 | /***********************FocusOverlayManager Listener****************************/ |
| 1980 | @Override |
| 1981 | public void autoFocus() { |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 1982 | if (mCameraDevice != null) { |
| 1983 | mCameraDevice.autoFocus(mHandler, mAutoFocusCallback); |
| 1984 | } |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | @Override |
| 1988 | public void cancelAutoFocus() { |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 1989 | if (mCameraDevice != null) { |
| 1990 | mCameraDevice.cancelAutoFocus(); |
| 1991 | setFocusParameters(); |
| 1992 | } |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | @Override |
| 1996 | public boolean capture() { |
| 1997 | return false; |
| 1998 | } |
| 1999 | |
| 2000 | @Override |
| 2001 | public void startFaceDetection() { |
| 2002 | |
| 2003 | } |
| 2004 | |
| 2005 | @Override |
| 2006 | public void stopFaceDetection() { |
| 2007 | |
| 2008 | } |
| 2009 | |
| 2010 | @Override |
| 2011 | public void setFocusParameters() { |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 2012 | if (mCameraDevice != null) { |
| 2013 | updateFocusParameters(); |
| 2014 | mCameraDevice.applySettings(mCameraSettings); |
| 2015 | } |
Doris Liu | a1ec04a | 2014-01-13 17:29:40 -0800 | [diff] [blame] | 2016 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2017 | } |