1 /*
2 * Copyright (C) Texas Instruments - http://www.ti.com/
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 #include "BaseCameraAdapter.h"
18
19 const int EVENT_MASK = 0xffff;
20
21 namespace Ti {
22 namespace Camera {
23
24 const LUT cameraCommandsUserToHAL[] = {
25 { "CAMERA_START_PREVIEW", CameraAdapter::CAMERA_START_PREVIEW },
26 { "CAMERA_STOP_PREVIEW", CameraAdapter::CAMERA_STOP_PREVIEW },
27 { "CAMERA_START_VIDEO", CameraAdapter::CAMERA_START_VIDEO },
28 { "CAMERA_STOP_VIDEO", CameraAdapter::CAMERA_STOP_VIDEO },
29 { "CAMERA_START_IMAGE_CAPTURE", CameraAdapter::CAMERA_START_IMAGE_CAPTURE },
30 { "CAMERA_STOP_IMAGE_CAPTURE", CameraAdapter::CAMERA_STOP_IMAGE_CAPTURE },
31 { "CAMERA_PERFORM_AUTOFOCUS", CameraAdapter::CAMERA_PERFORM_AUTOFOCUS },
32 { "CAMERA_CANCEL_AUTOFOCUS", CameraAdapter::CAMERA_CANCEL_AUTOFOCUS },
33 { "CAMERA_PREVIEW_FLUSH_BUFFERS", CameraAdapter::CAMERA_PREVIEW_FLUSH_BUFFERS },
34 { "CAMERA_START_SMOOTH_ZOOM", CameraAdapter::CAMERA_START_SMOOTH_ZOOM },
35 { "CAMERA_STOP_SMOOTH_ZOOM", CameraAdapter::CAMERA_STOP_SMOOTH_ZOOM },
36 { "CAMERA_USE_BUFFERS_PREVIEW", CameraAdapter::CAMERA_USE_BUFFERS_PREVIEW },
37 { "CAMERA_SET_TIMEOUT", CameraAdapter::CAMERA_SET_TIMEOUT },
38 { "CAMERA_CANCEL_TIMEOUT", CameraAdapter::CAMERA_CANCEL_TIMEOUT },
39 { "CAMERA_START_BRACKET_CAPTURE", CameraAdapter::CAMERA_START_BRACKET_CAPTURE },
40 { "CAMERA_STOP_BRACKET_CAPTURE", CameraAdapter::CAMERA_STOP_BRACKET_CAPTURE },
41 { "CAMERA_QUERY_RESOLUTION_PREVIEW", CameraAdapter::CAMERA_QUERY_RESOLUTION_PREVIEW },
42 { "CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE", CameraAdapter::CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE },
43 { "CAMERA_QUERY_BUFFER_SIZE_PREVIEW_DATA", CameraAdapter::CAMERA_QUERY_BUFFER_SIZE_PREVIEW_DATA },
44 { "CAMERA_USE_BUFFERS_IMAGE_CAPTURE", CameraAdapter::CAMERA_USE_BUFFERS_IMAGE_CAPTURE },
45 { "CAMERA_USE_BUFFERS_PREVIEW_DATA", CameraAdapter::CAMERA_USE_BUFFERS_PREVIEW_DATA },
46 { "CAMERA_TIMEOUT_EXPIRED", CameraAdapter::CAMERA_TIMEOUT_EXPIRED },
47 { "CAMERA_START_FD", CameraAdapter::CAMERA_START_FD },
48 { "CAMERA_STOP_FD", CameraAdapter::CAMERA_STOP_FD },
49 { "CAMERA_SWITCH_TO_EXECUTING", CameraAdapter::CAMERA_SWITCH_TO_EXECUTING },
50 { "CAMERA_USE_BUFFERS_VIDEO_CAPTURE", CameraAdapter::CAMERA_USE_BUFFERS_VIDEO_CAPTURE },
51 #ifdef OMAP_ENHANCEMENT_CPCAM
52 { "CAMERA_USE_BUFFERS_REPROCESS", CameraAdapter::CAMERA_USE_BUFFERS_REPROCESS },
53 { "CAMERA_START_REPROCESS", CameraAdapter::CAMERA_START_REPROCESS },
54 #endif
55 };
56
57 const LUTtypeHAL CamCommandsLUT = {
58 sizeof(cameraCommandsUserToHAL)/sizeof(cameraCommandsUserToHAL[0]),
59 cameraCommandsUserToHAL
60 };
61
62 /*--------------------Camera Adapter Class STARTS here-----------------------------*/
63
BaseCameraAdapter()64 BaseCameraAdapter::BaseCameraAdapter()
65 {
66 mReleaseImageBuffersCallback = NULL;
67 mEndImageCaptureCallback = NULL;
68 mErrorNotifier = NULL;
69 mEndCaptureData = NULL;
70 mReleaseData = NULL;
71 mRecording = false;
72
73 mPreviewBuffers = NULL;
74 mPreviewBufferCount = 0;
75 mPreviewBuffersLength = 0;
76
77 mVideoBuffers = NULL;
78 mVideoBuffersCount = 0;
79 mVideoBuffersLength = 0;
80
81 mCaptureBuffers = NULL;
82 mCaptureBuffersCount = 0;
83 mCaptureBuffersLength = 0;
84
85 mPreviewDataBuffers = NULL;
86 mPreviewDataBuffersCount = 0;
87 mPreviewDataBuffersLength = 0;
88
89 mAdapterState = INTIALIZED_STATE;
90
91 mSharedAllocator = NULL;
92
93 #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
94 mStartFocus.tv_sec = 0;
95 mStartFocus.tv_usec = 0;
96 mStartCapture.tv_sec = 0;
97 mStartCapture.tv_usec = 0;
98 #endif
99
100 }
101
~BaseCameraAdapter()102 BaseCameraAdapter::~BaseCameraAdapter()
103 {
104 LOG_FUNCTION_NAME;
105
106 android::AutoMutex lock(mSubscriberLock);
107
108 mFrameSubscribers.clear();
109 mImageSubscribers.clear();
110 mRawSubscribers.clear();
111 mVideoSubscribers.clear();
112 mVideoInSubscribers.clear();
113 mFocusSubscribers.clear();
114 mShutterSubscribers.clear();
115 mZoomSubscribers.clear();
116 mSnapshotSubscribers.clear();
117 mMetadataSubscribers.clear();
118
119 LOG_FUNCTION_NAME_EXIT;
120 }
121
registerImageReleaseCallback(release_image_buffers_callback callback,void * user_data)122 status_t BaseCameraAdapter::registerImageReleaseCallback(release_image_buffers_callback callback, void *user_data)
123 {
124 status_t ret = NO_ERROR;
125
126 LOG_FUNCTION_NAME;
127
128 mReleaseImageBuffersCallback = callback;
129 mReleaseData = user_data;
130
131 LOG_FUNCTION_NAME_EXIT;
132
133 return ret;
134 }
135
registerEndCaptureCallback(end_image_capture_callback callback,void * user_data)136 status_t BaseCameraAdapter::registerEndCaptureCallback(end_image_capture_callback callback, void *user_data)
137 {
138 status_t ret = NO_ERROR;
139
140 LOG_FUNCTION_NAME;
141
142 mEndImageCaptureCallback= callback;
143 mEndCaptureData = user_data;
144
145 LOG_FUNCTION_NAME_EXIT;
146
147 return ret;
148 }
149
setErrorHandler(ErrorNotifier * errorNotifier)150 status_t BaseCameraAdapter::setErrorHandler(ErrorNotifier *errorNotifier)
151 {
152 status_t ret = NO_ERROR;
153
154 LOG_FUNCTION_NAME;
155
156 if ( NULL == errorNotifier )
157 {
158 CAMHAL_LOGEA("Invalid Error Notifier reference");
159 ret = -EINVAL;
160 }
161
162 if ( NO_ERROR == ret )
163 {
164 mErrorNotifier = errorNotifier;
165 }
166
167 LOG_FUNCTION_NAME_EXIT;
168
169 return ret;
170 }
171
enableMsgType(int32_t msgs,frame_callback callback,event_callback eventCb,void * cookie)172 void BaseCameraAdapter::enableMsgType(int32_t msgs, frame_callback callback, event_callback eventCb, void* cookie)
173 {
174 android::AutoMutex lock(mSubscriberLock);
175
176 LOG_FUNCTION_NAME;
177
178 int32_t frameMsg = ((msgs >> MessageNotifier::FRAME_BIT_FIELD_POSITION) & EVENT_MASK);
179 int32_t eventMsg = ((msgs >> MessageNotifier::EVENT_BIT_FIELD_POSITION) & EVENT_MASK);
180
181 if ( frameMsg != 0 )
182 {
183 CAMHAL_LOGVB("Frame message type id=0x%x subscription request", frameMsg);
184 switch ( frameMsg )
185 {
186 case CameraFrame::PREVIEW_FRAME_SYNC:
187 mFrameSubscribers.add((int) cookie, callback);
188 break;
189 case CameraFrame::FRAME_DATA_SYNC:
190 mFrameDataSubscribers.add((int) cookie, callback);
191 break;
192 case CameraFrame::SNAPSHOT_FRAME:
193 mSnapshotSubscribers.add((int) cookie, callback);
194 break;
195 case CameraFrame::IMAGE_FRAME:
196 mImageSubscribers.add((int) cookie, callback);
197 break;
198 case CameraFrame::RAW_FRAME:
199 mRawSubscribers.add((int) cookie, callback);
200 break;
201 case CameraFrame::VIDEO_FRAME_SYNC:
202 mVideoSubscribers.add((int) cookie, callback);
203 break;
204 case CameraFrame::REPROCESS_INPUT_FRAME:
205 mVideoInSubscribers.add((int) cookie, callback);
206 break;
207 default:
208 CAMHAL_LOGEA("Frame message type id=0x%x subscription no supported yet!", frameMsg);
209 break;
210 }
211 }
212
213 if ( eventMsg != 0)
214 {
215 CAMHAL_LOGVB("Event message type id=0x%x subscription request", eventMsg);
216 if ( CameraHalEvent::ALL_EVENTS == eventMsg )
217 {
218 mFocusSubscribers.add((int) cookie, eventCb);
219 mShutterSubscribers.add((int) cookie, eventCb);
220 mZoomSubscribers.add((int) cookie, eventCb);
221 mMetadataSubscribers.add((int) cookie, eventCb);
222 }
223 else
224 {
225 CAMHAL_LOGEA("Event message type id=0x%x subscription no supported yet!", eventMsg);
226 }
227 }
228
229 LOG_FUNCTION_NAME_EXIT;
230 }
231
disableMsgType(int32_t msgs,void * cookie)232 void BaseCameraAdapter::disableMsgType(int32_t msgs, void* cookie)
233 {
234 android::AutoMutex lock(mSubscriberLock);
235
236 LOG_FUNCTION_NAME;
237
238 int32_t frameMsg = ((msgs >> MessageNotifier::FRAME_BIT_FIELD_POSITION) & EVENT_MASK);
239 int32_t eventMsg = ((msgs >> MessageNotifier::EVENT_BIT_FIELD_POSITION) & EVENT_MASK);
240
241 if ( frameMsg != 0 )
242 {
243 CAMHAL_LOGVB("Frame message type id=0x%x remove subscription request", frameMsg);
244 switch ( frameMsg )
245 {
246 case CameraFrame::PREVIEW_FRAME_SYNC:
247 mFrameSubscribers.removeItem((int) cookie);
248 break;
249 case CameraFrame::FRAME_DATA_SYNC:
250 mFrameDataSubscribers.removeItem((int) cookie);
251 break;
252 case CameraFrame::SNAPSHOT_FRAME:
253 mSnapshotSubscribers.removeItem((int) cookie);
254 break;
255 case CameraFrame::IMAGE_FRAME:
256 mImageSubscribers.removeItem((int) cookie);
257 break;
258 case CameraFrame::RAW_FRAME:
259 mRawSubscribers.removeItem((int) cookie);
260 break;
261 case CameraFrame::VIDEO_FRAME_SYNC:
262 mVideoSubscribers.removeItem((int) cookie);
263 break;
264 case CameraFrame::REPROCESS_INPUT_FRAME:
265 mVideoInSubscribers.removeItem((int) cookie);
266 break;
267 case CameraFrame::ALL_FRAMES:
268 mFrameSubscribers.removeItem((int) cookie);
269 mFrameDataSubscribers.removeItem((int) cookie);
270 mSnapshotSubscribers.removeItem((int) cookie);
271 mImageSubscribers.removeItem((int) cookie);
272 mRawSubscribers.removeItem((int) cookie);
273 mVideoSubscribers.removeItem((int) cookie);
274 mVideoInSubscribers.removeItem((int) cookie);
275 break;
276 default:
277 CAMHAL_LOGEA("Frame message type id=0x%x subscription remove not supported yet!", frameMsg);
278 break;
279 }
280 }
281
282 if ( eventMsg != 0 )
283 {
284 CAMHAL_LOGVB("Event message type id=0x%x remove subscription request", eventMsg);
285 if ( CameraHalEvent::ALL_EVENTS == eventMsg)
286 {
287 //TODO: Process case by case
288 mFocusSubscribers.removeItem((int) cookie);
289 mShutterSubscribers.removeItem((int) cookie);
290 mZoomSubscribers.removeItem((int) cookie);
291 mMetadataSubscribers.removeItem((int) cookie);
292 }
293 else
294 {
295 CAMHAL_LOGEA("Event message type id=0x%x subscription remove not supported yet!", eventMsg);
296 }
297 }
298
299 LOG_FUNCTION_NAME_EXIT;
300 }
301
addFramePointers(CameraBuffer * frameBuf,void * buf)302 void BaseCameraAdapter::addFramePointers(CameraBuffer *frameBuf, void *buf)
303 {
304 unsigned int *pBuf = (unsigned int *)buf;
305 android::AutoMutex lock(mSubscriberLock);
306
307 if ((frameBuf != NULL) && ( pBuf != NULL) )
308 {
309 CameraFrame *frame = new CameraFrame;
310 frame->mBuffer = frameBuf;
311 frame->mYuv[0] = pBuf[0];
312 frame->mYuv[1] = pBuf[1];
313 mFrameQueue.add(frameBuf, frame);
314
315 CAMHAL_LOGVB("Adding Frame=0x%x Y=0x%x UV=0x%x", frame->mBuffer, frame->mYuv[0], frame->mYuv[1]);
316 }
317 }
318
removeFramePointers()319 void BaseCameraAdapter::removeFramePointers()
320 {
321 android::AutoMutex lock(mSubscriberLock);
322
323 int size = mFrameQueue.size();
324 CAMHAL_LOGVB("Removing %d Frames = ", size);
325 for (int i = 0; i < size; i++)
326 {
327 CameraFrame *frame = (CameraFrame *)mFrameQueue.valueAt(i);
328 CAMHAL_LOGVB("Free Frame=0x%x Y=0x%x UV=0x%x", frame->mBuffer, frame->mYuv[0], frame->mYuv[1]);
329 delete frame;
330 }
331 mFrameQueue.clear();
332 }
333
returnFrame(CameraBuffer * frameBuf,CameraFrame::FrameType frameType)334 void BaseCameraAdapter::returnFrame(CameraBuffer * frameBuf, CameraFrame::FrameType frameType)
335 {
336 status_t res = NO_ERROR;
337 size_t subscriberCount = 0;
338 int refCount = -1;
339
340 if ( NULL == frameBuf )
341 {
342 CAMHAL_LOGEA("Invalid frameBuf");
343 return;
344 }
345
346 if ( NO_ERROR == res)
347 {
348 android::AutoMutex lock(mReturnFrameLock);
349
350 refCount = getFrameRefCount(frameBuf, frameType);
351
352 if(frameType == CameraFrame::PREVIEW_FRAME_SYNC)
353 {
354 mFramesWithDisplay--;
355 }
356 else if(frameType == CameraFrame::VIDEO_FRAME_SYNC)
357 {
358 mFramesWithEncoder--;
359 }
360
361 if ( 0 < refCount )
362 {
363
364 refCount--;
365 setFrameRefCount(frameBuf, frameType, refCount);
366
367
368 if ( mRecording && (CameraFrame::VIDEO_FRAME_SYNC == frameType) ) {
369 refCount += getFrameRefCount(frameBuf, CameraFrame::PREVIEW_FRAME_SYNC);
370 } else if ( mRecording && (CameraFrame::PREVIEW_FRAME_SYNC == frameType) ) {
371 refCount += getFrameRefCount(frameBuf, CameraFrame::VIDEO_FRAME_SYNC);
372 } else if ( mRecording && (CameraFrame::SNAPSHOT_FRAME == frameType) ) {
373 refCount += getFrameRefCount(frameBuf, CameraFrame::VIDEO_FRAME_SYNC);
374 }
375
376
377 }
378 else
379 {
380 CAMHAL_LOGDA("Frame returned when ref count is already zero!!");
381 return;
382 }
383 }
384
385 CAMHAL_LOGVB("REFCOUNT 0x%x %d", frameBuf, refCount);
386
387 if ( NO_ERROR == res )
388 {
389 //check if someone is holding this buffer
390 if ( 0 == refCount )
391 {
392 #ifdef CAMERAHAL_DEBUG
393 if((mBuffersWithDucati.indexOfKey((int)camera_buffer_get_omx_ptr(frameBuf)) >= 0) &&
394 ((CameraFrame::PREVIEW_FRAME_SYNC == frameType) ||
395 (CameraFrame::SNAPSHOT_FRAME == frameType)))
396 {
397 CAMHAL_LOGE("Buffer already with Ducati!! 0x%x", frameBuf);
398 for(int i=0;i<mBuffersWithDucati.size();i++) CAMHAL_LOGE("0x%x", mBuffersWithDucati.keyAt(i));
399 }
400 mBuffersWithDucati.add((int)camera_buffer_get_omx_ptr(frameBuf),1);
401 #endif
402 res = fillThisBuffer(frameBuf, frameType);
403 }
404 }
405
406 }
407
sendCommand(CameraCommands operation,int value1,int value2,int value3,int value4)408 status_t BaseCameraAdapter::sendCommand(CameraCommands operation, int value1, int value2, int value3, int value4) {
409 status_t ret = NO_ERROR;
410 struct timeval *refTimestamp;
411 BuffersDescriptor *desc = NULL;
412 CameraFrame *frame = NULL;
413
414 LOG_FUNCTION_NAME;
415
416 switch ( operation ) {
417 case CameraAdapter::CAMERA_USE_BUFFERS_PREVIEW:
418 CAMHAL_LOGDA("Use buffers for preview");
419 desc = ( BuffersDescriptor * ) value1;
420
421 if ( NULL == desc )
422 {
423 CAMHAL_LOGEA("Invalid preview buffers!");
424 return -EINVAL;
425 }
426
427 if ( ret == NO_ERROR )
428 {
429 ret = setState(operation);
430 }
431
432 if ( ret == NO_ERROR )
433 {
434 android::AutoMutex lock(mPreviewBufferLock);
435 mPreviewBuffers = desc->mBuffers;
436 mPreviewBuffersLength = desc->mLength;
437 mPreviewBuffersAvailable.clear();
438 mSnapshotBuffersAvailable.clear();
439 for ( uint32_t i = 0 ; i < desc->mMaxQueueable ; i++ )
440 {
441 mPreviewBuffersAvailable.add(&mPreviewBuffers[i], 0);
442 }
443 // initial ref count for undeqeueued buffers is 1 since buffer provider
444 // is still holding on to it
445 for ( uint32_t i = desc->mMaxQueueable ; i < desc->mCount ; i++ )
446 {
447 mPreviewBuffersAvailable.add(&mPreviewBuffers[i], 1);
448 }
449 }
450
451 if ( NULL != desc )
452 {
453 ret = useBuffers(CameraAdapter::CAMERA_PREVIEW,
454 desc->mBuffers,
455 desc->mCount,
456 desc->mLength,
457 desc->mMaxQueueable);
458 }
459
460 if ( ret == NO_ERROR )
461 {
462 ret = commitState();
463 }
464 else
465 {
466 ret |= rollbackState();
467 }
468
469 break;
470
471 case CameraAdapter::CAMERA_USE_BUFFERS_PREVIEW_DATA:
472 CAMHAL_LOGDA("Use buffers for preview data");
473 desc = ( BuffersDescriptor * ) value1;
474
475 if ( NULL == desc )
476 {
477 CAMHAL_LOGEA("Invalid preview data buffers!");
478 return -EINVAL;
479 }
480
481 if ( ret == NO_ERROR )
482 {
483 ret = setState(operation);
484 }
485
486 if ( ret == NO_ERROR )
487 {
488 android::AutoMutex lock(mPreviewDataBufferLock);
489 mPreviewDataBuffers = desc->mBuffers;
490 mPreviewDataBuffersLength = desc->mLength;
491 mPreviewDataBuffersAvailable.clear();
492 for ( uint32_t i = 0 ; i < desc->mMaxQueueable ; i++ )
493 {
494 mPreviewDataBuffersAvailable.add(&mPreviewDataBuffers[i], 0);
495 }
496 // initial ref count for undeqeueued buffers is 1 since buffer provider
497 // is still holding on to it
498 for ( uint32_t i = desc->mMaxQueueable ; i < desc->mCount ; i++ )
499 {
500 mPreviewDataBuffersAvailable.add(&mPreviewDataBuffers[i], 1);
501 }
502 }
503
504 if ( NULL != desc )
505 {
506 ret = useBuffers(CameraAdapter::CAMERA_MEASUREMENT,
507 desc->mBuffers,
508 desc->mCount,
509 desc->mLength,
510 desc->mMaxQueueable);
511 }
512
513 if ( ret == NO_ERROR )
514 {
515 ret = commitState();
516 }
517 else
518 {
519 ret |= rollbackState();
520 }
521
522 break;
523
524 case CameraAdapter::CAMERA_USE_BUFFERS_IMAGE_CAPTURE:
525 CAMHAL_LOGDA("Use buffers for image capture");
526 desc = ( BuffersDescriptor * ) value1;
527
528 if ( NULL == desc )
529 {
530 CAMHAL_LOGEA("Invalid capture buffers!");
531 return -EINVAL;
532 }
533
534 if ( ret == NO_ERROR )
535 {
536 ret = setState(operation);
537 }
538
539 if ( ret == NO_ERROR )
540 {
541 android::AutoMutex lock(mCaptureBufferLock);
542 mCaptureBuffers = desc->mBuffers;
543 mCaptureBuffersLength = desc->mLength;
544 }
545
546 if ( NULL != desc )
547 {
548 ret = useBuffers(CameraAdapter::CAMERA_IMAGE_CAPTURE,
549 desc->mBuffers,
550 desc->mCount,
551 desc->mLength,
552 desc->mMaxQueueable);
553 }
554
555 if ( ret == NO_ERROR )
556 {
557 ret = commitState();
558 }
559 else
560 {
561 ret |= rollbackState();
562 }
563
564 break;
565
566 #ifdef OMAP_ENHANCEMENT_CPCAM
567 case CameraAdapter::CAMERA_USE_BUFFERS_REPROCESS:
568 CAMHAL_LOGDA("Use buffers for reprocessing");
569 desc = (BuffersDescriptor *) value1;
570
571 if (NULL == desc) {
572 CAMHAL_LOGEA("Invalid capture buffers!");
573 return -EINVAL;
574 }
575
576 if (ret == NO_ERROR) {
577 ret = setState(operation);
578 }
579
580 if (ret == NO_ERROR) {
581 android::AutoMutex lock(mVideoInBufferLock);
582 mVideoInBuffers = desc->mBuffers;
583 mVideoInBuffersAvailable.clear();
584 for (uint32_t i = 0 ; i < desc->mMaxQueueable ; i++) {
585 mVideoInBuffersAvailable.add(&mVideoInBuffers[i], 0);
586 }
587 // initial ref count for undeqeueued buffers is 1 since buffer provider
588 // is still holding on to it
589 for ( uint32_t i = desc->mMaxQueueable ; i < desc->mCount ; i++ ) {
590 mVideoInBuffersAvailable.add(&mVideoInBuffers[i], 1);
591 }
592 ret = useBuffers(CameraAdapter::CAMERA_REPROCESS,
593 desc->mBuffers,
594 desc->mCount,
595 desc->mLength,
596 desc->mMaxQueueable);
597 }
598
599 if ( ret == NO_ERROR ) {
600 ret = commitState();
601 } else {
602 ret |= rollbackState();
603 }
604
605 break;
606 #endif
607
608 case CameraAdapter::CAMERA_START_SMOOTH_ZOOM:
609 {
610
611 if ( ret == NO_ERROR )
612 {
613 ret = setState(operation);
614 }
615
616 if ( ret == NO_ERROR )
617 {
618 ret = startSmoothZoom(value1);
619 }
620
621 if ( ret == NO_ERROR )
622 {
623 ret = commitState();
624 }
625 else
626 {
627 ret |= rollbackState();
628 }
629
630 break;
631
632 }
633
634 case CameraAdapter::CAMERA_STOP_SMOOTH_ZOOM:
635 {
636
637 if ( ret == NO_ERROR )
638 {
639 ret = setState(operation);
640 }
641
642 if ( ret == NO_ERROR )
643 {
644 ret = stopSmoothZoom();
645 }
646
647 if ( ret == NO_ERROR )
648 {
649 ret = commitState();
650 }
651 else
652 {
653 ret |= rollbackState();
654 }
655
656 break;
657
658 }
659
660 case CameraAdapter::CAMERA_START_PREVIEW:
661 {
662
663 CAMHAL_LOGDA("Start Preview");
664
665 if ( ret == NO_ERROR )
666 {
667 ret = setState(operation);
668 }
669
670 if ( ret == NO_ERROR )
671 {
672 ret = startPreview();
673 }
674
675 if ( ret == NO_ERROR )
676 {
677 ret = commitState();
678 }
679 else
680 {
681 ret |= rollbackState();
682 }
683
684 break;
685
686 }
687
688 case CameraAdapter::CAMERA_STOP_PREVIEW:
689 {
690
691 CAMHAL_LOGDA("Stop Preview");
692
693 if ( ret == NO_ERROR )
694 {
695 ret = setState(operation);
696 }
697
698 if ( ret == NO_ERROR )
699 {
700 ret = stopPreview();
701 }
702
703 if ( ret == NO_ERROR )
704 {
705 ret = commitState();
706 }
707 else
708 {
709 ret |= rollbackState();
710 }
711
712 break;
713
714 }
715
716 case CameraAdapter::CAMERA_START_VIDEO:
717 {
718
719 CAMHAL_LOGDA("Start video recording");
720
721 if ( ret == NO_ERROR )
722 {
723 ret = setState(operation);
724 }
725
726 if ( ret == NO_ERROR )
727 {
728 ret = startVideoCapture();
729 }
730
731 if ( ret == NO_ERROR )
732 {
733 ret = commitState();
734 }
735 else
736 {
737 ret |= rollbackState();
738 }
739
740 break;
741
742 }
743
744 case CameraAdapter::CAMERA_STOP_VIDEO:
745 {
746
747 CAMHAL_LOGDA("Stop video recording");
748
749 if ( ret == NO_ERROR )
750 {
751 ret = setState(operation);
752 }
753
754 if ( ret == NO_ERROR )
755 {
756 ret = stopVideoCapture();
757 }
758
759 if ( ret == NO_ERROR )
760 {
761 ret = commitState();
762 }
763 else
764 {
765 ret |= rollbackState();
766 }
767
768 break;
769
770 }
771
772 case CameraAdapter::CAMERA_START_IMAGE_CAPTURE:
773 {
774
775 #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
776
777 refTimestamp = ( struct timeval * ) value1;
778 if ( NULL != refTimestamp )
779 {
780 memcpy( &mStartCapture, refTimestamp, sizeof( struct timeval ));
781 }
782
783 #endif
784
785 if ( ret == NO_ERROR )
786 {
787 ret = setState(operation);
788 }
789
790 if ( ret == NO_ERROR )
791 {
792 ret = takePicture();
793 }
794
795 if ( ret == NO_ERROR )
796 {
797 ret = commitState();
798 }
799 else
800 {
801 ret |= rollbackState();
802 }
803
804 break;
805
806 }
807
808 case CameraAdapter::CAMERA_STOP_IMAGE_CAPTURE:
809 {
810
811 if ( ret == NO_ERROR )
812 {
813 ret = setState(operation);
814 }
815
816 if ( ret == NO_ERROR )
817 {
818 ret = stopImageCapture();
819 }
820
821 if ( ret == NO_ERROR )
822 {
823 ret = commitState();
824 }
825 else
826 {
827 ret |= rollbackState();
828 }
829
830 break;
831
832 }
833
834 case CameraAdapter::CAMERA_START_BRACKET_CAPTURE:
835 {
836
837 #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
838
839 refTimestamp = ( struct timeval * ) value2;
840 if ( NULL != refTimestamp )
841 {
842 memcpy( &mStartCapture, refTimestamp, sizeof( struct timeval ));
843 }
844
845 #endif
846
847 if ( ret == NO_ERROR )
848 {
849 ret = setState(operation);
850 }
851
852 if ( ret == NO_ERROR )
853 {
854 ret = startBracketing(value1);
855 }
856
857 if ( ret == NO_ERROR )
858 {
859 ret = commitState();
860 }
861 else
862 {
863 ret |= rollbackState();
864 }
865
866 break;
867
868 }
869
870 case CameraAdapter::CAMERA_STOP_BRACKET_CAPTURE:
871 {
872
873 if ( ret == NO_ERROR )
874 {
875 ret = setState(operation);
876 }
877
878 if ( ret == NO_ERROR )
879 {
880 ret = stopBracketing();
881 }
882
883 if ( ret == NO_ERROR )
884 {
885 ret = commitState();
886 }
887 else
888 {
889 ret |= rollbackState();
890 }
891
892 break;
893
894 }
895
896 case CameraAdapter::CAMERA_PERFORM_AUTOFOCUS:
897
898 #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
899
900 refTimestamp = ( struct timeval * ) value1;
901 if ( NULL != refTimestamp )
902 {
903 memcpy( &mStartFocus, refTimestamp, sizeof( struct timeval ));
904 }
905
906 #endif
907
908 if ( ret == NO_ERROR )
909 {
910 ret = setState(operation);
911 }
912
913 if ( ret == NO_ERROR )
914 {
915 ret = autoFocus();
916 }
917
918 if ( ret == NO_ERROR )
919 {
920 ret = commitState();
921 }
922 else
923 {
924 ret |= rollbackState();
925 }
926
927 break;
928
929 case CameraAdapter::CAMERA_CANCEL_AUTOFOCUS:
930
931 if ( ret == NO_ERROR )
932 {
933 ret = setState(operation);
934 }
935
936 if ( ret == NO_ERROR )
937 {
938 ret = cancelAutoFocus();
939 }
940
941 if ( ret == NO_ERROR )
942 {
943 ret = commitState();
944 }
945 else
946 {
947 ret |= rollbackState();
948 }
949
950 break;
951
952 case CameraAdapter::CAMERA_QUERY_RESOLUTION_PREVIEW:
953
954 if ( ret == NO_ERROR )
955 {
956 ret = setState(operation);
957 }
958
959 if ( ret == NO_ERROR )
960 {
961 frame = ( CameraFrame * ) value1;
962
963 if ( NULL != frame )
964 {
965 ret = getFrameSize(frame->mWidth, frame->mHeight);
966 }
967 else
968 {
969 ret = -EINVAL;
970 }
971 }
972
973 if ( ret == NO_ERROR )
974 {
975 ret = commitState();
976 }
977 else
978 {
979 ret |= rollbackState();
980 }
981
982 break;
983
984 case CameraAdapter::CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE:
985
986 if ( ret == NO_ERROR )
987 {
988 ret = setState(operation);
989 }
990
991 if ( ret == NO_ERROR )
992 {
993 frame = ( CameraFrame * ) value1;
994
995 if ( NULL != frame )
996 {
997 ret = getPictureBufferSize(*frame, value2);
998 }
999 else
1000 {
1001 ret = -EINVAL;
1002 }
1003 }
1004
1005 if ( ret == NO_ERROR )
1006 {
1007 ret = commitState();
1008 }
1009 else
1010 {
1011 ret |= rollbackState();
1012 }
1013
1014 break;
1015
1016 case CameraAdapter::CAMERA_QUERY_BUFFER_SIZE_PREVIEW_DATA:
1017
1018 if ( ret == NO_ERROR )
1019 {
1020 ret = setState(operation);
1021 }
1022
1023 if ( ret == NO_ERROR )
1024 {
1025 frame = ( CameraFrame * ) value1;
1026
1027 if ( NULL != frame )
1028 {
1029 ret = getFrameDataSize(frame->mLength, value2);
1030 }
1031 else
1032 {
1033 ret = -EINVAL;
1034 }
1035 }
1036
1037 if ( ret == NO_ERROR )
1038 {
1039 ret = commitState();
1040 }
1041 else
1042 {
1043 ret |= rollbackState();
1044 }
1045
1046 break;
1047
1048 case CameraAdapter::CAMERA_START_FD:
1049
1050 ret = startFaceDetection();
1051
1052 break;
1053
1054 case CameraAdapter::CAMERA_STOP_FD:
1055
1056 ret = stopFaceDetection();
1057
1058 break;
1059
1060 case CameraAdapter::CAMERA_USE_BUFFERS_VIDEO_CAPTURE:
1061
1062 CAMHAL_LOGDA("Use buffers for video (RAW + JPEG) capture");
1063 desc = ( BuffersDescriptor * ) value1;
1064
1065 if ( NULL == desc ) {
1066 CAMHAL_LOGEA("Invalid capture buffers!");
1067 return -EINVAL;
1068 }
1069
1070 if ( ret == NO_ERROR ) {
1071 ret = setState(operation);
1072 }
1073
1074 if ( ret == NO_ERROR ) {
1075 android::AutoMutex lock(mVideoBufferLock);
1076 mVideoBuffers = desc->mBuffers;
1077 mVideoBuffersLength = desc->mLength;
1078 mVideoBuffersAvailable.clear();
1079 for ( uint32_t i = 0 ; i < desc->mMaxQueueable ; i++ ) {
1080 mVideoBuffersAvailable.add(&mVideoBuffers[i], 1);
1081 }
1082 // initial ref count for undeqeueued buffers is 1 since buffer provider
1083 // is still holding on to it
1084 for ( uint32_t i = desc->mMaxQueueable ; i < desc->mCount ; i++ ) {
1085 mVideoBuffersAvailable.add(&mVideoBuffers[i], 1);
1086 }
1087 }
1088
1089 if ( NULL != desc ) {
1090 ret = useBuffers(CameraAdapter::CAMERA_VIDEO,
1091 desc->mBuffers,
1092 desc->mCount,
1093 desc->mLength,
1094 desc->mMaxQueueable);
1095 }
1096
1097 if ( ret == NO_ERROR ) {
1098 ret = commitState();
1099 } else {
1100 ret |= rollbackState();
1101 }
1102
1103 break;
1104
1105 case CameraAdapter::CAMERA_SWITCH_TO_EXECUTING:
1106 ret = switchToExecuting();
1107 break;
1108
1109 #ifdef OMAP_ENHANCEMENT_VTC
1110 case CameraAdapter::CAMERA_SETUP_TUNNEL:
1111 ret = setupTunnel(value1, value2, value3, value4);
1112 break;
1113
1114 case CameraAdapter::CAMERA_DESTROY_TUNNEL:
1115 ret = destroyTunnel();
1116 break;
1117 #endif
1118
1119 case CameraAdapter::CAMERA_PREVIEW_INITIALIZATION:
1120 ret = cameraPreviewInitialization();
1121 break;
1122
1123 default:
1124 CAMHAL_LOGEB("Command 0x%x unsupported!", operation);
1125 break;
1126 };
1127
1128 LOG_FUNCTION_NAME_EXIT;
1129 return ret;
1130 }
1131
notifyFocusSubscribers(CameraHalEvent::FocusStatus status)1132 status_t BaseCameraAdapter::notifyFocusSubscribers(CameraHalEvent::FocusStatus status)
1133 {
1134 event_callback eventCb;
1135 CameraHalEvent focusEvent;
1136 status_t ret = NO_ERROR;
1137
1138 LOG_FUNCTION_NAME;
1139
1140 if ( mFocusSubscribers.size() == 0 ) {
1141 CAMHAL_LOGDA("No Focus Subscribers!");
1142 return NO_INIT;
1143 }
1144
1145 #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
1146 if (status == CameraHalEvent::FOCUS_STATUS_PENDING) {
1147 gettimeofday(&mStartFocus, NULL);
1148 } else {
1149 //dump the AF latency
1150 CameraHal::PPM("Focus finished in: ", &mStartFocus);
1151 }
1152 #endif
1153
1154 focusEvent.mEventData = new CameraHalEvent::CameraHalEventData();
1155 if ( NULL == focusEvent.mEventData.get() ) {
1156 return -ENOMEM;
1157 }
1158
1159 focusEvent.mEventType = CameraHalEvent::EVENT_FOCUS_LOCKED;
1160 focusEvent.mEventData->focusEvent.focusStatus = status;
1161
1162 for (unsigned int i = 0 ; i < mFocusSubscribers.size(); i++ )
1163 {
1164 focusEvent.mCookie = (void *) mFocusSubscribers.keyAt(i);
1165 eventCb = (event_callback) mFocusSubscribers.valueAt(i);
1166 eventCb ( &focusEvent );
1167 }
1168
1169 focusEvent.mEventData.clear();
1170
1171 LOG_FUNCTION_NAME_EXIT;
1172
1173 return ret;
1174 }
1175
notifyShutterSubscribers()1176 status_t BaseCameraAdapter::notifyShutterSubscribers()
1177 {
1178 CameraHalEvent shutterEvent;
1179 event_callback eventCb;
1180 status_t ret = NO_ERROR;
1181
1182 LOG_FUNCTION_NAME;
1183
1184 if ( mShutterSubscribers.size() == 0 )
1185 {
1186 CAMHAL_LOGEA("No shutter Subscribers!");
1187 return NO_INIT;
1188 }
1189
1190 shutterEvent.mEventData = new CameraHalEvent::CameraHalEventData();
1191 if ( NULL == shutterEvent.mEventData.get() ) {
1192 return -ENOMEM;
1193 }
1194
1195 shutterEvent.mEventType = CameraHalEvent::EVENT_SHUTTER;
1196 shutterEvent.mEventData->shutterEvent.shutterClosed = true;
1197
1198 for (unsigned int i = 0 ; i < mShutterSubscribers.size() ; i++ ) {
1199 shutterEvent.mCookie = ( void * ) mShutterSubscribers.keyAt(i);
1200 eventCb = ( event_callback ) mShutterSubscribers.valueAt(i);
1201
1202 CAMHAL_LOGD("Sending shutter callback");
1203
1204 eventCb ( &shutterEvent );
1205 }
1206
1207 shutterEvent.mEventData.clear();
1208
1209 LOG_FUNCTION_NAME_EXIT;
1210
1211 return ret;
1212 }
1213
notifyZoomSubscribers(int zoomIdx,bool targetReached)1214 status_t BaseCameraAdapter::notifyZoomSubscribers(int zoomIdx, bool targetReached)
1215 {
1216 event_callback eventCb;
1217 CameraHalEvent zoomEvent;
1218 status_t ret = NO_ERROR;
1219
1220 LOG_FUNCTION_NAME;
1221
1222 if ( mZoomSubscribers.size() == 0 ) {
1223 CAMHAL_LOGDA("No zoom Subscribers!");
1224 return NO_INIT;
1225 }
1226
1227 zoomEvent.mEventData = new CameraHalEvent::CameraHalEventData();
1228 if ( NULL == zoomEvent.mEventData.get() ) {
1229 return -ENOMEM;
1230 }
1231
1232 zoomEvent.mEventType = CameraHalEvent::EVENT_ZOOM_INDEX_REACHED;
1233 zoomEvent.mEventData->zoomEvent.currentZoomIndex = zoomIdx;
1234 zoomEvent.mEventData->zoomEvent.targetZoomIndexReached = targetReached;
1235
1236 for (unsigned int i = 0 ; i < mZoomSubscribers.size(); i++ ) {
1237 zoomEvent.mCookie = (void *) mZoomSubscribers.keyAt(i);
1238 eventCb = (event_callback) mZoomSubscribers.valueAt(i);
1239
1240 eventCb ( &zoomEvent );
1241 }
1242
1243 zoomEvent.mEventData.clear();
1244
1245 LOG_FUNCTION_NAME_EXIT;
1246
1247 return ret;
1248 }
1249
notifyMetadataSubscribers(android::sp<CameraMetadataResult> & meta)1250 status_t BaseCameraAdapter::notifyMetadataSubscribers(android::sp<CameraMetadataResult> &meta)
1251 {
1252 event_callback eventCb;
1253 CameraHalEvent metaEvent;
1254 status_t ret = NO_ERROR;
1255
1256 LOG_FUNCTION_NAME;
1257
1258 if ( mMetadataSubscribers.size() == 0 ) {
1259 CAMHAL_LOGDA("No preview metadata subscribers!");
1260 return NO_INIT;
1261 }
1262
1263 metaEvent.mEventData = new CameraHalEvent::CameraHalEventData();
1264 if ( NULL == metaEvent.mEventData.get() ) {
1265 return -ENOMEM;
1266 }
1267
1268 metaEvent.mEventType = CameraHalEvent::EVENT_METADATA;
1269 metaEvent.mEventData->metadataEvent = meta;
1270
1271 for (unsigned int i = 0 ; i < mMetadataSubscribers.size(); i++ ) {
1272 metaEvent.mCookie = (void *) mMetadataSubscribers.keyAt(i);
1273 eventCb = (event_callback) mMetadataSubscribers.valueAt(i);
1274
1275 eventCb ( &metaEvent );
1276 }
1277
1278 metaEvent.mEventData.clear();
1279
1280 LOG_FUNCTION_NAME_EXIT;
1281
1282 return ret;
1283 }
1284
sendFrameToSubscribers(CameraFrame * frame)1285 status_t BaseCameraAdapter::sendFrameToSubscribers(CameraFrame *frame)
1286 {
1287 status_t ret = NO_ERROR;
1288 unsigned int mask;
1289
1290 if ( NULL == frame )
1291 {
1292 CAMHAL_LOGEA("Invalid CameraFrame");
1293 return -EINVAL;
1294 }
1295
1296 for( mask = 1; mask < CameraFrame::ALL_FRAMES; mask <<= 1){
1297 if( mask & frame->mFrameMask ){
1298 switch( mask ){
1299
1300 case CameraFrame::IMAGE_FRAME:
1301 {
1302 #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
1303 CameraHal::PPM("Shot to Jpeg: ", &mStartCapture);
1304 #endif
1305 ret = __sendFrameToSubscribers(frame, &mImageSubscribers, CameraFrame::IMAGE_FRAME);
1306 }
1307 break;
1308 case CameraFrame::RAW_FRAME:
1309 {
1310 ret = __sendFrameToSubscribers(frame, &mRawSubscribers, CameraFrame::RAW_FRAME);
1311 }
1312 break;
1313 case CameraFrame::PREVIEW_FRAME_SYNC:
1314 {
1315 ret = __sendFrameToSubscribers(frame, &mFrameSubscribers, CameraFrame::PREVIEW_FRAME_SYNC);
1316 }
1317 break;
1318 case CameraFrame::SNAPSHOT_FRAME:
1319 {
1320 ret = __sendFrameToSubscribers(frame, &mSnapshotSubscribers, CameraFrame::SNAPSHOT_FRAME);
1321 }
1322 break;
1323 case CameraFrame::VIDEO_FRAME_SYNC:
1324 {
1325 ret = __sendFrameToSubscribers(frame, &mVideoSubscribers, CameraFrame::VIDEO_FRAME_SYNC);
1326 }
1327 break;
1328 case CameraFrame::FRAME_DATA_SYNC:
1329 {
1330 ret = __sendFrameToSubscribers(frame, &mFrameDataSubscribers, CameraFrame::FRAME_DATA_SYNC);
1331 }
1332 break;
1333 case CameraFrame::REPROCESS_INPUT_FRAME:
1334 {
1335 ret = __sendFrameToSubscribers(frame, &mVideoInSubscribers, CameraFrame::REPROCESS_INPUT_FRAME);
1336 }
1337 break;
1338 default:
1339 CAMHAL_LOGEB("FRAMETYPE NOT SUPPORTED 0x%x", mask);
1340 break;
1341 }//SWITCH
1342 frame->mFrameMask &= ~mask;
1343
1344 if (ret != NO_ERROR) {
1345 goto EXIT;
1346 }
1347 }//IF
1348 }//FOR
1349
1350 EXIT:
1351 return ret;
1352 }
1353
__sendFrameToSubscribers(CameraFrame * frame,android::KeyedVector<int,frame_callback> * subscribers,CameraFrame::FrameType frameType)1354 status_t BaseCameraAdapter::__sendFrameToSubscribers(CameraFrame* frame,
1355 android::KeyedVector<int, frame_callback> *subscribers,
1356 CameraFrame::FrameType frameType)
1357 {
1358 size_t refCount = 0;
1359 status_t ret = NO_ERROR;
1360 frame_callback callback = NULL;
1361
1362 frame->mFrameType = frameType;
1363
1364 if ( (frameType == CameraFrame::PREVIEW_FRAME_SYNC) ||
1365 (frameType == CameraFrame::VIDEO_FRAME_SYNC) ||
1366 (frameType == CameraFrame::SNAPSHOT_FRAME) ){
1367 if (mFrameQueue.size() > 0){
1368 CameraFrame *lframe = (CameraFrame *)mFrameQueue.valueFor(frame->mBuffer);
1369 frame->mYuv[0] = lframe->mYuv[0];
1370 frame->mYuv[1] = frame->mYuv[0] + (frame->mLength + frame->mOffset)*2/3;
1371 }
1372 else{
1373 CAMHAL_LOGDA("Empty Frame Queue");
1374 return -EINVAL;
1375 }
1376 }
1377
1378 if (NULL != subscribers) {
1379 refCount = getFrameRefCount(frame->mBuffer, frameType);
1380
1381 if (refCount == 0) {
1382 CAMHAL_LOGDA("Invalid ref count of 0");
1383 return -EINVAL;
1384 }
1385
1386 if (refCount > subscribers->size()) {
1387 CAMHAL_LOGEB("Invalid ref count for frame type: 0x%x", frameType);
1388 return -EINVAL;
1389 }
1390
1391 CAMHAL_LOGVB("Type of Frame: 0x%x address: 0x%x refCount start %d",
1392 frame->mFrameType,
1393 ( uint32_t ) frame->mBuffer,
1394 refCount);
1395
1396 for ( unsigned int i = 0 ; i < refCount; i++ ) {
1397 frame->mCookie = ( void * ) subscribers->keyAt(i);
1398 callback = (frame_callback) subscribers->valueAt(i);
1399
1400 if (!callback) {
1401 CAMHAL_LOGEB("callback not set for frame type: 0x%x", frameType);
1402 return -EINVAL;
1403 }
1404
1405 callback(frame);
1406 }
1407 } else {
1408 CAMHAL_LOGEA("Subscribers is null??");
1409 return -EINVAL;
1410 }
1411
1412 return ret;
1413 }
1414
setInitFrameRefCount(CameraBuffer * buf,unsigned int mask)1415 int BaseCameraAdapter::setInitFrameRefCount(CameraBuffer * buf, unsigned int mask)
1416 {
1417 int ret = NO_ERROR;
1418 unsigned int lmask;
1419
1420 LOG_FUNCTION_NAME;
1421
1422 if (buf == NULL)
1423 {
1424 return -EINVAL;
1425 }
1426
1427 for( lmask = 1; lmask < CameraFrame::ALL_FRAMES; lmask <<= 1){
1428 if( lmask & mask ){
1429 switch( lmask ){
1430
1431 case CameraFrame::IMAGE_FRAME:
1432 {
1433 setFrameRefCount(buf, CameraFrame::IMAGE_FRAME, (int) mImageSubscribers.size());
1434 }
1435 break;
1436 case CameraFrame::RAW_FRAME:
1437 {
1438 setFrameRefCount(buf, CameraFrame::RAW_FRAME, mRawSubscribers.size());
1439 }
1440 break;
1441 case CameraFrame::PREVIEW_FRAME_SYNC:
1442 {
1443 setFrameRefCount(buf, CameraFrame::PREVIEW_FRAME_SYNC, mFrameSubscribers.size());
1444 }
1445 break;
1446 case CameraFrame::SNAPSHOT_FRAME:
1447 {
1448 setFrameRefCount(buf, CameraFrame::SNAPSHOT_FRAME, mSnapshotSubscribers.size());
1449 }
1450 break;
1451 case CameraFrame::VIDEO_FRAME_SYNC:
1452 {
1453 setFrameRefCount(buf,CameraFrame::VIDEO_FRAME_SYNC, mVideoSubscribers.size());
1454 }
1455 break;
1456 case CameraFrame::FRAME_DATA_SYNC:
1457 {
1458 setFrameRefCount(buf, CameraFrame::FRAME_DATA_SYNC, mFrameDataSubscribers.size());
1459 }
1460 break;
1461 case CameraFrame::REPROCESS_INPUT_FRAME:
1462 {
1463 setFrameRefCount(buf,CameraFrame::REPROCESS_INPUT_FRAME, mVideoInSubscribers.size());
1464 }
1465 break;
1466 default:
1467 CAMHAL_LOGEB("FRAMETYPE NOT SUPPORTED 0x%x", lmask);
1468 break;
1469 }//SWITCH
1470 mask &= ~lmask;
1471 }//IF
1472 }//FOR
1473 LOG_FUNCTION_NAME_EXIT;
1474 return ret;
1475 }
1476
getFrameRefCount(CameraBuffer * frameBuf,CameraFrame::FrameType frameType)1477 int BaseCameraAdapter::getFrameRefCount(CameraBuffer * frameBuf, CameraFrame::FrameType frameType)
1478 {
1479 int res = -1;
1480
1481 LOG_FUNCTION_NAME;
1482
1483 switch ( frameType )
1484 {
1485 case CameraFrame::IMAGE_FRAME:
1486 case CameraFrame::RAW_FRAME:
1487 {
1488 android::AutoMutex lock(mCaptureBufferLock);
1489 res = mCaptureBuffersAvailable.valueFor(frameBuf );
1490 }
1491 break;
1492 case CameraFrame::SNAPSHOT_FRAME:
1493 {
1494 android::AutoMutex lock(mSnapshotBufferLock);
1495 res = mSnapshotBuffersAvailable.valueFor( ( unsigned int ) frameBuf );
1496 }
1497 break;
1498 case CameraFrame::PREVIEW_FRAME_SYNC:
1499 {
1500 android::AutoMutex lock(mPreviewBufferLock);
1501 res = mPreviewBuffersAvailable.valueFor(frameBuf );
1502 }
1503 break;
1504 case CameraFrame::FRAME_DATA_SYNC:
1505 {
1506 android::AutoMutex lock(mPreviewDataBufferLock);
1507 res = mPreviewDataBuffersAvailable.valueFor(frameBuf );
1508 }
1509 break;
1510 case CameraFrame::VIDEO_FRAME_SYNC:
1511 {
1512 android::AutoMutex lock(mVideoBufferLock);
1513 res = mVideoBuffersAvailable.valueFor(frameBuf );
1514 }
1515 break;
1516 case CameraFrame::REPROCESS_INPUT_FRAME: {
1517 android::AutoMutex lock(mVideoInBufferLock);
1518 res = mVideoInBuffersAvailable.valueFor(frameBuf );
1519 }
1520 break;
1521 default:
1522 break;
1523 };
1524
1525 LOG_FUNCTION_NAME_EXIT;
1526
1527 return res;
1528 }
1529
setFrameRefCount(CameraBuffer * frameBuf,CameraFrame::FrameType frameType,int refCount)1530 void BaseCameraAdapter::setFrameRefCount(CameraBuffer * frameBuf, CameraFrame::FrameType frameType, int refCount)
1531 {
1532
1533 LOG_FUNCTION_NAME;
1534
1535 switch ( frameType )
1536 {
1537 case CameraFrame::IMAGE_FRAME:
1538 case CameraFrame::RAW_FRAME:
1539 {
1540 android::AutoMutex lock(mCaptureBufferLock);
1541 mCaptureBuffersAvailable.replaceValueFor(frameBuf, refCount);
1542 }
1543 break;
1544 case CameraFrame::SNAPSHOT_FRAME:
1545 {
1546 android::AutoMutex lock(mSnapshotBufferLock);
1547 mSnapshotBuffersAvailable.replaceValueFor( ( unsigned int ) frameBuf, refCount);
1548 }
1549 break;
1550 case CameraFrame::PREVIEW_FRAME_SYNC:
1551 {
1552 android::AutoMutex lock(mPreviewBufferLock);
1553 mPreviewBuffersAvailable.replaceValueFor(frameBuf, refCount);
1554 }
1555 break;
1556 case CameraFrame::FRAME_DATA_SYNC:
1557 {
1558 android::AutoMutex lock(mPreviewDataBufferLock);
1559 mPreviewDataBuffersAvailable.replaceValueFor(frameBuf, refCount);
1560 }
1561 break;
1562 case CameraFrame::VIDEO_FRAME_SYNC:
1563 {
1564 android::AutoMutex lock(mVideoBufferLock);
1565 mVideoBuffersAvailable.replaceValueFor(frameBuf, refCount);
1566 }
1567 break;
1568 case CameraFrame::REPROCESS_INPUT_FRAME: {
1569 android::AutoMutex lock(mVideoInBufferLock);
1570 mVideoInBuffersAvailable.replaceValueFor(frameBuf, refCount);
1571 }
1572 break;
1573 default:
1574 break;
1575 };
1576
1577 LOG_FUNCTION_NAME_EXIT;
1578
1579 }
1580
startVideoCapture()1581 status_t BaseCameraAdapter::startVideoCapture()
1582 {
1583 status_t ret = NO_ERROR;
1584
1585 LOG_FUNCTION_NAME;
1586
1587 android::AutoMutex lock(mVideoBufferLock);
1588
1589 //If the capture is already ongoing, return from here.
1590 if ( mRecording )
1591 {
1592 ret = NO_INIT;
1593 }
1594
1595
1596 if ( NO_ERROR == ret )
1597 {
1598
1599 for ( unsigned int i = 0 ; i < mPreviewBuffersAvailable.size() ; i++ )
1600 {
1601 mVideoBuffersAvailable.add(mPreviewBuffersAvailable.keyAt(i), 0);
1602 }
1603
1604 mRecording = true;
1605 }
1606
1607 LOG_FUNCTION_NAME_EXIT;
1608
1609 return ret;
1610 }
1611
stopVideoCapture()1612 status_t BaseCameraAdapter::stopVideoCapture()
1613 {
1614 status_t ret = NO_ERROR;
1615
1616 LOG_FUNCTION_NAME;
1617
1618 if ( !mRecording )
1619 {
1620 ret = NO_INIT;
1621 }
1622
1623 if ( NO_ERROR == ret )
1624 {
1625 for ( unsigned int i = 0 ; i < mVideoBuffersAvailable.size() ; i++ )
1626 {
1627 CameraBuffer *frameBuf = mVideoBuffersAvailable.keyAt(i);
1628 if( getFrameRefCount(frameBuf, CameraFrame::VIDEO_FRAME_SYNC) > 0)
1629 {
1630 returnFrame(frameBuf, CameraFrame::VIDEO_FRAME_SYNC);
1631 }
1632 }
1633
1634 mVideoBuffersAvailable.clear();
1635
1636 mRecording = false;
1637 }
1638
1639 LOG_FUNCTION_NAME_EXIT;
1640
1641 return ret;
1642 }
1643
1644 //-----------------Stub implementation of the interface ------------------------------
1645
takePicture()1646 status_t BaseCameraAdapter::takePicture()
1647 {
1648 status_t ret = NO_ERROR;
1649
1650 LOG_FUNCTION_NAME;
1651
1652 LOG_FUNCTION_NAME_EXIT;
1653
1654 return ret;
1655 }
1656
stopImageCapture()1657 status_t BaseCameraAdapter::stopImageCapture()
1658 {
1659 status_t ret = NO_ERROR;
1660
1661 LOG_FUNCTION_NAME;
1662
1663 LOG_FUNCTION_NAME_EXIT;
1664
1665 return ret;
1666 }
1667
startBracketing(int range)1668 status_t BaseCameraAdapter::startBracketing(int range)
1669 {
1670 status_t ret = NO_ERROR;
1671
1672 LOG_FUNCTION_NAME;
1673
1674 LOG_FUNCTION_NAME_EXIT;
1675
1676 return ret;
1677 }
1678
stopBracketing()1679 status_t BaseCameraAdapter::stopBracketing()
1680 {
1681 status_t ret = NO_ERROR;
1682
1683 LOG_FUNCTION_NAME;
1684
1685 LOG_FUNCTION_NAME_EXIT;
1686
1687 return ret;
1688 }
1689
autoFocus()1690 status_t BaseCameraAdapter::autoFocus()
1691 {
1692 status_t ret = NO_ERROR;
1693
1694 LOG_FUNCTION_NAME;
1695
1696 notifyFocusSubscribers(CameraHalEvent::FOCUS_STATUS_FAIL);
1697
1698 LOG_FUNCTION_NAME_EXIT;
1699
1700 return ret;
1701 }
1702
cancelAutoFocus()1703 status_t BaseCameraAdapter::cancelAutoFocus()
1704 {
1705 status_t ret = NO_ERROR;
1706
1707 LOG_FUNCTION_NAME;
1708
1709 LOG_FUNCTION_NAME_EXIT;
1710
1711 return ret;
1712 }
1713
startSmoothZoom(int targetIdx)1714 status_t BaseCameraAdapter::startSmoothZoom(int targetIdx)
1715 {
1716 status_t ret = NO_ERROR;
1717
1718 LOG_FUNCTION_NAME;
1719
1720 LOG_FUNCTION_NAME_EXIT;
1721
1722 return ret;
1723 }
1724
stopSmoothZoom()1725 status_t BaseCameraAdapter::stopSmoothZoom()
1726 {
1727 status_t ret = NO_ERROR;
1728
1729 LOG_FUNCTION_NAME;
1730
1731 LOG_FUNCTION_NAME_EXIT;
1732
1733 return ret;
1734 }
1735
startPreview()1736 status_t BaseCameraAdapter::startPreview()
1737 {
1738 status_t ret = NO_ERROR;
1739
1740 LOG_FUNCTION_NAME;
1741
1742 LOG_FUNCTION_NAME_EXIT;
1743
1744 return ret;
1745 }
1746
stopPreview()1747 status_t BaseCameraAdapter::stopPreview()
1748 {
1749 status_t ret = NO_ERROR;
1750
1751 LOG_FUNCTION_NAME;
1752
1753 LOG_FUNCTION_NAME_EXIT;
1754
1755 return ret;
1756 }
1757
useBuffers(CameraMode mode,CameraBuffer * bufArr,int num,size_t length,unsigned int queueable)1758 status_t BaseCameraAdapter::useBuffers(CameraMode mode, CameraBuffer* bufArr, int num, size_t length, unsigned int queueable)
1759 {
1760 status_t ret = NO_ERROR;
1761
1762 LOG_FUNCTION_NAME;
1763
1764 LOG_FUNCTION_NAME_EXIT;
1765
1766 return ret;
1767 }
1768
fillThisBuffer(CameraBuffer * frameBuf,CameraFrame::FrameType frameType)1769 status_t BaseCameraAdapter::fillThisBuffer(CameraBuffer * frameBuf, CameraFrame::FrameType frameType)
1770 {
1771 status_t ret = NO_ERROR;
1772
1773 LOG_FUNCTION_NAME;
1774
1775 LOG_FUNCTION_NAME_EXIT;
1776
1777 return ret;
1778 }
1779
getFrameSize(size_t & width,size_t & height)1780 status_t BaseCameraAdapter::getFrameSize(size_t &width, size_t &height)
1781 {
1782 status_t ret = NO_ERROR;
1783
1784 LOG_FUNCTION_NAME;
1785
1786 LOG_FUNCTION_NAME_EXIT;
1787
1788 return ret;
1789 }
1790
getFrameDataSize(size_t & dataFrameSize,size_t bufferCount)1791 status_t BaseCameraAdapter::getFrameDataSize(size_t &dataFrameSize, size_t bufferCount)
1792 {
1793 status_t ret = NO_ERROR;
1794
1795 LOG_FUNCTION_NAME;
1796
1797 LOG_FUNCTION_NAME_EXIT;
1798
1799 return ret;
1800 }
1801
getPictureBufferSize(CameraFrame & frame,size_t bufferCount)1802 status_t BaseCameraAdapter::getPictureBufferSize(CameraFrame &frame, size_t bufferCount)
1803 {
1804 status_t ret = NO_ERROR;
1805
1806 LOG_FUNCTION_NAME;
1807
1808 LOG_FUNCTION_NAME_EXIT;
1809
1810 return ret;
1811 }
1812
startFaceDetection()1813 status_t BaseCameraAdapter::startFaceDetection()
1814 {
1815 status_t ret = NO_ERROR;
1816
1817 LOG_FUNCTION_NAME;
1818
1819 LOG_FUNCTION_NAME_EXIT;
1820
1821 return ret;
1822 }
1823
stopFaceDetection()1824 status_t BaseCameraAdapter::stopFaceDetection()
1825 {
1826 status_t ret = NO_ERROR;
1827
1828 LOG_FUNCTION_NAME;
1829
1830 LOG_FUNCTION_NAME_EXIT;
1831
1832 return ret;
1833 }
1834
switchToExecuting()1835 status_t BaseCameraAdapter::switchToExecuting()
1836 {
1837 status_t ret = NO_ERROR;
1838 LOG_FUNCTION_NAME;
1839 LOG_FUNCTION_NAME_EXIT;
1840 return ret;
1841 }
1842
getLUTvalue_translateHAL(int Value,LUTtypeHAL LUT)1843 const char* BaseCameraAdapter::getLUTvalue_translateHAL(int Value, LUTtypeHAL LUT) {
1844 int LUTsize = LUT.size;
1845 for(int i = 0; i < LUTsize; i++)
1846 if( LUT.Table[i].halDefinition == Value )
1847 return LUT.Table[i].userDefinition;
1848
1849 return NULL;
1850 }
1851
setupTunnel(uint32_t SliceHeight,uint32_t EncoderHandle,uint32_t width,uint32_t height)1852 status_t BaseCameraAdapter::setupTunnel(uint32_t SliceHeight, uint32_t EncoderHandle, uint32_t width, uint32_t height) {
1853 status_t ret = NO_ERROR;
1854 LOG_FUNCTION_NAME;
1855 LOG_FUNCTION_NAME_EXIT;
1856 return ret;
1857 }
1858
destroyTunnel()1859 status_t BaseCameraAdapter::destroyTunnel() {
1860 status_t ret = NO_ERROR;
1861 LOG_FUNCTION_NAME;
1862 LOG_FUNCTION_NAME_EXIT;
1863 return ret;
1864 }
1865
cameraPreviewInitialization()1866 status_t BaseCameraAdapter::cameraPreviewInitialization() {
1867 status_t ret = NO_ERROR;
1868 LOG_FUNCTION_NAME;
1869 LOG_FUNCTION_NAME_EXIT;
1870 return ret;
1871 }
1872
setState(CameraCommands operation)1873 status_t BaseCameraAdapter::setState(CameraCommands operation)
1874 {
1875 status_t ret = NO_ERROR;
1876
1877 LOG_FUNCTION_NAME;
1878
1879 const char *printState = getLUTvalue_translateHAL(operation, CamCommandsLUT);
1880
1881 mLock.lock();
1882
1883 switch ( mAdapterState )
1884 {
1885
1886 case INTIALIZED_STATE:
1887
1888 switch ( operation )
1889 {
1890
1891 case CAMERA_USE_BUFFERS_PREVIEW:
1892 CAMHAL_LOGDB("Adapter state switch INTIALIZED_STATE->LOADED_PREVIEW_STATE event = %s",
1893 printState);
1894 mNextState = LOADED_PREVIEW_STATE;
1895 break;
1896
1897 //These events don't change the current state
1898 case CAMERA_QUERY_RESOLUTION_PREVIEW:
1899 case CAMERA_QUERY_BUFFER_SIZE_PREVIEW_DATA:
1900 CAMHAL_LOGDB("Adapter state switch INTIALIZED_STATE->INTIALIZED_STATE event = %s",
1901 printState);
1902 mNextState = INTIALIZED_STATE;
1903 break;
1904 case CAMERA_STOP_BRACKET_CAPTURE:
1905 case CAMERA_STOP_IMAGE_CAPTURE:
1906 ret = INVALID_OPERATION;
1907 break;
1908 case CAMERA_CANCEL_AUTOFOCUS:
1909 ret = INVALID_OPERATION;
1910 break;
1911
1912 default:
1913 CAMHAL_LOGEB("Adapter state switch INTIALIZED_STATE Invalid Op! event = %s",
1914 printState);
1915 ret = INVALID_OPERATION;
1916 break;
1917
1918 }
1919
1920 break;
1921
1922 case LOADED_PREVIEW_STATE:
1923
1924 switch ( operation )
1925 {
1926
1927 case CAMERA_START_PREVIEW:
1928 CAMHAL_LOGDB("Adapter state switch LOADED_PREVIEW_STATE->PREVIEW_STATE event = %s",
1929 printState);
1930 mNextState = PREVIEW_STATE;
1931 break;
1932
1933 case CAMERA_STOP_PREVIEW:
1934 CAMHAL_LOGDB("Adapter state switch LOADED_PREVIEW_STATE->INTIALIZED_STATE event = 0x%x",
1935 operation);
1936 mNextState = INTIALIZED_STATE;
1937 break;
1938
1939 //These events don't change the current state
1940 case CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE:
1941 case CAMERA_QUERY_BUFFER_SIZE_PREVIEW_DATA:
1942 case CAMERA_USE_BUFFERS_PREVIEW_DATA:
1943 CAMHAL_LOGDB("Adapter state switch LOADED_PREVIEW_STATE->LOADED_PREVIEW_STATE event = %s",
1944 printState);
1945 mNextState = LOADED_PREVIEW_STATE;
1946 break;
1947
1948 default:
1949 CAMHAL_LOGDB("Adapter state switch LOADED_PREVIEW Invalid Op! event = %s",
1950 printState);
1951 ret = INVALID_OPERATION;
1952 break;
1953
1954 }
1955
1956 break;
1957
1958 case PREVIEW_STATE:
1959
1960 switch ( operation )
1961 {
1962
1963 case CAMERA_STOP_PREVIEW:
1964 CAMHAL_LOGDB("Adapter state switch PREVIEW_STATE->INTIALIZED_STATE event = %s",
1965 printState);
1966 mNextState = INTIALIZED_STATE;
1967 break;
1968
1969 case CAMERA_PERFORM_AUTOFOCUS:
1970 CAMHAL_LOGDB("Adapter state switch PREVIEW_STATE->AF_STATE event = %s",
1971 printState);
1972 mNextState = AF_STATE;
1973 break;
1974
1975 case CAMERA_START_SMOOTH_ZOOM:
1976 CAMHAL_LOGDB("Adapter state switch PREVIEW_STATE->ZOOM_STATE event = %s",
1977 printState);
1978 mNextState = ZOOM_STATE;
1979 break;
1980
1981 case CAMERA_USE_BUFFERS_IMAGE_CAPTURE:
1982 CAMHAL_LOGDB("Adapter state switch PREVIEW_STATE->LOADED_CAPTURE_STATE event = %s",
1983 printState);
1984 mNextState = LOADED_CAPTURE_STATE;
1985 break;
1986
1987 #ifdef OMAP_ENHANCEMENT_CPCAM
1988 case CAMERA_USE_BUFFERS_REPROCESS:
1989 CAMHAL_LOGDB("Adapter state switch PREVIEW_STATE->LOADED_REPROCESS_STATE event = %s",
1990 printState);
1991 mNextState = LOADED_REPROCESS_STATE;
1992 break;
1993 #endif
1994
1995 case CAMERA_START_VIDEO:
1996 CAMHAL_LOGDB("Adapter state switch PREVIEW_STATE->VIDEO_STATE event = %s",
1997 printState);
1998 mNextState = VIDEO_STATE;
1999 break;
2000
2001 case CAMERA_CANCEL_AUTOFOCUS:
2002 case CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE:
2003 case CAMERA_STOP_SMOOTH_ZOOM:
2004 CAMHAL_LOGDB("Adapter state switch PREVIEW_ACTIVE->PREVIEW_ACTIVE event = %s",
2005 printState);
2006 mNextState = PREVIEW_STATE;
2007 break;
2008
2009 case CAMERA_STOP_IMAGE_CAPTURE:
2010 case CAMERA_STOP_BRACKET_CAPTURE:
2011 CAMHAL_LOGDB("Adapter state switch PREVIEW_ACTIVE->PREVIEW_ACTIVE event = %s",
2012 printState);
2013 ret = INVALID_OPERATION;
2014 break;
2015
2016 default:
2017 CAMHAL_LOGEB("Adapter state switch PREVIEW_ACTIVE Invalid Op! event = %s",
2018 printState);
2019 ret = INVALID_OPERATION;
2020 break;
2021
2022 }
2023
2024 break;
2025
2026 #ifdef OMAP_ENHANCEMENT_CPCAM
2027 case LOADED_REPROCESS_STATE:
2028 switch (operation) {
2029 case CAMERA_USE_BUFFERS_IMAGE_CAPTURE:
2030 CAMHAL_LOGDB("Adapter state switch LOADED_REPROCESS_STATE->LOADED_REPROCESS_CAPTURE_STATE event = %s",
2031 printState);
2032 mNextState = LOADED_REPROCESS_CAPTURE_STATE;
2033 break;
2034 case CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE:
2035 CAMHAL_LOGDB("Adapter state switch LOADED_REPROCESS_STATE->LOADED_REPROCESS_STATE event = %s",
2036 printState);
2037 mNextState = LOADED_REPROCESS_STATE;
2038 break;
2039 default:
2040 CAMHAL_LOGEB("Adapter state switch LOADED_REPROCESS_STATE Invalid Op! event = %s",
2041 printState);
2042 ret = INVALID_OPERATION;
2043 break;
2044 }
2045
2046 break;
2047
2048 case LOADED_REPROCESS_CAPTURE_STATE:
2049 switch (operation) {
2050 case CAMERA_START_IMAGE_CAPTURE:
2051 CAMHAL_LOGDB("Adapter state switch LOADED_REPROCESS_CAPTURE_STATE->REPROCESS_STATE event = %s",
2052 printState);
2053 mNextState = REPROCESS_STATE;
2054 break;
2055 default:
2056 CAMHAL_LOGEB("Adapter state switch LOADED_REPROCESS_CAPTURE_STATE Invalid Op! event = %s",
2057 printState);
2058 ret = INVALID_OPERATION;
2059 break;
2060 }
2061 break;
2062 #endif
2063
2064 case LOADED_CAPTURE_STATE:
2065
2066 switch ( operation )
2067 {
2068
2069 case CAMERA_START_IMAGE_CAPTURE:
2070 CAMHAL_LOGDB("Adapter state switch LOADED_CAPTURE_STATE->CAPTURE_STATE event = %s",
2071 printState);
2072 mNextState = CAPTURE_STATE;
2073 break;
2074
2075 case CAMERA_START_BRACKET_CAPTURE:
2076 CAMHAL_LOGDB("Adapter state switch LOADED_CAPTURE_STATE->BRACKETING_STATE event = %s",
2077 printState);
2078 mNextState = BRACKETING_STATE;
2079 break;
2080
2081 case CAMERA_USE_BUFFERS_VIDEO_CAPTURE:
2082 //Hadnle this state for raw capture path.
2083 //Just need to keep the same state.
2084 //The next CAMERA_START_IMAGE_CAPTURE command will assign the mNextState.
2085 CAMHAL_LOGDB("Adapter state switch LOADED_CAPTURE_STATE->LOADED_CAPTURE_STATE event = %s",
2086 printState);
2087 break;
2088
2089 default:
2090 CAMHAL_LOGEB("Adapter state switch LOADED_CAPTURE_STATE Invalid Op! event = %s",
2091 printState);
2092 ret = INVALID_OPERATION;
2093 break;
2094
2095 }
2096
2097 break;
2098
2099 case CAPTURE_STATE:
2100
2101 switch ( operation )
2102 {
2103 case CAMERA_STOP_IMAGE_CAPTURE:
2104 case CAMERA_STOP_BRACKET_CAPTURE:
2105 CAMHAL_LOGDB("Adapter state switch CAPTURE_STATE->PREVIEW_STATE event = %s",
2106 printState);
2107 mNextState = PREVIEW_STATE;
2108 break;
2109
2110 case CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE:
2111 case CAMERA_START_IMAGE_CAPTURE:
2112 CAMHAL_LOGDB("Adapter state switch CAPTURE_STATE->CAPTURE_STATE event = %s",
2113 printState);
2114 mNextState = CAPTURE_STATE;
2115 break;
2116
2117 #ifdef OMAP_ENHANCEMENT_CPCAM
2118 case CAMERA_USE_BUFFERS_REPROCESS:
2119 CAMHAL_LOGDB("Adapter state switch CAPTURE_STATE->->LOADED_REPROCESS_STATE event = %s",
2120 printState);
2121 mNextState = LOADED_REPROCESS_STATE;
2122 break;
2123 #endif
2124
2125 default:
2126 CAMHAL_LOGEB("Adapter state switch CAPTURE_STATE Invalid Op! event = %s",
2127 printState);
2128 ret = INVALID_OPERATION;
2129 break;
2130
2131 }
2132
2133 break;
2134
2135 case BRACKETING_STATE:
2136
2137 switch ( operation )
2138 {
2139
2140 case CAMERA_STOP_IMAGE_CAPTURE:
2141 case CAMERA_STOP_BRACKET_CAPTURE:
2142 CAMHAL_LOGDB("Adapter state switch BRACKETING_STATE->PREVIEW_STATE event = %s",
2143 printState);
2144 mNextState = PREVIEW_STATE;
2145 break;
2146
2147 case CAMERA_START_IMAGE_CAPTURE:
2148 CAMHAL_LOGDB("Adapter state switch BRACKETING_STATE->CAPTURE_STATE event = %s",
2149 printState);
2150 mNextState = CAPTURE_STATE;
2151 break;
2152
2153 default:
2154 CAMHAL_LOGEB("Adapter state switch BRACKETING_STATE Invalid Op! event = %s",
2155 printState);
2156 ret = INVALID_OPERATION;
2157 break;
2158
2159 }
2160
2161 break;
2162
2163 case AF_STATE:
2164
2165 switch ( operation )
2166 {
2167
2168 case CAMERA_CANCEL_AUTOFOCUS:
2169 CAMHAL_LOGDB("Adapter state switch AF_STATE->PREVIEW_STATE event = %s",
2170 printState);
2171 mNextState = PREVIEW_STATE;
2172 break;
2173
2174 case CAMERA_START_SMOOTH_ZOOM:
2175 CAMHAL_LOGDB("Adapter state switch AF_STATE->AF_ZOOM_STATE event = %s",
2176 printState);
2177 mNextState = AF_ZOOM_STATE;
2178 break;
2179
2180 default:
2181 CAMHAL_LOGEB("Adapter state switch AF_STATE Invalid Op! event = %s",
2182 printState);
2183 ret = INVALID_OPERATION;
2184 break;
2185
2186 }
2187
2188 break;
2189
2190 case ZOOM_STATE:
2191
2192 switch ( operation )
2193 {
2194
2195 case CAMERA_CANCEL_AUTOFOCUS:
2196 CAMHAL_LOGDB("Adapter state switch AF_STATE->PREVIEW_STATE event = %s",
2197 printState);
2198 mNextState = ZOOM_STATE;
2199 break;
2200
2201 case CAMERA_STOP_SMOOTH_ZOOM:
2202 CAMHAL_LOGDB("Adapter state switch ZOOM_STATE->PREVIEW_STATE event = %s",
2203 printState);
2204 mNextState = PREVIEW_STATE;
2205 break;
2206
2207 case CAMERA_PERFORM_AUTOFOCUS:
2208 CAMHAL_LOGDB("Adapter state switch ZOOM_STATE->AF_ZOOM_STATE event = %s",
2209 printState);
2210 mNextState = AF_ZOOM_STATE;
2211 break;
2212
2213 case CAMERA_START_VIDEO:
2214 CAMHAL_LOGDB("Adapter state switch ZOOM_STATE->VIDEO_ZOOM_STATE event = %s",
2215 printState);
2216 mNextState = VIDEO_ZOOM_STATE;
2217 break;
2218
2219 default:
2220 CAMHAL_LOGEB("Adapter state switch ZOOM_STATE Invalid Op! event = %s",
2221 printState);
2222 ret = INVALID_OPERATION;
2223 break;
2224
2225 }
2226
2227 break;
2228
2229 case VIDEO_STATE:
2230
2231 switch ( operation )
2232 {
2233
2234 case CAMERA_STOP_VIDEO:
2235 CAMHAL_LOGDB("Adapter state switch VIDEO_STATE->PREVIEW_STATE event = %s",
2236 printState);
2237 mNextState = PREVIEW_STATE;
2238 break;
2239
2240 case CAMERA_PERFORM_AUTOFOCUS:
2241 CAMHAL_LOGDB("Adapter state switch VIDEO_STATE->VIDEO_AF_STATE event = %s",
2242 printState);
2243 mNextState = VIDEO_AF_STATE;
2244 break;
2245
2246 case CAMERA_START_SMOOTH_ZOOM:
2247 CAMHAL_LOGDB("Adapter state switch VIDEO_STATE->VIDEO_ZOOM_STATE event = %s",
2248 printState);
2249 mNextState = VIDEO_ZOOM_STATE;
2250 break;
2251
2252 case CAMERA_USE_BUFFERS_IMAGE_CAPTURE:
2253 CAMHAL_LOGDB("Adapter state switch VIDEO_STATE->VIDEO_LOADED_CAPTURE_STATE event = %s",
2254 printState);
2255 mNextState = VIDEO_LOADED_CAPTURE_STATE;
2256 break;
2257
2258 case CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE:
2259 CAMHAL_LOGDB("Adapter state switch VIDEO_STATE->VIDEO_STATE event = %s",
2260 printState);
2261 mNextState = VIDEO_STATE;
2262 break;
2263
2264 default:
2265 CAMHAL_LOGEB("Adapter state switch VIDEO_STATE Invalid Op! event = %s",
2266 printState);
2267 ret = INVALID_OPERATION;
2268 break;
2269
2270 }
2271
2272 break;
2273
2274 case VIDEO_AF_STATE:
2275
2276 switch ( operation )
2277 {
2278
2279 case CAMERA_CANCEL_AUTOFOCUS:
2280 CAMHAL_LOGDB("Adapter state switch VIDEO_AF_STATE->VIDEO_STATE event = %s",
2281 printState);
2282 mNextState = VIDEO_STATE;
2283 break;
2284
2285 default:
2286 CAMHAL_LOGEB("Adapter state switch VIDEO_AF_STATE Invalid Op! event = %s",
2287 printState);
2288 ret = INVALID_OPERATION;
2289 break;
2290
2291 }
2292
2293 break;
2294
2295 case VIDEO_LOADED_CAPTURE_STATE:
2296
2297 switch ( operation )
2298 {
2299
2300 case CAMERA_START_IMAGE_CAPTURE:
2301 CAMHAL_LOGDB("Adapter state switch LOADED_CAPTURE_STATE->CAPTURE_STATE event = %s",
2302 printState);
2303 mNextState = VIDEO_CAPTURE_STATE;
2304 break;
2305
2306 default:
2307 CAMHAL_LOGEB("Adapter state switch LOADED_CAPTURE_STATE Invalid Op! event = %s",
2308 printState);
2309 ret = INVALID_OPERATION;
2310 break;
2311
2312 }
2313
2314 break;
2315
2316 case VIDEO_CAPTURE_STATE:
2317
2318 switch ( operation )
2319 {
2320 case CAMERA_STOP_IMAGE_CAPTURE:
2321 CAMHAL_LOGDB("Adapter state switch CAPTURE_STATE->PREVIEW_STATE event = %s",
2322 printState);
2323 mNextState = VIDEO_STATE;
2324 break;
2325
2326 default:
2327 CAMHAL_LOGEB("Adapter state switch CAPTURE_STATE Invalid Op! event = %s",
2328 printState);
2329 ret = INVALID_OPERATION;
2330 break;
2331
2332 }
2333
2334 break;
2335
2336 case AF_ZOOM_STATE:
2337
2338 switch ( operation )
2339 {
2340
2341 case CAMERA_STOP_SMOOTH_ZOOM:
2342 CAMHAL_LOGDB("Adapter state switch AF_ZOOM_STATE->AF_STATE event = %s",
2343 printState);
2344 mNextState = AF_STATE;
2345 break;
2346
2347 case CAMERA_CANCEL_AUTOFOCUS:
2348 CAMHAL_LOGDB("Adapter state switch AF_ZOOM_STATE->ZOOM_STATE event = %s",
2349 printState);
2350 mNextState = ZOOM_STATE;
2351 break;
2352
2353 default:
2354 CAMHAL_LOGEB("Adapter state switch AF_ZOOM_STATE Invalid Op! event = %s",
2355 printState);
2356 ret = INVALID_OPERATION;
2357 break;
2358
2359 }
2360
2361 break;
2362
2363 case VIDEO_ZOOM_STATE:
2364
2365 switch ( operation )
2366 {
2367
2368 case CAMERA_STOP_SMOOTH_ZOOM:
2369 CAMHAL_LOGDB("Adapter state switch VIDEO_ZOOM_STATE->VIDEO_STATE event = %s",
2370 printState);
2371 mNextState = VIDEO_STATE;
2372 break;
2373
2374 case CAMERA_STOP_VIDEO:
2375 CAMHAL_LOGDB("Adapter state switch VIDEO_ZOOM_STATE->ZOOM_STATE event = %s",
2376 printState);
2377 mNextState = ZOOM_STATE;
2378 break;
2379
2380 default:
2381 CAMHAL_LOGEB("Adapter state switch VIDEO_ZOOM_STATE Invalid Op! event = %s",
2382 printState);
2383 ret = INVALID_OPERATION;
2384 break;
2385
2386 }
2387
2388 break;
2389
2390 case BRACKETING_ZOOM_STATE:
2391
2392 switch ( operation )
2393 {
2394
2395 case CAMERA_STOP_SMOOTH_ZOOM:
2396 CAMHAL_LOGDB("Adapter state switch BRACKETING_ZOOM_STATE->BRACKETING_STATE event = %s",
2397 printState);
2398 mNextState = BRACKETING_STATE;
2399 break;
2400
2401 default:
2402 CAMHAL_LOGEB("Adapter state switch BRACKETING_ZOOM_STATE Invalid Op! event = %s",
2403 printState);
2404 ret = INVALID_OPERATION;
2405 break;
2406
2407 }
2408
2409 break;
2410
2411 #ifdef OMAP_ENHANCEMENT_CPCAM
2412 case REPROCESS_STATE:
2413 switch (operation) {
2414 case CAMERA_STOP_IMAGE_CAPTURE:
2415 CAMHAL_LOGDB("Adapter state switch REPROCESS_STATE->PREVIEW_STATE event = %s",
2416 printState);
2417 mNextState = PREVIEW_STATE;
2418 break;
2419 case CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE:
2420 case CAMERA_START_IMAGE_CAPTURE:
2421 CAMHAL_LOGDB("Adapter state switch REPROCESS_STATE->REPROCESS_STATE event = %s",
2422 printState);
2423 mNextState = REPROCESS_STATE;
2424 break;
2425 case CAMERA_USE_BUFFERS_REPROCESS:
2426 CAMHAL_LOGDB("Adapter state switch REPROCESS_STATE->REPROCESS_STATE event = %s",
2427 printState);
2428 mNextState = LOADED_REPROCESS_STATE;
2429 break;
2430
2431 case CAMERA_USE_BUFFERS_IMAGE_CAPTURE:
2432 CAMHAL_LOGDB("Adapter state switch REPROCESS_STATE->LOADED_CAPTURE_STATE event = %s",
2433 printState);
2434 mNextState = LOADED_CAPTURE_STATE;
2435 break;
2436 default:
2437 CAMHAL_LOGEB("Adapter state switch REPROCESS_STATE Invalid Op! event = %s",
2438 printState);
2439 ret = INVALID_OPERATION;
2440 break;
2441
2442 }
2443
2444 break;
2445 #endif
2446
2447
2448 default:
2449 CAMHAL_LOGEA("Invalid Adapter state!");
2450 ret = INVALID_OPERATION;
2451 }
2452
2453 LOG_FUNCTION_NAME_EXIT;
2454
2455 return ret;
2456 }
2457
rollbackToInitializedState()2458 status_t BaseCameraAdapter::rollbackToInitializedState()
2459 {
2460 status_t ret = NO_ERROR;
2461
2462 LOG_FUNCTION_NAME;
2463
2464 while ((getState() != INTIALIZED_STATE) && (ret == NO_ERROR)) {
2465 ret = rollbackToPreviousState();
2466 }
2467
2468 LOG_FUNCTION_NAME_EXIT;
2469
2470 return ret;
2471 }
2472
rollbackToPreviousState()2473 status_t BaseCameraAdapter::rollbackToPreviousState()
2474 {
2475 status_t ret = NO_ERROR;
2476
2477 LOG_FUNCTION_NAME;
2478
2479 CameraAdapter::AdapterState currentState = getState();
2480
2481 switch (currentState) {
2482 case INTIALIZED_STATE:
2483 return NO_ERROR;
2484
2485 case PREVIEW_STATE:
2486 ret = sendCommand(CAMERA_STOP_PREVIEW);
2487 break;
2488
2489 case CAPTURE_STATE:
2490 #ifdef OMAP_ENHANCEMENT_CPCAM
2491 case REPROCESS_STATE:
2492 #endif
2493 ret = sendCommand(CAMERA_STOP_IMAGE_CAPTURE);
2494 break;
2495
2496 case BRACKETING_STATE:
2497 ret = sendCommand(CAMERA_STOP_BRACKET_CAPTURE);
2498 break;
2499
2500 case AF_STATE:
2501 ret = sendCommand(CAMERA_CANCEL_AUTOFOCUS);
2502 break;
2503
2504 case ZOOM_STATE:
2505 ret = sendCommand(CAMERA_STOP_SMOOTH_ZOOM);
2506 break;
2507
2508 case VIDEO_STATE:
2509 ret = sendCommand(CAMERA_STOP_VIDEO);
2510 break;
2511
2512 case VIDEO_AF_STATE:
2513 ret = sendCommand(CAMERA_CANCEL_AUTOFOCUS);
2514 break;
2515
2516 case VIDEO_CAPTURE_STATE:
2517 ret = sendCommand(CAMERA_STOP_IMAGE_CAPTURE);
2518 break;
2519
2520 case AF_ZOOM_STATE:
2521 ret = sendCommand(CAMERA_STOP_SMOOTH_ZOOM);
2522 break;
2523
2524 case VIDEO_ZOOM_STATE:
2525 ret = sendCommand(CAMERA_STOP_SMOOTH_ZOOM);
2526 break;
2527
2528 case BRACKETING_ZOOM_STATE:
2529 ret = sendCommand(CAMERA_STOP_SMOOTH_ZOOM);
2530 break;
2531
2532 default:
2533 CAMHAL_LOGEA("Invalid Adapter state!");
2534 ret = INVALID_OPERATION;
2535 }
2536
2537 LOG_FUNCTION_NAME_EXIT;
2538
2539 return ret;
2540 }
2541
2542 //State transition finished successfully.
2543 //Commit the state and unlock the adapter state.
commitState()2544 status_t BaseCameraAdapter::commitState()
2545 {
2546 status_t ret = NO_ERROR;
2547
2548 LOG_FUNCTION_NAME;
2549
2550 mAdapterState = mNextState;
2551
2552 mLock.unlock();
2553
2554 LOG_FUNCTION_NAME_EXIT;
2555
2556 return ret;
2557 }
2558
rollbackState()2559 status_t BaseCameraAdapter::rollbackState()
2560 {
2561 status_t ret = NO_ERROR;
2562
2563 LOG_FUNCTION_NAME;
2564
2565 mNextState = mAdapterState;
2566
2567 mLock.unlock();
2568
2569 LOG_FUNCTION_NAME_EXIT;
2570
2571 return ret;
2572 }
2573
2574 // getNextState() and getState()
2575 // publicly exposed functions to retrieve the adapter states
2576 // please notice that these functions are locked
getState()2577 CameraAdapter::AdapterState BaseCameraAdapter::getState()
2578 {
2579 status_t ret = NO_ERROR;
2580
2581 LOG_FUNCTION_NAME;
2582
2583 android::AutoMutex lock(mLock);
2584
2585 LOG_FUNCTION_NAME_EXIT;
2586
2587 return mAdapterState;
2588 }
2589
getNextState()2590 CameraAdapter::AdapterState BaseCameraAdapter::getNextState()
2591 {
2592 status_t ret = NO_ERROR;
2593
2594 LOG_FUNCTION_NAME;
2595
2596 android::AutoMutex lock(mLock);
2597
2598 LOG_FUNCTION_NAME_EXIT;
2599
2600 return mNextState;
2601 }
2602
2603 // getNextState() and getState()
2604 // internal protected functions to retrieve the adapter states
2605 // please notice that these functions are NOT locked to help
2606 // internal functions query state in the middle of state
2607 // transition
getState(AdapterState & state)2608 status_t BaseCameraAdapter::getState(AdapterState &state)
2609 {
2610 status_t ret = NO_ERROR;
2611
2612 LOG_FUNCTION_NAME;
2613
2614 state = mAdapterState;
2615
2616 LOG_FUNCTION_NAME_EXIT;
2617
2618 return ret;
2619 }
2620
getNextState(AdapterState & state)2621 status_t BaseCameraAdapter::getNextState(AdapterState &state)
2622 {
2623 status_t ret = NO_ERROR;
2624
2625 LOG_FUNCTION_NAME;
2626
2627 state = mNextState;
2628
2629 LOG_FUNCTION_NAME_EXIT;
2630
2631 return ret;
2632 }
2633
onOrientationEvent(uint32_t orientation,uint32_t tilt)2634 void BaseCameraAdapter::onOrientationEvent(uint32_t orientation, uint32_t tilt)
2635 {
2636 LOG_FUNCTION_NAME;
2637 LOG_FUNCTION_NAME_EXIT;
2638 }
2639
2640 //-----------------------------------------------------------------------------
2641
2642 extern "C" status_t OMXCameraAdapter_Capabilities(
2643 CameraProperties::Properties * const properties_array,
2644 const int starting_camera, const int max_camera, int & supportedCameras);
2645 extern "C" status_t V4LCameraAdapter_Capabilities(
2646 CameraProperties::Properties * const properties_array,
2647 const int starting_camera, const int max_camera, int & supportedCameras);
2648
CameraAdapter_Capabilities(CameraProperties::Properties * const properties_array,const int starting_camera,const int max_camera,int & supportedCameras)2649 extern "C" status_t CameraAdapter_Capabilities(
2650 CameraProperties::Properties * const properties_array,
2651 const int starting_camera, const int max_camera, int & supportedCameras)
2652 {
2653
2654 status_t ret = NO_ERROR;
2655 status_t err = NO_ERROR;
2656 int num_cameras_supported = 0;
2657
2658 LOG_FUNCTION_NAME;
2659
2660 supportedCameras = 0;
2661 #ifdef OMX_CAMERA_ADAPTER
2662 //Query OMX cameras
2663 err = OMXCameraAdapter_Capabilities( properties_array, starting_camera,
2664 max_camera, supportedCameras);
2665 if(err != NO_ERROR) {
2666 CAMHAL_LOGEA("error while getting OMXCameraAdapter capabilities");
2667 ret = UNKNOWN_ERROR;
2668 }
2669 #endif
2670 #ifdef V4L_CAMERA_ADAPTER
2671 //Query V4L cameras
2672 err = V4LCameraAdapter_Capabilities( properties_array, (const int) supportedCameras,
2673 max_camera, num_cameras_supported);
2674 if(err != NO_ERROR) {
2675 CAMHAL_LOGEA("error while getting V4LCameraAdapter capabilities");
2676 ret = UNKNOWN_ERROR;
2677 }
2678 #endif
2679
2680 supportedCameras += num_cameras_supported;
2681 CAMHAL_LOGEB("supportedCameras= %d\n", supportedCameras);
2682 LOG_FUNCTION_NAME_EXIT;
2683 return ret;
2684 }
2685
2686 //-----------------------------------------------------------------------------
2687
2688 } // namespace Camera
2689 } // namespace Ti
2690
2691 /*--------------------Camera Adapter Class ENDS here-----------------------------*/
2692
2693