From 7252fd0c4d3597a51d51f2e0bb554f0406628fb6 Mon Sep 17 00:00:00 2001 From: Jay Wang Date: Thu, 25 Feb 2016 14:23:02 -0800 Subject: SnapdragonCamera: Add face detection icon to video Add video face detection to developer option CRs-Fixed: 978207 Change-Id: I9308573a5a1004fc3803a955bc96f495ecbfc6c7 --- src/com/android/camera/VideoMenu.java | 1 + src/com/android/camera/VideoModule.java | 52 +++++++++++++++++++++ src/com/android/camera/VideoUI.java | 82 ++++++++++++++++++++++++++++++++- 3 files changed, 133 insertions(+), 2 deletions(-) (limited to 'src/com/android/camera') diff --git a/src/com/android/camera/VideoMenu.java b/src/com/android/camera/VideoMenu.java index 05e0a7c8e..a7eb7306c 100644 --- a/src/com/android/camera/VideoMenu.java +++ b/src/com/android/camera/VideoMenu.java @@ -123,6 +123,7 @@ public class VideoMenu extends MenuController CameraSettings.KEY_RECORD_LOCATION, CameraSettings.KEY_CAMERA_SAVEPATH, CameraSettings.KEY_WHITE_BALANCE, + CameraSettings.KEY_FACE_DETECTION, CameraSettings.KEY_VIDEO_HIGH_FRAME_RATE, CameraSettings.KEY_SEE_MORE, CameraSettings.KEY_NOISE_REDUCTION, diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java index 64cb814e9..5efe02ace 100644 --- a/src/com/android/camera/VideoModule.java +++ b/src/com/android/camera/VideoModule.java @@ -209,6 +209,9 @@ public class VideoModule implements CameraModule, private boolean mIsMute = false; private boolean mWasMute = false; + private boolean mFaceDetectionEnabled = false; + private boolean mFaceDetectionStarted = false; + private final MediaSaveService.OnMediaSavedListener mOnVideoSavedListener = new MediaSaveService.OnMediaSavedListener() { @Override @@ -1190,6 +1193,7 @@ public class VideoModule implements CameraModule, private void onPreviewStarted() { mUI.enableShutter(true); + startFaceDetection(); } @Override @@ -1204,6 +1208,7 @@ public class VideoModule implements CameraModule, mPreviewing = false; mStopPrevPending = false; mUI.enableShutter(false); + stopFaceDetection(); } private void closeCamera() { @@ -1214,11 +1219,13 @@ public class VideoModule implements CameraModule, } mCameraDevice.setZoomChangeListener(null); mCameraDevice.setErrorCallback(null); + mCameraDevice.setFaceDetectionCallback(null, null); CameraHolder.instance().release(); mCameraDevice = null; mPreviewing = false; mSnapshotInProgress = false; mPreviewFocused = false; + mFaceDetectionStarted = false; } private void releasePreviewResources() { @@ -2475,6 +2482,23 @@ public class VideoModule implements CameraModule, //set power mode settings updatePowerMode(); + + // 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") @@ -2926,4 +2950,32 @@ public class VideoModule implements CameraModule, } } + + 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 be76e7115..17d472fff 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; @@ -43,10 +45,13 @@ import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; +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; @@ -61,7 +66,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 CameraActivity mActivity; @@ -118,6 +124,12 @@ public class VideoUI implements PieRenderer.PieListener, private int mBottomMargin = 0; private RotateImageView mMuteButton; + //Face detection + private FaceView mFaceView; + private SurfaceTextureSizeChangedListener mSurfaceTextureSizeListener; + private float mSurfaceTextureUncroppedWidth; + private float mSurfaceTextureUncroppedHeight; + private OnLayoutChangeListener mLayoutListener = new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, @@ -256,6 +268,15 @@ public class VideoUI implements PieRenderer.PieListener, initializeControlByIntent(); initializeOverlay(); 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; @@ -279,6 +300,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); @@ -394,7 +419,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; @@ -438,10 +463,29 @@ 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); + } + } + } /** @@ -546,6 +590,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(); @@ -1163,4 +1211,34 @@ public class VideoUI implements PieRenderer.PieListener, public void adjustOrientation() { setOrientation(mOrientation, false); } + + @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(); + } + } } -- cgit v1.2.3