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 "QCameraHAL3VideoTest.h" 31 #include "QCameraHAL3MainTestContext.h" 32 33 namespace qcamera { 34 35 extern hal3_camera_lib_test *CamObj_handle; 36 buffer_thread_t Video_thread; 37 int video_req_sent; 38 extern pthread_cond_t mRequestAppCond; 39 40 extern int test_case_end; 41 extern bool thread_exit; 42 extern std::list<uint32_t> VideoQueue; 43 int video_buffer_allocated; 44 extern pthread_mutex_t TestAppLock, mCaptureRequestLock; 45 extern int snapshot_buffer; 46 47 48 QCameraHAL3VideoTest::QCameraHAL3VideoTest(int camid) : 49 QCameraHAL3Test(0), 50 mVideoHandle(NULL), 51 mCaptureHandle(NULL), 52 mVideoStream(NULL), 53 mCameraId(camid) 54 { 55 56 } 57 58 void QCameraHAL3VideoTest::initTest(hal3_camera_lib_test *handle, 59 int testcase, int camid, int w, int h) 60 { 61 int i; 62 CamObj_handle = handle; thread_exit = 0; 63 test_case_end = 0; 64 LOGD("\n buffer thread created for testcase %d %d and %d ",testcase, w, h); 65 configureVideoStream(&(handle->test_obj), camid, w, h); 66 LOGD("\n video stream configured"); 67 constructDefaultRequest(&(handle->test_obj), camid); 68 LOGD("pipeline_depth is %d", mPipelineDepthVideo); 69 mVideoHandle = new native_handle_t *[mPipelineDepthVideo]; 70 for (i = 0; i < mPipelineDepthVideo; i++) { 71 mVideoHandle[i] = new native_handle_t; 72 } 73 74 for (i = 0, video_req_sent = 1; i < mPipelineDepthVideo; i++, video_req_sent++) { 75 vidoeAllocateBuffers(width, height, i); 76 VideoQueue.push_back(i); 77 } 78 LOGD(" Request Number is : %d ",mRequest.frame_number); 79 mRequest.frame_number = 0; 80 videoProcessThreadCreate(handle); 81 } 82 83 84 void QCameraHAL3VideoTest::snapshotCaptureRequest(hal3_camera_lib_test *handle, 85 int testcase, int camid, int w, int h) 86 { 87 LOGD("Requested Capture Sizes for testcase:%d are :%d X %d",testcase, w, h); 88 captureRequestRepeat(handle, camid, MENU_START_CAPTURE); 89 pthread_mutex_unlock(&mCaptureRequestLock); 90 } 91 92 93 void QCameraHAL3VideoTest::configureVideoStream(hal3_camera_test_obj_t *my_test_obj, 94 int camid, int w, int h) 95 { 96 camera3_device_t *device_handle = my_test_obj->device; 97 mVideoStream = new camera3_stream_t; 98 memset(mVideoStream, 0, sizeof(camera3_stream_t)); 99 mVideoStream = initStream(CAMERA3_STREAM_OUTPUT, camid, w, h, FLAGS_VIDEO_ENCODER, 100 HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, HAL3_DATASPACE_UNKNOWN); 101 mVideoConfig = configureStream(CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE, 1); 102 mVideoConfig.streams[0] = mVideoStream; 103 104 device_handle->ops->configure_streams(my_test_obj->device, &(mVideoConfig)); 105 mPipelineDepthVideo = mVideoConfig.streams[0]->max_buffers; 106 video_buffer_allocated = mPipelineDepthVideo; 107 } 108 109 void QCameraHAL3VideoTest::constructDefaultRequest( 110 hal3_camera_test_obj_t *my_test_obj, int camid) 111 { 112 camera3_device_t *device_handle = my_test_obj->device; 113 LOGD("Camera ID : %d",camid); 114 mMetaDataPtr[0] = device_handle->ops->construct_default_request_settings( 115 my_test_obj->device, CAMERA3_TEMPLATE_VIDEO_RECORD); 116 mMetaDataPtr[1] = device_handle->ops->construct_default_request_settings(my_test_obj->device, 117 CAMERA3_TEMPLATE_STILL_CAPTURE); 118 } 119 120 121 122 void QCameraHAL3VideoTest::captureRequestRepeat( 123 hal3_camera_lib_test *my_hal3test_obj, int camid, int testcase) 124 { 125 int num1, num2; 126 hal3_camera_test_obj_t *my_test_obj = &(my_hal3test_obj->test_obj); 127 camera3_device_t *device_handle = my_test_obj->device; 128 if (testcase == MENU_START_VIDEO) { 129 if (VideoQueue.empty()) { 130 LOGE("no Video buffer for CamID : %d", camid); 131 } 132 else { 133 if (test_case_end == 0) { 134 LOGD(" Request Number is : %d ", mRequest.frame_number); 135 pthread_mutex_lock(&mCaptureRequestLock); 136 num2 = VideoQueue.front(); 137 VideoQueue.pop_front(); 138 num1 = mRequest.frame_number; 139 if (num1 < 2) { 140 (mRequest).settings = mMetaDataPtr[0]; 141 } 142 else { 143 (mRequest).settings = NULL; 144 } 145 (mRequest).input_buffer = NULL; 146 (mRequest).num_output_buffers = 1; 147 mVideoStreamBuffs.stream = mVideoStream; 148 mVideoStreamBuffs.status = 0; 149 mVideoStreamBuffs.buffer = 150 (const native_handle_t**)&mVideoHandle[num2]; 151 mVideoStreamBuffs.release_fence = -1; 152 mVideoStreamBuffs.acquire_fence = -1; 153 (mRequest).output_buffers = &(mVideoStreamBuffs); 154 LOGD("Calling HAL3APP repeat capture request %d and %d and free buffer :%d " 155 , num1, num2, VideoQueue.size()); 156 device_handle->ops->process_capture_request(my_test_obj->device, &(mRequest)); 157 (mRequest.frame_number)++; 158 pthread_mutex_unlock(&mCaptureRequestLock); 159 } 160 } 161 } 162 else { 163 snapshot_buffer = mRequest.frame_number; 164 (mRequest).settings = mMetaDataPtr[1]; 165 mSnapshotStreamBuffs = hal3appGetStreamBuffs(mSnapshotStream); 166 mSnapshotStreamBuffs.buffer = (const native_handle_t**)&mCaptureHandle; 167 mRequest = hal3appGetRequestSettings(&mSnapshotStreamBuffs, 1); 168 LOGD("Calling snap HAL3APP repeat capture request repeat %d ", snapshot_buffer); 169 device_handle->ops->process_capture_request(my_test_obj->device, &(mRequest)); 170 (mRequest.frame_number)++; 171 } 172 } 173 174 void QCameraHAL3VideoTest::videoTestEnd( 175 hal3_camera_lib_test *my_hal3test_obj, int camid) 176 { 177 test_case_end = 1; 178 hal3_camera_test_obj_t *my_test_obj = &(my_hal3test_obj->test_obj); 179 camera3_device_t *device_handle = my_test_obj->device; 180 device_handle->ops->flush(my_test_obj->device); 181 LOGD("%s Closing Camera %d", __func__, camid); 182 ioctl(mVideoMeminfo.ion_fd, ION_IOC_FREE, &mVideoMeminfo.ion_handle); 183 close(mVideoMeminfo.ion_fd); 184 mVideoMeminfo.ion_fd = -1; 185 LOGD("%s Closing thread", __func__); 186 thread_exit = 1; 187 } 188 189 void QCameraHAL3VideoTest::vidoeAllocateBuffers(int height, int width, int num) 190 { 191 mVideoHandle[num] = allocateBuffers(width, height, &mVideoMeminfo); 192 } 193 194 void QCameraHAL3VideoTest::snapshotAllocateBuffers(int width, int height) 195 { 196 mCaptureHandle = allocateBuffers(width, height, &mCaptureMemInfo); 197 } 198 199 bool QCameraHAL3VideoTest::videoProcessThreadCreate( 200 hal3_camera_lib_test *handle) { 201 if(handle == NULL) { 202 LOGD("Camera Hanle is NULL"); 203 } 204 processThreadCreate(this, MENU_START_VIDEO); 205 return 1; 206 } 207 208 QCameraHAL3VideoTest::~QCameraHAL3VideoTest() 209 { 210 211 } 212 213 } 214