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