1 /* Copyright (c) 2012-2013, The Linux Foundataion. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer in the documentation and/or other materials provided 11 * with the distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #ifndef QCAMERA_TEST_H 31 #define QCAMERA_TEST_H 32 33 namespace qcamera { 34 35 using namespace android; 36 37 typedef enum qcamera_test_cmds_t { 38 SWITCH_CAMERA_CMD = 'A', 39 RESUME_PREVIEW_CMD = '[', 40 START_PREVIEW_CMD = '1', 41 STOP_PREVIEW_CMD = '2', 42 CHANGE_PREVIEW_SIZE_CMD = '4', 43 CHANGE_PICTURE_SIZE_CMD = '5', 44 DUMP_CAPS_CMD = 'E', 45 AUTOFOCUS_CMD = 'f', 46 TAKEPICTURE_CMD = 'p', 47 ENABLE_PRV_CALLBACKS_CMD = '&', 48 EXIT_CMD = 'q' 49 } qcamera_test_cmds; 50 51 class CameraContext : public CameraListener { 52 public: 53 CameraContext(int cameraIndex)54 CameraContext(int cameraIndex) : 55 mCameraIndex(cameraIndex), 56 mResizePreview(true), 57 mHardwareActive(false), 58 mPreviewRunning(false), 59 mCamera(NULL), 60 mClient(NULL), 61 mSurfaceControl(NULL), 62 mPreviewSurface(NULL) {} 63 64 status_t openCamera(); 65 status_t closeCamera(); 66 67 status_t startPreview(); 68 status_t stopPreview(); 69 status_t resumePreview(); 70 status_t autoFocus(); 71 status_t enablePreviewCallbacks(); 72 status_t takePicture(); 73 74 status_t nextPreviewSize(); 75 status_t getCurrentPreviewSize(Size &previewSize); 76 77 status_t nextPictureSize(); 78 status_t getCurrentPictureSize(Size &pictureSize); 79 80 void printSupportedParams(); 81 getCameraIndex()82 int getCameraIndex() { return mCameraIndex; } 83 int getNumberOfCameras(); 84 85 virtual ~CameraContext(); 86 87 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2); 88 virtual void postData(int32_t msgType, 89 const sp<IMemory>& dataPtr, 90 camera_frame_metadata_t *metadata); 91 92 virtual void postDataTimestamp(nsecs_t timestamp, 93 int32_t msgType, 94 const sp<IMemory>& dataPtr); 95 96 private: 97 98 status_t createPreviewSurface(unsigned int width, 99 unsigned int height, 100 int32_t pixFormat); 101 status_t destroyPreviewSurface(); 102 103 status_t saveFile(const sp<IMemory>& mem, String8 path); 104 void previewCallback(const sp<IMemory>& mem); 105 106 static int JpegIdx; 107 int mCameraIndex; 108 bool mResizePreview; 109 bool mHardwareActive; 110 bool mPreviewRunning; 111 112 sp<Camera> mCamera; 113 sp<SurfaceComposerClient> mClient; 114 sp<SurfaceControl> mSurfaceControl; 115 sp<Surface> mPreviewSurface; 116 CameraParameters mParams; 117 118 int mCurrentPreviewSizeIdx; 119 int mCurrentPictureSizeIdx; 120 Vector<Size> mSupportedPreviewSizes; 121 Vector<Size> mSupportedPictureSizes; 122 }; 123 124 }; //namespace qcamera 125 126 #endif 127