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