summaryrefslogtreecommitdiff
path: root/vircam/VirtualCamHal.cpp (plain)
blob: 12d267f92c3e57ac938a92d89fd63dd2b626170b
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18* @file VirtualCamHal.cpp
19*
20* This file maps the Camera Hardware Interface to V4L2.
21*
22*/
23
24#define LOG_NDEBUG 0
25#define LOG_TAG "CAMHAL_VirtCamHAL "
26
27#include "VirtualCamHal.h"
28#include "ANativeWindowDisplayAdapter.h"
29#include "ExCameraParameters.h"
30#include "CameraProperties.h"
31#include <cutils/properties.h>
32
33#include <poll.h>
34#include <math.h>
35
36namespace android {
37#define LOGD ALOGD
38#define LOGE ALOGE
39#define LOGV ALOGV
40#define LOGI ALOGI
41
42static void write_sys_int(const char *path, int val)
43{
44 char cmd[16];
45 int fd = open(path, O_RDWR);
46
47 if(fd >= 0) {
48 sprintf(cmd, "%d", val);
49 write(fd, cmd, strlen(cmd));
50 close(fd);
51 }
52}
53
54static void write_sys_string(const char *path, const char *s)
55{
56 int fd = open(path, O_RDWR);
57
58 if(fd >= 0) {
59 write(fd, s, strlen(s));
60 close(fd);
61 }
62}
63
64#define DISABLE_VIDEO "/sys/class/video/disable_video"
65#define ENABLE_AVSYNC "/sys/class/tsync/enable"
66#define TSYNC_EVENT "/sys/class/tsync/event"
67#define VIDEO_ZOOM "/sys/class/video/zoom"
68#define SCREEN_MODE "/sys/class/video/screen_mode"
69
70static int SYS_enable_nextvideo()
71{
72 write_sys_int(DISABLE_VIDEO, 2);
73 return 0;
74}
75
76static int SYS_close_video()
77{
78 write_sys_int(DISABLE_VIDEO, 1);
79 return 0;
80}
81
82static int SYS_open_video()
83{
84 write_sys_int(DISABLE_VIDEO, 0);
85 return 0;
86}
87
88static int SYS_disable_avsync()
89{
90 write_sys_int(ENABLE_AVSYNC, 0);
91 return 0;
92}
93
94static int SYS_disable_video_pause()
95{
96 write_sys_string(TSYNC_EVENT, "VIDEO_PAUSE:0x0");
97 return 0;
98}
99
100extern "C" CameraAdapter* CameraAdapter_Factory(size_t);
101
102/*****************************************************************************/
103
104////Constant definitions and declarations
105////@todo Have a CameraProperties class to store these parameters as constants for every camera
106//// Currently, they are hard-coded
107
108const int VirtualCamHal::NO_BUFFERS_PREVIEW = MAX_CAMERA_BUFFERS;
109const int VirtualCamHal::NO_BUFFERS_IMAGE_CAPTURE = 2;
110
111/******************************************************************************/
112
113#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
114
115struct timeval VirtualCamHal::mStartPreview;
116struct timeval VirtualCamHal::mStartFocus;
117struct timeval VirtualCamHal::mStartCapture;
118
119#endif
120
121static void orientation_cb(uint32_t orientation, uint32_t tilt, void* cookie) {
122 VirtualCamHal *camera = NULL;
123
124 if (cookie) {
125 camera = (VirtualCamHal*) cookie;
126 camera->onOrientationEvent(orientation, tilt);
127 }
128
129}
130/*-------------Camera Hal Interface Method definitions STARTS here--------------------*/
131
132/**
133 Callback function to receive orientation events from SensorListener
134 */
135void VirtualCamHal::onOrientationEvent(uint32_t orientation, uint32_t tilt) {
136 LOG_FUNCTION_NAME;
137
138 if ( NULL != mCameraAdapter ) {
139 mCameraAdapter->onOrientationEvent(orientation, tilt);
140 }
141
142 LOG_FUNCTION_NAME_EXIT;
143}
144
145/**
146 @brief Set the notification and data callbacks
147
148 @param[in] notify_cb Notify callback for notifying the app about events and errors
149 @param[in] data_cb Buffer callback for sending the preview/raw frames to the app
150 @param[in] data_cb_timestamp Buffer callback for sending the video frames w/ timestamp
151 @param[in] user Callback cookie
152 @return none
153
154 */
155void VirtualCamHal::setCallbacks(camera_notify_callback notify_cb,
156 camera_data_callback data_cb,
157 camera_data_timestamp_callback data_cb_timestamp,
158 camera_request_memory get_memory,
159 void *user)
160{
161 LOG_FUNCTION_NAME;
162
163 if ( NULL != mAppCbNotifier.get() )
164 {
165 mAppCbNotifier->setCallbacks(this,
166 notify_cb,
167 data_cb,
168 data_cb_timestamp,
169 get_memory,
170 user);
171 }
172
173 if ( NULL != mMemoryManager.get() )
174 {
175 mMemoryManager->setRequestMemoryCallback(get_memory);
176 }
177
178 LOG_FUNCTION_NAME_EXIT;
179}
180
181/**
182 @brief Enable a message, or set of messages.
183
184 @param[in] msgtype Bitmask of the messages to enable (defined in include/ui/Camera.h)
185 @return none
186
187 */
188void VirtualCamHal::enableMsgType(int32_t msgType)
189{
190 LOG_FUNCTION_NAME;
191
192 if ( ( msgType & CAMERA_MSG_SHUTTER ) && ( !mShutterEnabled ) )
193 {
194 msgType &= ~CAMERA_MSG_SHUTTER;
195 }
196
197 // ignoring enable focus message from camera service
198 // we will enable internally in autoFocus call
199 if (msgType & CAMERA_MSG_FOCUS) {
200 msgType &= ~CAMERA_MSG_FOCUS;
201 }
202 if (msgType & CAMERA_MSG_FOCUS_MOVE ) {
203 msgType &= ~CAMERA_MSG_FOCUS_MOVE;
204 }
205
206 {
207 Mutex::Autolock lock(mLock);
208 mMsgEnabled |= msgType;
209 }
210
211 if(mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME)
212 {
213 if(mDisplayPaused)
214 {
215 CAMHAL_LOGDA("Preview currently paused...will enable preview callback when restarted");
216 msgType &= ~CAMERA_MSG_PREVIEW_FRAME;
217 }else
218 {
219 CAMHAL_LOGDA("Enabling Preview Callback");
220 }
221 }
222 else
223 {
224 CAMHAL_LOGDB("Preview callback not enabled %x", msgType);
225 }
226
227
228 ///Configure app callback notifier with the message callback required
229 mAppCbNotifier->enableMsgType (msgType);
230
231 LOG_FUNCTION_NAME_EXIT;
232}
233
234/**
235 @brief Disable a message, or set of messages.
236
237 @param[in] msgtype Bitmask of the messages to disable (defined in include/ui/Camera.h)
238 @return none
239
240 */
241void VirtualCamHal::disableMsgType(int32_t msgType)
242{
243 LOG_FUNCTION_NAME;
244 int32_t CurMsg = 0;
245 {
246 Mutex::Autolock lock(mLock);
247 mMsgEnabled &= ~msgType;
248 CurMsg = mMsgEnabled;
249 }
250
251 if( msgType & CAMERA_MSG_PREVIEW_FRAME){
252 CAMHAL_LOGDA("Disabling Preview Callback");
253 }
254
255 ///Configure app callback notifier
256 mAppCbNotifier->disableMsgType (CurMsg);
257
258 LOG_FUNCTION_NAME_EXIT;
259}
260
261/**
262 @brief Query whether a message, or a set of messages, is enabled.
263
264 Note that this is operates as an AND, if any of the messages queried are off, this will
265 return false.
266
267 @param[in] msgtype Bitmask of the messages to query (defined in include/ui/Camera.h)
268 @return true If all message types are enabled
269 false If any message type
270
271 */
272int VirtualCamHal::msgTypeEnabled(int32_t msgType)
273{
274 LOG_FUNCTION_NAME;
275 Mutex::Autolock lock(mLock);
276 LOG_FUNCTION_NAME_EXIT;
277 return (mMsgEnabled & msgType);
278}
279
280/**
281 @brief Set the camera parameters.
282
283 @param[in] params Camera parameters to configure the camera
284 @return NO_ERROR
285 @todo Define error codes
286
287 */
288int VirtualCamHal::setParameters(const char* parameters)
289{
290
291 LOG_FUNCTION_NAME;
292
293 CameraParameters params;
294
295 String8 str_params(parameters);
296 params.unflatten(str_params);
297
298 LOG_FUNCTION_NAME_EXIT;
299
300 return setParameters(params);
301}
302
303/**
304 @brief Set the camera parameters.
305
306 @param[in] params Camera parameters to configure the camera
307 @return NO_ERROR
308 @todo Define error codes
309
310 */
311int VirtualCamHal::setParameters(const CameraParameters& params)
312{
313
314 LOG_FUNCTION_NAME;
315
316 int w, h;
317 int w_orig, h_orig;
318 int framerate,minframerate;
319 int maxFPS, minFPS;
320 int error;
321 int base;
322 const char *valstr = NULL;
323 const char *prevFormat;
324 char *af_coord;
325 MSGUTILS::Message msg;
326 status_t ret = NO_ERROR;
327 // Needed for KEY_RECORDING_HINT
328 bool restartPreviewRequired = false;
329 bool updateRequired = false;
330 CameraParameters oldParams(mParameters.flatten());
331 bool videoMode = false;
332 char range[MAX_PROP_VALUE_LENGTH];
333
334 {
335 Mutex::Autolock lock(mLock);
336
337 ///Ensure that preview is not enabled when the below parameters are changed.
338 if(!previewEnabled())
339 {
340
341 CAMHAL_LOGDB("PreviewFormat %s", params.getPreviewFormat());
342
343 if ((valstr = params.getPreviewFormat()) != NULL) {
344 if ( isParameterValid(valstr, mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_FORMATS))) {
345 mParameters.setPreviewFormat(valstr);
346 } else {
347 CAMHAL_LOGEB("Invalid preview format.Supported: %s", mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_FORMATS));
348 return -EINVAL;
349 }
350 }
351
352 if ((valstr = params.get(ExCameraParameters::KEY_VNF)) != NULL) {
353 if ( (params.getInt(ExCameraParameters::KEY_VNF)==0) || (params.getInt(ExCameraParameters::KEY_VNF)==1) ) {
354 CAMHAL_LOGDB("VNF set %s", params.get(ExCameraParameters::KEY_VNF));
355 mParameters.set(ExCameraParameters::KEY_VNF, valstr);
356 } else {
357 CAMHAL_LOGEB("ERROR: Invalid VNF: %s", valstr);
358 ret = -EINVAL;
359 }
360 }
361
362 if ((valstr = params.get(CameraParameters::KEY_VIDEO_STABILIZATION)) != NULL) {
363 // make sure we support vstab...if we don't and application is trying to set
364 // vstab then return an error
365 if (strcmp(mCameraProperties->get(CameraProperties::VSTAB_SUPPORTED),
366 CameraParameters::TRUE) == 0) {
367 CAMHAL_LOGDB("VSTAB %s",
368 params.get(CameraParameters::KEY_VIDEO_STABILIZATION));
369 mParameters.set(CameraParameters::KEY_VIDEO_STABILIZATION,
370 params.get(CameraParameters::KEY_VIDEO_STABILIZATION));
371 } else if (strcmp(valstr, CameraParameters::TRUE) == 0) {
372 CAMHAL_LOGEB("ERROR: Invalid VSTAB: %s", valstr);
373 ret = -EINVAL;
374 } else {
375 mParameters.set(CameraParameters::KEY_VIDEO_STABILIZATION,
376 CameraParameters::FALSE);
377 }
378 }
379
380 if( (valstr = params.get(ExCameraParameters::KEY_CAP_MODE)) != NULL)
381 {
382 CAMHAL_LOGDB("Capture mode set %s", params.get(ExCameraParameters::KEY_CAP_MODE));
383 mParameters.set(ExCameraParameters::KEY_CAP_MODE, valstr);
384 }
385
386 if ((valstr = params.get(ExCameraParameters::KEY_IPP)) != NULL) {
387 if (isParameterValid(valstr,mCameraProperties->get(CameraProperties::SUPPORTED_IPP_MODES))) {
388 CAMHAL_LOGDB("IPP mode set %s", params.get(ExCameraParameters::KEY_IPP));
389 mParameters.set(ExCameraParameters::KEY_IPP, valstr);
390 } else {
391 CAMHAL_LOGEB("ERROR: Invalid IPP mode: %s. Supported: %s", valstr,
392 mCameraProperties->get(CameraProperties::SUPPORTED_IPP_MODES));
393 ret = -EINVAL;
394 }
395 }
396
397 if((valstr = params.get(ExCameraParameters::KEY_S3D2D_PREVIEW)) != NULL)
398 {
399 CAMHAL_LOGDB("Stereo 3D->2D Preview mode is %s", params.get(ExCameraParameters::KEY_S3D2D_PREVIEW));
400 mParameters.set(ExCameraParameters::KEY_S3D2D_PREVIEW, valstr);
401 }
402
403 if((valstr = params.get(ExCameraParameters::KEY_AUTOCONVERGENCE)) != NULL)
404 {
405 CAMHAL_LOGDB("AutoConvergence mode is %s", params.get(ExCameraParameters::KEY_AUTOCONVERGENCE));
406 mParameters.set(ExCameraParameters::KEY_AUTOCONVERGENCE, valstr);
407 }
408
409 }
410
411 params.getPreviewSize(&w, &h);
412 if (w == -1 && h == -1) {
413 CAMHAL_LOGEA("Unable to get preview size");
414 return -EINVAL;
415 }
416
417 int oldWidth, oldHeight;
418 mParameters.getPreviewSize(&oldWidth, &oldHeight);
419
420 int orientation =0;
421 if((valstr = params.get(ExCameraParameters::KEY_SENSOR_ORIENTATION)) != NULL)
422 {
423 CAMHAL_LOGDB("Sensor Orientation is set to %s", params.get(ExCameraParameters::KEY_SENSOR_ORIENTATION));
424 mParameters.set(ExCameraParameters::KEY_SENSOR_ORIENTATION, valstr);
425 orientation = params.getInt(ExCameraParameters::KEY_SENSOR_ORIENTATION);
426 }
427
428 if(orientation ==90 || orientation ==270)
429 {
430 if ( !isResolutionValid(h,w, mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_SIZES)))
431 {
432 CAMHAL_LOGEB("Invalid preview resolution %d x %d. Supported: %s", w, h,
433 mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_SIZES));
434 return -EINVAL;
435 }
436 else
437 {
438 mParameters.setPreviewSize(w, h);
439 mVideoWidth = w;
440 mVideoHeight = h;
441 }
442 }
443 else
444 {
445 if ( !isResolutionValid(w, h, mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_SIZES)))
446 {
447 CAMHAL_LOGEB("Invalid preview resolution2 %d x %d. Supported: %s", w, h,
448 mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_SIZES));
449 return -EINVAL;
450 }
451 else
452 {
453 mParameters.setPreviewSize(w, h);
454 }
455 }
456
457 if ( ( oldWidth != w ) || ( oldHeight != h ) )
458 {
459 restartPreviewRequired |= true;
460 }
461
462 CAMHAL_LOGDB("PreviewResolution by App %d x %d", w, h);
463
464 // Handle RECORDING_HINT to Set/Reset Video Mode Parameters
465 valstr = params.get(CameraParameters::KEY_RECORDING_HINT);
466 if(valstr != NULL)
467 {
468 if(strcmp(valstr, CameraParameters::TRUE) == 0)
469 {
470 CAMHAL_LOGDB("Recording Hint is set to %s", valstr);
471 mParameters.set(CameraParameters::KEY_RECORDING_HINT, valstr);
472 videoMode = true;
473 int w, h;
474
475 params.getPreviewSize(&w, &h);
476 CAMHAL_LOGVB("%s Preview Width=%d Height=%d\n", __FUNCTION__, w, h);
477 //HACK FOR MMS
478 mVideoWidth = w;
479 mVideoHeight = h;
480 CAMHAL_LOGVB("%s Video Width=%d Height=%d\n", __FUNCTION__, mVideoWidth, mVideoHeight);
481
482 //setPreferredPreviewRes(w, h);
483 mParameters.getPreviewSize(&w, &h);
484 CAMHAL_LOGVB("%s Preview Width=%d Height=%d\n", __FUNCTION__, w, h);
485 //Avoid restarting preview for MMS HACK
486 if ((w != mVideoWidth) && (h != mVideoHeight))
487 {
488 restartPreviewRequired = false;
489 }
490
491 restartPreviewRequired |= setVideoModeParameters(params);
492 }
493 else if(strcmp(valstr, CameraParameters::FALSE) == 0)
494 {
495 CAMHAL_LOGDB("Recording Hint is set to %s", valstr);
496 mParameters.set(CameraParameters::KEY_RECORDING_HINT, valstr);
497 restartPreviewRequired |= resetVideoModeParameters();
498 params.getPreviewSize(&mVideoWidth, &mVideoHeight);
499 }
500 else
501 {
502 CAMHAL_LOGEA("Invalid RECORDING_HINT");
503 return -EINVAL;
504 }
505 }
506 else
507 {
508 // This check is required in following case.
509 // If VideoRecording activity sets KEY_RECORDING_HINT to TRUE and
510 // ImageCapture activity doesnot set KEY_RECORDING_HINT to FALSE (i.e. simply NULL),
511 // then Video Mode parameters may remain present in ImageCapture activity as well.
512 CAMHAL_LOGDA("Recording Hint is set to NULL");
513 mParameters.set(CameraParameters::KEY_RECORDING_HINT, "");
514 restartPreviewRequired |= resetVideoModeParameters();
515 params.getPreviewSize(&mVideoWidth, &mVideoHeight);
516 }
517
518 if ((valstr = params.get(CameraParameters::KEY_FOCUS_MODE)) != NULL) {
519 if (isParameterValid(valstr, mCameraProperties->get(CameraProperties::SUPPORTED_FOCUS_MODES))) {
520 CAMHAL_LOGDB("Focus mode set %s", params.get(CameraParameters::KEY_FOCUS_MODE));
521
522 // we need to take a decision on the capture mode based on whether CAF picture or
523 // video is chosen so the behavior of each is consistent to the application
524 if(strcmp(valstr, CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE) == 0){
525 restartPreviewRequired |= resetVideoModeParameters();
526 } else if (strcmp(valstr, CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO) == 0){
527 restartPreviewRequired |= setVideoModeParameters(params);
528 }
529
530 mParameters.set(CameraParameters::KEY_FOCUS_MODE, valstr);
531 } else {
532 CAMHAL_LOGEB("ERROR: Invalid FOCUS mode = %s", valstr);
533 ret = -EINVAL;
534 }
535 }
536
537 ///Below parameters can be changed when the preview is running
538 if ( (valstr = params.getPictureFormat()) != NULL ) {
539 if (isParameterValid(params.getPictureFormat(),mCameraProperties->get(CameraProperties::SUPPORTED_PICTURE_FORMATS))) {
540 mParameters.setPictureFormat(valstr);
541 } else {
542 CAMHAL_LOGEB("ERROR: Invalid picture format: %s",valstr);
543 ret = -EINVAL;
544 }
545 }
546
547 params.getPictureSize(&w, &h);
548 if ( isResolutionValid(w, h, mCameraProperties->get(CameraProperties::SUPPORTED_PICTURE_SIZES))) {
549 mParameters.setPictureSize(w, h);
550 } else {
551 CAMHAL_LOGEB("ERROR: Invalid picture resolution %dx%d", w, h);
552 ret = -EINVAL;
553 }
554
555 CAMHAL_LOGDB("Picture Size by App %d x %d", w, h);
556
557 if ((valstr = params.get(ExCameraParameters::KEY_BURST)) != NULL) {
558 if (params.getInt(ExCameraParameters::KEY_BURST) >=0) {
559 CAMHAL_LOGDB("Burst set %s", params.get(ExCameraParameters::KEY_BURST));
560 mParameters.set(ExCameraParameters::KEY_BURST, valstr);
561 } else {
562 CAMHAL_LOGEB("ERROR: Invalid Burst value: %s",valstr);
563 ret = -EINVAL;
564 }
565 }
566
567 framerate = params.getPreviewFrameRate();
568 valstr = params.get(CameraParameters::KEY_PREVIEW_FPS_RANGE);
569 CAMHAL_LOGDB("FRAMERATE %d", framerate);
570
571 CAMHAL_LOGDB("Passed FRR: %s, Supported FRR %s", valstr
572 , mCameraProperties->get(CameraProperties::FRAMERATE_RANGE_SUPPORTED));
573 CAMHAL_LOGDB("Passed FR: %d, Supported FR %s", framerate
574 , mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_FRAME_RATES));
575
576
577 if (valstr == NULL)
578 valstr = "";
579 //Perform parameter validation
580 if(!isParameterValid(valstr
581 , mCameraProperties->get(CameraProperties::FRAMERATE_RANGE_SUPPORTED))
582 || !isParameterInRange(framerate,
583 mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_FRAME_RATES)))
584 {
585 CAMHAL_LOGEA("Invalid frame rate range or frame rate");
586 return -EINVAL;
587 }
588
589 // Variable framerate ranges have higher priority over
590 // deprecated constant FPS. "KEY_PREVIEW_FPS_RANGE" should
591 // be cleared by the client in order for constant FPS to get
592 // applied.
593 if ( strcmp(valstr, mCameraProperties->get(CameraProperties::FRAMERATE_RANGE)) != 0)
594 {
595 // APP wants to set FPS range
596 //Set framerate = MAXFPS
597 CAMHAL_LOGDA("APP IS CHANGING FRAME RATE RANGE");
598 params.getPreviewFpsRange(&minFPS, &maxFPS);
599
600 if ( ( 0 > minFPS ) || ( 0 > maxFPS ) )
601 {
602 CAMHAL_LOGEA("ERROR: FPS Range is negative!");
603 return -EINVAL;
604 }
605
606 framerate = maxFPS /VirtualCamHal::VFR_SCALE;
607
608 }
609 else
610 {
611 if ( framerate != atoi(mCameraProperties->get(CameraProperties::PREVIEW_FRAME_RATE)) )
612 {
613
614 selectFPSRange(framerate, &minFPS, &maxFPS);
615 CAMHAL_LOGDB("Select FPS Range %d %d", minFPS, maxFPS);
616 }
617 else
618 {
619 if (videoMode) {
620 valstr = mCameraProperties->get(CameraProperties::FRAMERATE_RANGE_VIDEO);
621 CameraParameters temp;
622 temp.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, valstr);
623 temp.getPreviewFpsRange(&minFPS, &maxFPS);
624 }
625 else {
626 valstr = mCameraProperties->get(CameraProperties::FRAMERATE_RANGE_IMAGE);
627 CameraParameters temp;
628 temp.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, valstr);
629 temp.getPreviewFpsRange(&minFPS, &maxFPS);
630 }
631
632 //framerate = maxFPS / VirtualCamHal::VFR_SCALE;
633 }
634
635 }
636
637 CAMHAL_LOGDB("FPS Range = %s", valstr);
638 CAMHAL_LOGDB("DEFAULT FPS Range = %s", mCameraProperties->get(CameraProperties::FRAMERATE_RANGE));
639
640 minFPS /= VirtualCamHal::VFR_SCALE;
641 maxFPS /= VirtualCamHal::VFR_SCALE;
642
643 if ( ( 0 == minFPS ) || ( 0 == maxFPS ) )
644 {
645 CAMHAL_LOGEA("ERROR: FPS Range is invalid!");
646 ret = -EINVAL;
647 }
648
649 if ( maxFPS < minFPS )
650 {
651 CAMHAL_LOGEA("ERROR: Max FPS is smaller than Min FPS!");
652 ret = -EINVAL;
653 }
654 if(framerate < minFPS)
655 framerate = minFPS;
656 if(framerate > maxFPS)
657 framerate = maxFPS;
658 CAMHAL_LOGDB("SET FRAMERATE %d", framerate);
659 mParameters.setPreviewFrameRate(framerate);
660 valstr = params.get(CameraParameters::KEY_PREVIEW_FPS_RANGE);
661 if (!valstr) valstr = "";
662 mParameters.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, valstr);
663
664 CAMHAL_LOGDB("FPS Range [%d, %d]", minFPS, maxFPS);
665 mParameters.set(ExCameraParameters::KEY_MINFRAMERATE, minFPS);
666 mParameters.set(ExCameraParameters::KEY_MAXFRAMERATE, maxFPS);
667
668 if( ( valstr = params.get(ExCameraParameters::KEY_GBCE) ) != NULL )
669 {
670 CAMHAL_LOGDB("GBCE Value = %s", valstr);
671 mParameters.set(ExCameraParameters::KEY_GBCE, valstr);
672 }
673
674 if( ( valstr = params.get(ExCameraParameters::KEY_GLBCE) ) != NULL )
675 {
676 CAMHAL_LOGDB("GLBCE Value = %s", valstr);
677 mParameters.set(ExCameraParameters::KEY_GLBCE, valstr);
678 }
679
680 ///Update the current parameter set
681 if( (valstr = params.get(ExCameraParameters::KEY_AUTOCONVERGENCE)) != NULL)
682 {
683 CAMHAL_LOGDB("AutoConvergence Mode is set = %s", params.get(ExCameraParameters::KEY_AUTOCONVERGENCE));
684 mParameters.set(ExCameraParameters::KEY_AUTOCONVERGENCE, valstr);
685 }
686
687 if( (valstr = params.get(ExCameraParameters::KEY_MANUALCONVERGENCE_VALUES)) !=NULL )
688 {
689 CAMHAL_LOGDB("ManualConvergence Value = %s", params.get(ExCameraParameters::KEY_MANUALCONVERGENCE_VALUES));
690 mParameters.set(ExCameraParameters::KEY_MANUALCONVERGENCE_VALUES, valstr);
691 }
692
693 if ((valstr = params.get(ExCameraParameters::KEY_EXPOSURE_MODE)) != NULL) {
694 if (isParameterValid(valstr, mCameraProperties->get(CameraProperties::SUPPORTED_EXPOSURE_MODES))) {
695 CAMHAL_LOGDB("Exposure set = %s", valstr);
696 mParameters.set(ExCameraParameters::KEY_EXPOSURE_MODE, valstr);
697 } else {
698 CAMHAL_LOGEB("ERROR: Invalid Exposure = %s", valstr);
699 ret = -EINVAL;
700 }
701 }
702
703 if ((valstr = params.get(CameraParameters::KEY_WHITE_BALANCE)) != NULL) {
704 if ( isParameterValid(valstr, mCameraProperties->get(CameraProperties::SUPPORTED_WHITE_BALANCE))) {
705 CAMHAL_LOGDB("White balance set %s", valstr);
706 mParameters.set(CameraParameters::KEY_WHITE_BALANCE, valstr);
707 } else {
708 CAMHAL_LOGEB("ERROR: Invalid white balance = %s", valstr);
709 ret = -EINVAL;
710 }
711 }
712
713 if ((valstr = params.get(ExCameraParameters::KEY_CONTRAST)) != NULL) {
714 if (params.getInt(ExCameraParameters::KEY_CONTRAST) >= 0 ) {
715 CAMHAL_LOGDB("Contrast set %s", valstr);
716 mParameters.set(ExCameraParameters::KEY_CONTRAST, valstr);
717 } else {
718 CAMHAL_LOGEB("ERROR: Invalid Contrast = %s", valstr);
719 ret = -EINVAL;
720 }
721 }
722
723 if ((valstr =params.get(ExCameraParameters::KEY_SHARPNESS)) != NULL) {
724 if (params.getInt(ExCameraParameters::KEY_SHARPNESS) >= 0 ) {
725 CAMHAL_LOGDB("Sharpness set %s", valstr);
726 mParameters.set(ExCameraParameters::KEY_SHARPNESS, valstr);
727 } else {
728 CAMHAL_LOGEB("ERROR: Invalid Sharpness = %s", valstr);
729 ret = -EINVAL;
730 }
731 }
732
733 if ((valstr = params.get(ExCameraParameters::KEY_SATURATION)) != NULL) {
734 if (params.getInt(ExCameraParameters::KEY_SATURATION) >= 0 ) {
735 CAMHAL_LOGDB("Saturation set %s", valstr);
736 mParameters.set(ExCameraParameters::KEY_SATURATION, valstr);
737 } else {
738 CAMHAL_LOGEB("ERROR: Invalid Saturation = %s", valstr);
739 ret = -EINVAL;
740 }
741 }
742
743 if ((valstr = params.get(ExCameraParameters::KEY_BRIGHTNESS)) != NULL) {
744 if (params.getInt(ExCameraParameters::KEY_BRIGHTNESS) >= 0 ) {
745 CAMHAL_LOGDB("Brightness set %s", valstr);
746 mParameters.set(ExCameraParameters::KEY_BRIGHTNESS, valstr);
747 } else {
748 CAMHAL_LOGEB("ERROR: Invalid Brightness = %s", valstr);
749 ret = -EINVAL;
750 }
751 }
752
753 if ((valstr = params.get(CameraParameters::KEY_ANTIBANDING)) != NULL) {
754 if (isParameterValid(valstr, mCameraProperties->get(CameraProperties::SUPPORTED_ANTIBANDING))) {
755 CAMHAL_LOGDB("Antibanding set %s", valstr);
756 mParameters.set(CameraParameters::KEY_ANTIBANDING, valstr);
757 } else {
758 CAMHAL_LOGEB("ERROR: Invalid Antibanding = %s", valstr);
759 ret = -EINVAL;
760 }
761 }
762
763 if ((valstr = params.get(ExCameraParameters::KEY_ISO)) != NULL) {
764 if (isParameterValid(valstr, mCameraProperties->get(CameraProperties::SUPPORTED_ISO_VALUES))) {
765 CAMHAL_LOGDB("ISO set %s", valstr);
766 mParameters.set(ExCameraParameters::KEY_ISO, valstr);
767 } else {
768 CAMHAL_LOGEB("ERROR: Invalid ISO = %s", valstr);
769 ret = -EINVAL;
770 }
771 }
772
773 if( (valstr = params.get(CameraParameters::KEY_FOCUS_AREAS)) != NULL )
774 {
775 CAMHAL_LOGEB("Focus areas position set %s", params.get(CameraParameters::KEY_FOCUS_AREAS));
776 mParameters.set(CameraParameters::KEY_FOCUS_AREAS, valstr);
777 }
778
779 if( (valstr = params.get(ExCameraParameters::KEY_MEASUREMENT_ENABLE)) != NULL )
780 {
781 CAMHAL_LOGDB("Measurements set to %s", params.get(ExCameraParameters::KEY_MEASUREMENT_ENABLE));
782 mParameters.set(ExCameraParameters::KEY_MEASUREMENT_ENABLE, valstr);
783
784 if (strcmp(valstr, (const char *) ExCameraParameters::MEASUREMENT_ENABLE) == 0)
785 {
786 mMeasurementEnabled = true;
787 }
788 else if (strcmp(valstr, (const char *) ExCameraParameters::MEASUREMENT_DISABLE) == 0)
789 {
790 mMeasurementEnabled = false;
791 }
792 else
793 {
794 mMeasurementEnabled = false;
795 }
796
797 }
798
799 if( (valstr = params.get(CameraParameters::KEY_EXPOSURE_COMPENSATION)) != NULL)
800 {
801 CAMHAL_LOGDB("Exposure compensation set %s", params.get(CameraParameters::KEY_EXPOSURE_COMPENSATION));
802 mParameters.set(CameraParameters::KEY_EXPOSURE_COMPENSATION, valstr);
803 }
804
805 if ((valstr = params.get(CameraParameters::KEY_SCENE_MODE)) != NULL) {
806 if (isParameterValid(valstr, mCameraProperties->get(CameraProperties::SUPPORTED_SCENE_MODES))) {
807 CAMHAL_LOGDB("Scene mode set %s", valstr);
808 doesSetParameterNeedUpdate(valstr,
809 mParameters.get(CameraParameters::KEY_SCENE_MODE),
810 updateRequired);
811 mParameters.set(CameraParameters::KEY_SCENE_MODE, valstr);
812 } else {
813 CAMHAL_LOGEB("ERROR: Invalid Scene mode = %s", valstr);
814 ret = -EINVAL;
815 }
816 }
817
818 if ((valstr = params.get(CameraParameters::KEY_FLASH_MODE)) != NULL) {
819 const char* supportlist = mCameraProperties->get(CameraProperties::SUPPORTED_FLASH_MODES);
820 if (supportlist != NULL) {
821 if (isParameterValid(valstr, mCameraProperties->get(CameraProperties::SUPPORTED_FLASH_MODES))) {
822 CAMHAL_LOGDB("Flash mode set %s", valstr);
823 mParameters.set(CameraParameters::KEY_FLASH_MODE, valstr);
824 } else {
825 CAMHAL_LOGEB("ERROR: Invalid Flash mode = %s", valstr);
826 ret = -EINVAL;
827 }
828 } else {
829
830 CAMHAL_LOGDA("WARNING : not support flash light, skip the parameter");
831
832 }
833 }
834
835 if ((valstr = params.get(CameraParameters::KEY_EFFECT)) != NULL) {
836 if (isParameterValid(valstr, mCameraProperties->get(CameraProperties::SUPPORTED_EFFECTS))) {
837 CAMHAL_LOGDB("Effect set %s", valstr);
838 mParameters.set(CameraParameters::KEY_EFFECT, valstr);
839 } else {
840 CAMHAL_LOGEB("ERROR: Invalid Effect = %s", valstr);
841 ret = -EINVAL;
842 }
843 }
844
845 if(( (valstr = params.get(CameraParameters::KEY_ROTATION)) != NULL)
846 && (params.getInt(CameraParameters::KEY_ROTATION) >=0))
847 {
848 CAMHAL_LOGDB("Rotation set %s", params.get(CameraParameters::KEY_ROTATION));
849 mParameters.set(CameraParameters::KEY_ROTATION, valstr);
850 }
851
852 if(( (valstr = params.get(CameraParameters::KEY_JPEG_QUALITY)) != NULL)
853 && (params.getInt(CameraParameters::KEY_JPEG_QUALITY) >=0))
854 {
855 CAMHAL_LOGDB("Jpeg quality set %s", params.get(CameraParameters::KEY_JPEG_QUALITY));
856 mParameters.set(CameraParameters::KEY_JPEG_QUALITY, valstr);
857 }
858
859 if(( (valstr = params.get(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH)) != NULL)
860 && (params.getInt(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH) >=0))
861 {
862 CAMHAL_LOGDB("Thumbnail width set %s", params.get(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH));
863 mParameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, valstr);
864 }
865
866 if(( (valstr = params.get(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT)) != NULL)
867 && (params.getInt(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT) >=0))
868 {
869 CAMHAL_LOGDB("Thumbnail width set %s", params.get(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT));
870 mParameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, valstr);
871 }
872
873 if(( (valstr = params.get(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY)) != NULL )
874 && (params.getInt(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY) >=0))
875 {
876 CAMHAL_LOGDB("Thumbnail quality set %s", params.get(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY));
877 mParameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, valstr);
878 }
879
880 if( (valstr = params.get(CameraParameters::KEY_GPS_LATITUDE)) != NULL )
881 {
882 CAMHAL_LOGDB("GPS latitude set %s", params.get(CameraParameters::KEY_GPS_LATITUDE));
883 mParameters.set(CameraParameters::KEY_GPS_LATITUDE, valstr);
884 }else{
885 mParameters.remove(CameraParameters::KEY_GPS_LATITUDE);
886 }
887
888 if( (valstr = params.get(CameraParameters::KEY_GPS_LONGITUDE)) != NULL )
889 {
890 CAMHAL_LOGDB("GPS longitude set %s", params.get(CameraParameters::KEY_GPS_LONGITUDE));
891 mParameters.set(CameraParameters::KEY_GPS_LONGITUDE, valstr);
892 }else{
893 mParameters.remove(CameraParameters::KEY_GPS_LONGITUDE);
894 }
895
896 if( (valstr = params.get(CameraParameters::KEY_GPS_ALTITUDE)) != NULL )
897 {
898 CAMHAL_LOGDB("GPS altitude set %s", params.get(CameraParameters::KEY_GPS_ALTITUDE));
899 mParameters.set(CameraParameters::KEY_GPS_ALTITUDE, valstr);
900 }else{
901 mParameters.remove(CameraParameters::KEY_GPS_ALTITUDE);
902 }
903
904 if( (valstr = params.get(CameraParameters::KEY_GPS_TIMESTAMP)) != NULL )
905 {
906 CAMHAL_LOGDB("GPS timestamp set %s", params.get(CameraParameters::KEY_GPS_TIMESTAMP));
907 mParameters.set(CameraParameters::KEY_GPS_TIMESTAMP, valstr);
908 }else{
909 mParameters.remove(CameraParameters::KEY_GPS_TIMESTAMP);
910 }
911
912 if( (valstr = params.get(ExCameraParameters::KEY_GPS_DATESTAMP)) != NULL )
913 {
914 CAMHAL_LOGDB("GPS datestamp set %s", params.get(ExCameraParameters::KEY_GPS_DATESTAMP));
915 mParameters.set(ExCameraParameters::KEY_GPS_DATESTAMP, valstr);
916 }else{
917 mParameters.remove(ExCameraParameters::KEY_GPS_DATESTAMP);
918 }
919
920 if( (valstr = params.get(CameraParameters::KEY_GPS_PROCESSING_METHOD)) != NULL )
921 {
922 CAMHAL_LOGDB("GPS processing method set %s", params.get(CameraParameters::KEY_GPS_PROCESSING_METHOD));
923 mParameters.set(CameraParameters::KEY_GPS_PROCESSING_METHOD, valstr);
924 }else{
925 mParameters.remove(CameraParameters::KEY_GPS_PROCESSING_METHOD);
926 }
927
928 if( (valstr = params.get(ExCameraParameters::KEY_GPS_MAPDATUM )) != NULL )
929 {
930 CAMHAL_LOGDB("GPS MAPDATUM set %s", params.get(ExCameraParameters::KEY_GPS_MAPDATUM));
931 mParameters.set(ExCameraParameters::KEY_GPS_MAPDATUM, valstr);
932 }else{
933 mParameters.remove(ExCameraParameters::KEY_GPS_MAPDATUM);
934 }
935
936 if( (valstr = params.get(ExCameraParameters::KEY_GPS_VERSION)) != NULL )
937 {
938 CAMHAL_LOGDB("GPS MAPDATUM set %s", params.get(ExCameraParameters::KEY_GPS_VERSION));
939 mParameters.set(ExCameraParameters::KEY_GPS_VERSION, valstr);
940 }else{
941 mParameters.remove(ExCameraParameters::KEY_GPS_VERSION);
942 }
943
944 if( (valstr = params.get(ExCameraParameters::KEY_EXIF_MODEL)) != NULL )
945 {
946 CAMHAL_LOGDB("EXIF Model set %s", params.get(ExCameraParameters::KEY_EXIF_MODEL));
947 mParameters.set(ExCameraParameters::KEY_EXIF_MODEL, valstr);
948 }
949
950 if( (valstr = params.get(ExCameraParameters::KEY_EXIF_MAKE)) != NULL )
951 {
952 CAMHAL_LOGDB("EXIF Make set %s", params.get(ExCameraParameters::KEY_EXIF_MAKE));
953 mParameters.set(ExCameraParameters::KEY_EXIF_MAKE, valstr);
954 }
955
956 if( (valstr = params.get(ExCameraParameters::KEY_EXP_BRACKETING_RANGE)) != NULL )
957 {
958 CAMHAL_LOGDB("Exposure Bracketing set %s", params.get(ExCameraParameters::KEY_EXP_BRACKETING_RANGE));
959 mParameters.set(ExCameraParameters::KEY_EXP_BRACKETING_RANGE, valstr);
960 }
961 else
962 {
963 mParameters.remove(ExCameraParameters::KEY_EXP_BRACKETING_RANGE);
964 }
965
966 if ((valstr = params.get(CameraParameters::KEY_ZOOM)) != NULL ) {
967 if ((params.getInt(CameraParameters::KEY_ZOOM) >= 0 ) &&
968 (params.getInt(CameraParameters::KEY_ZOOM) <= mMaxZoomSupported )) {
969 CAMHAL_LOGDB("Zoom set %s", valstr);
970 doesSetParameterNeedUpdate(valstr,
971 mParameters.get(CameraParameters::KEY_ZOOM),
972 updateRequired);
973 mParameters.set(CameraParameters::KEY_ZOOM, valstr);
974 } else {
975 CAMHAL_LOGEB("ERROR: Invalid Zoom: %s", valstr);
976 ret = -EINVAL;
977 }
978 }
979
980 if( (valstr = params.get(CameraParameters::KEY_AUTO_EXPOSURE_LOCK)) != NULL )
981 {
982 CAMHAL_LOGDB("Auto Exposure Lock set %s", params.get(CameraParameters::KEY_AUTO_EXPOSURE_LOCK));
983 doesSetParameterNeedUpdate(valstr,
984 mParameters.get(CameraParameters::KEY_AUTO_EXPOSURE_LOCK),
985 updateRequired);
986 mParameters.set(CameraParameters::KEY_AUTO_EXPOSURE_LOCK, valstr);
987 }
988
989 if( (valstr = params.get(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK)) != NULL )
990 {
991 CAMHAL_LOGDB("Auto WhiteBalance Lock set %s", params.get(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK));
992 doesSetParameterNeedUpdate(valstr,
993 mParameters.get(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK),
994 updateRequired);
995 mParameters.set(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK, valstr);
996 }
997 if( (valstr = params.get(CameraParameters::KEY_METERING_AREAS)) != NULL )
998 {
999 CAMHAL_LOGEB("Metering areas position set %s", params.get(CameraParameters::KEY_METERING_AREAS));
1000 mParameters.set(CameraParameters::KEY_METERING_AREAS, valstr);
1001 }
1002
1003 CAMHAL_LOGDB("KEY_PICTURE_SIZE=%s", mParameters.get(CameraParameters::KEY_PICTURE_SIZE));
1004 CameraParameters adapterParams = mParameters;
1005
1006 // Only send parameters to adapter if preview is already
1007 // enabled or doesSetParameterNeedUpdate says so. Initial setParameters to camera adapter,
1008 // will be called in startPreview()
1009 // TODO(XXX): Need to identify other parameters that need update from camera adapter
1010 CAMHAL_LOGDB("mCameraAdapter=%p,mPreviewEnabled=%d,updateRequired=%d",
1011 mCameraAdapter, mPreviewEnabled, updateRequired);
1012 if ( (NULL != mCameraAdapter) && (mPreviewEnabled || updateRequired) ) {
1013 ret |= mCameraAdapter->setParameters(adapterParams);
1014 }
1015 CAMHAL_LOGDB("KEY_PICTURE_SIZE=%s", mParameters.get(CameraParameters::KEY_PICTURE_SIZE));
1016
1017 if( NULL != params.get(ExCameraParameters::KEY_TEMP_BRACKETING_RANGE_POS) )
1018 {
1019 int posBracketRange = params.getInt(ExCameraParameters::KEY_TEMP_BRACKETING_RANGE_POS);
1020 if ( 0 < posBracketRange )
1021 {
1022 mBracketRangePositive = posBracketRange;
1023 }
1024 }
1025 CAMHAL_LOGDB("Positive bracketing range %d", mBracketRangePositive);
1026
1027
1028 if( NULL != params.get(ExCameraParameters::KEY_TEMP_BRACKETING_RANGE_NEG) )
1029 {
1030 int negBracketRange = params.getInt(ExCameraParameters::KEY_TEMP_BRACKETING_RANGE_NEG);
1031 if ( 0 < negBracketRange )
1032 {
1033 mBracketRangeNegative = negBracketRange;
1034 }
1035 }
1036 CAMHAL_LOGDB("Negative bracketing range %d", mBracketRangeNegative);
1037
1038 if( ( (valstr = params.get(ExCameraParameters::KEY_TEMP_BRACKETING)) != NULL) &&
1039 ( strcmp(valstr, ExCameraParameters::BRACKET_ENABLE) == 0 ))
1040 {
1041 if ( !mBracketingEnabled )
1042 {
1043 CAMHAL_LOGDA("Enabling bracketing");
1044 mBracketingEnabled = true;
1045
1046 //Wait for AF events to enable bracketing
1047 if ( NULL != mCameraAdapter )
1048 {
1049 setEventProvider( CameraHalEvent::ALL_EVENTS, mCameraAdapter );
1050 }
1051 }
1052 else
1053 {
1054 CAMHAL_LOGDA("Bracketing already enabled");
1055 }
1056 }
1057 else if ( ( (valstr = params.get(ExCameraParameters::KEY_TEMP_BRACKETING)) != NULL ) &&
1058 ( strcmp(valstr, ExCameraParameters::BRACKET_DISABLE) == 0 ))
1059 {
1060 CAMHAL_LOGDA("Disabling bracketing");
1061
1062 mBracketingEnabled = false;
1063 stopImageBracketing();
1064
1065 //Remove AF events subscription
1066 if ( NULL != mEventProvider )
1067 {
1068 mEventProvider->disableEventNotification( CameraHalEvent::ALL_EVENTS );
1069 delete mEventProvider;
1070 mEventProvider = NULL;
1071 }
1072
1073 }
1074
1075 if( ( (valstr = params.get(ExCameraParameters::KEY_SHUTTER_ENABLE)) != NULL ) &&
1076 ( strcmp(valstr, ExCameraParameters::SHUTTER_ENABLE) == 0 ))
1077 {
1078 CAMHAL_LOGDA("Enabling shutter sound");
1079
1080 mShutterEnabled = true;
1081 mMsgEnabled |= CAMERA_MSG_SHUTTER;
1082 mParameters.set(ExCameraParameters::KEY_SHUTTER_ENABLE, valstr);
1083 }
1084 else if ( ( (valstr = params.get(ExCameraParameters::KEY_SHUTTER_ENABLE)) != NULL ) &&
1085 ( strcmp(valstr, ExCameraParameters::SHUTTER_DISABLE) == 0 ))
1086 {
1087 CAMHAL_LOGDA("Disabling shutter sound");
1088
1089 mShutterEnabled = false;
1090 mMsgEnabled &= ~CAMERA_MSG_SHUTTER;
1091 mParameters.set(ExCameraParameters::KEY_SHUTTER_ENABLE, valstr);
1092 }
1093
1094 }
1095
1096 //On fail restore old parameters
1097 if ( NO_ERROR != ret ) {
1098 mParameters.unflatten(oldParams.flatten());
1099 }
1100
1101 // Restart Preview if needed by KEY_RECODING_HINT only if preview is already running.
1102 // If preview is not started yet, Video Mode parameters will take effect on next startPreview()
1103 if (restartPreviewRequired && previewEnabled() && !mRecordingEnabled) {
1104 CAMHAL_LOGDA("Restarting Preview");
1105 ret = restartPreview();
1106 } else if (restartPreviewRequired && !previewEnabled() &&
1107 mDisplayPaused && !mRecordingEnabled) {
1108 CAMHAL_LOGDA("Stopping Preview");
1109 forceStopPreview();
1110 }
1111
1112 if (ret != NO_ERROR)
1113 {
1114 CAMHAL_LOGEA("Failed to restart Preview");
1115 return ret;
1116 }
1117
1118 CAMHAL_LOGDB("KEY_PICTURE_SIZE=%s", mParameters.get(CameraParameters::KEY_PICTURE_SIZE));
1119 LOG_FUNCTION_NAME_EXIT;
1120
1121 return ret;
1122}
1123
1124status_t VirtualCamHal::allocPreviewBufs(int width, int height, const char* previewFormat,
1125 unsigned int buffercount, unsigned int &max_queueable)
1126{
1127 status_t ret = NO_ERROR;
1128
1129 LOG_FUNCTION_NAME;
1130
1131 if(mDisplayAdapter.get() == NULL)
1132 {
1133 // Memory allocation of preview buffers is now placed in gralloc
1134 // VirtualCamHal should not allocate preview buffers without DisplayAdapter
1135 return NO_MEMORY;
1136 }
1137
1138 if(!mPreviewBufs)
1139 {
1140 ///@todo Pluralise the name of this method to allocateBuffers
1141 mPreviewLength = 0;
1142#ifndef AMLOGIC_CAMERA_OVERLAY_SUPPORT
1143 mPreviewBufs = (int32_t *) mDisplayAdapter->allocateBuffer(width, height,
1144 previewFormat,
1145 mPreviewLength,
1146 buffercount);
1147
1148 CAMHAL_LOGDB("buffercount=%d", buffercount);
1149
1150 if (NULL == mPreviewBufs ) {
1151 CAMHAL_LOGEA("Couldn't allocate preview buffers");
1152 return NO_MEMORY;
1153 }
1154
1155 mPreviewOffsets = (uint32_t *) mDisplayAdapter->getOffsets();
1156 if ( NULL == mPreviewOffsets ) {
1157 CAMHAL_LOGEA("Buffer mapping failed");
1158 return BAD_VALUE;
1159 }
1160
1161 mPreviewFd = mDisplayAdapter->getFd();
1162 /* mPreviewFd and desc.mFd seem to be unused.
1163 if ( -1 == mPreviewFd ) {
1164 CAMHAL_LOGEA("Invalid handle");
1165 return BAD_VALUE;
1166 }*/
1167
1168 mBufProvider = (BufferProvider*) mDisplayAdapter.get();
1169
1170 ret = mDisplayAdapter->maxQueueableBuffers(max_queueable);
1171 if (ret != NO_ERROR) {
1172 return ret;
1173 }
1174#else
1175 int buf_size = 0;
1176 if ( previewFormat != NULL ) {
1177 if(strcmp(previewFormat,(const char *) CameraParameters::PIXEL_FORMAT_YUV422I) == 0) {
1178 buf_size = width * height * 2;
1179 }else if((strcmp(previewFormat, CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) ||
1180 (strcmp(previewFormat, CameraParameters::PIXEL_FORMAT_YUV420P) == 0)) {
1181 buf_size = width * height * 3 / 2;
1182 }else if(strcmp(previewFormat,(const char *) CameraParameters::PIXEL_FORMAT_RGB565) == 0) {
1183 buf_size = width * height * 2;
1184 } else {
1185 CAMHAL_LOGEA("Invalid format");
1186 buf_size = 0;
1187 }
1188 } else {
1189 CAMHAL_LOGEA("Preview format is NULL");
1190 buf_size = 0;
1191 }
1192
1193 //buf_size = ((buf_size+4095)/4096)*4096;
1194 mPreviewBufs = (int32_t *)mMemoryManager->allocateBuffer(0, 0, NULL, buf_size, buffercount);
1195
1196 CAMHAL_LOGDB("buffercount=%d", buffercount);
1197
1198 if (NULL == mPreviewBufs ) {
1199 CAMHAL_LOGEA("Couldn't allocate preview buffers");
1200 return NO_MEMORY;
1201 }
1202
1203 mPreviewLength = buf_size;
1204
1205 mPreviewOffsets = (uint32_t *) mMemoryManager->getOffsets();
1206 //if ( NULL == mPreviewOffsets ) {
1207 // CAMHAL_LOGEA("Buffer mapping failed");
1208 // return BAD_VALUE;
1209 //}
1210
1211 mPreviewFd = mMemoryManager->getFd();
1212 /* mPreviewFd and desc.mFd seem to be unused.
1213 if ( -1 == mPreviewFd ) {
1214 CAMHAL_LOGEA("Invalid handle");
1215 return BAD_VALUE;
1216 }*/
1217
1218 mBufProvider = (BufferProvider*) mMemoryManager.get();
1219 max_queueable = buffercount;
1220 //ret = mDisplayAdapter->maxQueueableBuffers(max_queueable);
1221 //if (ret != NO_ERROR) {
1222 // return ret;
1223 //}
1224#endif
1225 }
1226
1227 LOG_FUNCTION_NAME_EXIT;
1228
1229 return ret;
1230
1231}
1232
1233status_t VirtualCamHal::freePreviewBufs()
1234{
1235 status_t ret = NO_ERROR;
1236 LOG_FUNCTION_NAME;
1237
1238 CAMHAL_LOGDB("mPreviewBufs = 0x%x", (unsigned int)mPreviewBufs);
1239 if(mPreviewBufs)
1240 {
1241 ///@todo Pluralise the name of this method to freeBuffers
1242 ret = mBufProvider->freeBuffer(mPreviewBufs);
1243 mPreviewBufs = NULL;
1244 LOG_FUNCTION_NAME_EXIT;
1245 return ret;
1246 }
1247 LOG_FUNCTION_NAME_EXIT;
1248 return ret;
1249}
1250
1251
1252status_t VirtualCamHal::allocPreviewDataBufs(size_t size, size_t bufferCount)
1253{
1254 status_t ret = NO_ERROR;
1255 int bytes;
1256
1257 LOG_FUNCTION_NAME;
1258
1259 bytes = size;
1260
1261 if ( NO_ERROR == ret )
1262 {
1263 if( NULL != mPreviewDataBufs )
1264 {
1265 ret = freePreviewDataBufs();
1266 }
1267 }
1268
1269 if ( NO_ERROR == ret )
1270 {
1271 bytes = ((bytes+4095)/4096)*4096;
1272 mPreviewDataBufs = (int32_t *)mMemoryManager->allocateBuffer(0, 0, NULL, bytes, bufferCount);
1273
1274 CAMHAL_LOGDB("Size of Preview data buffer = %d", bytes);
1275 if( NULL == mPreviewDataBufs )
1276 {
1277 CAMHAL_LOGEA("Couldn't allocate image buffers using memory manager");
1278 ret = -NO_MEMORY;
1279 }
1280 else
1281 {
1282 bytes = size;
1283 }
1284 }
1285
1286 if ( NO_ERROR == ret )
1287 {
1288 mPreviewDataFd = mMemoryManager->getFd();
1289 mPreviewDataLength = bytes;
1290 mPreviewDataOffsets = mMemoryManager->getOffsets();
1291 }
1292 else
1293 {
1294 mPreviewDataFd = -1;
1295 mPreviewDataLength = 0;
1296 mPreviewDataOffsets = NULL;
1297 }
1298
1299 LOG_FUNCTION_NAME;
1300
1301 return ret;
1302}
1303
1304status_t VirtualCamHal::freePreviewDataBufs()
1305{
1306 status_t ret = NO_ERROR;
1307
1308 LOG_FUNCTION_NAME;
1309
1310 if ( NO_ERROR == ret )
1311 {
1312
1313 if( NULL != mPreviewDataBufs )
1314 {
1315
1316 ///@todo Pluralise the name of this method to freeBuffers
1317 ret = mMemoryManager->freeBuffer(mPreviewDataBufs);
1318 mPreviewDataBufs = NULL;
1319
1320 }
1321 }
1322
1323 LOG_FUNCTION_NAME_EXIT;
1324
1325 return ret;
1326}
1327
1328status_t VirtualCamHal::allocImageBufs(unsigned int width, unsigned int height, size_t size, const char* previewFormat, unsigned int bufferCount)
1329{
1330 status_t ret = NO_ERROR;
1331 int bytes;
1332
1333 LOG_FUNCTION_NAME;
1334
1335 bytes = size;
1336
1337 // allocate image buffers only if not already allocated
1338 if(NULL != mImageBufs) {
1339 CAMHAL_LOGEB("mImageBufs is not null:0x%p",mImageBufs);
1340 return NO_ERROR;
1341 }
1342
1343 if ( NO_ERROR == ret )
1344 {
1345 bytes = ((bytes+4095)/4096)*4096;
1346 mImageBufs = (int32_t *)mMemoryManager->allocateBuffer(0, 0, previewFormat, bytes, bufferCount);
1347
1348 CAMHAL_LOGDB("Size of Image cap buffer = %d", bytes);
1349 if( NULL == mImageBufs )
1350 {
1351 CAMHAL_LOGEA("Couldn't allocate image buffers using memory manager");
1352 ret = -NO_MEMORY;
1353 }
1354 else
1355 {
1356 bytes = size;
1357 }
1358 }
1359
1360 if ( NO_ERROR == ret )
1361 {
1362 mImageFd = mMemoryManager->getFd();
1363 mImageLength = bytes;
1364 mImageOffsets = mMemoryManager->getOffsets();
1365 }
1366 else
1367 {
1368 mImageFd = -1;
1369 mImageLength = 0;
1370 mImageOffsets = NULL;
1371 }
1372
1373 LOG_FUNCTION_NAME;
1374
1375 return ret;
1376}
1377
1378status_t VirtualCamHal::allocVideoBufs(uint32_t width, uint32_t height, uint32_t bufferCount)
1379{
1380 status_t ret = NO_ERROR;
1381 LOG_FUNCTION_NAME;
1382
1383 if( NULL != mVideoBufs ){
1384 ret = freeVideoBufs(mVideoBufs);
1385 mVideoBufs = NULL;
1386 }
1387
1388 if ( NO_ERROR == ret ){
1389 int32_t stride;
1390 buffer_handle_t *bufsArr = new buffer_handle_t [bufferCount];
1391
1392 if (bufsArr != NULL){
1393 for (uint32_t i = 0; i< bufferCount; i++){
1394 GraphicBufferAllocator &GrallocAlloc = GraphicBufferAllocator::get();
1395 buffer_handle_t buf;
1396 ret = GrallocAlloc.alloc(width, height, HAL_PIXEL_FORMAT_NV12, CAMHAL_GRALLOC_USAGE, &buf, &stride);
1397 if (ret != NO_ERROR){
1398 CAMHAL_LOGEA("Couldn't allocate video buffers using Gralloc");
1399 ret = -NO_MEMORY;
1400 for (uint32_t j=0; j< i; j++){
1401 buf = (buffer_handle_t)bufsArr[j];
1402 CAMHAL_LOGEB("Freeing Gralloc Buffer 0x%x", (uint32_t)buf);
1403 GrallocAlloc.free(buf);
1404 }
1405 delete [] bufsArr;
1406 goto exit;
1407 }
1408 bufsArr[i] = buf;
1409 CAMHAL_LOGVB("*** Gralloc Handle =0x%x ***", (uint32_t)buf);
1410 }
1411
1412 mVideoBufs = (int32_t *)bufsArr;
1413 }
1414 else{
1415 CAMHAL_LOGEA("Couldn't allocate video buffers ");
1416 ret = -NO_MEMORY;
1417 }
1418 }
1419
1420 exit:
1421 LOG_FUNCTION_NAME;
1422
1423 return ret;
1424}
1425
1426void endImageCapture( void *userData)
1427{
1428 LOG_FUNCTION_NAME;
1429
1430 if ( NULL != userData )
1431 {
1432 VirtualCamHal *c = reinterpret_cast<VirtualCamHal *>(userData);
1433 c->signalEndImageCapture();
1434 }
1435
1436 LOG_FUNCTION_NAME_EXIT;
1437}
1438
1439void releaseImageBuffers(void *userData)
1440{
1441 LOG_FUNCTION_NAME;
1442
1443 if (NULL != userData) {
1444 VirtualCamHal *c = reinterpret_cast<VirtualCamHal *>(userData);
1445 c->freeImageBufs();
1446 }
1447
1448 LOG_FUNCTION_NAME_EXIT;
1449}
1450
1451status_t VirtualCamHal::signalEndImageCapture()
1452{
1453 status_t ret = NO_ERROR;
1454 int w,h;
1455 CameraParameters adapterParams = mParameters;
1456 Mutex::Autolock lock(mLock);
1457
1458 LOG_FUNCTION_NAME;
1459
1460 if ( mBracketingRunning ) {
1461 stopImageBracketing();
1462 } else {
1463 mCameraAdapter->sendCommand(CameraAdapter::CAMERA_STOP_IMAGE_CAPTURE);
1464 }
1465
1466 LOG_FUNCTION_NAME_EXIT;
1467
1468 return ret;
1469}
1470
1471status_t VirtualCamHal::freeImageBufs()
1472{
1473 status_t ret = NO_ERROR;
1474
1475 LOG_FUNCTION_NAME;
1476
1477 if ( NO_ERROR == ret )
1478 {
1479
1480 if( NULL != mImageBufs )
1481 {
1482
1483 ///@todo Pluralise the name of this method to freeBuffers
1484 ret = mMemoryManager->freeBuffer(mImageBufs);
1485 mImageBufs = NULL;
1486
1487 }
1488 else
1489 {
1490 ret = -EINVAL;
1491 }
1492
1493 }
1494
1495 LOG_FUNCTION_NAME_EXIT;
1496
1497 return ret;
1498}
1499
1500status_t VirtualCamHal::freeVideoBufs(void *bufs)
1501{
1502 status_t ret = NO_ERROR;
1503
1504 LOG_FUNCTION_NAME;
1505
1506 buffer_handle_t *pBuf = (buffer_handle_t*)bufs;
1507 int count = atoi(mCameraProperties->get(CameraProperties::REQUIRED_PREVIEW_BUFS));
1508 if(pBuf == NULL)
1509 {
1510 CAMHAL_LOGEA("NULL pointer passed to freeVideoBuffer");
1511 LOG_FUNCTION_NAME_EXIT;
1512 return BAD_VALUE;
1513 }
1514
1515 GraphicBufferAllocator &GrallocAlloc = GraphicBufferAllocator::get();
1516
1517 for(int i = 0; i < count; i++){
1518 buffer_handle_t ptr = *pBuf++;
1519 CAMHAL_LOGVB("Free Video Gralloc Handle 0x%x", (uint32_t)ptr);
1520 GrallocAlloc.free(ptr);
1521 }
1522
1523 LOG_FUNCTION_NAME_EXIT;
1524
1525 return ret;
1526}
1527
1528/**
1529 @brief Start preview mode.
1530
1531 @param none
1532 @return NO_ERROR Camera switched to VF mode
1533 @todo Update function header with the different errors that are possible
1534
1535 */
1536status_t VirtualCamHal::startPreview()
1537{
1538 status_t ret = NO_ERROR;
1539 CameraAdapter::BuffersDescriptor desc;
1540 CameraFrame frame;
1541 const char *valstr = NULL;
1542 unsigned int required_buffer_count;
1543 unsigned int max_queueble_buffers;
1544
1545#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
1546 gettimeofday(&mStartPreview, NULL);
1547#endif
1548
1549 LOG_FUNCTION_NAME;
1550
1551 if ( mPreviewEnabled ){
1552 CAMHAL_LOGDA("Preview already running");
1553 LOG_FUNCTION_NAME_EXIT;
1554 return ALREADY_EXISTS;
1555 }
1556
1557 if ( NULL != mCameraAdapter ) {
1558 ret = mCameraAdapter->setParameters(mParameters);
1559 }
1560
1561 if ((mPreviewStartInProgress == false) && (mDisplayPaused == false)){
1562 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_QUERY_RESOLUTION_PREVIEW,( int ) &frame);
1563 if ( NO_ERROR != ret ){
1564 CAMHAL_LOGEB("Error: CAMERA_QUERY_RESOLUTION_PREVIEW %d", ret);
1565 return ret;
1566 }
1567
1568 ///Update the current preview width and height
1569 mPreviewWidth = frame.mWidth;
1570 mPreviewHeight = frame.mHeight;
1571 //Update the padded width and height - required for VNF and VSTAB
1572 mParameters.set(ExCameraParameters::KEY_PADDED_WIDTH, mPreviewWidth);
1573 mParameters.set(ExCameraParameters::KEY_PADDED_HEIGHT, mPreviewHeight);
1574
1575 }
1576
1577 ///If we don't have the preview callback enabled and display adapter,
1578 if(!mSetPreviewWindowCalled || (mDisplayAdapter.get() == NULL)){
1579 CAMHAL_LOGEA("Preview not started. Preview in progress flag set");
1580 mPreviewStartInProgress = true;
1581 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_SWITCH_TO_EXECUTING);
1582 if ( NO_ERROR != ret ){
1583 CAMHAL_LOGEB("Error: CAMERA_SWITCH_TO_EXECUTING %d", ret);
1584 return ret;
1585 }
1586 return NO_ERROR;
1587 }
1588
1589 if( (mDisplayAdapter.get() != NULL) && ( !mPreviewEnabled ) && ( mDisplayPaused ) )
1590 {
1591 CAMHAL_LOGDA("Preview is in paused state");
1592
1593 mDisplayPaused = false;
1594 mPreviewEnabled = true;
1595 if ( NO_ERROR == ret )
1596 {
1597 ret = mDisplayAdapter->pauseDisplay(mDisplayPaused);
1598 if ( NO_ERROR != ret )
1599 {
1600 CAMHAL_LOGEB("Display adapter resume failed %x", ret);
1601 }
1602 }
1603 //restart preview callbacks
1604 if(mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME)
1605 {
1606 mAppCbNotifier->enableMsgType (CAMERA_MSG_PREVIEW_FRAME);
1607 }
1608 return ret;
1609 }
1610 required_buffer_count = atoi(mCameraProperties->get(CameraProperties::REQUIRED_PREVIEW_BUFS));
1611
1612 ///Allocate the preview buffers
1613 ret = allocPreviewBufs(mPreviewWidth, mPreviewHeight, mParameters.getPreviewFormat(), required_buffer_count, max_queueble_buffers);
1614
1615 if ( NO_ERROR != ret )
1616 {
1617 CAMHAL_LOGEA("Couldn't allocate buffers for Preview");
1618 goto error;
1619 }
1620
1621 if ( mMeasurementEnabled )
1622 {
1623 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_QUERY_BUFFER_SIZE_PREVIEW_DATA,
1624 ( int ) &frame,
1625 required_buffer_count);
1626 if ( NO_ERROR != ret )
1627 {
1628 return ret;
1629 }
1630
1631 ///Allocate the preview data buffers
1632 ret = allocPreviewDataBufs(frame.mLength, required_buffer_count);
1633 if ( NO_ERROR != ret ) {
1634 CAMHAL_LOGEA("Couldn't allocate preview data buffers");
1635 goto error;
1636 }
1637
1638 if ( NO_ERROR == ret )
1639 {
1640 desc.mBuffers = mPreviewDataBufs;
1641 desc.mOffsets = mPreviewDataOffsets;
1642 desc.mFd = mPreviewDataFd;
1643 desc.mLength = mPreviewDataLength;
1644 desc.mCount = ( size_t ) required_buffer_count;
1645 desc.mMaxQueueable = (size_t) required_buffer_count;
1646 mCameraAdapter->sendCommand(CameraAdapter::CAMERA_USE_BUFFERS_PREVIEW_DATA,
1647 ( int ) &desc);
1648 }
1649 }
1650
1651 ///Pass the buffers to Camera Adapter
1652 desc.mBuffers = mPreviewBufs;
1653 desc.mOffsets = mPreviewOffsets;
1654 desc.mFd = mPreviewFd;
1655 desc.mLength = mPreviewLength;
1656 desc.mCount = ( size_t ) required_buffer_count;
1657 desc.mMaxQueueable = (size_t) max_queueble_buffers;
1658
1659 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_USE_BUFFERS_PREVIEW,
1660 ( int ) &desc);
1661
1662 if ( NO_ERROR != ret )
1663 {
1664 CAMHAL_LOGEB("Failed to register preview buffers: 0x%x", ret);
1665 freePreviewBufs();
1666 return ret;
1667 }
1668
1669 mAppCbNotifier->startPreviewCallbacks(mParameters, mPreviewBufs, mPreviewOffsets, mPreviewFd, mPreviewLength, required_buffer_count);
1670
1671 ///Start the callback notifier
1672 ret = mAppCbNotifier->start();
1673
1674 if( ALREADY_EXISTS == ret )
1675 {
1676 //Already running, do nothing
1677 CAMHAL_LOGDA("AppCbNotifier already running");
1678 ret = NO_ERROR;
1679 }
1680 else if ( NO_ERROR == ret ) {
1681 CAMHAL_LOGDA("Started AppCbNotifier..");
1682 mAppCbNotifier->setMeasurements(mMeasurementEnabled);
1683 }
1684 else
1685 {
1686 CAMHAL_LOGDA("Couldn't start AppCallbackNotifier");
1687 goto error;
1688 }
1689
1690 ///Enable the display adapter if present, actual overlay enable happens when we post the buffer
1691 if(mDisplayAdapter.get() != NULL)
1692 {
1693 CAMHAL_LOGDA("Enabling display");
1694 bool isS3d = false;
1695 DisplayAdapter::S3DParameters s3dParams;
1696 int width, height;
1697 mParameters.getPreviewSize(&width, &height);
1698#if 0 //TODO: s3d is not part of bringup...will reenable
1699 if ( (valstr = mParameters.get(ExCameraParameters::KEY_S3D_SUPPORTED)) != NULL) {
1700 isS3d = (strcmp(valstr, "true") == 0);
1701 }
1702 if ( (valstr = mParameters.get(ExCameraParameters::KEY_S3D2D_PREVIEW)) != NULL) {
1703 if (strcmp(valstr, "off") == 0)
1704 {
1705 CAMHAL_LOGEA("STEREO 3D->2D PREVIEW MODE IS OFF");
1706 //TODO: obtain the frame packing configuration from camera or user settings
1707 //once side by side configuration is supported
1708 s3dParams.mode = OVERLAY_S3D_MODE_ON;
1709 s3dParams.framePacking = OVERLAY_S3D_FORMAT_OVERUNDER;
1710 s3dParams.order = OVERLAY_S3D_ORDER_LF;
1711 s3dParams.subSampling = OVERLAY_S3D_SS_NONE;
1712 }
1713 else
1714 {
1715 CAMHAL_LOGEA("STEREO 3D->2D PREVIEW MODE IS ON");
1716 s3dParams.mode = OVERLAY_S3D_MODE_OFF;
1717 s3dParams.framePacking = OVERLAY_S3D_FORMAT_OVERUNDER;
1718 s3dParams.order = OVERLAY_S3D_ORDER_LF;
1719 s3dParams.subSampling = OVERLAY_S3D_SS_NONE;
1720 }
1721 }
1722#endif //if 0
1723
1724#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
1725
1726 ret = mDisplayAdapter->enableDisplay(width, height, &mStartPreview, isS3d ? &s3dParams : NULL);
1727#else
1728 ret = mDisplayAdapter->enableDisplay(width, height, NULL, isS3d ? &s3dParams : NULL);
1729#endif
1730 if ( ret != NO_ERROR )
1731 {
1732 CAMHAL_LOGEA("Couldn't enable display");
1733 goto error;
1734 }
1735 }
1736
1737 ///Send START_PREVIEW command to adapter
1738 CAMHAL_LOGDA("Starting CameraAdapter preview mode");
1739 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_PREVIEW);
1740 if(ret!=NO_ERROR)
1741 {
1742 CAMHAL_LOGEA("Couldn't start preview w/ CameraAdapter");
1743 goto error;
1744 }
1745 CAMHAL_LOGDA("Started preview");
1746
1747 mPreviewEnabled = true;
1748 mPreviewStartInProgress = false;
1749 return ret;
1750
1751error:
1752 CAMHAL_LOGEA("Performing cleanup after error");
1753 //Do all the cleanup
1754 freePreviewBufs();
1755 mCameraAdapter->sendCommand(CameraAdapter::CAMERA_STOP_PREVIEW);
1756 if(mDisplayAdapter.get() != NULL)
1757 {
1758 mDisplayAdapter->disableDisplay(false);
1759 }
1760 mAppCbNotifier->stop();
1761 mPreviewStartInProgress = false;
1762 mPreviewEnabled = false;
1763 LOG_FUNCTION_NAME_EXIT;
1764 return ret;
1765}
1766
1767/**
1768 @brief Sets ANativeWindow object.
1769
1770 Preview buffers provided to VirtualCamHal via this object. DisplayAdapter will be interfacing with it
1771 to render buffers to display.
1772
1773 @param[in] window The ANativeWindow object created by Surface flinger
1774 @return NO_ERROR If the ANativeWindow object passes validation criteria
1775 @todo Define validation criteria for ANativeWindow object. Define error codes for scenarios
1776
1777 */
1778status_t VirtualCamHal::setPreviewWindow(struct preview_stream_ops *window)
1779{
1780 status_t ret = NO_ERROR;
1781 CameraAdapter::BuffersDescriptor desc;
1782
1783 LOG_FUNCTION_NAME;
1784 mSetPreviewWindowCalled = true;
1785
1786 ///If the Camera service passes a null window, we destroy existing window and free the DisplayAdapter
1787 if(!window)
1788 {
1789 if(mDisplayAdapter.get() != NULL)
1790 {
1791 ///NULL window passed, destroy the display adapter if present
1792 CAMHAL_LOGEA("NULL window passed, destroying display adapter");
1793 mDisplayAdapter.clear();
1794 ///@remarks If there was a window previously existing, we usually expect another valid window to be passed by the client
1795 ///@remarks so, we will wait until it passes a valid window to begin the preview again
1796 mSetPreviewWindowCalled = false;
1797 }
1798 CAMHAL_LOGEA("NULL ANativeWindow passed to setPreviewWindow");
1799 return NO_ERROR;
1800 }else if(mDisplayAdapter.get() == NULL)
1801 {
1802 // Need to create the display adapter since it has not been created
1803 // Create display adapter
1804 mDisplayAdapter = new ANativeWindowDisplayAdapter();
1805 ret = NO_ERROR;
1806 if(!mDisplayAdapter.get() || ((ret=mDisplayAdapter->initialize())!=NO_ERROR))
1807 {
1808 if(ret!=NO_ERROR)
1809 {
1810 mDisplayAdapter.clear();
1811 CAMHAL_LOGEA("DisplayAdapter initialize failed");
1812 LOG_FUNCTION_NAME_EXIT;
1813 return ret;
1814 }
1815 else
1816 {
1817 CAMHAL_LOGEA("Couldn't create DisplayAdapter");
1818 LOG_FUNCTION_NAME_EXIT;
1819 return NO_MEMORY;
1820 }
1821 }
1822
1823 // DisplayAdapter needs to know where to get the CameraFrames from inorder to display
1824 // Since CameraAdapter is the one that provides the frames, set it as the frame provider for DisplayAdapter
1825 mDisplayAdapter->setFrameProvider(mCameraAdapter);
1826
1827 // Any dynamic errors that happen during the camera use case has to be propagated back to the application
1828 // via CAMERA_MSG_ERROR. AppCallbackNotifier is the class that notifies such errors to the application
1829 // Set it as the error handler for the DisplayAdapter
1830 mDisplayAdapter->setErrorHandler(mAppCbNotifier.get());
1831
1832 // Update the display adapter with the new window that is passed from CameraService
1833 ret = mDisplayAdapter->setPreviewWindow(window);
1834 if(ret!=NO_ERROR)
1835 {
1836 CAMHAL_LOGEB("DisplayAdapter setPreviewWindow returned error %d", ret);
1837 }
1838
1839 if(mPreviewStartInProgress)
1840 {
1841 CAMHAL_LOGDA("setPreviewWindow called when preview running");
1842 // Start the preview since the window is now available
1843 ret = startPreview();
1844 }
1845 }else
1846 {
1847 /* If mDisplayAdpater is already created. No need to do anything.
1848 * We get a surface handle directly now, so we can reconfigure surface
1849 * itself in DisplayAdapter if dimensions have changed
1850 */
1851 }
1852 LOG_FUNCTION_NAME_EXIT;
1853
1854 return ret;
1855
1856}
1857
1858
1859/**
1860 @brief Stop a previously started preview.
1861
1862 @param none
1863 @return none
1864
1865 */
1866void VirtualCamHal::stopPreview()
1867{
1868 LOG_FUNCTION_NAME;
1869
1870 if( (!previewEnabled() && !mDisplayPaused) || mRecordingEnabled)
1871 {
1872 LOG_FUNCTION_NAME_EXIT;
1873 return;
1874 }
1875
1876 bool imageCaptureRunning = (mCameraAdapter->getState() == CameraAdapter::CAPTURE_STATE) &&
1877 (mCameraAdapter->getNextState() != CameraAdapter::PREVIEW_STATE);
1878 if(mDisplayPaused && !imageCaptureRunning)
1879 {
1880 // Display is paused, which essentially means there is no preview active.
1881 // Note: this is done so that when stopPreview is called by client after
1882 // an image capture, we do not de-initialize the camera adapter and
1883 // restart over again.
1884 return;
1885 }
1886
1887 forceStopPreview();
1888
1889 // Reset Capture-Mode to default, so that when we switch from VideoRecording
1890 // to ImageCapture, CAPTURE_MODE is not left to VIDEO_MODE.
1891 CAMHAL_LOGDA("Resetting Capture-Mode to default");
1892 mParameters.set(ExCameraParameters::KEY_CAP_MODE, "");
1893
1894 LOG_FUNCTION_NAME_EXIT;
1895}
1896
1897/**
1898 @brief Returns true if preview is enabled
1899
1900 @param none
1901 @return true If preview is running currently
1902 false If preview has been stopped
1903
1904 */
1905bool VirtualCamHal::previewEnabled()
1906{
1907 LOG_FUNCTION_NAME;
1908
1909 return (mPreviewEnabled || mPreviewStartInProgress);
1910}
1911
1912/**
1913 @brief Start record mode.
1914
1915 When a record image is available a CAMERA_MSG_VIDEO_FRAME message is sent with
1916 the corresponding frame. Every record frame must be released by calling
1917 releaseRecordingFrame().
1918
1919 @param none
1920 @return NO_ERROR If recording could be started without any issues
1921 @todo Update the header with possible error values in failure scenarios
1922
1923 */
1924status_t VirtualCamHal::startRecording( )
1925{
1926 int w, h;
1927 const char *valstr = NULL;
1928 bool restartPreviewRequired = false;
1929 status_t ret = NO_ERROR;
1930
1931 LOG_FUNCTION_NAME;
1932
1933#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
1934 gettimeofday(&mStartPreview, NULL);
1935#endif
1936
1937 if(!previewEnabled())
1938 {
1939 return NO_INIT;
1940 }
1941
1942 // set internal recording hint in case camera adapter needs to make some
1943 // decisions....(will only be sent to camera adapter if camera restart is required)
1944 mParameters.set(ExCameraParameters::KEY_RECORDING_HINT, CameraParameters::TRUE);
1945
1946 // if application starts recording in continuous focus picture mode...
1947 // then we need to force default capture mode (as opposed to video mode)
1948 if ( ((valstr = mParameters.get(CameraParameters::KEY_FOCUS_MODE)) != NULL) &&
1949 (strcmp(valstr, CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE) == 0) ){
1950 restartPreviewRequired = resetVideoModeParameters();
1951 }
1952
1953 // only need to check recording hint if preview restart is not already needed
1954 valstr = mParameters.get(CameraParameters::KEY_RECORDING_HINT);
1955 if ( !restartPreviewRequired &&
1956 (!valstr || (valstr && (strcmp(valstr, CameraParameters::TRUE) != 0))) ) {
1957 restartPreviewRequired = setVideoModeParameters(mParameters);
1958 }
1959
1960 if (restartPreviewRequired) {
1961 ret = restartPreview();
1962 }
1963
1964 if ( NO_ERROR == ret )
1965 {
1966 int count = atoi(mCameraProperties->get(CameraProperties::REQUIRED_PREVIEW_BUFS));
1967 mParameters.getPreviewSize(&w, &h);
1968 CAMHAL_LOGDB("%s Video Width=%d Height=%d", __FUNCTION__, mVideoWidth, mVideoHeight);
1969
1970 if ((w != mVideoWidth) && (h != mVideoHeight))
1971 {
1972 ret = allocVideoBufs(mVideoWidth, mVideoHeight, count);
1973 if ( NO_ERROR != ret )
1974 {
1975 CAMHAL_LOGEB("allocVideoBufs returned error 0x%x", ret);
1976 mParameters.remove(ExCameraParameters::KEY_RECORDING_HINT);
1977 return ret;
1978 }
1979
1980 mAppCbNotifier->useVideoBuffers(true);
1981 mAppCbNotifier->setVideoRes(mVideoWidth, mVideoHeight);
1982 ret = mAppCbNotifier->initSharedVideoBuffers(mPreviewBufs, mPreviewOffsets, mPreviewFd, mPreviewLength, count, mVideoBufs);
1983 }
1984 else
1985 {
1986 mAppCbNotifier->useVideoBuffers(false);
1987 mAppCbNotifier->setVideoRes(mPreviewWidth, mPreviewHeight);
1988 ret = mAppCbNotifier->initSharedVideoBuffers(mPreviewBufs, mPreviewOffsets, mPreviewFd, mPreviewLength, count, NULL);
1989 }
1990 }
1991
1992 if ( NO_ERROR == ret )
1993 {
1994 ret = mAppCbNotifier->startRecording();
1995 }
1996
1997 if ( NO_ERROR == ret )
1998 {
1999 ///Buffers for video capture (if different from preview) are expected to be allocated within CameraAdapter
2000 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_VIDEO);
2001 }
2002
2003 if ( NO_ERROR == ret )
2004 {
2005 mRecordingEnabled = true;
2006 }
2007
2008 LOG_FUNCTION_NAME_EXIT;
2009
2010 return ret;
2011}
2012
2013/**
2014 @brief Set the camera parameters specific to Video Recording.
2015
2016 This function checks for the camera parameters which have to be set for recording.
2017 Video Recording needs CAPTURE_MODE to be VIDEO_MODE. This function sets it.
2018 This function also enables Video Recording specific functions like VSTAB & VNF.
2019
2020 @param none
2021 @return true if preview needs to be restarted for VIDEO_MODE parameters to take effect.
2022 @todo Modify the policies for enabling VSTAB & VNF usecase based later.
2023
2024 */
2025bool VirtualCamHal::setVideoModeParameters(const CameraParameters& params)
2026{
2027 const char *valstr = NULL;
2028 bool restartPreviewRequired = false;
2029 status_t ret = NO_ERROR;
2030
2031 LOG_FUNCTION_NAME;
2032
2033 // Set CAPTURE_MODE to VIDEO_MODE, if not set already and Restart Preview
2034 valstr = mParameters.get(ExCameraParameters::KEY_CAP_MODE);
2035 if ( (valstr == NULL) ||
2036 ( (valstr != NULL) && (strcmp(valstr, (const char *) ExCameraParameters::VIDEO_MODE) != 0) ) )
2037 {
2038 CAMHAL_LOGDA("Set CAPTURE_MODE to VIDEO_MODE");
2039 mParameters.set(ExCameraParameters::KEY_CAP_MODE, (const char *) ExCameraParameters::VIDEO_MODE);
2040 restartPreviewRequired = true;
2041 }
2042
2043 // Check if CAPTURE_MODE is VIDEO_MODE, since VSTAB & VNF work only in VIDEO_MODE.
2044 valstr = mParameters.get(ExCameraParameters::KEY_CAP_MODE);
2045 if (strcmp(valstr, (const char *) ExCameraParameters::VIDEO_MODE) == 0) {
2046 // set VSTAB. restart is required if vstab value has changed
2047 if (params.get(CameraParameters::KEY_VIDEO_STABILIZATION) != NULL) {
2048 // make sure we support vstab
2049 if (strcmp(mCameraProperties->get(CameraProperties::VSTAB_SUPPORTED),
2050 CameraParameters::TRUE) == 0) {
2051 valstr = mParameters.get(CameraParameters::KEY_VIDEO_STABILIZATION);
2052 // vstab value has changed
2053 if ((valstr != NULL) &&
2054 strcmp(valstr, params.get(CameraParameters::KEY_VIDEO_STABILIZATION)) != 0) {
2055 restartPreviewRequired = true;
2056 }
2057 mParameters.set(CameraParameters::KEY_VIDEO_STABILIZATION,
2058 params.get(CameraParameters::KEY_VIDEO_STABILIZATION));
2059 }
2060 } else if (mParameters.get(CameraParameters::KEY_VIDEO_STABILIZATION)) {
2061 // vstab was configured but now unset
2062 restartPreviewRequired = true;
2063 mParameters.remove(CameraParameters::KEY_VIDEO_STABILIZATION);
2064 }
2065
2066 // Set VNF
2067 if (params.get(ExCameraParameters::KEY_VNF) == NULL) {
2068 CAMHAL_LOGDA("Enable VNF");
2069 mParameters.set(ExCameraParameters::KEY_VNF, "1");
2070 restartPreviewRequired = true;
2071 } else {
2072 valstr = mParameters.get(ExCameraParameters::KEY_VNF);
2073 if (valstr && strcmp(valstr, params.get(ExCameraParameters::KEY_VNF)) != 0) {
2074 restartPreviewRequired = true;
2075 }
2076 mParameters.set(ExCameraParameters::KEY_VNF, params.get(ExCameraParameters::KEY_VNF));
2077 }
2078
2079 // For VSTAB alone for 1080p resolution, padded width goes > 2048, which cannot be rendered by GPU.
2080 // In such case, there is support in Ducati for combination of VSTAB & VNF requiring padded width < 2048.
2081 // So we are forcefully enabling VNF, if VSTAB is enabled for 1080p resolution.
2082 valstr = mParameters.get(CameraParameters::KEY_VIDEO_STABILIZATION);
2083 if (valstr && (strcmp(valstr, CameraParameters::TRUE) == 0) && (mPreviewWidth == 1920)) {
2084 CAMHAL_LOGDA("Force Enable VNF for 1080p");
2085 mParameters.set(ExCameraParameters::KEY_VNF, "1");
2086 restartPreviewRequired = true;
2087 }
2088 }
2089 LOG_FUNCTION_NAME_EXIT;
2090
2091 return restartPreviewRequired;
2092}
2093
2094/**
2095 @brief Reset the camera parameters specific to Video Recording.
2096
2097 This function resets CAPTURE_MODE and disables Recording specific functions like VSTAB & VNF.
2098
2099 @param none
2100 @return true if preview needs to be restarted for VIDEO_MODE parameters to take effect.
2101
2102 */
2103bool VirtualCamHal::resetVideoModeParameters()
2104{
2105 const char *valstr = NULL;
2106 bool restartPreviewRequired = false;
2107 status_t ret = NO_ERROR;
2108
2109 LOG_FUNCTION_NAME;
2110
2111 // ignore this if we are already recording
2112 if (mRecordingEnabled) {
2113 return false;
2114 }
2115
2116 // Set CAPTURE_MODE to VIDEO_MODE, if not set already and Restart Preview
2117 valstr = mParameters.get(ExCameraParameters::KEY_CAP_MODE);
2118 if ((valstr != NULL) && (strcmp(valstr, ExCameraParameters::VIDEO_MODE) == 0)) {
2119 CAMHAL_LOGDA("Reset Capture-Mode to default");
2120 mParameters.set(ExCameraParameters::KEY_CAP_MODE, "");
2121 restartPreviewRequired = true;
2122 }
2123
2124 LOG_FUNCTION_NAME_EXIT;
2125
2126 return restartPreviewRequired;
2127}
2128
2129/**
2130 @brief Restart the preview with setParameter.
2131
2132 This function restarts preview, for some VIDEO_MODE parameters to take effect.
2133
2134 @param none
2135 @return NO_ERROR If recording parameters could be set without any issues
2136
2137 */
2138status_t VirtualCamHal::restartPreview()
2139{
2140 const char *valstr = NULL;
2141 char tmpvalstr[30];
2142 status_t ret = NO_ERROR;
2143
2144 LOG_FUNCTION_NAME;
2145
2146 // Retain CAPTURE_MODE before calling stopPreview(), since it is reset in stopPreview().
2147 tmpvalstr[0] = 0;
2148 valstr = mParameters.get(ExCameraParameters::KEY_CAP_MODE);
2149 if(valstr != NULL)
2150 {
2151 if(sizeof(tmpvalstr) < (strlen(valstr)+1))
2152 {
2153 return -EINVAL;
2154 }
2155
2156 strncpy(tmpvalstr, valstr, sizeof(tmpvalstr));
2157 tmpvalstr[sizeof(tmpvalstr)-1] = 0;
2158 }
2159
2160 forceStopPreview();
2161
2162 {
2163 Mutex::Autolock lock(mLock);
2164 mParameters.set(ExCameraParameters::KEY_CAP_MODE, tmpvalstr);
2165 mCameraAdapter->setParameters(mParameters);
2166 }
2167
2168 ret = startPreview();
2169
2170 LOG_FUNCTION_NAME_EXIT;
2171
2172 return ret;
2173}
2174
2175/**
2176 @brief Stop a previously started recording.
2177
2178 @param none
2179 @return none
2180
2181 */
2182void VirtualCamHal::stopRecording()
2183{
2184 CameraAdapter::AdapterState currentState;
2185
2186 LOG_FUNCTION_NAME;
2187
2188 Mutex::Autolock lock(mLock);
2189
2190 if (!mRecordingEnabled )
2191 {
2192 return;
2193 }
2194
2195 currentState = mCameraAdapter->getState();
2196 if (currentState == CameraAdapter::VIDEO_CAPTURE_STATE) {
2197 mCameraAdapter->sendCommand(CameraAdapter::CAMERA_STOP_IMAGE_CAPTURE);
2198 }
2199
2200 mAppCbNotifier->stopRecording();
2201
2202 mCameraAdapter->sendCommand(CameraAdapter::CAMERA_STOP_VIDEO);
2203
2204 mRecordingEnabled = false;
2205
2206 if ( mAppCbNotifier->getUseVideoBuffers() ){
2207 freeVideoBufs(mVideoBufs);
2208 if (mVideoBufs){
2209 CAMHAL_LOGVB(" FREEING mVideoBufs 0x%x", (uint32_t)mVideoBufs);
2210 delete [] mVideoBufs;
2211 }
2212 mVideoBufs = NULL;
2213 }
2214
2215 // reset internal recording hint in case camera adapter needs to make some
2216 // decisions....(will only be sent to camera adapter if camera restart is required)
2217 mParameters.remove(ExCameraParameters::KEY_RECORDING_HINT);
2218
2219 LOG_FUNCTION_NAME_EXIT;
2220}
2221
2222/**
2223 @brief Returns true if recording is enabled.
2224
2225 @param none
2226 @return true If recording is currently running
2227 false If recording has been stopped
2228
2229 */
2230int VirtualCamHal::recordingEnabled()
2231{
2232 LOG_FUNCTION_NAME;
2233
2234 LOG_FUNCTION_NAME_EXIT;
2235
2236 return mRecordingEnabled;
2237}
2238
2239/**
2240 @brief Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
2241
2242 @param[in] mem MemoryBase pointer to the frame being released. Must be one of the buffers
2243 previously given by VirtualCamHal
2244 @return none
2245
2246 */
2247void VirtualCamHal::releaseRecordingFrame(const void* mem)
2248{
2249 LOG_FUNCTION_NAME;
2250
2251 //CAMHAL_LOGDB(" 0x%x", mem->pointer());
2252
2253 if ( ( mRecordingEnabled ) && mem != NULL)
2254 {
2255 mAppCbNotifier->releaseRecordingFrame(mem);
2256 }
2257
2258 LOG_FUNCTION_NAME_EXIT;
2259
2260 return;
2261}
2262
2263/**
2264 @brief Start auto focus
2265
2266 This call asynchronous.
2267 The notification callback routine is called with CAMERA_MSG_FOCUS once when
2268 focusing is complete. autoFocus() will be called again if another auto focus is
2269 needed.
2270
2271 @param none
2272 @return NO_ERROR
2273 @todo Define the error codes if the focus is not locked
2274
2275 */
2276status_t VirtualCamHal::autoFocus()
2277{
2278 status_t ret = NO_ERROR;
2279
2280#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
2281
2282 gettimeofday(&mStartFocus, NULL);
2283
2284#endif
2285
2286
2287 LOG_FUNCTION_NAME;
2288
2289 {
2290 Mutex::Autolock lock(mLock);
2291 mMsgEnabled |= CAMERA_MSG_FOCUS;
2292 }
2293
2294
2295 if ( NULL != mCameraAdapter )
2296 {
2297
2298#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
2299
2300 //pass the autoFocus timestamp along with the command to camera adapter
2301 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_PERFORM_AUTOFOCUS, ( int ) &mStartFocus);
2302
2303#else
2304
2305 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_PERFORM_AUTOFOCUS);
2306
2307#endif
2308
2309 }
2310 else
2311 {
2312 ret = -1;
2313 }
2314
2315 LOG_FUNCTION_NAME_EXIT;
2316
2317 return ret;
2318}
2319
2320/**
2321 @brief Cancels auto-focus function.
2322
2323 If the auto-focus is still in progress, this function will cancel it.
2324 Whether the auto-focus is in progress or not, this function will return the
2325 focus position to the default. If the camera does not support auto-focus, this is a no-op.
2326
2327
2328 @param none
2329 @return NO_ERROR If the cancel succeeded
2330 @todo Define error codes if cancel didnt succeed
2331
2332 */
2333status_t VirtualCamHal::cancelAutoFocus()
2334{
2335 LOG_FUNCTION_NAME;
2336
2337 Mutex::Autolock lock(mLock);
2338 CameraParameters adapterParams = mParameters;
2339 mMsgEnabled &= ~CAMERA_MSG_FOCUS;
2340
2341 if( NULL != mCameraAdapter )
2342 {
2343 adapterParams.set(ExCameraParameters::KEY_AUTO_FOCUS_LOCK, CameraParameters::FALSE);
2344 mCameraAdapter->setParameters(adapterParams);
2345 mCameraAdapter->sendCommand(CameraAdapter::CAMERA_CANCEL_AUTOFOCUS);
2346 mAppCbNotifier->flushEventQueue();
2347 }
2348
2349 LOG_FUNCTION_NAME_EXIT;
2350 return NO_ERROR;
2351}
2352
2353void VirtualCamHal::setEventProvider(int32_t eventMask, MessageNotifier * eventNotifier)
2354{
2355
2356 LOG_FUNCTION_NAME;
2357
2358 if ( NULL != mEventProvider )
2359 {
2360 mEventProvider->disableEventNotification(CameraHalEvent::ALL_EVENTS);
2361 delete mEventProvider;
2362 mEventProvider = NULL;
2363 }
2364
2365 mEventProvider = new EventProvider(eventNotifier, this, eventCallbackRelay);
2366 if ( NULL == mEventProvider )
2367 {
2368 CAMHAL_LOGEA("Error in creating EventProvider");
2369 }
2370 else
2371 {
2372 mEventProvider->enableEventNotification(eventMask);
2373 }
2374
2375 LOG_FUNCTION_NAME_EXIT;
2376}
2377
2378void VirtualCamHal::eventCallbackRelay(CameraHalEvent* event)
2379{
2380 LOG_FUNCTION_NAME;
2381
2382 VirtualCamHal *appcbn = ( VirtualCamHal * ) (event->mCookie);
2383 appcbn->eventCallback(event );
2384
2385 LOG_FUNCTION_NAME_EXIT;
2386}
2387
2388void VirtualCamHal::eventCallback(CameraHalEvent* event)
2389{
2390 LOG_FUNCTION_NAME;
2391
2392 if ( NULL != event )
2393 {
2394 switch( event->mEventType )
2395 {
2396 case CameraHalEvent::EVENT_FOCUS_LOCKED:
2397 case CameraHalEvent::EVENT_FOCUS_ERROR:
2398 {
2399 if ( mBracketingEnabled )
2400 {
2401 startImageBracketing();
2402 }
2403 break;
2404 }
2405 default:
2406 {
2407 break;
2408 }
2409 };
2410 }
2411
2412 LOG_FUNCTION_NAME_EXIT;
2413}
2414
2415status_t VirtualCamHal::startImageBracketing()
2416{
2417 status_t ret = NO_ERROR;
2418 CameraFrame frame;
2419 CameraAdapter::BuffersDescriptor desc;
2420
2421#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
2422
2423 gettimeofday(&mStartCapture, NULL);
2424
2425#endif
2426
2427 LOG_FUNCTION_NAME;
2428
2429 if(!previewEnabled() && !mDisplayPaused)
2430 {
2431 LOG_FUNCTION_NAME_EXIT;
2432 return NO_INIT;
2433 }
2434
2435 if ( !mBracketingEnabled )
2436 {
2437 return ret;
2438 }
2439
2440 if ( NO_ERROR == ret )
2441 {
2442 mBracketingRunning = true;
2443 }
2444
2445 if ( (NO_ERROR == ret) && ( NULL != mCameraAdapter ) )
2446 {
2447 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE,
2448 ( int ) &frame,
2449 ( mBracketRangeNegative + 1 ));
2450
2451 if ( NO_ERROR != ret )
2452 {
2453 CAMHAL_LOGEB("CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE returned error 0x%x", ret);
2454 }
2455 }
2456
2457 if ( NO_ERROR == ret )
2458 {
2459 if ( NULL != mAppCbNotifier.get() )
2460 {
2461 mAppCbNotifier->setBurst(true);
2462 }
2463 }
2464
2465 if ( NO_ERROR == ret )
2466 {
2467 mParameters.getPictureSize(( int * ) &frame.mWidth,
2468 ( int * ) &frame.mHeight);
2469
2470 ret = allocImageBufs(frame.mWidth,
2471 frame.mHeight,
2472 frame.mLength,
2473 mParameters.getPictureFormat(),
2474 ( mBracketRangeNegative + 1 ));
2475 if ( NO_ERROR != ret )
2476 {
2477 CAMHAL_LOGEB("allocImageBufs returned error 0x%x", ret);
2478 }
2479 }
2480
2481 if ( (NO_ERROR == ret) && ( NULL != mCameraAdapter ) )
2482 {
2483
2484 desc.mBuffers = mImageBufs;
2485 desc.mOffsets = mImageOffsets;
2486 desc.mFd = mImageFd;
2487 desc.mLength = mImageLength;
2488 desc.mCount = ( size_t ) ( mBracketRangeNegative + 1 );
2489 desc.mMaxQueueable = ( size_t ) ( mBracketRangeNegative + 1 );
2490
2491 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_USE_BUFFERS_IMAGE_CAPTURE,
2492 ( int ) &desc);
2493
2494 if ( NO_ERROR == ret )
2495 {
2496
2497#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
2498
2499 //pass capture timestamp along with the camera adapter command
2500 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_BRACKET_CAPTURE, ( mBracketRangePositive + 1 ), (int) &mStartCapture);
2501
2502#else
2503
2504 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_BRACKET_CAPTURE, ( mBracketRangePositive + 1 ));
2505
2506#endif
2507
2508 }
2509 }
2510
2511 return ret;
2512}
2513
2514status_t VirtualCamHal::stopImageBracketing()
2515{
2516 status_t ret = NO_ERROR;
2517
2518 LOG_FUNCTION_NAME;
2519
2520 if( !previewEnabled() )
2521 {
2522 return NO_INIT;
2523 }
2524
2525 mBracketingRunning = false;
2526
2527 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_STOP_BRACKET_CAPTURE);
2528
2529 LOG_FUNCTION_NAME_EXIT;
2530
2531 return ret;
2532}
2533
2534/**
2535 @brief Take a picture.
2536
2537 @param none
2538 @return NO_ERROR If able to switch to image capture
2539 @todo Define error codes if unable to switch to image capture
2540
2541 */
2542status_t VirtualCamHal::takePicture( )
2543{
2544 status_t ret = NO_ERROR;
2545 CameraFrame frame;
2546 CameraAdapter::BuffersDescriptor desc;
2547 int burst;
2548 const char *valstr = NULL;
2549 unsigned int bufferCount = 1;
2550
2551 Mutex::Autolock lock(mLock);
2552
2553#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
2554
2555 gettimeofday(&mStartCapture, NULL);
2556
2557#endif
2558
2559 LOG_FUNCTION_NAME;
2560
2561 if(!previewEnabled() && !mDisplayPaused)
2562 {
2563 LOG_FUNCTION_NAME_EXIT;
2564 CAMHAL_LOGEA("Preview not started...");
2565 return NO_INIT;
2566 }
2567
2568 // return error if we are already capturing
2569 if((mCameraAdapter->getState() == CameraAdapter::CAPTURE_STATE &&
2570 mCameraAdapter->getNextState() != CameraAdapter::PREVIEW_STATE) ||
2571 (mCameraAdapter->getState() == CameraAdapter::VIDEO_CAPTURE_STATE &&
2572 mCameraAdapter->getNextState() != CameraAdapter::VIDEO_STATE) ) {
2573 CAMHAL_LOGEA("Already capturing an image...");
2574 return NO_INIT;
2575 }
2576
2577 // we only support video snapshot if we are in video mode (recording hint is set)
2578 valstr = mParameters.get(ExCameraParameters::KEY_CAP_MODE);
2579 if((mCameraAdapter->getState() == CameraAdapter::VIDEO_STATE) &&
2580 (valstr && strcmp(valstr, ExCameraParameters::VIDEO_MODE)) ) {
2581 CAMHAL_LOGEA("Trying to capture while recording without recording hint set...");
2582 return INVALID_OPERATION;
2583 }
2584
2585 if ( !mBracketingRunning )
2586 {
2587 if ( NO_ERROR == ret )
2588 {
2589 burst = mParameters.getInt(ExCameraParameters::KEY_BURST);
2590 }
2591
2592 //Allocate all buffers only in burst capture case
2593 if ( burst > 1 )
2594 {
2595 bufferCount = VirtualCamHal::NO_BUFFERS_IMAGE_CAPTURE;
2596 if ( NULL != mAppCbNotifier.get() )
2597 {
2598 mAppCbNotifier->setBurst(true);
2599 }
2600 }
2601 else
2602 {
2603 if ( NULL != mAppCbNotifier.get() )
2604 {
2605 mAppCbNotifier->setBurst(false);
2606 }
2607 }
2608
2609 // pause preview during normal image capture
2610 // do not pause preview if recording (video state)
2611 if (NO_ERROR == ret &&
2612 NULL != mDisplayAdapter.get() &&
2613 burst < 1) {
2614 if (mCameraAdapter->getState() != CameraAdapter::VIDEO_STATE) {
2615 mDisplayPaused = true;
2616 mPreviewEnabled = false;
2617 ret = mDisplayAdapter->pauseDisplay(mDisplayPaused);
2618 // since preview is paused we should stop sending preview frames too
2619 if(mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME) {
2620 mAppCbNotifier->disableMsgType (mMsgEnabled & CAMERA_MSG_POSTVIEW_FRAME);
2621 CAMHAL_LOGDA("disable MSG_PREVIEW_FRAME");
2622 }
2623 }
2624
2625#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
2626 CAMHAL_LOGDA("setSnapshotTimeRef!!\n");
2627 mDisplayAdapter->setSnapshotTimeRef(&mStartCapture);
2628#endif
2629 }
2630
2631 // if we taking video snapshot...
2632 if ((NO_ERROR == ret) && (mCameraAdapter->getState() == CameraAdapter::VIDEO_STATE)) {
2633 // enable post view frames if not already enabled so we can internally
2634 // save snapshot frames for generating thumbnail
2635 if((mMsgEnabled & CAMERA_MSG_POSTVIEW_FRAME) == 0) {
2636 mAppCbNotifier->enableMsgType(CAMERA_MSG_POSTVIEW_FRAME);
2637 }
2638 }
2639
2640 if ( (NO_ERROR == ret) && (NULL != mCameraAdapter) )
2641 {
2642 if ( NO_ERROR == ret )
2643 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE,
2644 ( int ) &frame,
2645 bufferCount);
2646
2647 if ( NO_ERROR != ret )
2648 {
2649 CAMHAL_LOGEB("CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE returned error 0x%x, count:%d", ret,bufferCount);
2650 }
2651 }
2652
2653 if ( NO_ERROR == ret )
2654 {
2655 mParameters.getPictureSize(( int * ) &frame.mWidth,
2656 ( int * ) &frame.mHeight);
2657
2658 ret = allocImageBufs(frame.mWidth,
2659 frame.mHeight,
2660 frame.mLength,
2661 mParameters.getPictureFormat(),
2662 bufferCount);
2663 if ( NO_ERROR != ret )
2664 {
2665 CAMHAL_LOGEB("allocImageBufs returned error 0x%x", ret);
2666 }
2667 }
2668
2669 if ( (NO_ERROR == ret) && ( NULL != mCameraAdapter ) )
2670 {
2671 desc.mBuffers = mImageBufs;
2672 desc.mOffsets = mImageOffsets;
2673 desc.mFd = mImageFd;
2674 desc.mLength = mImageLength;
2675 desc.mCount = ( size_t ) bufferCount;
2676 desc.mMaxQueueable = ( size_t ) bufferCount;
2677
2678 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_USE_BUFFERS_IMAGE_CAPTURE, ( int ) &desc);
2679 }
2680 }
2681
2682 if ( ( NO_ERROR == ret ) && ( NULL != mCameraAdapter ) )
2683 {
2684#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
2685 //pass capture timestamp along with the camera adapter command
2686 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_IMAGE_CAPTURE, (int) &mStartCapture);
2687#else
2688 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_IMAGE_CAPTURE);
2689#endif
2690 }
2691
2692 return ret;
2693}
2694
2695/**
2696 @brief Cancel a picture that was started with takePicture.
2697
2698 Calling this method when no picture is being taken is a no-op.
2699
2700 @param none
2701 @return NO_ERROR If cancel succeeded. Cancel can succeed if image callback is not sent
2702 @todo Define error codes
2703
2704 */
2705status_t VirtualCamHal::cancelPicture( )
2706{
2707 LOG_FUNCTION_NAME;
2708
2709 Mutex::Autolock lock(mLock);
2710
2711 mCameraAdapter->sendCommand(CameraAdapter::CAMERA_STOP_IMAGE_CAPTURE);
2712
2713 return NO_ERROR;
2714}
2715
2716/**
2717 @brief Return the camera parameters.
2718
2719 @param none
2720 @return Currently configured camera parameters
2721
2722 */
2723char* VirtualCamHal::getParameters()
2724{
2725 String8 params_str8;
2726 char* params_string;
2727 const char * valstr = NULL;
2728
2729 LOG_FUNCTION_NAME;
2730
2731LOGD("getParameters, 1 mParameters KEY_PICTURE_SIZE=%s", mParameters.get(CameraParameters::KEY_PICTURE_SIZE));
2732 if( NULL != mCameraAdapter )
2733 {
2734 mCameraAdapter->getParameters(mParameters);
2735 }
2736LOGD("getParameters, 2 mParameters KEY_PICTURE_SIZE=%s", mParameters.get(CameraParameters::KEY_PICTURE_SIZE));
2737
2738 CameraParameters mParams = mParameters;
2739
2740 // Handle RECORDING_HINT to Set/Reset Video Mode Parameters
2741 valstr = mParameters.get(CameraParameters::KEY_RECORDING_HINT);
2742 if(valstr != NULL)
2743 {
2744 if(strcmp(valstr, CameraParameters::TRUE) == 0)
2745 {
2746 //HACK FOR MMS MODE
2747 resetPreviewRes(&mParams, mVideoWidth, mVideoHeight);
2748 }
2749 }
2750
2751 // do not send internal parameters to upper layers
2752 mParams.remove(ExCameraParameters::KEY_RECORDING_HINT);
2753 mParams.remove(ExCameraParameters::KEY_AUTO_FOCUS_LOCK);
2754 mParameters.remove(CameraProperties::RELOAD_WHEN_OPEN);
2755#ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT
2756 mParams.remove(CameraProperties::DEVICE_NAME);
2757#endif
2758
2759 params_str8 = mParams.flatten();
2760
2761 // camera service frees this string...
2762 params_string = (char*) malloc(sizeof(char) * (params_str8.length()+1));
2763 strcpy(params_string, params_str8.string());
2764
2765 LOG_FUNCTION_NAME_EXIT;
2766
2767 ///Return the current set of parameters
2768
2769 return params_string;
2770}
2771
2772void VirtualCamHal::putParameters(char *parms)
2773{
2774 free(parms);
2775}
2776
2777/**
2778 @brief Send command to camera driver.
2779
2780 @param none
2781 @return NO_ERROR If the command succeeds
2782 @todo Define the error codes that this function can return
2783
2784 */
2785status_t VirtualCamHal::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
2786{
2787 status_t ret = NO_ERROR;
2788
2789 LOG_FUNCTION_NAME;
2790
2791
2792 if ( ( NO_ERROR == ret ) && ( NULL == mCameraAdapter ) )
2793 {
2794 CAMHAL_LOGEA("No CameraAdapter instance");
2795 ret = -EINVAL;
2796 }
2797
2798 if ( ( NO_ERROR == ret ) && ( !previewEnabled() ))
2799 {
2800 if( cmd == CAMERA_CMD_SET_DISPLAY_ORIENTATION) {
2801 if(arg2 == 1) {//disable mirror
2802 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_DISABLE_MIRROR, 1);
2803 }
2804 }
2805 if( CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG != cmd){
2806 CAMHAL_LOGEA("Preview is not running");
2807 ret = -EINVAL;
2808 }
2809 }
2810
2811 if ( NO_ERROR == ret )
2812 {
2813 switch(cmd)
2814 {
2815 case CAMERA_CMD_SET_DISPLAY_ORIENTATION:
2816
2817 if(arg2 == 1) {//disable mirror
2818 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_DISABLE_MIRROR, 1);
2819 }
2820
2821 break;
2822 case CAMERA_CMD_START_SMOOTH_ZOOM:
2823
2824 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_SMOOTH_ZOOM, arg1);
2825
2826 break;
2827 case CAMERA_CMD_STOP_SMOOTH_ZOOM:
2828
2829 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_STOP_SMOOTH_ZOOM);
2830
2831 case CAMERA_CMD_START_FACE_DETECTION:
2832
2833 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_FD);
2834
2835 break;
2836
2837 case CAMERA_CMD_STOP_FACE_DETECTION:
2838
2839 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_STOP_FD);
2840
2841 break;
2842
2843 case CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG:
2844
2845 mMsgEnabled |= CAMERA_MSG_FOCUS_MOVE;
2846
2847 ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_FOCUS_MOVE_MSG);
2848
2849 break;
2850
2851 default:
2852 break;
2853 };
2854 }
2855
2856 LOG_FUNCTION_NAME_EXIT;
2857
2858 return ret;
2859}
2860
2861/**
2862 @brief Release the hardware resources owned by this object.
2863
2864 Note that this is *not* done in the destructor.
2865
2866 @param none
2867 @return none
2868
2869 */
2870void VirtualCamHal::release()
2871{
2872 LOG_FUNCTION_NAME;
2873 ///@todo Investigate on how release is used by CameraService. Vaguely remember that this is called
2874 ///just before VirtualCamHal object destruction
2875 deinitialize();
2876
2877 SYS_enable_nextvideo();
2878
2879 LOG_FUNCTION_NAME_EXIT;
2880}
2881
2882
2883/**
2884 @brief Dump state of the camera hardware
2885
2886 @param[in] fd File descriptor
2887 @param[in] args Arguments
2888 @return NO_ERROR Dump succeeded
2889 @todo Error codes for dump fail
2890
2891 */
2892status_t VirtualCamHal::dump(int fd) const
2893{
2894 LOG_FUNCTION_NAME;
2895 ///Implement this method when the h/w dump function is supported on Ducati side
2896 return NO_ERROR;
2897}
2898
2899/*-------------Camera Hal Interface Method definitions ENDS here--------------------*/
2900
2901
2902
2903
2904/*-------------Camera Hal Internal Method definitions STARTS here--------------------*/
2905
2906/**
2907 @brief Constructor of VirtualCamHal
2908
2909 Member variables are initialized here. No allocations should be done here as we
2910 don't use c++ exceptions in the code.
2911
2912 */
2913VirtualCamHal::VirtualCamHal(int cameraId)
2914{
2915 LOG_FUNCTION_NAME;
2916
2917 ///Initialize all the member variables to their defaults
2918 mPreviewEnabled = false;
2919 mPreviewBufs = NULL;
2920 mImageBufs = NULL;
2921 mBufProvider = NULL;
2922 mPreviewStartInProgress = false;
2923 mVideoBufs = NULL;
2924 mVideoBufProvider = NULL;
2925 mRecordingEnabled = false;
2926 mDisplayPaused = false;
2927 mSetPreviewWindowCalled = false;
2928 mMsgEnabled = 0;
2929 mAppCbNotifier = NULL;
2930 mMemoryManager = NULL;
2931 mCameraAdapter = NULL;
2932 mBracketingEnabled = false;
2933 mBracketingRunning = false;
2934 mEventProvider = NULL;
2935 mBracketRangePositive = 1;
2936 mBracketRangeNegative = 1;
2937 mMaxZoomSupported = 0;
2938 mShutterEnabled = true;
2939 mMeasurementEnabled = false;
2940 mPreviewDataBufs = NULL;
2941 mCameraProperties = NULL;
2942 mCurrentTime = 0;
2943 mFalsePreview = 0;
2944 mImageOffsets = NULL;
2945 mImageLength = 0;
2946 mImageFd = -1;
2947 mVideoOffsets = NULL;
2948 mVideoFd = -1;
2949 mVideoLength = 0;
2950 mPreviewDataOffsets = NULL;
2951 mPreviewDataFd = -1;
2952 mPreviewDataLength = 0;
2953 mPreviewFd = -1;
2954 mPreviewWidth = 0;
2955 mPreviewHeight = 0;
2956 mPreviewLength = 0;
2957 mPreviewOffsets = NULL;
2958 mPreviewRunning = 0;
2959 mPreviewStateOld = 0;
2960 mRecordingEnabled = 0;
2961 mRecordEnabled = 0;
2962#ifdef ENABLE_SENSOR_LISTENER
2963 mSensorListener = NULL;
2964#endif
2965 mVideoWidth = 0;
2966 mVideoHeight = 0;
2967
2968#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
2969
2970 //Initialize the CameraHAL constructor timestamp, which is used in the
2971 // PPM() method as time reference if the user does not supply one.
2972 gettimeofday(&ppm_start, NULL);
2973
2974#endif
2975
2976 mCameraIndex = cameraId;
2977
2978 SYS_disable_avsync();
2979 SYS_disable_video_pause();
2980#ifdef AMLOGIC_CAMERA_OVERLAY_SUPPORT
2981 SYS_enable_nextvideo();
2982#else
2983 SYS_close_video();
2984#endif
2985
2986 LOG_FUNCTION_NAME_EXIT;
2987}
2988
2989/**
2990 @brief Destructor of VirtualCamHal
2991
2992 This function simply calls deinitialize() to free up memory allocate during construct
2993 phase
2994 */
2995VirtualCamHal::~VirtualCamHal()
2996{
2997 LOG_FUNCTION_NAME;
2998
2999 ///Call de-initialize here once more - it is the last chance for us to relinquish all the h/w and s/w resources
3000 deinitialize();
3001
3002 if ( NULL != mEventProvider )
3003 {
3004 mEventProvider->disableEventNotification(CameraHalEvent::ALL_EVENTS);
3005 delete mEventProvider;
3006 mEventProvider = NULL;
3007 }
3008
3009 /// Free the callback notifier
3010 mAppCbNotifier.clear();
3011
3012 /// Free the display adapter
3013 mDisplayAdapter.clear();
3014
3015 if ( NULL != mCameraAdapter ) {
3016 int strongCount = mCameraAdapter->getStrongCount();
3017
3018 mCameraAdapter->decStrong(mCameraAdapter);
3019
3020 mCameraAdapter = NULL;
3021 }
3022
3023 freeImageBufs();
3024
3025 /// Free the memory manager
3026 mMemoryManager.clear();
3027
3028 SYS_enable_nextvideo();
3029
3030 LOG_FUNCTION_NAME_EXIT;
3031}
3032
3033/**
3034 @brief Initialize the Camera HAL
3035
3036 Creates CameraAdapter, AppCallbackNotifier, DisplayAdapter and MemoryManager
3037
3038 @param None
3039 @return NO_ERROR - On success
3040 NO_MEMORY - On failure to allocate memory for any of the objects
3041 @remarks Camera Hal internal function
3042
3043 */
3044
3045status_t VirtualCamHal::initialize(CameraProperties::Properties* properties)
3046{
3047 LOG_FUNCTION_NAME;
3048
3049 int sensor_index = 0;
3050
3051 ///Initialize the event mask used for registering an event provider for AppCallbackNotifier
3052 ///Currently, registering all events as to be coming from CameraAdapter
3053 int32_t eventMask = CameraHalEvent::ALL_EVENTS;
3054
3055 // Get my camera properties
3056 mCameraProperties = properties;
3057
3058 if(!mCameraProperties)
3059 {
3060 goto fail_loop;
3061 }
3062
3063 // Dump the properties of this Camera
3064 // will only print if DEBUG macro is defined
3065 mCameraProperties->dump();
3066
3067 if (strcmp(CameraProperties::DEFAULT_VALUE, mCameraProperties->get(CameraProperties::CAMERA_SENSOR_INDEX)) != 0 )
3068 {
3069 sensor_index = atoi(mCameraProperties->get(CameraProperties::CAMERA_SENSOR_INDEX));
3070 }
3071
3072 CAMHAL_LOGDB("Sensor index %d", sensor_index);
3073
3074 mCameraAdapter = CameraAdapter_Factory(sensor_index);
3075 if ( ( NULL == mCameraAdapter ) || (mCameraAdapter->initialize(properties)!=NO_ERROR))
3076 {
3077 CAMHAL_LOGEA("Unable to create or initialize CameraAdapter");
3078 mCameraAdapter = NULL;
3079 goto fail_loop;
3080 }
3081
3082 mCameraAdapter->incStrong(mCameraAdapter);
3083 mCameraAdapter->registerImageReleaseCallback(releaseImageBuffers, (void *) this);
3084 mCameraAdapter->registerEndCaptureCallback(endImageCapture, (void *)this);
3085
3086 if(!mAppCbNotifier.get())
3087 {
3088 /// Create the callback notifier
3089 mAppCbNotifier = new AppCbNotifier();
3090 if( ( NULL == mAppCbNotifier.get() ) || ( mAppCbNotifier->initialize() != NO_ERROR))
3091 {
3092 CAMHAL_LOGEA("Unable to create or initialize AppCbNotifier");
3093 goto fail_loop;
3094 }
3095 }
3096
3097 if(!mMemoryManager.get())
3098 {
3099 /// Create Memory Manager
3100 mMemoryManager = new MemoryManager();
3101 if( ( NULL == mMemoryManager.get() ) || ( mMemoryManager->initialize() != NO_ERROR))
3102 {
3103 CAMHAL_LOGEA("Unable to create or initialize MemoryManager");
3104 goto fail_loop;
3105 }
3106 }
3107
3108 ///Setup the class dependencies...
3109
3110 ///AppCallbackNotifier has to know where to get the Camera frames and the events like auto focus lock etc from.
3111 ///CameraAdapter is the one which provides those events
3112 ///Set it as the frame and event providers for AppCallbackNotifier
3113 ///@remarks setEventProvider API takes in a bit mask of events for registering a provider for the different events
3114 /// That way, if events can come from DisplayAdapter in future, we will be able to add it as provider
3115 /// for any event
3116 mAppCbNotifier->setEventProvider(eventMask, mCameraAdapter);
3117 mAppCbNotifier->setFrameProvider(mCameraAdapter);
3118
3119 ///Any dynamic errors that happen during the camera use case has to be propagated back to the application
3120 ///via CAMERA_MSG_ERROR. AppCallbackNotifier is the class that notifies such errors to the application
3121 ///Set it as the error handler for CameraAdapter
3122 mCameraAdapter->setErrorHandler(mAppCbNotifier.get());
3123
3124 ///Start the callback notifier
3125 if(mAppCbNotifier->start() != NO_ERROR)
3126 {
3127 CAMHAL_LOGEA("Couldn't start AppCallbackNotifier");
3128 goto fail_loop;
3129 }
3130
3131 CAMHAL_LOGDA("Started AppCallbackNotifier..");
3132 mAppCbNotifier->setMeasurements(mMeasurementEnabled);
3133
3134 ///Initialize default parameters
3135 initDefaultParameters();
3136
3137 if ( setParameters(mParameters) != NO_ERROR )
3138 {
3139 CAMHAL_LOGEA("Failed to set default parameters?!");
3140 }
3141
3142#ifdef ENABLE_SENSOR_LISTENER
3143 // register for sensor events
3144 mSensorListener = new SensorListener();
3145 if (mSensorListener.get()) {
3146 if (mSensorListener->initialize() == NO_ERROR) {
3147 mSensorListener->setCallbacks(orientation_cb, this);
3148 mSensorListener->enableSensor(SensorListener::SENSOR_ORIENTATION);
3149 } else {
3150 CAMHAL_LOGEA("Error initializing SensorListener. not fatal, continuing");
3151 mSensorListener.clear();
3152 mSensorListener = NULL;
3153 }
3154 }
3155#endif
3156
3157 LOG_FUNCTION_NAME_EXIT;
3158 return NO_ERROR;
3159
3160fail_loop:
3161
3162 ///Free up the resources because we failed somewhere up
3163 deinitialize();
3164 LOG_FUNCTION_NAME_EXIT;
3165
3166 return NO_MEMORY;
3167
3168}
3169
3170#if 1//ndef AMLOGIC_USB_CAMERA_SUPPORT
3171//By vm or mipi driver, the resolution only need be smaller the max preview size. (1920*1080)
3172bool VirtualCamHal::isResolutionValid(unsigned int width, unsigned int height, const char *supportedResolutions)
3173{
3174 bool ret = false;
3175 status_t status = NO_ERROR;
3176 char *pos = NULL;
3177 unsigned int supported_w = 0, supported_h = 0;
3178 LOG_FUNCTION_NAME;
3179
3180 if ( NULL == supportedResolutions )
3181 {
3182 CAMHAL_LOGEA("Invalid supported resolutions string");
3183 ret = false;
3184 goto exit;
3185 }
3186 pos = (char *)supportedResolutions;
3187 while(pos != NULL){
3188 if (sscanf(pos, "%dx%d", &supported_w, &supported_h) != 2){
3189 CAMHAL_LOGEB("Read supported resolutions string error!(%s)",pos);
3190 ret = false;
3191 break;
3192 }
3193 //CAMHAL_LOGVB("Read supported resolutions %dx%d",supported_w,supported_h);
3194 if((width<=supported_w)&&(height<=supported_h)){
3195 ret = true;
3196 break;
3197 }
3198 pos = strchr(pos, ',');
3199 if(pos)
3200 pos++;
3201 }
3202
3203exit:
3204
3205 LOG_FUNCTION_NAME_EXIT;
3206 return ret;
3207}
3208#else
3209bool VirtualCamHal::isResolutionValid(unsigned int width, unsigned int height, const char *supportedResolutions)
3210{
3211 bool ret = true;
3212 status_t status = NO_ERROR;
3213 char tmpBuffer[PARAM_BUFFER + 1];
3214 char *pos = NULL;
3215
3216 LOG_FUNCTION_NAME;
3217
3218 if ( NULL == supportedResolutions )
3219 {
3220 CAMHAL_LOGEA("Invalid supported resolutions string");
3221 ret = false;
3222 goto exit;
3223 }
3224
3225 status = snprintf(tmpBuffer, PARAM_BUFFER, "%dx%d", width, height);
3226 if ( 0 > status )
3227 {
3228 CAMHAL_LOGEA("Error encountered while generating validation string");
3229 ret = false;
3230 goto exit;
3231 }
3232
3233 pos = strstr(supportedResolutions, tmpBuffer);
3234 if ( NULL == pos )
3235 {
3236 ret = false;
3237 }
3238 else
3239 {
3240 ret = true;
3241 }
3242
3243exit:
3244
3245 LOG_FUNCTION_NAME_EXIT;
3246
3247 return ret;
3248}
3249#endif
3250
3251bool VirtualCamHal::isParameterValid(const char *param, const char *supportedParams)
3252{
3253 bool ret = true;
3254 char *pos = NULL;
3255
3256 LOG_FUNCTION_NAME;
3257
3258 if ( NULL == supportedParams )
3259 {
3260 CAMHAL_LOGEA("Invalid supported parameters string");
3261 ret = false;
3262 goto exit;
3263 }
3264
3265 if ( NULL == param )
3266 {
3267 CAMHAL_LOGEA("Invalid parameter string");
3268 ret = false;
3269 goto exit;
3270 }
3271
3272 pos = strstr(supportedParams, param);
3273 if ( NULL == pos )
3274 {
3275 ret = false;
3276 }
3277 else
3278 {
3279 ret = true;
3280 }
3281
3282exit:
3283
3284 LOG_FUNCTION_NAME_EXIT;
3285
3286 return ret;
3287}
3288
3289bool VirtualCamHal::isParameterValid(int param, const char *supportedParams)
3290{
3291 bool ret = true;
3292 char *pos = NULL;
3293 status_t status;
3294 char tmpBuffer[PARAM_BUFFER + 1];
3295
3296 LOG_FUNCTION_NAME;
3297
3298 if ( NULL == supportedParams )
3299 {
3300 CAMHAL_LOGEA("Invalid supported parameters string");
3301 ret = false;
3302 goto exit;
3303 }
3304
3305 status = snprintf(tmpBuffer, PARAM_BUFFER, "%d", param);
3306 if ( 0 > status )
3307 {
3308 CAMHAL_LOGEA("Error encountered while generating validation string");
3309 ret = false;
3310 goto exit;
3311 }
3312
3313 pos = strstr(supportedParams, tmpBuffer);
3314 if ( NULL == pos )
3315 {
3316 ret = false;
3317 }
3318 else
3319 {
3320 ret = true;
3321 }
3322
3323exit:
3324
3325 LOG_FUNCTION_NAME_EXIT;
3326
3327 return ret;
3328}
3329
3330bool VirtualCamHal::isParameterInRange(int param, const char *supportedParams)
3331{
3332 bool ret = true;
3333 char *pos = NULL;
3334 status_t status;
3335 int min_range = 0, max_range = 0;
3336
3337 LOG_FUNCTION_NAME;
3338
3339 if ( NULL == supportedParams )
3340 {
3341 CAMHAL_LOGEA("Invalid supported parameters string");
3342 ret = false;
3343 goto exit;
3344 }
3345 if (sscanf(supportedParams, "%d,%d", &min_range, &max_range) != 2){
3346 CAMHAL_LOGEA("Error encountered while get Parameter Range");
3347 ret = false;
3348 goto exit;
3349 }
3350 if(min_range==max_range){
3351 CAMHAL_LOGEA("Parameter Range Invalid");
3352 ret = false;
3353 goto exit;
3354 }
3355
3356 if(min_range>max_range){
3357 int temp = max_range;
3358 max_range = min_range;
3359 min_range = temp;
3360 }
3361
3362 if((min_range<=param)&&(param<=max_range))
3363 ret = true;
3364 else
3365 ret = false;
3366exit:
3367
3368 LOG_FUNCTION_NAME_EXIT;
3369
3370 return ret;
3371}
3372
3373status_t VirtualCamHal::doesSetParameterNeedUpdate(const char* new_param, const char* old_param, bool& update)
3374{
3375 if (!new_param || !old_param) {
3376 return -EINVAL;
3377 }
3378
3379 // if params mismatch we should update parameters for camera adapter
3380 if ((strcmp(new_param, old_param) != 0)) {
3381 update = true;
3382 }
3383
3384 return NO_ERROR;
3385}
3386
3387status_t VirtualCamHal::parseResolution(const char *resStr, int &width, int &height)
3388{
3389 status_t ret = NO_ERROR;
3390 char *ctx, *pWidth, *pHeight;
3391 const char *sep = "x";
3392 char *tmp = NULL;
3393
3394 LOG_FUNCTION_NAME;
3395
3396 if ( NULL == resStr )
3397 {
3398 return -EINVAL;
3399 }
3400
3401 //This fixes "Invalid input resolution"
3402 char *resStr_copy = (char *)malloc(strlen(resStr) + 1);
3403 if ( NULL!=resStr_copy ) {
3404 if ( NO_ERROR == ret )
3405 {
3406 strcpy(resStr_copy, resStr);
3407 pWidth = strtok_r( (char *) resStr_copy, sep, &ctx);
3408
3409 if ( NULL != pWidth )
3410 {
3411 width = atoi(pWidth);
3412 }
3413 else
3414 {
3415 CAMHAL_LOGEB("Invalid input resolution %s", resStr);
3416 ret = -EINVAL;
3417 }
3418 }
3419
3420 if ( NO_ERROR == ret )
3421 {
3422 pHeight = strtok_r(NULL, sep, &ctx);
3423
3424 if ( NULL != pHeight )
3425 {
3426 height = atoi(pHeight);
3427 }
3428 else
3429 {
3430 CAMHAL_LOGEB("Invalid input resolution %s", resStr);
3431 ret = -EINVAL;
3432 }
3433 }
3434
3435 free(resStr_copy);
3436 resStr_copy = NULL;
3437 }
3438 LOG_FUNCTION_NAME_EXIT;
3439
3440 return ret;
3441}
3442
3443void VirtualCamHal::insertSupportedParams()
3444{
3445 char tmpBuffer[PARAM_BUFFER + 1];
3446
3447 LOG_FUNCTION_NAME;
3448
3449 CameraParameters &p = mParameters;
3450
3451 ///Set the name of the camera
3452 p.set(ExCameraParameters::KEY_CAMERA_NAME, mCameraProperties->get(CameraProperties::CAMERA_NAME));
3453
3454 mMaxZoomSupported = atoi(mCameraProperties->get(CameraProperties::SUPPORTED_ZOOM_STAGES));
3455
3456 p.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, mCameraProperties->get(CameraProperties::SUPPORTED_PICTURE_SIZES));
3457 p.set(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS, mCameraProperties->get(CameraProperties::SUPPORTED_PICTURE_FORMATS));
3458 p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_SIZES));
3459 p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS, mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_FORMATS));
3460 p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_FRAME_RATES));
3461 p.set(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, mCameraProperties->get(CameraProperties::SUPPORTED_THUMBNAIL_SIZES));
3462 p.set(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE, mCameraProperties->get(CameraProperties::SUPPORTED_WHITE_BALANCE));
3463 p.set(CameraParameters::KEY_SUPPORTED_EFFECTS, mCameraProperties->get(CameraProperties::SUPPORTED_EFFECTS));
3464 p.set(CameraParameters::KEY_SUPPORTED_SCENE_MODES, mCameraProperties->get(CameraProperties::SUPPORTED_SCENE_MODES));
3465
3466 const char *flashmode = mCameraProperties->get(CameraProperties::SUPPORTED_FLASH_MODES);
3467 if(flashmode&&(flashmode[0]!=0)){
3468 p.set(CameraParameters::KEY_SUPPORTED_FLASH_MODES, flashmode);
3469 }
3470
3471 p.set(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, mCameraProperties->get(CameraProperties::SUPPORTED_FOCUS_MODES));
3472 p.set(CameraParameters::KEY_SUPPORTED_ANTIBANDING, mCameraProperties->get(CameraProperties::SUPPORTED_ANTIBANDING));
3473 p.set(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION, mCameraProperties->get(CameraProperties::SUPPORTED_EV_MAX));
3474 p.set(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION, mCameraProperties->get(CameraProperties::SUPPORTED_EV_MIN));
3475 p.set(CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP, mCameraProperties->get(CameraProperties::SUPPORTED_EV_STEP));
3476 p.set(CameraParameters::KEY_SUPPORTED_SCENE_MODES, mCameraProperties->get(CameraProperties::SUPPORTED_SCENE_MODES));
3477 p.set(ExCameraParameters::KEY_SUPPORTED_EXPOSURE, mCameraProperties->get(CameraProperties::SUPPORTED_EXPOSURE_MODES));
3478 p.set(ExCameraParameters::KEY_SUPPORTED_ISO_VALUES, mCameraProperties->get(CameraProperties::SUPPORTED_ISO_VALUES));
3479 p.set(CameraParameters::KEY_ZOOM_RATIOS, mCameraProperties->get(CameraProperties::SUPPORTED_ZOOM_RATIOS));
3480 p.set(CameraParameters::KEY_MAX_ZOOM, mCameraProperties->get(CameraProperties::SUPPORTED_ZOOM_STAGES));
3481 p.set(CameraParameters::KEY_ZOOM_SUPPORTED, mCameraProperties->get(CameraProperties::ZOOM_SUPPORTED));
3482 p.set(CameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED, mCameraProperties->get(CameraProperties::SMOOTH_ZOOM_SUPPORTED));
3483 p.set(ExCameraParameters::KEY_SUPPORTED_IPP, mCameraProperties->get(CameraProperties::SUPPORTED_IPP_MODES));
3484 p.set(ExCameraParameters::KEY_S3D_SUPPORTED,mCameraProperties->get(CameraProperties::S3D_SUPPORTED));
3485 p.set(ExCameraParameters::KEY_S3D2D_PREVIEW_MODE,mCameraProperties->get(CameraProperties::S3D2D_PREVIEW_MODES));
3486 p.set(ExCameraParameters::KEY_AUTOCONVERGENCE_MODE, mCameraProperties->get(CameraProperties::AUTOCONVERGENCE_MODE));
3487 p.set(ExCameraParameters::KEY_MANUALCONVERGENCE_VALUES, mCameraProperties->get(CameraProperties::MANUALCONVERGENCE_VALUES));
3488 p.set(CameraParameters::KEY_VIDEO_STABILIZATION_SUPPORTED, mCameraProperties->get(CameraProperties::VSTAB_SUPPORTED));
3489 p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, mCameraProperties->get(CameraProperties::FRAMERATE_RANGE_SUPPORTED));
3490 p.set(ExCameraParameters::KEY_SENSOR_ORIENTATION, mCameraProperties->get(CameraProperties::SENSOR_ORIENTATION));
3491 p.set(ExCameraParameters::KEY_SENSOR_ORIENTATION_VALUES, mCameraProperties->get(CameraProperties::SENSOR_ORIENTATION_VALUES));
3492 p.set(CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED, mCameraProperties->get(CameraProperties::AUTO_EXPOSURE_LOCK_SUPPORTED));
3493 p.set(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED, mCameraProperties->get(CameraProperties::AUTO_WHITEBALANCE_LOCK_SUPPORTED));
3494 p.set(CameraParameters::KEY_VIDEO_SNAPSHOT_SUPPORTED, mCameraProperties->get(CameraProperties::VIDEO_SNAPSHOT_SUPPORTED));
3495
3496 //p.set(CameraParameters::KEY_SUPPORTED_VIDEO_SIZES, mCameraProperties->get(CameraProperties::SUPPORTED_PREVIEW_SIZES));
3497
3498 p.set(CameraParameters::KEY_FOCUS_DISTANCES,"0.95,1.9,Infinity");
3499
3500 LOG_FUNCTION_NAME_EXIT;
3501
3502}
3503
3504void VirtualCamHal::initDefaultParameters()
3505{
3506 //Purpose of this function is to initialize the default current and supported parameters for the currently
3507 //selected camera.
3508
3509 CameraParameters &p = mParameters;
3510 int currentRevision, adapterRevision;
3511 status_t ret = NO_ERROR;
3512 int width, height;
3513
3514 LOG_FUNCTION_NAME;
3515
3516 ret = parseResolution(mCameraProperties->get(CameraProperties::PREVIEW_SIZE), width, height);
3517
3518 if ( NO_ERROR == ret )
3519 {
3520 p.setPreviewSize(width, height);
3521 }
3522 else
3523 {
3524 p.setPreviewSize(MIN_WIDTH, MIN_HEIGHT);
3525 }
3526
3527 ret = parseResolution(mCameraProperties->get(CameraProperties::PICTURE_SIZE), width, height);
3528
3529 if ( NO_ERROR == ret )
3530 {
3531 p.setPictureSize(width, height);
3532 }
3533 else
3534 {
3535 p.setPictureSize(PICTURE_WIDTH, PICTURE_HEIGHT);
3536 }
3537
3538 ret = parseResolution(mCameraProperties->get(CameraProperties::JPEG_THUMBNAIL_SIZE), width, height);
3539
3540 if ( NO_ERROR == ret )
3541 {
3542 p.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, width);
3543 p.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, height);
3544 }
3545 else
3546 {
3547 p.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, MIN_WIDTH);
3548 p.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, MIN_HEIGHT);
3549 }
3550
3551 insertSupportedParams();
3552
3553 //Insert default values
3554 p.setPreviewFrameRate(atoi(mCameraProperties->get(CameraProperties::PREVIEW_FRAME_RATE)));
3555 p.setPreviewFormat(mCameraProperties->get(CameraProperties::PREVIEW_FORMAT));
3556 p.setPictureFormat(mCameraProperties->get(CameraProperties::PICTURE_FORMAT));
3557 p.set(CameraParameters::KEY_JPEG_QUALITY, mCameraProperties->get(CameraProperties::JPEG_QUALITY));
3558 p.set(CameraParameters::KEY_WHITE_BALANCE, mCameraProperties->get(CameraProperties::WHITEBALANCE));
3559 p.set(CameraParameters::KEY_EFFECT, mCameraProperties->get(CameraProperties::EFFECT));
3560 p.set(CameraParameters::KEY_ANTIBANDING, mCameraProperties->get(CameraProperties::ANTIBANDING));
3561 p.set(CameraParameters::KEY_FOCUS_MODE, mCameraProperties->get(CameraProperties::FOCUS_MODE));
3562 p.set(CameraParameters::KEY_EXPOSURE_COMPENSATION, mCameraProperties->get(CameraProperties::EV_COMPENSATION));
3563 p.set(CameraParameters::KEY_SCENE_MODE, mCameraProperties->get(CameraProperties::SCENE_MODE));
3564
3565 const char *flashmode = mCameraProperties->get(CameraProperties::FLASH_MODE);
3566 if(flashmode&&(flashmode[0]!=0)){
3567 p.set(CameraParameters::KEY_FLASH_MODE, flashmode);
3568 }
3569
3570 p.set(CameraParameters::KEY_ZOOM, mCameraProperties->get(CameraProperties::ZOOM));
3571 p.set(ExCameraParameters::KEY_CONTRAST, mCameraProperties->get(CameraProperties::CONTRAST));
3572 p.set(ExCameraParameters::KEY_SATURATION, mCameraProperties->get(CameraProperties::SATURATION));
3573 p.set(ExCameraParameters::KEY_BRIGHTNESS, mCameraProperties->get(CameraProperties::BRIGHTNESS));
3574 p.set(ExCameraParameters::KEY_SHARPNESS, mCameraProperties->get(CameraProperties::SHARPNESS));
3575 p.set(ExCameraParameters::KEY_EXPOSURE_MODE, mCameraProperties->get(CameraProperties::EXPOSURE_MODE));
3576 p.set(ExCameraParameters::KEY_ISO, mCameraProperties->get(CameraProperties::ISO_MODE));
3577 p.set(ExCameraParameters::KEY_IPP, mCameraProperties->get(CameraProperties::IPP));
3578 p.set(ExCameraParameters::KEY_GBCE, mCameraProperties->get(CameraProperties::GBCE));
3579 p.set(ExCameraParameters::KEY_S3D2D_PREVIEW, mCameraProperties->get(CameraProperties::S3D2D_PREVIEW));
3580 p.set(ExCameraParameters::KEY_AUTOCONVERGENCE, mCameraProperties->get(CameraProperties::AUTOCONVERGENCE));
3581 p.set(ExCameraParameters::KEY_MANUALCONVERGENCE_VALUES, mCameraProperties->get(CameraProperties::MANUALCONVERGENCE_VALUES));
3582 p.set(CameraParameters::KEY_VIDEO_STABILIZATION, mCameraProperties->get(CameraProperties::VSTAB));
3583 p.set(CameraParameters::KEY_FOCAL_LENGTH, mCameraProperties->get(CameraProperties::FOCAL_LENGTH));
3584 p.set(CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, mCameraProperties->get(CameraProperties::HOR_ANGLE));
3585 p.set(CameraParameters::KEY_VERTICAL_VIEW_ANGLE, mCameraProperties->get(CameraProperties::VER_ANGLE));
3586 p.set(CameraParameters::KEY_PREVIEW_FPS_RANGE,mCameraProperties->get(CameraProperties::FRAMERATE_RANGE));
3587 p.set(ExCameraParameters::KEY_SENSOR_ORIENTATION, mCameraProperties->get(CameraProperties::SENSOR_ORIENTATION));
3588 p.set(ExCameraParameters::KEY_SENSOR_ORIENTATION_VALUES, mCameraProperties->get(CameraProperties::SENSOR_ORIENTATION_VALUES));
3589 p.set(ExCameraParameters::KEY_EXIF_MAKE, mCameraProperties->get(CameraProperties::EXIF_MAKE));
3590 p.set(ExCameraParameters::KEY_EXIF_MODEL, mCameraProperties->get(CameraProperties::EXIF_MODEL));
3591 p.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, mCameraProperties->get(CameraProperties::JPEG_THUMBNAIL_QUALITY));
3592 p.set(CameraParameters::KEY_VIDEO_FRAME_FORMAT, (const char *) CameraParameters::PIXEL_FORMAT_YUV420SP);
3593 p.set(CameraParameters::KEY_MAX_NUM_DETECTED_FACES_HW, mCameraProperties->get(CameraProperties::MAX_FD_HW_FACES));
3594 p.set(CameraParameters::KEY_MAX_NUM_DETECTED_FACES_SW, mCameraProperties->get(CameraProperties::MAX_FD_SW_FACES));
3595
3596 // Only one area a.k.a Touch AF for now.
3597 // TODO: Add support for multiple focus areas.
3598 p.set(CameraParameters::KEY_MAX_NUM_FOCUS_AREAS, mCameraProperties->get(CameraProperties::MAX_FOCUS_AREAS));
3599 p.set(CameraParameters::KEY_AUTO_EXPOSURE_LOCK, mCameraProperties->get(CameraProperties::AUTO_EXPOSURE_LOCK));
3600 p.set(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK, mCameraProperties->get(CameraProperties::AUTO_WHITEBALANCE_LOCK));
3601 p.set(CameraParameters::KEY_MAX_NUM_METERING_AREAS, mCameraProperties->get(CameraProperties::MAX_NUM_METERING_AREAS));
3602 p.set(CameraParameters::KEY_VIDEO_SIZE, mCameraProperties->get(CameraProperties::VIDEO_SIZE));
3603 //p.set(CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO, mCameraProperties->get(CameraProperties::PREFERRED_PREVIEW_SIZE_FOR_VIDEO));
3604
3605 LOG_FUNCTION_NAME_EXIT;
3606}
3607
3608/**
3609 @brief Stop a previously started preview.
3610 @param none
3611 @return none
3612
3613 */
3614void VirtualCamHal::forceStopPreview()
3615{
3616 LOG_FUNCTION_NAME;
3617
3618 // stop bracketing if it is running
3619 stopImageBracketing();
3620
3621 if(mDisplayAdapter.get() != NULL) {
3622 ///Stop the buffer display first
3623 mDisplayAdapter->disableDisplay();
3624 }
3625
3626 if(mAppCbNotifier.get() != NULL) {
3627 //Stop the callback sending
3628 mAppCbNotifier->stop();
3629 mAppCbNotifier->flushAndReturnFrames();
3630 mAppCbNotifier->stopPreviewCallbacks();
3631 }
3632
3633 if ( NULL != mCameraAdapter ) {
3634 // only need to send these control commands to state machine if we are
3635 // passed the LOADED_PREVIEW_STATE
3636 if (mCameraAdapter->getState() > CameraAdapter::LOADED_PREVIEW_STATE) {
3637 // according to javadoc...FD should be stopped in stopPreview
3638 // and application needs to call startFaceDection again
3639 // to restart FD
3640 mCameraAdapter->sendCommand(CameraAdapter::CAMERA_STOP_FD);
3641 }
3642
3643 LOGD("rollback!!!!!!!!");
3644 mCameraAdapter->rollbackToInitializedState();
3645
3646 }
3647
3648 freePreviewBufs();
3649 freePreviewDataBufs();
3650
3651 mPreviewEnabled = false;
3652 mDisplayPaused = false;
3653 mPreviewStartInProgress = false;
3654
3655 LOG_FUNCTION_NAME_EXIT;
3656}
3657
3658/**
3659 @brief Deallocates memory for all the resources held by Camera HAL.
3660
3661 Frees the following objects- CameraAdapter, AppCallbackNotifier, DisplayAdapter,
3662 and Memory Manager
3663
3664 @param none
3665 @return none
3666
3667 */
3668void VirtualCamHal::deinitialize()
3669{
3670 LOG_FUNCTION_NAME;
3671
3672 if ( mPreviewEnabled || mDisplayPaused ) {
3673 forceStopPreview();
3674 }
3675
3676 mSetPreviewWindowCalled = false;
3677
3678#ifdef ENABLE_SENSOR_LISTENER
3679 if (mSensorListener.get()) {
3680 mSensorListener->disableSensor(SensorListener::SENSOR_ORIENTATION);
3681 mSensorListener.clear();
3682 mSensorListener = NULL;
3683 }
3684#endif
3685
3686 LOG_FUNCTION_NAME_EXIT;
3687
3688}
3689
3690status_t VirtualCamHal::storeMetaDataInBuffers(bool enable)
3691{
3692 LOG_FUNCTION_NAME;
3693
3694 return mAppCbNotifier->useMetaDataBufferMode(enable);
3695
3696 LOG_FUNCTION_NAME_EXIT;
3697}
3698
3699void VirtualCamHal::selectFPSRange(int framerate, int *min_fps, int *max_fps)
3700{
3701 char * ptr;
3702 char supported[MAX_PROP_VALUE_LENGTH];
3703 int fpsrangeArray[2];
3704 int i = 0;
3705
3706 LOG_FUNCTION_NAME;
3707 size_t size = strlen(mCameraProperties->get(CameraProperties::FRAMERATE_RANGE_SUPPORTED))+1;
3708 strncpy(supported, mCameraProperties->get(CameraProperties::FRAMERATE_RANGE_SUPPORTED), size);
3709
3710 ptr = strtok (supported," (,)");
3711
3712 while (ptr != NULL)
3713 {
3714 fpsrangeArray[i]= atoi(ptr)/VirtualCamHal::VFR_SCALE;
3715 if (i == 1)
3716 {
3717 if ((framerate <= fpsrangeArray[i])&&(framerate >= fpsrangeArray[i-1]))
3718 {
3719 CAMHAL_LOGDB("SETTING FPS RANGE min = %d max = %d \n", fpsrangeArray[0], fpsrangeArray[1]);
3720 *min_fps = fpsrangeArray[0]*VirtualCamHal::VFR_SCALE;
3721 *max_fps = fpsrangeArray[1]*VirtualCamHal::VFR_SCALE;
3722 break;
3723 }
3724 }
3725 ptr = strtok (NULL, " (,)");
3726 i++;
3727 i%=2;
3728 }
3729
3730 LOG_FUNCTION_NAME_EXIT;
3731
3732}
3733
3734void VirtualCamHal::setPreferredPreviewRes(int width, int height)
3735{
3736 LOG_FUNCTION_NAME;
3737
3738 if ( (width == 320) && (height == 240)){
3739 mParameters.setPreviewSize(640,480);
3740 }
3741 if ( (width == 176) && (height == 144)){
3742 mParameters.setPreviewSize(704,576);
3743 }
3744
3745 LOG_FUNCTION_NAME_EXIT;
3746}
3747
3748void VirtualCamHal::resetPreviewRes(CameraParameters *mParams, int width, int height)
3749{
3750 LOG_FUNCTION_NAME;
3751
3752 if ( (width <= 320) && (height <= 240)){
3753 mParams->setPreviewSize(mVideoWidth, mVideoHeight);
3754 }
3755
3756 LOG_FUNCTION_NAME_EXIT;
3757}
3758
3759};
3760
3761
3762