• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*Copyright (c) 2016, The Linux Foundation. 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 #include "QCameraHAL3MainTestContext.h"
31 #include "QCameraHAL3SnapshotTest.h"
32 #include "QCameraHAL3RawSnapshotTest.h"
33 #include "QCameraHAL3PreviewTest.h"
34 
35 #ifdef QCAMERA_HAL3_SUPPORT
36 #define LIB_PATH /usr/lib/hw/camera.msm8953.so
37 #else
38 #define LIB_PATH /system/lib/hw/camera.msm8953.so
39 #endif
40 
41 extern "C" {
42 extern int set_camera_metadata_vendor_ops(const vendor_tag_ops_t *query_ops);
43 }
44 
45 /*#ifdef CAMERA_CHIPSET_8953
46 #define CHIPSET_LIB lib/hw/camera.msm8953.so
47 #else
48 #define CHIPSET_LIB lib/hw/camera.msm8937.so
49 #endif*/
50 
51 #define CAM_LIB(s) STR_LIB_PATH(s)
52 #define STR_LIB_PATH(s) #s
53 
54 namespace qcamera {
55 
56 QCameraHAL3PreviewTest *mPreviewtestCase = NULL;
57 QCameraHAL3VideoTest *mVideotestCase = NULL;
58 QCameraHAL3SnapshotTest *mSnapshottestCase = NULL;
59 QCameraHAL3RawSnapshotTest *mRawSnapshottestCase = NULL;
60 
61 struct timeval start_time;
62 int capture_received;
63 int pfd[2];
64 extern int test_case_end;
65 extern int snapshot_buffer;
66 
67 pthread_cond_t mRequestAppCond;
68 std::list<uint32_t> PreviewQueue;
69 std::list<uint32_t> VideoQueue;
70 
71 pthread_mutex_t TestAppLock = PTHREAD_MUTEX_INITIALIZER;
72 pthread_mutex_t mCaptureRequestLock = PTHREAD_MUTEX_INITIALIZER;
73 
74 
75 
camera_device_status_change(const struct camera_module_callbacks * callbacks,int camera_id,int new_status)76 static void camera_device_status_change(
77         const struct camera_module_callbacks* callbacks,
78         int camera_id, int new_status)
79 {
80     /* Stub function */
81     if (callbacks == NULL) {
82         LOGD("Parameters are NULL %d %d", camera_id, new_status);
83     }
84 }
85 
torch_mode_status_change(const struct camera_module_callbacks * callbacks,const char * camera_id,int new_status)86 static void torch_mode_status_change(
87         const struct camera_module_callbacks* callbacks,
88         const char* camera_id, int new_status)
89 {
90     /* Stub function */
91     if((callbacks == NULL) || (camera_id == NULL)) {
92         LOGD("Parameters are NULL %d", new_status);
93     }
94 }
95 
Notify(const camera3_callback_ops * cb,const camera3_notify_msg * msg)96 static void Notify(
97         const camera3_callback_ops *cb,
98         const camera3_notify_msg *msg)
99 {
100     /* Stub function */
101     if((cb == NULL) || (msg == NULL)) {
102         LOGD("Parameters are NULL ");
103     }
104 }
105 
ProcessCaptureResult(const camera3_callback_ops * cb,const camera3_capture_result * result)106 static void ProcessCaptureResult(
107         const camera3_callback_ops *cb,
108         const camera3_capture_result *result)
109 {
110     buffer_thread_msg_t msg;
111     extern CameraHAL3Base *mCamHal3Base;
112     int frame_num;
113     extern int req_sent;
114     extern int preview_buffer_allocated;
115     extern int video_buffer_allocated;
116     int num;
117     if(cb == NULL) {
118         LOGD("callback returned is NULL");
119     }
120     LOGD("Cam Capture Result Callback %d and %d",
121             result->num_output_buffers, mCamHal3Base->mFrameCount);
122     if (mCamHal3Base->mTestCaseSelected == MENU_START_PREVIEW ||
123             mCamHal3Base->mTestCaseSelected == MENU_START_VIDEO) {
124         if (result->num_output_buffers == 1) {
125             frame_num = result->frame_number;
126             LOGD("Frame width:%d and height:%d and format:%d",
127                     result->output_buffers->stream->width,
128                     result->output_buffers->stream->height,
129                     result->output_buffers->stream->format);
130             (mCamHal3Base->mFrameCount)++;
131             LOGD("Preview/Video Capture Result %d and fcount: %d and req_Sent:%d and %d ",
132             result->num_output_buffers, mCamHal3Base->mFrameCount, req_sent, result->frame_number);
133             if (test_case_end == 0) {
134                 if (mCamHal3Base->mTestCaseSelected == MENU_START_PREVIEW) {
135                     num = (result->frame_number)%preview_buffer_allocated;
136                     PreviewQueue.push_back(num);
137                 }
138                 else {
139                     num = (result->frame_number)%video_buffer_allocated;
140                            VideoQueue.push_back(num);
141                 }
142                 pthread_cond_signal(&mRequestAppCond);
143                 memset(&msg, 0, sizeof(buffer_thread_msg_t));
144             }
145         }
146     }
147     else {
148         extern int fcount_captured;
149         if (result->num_output_buffers == 1) {
150             LOGD("snapshot/Raw Capture1 Result Callback %d and %d",
151                     result->num_output_buffers, fcount_captured);
152             (mCamHal3Base->mFrameCount)++;
153             fcount_captured++;
154             LOGD("\n Capture %d done preparing for capture ", fcount_captured);
155             memset(&msg, 0, sizeof(buffer_thread_msg_t));
156             write(pfd[1], &msg, sizeof(buffer_thread_msg_t));
157         }
158     }
159 }
160 
CameraHAL3Base(int cameraIndex)161 CameraHAL3Base::CameraHAL3Base(int cameraIndex) :
162     mCameraIndex(cameraIndex),
163     mLibHandle(NULL),
164     mFrameCount(0),
165     mSecElapsed(1),
166     mTestCaseSelected(0),
167     mPreviewRunning(0),
168     mVideoRunning(0),
169     mSnapShotRunning(0)
170 {
171 
172 }
173 
174 
hal3appCameraTestLoad()175 int CameraHAL3Base::hal3appCameraTestLoad()
176 {
177     int rc = HAL3_CAM_OK;
178     int numCam;
179     int32_t res = 0;
180     hal3_camera_test_obj_t *my_test_obj;
181     mLibHandle = new hal3_camera_lib_test;
182     memset(mLibHandle, 0, sizeof(hal3_camera_lib_handle));
183     rc = hal3appTestLoad(&mLibHandle->app_obj);
184     camera_module_t *my_if_handle = mLibHandle->app_obj.hal3_lib.halModule_t;
185     if (HAL3_CAM_OK != rc) {
186         LOGE("hal3 err\n");
187         goto EXIT;
188     }
189 
190     numCam = my_if_handle->get_number_of_cameras();
191     printf("\n Number of Cameras are : %d ", numCam);
192     if (my_if_handle->get_vendor_tag_ops) {
193         mLibHandle->app_obj.mVendorTagOps = vendor_tag_ops_t();
194         my_if_handle->get_vendor_tag_ops(&(mLibHandle->app_obj.mVendorTagOps));
195 
196         res = set_camera_metadata_vendor_ops(&(mLibHandle->app_obj.mVendorTagOps));
197         if (0 != res) {
198             printf("%s: Could not set vendor tag descriptor, "
199                     "received error %s (%d). \n", __func__,
200                     strerror(-res), res);
201             goto EXIT;
202         }
203     }
204     my_test_obj = &(mLibHandle->test_obj);
205     my_test_obj->module_cb.torch_mode_status_change = &torch_mode_status_change;
206     my_test_obj->module_cb.camera_device_status_change = &camera_device_status_change;
207     my_if_handle->set_callbacks(&(my_test_obj->module_cb));
208     my_if_handle->get_camera_info(0, &(mLibHandle->test_obj.cam_info));
209     camcap_info = mLibHandle->test_obj.cam_info;
210     hal3app_cam_settings = (camcap_info.static_camera_characteristics);
211     display_capability();
212     return numCam;
213     EXIT:
214     return rc;
215 
216 }
217 
display_capability()218 void CameraHAL3Base::display_capability()
219 {
220     ALOGE("Camera Here");
221     int i,j;
222     int *available_ir_modes = NULL, *available_svhdr_mode = NULL, count_stream;
223     if(hal3app_cam_settings.exists(QCAMERA3_IR_AVAILABLE_MODES)) {
224         ALOGE("\n mrad check1 ");
225         entry_hal3app = hal3app_cam_settings.find(QCAMERA3_IR_AVAILABLE_MODES);
226         available_ir_modes = (int *) malloc((entry_hal3app.count)*sizeof(int ));
227         for(i =0;i < (int)entry_hal3app.count; i++){
228                     available_ir_modes[i] = entry_hal3app.data.i32[i];
229             ALOGE("\n mrad cap %d ", available_ir_modes[i]);
230 
231         }
232     }
233 }
234 
hal3appCameraLibOpen(int camid)235 int CameraHAL3Base::hal3appCameraLibOpen(int camid)
236 {
237     int rc;
238     rc = hal3appCamOpen(&mLibHandle->app_obj, (int)camid, &(mLibHandle->test_obj));
239     if (rc != HAL3_CAM_OK) {
240         LOGE("hal3appCamOpen() camidx=%d, err=%d\n",
241                 camid, rc);
242         goto EXIT;
243     }
244     rc = hal3appCamInitialize((int)camid, &mLibHandle->test_obj);
245     EXIT:
246     return rc;
247 }
248 
hal3appTestLoad(hal3_camera_app_t * my_hal3_app)249 int CameraHAL3Base::hal3appTestLoad(hal3_camera_app_t *my_hal3_app)
250 {
251     memset(&my_hal3_app->hal3_lib, 0, sizeof(hal3_interface_lib_t));
252     printf("\nLibrary path is :%s", CAM_LIB(LIB_PATH));
253     my_hal3_app->hal3_lib.ptr = dlopen(CAM_LIB(LIB_PATH), RTLD_NOW);
254 
255     if (!my_hal3_app->hal3_lib.ptr) {
256         LOGE("Error opening HAL libraries %s\n",
257                 dlerror());
258         return -HAL3_CAM_E_GENERAL;
259     }
260     my_hal3_app->hal3_lib.halModule_t =
261         (camera_module_t*)dlsym(my_hal3_app->hal3_lib.ptr, HAL_MODULE_INFO_SYM_AS_STR);
262     if (my_hal3_app->hal3_lib.halModule_t == NULL) {
263         LOGE("Error opening HAL library %s\n",
264                 dlerror());
265         return -HAL3_CAM_E_GENERAL;
266     }
267     return HAL3_CAM_OK;
268 }
269 
hal3appCamOpen(hal3_camera_app_t * my_hal3_app,int camid,hal3_camera_test_obj_t * my_test_obj)270 int CameraHAL3Base::hal3appCamOpen(
271         hal3_camera_app_t *my_hal3_app,
272         int camid,
273         hal3_camera_test_obj_t *my_test_obj)
274 {
275     camera_module_t *my_if_handle = my_hal3_app->hal3_lib.halModule_t;
276     my_if_handle->common.methods->open(&(my_if_handle->common), "0",
277             reinterpret_cast<hw_device_t**>(&(my_test_obj->device)));
278     printf("\n Camera ID %d Opened \n", camid);
279     return HAL3_CAM_OK;
280 }
281 
hal3appCamInitialize(int camid,hal3_camera_test_obj_t * my_test_obj)282 int CameraHAL3Base::hal3appCamInitialize(int camid, hal3_camera_test_obj_t *my_test_obj)
283 {
284     int rc = 0;
285     camera3_device_t *device_handle = my_test_obj->device;
286     my_test_obj->callback_ops.notify = &Notify;
287     my_test_obj->callback_ops.process_capture_result = &ProcessCaptureResult;
288     rc = device_handle->ops->initialize(my_test_obj->device, &(my_test_obj->callback_ops));
289     if (rc != HAL3_CAM_OK) {
290         LOGE("hal3appCamInitialize() camidx=%d, err=%d\n",
291                 camid, rc);
292         goto EXIT;
293     }
294     EXIT:
295     return rc;
296 }
297 
298 
hal3appCheckStream(int testcase,int camid)299 void CameraHAL3Base::hal3appCheckStream(int testcase, int camid)
300 {
301     if (testcase != MENU_START_PREVIEW) {
302         if (mPreviewtestCase != NULL) {
303             mPreviewtestCase->previewTestEnd(mLibHandle, camid);
304             delete mPreviewtestCase;
305             mPreviewtestCase = NULL;
306         }
307     }
308     if (testcase != MENU_START_VIDEO){
309         if (mVideotestCase != NULL) {
310             mVideotestCase->videoTestEnd(mLibHandle, camid);
311             delete mVideotestCase;
312             mVideotestCase = NULL;
313         }
314     }
315 
316     if (testcase != MENU_START_CAPTURE){
317         if (mSnapshottestCase != NULL) {
318             delete mSnapshottestCase;
319             mSnapshottestCase = NULL;
320         }
321     }
322 
323     if (testcase != MENU_START_RAW_CAPTURE) {
324         if (mRawSnapshottestCase != NULL) {
325             delete mRawSnapshottestCase;
326             mRawSnapshottestCase = NULL;
327         }
328     }
329 }
330 
331 
hal3appCameraPreviewInit(int testcase,int camid,int w,int h)332 int CameraHAL3Base::hal3appCameraPreviewInit(int testcase, int camid, int w, int h)
333 {
334     extern int req_sent;
335     int testCaseEndComplete = 0;
336     if (w == 0 || h == 0) {
337         printf("\n Frame dimension is wrong");
338         return -1;
339     }
340     if ( mPreviewtestCase != NULL) {
341         if(testcase == MENU_TOGGLE_IR_MODE) {
342             ALOGE("\n IR mode requested is :%d", ir_mode);
343             mPreviewtestCase->ir_mode = ir_mode;
344         }
345         if(testcase == MENU_TOGGLE_SVHDR_MODE) {
346             ALOGE("\n SVHDR mode requested is :%d", svhdr_mode);
347             mPreviewtestCase->svhdr_mode = svhdr_mode;
348         }
349         return 0;
350     }
351     else {
352         testCaseEndComplete = 0;
353         do {
354             if (mVideoRunning == 1) {
355                 hal3appCheckStream(MENU_START_PREVIEW, camid);
356             }
357             pthread_mutex_lock(&TestAppLock);
358             mTestCaseSelected = MENU_START_PREVIEW;
359             if (mVideoRunning != 1) {
360                 hal3appCheckStream(MENU_START_PREVIEW, camid);
361             }
362             mPreviewtestCase = new QCameraHAL3PreviewTest(0);
363             printf("\n\n Testing the Resolution : %d X %d", w, h);
364             req_sent = 0;
365             PreviewQueue.clear();
366             capture_received = 0; mSecElapsed = 1;
367             snapshot_buffer = -1; mFrameCount = 0;
368             mPreviewtestCase->width = w; mPreviewtestCase->height = h;
369             mPreviewtestCase->ir_mode = 0; mPreviewtestCase->svhdr_mode = 0;
370             mPreviewtestCase->initTest(mLibHandle,
371                     (int) MENU_START_PREVIEW, camid, w, h);
372             testCaseEndComplete = 1;
373         }while(testCaseEndComplete != 1);
374     }
375     return 0;
376 }
377 
hal3appCameraVideoInit(int testcase,int camid,int w,int h)378 int CameraHAL3Base::hal3appCameraVideoInit(int testcase, int camid, int w, int h)
379 {
380     extern int req_sent;
381     int testCaseEndComplete = 0;
382     if (w == 0 || h == 0) {
383         printf("\n Frame dimension is wrong");
384         return -1;
385     }
386 
387     if (mVideotestCase != NULL) {
388         LOGD("testcase is : %d", testcase);
389         return 0;
390     }
391     else {
392         testCaseEndComplete = 0;
393         do {
394             if (mPreviewRunning == 1) {
395                 hal3appCheckStream(MENU_START_VIDEO, camid);
396             }
397             pthread_mutex_lock(&TestAppLock);
398             mTestCaseSelected = MENU_START_VIDEO;
399             if (mPreviewRunning != 1) {
400                 hal3appCheckStream(MENU_START_VIDEO, camid);
401             }
402             mVideotestCase = new QCameraHAL3VideoTest(0);
403             VideoQueue.clear();
404             printf("\n\nTesting the Resolution : %d X %d", w, h);
405             req_sent = 0;
406             capture_received =0; mSecElapsed = 1; test_case_end = 0;
407             mVideotestCase->width = w; mVideotestCase->height = h;
408             snapshot_buffer = -1; mFrameCount = 0;
409             mVideotestCase->initTest(mLibHandle,
410                     (int) MENU_START_VIDEO, camid, w, h);
411             testCaseEndComplete = 1;
412         }while(testCaseEndComplete !=1);
413     }
414     return 0;
415 }
416 
417 
hal3appRawCaptureInit(hal3_camera_lib_test * handle,int camid,int req_cap)418 int CameraHAL3Base::hal3appRawCaptureInit(hal3_camera_lib_test *handle, int camid, int req_cap)
419 {
420     int testCaseEndComplete = 0;
421     if(handle == NULL) {
422         LOGE("Camera Handle is NULL");
423     }
424     if (mSnapShotRunning != 1) {
425         hal3appCheckStream(MENU_START_RAW_CAPTURE, camid);
426     }
427     testCaseEndComplete = 0;
428     do {
429         pthread_mutex_lock(&TestAppLock);
430         if (mSnapShotRunning == 1) {
431             hal3appCheckStream(MENU_START_RAW_CAPTURE, camid);
432         }
433         printf("\n capture:%d", req_cap);
434         mTestCaseSelected = MENU_START_RAW_CAPTURE;
435         mRawSnapshottestCase = new QCameraHAL3RawSnapshotTest(req_cap);
436         mRawSnapshottestCase->mRequestedCapture = req_cap;
437         mRawSnapshottestCase->initTest(mLibHandle,
438         (int) MENU_START_RAW_CAPTURE, camid, RAWSNAPSHOT_CAPTURE_WIDTH,
439                 RAWSNAPSHOT_CAPTURE_HEIGHT);
440         testCaseEndComplete = 1;
441     }while(testCaseEndComplete !=1);
442     return 0;
443 }
444 
hal3appCameraCaptureInit(hal3_camera_lib_test * handle,int camid,int req_cap)445 int CameraHAL3Base::hal3appCameraCaptureInit(hal3_camera_lib_test *handle,
446         int camid, int req_cap)
447 {
448     int testCaseEndComplete = 0;
449     if(handle == NULL) {
450         LOGE("Camera Handle is NULL");
451     }
452     if (mSnapShotRunning != 1) {
453         hal3appCheckStream(MENU_START_CAPTURE, camid);
454     }
455     testCaseEndComplete = 0;
456     do {
457         pthread_mutex_lock(&TestAppLock);
458         if (mSnapShotRunning == 1) {
459             hal3appCheckStream(MENU_START_CAPTURE, camid);
460         }
461         printf("\n capture:%d", req_cap);
462         mTestCaseSelected = MENU_START_CAPTURE;
463         mSnapshottestCase = new QCameraHAL3SnapshotTest(req_cap);
464         mSnapshottestCase->mRequestedCapture = req_cap;
465         mSnapshottestCase->initTest(mLibHandle,
466             (int) MENU_START_CAPTURE, camid, SNAPSHOT_CAPTURE_WIDTH, SNAPSHOT_CAPTURE_HEIGHT);
467         testCaseEndComplete = 1;
468     }while(testCaseEndComplete != 1);
469     return 0;
470 }
471 
472 }
473 
474