diff options
author | Jay Wang <jaywang@codeaurora.org> | 2016-02-25 14:23:02 -0800 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2016-08-25 21:55:20 -0700 |
commit | ec8173bc779d50a81aefead62798090bab2b254e (patch) | |
tree | 4d62d6beb7c302baf6f1b64e1e00e18198ae9ff7 /src/com/android | |
parent | d9a3ac812c46f5dcc21754edbc6df484ea4b1231 (diff) | |
download | android_packages_apps_Snap-ec8173bc779d50a81aefead62798090bab2b254e.tar.gz android_packages_apps_Snap-ec8173bc779d50a81aefead62798090bab2b254e.tar.bz2 android_packages_apps_Snap-ec8173bc779d50a81aefead62798090bab2b254e.zip |
SnapdragonCamera: Add face detection icon to video
Add video face detection to developer option
CRs-Fixed: 978207
Change-Id: I9308573a5a1004fc3803a955bc96f495ecbfc6c7
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/camera/VideoMenu.java | 1 | ||||
-rw-r--r-- | src/com/android/camera/VideoModule.java | 52 | ||||
-rw-r--r-- | src/com/android/camera/VideoUI.java | 82 |
3 files changed, 133 insertions, 2 deletions
diff --git a/src/com/android/camera/VideoMenu.java b/src/com/android/camera/VideoMenu.java index d42c24835..667025303 100644 --- a/src/com/android/camera/VideoMenu.java +++ b/src/com/android/camera/VideoMenu.java @@ -131,6 +131,7 @@ public class VideoMenu extends MenuController CameraSettings.KEY_CAMERA_SAVEPATH, CameraSettings.KEY_EXPOSURE, CameraSettings.KEY_WHITE_BALANCE, + CameraSettings.KEY_FACE_DETECTION, CameraSettings.KEY_VIDEO_HIGH_FRAME_RATE, CameraSettings.KEY_POWER_SHUTTER, CameraSettings.KEY_MAX_BRIGHTNESS, diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java index fc7548790..b8537c2b5 100644 --- a/src/com/android/camera/VideoModule.java +++ b/src/com/android/camera/VideoModule.java @@ -217,6 +217,9 @@ public class VideoModule implements CameraModule, // The preview window is on focus private boolean mPreviewFocused = false; + private boolean mFaceDetectionEnabled = false; + private boolean mFaceDetectionStarted = false; + private final MediaSaveService.OnMediaSavedListener mOnVideoSavedListener = new MediaSaveService.OnMediaSavedListener() { @Override @@ -1293,6 +1296,7 @@ public class VideoModule implements CameraModule, private void onPreviewStarted() { mUI.enableShutter(true); + startFaceDetection(); } @Override @@ -1309,6 +1313,7 @@ public class VideoModule implements CameraModule, mPreviewing = false; mStopPrevPending = false; mUI.enableShutter(false); + stopFaceDetection(); } private void closeCamera() { @@ -1319,12 +1324,14 @@ public class VideoModule implements CameraModule, } mCameraDevice.setZoomChangeListener(null); mCameraDevice.setErrorCallback(null); + mCameraDevice.setFaceDetectionCallback(null, null); CameraHolder.instance().release(); mCameraDevice = null; mPreviewing = false; mSnapshotInProgress = false; mFocusManager.onCameraReleased(); mPreviewFocused = false; + mFaceDetectionStarted = false; } private void releasePreviewResources() { @@ -2643,6 +2650,23 @@ public class VideoModule implements CameraModule, mFocusManager.setFocusTime(Integer.decode( mPreferences.getString(CameraSettings.KEY_VIDEOCAMERA_FOCUS_TIME, mActivity.getString(R.string.pref_camera_video_focustime_default)))); + + // Set face detetction parameter. + String faceDetection = mPreferences.getString( + CameraSettings.KEY_FACE_DETECTION, + mActivity.getString(R.string.pref_camera_facedetection_default)); + + if (CameraUtil.isSupported(faceDetection, mParameters.getSupportedFaceDetectionModes())) { + Log.d(TAG, "setFaceDetectionMode "+faceDetection); + mParameters.setFaceDetectionMode(faceDetection); + if(faceDetection.equals("on") && mFaceDetectionEnabled == false) { + mFaceDetectionEnabled = true; + startFaceDetection(); + } else if(faceDetection.equals("off") && mFaceDetectionEnabled == true) { + stopFaceDetection(); + mFaceDetectionEnabled = false; + } + } } @SuppressWarnings("deprecation") @@ -3084,5 +3108,33 @@ public class VideoModule implements CameraModule, enableRecordingLocation(false); } + + public void startFaceDetection() { + if (mCameraDevice == null) return; + + if (mFaceDetectionEnabled == false + || mFaceDetectionStarted) return; + if (mParameters.getMaxNumDetectedFaces() > 0) { + mFaceDetectionStarted = true; + CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId]; + mUI.onStartFaceDetection(mCameraDisplayOrientation, + (info.facing == CameraInfo.CAMERA_FACING_FRONT)); + mCameraDevice.setFaceDetectionCallback(mHandler, mUI); + Log.d(TAG, "start face detection Video "+mParameters.getMaxNumDetectedFaces()); + mCameraDevice.startFaceDetection(); + } + } + + public void stopFaceDetection() { + Log.d(TAG, "stop face detection"); + if (mFaceDetectionEnabled == false || !mFaceDetectionStarted) return; + if (mParameters.getMaxNumDetectedFaces() > 0) { + mFaceDetectionStarted = false; + mCameraDevice.setFaceDetectionCallback(null, null); + mUI.pauseFaceDetection(); + mCameraDevice.stopFaceDetection(); + mUI.onStopFaceDetection(); + } + } } diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java index 6a8612cad..01a7f70a9 100644 --- a/src/com/android/camera/VideoUI.java +++ b/src/com/android/camera/VideoUI.java @@ -26,6 +26,7 @@ import android.graphics.Color; import android.graphics.Point; import android.graphics.drawable.ColorDrawable; import android.hardware.Camera.Parameters; +import android.hardware.Camera.Face; import android.util.Log; import android.view.Gravity; import android.view.MotionEvent; @@ -35,6 +36,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLayoutChangeListener; import android.view.ViewGroup; +import android.view.ViewStub; import android.widget.FrameLayout; import android.widget.FrameLayout.LayoutParams; import android.widget.ImageView; @@ -44,10 +46,13 @@ import android.widget.PopupWindow; import android.widget.TextView; import android.view.View.OnLayoutChangeListener; +import com.android.camera.CameraManager.CameraProxy; import com.android.camera.CameraPreference.OnPreferenceChangedListener; +import com.android.camera.PhotoUI.SurfaceTextureSizeChangedListener; import com.android.camera.ui.AbstractSettingPopup; import com.android.camera.ui.CameraControls; import com.android.camera.ui.CameraRootView; +import com.android.camera.ui.FaceView; import com.android.camera.ui.ListSubMenu; import com.android.camera.ui.ModuleSwitcher; import com.android.camera.ui.PieRenderer; @@ -62,7 +67,8 @@ public class VideoUI implements PieRenderer.PieListener, PreviewGestures.SingleTapListener, CameraRootView.MyDisplayListener, SurfaceHolder.Callback, - PauseButton.OnPauseButtonListener { + PauseButton.OnPauseButtonListener, + CameraManager.CameraFaceDetectionCallback{ private static final String TAG = "CAM_VideoUI"; // module fields private final FocusRing mFocusRing; @@ -123,6 +129,12 @@ public class VideoUI implements PieRenderer.PieListener, SURFACE_VIEW; } + //Face detection + private FaceView mFaceView; + private SurfaceTextureSizeChangedListener mSurfaceTextureSizeListener; + private float mSurfaceTextureUncroppedWidth; + private float mSurfaceTextureUncroppedHeight; + public void showPreviewCover() { mPreviewCover.setVisibility(View.VISIBLE); } @@ -248,6 +260,15 @@ public class VideoUI implements PieRenderer.PieListener, initializeOverlay(); initializeControlByIntent(); initializePauseButton(); + + mCameraControls = (CameraControls) mRootView.findViewById(R.id.camera_controls); + ViewStub faceViewStub = (ViewStub) mRootView + .findViewById(R.id.face_view_stub); + if (faceViewStub != null) { + faceViewStub.inflate(); + mFaceView = (FaceView) mRootView.findViewById(R.id.face_view); + setSurfaceTextureSizeChangedListener(mFaceView); + } mAnimationManager = new AnimationManager(); mOrientationResize = false; mPrevOrientationResize = false; @@ -271,6 +292,10 @@ public class VideoUI implements PieRenderer.PieListener, mOrientationResize = orientation; } + public void setSurfaceTextureSizeChangedListener(SurfaceTextureSizeChangedListener listener) { + mSurfaceTextureSizeListener = listener; + } + public void initializeSurfaceView() { if (mSurfaceView == null) { mSurfaceView = new SurfaceView(mActivity); @@ -381,7 +406,7 @@ public class VideoUI implements PieRenderer.PieListener, scaledTextureHeight = l * 3 / 4; break; } - } else if (mMaxPreviewWidth != 0 && mMaxPreviewHeight != 0) { + } else { float width = mMaxPreviewWidth, height = mMaxPreviewHeight; if (mOrientationResize) { scaledTextureWidth = height * mAspectRatio; @@ -425,9 +450,27 @@ public class VideoUI implements PieRenderer.PieListener, } } + if (mSurfaceTextureUncroppedWidth != scaledTextureWidth || + mSurfaceTextureUncroppedHeight != scaledTextureHeight) { + mSurfaceTextureUncroppedWidth = scaledTextureWidth; + mSurfaceTextureUncroppedHeight = scaledTextureHeight; + if (mSurfaceTextureSizeListener != null) { + mSurfaceTextureSizeListener.onSurfaceTextureSizeChanged( + (int) mSurfaceTextureUncroppedWidth, + (int) mSurfaceTextureUncroppedHeight); + Log.d(TAG, "mSurfaceTextureUncroppedWidth=" + mSurfaceTextureUncroppedWidth + + "mSurfaceTextureUncroppedHeight=" + mSurfaceTextureUncroppedHeight); + } + } + + if(lp != null) { mSurfaceView.setLayoutParams(lp); mSurfaceView.requestLayout(); + if (mFaceView != null) { + mFaceView.setLayoutParams(lp); + } + } if (scaledTextureWidth > 0 && scaledTextureHeight > 0) { @@ -538,6 +581,10 @@ public class VideoUI implements PieRenderer.PieListener, } public void setDisplayOrientation(int orientation) { + if (mFaceView != null) { + mFaceView.setDisplayOrientation(orientation); + } + if ((mPreviewOrientation == -1 || mPreviewOrientation != orientation) && mVideoMenu != null && mVideoMenu.isPreviewMenuBeingShown()) { dismissSceneModeMenu(); @@ -1149,4 +1196,35 @@ public class VideoUI implements PieRenderer.PieListener, public FocusRing getFocusRing() { return mFocusRing; } + + @Override + public void onFaceDetection(Face[] faces, CameraProxy camera) { + Log.d(TAG, "onFacedetectopmn"); + mFaceView.setFaces(faces); + } + + public void pauseFaceDetection() { + if (mFaceView != null) mFaceView.pause(); + } + + public void resumeFaceDetection() { + if (mFaceView != null) mFaceView.resume(); + } + + public void onStartFaceDetection(int orientation, boolean mirror) { + mFaceView.setBlockDraw(false); + mFaceView.clear(); + mFaceView.setVisibility(View.VISIBLE); + mFaceView.setDisplayOrientation(orientation); + mFaceView.setMirror(mirror); + mFaceView.resume(); + } + + public void onStopFaceDetection() { + if (mFaceView != null) { + mFaceView.setBlockDraw(true); + mFaceView.clear(); + } +>>>>>>> 7252fd0... SnapdragonCamera: Add face detection icon to video + } } |