diff options
author | Mike Dodd <mdodd@google.com> | 2011-05-18 10:21:58 -0700 |
---|---|---|
committer | Mike Dodd <mdodd@google.com> | 2011-05-18 10:21:58 -0700 |
commit | 195a467ffa319cc37c90b7c1ad5ae2a1ed0c5baf (patch) | |
tree | 9bd2db14bcb06fc4425f6bea00e080697c237a9a | |
parent | c9bc9958cc1f0261cb0c87070d9e8e00558f9b52 (diff) | |
download | experimental-195a467ffa319cc37c90b7c1ad5ae2a1ed0c5baf.tar.gz |
Video chat test app update for rotation.
Include an 'auto' checkbox to allow setting the display orientation
to whatever is correct for the camera info and device orientation.
This should match what Talk itself does.
Don't assume rear camera ID == 0, front == 1. Instead get the camera
info to determine which camera to use. Again, this should now match
what Talk does.
Change-Id: I2932ce1cd567e5e62bbc9e8fc95e0a35499e123f
3 files changed, 82 insertions, 17 deletions
diff --git a/CameraPreviewTest/res/layout/videochatcameratest_activity.xml b/CameraPreviewTest/res/layout/videochatcameratest_activity.xml index 9932bf3..cebff29 100644 --- a/CameraPreviewTest/res/layout/videochatcameratest_activity.xml +++ b/CameraPreviewTest/res/layout/videochatcameratest_activity.xml @@ -129,6 +129,11 @@ android:layout_height="wrap_content" android:text="@string/rotate270" android:checked="false" /> + <CheckBox android:id="@+id/rotateautocheckbox" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/rotateauto" + android:checked="true" /> </LinearLayout> <CheckBox android:id="@+id/repeatcheckbox" diff --git a/CameraPreviewTest/res/values/strings.xml b/CameraPreviewTest/res/values/strings.xml index af359e0..c1598b4 100644 --- a/CameraPreviewTest/res/values/strings.xml +++ b/CameraPreviewTest/res/values/strings.xml @@ -34,6 +34,7 @@ <string name="rotate90">90</string> <string name="rotate180">180</string> <string name="rotate270">270</string> + <string name="rotateauto">auto</string> <string name="forever">Repeat forever</string> </resources> diff --git a/CameraPreviewTest/src/com/example/android/videochatcameratest/VideoChatTestActivity.java b/CameraPreviewTest/src/com/example/android/videochatcameratest/VideoChatTestActivity.java index 87a2fe7..50879cf 100644 --- a/CameraPreviewTest/src/com/example/android/videochatcameratest/VideoChatTestActivity.java +++ b/CameraPreviewTest/src/com/example/android/videochatcameratest/VideoChatTestActivity.java @@ -23,6 +23,7 @@ import android.hardware.Camera.Size; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; +import android.view.Surface; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; @@ -61,6 +62,7 @@ public class VideoChatTestActivity extends Activity { ((TextView)findViewById(R.id.statushistory)).setVerticalScrollBarEnabled(true); mTextStatusHistory = (TextView) findViewById(R.id.statushistory); + logMessage("Display Orientation " + getDisplayOrientation()); for (int i = 0; i < Camera.getNumberOfCameras(); i++) { dumpCameraCaps(i); } @@ -108,23 +110,46 @@ public class VideoChatTestActivity extends Activity { super.onResume(); } + private int getDisplayOrientation() { + int rotation = getWindowManager().getDefaultDisplay().getRotation(); + int degrees = 0; + switch (rotation) { + case Surface.ROTATION_0: + degrees = 0; + break; + case Surface.ROTATION_90: + degrees = 90; + break; + case Surface.ROTATION_180: + degrees = 180; + break; + case Surface.ROTATION_270: + degrees = 270; + break; + } + return degrees; + } + /** * A call-back for when the user presses the back button. */ OnClickListener mGoListener = new OnClickListener() { - + @Override public void onClick(View v) { - new CameraTestRunner().execute(); + int degrees = getDisplayOrientation(); + new CameraTestRunner().execute(new Integer[] { degrees }); } }; - private class CameraTestRunner extends AsyncTask<Void, String, Void> { + private class CameraTestRunner extends AsyncTask<Integer, String, Void> { TextView mTextStatus; TextView mTextStatusHistory; + private int mDisplayOrientation; @Override - protected Void doInBackground(Void... params) { + protected Void doInBackground(Integer... params) { + mDisplayOrientation = params[0]; mTextStatus = (TextView) findViewById(R.id.status); mTextStatusHistory = (TextView) findViewById(R.id.statushistory); boolean testFrontCamera = @@ -138,6 +163,7 @@ public class VideoChatTestActivity extends Activity { boolean testRotate90 = ((CheckBox) findViewById(R.id.rotate90checkbox)).isChecked(); boolean testRotate180 = ((CheckBox) findViewById(R.id.rotate180checkbox)).isChecked(); boolean testRotate270 = ((CheckBox) findViewById(R.id.rotate270checkbox)).isChecked(); + boolean testRotateAuto = ((CheckBox) findViewById(R.id.rotateautocheckbox)).isChecked(); ArrayList<Integer> setDisplayOrentationAngles = new ArrayList<Integer>(); @@ -153,23 +179,39 @@ public class VideoChatTestActivity extends Activity { if (testRotate270) { setDisplayOrentationAngles.add(270); } + if (testRotateAuto) { + setDisplayOrentationAngles.add(-1); + } final int widths[] = new int[] {320, 640}; final int heights[] = new int[] {240, 480}; final int framerates[] = new int[] {15, 30}; - do { - for (int whichCamera = 0; whichCamera < 2; whichCamera++) { - if (whichCamera == 0 && !testBackCamera) { - continue; + ArrayList<Integer> whichCameras = new ArrayList<Integer>(); + int numCameras = Camera.getNumberOfCameras(); + if (testFrontCamera) { + for (int i = 0; i < numCameras; i++) { + Camera.CameraInfo info = new Camera.CameraInfo(); + Camera.getCameraInfo(i, info); + if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { + whichCameras.add(i); + break; } - - - if (whichCamera == 1 && !testFrontCamera) { - continue; + } + } + if (testBackCamera) { + for (int i = 0; i < numCameras; i++) { + Camera.CameraInfo info = new Camera.CameraInfo(); + Camera.getCameraInfo(i, info); + if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { + whichCameras.add(i); + break; } - + } + } + do { + for (Integer whichCamera : whichCameras) { for (int whichResolution = 0; whichResolution < 2; whichResolution++) { if (whichResolution == 0 && !testQVGA) { continue; @@ -233,6 +275,23 @@ public class VideoChatTestActivity extends Activity { camera.addCallbackBuffer(cameraBuffer); } } + + private int getAutoDisplayOrientation(int displayOrientationDegrees, + int cameraId, android.hardware.Camera camera) { + android.hardware.Camera.CameraInfo info = + new android.hardware.Camera.CameraInfo(); + android.hardware.Camera.getCameraInfo(cameraId, info); + + int result; + if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { + result = (info.orientation + displayOrientationDegrees) % 360; + result = (360 - result) % 360; // compensate the mirror + } else { // back-facing + result = (info.orientation - displayOrientationDegrees + 360) % 360; + } + return result; + } + protected void TestCamera(int whichCamera, int width, int height, int frameRate, @@ -258,7 +317,6 @@ public class VideoChatTestActivity extends Activity { status = exception.toString(); return; } - camera.startPreview(); camera.setPreviewCallbackWithBuffer(null); Camera.Parameters parameters = camera.getParameters(); @@ -269,9 +327,7 @@ public class VideoChatTestActivity extends Activity { parameters.setPreviewFormat(ImageFormat.NV21); parameters.setPreviewFrameRate(frameRate); - camera.stopPreview(); camera.setParameters(parameters); - camera.startPreview(); publishProgress("Validating preview parameters " + baseStatus); @@ -307,7 +363,6 @@ public class VideoChatTestActivity extends Activity { succeeded = false; throw new UnsupportedOperationException(status); } - camera.stopPreview(); FrameCatcher catcher = new FrameCatcher(setSize.width, setSize.height); @@ -330,6 +385,10 @@ public class VideoChatTestActivity extends Activity { for (int i = 0; i < numPasses; i++) { if (doSetDisplayOrientation) { int rotation = setDisplayOrentationAngles.get(i); + if (rotation == -1) { + rotation = getAutoDisplayOrientation(mDisplayOrientation, + whichCamera, camera); + } publishProgress("setDisplayOrientation to " + rotation); try { camera.setDisplayOrientation(rotation); |