CameraLatency.java revision b76ece241964df73be366a8e4d9d7e2c8bbbf4a7
1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.camera.stress; 18 19import com.android.camera.Camera; 20 21import java.io.BufferedWriter; 22import java.io.FileWriter; 23 24import android.app.Instrumentation; 25import android.test.ActivityInstrumentationTestCase2; 26import android.test.suitebuilder.annotation.LargeTest; 27import android.util.Log; 28import android.view.KeyEvent; 29 30/** 31 * Junit / Instrumentation test case for camera test 32 * 33 */ 34 35public class CameraLatency extends ActivityInstrumentationTestCase2 <Camera> { 36 private String TAG = "CameraLatency"; 37 private static final int TOTAL_NUMBER_OF_IMAGECAPTURE = 20; 38 private static final long WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN = 4000; 39 private static final String CAMERA_TEST_OUTPUT_FILE = "/sdcard/mediaStressOut.txt"; 40 41 private long mTotalAutoFocusTime; 42 private long mTotalShutterLag; 43 private long mTotalShutterToPictureDisplayedTime; 44 private long mTotalPictureDisplayedToJpegCallbackTime; 45 private long mTotalJpegCallbackToFirstFrameTime; 46 private long mAvgAutoFocusTime; 47 private long mAvgShutterLag = mTotalShutterLag; 48 private long mAvgShutterToPictureDisplayedTime; 49 private long mAvgPictureDisplayedToJpegCallbackTime; 50 private long mAvgJpegCallbackToFirstFrameTime; 51 52 public CameraLatency() { 53 super("com.google.android.camera", Camera.class); 54 } 55 56 @Override 57 protected void setUp() throws Exception { 58 getActivity(); 59 super.setUp(); 60 } 61 62 @Override 63 protected void tearDown() throws Exception { 64 super.tearDown(); 65 } 66 67 @LargeTest 68 public void testImageCapture() { 69 Log.v(TAG, "start testImageCapture test"); 70 Instrumentation inst = getInstrumentation(); 71 try { 72 for (int i = 0; i < TOTAL_NUMBER_OF_IMAGECAPTURE; i++) { 73 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); 74 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP); 75 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); 76 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); 77 //skip the first measurement 78 if (i != 0) { 79 Camera c = getActivity(); 80 mTotalAutoFocusTime += c.mAutoFocusTime; 81 mTotalShutterLag += c.mShutterLag; 82 mTotalShutterToPictureDisplayedTime += 83 c.mShutterToPictureDisplayedTime; 84 mTotalPictureDisplayedToJpegCallbackTime += 85 c.mPictureDisplayedToJpegCallbackTime; 86 mTotalJpegCallbackToFirstFrameTime += c.mJpegCallbackToFirstFrameTime; 87 } 88 } 89 } catch (Exception e) { 90 Log.v(TAG, e.toString()); 91 } 92 //ToDO: yslau 93 //1) Need to get the baseline from the cupcake so that we can add the 94 //failure condition of the camera latency. 95 //2) Only count those number with succesful capture. Set the timer to invalid 96 //before capture and ignore them if the value is invalid 97 int numberofRun = TOTAL_NUMBER_OF_IMAGECAPTURE - 1; 98 mAvgAutoFocusTime = mTotalAutoFocusTime / numberofRun; 99 mAvgShutterLag = mTotalShutterLag / numberofRun; 100 mAvgShutterToPictureDisplayedTime = 101 mTotalShutterToPictureDisplayedTime / numberofRun; 102 mAvgPictureDisplayedToJpegCallbackTime = 103 mTotalPictureDisplayedToJpegCallbackTime / numberofRun; 104 mAvgJpegCallbackToFirstFrameTime = 105 mTotalJpegCallbackToFirstFrameTime / numberofRun; 106 107 try { 108 FileWriter fstream = null; 109 fstream = new FileWriter(CAMERA_TEST_OUTPUT_FILE, true); 110 BufferedWriter out = new BufferedWriter(fstream); 111 out.write("Camera Latency : \n"); 112 out.write("Number of loop: " + TOTAL_NUMBER_OF_IMAGECAPTURE + "\n"); 113 out.write("Avg AutoFocus = " + mAvgAutoFocusTime + "\n"); 114 out.write("Avg mShutterLag = " + mAvgShutterLag + "\n"); 115 out.write("Avg mShutterToPictureDisplayedTime = " 116 + mAvgShutterToPictureDisplayedTime + "\n"); 117 out.write("Avg mPictureDisplayedToJpegCallbackTime = " 118 + mAvgPictureDisplayedToJpegCallbackTime + "\n"); 119 out.write("Avg mJpegCallbackToFirstFrameTime = " + 120 mAvgJpegCallbackToFirstFrameTime + "\n"); 121 out.close(); 122 fstream.close(); 123 } catch (Exception e) { 124 fail("Camera Latency write output to file"); 125 } 126 Log.v(TAG, "The Image capture wait time = " + 127 WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); 128 Log.v(TAG, "Avg AutoFocus = " + mAvgAutoFocusTime); 129 Log.v(TAG, "Avg mShutterLag = " + mAvgShutterLag); 130 Log.v(TAG, "Avg mShutterToPictureDisplayedTime = " 131 + mAvgShutterToPictureDisplayedTime); 132 Log.v(TAG, "Avg mPictureDisplayedToJpegCallbackTime = " 133 + mAvgPictureDisplayedToJpegCallbackTime); 134 Log.v(TAG, "Avg mJpegCallbackToFirstFrameTime = " + mAvgJpegCallbackToFirstFrameTime); 135 assertTrue("testImageCapture", true); 136 } 137} 138 139