Venkateshwarlu Domakonda | 1c2c435 | 2014-05-26 14:35:12 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, The Linux Foundation. All rights reserved. |
| 3 | |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are 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 copyright |
| 9 | * notice, this list of conditions and the following disclaimer in the |
| 10 | * documentation and/or other materials provided with the distribution. |
| 11 | * * Neither the name of The Linux Foundation nor |
| 12 | * the names of its contributors may be used to endorse or promote |
| 13 | * products derived from this software without specific prior written |
| 14 | * permission. |
| 15 | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include "FmPerformanceParams.h" |
| 30 | #include "FmIoctlsInterface.h" |
| 31 | |
| 32 | #include <cstdio> |
| 33 | #include <linux/videodev2.h> |
| 34 | #include <utils/Log.h> |
| 35 | |
| 36 | signed char FmPerformanceParams :: SetAfRmssiTh |
| 37 | ( |
| 38 | UINT fd, unsigned short th |
| 39 | ) |
| 40 | { |
| 41 | signed char ret = FM_FAILURE; |
| 42 | |
| 43 | ret = FmIoctlsInterface::set_control(fd, |
| 44 | V4L2_CID_PRV_AF_RMSSI_TH, th); |
| 45 | |
| 46 | return ret; |
| 47 | } |
| 48 | |
| 49 | signed char FmPerformanceParams :: SetAfRmssiSamplesCnt |
| 50 | ( |
| 51 | UINT fd, unsigned char cnt |
| 52 | ) |
| 53 | { |
| 54 | signed char ret = FM_FAILURE; |
| 55 | |
| 56 | ret = FmIoctlsInterface::set_control(fd, |
| 57 | V4L2_CID_PRV_AF_RMSSI_SAMPLES, cnt); |
| 58 | |
| 59 | return ret; |
| 60 | } |
| 61 | |
| 62 | signed char FmPerformanceParams :: SetGoodChannelRmssiTh |
| 63 | ( |
| 64 | UINT fd, signed char th |
| 65 | ) |
| 66 | { |
| 67 | signed char ret = FM_FAILURE; |
| 68 | |
| 69 | ret = FmIoctlsInterface::set_control(fd, |
| 70 | V4L2_CID_PRV_GOOD_CH_RMSSI_TH, th); |
| 71 | |
| 72 | return ret; |
| 73 | } |
| 74 | |
| 75 | signed char FmPerformanceParams :: SetSrchAlgoType |
| 76 | ( |
| 77 | UINT fd, unsigned char algo |
| 78 | ) |
| 79 | { |
| 80 | signed char ret = FM_FAILURE; |
| 81 | |
| 82 | ret = FmIoctlsInterface::set_control(fd, |
| 83 | V4L2_CID_PRV_SRCHALGOTYPE, algo); |
| 84 | |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | signed char FmPerformanceParams :: SetSinrFirstStage |
| 89 | ( |
| 90 | UINT fd, signed char th |
| 91 | ) |
| 92 | { |
| 93 | signed char ret = FM_FAILURE; |
| 94 | |
| 95 | ret = FmIoctlsInterface::set_control(fd, |
| 96 | V4L2_CID_PRV_SINRFIRSTSTAGE, th); |
| 97 | |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | signed char FmPerformanceParams :: SetRmssiFirstStage |
| 102 | ( |
| 103 | UINT fd, signed char th |
| 104 | ) |
| 105 | { |
| 106 | signed char ret = FM_FAILURE; |
| 107 | |
| 108 | ret = FmIoctlsInterface::set_control(fd, |
| 109 | V4L2_CID_PRV_RMSSIFIRSTSTAGE, th); |
| 110 | |
| 111 | return ret; |
| 112 | } |
| 113 | |
| 114 | signed char FmPerformanceParams :: SetCf0Th12 |
| 115 | ( |
| 116 | UINT fd, int th |
| 117 | ) |
| 118 | { |
| 119 | signed char ret = FM_FAILURE; |
| 120 | |
| 121 | ret = FmIoctlsInterface::set_control(fd, |
| 122 | V4L2_CID_PRV_CF0TH12, th); |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | signed char FmPerformanceParams :: SetSinrSamplesCnt |
| 127 | ( |
| 128 | UINT fd, unsigned char cnt |
| 129 | ) |
| 130 | { |
| 131 | signed char ret = FM_FAILURE; |
| 132 | |
| 133 | ret = FmIoctlsInterface::set_control(fd, |
| 134 | V4L2_CID_PRV_SINR_SAMPLES, cnt); |
| 135 | |
| 136 | return ret; |
| 137 | } |
| 138 | |
| 139 | signed char FmPerformanceParams :: SetIntfLowTh |
| 140 | ( |
| 141 | UINT fd, unsigned char th |
| 142 | ) |
| 143 | { |
| 144 | signed char ret = FM_FAILURE; |
| 145 | |
| 146 | ret = FmIoctlsInterface::set_control(fd, |
| 147 | V4L2_CID_PRV_ON_CHANNEL_THRESHOLD, th); |
| 148 | |
| 149 | return ret; |
| 150 | } |
| 151 | |
| 152 | signed char FmPerformanceParams :: SetIntfHighTh |
| 153 | ( |
| 154 | UINT fd, unsigned char th |
| 155 | ) |
| 156 | { |
| 157 | signed char ret = FM_FAILURE; |
| 158 | |
| 159 | ret = FmIoctlsInterface::set_control(fd, |
| 160 | V4L2_CID_PRV_OFF_CHANNEL_THRESHOLD, th); |
| 161 | return ret; |
| 162 | } |
| 163 | |
| 164 | signed char FmPerformanceParams :: SetSinrFinalStage |
| 165 | ( |
| 166 | UINT fd, signed char th |
| 167 | ) |
| 168 | { |
| 169 | signed char ret = FM_FAILURE; |
| 170 | |
| 171 | ret = FmIoctlsInterface::set_control(fd, |
| 172 | V4L2_CID_PRV_SINR_THRESHOLD, th); |
| 173 | |
| 174 | return ret; |
| 175 | } |
| 176 | |
| 177 | signed char FmPerformanceParams :: GetAfRmssiTh |
| 178 | ( |
| 179 | UINT fd, unsigned short &th |
| 180 | ) |
| 181 | { |
| 182 | long int af_rmssi_th; |
| 183 | signed char ret = FM_FAILURE; |
| 184 | |
| 185 | ret = FmIoctlsInterface::get_control(fd, |
| 186 | V4L2_CID_PRV_AF_RMSSI_TH, af_rmssi_th); |
| 187 | if(ret == FM_SUCCESS) { |
| 188 | th = af_rmssi_th; |
| 189 | } |
| 190 | return ret; |
| 191 | } |
| 192 | |
| 193 | signed char FmPerformanceParams :: GetAfRmssiSamplesCnt |
| 194 | ( |
| 195 | UINT fd, unsigned char &cnt |
| 196 | ) |
| 197 | { |
| 198 | long int af_samples_cnt; |
| 199 | signed char ret = FM_FAILURE; |
| 200 | |
| 201 | ret = FmIoctlsInterface::get_control(fd, |
| 202 | V4L2_CID_PRV_AF_RMSSI_SAMPLES, af_samples_cnt); |
| 203 | if(ret == FM_SUCCESS) { |
| 204 | cnt = af_samples_cnt; |
| 205 | } |
| 206 | return ret; |
| 207 | } |
| 208 | |
| 209 | signed char FmPerformanceParams :: GetGoodChannelRmssiTh |
| 210 | ( |
| 211 | UINT fd, signed char &th |
| 212 | ) |
| 213 | { |
| 214 | long int gd_chan_rmssi_th; |
| 215 | signed char ret = FM_FAILURE; |
| 216 | |
| 217 | ret = FmIoctlsInterface::get_control(fd, |
| 218 | V4L2_CID_PRV_GOOD_CH_RMSSI_TH, gd_chan_rmssi_th); |
| 219 | if(ret == FM_SUCCESS) { |
| 220 | th = gd_chan_rmssi_th; |
| 221 | } |
| 222 | return ret; |
| 223 | } |
| 224 | |
| 225 | signed char FmPerformanceParams :: GetSrchAlgoType |
| 226 | ( |
| 227 | UINT fd, unsigned char &algo |
| 228 | ) |
| 229 | { |
| 230 | long int srch_algo_type; |
| 231 | signed char ret = FM_FAILURE; |
| 232 | |
| 233 | ret = FmIoctlsInterface::get_control(fd, |
| 234 | V4L2_CID_PRV_SRCHALGOTYPE, srch_algo_type); |
| 235 | if(ret == FM_SUCCESS) { |
| 236 | algo = srch_algo_type; |
| 237 | } |
| 238 | return ret; |
| 239 | } |
| 240 | |
| 241 | signed char FmPerformanceParams :: GetSinrFirstStage |
| 242 | ( |
| 243 | UINT fd, signed char &th |
| 244 | ) |
| 245 | { |
| 246 | long int sinr_first_stage; |
| 247 | signed char ret = FM_FAILURE; |
| 248 | |
| 249 | ret = FmIoctlsInterface::get_control(fd, |
| 250 | V4L2_CID_PRV_SINRFIRSTSTAGE, sinr_first_stage); |
| 251 | if(ret == FM_SUCCESS) { |
| 252 | th = sinr_first_stage; |
| 253 | } |
| 254 | return ret; |
| 255 | } |
| 256 | |
| 257 | signed char FmPerformanceParams :: GetRmssiFirstStage |
| 258 | ( |
| 259 | UINT fd, signed char &th |
| 260 | ) |
| 261 | { |
| 262 | long int rmssi_first_stage; |
| 263 | signed char ret = FM_FAILURE; |
| 264 | |
| 265 | ret = FmIoctlsInterface::get_control(fd, |
| 266 | V4L2_CID_PRV_RMSSIFIRSTSTAGE, rmssi_first_stage); |
| 267 | if(ret == FM_SUCCESS) { |
| 268 | th = rmssi_first_stage; |
| 269 | } |
| 270 | return ret; |
| 271 | } |
| 272 | |
| 273 | signed char FmPerformanceParams :: GetCf0Th12 |
| 274 | ( |
| 275 | UINT fd, int &th |
| 276 | ) |
| 277 | { |
| 278 | long int cf0th12; |
| 279 | signed char ret = FM_FAILURE; |
| 280 | |
| 281 | ret = FmIoctlsInterface::get_control(fd, |
| 282 | V4L2_CID_PRV_CF0TH12, cf0th12); |
| 283 | if(ret == FM_SUCCESS) { |
| 284 | th = cf0th12; |
| 285 | } |
| 286 | return ret; |
| 287 | } |
| 288 | |
| 289 | signed char FmPerformanceParams :: GetSinrSamplesCnt |
| 290 | ( |
| 291 | UINT fd, unsigned char &cnt |
| 292 | ) |
| 293 | { |
| 294 | long int sinr_samples_cnt; |
| 295 | signed char ret = FM_FAILURE; |
| 296 | |
| 297 | ret = FmIoctlsInterface::get_control(fd, |
| 298 | V4L2_CID_PRV_SINR_SAMPLES, sinr_samples_cnt); |
| 299 | if(ret == FM_SUCCESS) { |
| 300 | cnt = sinr_samples_cnt; |
| 301 | } |
| 302 | return ret; |
| 303 | } |
| 304 | |
| 305 | signed char FmPerformanceParams :: GetIntfLowTh |
| 306 | ( |
| 307 | UINT fd, unsigned char &th |
| 308 | ) |
| 309 | { |
| 310 | long int intf_low_th; |
| 311 | signed char ret = FM_FAILURE; |
| 312 | |
| 313 | ret = FmIoctlsInterface::get_control(fd, |
| 314 | V4L2_CID_PRV_ON_CHANNEL_THRESHOLD, intf_low_th); |
| 315 | if(ret == FM_SUCCESS) { |
| 316 | th = intf_low_th; |
| 317 | } |
| 318 | return ret; |
| 319 | } |
| 320 | |
| 321 | signed char FmPerformanceParams :: GetIntfHighTh |
| 322 | ( |
| 323 | UINT fd, unsigned char &th |
| 324 | ) |
| 325 | { |
| 326 | long int intf_high_th; |
| 327 | signed char ret = FM_FAILURE; |
| 328 | |
| 329 | ret = FmIoctlsInterface::get_control(fd, |
| 330 | V4L2_CID_PRV_OFF_CHANNEL_THRESHOLD, intf_high_th); |
| 331 | if(ret == FM_SUCCESS) { |
| 332 | th = intf_high_th; |
| 333 | } |
| 334 | return ret; |
| 335 | } |
| 336 | |
| 337 | signed char FmPerformanceParams :: GetIntfDet |
| 338 | ( |
| 339 | UINT fd, unsigned char &th |
| 340 | ) |
| 341 | { |
| 342 | long int int_det; |
| 343 | signed char ret = FM_FAILURE; |
| 344 | |
| 345 | ret = FmIoctlsInterface::get_control(fd, |
| 346 | V4L2_CID_PRV_INTDET, int_det); |
| 347 | if(ret == FM_SUCCESS) { |
| 348 | th = int_det; |
| 349 | } |
| 350 | return ret; |
| 351 | } |
| 352 | signed char FmPerformanceParams :: GetSinrFinalStage |
| 353 | ( |
| 354 | UINT fd, signed char &th |
| 355 | ) |
| 356 | { |
| 357 | signed char ret = FM_FAILURE; |
| 358 | long int sinr; |
| 359 | |
| 360 | ret = FmIoctlsInterface::get_control(fd, |
| 361 | V4L2_CID_PRV_SINR_THRESHOLD, sinr); |
| 362 | |
| 363 | if(ret == FM_SUCCESS) { |
| 364 | th = sinr; |
| 365 | } |
| 366 | return ret; |
| 367 | } |
| 368 | |
| 369 | signed char FmPerformanceParams :: SetHybridSrchList |
| 370 | ( |
| 371 | UINT fd, |
| 372 | unsigned int *freqs, |
| 373 | signed char *sinrs, |
| 374 | unsigned int n |
| 375 | ) |
| 376 | { |
| 377 | struct v4l2_ext_control ext_ctl; |
| 378 | struct v4l2_ext_controls v4l2_ctls; |
| 379 | unsigned int freq; |
| 380 | signed char sinr; |
| 381 | unsigned int size = 0; |
| 382 | char *data = NULL; |
| 383 | signed char ret = FM_FAILURE; |
| 384 | |
| 385 | if(n <= 0) { |
| 386 | return ret; |
| 387 | } |
| 388 | data = new char[(n * 3 + 3)]; |
| 389 | |
| 390 | if(data != NULL) { |
| 391 | data[size++] = 0x40; |
| 392 | data[size++] = ((n * 3) + 1); |
| 393 | data[size++] = n; |
| 394 | while((size < (n * 3 + 2)) && (freqs != NULL) |
| 395 | && (sinrs != NULL)) { |
| 396 | freq = (*freqs - 76000) / 50; |
| 397 | data[size++] = (freq & 0xff); |
| 398 | data[size++] = ((freq >> 8) & 0xff); |
| 399 | data[size++] = *sinrs; |
| 400 | freqs++; |
| 401 | sinrs++; |
| 402 | } |
| 403 | if(size == (n * 3 + 3)) { |
| 404 | ext_ctl.id = V4L2_CID_PRV_IRIS_WRITE_DEFAULT; |
| 405 | ext_ctl.string = data; |
| 406 | ext_ctl.size = size; |
| 407 | v4l2_ctls.ctrl_class = V4L2_CTRL_CLASS_USER; |
| 408 | v4l2_ctls.count = 1; |
| 409 | v4l2_ctls.controls = &ext_ctl; |
| 410 | ret = FmIoctlsInterface::set_ext_control(fd, &v4l2_ctls); |
| 411 | if(ret == FM_SUCCESS) { |
| 412 | ALOGE("hybrid srch list sent successfully\n"); |
| 413 | }else { |
| 414 | ALOGE("hybrid srch list setting failed\n"); |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | delete []data; |
| 420 | |
| 421 | return ret; |
| 422 | } |