summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/layout/video_module.xml10
-rw-r--r--res/xml/video_preferences.xml7
-rw-r--r--src/com/android/camera/VideoMenu.java1
-rw-r--r--src/com/android/camera/VideoModule.java52
-rw-r--r--src/com/android/camera/VideoUI.java82
5 files changed, 150 insertions, 2 deletions
diff --git a/res/layout/video_module.xml b/res/layout/video_module.xml
index 561539e..c6a9d7e 100644
--- a/res/layout/video_module.xml
+++ b/res/layout/video_module.xml
@@ -28,6 +28,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
+ <FrameLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <ViewStub android:id="@+id/face_view_stub"
+ android:inflatedId="@+id/face_view"
+ android:layout="@layout/face_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="gone"/>
+ </FrameLayout>
<View
android:id="@+id/preview_cover"
android:layout_width="match_parent"
diff --git a/res/xml/video_preferences.xml b/res/xml/video_preferences.xml
index dc37901..00b55c6 100644
--- a/res/xml/video_preferences.xml
+++ b/res/xml/video_preferences.xml
@@ -124,6 +124,13 @@
camera:singleIcon="@drawable/ic_settings_filter"
camera:entryValues="@array/pref_camera_coloreffect_entryvalues" />
<IconListPreference
+ camera:key="pref_camera_facedetection_key"
+ camera:defaultValue="@string/pref_camera_facedetection_default"
+ camera:title="@string/pref_camera_facedetection_title"
+ camera:entries="@array/pref_camera_facedetection_entries"
+ camera:singleIcon="@drawable/ic_settings_facerec"
+ camera:entryValues="@array/pref_camera_facedetection_entryvalues" />
+ <IconListPreference
camera:key="pref_camera_hfr_key"
camera:defaultValue="@string/pref_camera_hfr_default"
camera:title="@string/pref_camera_hfr_title"
diff --git a/src/com/android/camera/VideoMenu.java b/src/com/android/camera/VideoMenu.java
index d42c248..6670253 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 fc75487..b8537c2 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 6a8612c..01a7f70 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
+ }
}