• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef CAMERA_TEST_H
2 #define CAMERA_TEST_H
3 
4 #ifdef ANDROID_API_JB_OR_LATER
5 #include <gui/Surface.h>
6 #include <gui/SurfaceComposerClient.h>
7 #else
8 #include <surfaceflinger/Surface.h>
9 #include <surfaceflinger/ISurface.h>
10 #include <surfaceflinger/ISurfaceComposer.h>
11 #include <surfaceflinger/ISurfaceComposerClient.h>
12 #include <surfaceflinger/SurfaceComposerClient.h>
13 #endif
14 
15 #ifdef ANDROID_API_JB_OR_LATER
16 #   define CAMHAL_LOGV            ALOGV
17 #   define CAMHAL_LOGE            ALOGE
18 #   define PRINTOVER(arg...)      ALOGD(#arg)
19 #   define LOG_FUNCTION_NAME      ALOGD("%d: %s() ENTER", __LINE__, __FUNCTION__);
20 #   define LOG_FUNCTION_NAME_EXIT ALOGD("%d: %s() EXIT", __LINE__, __FUNCTION__);
21 #else
22 #   define CAMHAL_LOGV            LOGV
23 #   define CAMHAL_LOGE            LOGE
24 #   define PRINTOVER(arg...)      LOGD(#arg)
25 #   define LOG_FUNCTION_NAME      LOGD("%d: %s() ENTER", __LINE__, __FUNCTION__);
26 #   define LOG_FUNCTION_NAME_EXIT LOGD("%d: %s() EXIT", __LINE__, __FUNCTION__);
27 #endif
28 
29 #define KEY_GBCE            "gbce"
30 #define KEY_GLBCE           "glbce"
31 #define KEY_CAMERA          "camera-index"
32 #define KEY_SATURATION      "saturation"
33 #define KEY_BRIGHTNESS      "brightness"
34 #define KEY_TI_BURST           "burst-capture"
35 #define KEY_EXPOSURE        "exposure"
36 #define KEY_CONTRAST        "contrast"
37 #define KEY_SHARPNESS       "sharpness"
38 #define KEY_ISO             "iso"
39 #define KEY_CAF             "caf"
40 #define KEY_MODE            "mode"
41 #define KEY_VNF             "vnf"
42 #define KEY_VSTAB           "vstab"
43 #define KEY_COMPENSATION    "exposure-compensation"
44 #define KEY_SENSOR_ORIENTATION "sensor-orientation"
45 
46 #define KEY_IPP             "ipp"
47 
48 #define KEY_BUFF_STARV      "buff-starvation"
49 #define KEY_METERING_MODE   "meter-mode"
50 #define KEY_AUTOCONVERGENCE "auto-convergence-mode"
51 #define KEY_MANUAL_CONVERGENCE "manual-convergence"
52 #define KEY_EXP_BRACKETING_RANGE "exp-bracketing-range"
53 #define KEY_EXP_GAIN_BRACKETING_RANGE "exp-gain-bracketing-range"
54 #define KEY_TEMP_BRACKETING "temporal-bracketing"
55 #define KEY_TEMP_BRACKETING_POS "temporal-bracketing-range-positive"
56 #define KEY_TEMP_BRACKETING_NEG "temporal-bracketing-range-negative"
57 #define KEY_MEASUREMENT "measurement"
58 #define KEY_S3D2D_PREVIEW_MODE "s3d2d-preview"
59 #define KEY_S3D_PRV_FRAME_LAYOUT "s3d-prv-frame-layout"
60 #define KEY_S3D_CAP_FRAME_LAYOUT "s3d-cap-frame-layout"
61 #define KEY_EXIF_MODEL "exif-model"
62 #define KEY_EXIF_MAKE "exif-make"
63 #define KEY_AF_TIMEOUT "af-timeout"
64 
65 #define KEY_AUTO_EXPOSURE_LOCK "auto-exposure-lock"
66 #define KEY_AUTO_WHITEBALANCE_LOCK "auto-whitebalance-lock"
67 
68 #define KEY_MECHANICAL_MISALIGNMENT_CORRECTION "mechanical-misalignment-correction"
69 
70 //TI extensions for enable/disable algos
71 #define KEY_ALGO_FIXED_GAMMA            "ti-algo-fixed-gamma"
72 #define KEY_ALGO_NSF1                   "ti-algo-nsf1"
73 #define KEY_ALGO_NSF2                   "ti-algo-nsf2"
74 #define KEY_ALGO_SHARPENING             "ti-algo-sharpening"
75 #define KEY_ALGO_THREELINCOLORMAP       "ti-algo-threelinecolormap"
76 #define KEY_ALGO_GIC                    "ti-algo-gic"
77 
78 #define KEY_TAP_OUT_SURFACES            "tap-out"
79 #define KEY_TAP_IN_SURFACE              "tap-in"
80 
81 #define BRACKETING_IDX_DEFAULT          0
82 #define BRACKETING_IDX_STREAM           1
83 #define BRACKETING_STREAM_BUFFERS       9
84 
85 #define SDCARD_PATH "/sdcard/"
86 #define SECONDARY_SENSOR "_SEC"
87 #define S3D_SENSOR "_S3D"
88 
89 #define MAX_BURST   15
90 #define BURST_INC     5
91 #define TEMP_BRACKETING_MAX_RANGE 4
92 
93 #define MEDIASERVER_DUMP "procmem -w $(ps | grep mediaserver | grep -Eo '[0-9]+' | head -n 1) | grep \"\\(Name\\|libcamera.so\\|libOMX\\|libomxcameraadapter.so\\|librcm.so\\|libnotify.so\\|libipcutils.so\\|libipc.so\\|libsysmgr.so\\|TOTAL\\)\""
94 #define MEMORY_DUMP "procrank -u"
95 #define KEY_METERING_MODE   "meter-mode"
96 
97 #define TEST_FOCUS_AREA "(-1000,500,-500,1000,1000),(500,500,1000,1000,1)"
98 #define TEST_METERING_AREA "(-1000,500,-500,1000,1000),(500,500,1000,1000,1)"
99 #define TEST_METERING_AREA_CENTER "(-250,-250,250,250,1000)"
100 #define TEST_METERING_AREA_AVERAGE "(-1000,-1000,1000,1000,1000)"
101 
102 #define COMPENSATION_OFFSET 20
103 #define DELIMITER           "|"
104 
105 #define MODEL "camera_test"
106 #define MAKE "camera_test"
107 
108 #define BLAZE 0
109 #define BLAZE_TABLET1 1
110 #define BLAZE_TABLET2 2
111 
112 #define MAX_LINES    80
113 #define MAX_SYMBOLS  65
114 
115 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
116 
117 typedef enum test_type {
118     TEST_TYPE_REGRESSION,
119     TEST_TYPE_FUNCTIONAL,
120     TEST_TYPE_API,
121     TEST_TYPE_ERROR,
122 } test_type_t;
123 
124 typedef enum param_ExpBracketParamType_t {
125     PARAM_EXP_BRACKET_PARAM_NONE,
126     PARAM_EXP_BRACKET_PARAM_COMP,
127     PARAM_EXP_BRACKET_PARAM_PAIR,
128 } param_ExpBracketParamType;
129 
130 typedef enum param_ExpBracketValueType_t {
131     PARAM_EXP_BRACKET_VALUE_NONE,
132     PARAM_EXP_BRACKET_VALUE_ABS,
133     PARAM_EXP_BRACKET_VALUE_REL,
134 } param_ExpBracketValueType;
135 
136 typedef enum param_ExpBracketApplyType_t {
137     PARAM_EXP_BRACKET_APPLY_NONE,
138     PARAM_EXP_BRACKET_APPLY_ADJUST,
139     PARAM_EXP_BRACKET_APPLY_FORCED,
140 } param_ExpBracketApplyType;
141 
142 enum logging {
143     LOGGING_LOGCAT = 0x01,
144     LOGGING_SYSLINK = 0x02
145 };
146 
147 typedef struct cmd_args {
148     test_type_t test_type;
149     const char *script_file_name;
150     const char *output_path;
151     int platform_id;
152     int logging;
153 } cmd_args_t;
154 
155 namespace android {
156     class CameraHandler: public CameraListener {
157         public:
158             virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2);
159             virtual void postData(int32_t msgType,
160                                   const sp<IMemory>& dataPtr,
161                                   camera_frame_metadata_t *metadata);
162 
163             virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
164     };
165 
166 };
167 
168 using namespace android;
169 
170 
171 typedef struct pixel_format_t {
172     int32_t pixelFormatDesc;
173     const char *pixformat;
174 }pixel_format;
175 
176 typedef struct output_format_t {
177     output_format type;
178     const char *desc;
179 } outformat;
180 
181 typedef struct Vcapture_size_t {
182     int width, height;
183     const char *desc;
184 } Vcapture_size;
185 
186 typedef struct param_Array_t {
187     int width, height;
188     char name[60];
189 } param_Array;
190 
191 typedef struct video_Codecs_t {
192     video_encoder type;
193     const char *desc;
194 } video_Codecs;
195 
196 typedef struct audio_Codecs_t {
197     audio_encoder type;
198     const char *desc;
199 } audio_Codecs;
200 
201 typedef struct V_bitRate_t {
202     uint32_t bit_rate;
203     const char *desc;
204 } V_bitRate;
205 
206 typedef struct zoom_t {
207     int idx;
208     const char *zoom_description;
209 } Zoom;
210 
211 typedef struct fps_ranges_t {
212     int rangeMin;
213     int rangeMax;
214 } fps_Array;
215 
216 typedef struct buffer_info {
217     int size;
218     int width;
219     int height;
220     int format;
221     size_t offset;
222     Rect crop;
223     sp<GraphicBuffer> buf;
224 } buffer_info_t;
225 
226 typedef struct param_NamedExpBracketList_t {
227     const char *desc;
228     param_ExpBracketParamType_t param_type;
229     param_ExpBracketValueType_t value_type;
230     param_ExpBracketApplyType_t apply_type;
231     const char *value;
232 } param_NamedExpBracketList;
233 
234 
235 char * get_cycle_cmd(const char *aSrc);
236 void trim_script_cmd(char *cmd);
237 int execute_functional_script(char *script);
238 status_t dump_mem_status();
239 int openCamera();
240 int closeCamera();
241 void createBufferOutputSource();
242 void createBufferInputSource();
243 void requestBufferSourceReset();
244 void initDefaults();
245 void setDefaultExpGainPreset(ShotParameters &params, int idx);
246 void setSingleExpGainPreset(ShotParameters &params, int idx, int exp, int gain);
247 void setExpGainPreset(ShotParameters &params, const char *input, bool force, param_ExpBracketParamType_t type, bool flush);
248 void calcNextSingleExpGainPreset(int idx, int &exp, int &gain);
249 void updateShotConfigFlushParam();
250 int startPreview();
251 void stopPreview();
252 int startRecording();
253 int stopRecording();
254 int closeRecorder();
255 int openRecorder();
256 int configureRecorder();
257 void printSupportedParams();
258 char *load_script(const char *config);
259 int start_logging(int flags, int &pid);
260 int stop_logging(int flags, int &pid);
261 int execute_error_script(char *script);
262 int getParametersFromCapabilities();
263 void  getSizeParametersFromCapabilities();
264 int getDefaultParameter(const char* val, int numOptions, char **array);
265 int getDefaultParameterResol(const char* val, int numOptions, param_Array  **array);
266 int getSupportedParameters(char* parameters, int* optionsCount, char ***elem);
267 int getSupportedParametersCaptureSize(char* parameters, int *optionsCount, param_Array array[], int arraySize);
268 int getSupportedParametersVideoCaptureSize(char* parameters, int *optionsCount, param_Array array[], int arraySize);
269 int getSupportedParametersPreviewSize(char* parameters, int *optionsCount, param_Array array[], int arraySize);
270 int getSupportedParametersThumbnailSize(char* parameters, int *optionsCount, param_Array array[], int arraySize);
271 int getSupportedParametersNames(int width, int height, param_Array array[], int arraySize);
272 int checkSupportedParamScript(char **array, int size, char *param);
273 int checkSupportedParamScriptLayout(char **array, int size, char *param,int *index);
274 int checkSupportedParamScriptResol(param_Array **array, int size, char *param, int *num);
275 int checkSupportedParamScriptResol(param_Array **array, int size, int w, int h, int *num);
276 int getSupportedParametersfps(char* parameters, int *optionsCount);
277 int checkSupportedParamScriptfpsConst(int *array, int size, char *param, int *num);
278 int checkSupportedParamScriptfpsRange(char **array, int size, char *param, int *num);
279 int trySetVideoStabilization(bool toggle);
280 int trySetVideoNoiseFilter(bool toggle);
281 int trySetAutoExposureLock(bool toggle);
282 int trySetAutoWhiteBalanceLock(bool toggle);
283 bool isRawPixelFormat (const char *format);
284 int deleteAllocatedMemory();
285 void initDefaultsSec();
286 
287 const char KEY_S3D_PRV_FRAME_LAYOUT_VALUES[] = "s3d-prv-frame-layout-values";
288 const char KEY_S3D_CAP_FRAME_LAYOUT_VALUES[] = "s3d-cap-frame-layout-values";
289 
290 const char KEY_SUPPORTED_PICTURE_TOPBOTTOM_SIZES[] = "supported-picture-topbottom-size-values";
291 const char KEY_SUPPORTED_PREVIEW_TOPBOTTOM_SIZES[] = "supported-preview-topbottom-size-values";
292 const char KEY_SUPPORTED_PICTURE_SIDEBYSIDE_SIZES[] = "supported-picture-sidebyside-size-values";
293 const char KEY_SUPPORTED_PREVIEW_SIDEBYSIDE_SIZES[] = "supported-preview-sidebyside-size-values";
294 const char KEY_SUPPORTED_PICTURE_SUBSAMPLED_SIZES[] = "supported-picture-subsampled-size-values";
295 const char KEY_SUPPORTED_PREVIEW_SUBSAMPLED_SIZES[] = "supported-preview-subsampled-size-values";
296 
297 const char KEY_AUTOCONVERGENCE_MODE[] = "auto-convergence-mode";
298 const char KEY_AUTOCONVERGENCE_MODE_VALUES[] = "auto-convergence-mode-values";
299 
300 const char KEY_MANUAL_EXPOSURE[] = "manual-exposure";
301 const char KEY_MANUAL_GAIN_ISO[] = "manual-gain-iso";
302 const char KEY_MANUAL_EXPOSURE_RIGHT[] = "manual-exposure-right";
303 const char KEY_MANUAL_GAIN_ISO_RIGHT[] = "manual-gain-iso-right";
304 
305 const char KEY_SUPPORTED_MANUAL_CONVERGENCE_MIN[] = "supported-manual-convergence-min";
306 const char KEY_SUPPORTED_MANUAL_CONVERGENCE_MAX[] = "supported-manual-convergence-max";
307 const char KEY_SUPPORTED_MANUAL_CONVERGENCE_STEP[] = "supported-manual-convergence-step";
308 
309 const char KEY_SUPPORTED_MANUAL_EXPOSURE_MIN[] = "supported-manual-exposure-min";
310 const char KEY_SUPPORTED_MANUAL_EXPOSURE_MAX[] = "supported-manual-exposure-max";
311 const char KEY_SUPPORTED_MANUAL_EXPOSURE_STEP[] = "supported-manual-exposure-step";
312 
313 const char KEY_SUPPORTED_MANUAL_GAIN_ISO_MIN[] = "supported-manual-gain-iso-min";
314 const char KEY_SUPPORTED_MANUAL_GAIN_ISO_MAX[] = "supported-manual-gain-iso-max";
315 const char KEY_SUPPORTED_MANUAL_GAIN_ISO_STEP[] = "supported-manual-gain-iso-step";
316 
317 class BufferSourceThread : public Thread {
318 public:
319     class Defer : public Thread {
320         private:
321             struct DeferContainer {
322                 sp<GraphicBuffer> graphicBuffer;
323                 uint8_t *mappedBuffer;
324                 unsigned int count;
325                 unsigned int slot;
326                 Rect crop;
327             };
328         public:
Defer(BufferSourceThread * bst)329             Defer(BufferSourceThread* bst) :
330                     Thread(false), mBST(bst), mExiting(false) { }
~Defer()331             virtual ~Defer() {
332                 Mutex::Autolock lock(mFrameQueueMutex);
333                 mExiting = true;
334                 while (!mDeferQueue.isEmpty()) {
335                     DeferContainer defer = mDeferQueue.itemAt(0);
336                     defer.graphicBuffer->unlock();
337                     mDeferQueue.removeAt(0);
338                 }
339                 mFrameQueueCondition.signal();
340             }
341 
requestExit()342             virtual void requestExit() {
343                 Thread::requestExit();
344 
345                 mExiting = true;
346                 mFrameQueueCondition.signal();
347             }
348 
threadLoop()349             virtual bool threadLoop() {
350                 Mutex::Autolock lock(mFrameQueueMutex);
351                 while (mDeferQueue.isEmpty() && !mExiting) {
352                     mFrameQueueCondition.wait(mFrameQueueMutex);
353                 }
354 
355                 if (!mExiting) {
356                     DeferContainer defer = mDeferQueue.itemAt(0);
357                     printf ("=== handling buffer %d\n", defer.count);
358                     mBST->handleBuffer(defer.graphicBuffer, defer.mappedBuffer,
359                                        defer.count, defer.crop);
360                     defer.graphicBuffer->unlock();
361                     mDeferQueue.removeAt(0);
362                     mBST->onHandled(defer.graphicBuffer, defer.slot);
363                     return true;
364                 }
365                 return false;
366             }
367             void add(sp<GraphicBuffer> &gbuf, const Rect &crop,
368                      unsigned int count, unsigned int slot = 0) {
369                 Mutex::Autolock lock(mFrameQueueMutex);
370                 DeferContainer defer;
371                 defer.graphicBuffer = gbuf;
372                 defer.count = count;
373                 defer.slot = slot;
374                 defer.crop = crop;
375                 gbuf->lock(GRALLOC_USAGE_SW_READ_RARELY, (void**) &defer.mappedBuffer);
376                 mDeferQueue.add(defer);
377                 mFrameQueueCondition.signal();
378             }
379         private:
380             Vector<DeferContainer> mDeferQueue;
381             Mutex mFrameQueueMutex;
382             Condition mFrameQueueCondition;
383             BufferSourceThread* mBST;
384             bool mExiting;
385     };
386 public:
BufferSourceThread(sp<Camera> camera)387     BufferSourceThread(sp<Camera> camera) :
388                  Thread(false), mCamera(camera),
389                  mDestroying(false), mRestartCapture(false),
390                  mExpBracketIdx(BRACKETING_IDX_DEFAULT), mExp(0), mGain(0), mCounter(0),
391                  kReturnedBuffersMaxCapacity(6) {
392 
393         mDeferThread = new Defer(this);
394         mDeferThread->run();
395     }
396 
~BufferSourceThread()397     virtual ~BufferSourceThread() {
398         mDestroying = true;
399 
400         for (unsigned int i = 0; i < mReturnedBuffers.size(); i++) {
401             buffer_info_t info = mReturnedBuffers.itemAt(i);
402             mReturnedBuffers.removeAt(i);
403         }
404         mDeferThread->requestExit();
405         mDeferThread.clear();
406     }
407 
threadLoop()408     virtual bool threadLoop() { return false;}
requestExit()409     virtual void requestExit() {};
setBuffer(android::ShotParameters & params)410     virtual void setBuffer(android::ShotParameters &params) {};
onHandled(sp<GraphicBuffer> & g,unsigned int slot)411     virtual void onHandled(sp<GraphicBuffer> &g, unsigned int slot) {};
412 
setStreamCapture(bool restart,int expBracketIdx)413     bool setStreamCapture(bool restart, int expBracketIdx) {
414         Mutex::Autolock lock(mToggleStateMutex);
415         mExpBracketIdx = expBracketIdx;
416         mRestartCapture = restart;
417         return mRestartCapture;
418     }
419 
popBuffer()420     buffer_info_t popBuffer() {
421         buffer_info_t buffer;
422         Mutex::Autolock lock(mReturnedBuffersMutex);
423         if (!mReturnedBuffers.isEmpty()) {
424             buffer = mReturnedBuffers.itemAt(0);
425             mReturnedBuffers.removeAt(0);
426         }
427         return buffer;
428     }
429 
hasBuffer()430     bool hasBuffer() {
431         Mutex::Autolock lock(mReturnedBuffersMutex);
432         return !mReturnedBuffers.isEmpty();
433     }
434 
435     void handleBuffer(sp<GraphicBuffer> &, uint8_t *, unsigned int, const Rect &);
436     Rect getCrop(sp<GraphicBuffer> &buffer, const float *mtx);
437     void showMetadata(sp<IMemory> data);
438 protected:
restartCapture()439     void restartCapture() {
440         Mutex::Autolock lock(mToggleStateMutex);
441         if (mRestartCapture) {
442             ShotParameters shotParams;
443             calcNextSingleExpGainPreset(mExpBracketIdx, mExp, mGain),
444             setSingleExpGainPreset(shotParams, mExpBracketIdx, mExp, mGain);
445             shotParams.set(ShotParameters::KEY_BURST, 1);
446             mCamera->takePictureWithParameters(0, shotParams.flatten());
447         }
448     }
449 protected:
450     sp<Camera> mCamera;
451     bool mDestroying;
452     bool mRestartCapture;
453     int mExpBracketIdx;
454     int mExp;
455     int mGain;
456     sp<Defer> mDeferThread;
457     unsigned int mCounter;
458 private:
459     Vector<buffer_info_t> mReturnedBuffers;
460     Mutex mReturnedBuffersMutex;
461     Mutex mToggleStateMutex;
462     const unsigned int kReturnedBuffersMaxCapacity;
463 };
464 
465 
466 class BufferSourceInput : public RefBase {
467 public:
BufferSourceInput(sp<Camera> camera)468     BufferSourceInput(sp<Camera> camera) : mCamera(camera) {
469         mTapOut = new BufferSourceThread(camera);
470         mTapOut->run();
471     }
472 
~BufferSourceInput()473     virtual ~BufferSourceInput() {
474         mTapOut->requestExit();
475         mTapOut.clear();
476     }
477 
478     virtual void setInput(buffer_info_t, const char *format, ShotParameters &params);
479 
480 protected:
481     sp<BufferSourceThread> mTapOut;
482     sp<ANativeWindow> mWindowTapIn;
483     sp<Camera> mCamera;
484 };
485 #endif
486