diff options
-rw-r--r-- | res/raw/backdropper.graph | 3 | ||||
-rw-r--r-- | res/raw/goofy_face.graph | 3 | ||||
-rw-r--r-- | src/com/android/camera/EffectsRecorder.java | 43 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 4 |
4 files changed, 50 insertions, 3 deletions
diff --git a/res/raw/backdropper.graph b/res/raw/backdropper.graph index 25c86e6..6a3f641 100644 --- a/res/raw/backdropper.graph +++ b/res/raw/backdropper.graph @@ -75,7 +75,8 @@ audioSource = $audioSource; recordingProfile = $recordingProfile; recording = false; - // outputFile, orientationHint, listeners will be set when recording starts + // outputFile, orientationHint, inputRegion, listeners + // will be set when recording starts } // Connections ----------------------------------------------- diff --git a/res/raw/goofy_face.graph b/res/raw/goofy_face.graph index 430c811..fe2c5d9 100644 --- a/res/raw/goofy_face.graph +++ b/res/raw/goofy_face.graph @@ -99,7 +99,8 @@ audioSource = $audioSource; recordingProfile = $recordingProfile; recording = false; - // outputFile, orientationHint, listeners will be set when recording starts + // outputFile, orientationHint, inputRegion, listeners + // will be set when recording starts } // Connections ----------------------------------------------- diff --git a/src/com/android/camera/EffectsRecorder.java b/src/com/android/camera/EffectsRecorder.java index f177387..94a3740 100644 --- a/src/com/android/camera/EffectsRecorder.java +++ b/src/com/android/camera/EffectsRecorder.java @@ -22,6 +22,8 @@ import android.filterfw.core.Filter; import android.filterfw.core.GLEnvironment; import android.filterfw.core.GraphRunner; import android.filterfw.core.GraphRunner.OnRunnerDoneListener; +import android.filterfw.geometry.Point; +import android.filterfw.geometry.Quad; import android.filterpacks.videosrc.SurfaceTextureSource.SurfaceTextureSourceListener; import android.filterpacks.videoproc.BackDropperFilter; import android.filterpacks.videoproc.BackDropperFilter.LearningDoneListener; @@ -78,6 +80,7 @@ public class EffectsRecorder { private String mOutputFile; private int mOrientationHint = 0; + private int mCameraFacing = Camera.CameraInfo.CAMERA_FACING_BACK; private int mEffect = EFFECT_NONE; private int mCurrentEffect = EFFECT_NONE; @@ -229,6 +232,31 @@ public class EffectsRecorder { } } + private void setRecordingOrientation() { + if ( mState <= STATE_PREVIEW && mRunner != null ) { + Point bl = new Point(0, 0); + Point br = new Point(1, 0); + Point tl = new Point(0, 1); + Point tr = new Point(1, 1); + Quad recordingRegion; + if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_BACK) { + // The back camera is not mirrored, so use a identity transform + recordingRegion = new Quad(bl, br, tl, tr); + } else { + // Recording region needs to be tweaked for front cameras, since they + // mirror their preview + if (mOrientationHint == 0 || mOrientationHint == 180) { + // Horizontal flip in landscape + recordingRegion = new Quad(br, bl, tr, tl); + } else { + // Horizontal flip in portrait + recordingRegion = new Quad(tl, tr, bl, br); + } + } + Filter recorder = mRunner.getGraph().getFilter("recorder"); + recorder.setInputValue("inputRegion", recordingRegion); + } + } public void setOrientationHint(int degrees) { switch (mState) { case STATE_RELEASED: @@ -241,6 +269,19 @@ public class EffectsRecorder { mOrientationHint = degrees; setFaceDetectOrientation(degrees); + setRecordingOrientation(); + } + + public void setCameraFacing(int facing) { + switch (mState) { + case STATE_RELEASED: + throw new RuntimeException( + "setCameraFacing called on alrady released recorder!"); + default: + break; + } + mCameraFacing = facing; + setRecordingOrientation(); } public void setOnInfoListener(MediaRecorder.OnInfoListener infoListener) { @@ -297,6 +338,7 @@ public class EffectsRecorder { Log.v(TAG, "Effect initializing. Preview size " + mPreviewWidth + ", " + mPreviewHeight); } + mGraphEnv.addReferences( "previewSurface", mPreviewSurfaceHolder.getSurface(), "previewWidth", mPreviewWidth, @@ -355,6 +397,7 @@ public class EffectsRecorder { break; } setFaceDetectOrientation(mOrientationHint); + setRecordingOrientation(); } public synchronized void startPreview() { diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 8deaaa3..aa90f55 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -1223,9 +1223,12 @@ public class VideoCamera extends ActivityBase // If the mCameraDevice is null, then this activity is going to finish if (mCameraDevice == null) return; + CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId]; + mEffectsRecorder = new EffectsRecorder(this); mEffectsRecorder.setCamera(mCameraDevice); + mEffectsRecorder.setCameraFacing(info.facing); mEffectsRecorder.setProfile(mProfile); mEffectsRecorder.setEffectsListener(this); mEffectsRecorder.setOnInfoListener(this); @@ -1235,7 +1238,6 @@ public class VideoCamera extends ActivityBase // documentation. int rotation = 0; if (mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) { - CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId]; rotation = (info.orientation + mOrientation) % 360; } mEffectsRecorder.setOrientationHint(rotation); |