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 #ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_H
20 #define ANDROID_HARDWARE_CAMERA_HARDWARE_H
21
22 #include <stdio.h>
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <time.h>
28 #include <fcntl.h>
29 #include <sys/ioctl.h>
30 #include <sys/mman.h>
31 #include <sys/stat.h>
32
33 #include <hardware/camera.h>
34 #include <utils/Log.h>
35 #include <utils/threads.h>
36 #include <utils/threads.h>
37 #include <binder/MemoryBase.h>
38 #include <binder/MemoryHeapBase.h>
39 #include <camera/CameraParameters.h>
40 #ifdef OMAP_ENHANCEMENT_CPCAM
41 #include <camera/CameraMetadata.h>
42 #include <camera/ShotParameters.h>
43 #endif
44 #include <ui/GraphicBufferAllocator.h>
45 #include <ui/GraphicBuffer.h>
46
47 /* For IMG_native_handle_t */
48 #include <ui/GraphicBufferMapper.h>
49 #include <hal_public.h>
50
51 #include <ion/ion.h>
52
53 #include "Common.h"
54 #include "MessageQueue.h"
55 #include "Semaphore.h"
56 #include "CameraProperties.h"
57 #include "SensorListener.h"
58
59 //temporarily define format here
60 #define HAL_PIXEL_FORMAT_TI_NV12 0x100
61 #define HAL_PIXEL_FORMAT_TI_Y8 0x103
62 #define HAL_PIXEL_FORMAT_TI_Y16 0x104
63 #define HAL_PIXEL_FORMAT_TI_UYVY 0x105
64
65 #define MIN_WIDTH 640
66 #define MIN_HEIGHT 480
67 #define PICTURE_WIDTH 3264 /* 5mp - 2560. 8mp - 3280 */ /* Make sure it is a multiple of 16. */
68 #define PICTURE_HEIGHT 2448 /* 5mp - 2048. 8mp - 2464 */ /* Make sure it is a multiple of 16. */
69 #define PREVIEW_WIDTH 176
70 #define PREVIEW_HEIGHT 144
71 #define PIXEL_FORMAT V4L2_PIX_FMT_UYVY
72
73 #define VIDEO_FRAME_COUNT_MAX 8 //NUM_OVERLAY_BUFFERS_REQUESTED
74 #define MAX_CAMERA_BUFFERS 8 //NUM_OVERLAY_BUFFERS_REQUESTED
75 #define MAX_ZOOM 3
76 #define THUMB_WIDTH 80
77 #define THUMB_HEIGHT 60
78 #define PIX_YUV422I 0
79 #define PIX_YUV420P 1
80
81 #define SATURATION_OFFSET 100
82 #define SHARPNESS_OFFSET 100
83 #define CONTRAST_OFFSET 100
84
85 #define FRAME_RATE_HIGH_HD 60
86
87 #define CAMHAL_GRALLOC_USAGE GRALLOC_USAGE_HW_TEXTURE | \
88 GRALLOC_USAGE_HW_RENDER | \
89 GRALLOC_USAGE_SW_READ_RARELY | \
90 GRALLOC_USAGE_SW_WRITE_NEVER
91
92 //Enables Absolute PPM measurements in logcat
93 #define PPM_INSTRUMENTATION_ABS 1
94
95 #define LOCK_BUFFER_TRIES 5
96 #define HAL_PIXEL_FORMAT_NV12 0x100
97
98 #define OP_STR_SIZE 100
99
100 #define NONNEG_ASSIGN(x,y) \
101 if(x > -1) \
102 y = x
103
104 #define CAMHAL_SIZE_OF_ARRAY(x) static_cast<int>(sizeof(x)/sizeof(x[0]))
105
106 namespace Ti {
107 namespace Camera {
108
109 #ifdef CAMERAHAL_USE_RAW_IMAGE_SAVING
110 extern const char * const kRawImagesOutputDirPath;
111 extern const char * const kYuvImagesOutputDirPath;
112 #endif
113 #define V4L_CAMERA_NAME_USB "USBCAMERA"
114 #define OMX_CAMERA_NAME_OV "OV5640"
115 #define OMX_CAMERA_NAME_SONY "IMX060"
116
117
118 ///Forward declarations
119 class CameraHal;
120 class CameraFrame;
121 class CameraHalEvent;
122 class DisplayFrame;
123
124 class FpsRange {
125 public:
126 static int compare(const FpsRange * left, const FpsRange * right);
127
128 FpsRange(int min, int max);
129 FpsRange();
130
131 bool operator==(const FpsRange & fpsRange) const;
132
133 bool isNull() const;
134 bool isFixed() const;
135
136 int min() const;
137 int max() const;
138
139 private:
140 int mMin;
141 int mMax;
142 };
143
144
compare(const FpsRange * const left,const FpsRange * const right)145 inline int FpsRange::compare(const FpsRange * const left, const FpsRange * const right) {
146 if ( left->max() < right->max() ) {
147 return -1;
148 }
149
150 if ( left->max() > right->max() ) {
151 return 1;
152 }
153
154 if ( left->min() < right->min() ) {
155 return -1;
156 }
157
158 if ( left->min() > right->min() ) {
159 return 1;
160 }
161
162 return 0;
163 }
164
FpsRange(const int min,const int max)165 inline FpsRange::FpsRange(const int min, const int max) : mMin(min), mMax(max) {}
166
FpsRange()167 inline FpsRange::FpsRange() : mMin(-1), mMax(-1) {}
168
169 inline bool FpsRange::operator==(const FpsRange & fpsRange) const {
170 return mMin == fpsRange.mMin && mMax == fpsRange.mMax;
171 }
172
isNull()173 inline bool FpsRange::isNull() const {
174 return mMin == -1 || mMax == -1;
175 }
176
isFixed()177 inline bool FpsRange::isFixed() const {
178 return mMin == mMax;
179 }
180
min()181 inline int FpsRange::min() const { return mMin; }
182
max()183 inline int FpsRange::max() const { return mMax; }
184
185 class CameraArea : public android::RefBase
186 {
187 public:
188
CameraArea(ssize_t top,ssize_t left,ssize_t bottom,ssize_t right,size_t weight)189 CameraArea(ssize_t top,
190 ssize_t left,
191 ssize_t bottom,
192 ssize_t right,
193 size_t weight) : mTop(top),
194 mLeft(left),
195 mBottom(bottom),
196 mRight(right),
197 mWeight(weight) {}
198
199 status_t transfrom(size_t width,
200 size_t height,
201 size_t &top,
202 size_t &left,
203 size_t &areaWidth,
204 size_t &areaHeight);
205
isValid()206 bool isValid()
207 {
208 return ( ( 0 != mTop ) || ( 0 != mLeft ) || ( 0 != mBottom ) || ( 0 != mRight) );
209 }
210
isZeroArea()211 bool isZeroArea()
212 {
213 return ( (0 == mTop ) && ( 0 == mLeft ) && ( 0 == mBottom )
214 && ( 0 == mRight ) && ( 0 == mWeight ));
215 }
216
getWeight()217 size_t getWeight()
218 {
219 return mWeight;
220 }
221
222 bool compare(const android::sp<CameraArea> &area);
223
224 static status_t parseAreas(const char *area,
225 size_t areaLength,
226 android::Vector< android::sp<CameraArea> > &areas);
227
228 static status_t checkArea(ssize_t top,
229 ssize_t left,
230 ssize_t bottom,
231 ssize_t right,
232 ssize_t weight);
233
234 static bool areAreasDifferent(android::Vector< android::sp<CameraArea> > &, android::Vector< android::sp<CameraArea> > &);
235
236 protected:
237 static const ssize_t TOP = -1000;
238 static const ssize_t LEFT = -1000;
239 static const ssize_t BOTTOM = 1000;
240 static const ssize_t RIGHT = 1000;
241 static const ssize_t WEIGHT_MIN = 1;
242 static const ssize_t WEIGHT_MAX = 1000;
243
244 ssize_t mTop;
245 ssize_t mLeft;
246 ssize_t mBottom;
247 ssize_t mRight;
248 size_t mWeight;
249 };
250
251 class CameraMetadataResult : public android::RefBase
252 {
253 public:
254
255 #ifdef OMAP_ENHANCEMENT_CPCAM
CameraMetadataResult(camera_memory_t * extMeta)256 CameraMetadataResult(camera_memory_t * extMeta) : mExtendedMetadata(extMeta) {
257 mMetadata.faces = NULL;
258 mMetadata.number_of_faces = 0;
259 #ifdef OMAP_ENHANCEMENT
260 mMetadata.analog_gain = 0;
261 mMetadata.exposure_time = 0;
262 #endif
263 };
264 #endif
265
CameraMetadataResult()266 CameraMetadataResult() {
267 mMetadata.faces = NULL;
268 mMetadata.number_of_faces = 0;
269 #ifdef OMAP_ENHANCEMENT_CPCAM
270 mMetadata.analog_gain = 0;
271 mMetadata.exposure_time = 0;
272 #endif
273
274 #ifdef OMAP_ENHANCEMENT_CPCAM
275 mExtendedMetadata = NULL;
276 #endif
277 }
278
~CameraMetadataResult()279 virtual ~CameraMetadataResult() {
280 if ( NULL != mMetadata.faces ) {
281 free(mMetadata.faces);
282 }
283 #ifdef OMAP_ENHANCEMENT_CPCAM
284 if ( NULL != mExtendedMetadata ) {
285 mExtendedMetadata->release(mExtendedMetadata);
286 }
287 #endif
288 }
289
getMetadataResult()290 camera_frame_metadata_t *getMetadataResult() { return &mMetadata; };
291
292 #ifdef OMAP_ENHANCEMENT_CPCAM
getExtendedMetadata()293 camera_memory_t *getExtendedMetadata() { return mExtendedMetadata; };
294 #endif
295
296 static const ssize_t TOP = -1000;
297 static const ssize_t LEFT = -1000;
298 static const ssize_t BOTTOM = 1000;
299 static const ssize_t RIGHT = 1000;
300 static const ssize_t INVALID_DATA = -2000;
301
302 private:
303
304 camera_frame_metadata_t mMetadata;
305 #ifdef OMAP_ENHANCEMENT_CPCAM
306 camera_memory_t *mExtendedMetadata;
307 #endif
308 };
309
310 typedef enum {
311 CAMERA_BUFFER_NONE = 0,
312 CAMERA_BUFFER_GRALLOC,
313 CAMERA_BUFFER_ANW,
314 CAMERA_BUFFER_MEMORY,
315 CAMERA_BUFFER_ION
316 } CameraBufferType;
317
318 typedef struct _CameraBuffer {
319 CameraBufferType type;
320 /* opaque is the generic drop-in replacement for the pointers
321 * that were used previously */
322 void *opaque;
323
324 /* opaque has different meanings depending on the buffer type:
325 * GRALLOC - gralloc_handle_t
326 * ANW - a pointer to the buffer_handle_t (which corresponds to
327 * the ANativeWindowBuffer *)
328 * MEMORY - address of allocated memory
329 * ION - address of mapped ion allocation
330 *
331 * FIXME opaque should be split into several fields:
332 * - handle/pointer we got from the allocator
333 * - handle/value we pass to OMX
334 * - pointer to mapped memory (if the buffer is mapped)
335 */
336
337 /* mapped holds ptr to mapped memory in userspace */
338 void *mapped;
339
340 /* These are specific to ION buffers */
341 struct ion_handle * ion_handle;
342 int ion_fd;
343 int fd;
344 size_t size;
345 int index;
346
347 /* These describe the camera buffer */
348 int width;
349 int stride;
350 int height;
351 const char *format;
352
353 #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
354
355 struct timeval ppmStamp;
356
357 #endif
358
359 /* These are for buffers which include borders */
360 int offset; // where valid data starts
361 int actual_size; // size of the entire buffer with borders
362 } CameraBuffer;
363
364 void * camera_buffer_get_omx_ptr (CameraBuffer *buffer);
365
366 class CameraFrame
367 {
368 public:
369
370 enum FrameType
371 {
372 PREVIEW_FRAME_SYNC = 0x1, ///SYNC implies that the frame needs to be explicitly returned after consuming in order to be filled by camera again
373 PREVIEW_FRAME = 0x2 , ///Preview frame includes viewfinder and snapshot frames
374 IMAGE_FRAME_SYNC = 0x4, ///Image Frame is the image capture output frame
375 IMAGE_FRAME = 0x8,
376 VIDEO_FRAME_SYNC = 0x10, ///Timestamp will be updated for these frames
377 VIDEO_FRAME = 0x20,
378 FRAME_DATA_SYNC = 0x40, ///Any extra data assosicated with the frame. Always synced with the frame
379 FRAME_DATA= 0x80,
380 RAW_FRAME = 0x100,
381 SNAPSHOT_FRAME = 0x200,
382 REPROCESS_INPUT_FRAME = 0x400,
383 ALL_FRAMES = 0xFFFF ///Maximum of 16 frame types supported
384 };
385
386 enum FrameQuirks
387 {
388 ENCODE_RAW_YUV422I_TO_JPEG = 0x1 << 0,
389 HAS_EXIF_DATA = 0x1 << 1,
390 FORMAT_YUV422I_YUYV = 0x1 << 2,
391 FORMAT_YUV422I_UYVY = 0x1 << 3,
392 };
393
394 //default contrustor
CameraFrame()395 CameraFrame():
396 mCookie(NULL),
397 mCookie2(NULL),
398 mBuffer(NULL),
399 mFrameType(0),
400 mTimestamp(0),
401 mWidth(0),
402 mHeight(0),
403 mOffset(0),
404 mAlignment(0),
405 mFd(0),
406 mLength(0),
407 mFrameMask(0),
408 mQuirks(0)
409 {
410 mYuv[0] = 0;
411 mYuv[1] = 0;
412
413 #ifdef OMAP_ENHANCEMENT_CPCAM
414 mMetaData = 0;
415 #endif
416 }
417
418 void *mCookie;
419 void *mCookie2;
420 CameraBuffer *mBuffer;
421 int mFrameType;
422 nsecs_t mTimestamp;
423 unsigned int mWidth, mHeight;
424 uint32_t mOffset;
425 unsigned int mAlignment;
426 int mFd;
427 size_t mLength;
428 unsigned mFrameMask;
429 unsigned int mQuirks;
430 unsigned int mYuv[2];
431 #ifdef OMAP_ENHANCEMENT_CPCAM
432 android::sp<CameraMetadataResult> mMetaData;
433 #endif
434 ///@todo add other member vars like stride etc
435 };
436
437 enum CameraHalError
438 {
439 CAMERA_ERROR_FATAL = 0x1, //Fatal errors can only be recovered by restarting media server
440 CAMERA_ERROR_HARD = 0x2, // Hard errors are hardware hangs that may be recoverable by resetting the hardware internally within the adapter
441 CAMERA_ERROR_SOFT = 0x4, // Soft errors are non fatal errors that can be recovered from without needing to stop use-case
442 };
443
444 ///Common Camera Hal Event class which is visible to CameraAdapter,DisplayAdapter and AppCallbackNotifier
445 ///@todo Rename this class to CameraEvent
446 class CameraHalEvent
447 {
448 public:
449 //Enums
450 enum CameraHalEventType {
451 NO_EVENTS = 0x0,
452 EVENT_FOCUS_LOCKED = 0x1,
453 EVENT_FOCUS_ERROR = 0x2,
454 EVENT_ZOOM_INDEX_REACHED = 0x4,
455 EVENT_SHUTTER = 0x8,
456 EVENT_METADATA = 0x10,
457 ///@remarks Future enum related to display, like frame displayed event, could be added here
458 ALL_EVENTS = 0xFFFF ///Maximum of 16 event types supported
459 };
460
461 enum FocusStatus {
462 FOCUS_STATUS_SUCCESS = 0x1,
463 FOCUS_STATUS_FAIL = 0x2,
464 FOCUS_STATUS_PENDING = 0x4,
465 FOCUS_STATUS_DONE = 0x8,
466 };
467
468 ///Class declarations
469 ///@remarks Add a new class for a new event type added above
470
471 //Shutter event specific data
472 typedef struct ShutterEventData_t {
473 bool shutterClosed;
474 }ShutterEventData;
475
476 ///Focus event specific data
477 typedef struct FocusEventData_t {
478 FocusStatus focusStatus;
479 int currentFocusValue;
480 } FocusEventData;
481
482 ///Zoom specific event data
483 typedef struct ZoomEventData_t {
484 int currentZoomIndex;
485 bool targetZoomIndexReached;
486 } ZoomEventData;
487
488 typedef struct FaceData_t {
489 ssize_t top;
490 ssize_t left;
491 ssize_t bottom;
492 ssize_t right;
493 size_t score;
494 } FaceData;
495
496 typedef android::sp<CameraMetadataResult> MetaEventData;
497
498 class CameraHalEventData : public android::RefBase{
499
500 public:
501
502 CameraHalEvent::FocusEventData focusEvent;
503 CameraHalEvent::ZoomEventData zoomEvent;
504 CameraHalEvent::ShutterEventData shutterEvent;
505 CameraHalEvent::MetaEventData metadataEvent;
506 };
507
508 //default contrustor
CameraHalEvent()509 CameraHalEvent():
510 mCookie(NULL),
511 mEventType(NO_EVENTS) {}
512
513 //copy constructor
CameraHalEvent(const CameraHalEvent & event)514 CameraHalEvent(const CameraHalEvent &event) :
515 mCookie(event.mCookie),
516 mEventType(event.mEventType),
517 mEventData(event.mEventData) {};
518
519 void* mCookie;
520 CameraHalEventType mEventType;
521 android::sp<CameraHalEventData> mEventData;
522
523 };
524
525 /// Have a generic callback class based on template - to adapt CameraFrame and Event
526 typedef void (*frame_callback) (CameraFrame *cameraFrame);
527 typedef void (*event_callback) (CameraHalEvent *event);
528
529 //signals CameraHAL to relase image buffers
530 typedef void (*release_image_buffers_callback) (void *userData);
531 typedef void (*end_image_capture_callback) (void *userData);
532
533 /**
534 * Interface class implemented by classes that have some events to communicate to dependendent classes
535 * Dependent classes use this interface for registering for events
536 */
537 class MessageNotifier
538 {
539 public:
540 static const uint32_t EVENT_BIT_FIELD_POSITION;
541 static const uint32_t FRAME_BIT_FIELD_POSITION;
542
543 ///@remarks Msg type comes from CameraFrame and CameraHalEvent classes
544 /// MSB 16 bits is for events and LSB 16 bits is for frame notifications
545 /// FrameProvider and EventProvider classes act as helpers to event/frame
546 /// consumers to call this api
547 virtual void enableMsgType(int32_t msgs, frame_callback frameCb=NULL, event_callback eventCb=NULL, void* cookie=NULL) = 0;
548 virtual void disableMsgType(int32_t msgs, void* cookie) = 0;
549
~MessageNotifier()550 virtual ~MessageNotifier() {};
551 };
552
553 class ErrorNotifier : public virtual android::RefBase
554 {
555 public:
556 virtual void errorNotify(int error) = 0;
557
~ErrorNotifier()558 virtual ~ErrorNotifier() {};
559 };
560
561
562 /**
563 * Interace class abstraction for Camera Adapter to act as a frame provider
564 * This interface is fully implemented by Camera Adapter
565 */
566 class FrameNotifier : public MessageNotifier
567 {
568 public:
569 virtual void returnFrame(CameraBuffer* frameBuf, CameraFrame::FrameType frameType) = 0;
570 virtual void addFramePointers(CameraBuffer *frameBuf, void *buf) = 0;
571 virtual void removeFramePointers() = 0;
572
~FrameNotifier()573 virtual ~FrameNotifier() {};
574 };
575
576 /** * Wrapper class around Frame Notifier, which is used by display and notification classes for interacting with Camera Adapter
577 */
578 class FrameProvider
579 {
580 FrameNotifier* mFrameNotifier;
581 void* mCookie;
582 frame_callback mFrameCallback;
583
584 public:
FrameProvider(FrameNotifier * fn,void * cookie,frame_callback frameCallback)585 FrameProvider(FrameNotifier *fn, void* cookie, frame_callback frameCallback)
586 :mFrameNotifier(fn), mCookie(cookie),mFrameCallback(frameCallback) { }
587
588 int enableFrameNotification(int32_t frameTypes);
589 int disableFrameNotification(int32_t frameTypes);
590 int returnFrame(CameraBuffer *frameBuf, CameraFrame::FrameType frameType);
591 void addFramePointers(CameraBuffer *frameBuf, void *buf);
592 void removeFramePointers();
593 };
594
595 /** Wrapper class around MessageNotifier, which is used by display and notification classes for interacting with
596 * Camera Adapter
597 */
598 class EventProvider
599 {
600 public:
601 MessageNotifier* mEventNotifier;
602 void* mCookie;
603 event_callback mEventCallback;
604
605 public:
EventProvider(MessageNotifier * mn,void * cookie,event_callback eventCallback)606 EventProvider(MessageNotifier *mn, void* cookie, event_callback eventCallback)
607 :mEventNotifier(mn), mCookie(cookie), mEventCallback(eventCallback) {}
608
609 int enableEventNotification(int32_t eventTypes);
610 int disableEventNotification(int32_t eventTypes);
611 };
612
613 /*
614 * Interface for providing buffers
615 */
616 class BufferProvider
617 {
618 public:
619 virtual CameraBuffer * allocateBufferList(int width, int height, const char* format, int &bytes, int numBufs) = 0;
620
621 // gets a buffer list from BufferProvider when buffers are sent from external source and already pre-allocated
622 // only call this function for an input source into CameraHal. If buffers are not from a pre-allocated source
623 // this function will return NULL and numBufs of -1
624 virtual CameraBuffer *getBufferList(int *numBufs) = 0;
625
626 //additional methods used for memory mapping
627 virtual uint32_t * getOffsets() = 0;
628 virtual int getFd() = 0;
629 virtual CameraBuffer * getBuffers(bool reset = false) { return NULL; }
getSize()630 virtual unsigned int getSize() {return 0; }
getBufferCount()631 virtual int getBufferCount() {return -1; }
632
633 virtual int freeBufferList(CameraBuffer * buf) = 0;
634
~BufferProvider()635 virtual ~BufferProvider() {}
636 };
637
638 /**
639 * Class for handling data and notify callbacks to application
640 */
641 class AppCallbackNotifier: public ErrorNotifier , public virtual android::RefBase
642 {
643
644 public:
645
646 ///Constants
647 static const int NOTIFIER_TIMEOUT;
648 static const int32_t MAX_BUFFERS = 8;
649
650 enum NotifierCommands
651 {
652 NOTIFIER_CMD_PROCESS_EVENT,
653 NOTIFIER_CMD_PROCESS_FRAME,
654 NOTIFIER_CMD_PROCESS_ERROR
655 };
656
657 enum NotifierState
658 {
659 NOTIFIER_STOPPED,
660 NOTIFIER_STARTED,
661 NOTIFIER_EXITED
662 };
663
664 public:
665
666 ~AppCallbackNotifier();
667
668 ///Initialzes the callback notifier, creates any resources required
669 status_t initialize();
670
671 ///Starts the callbacks to application
672 status_t start();
673
674 ///Stops the callbacks from going to application
675 status_t stop();
676
677 void setEventProvider(int32_t eventMask, MessageNotifier * eventProvider);
678 void setFrameProvider(FrameNotifier *frameProvider);
679
680 //All sub-components of Camera HAL call this whenever any error happens
681 virtual void errorNotify(int error);
682
683 status_t startPreviewCallbacks(android::CameraParameters ¶ms, CameraBuffer *buffers, uint32_t *offsets, int fd, size_t length, size_t count);
684 status_t stopPreviewCallbacks();
685
686 status_t enableMsgType(int32_t msgType);
687 status_t disableMsgType(int32_t msgType);
688
689 //API for enabling/disabling measurement data
690 void setMeasurements(bool enable);
691
692 //thread loops
693 bool notificationThread();
694
695 ///Notification callback functions
696 static void frameCallbackRelay(CameraFrame* caFrame);
697 static void eventCallbackRelay(CameraHalEvent* chEvt);
698 void frameCallback(CameraFrame* caFrame);
699 void eventCallback(CameraHalEvent* chEvt);
700 void flushAndReturnFrames();
701
702 void setCallbacks(CameraHal *cameraHal,
703 camera_notify_callback notify_cb,
704 camera_data_callback data_cb,
705 camera_data_timestamp_callback data_cb_timestamp,
706 camera_request_memory get_memory,
707 void *user);
708
709 //Set Burst mode
710 void setBurst(bool burst);
711
712 //Notifications from CameraHal for video recording case
713 status_t startRecording();
714 status_t stopRecording();
715 status_t initSharedVideoBuffers(CameraBuffer *buffers, uint32_t *offsets, int fd, size_t length, size_t count, CameraBuffer *vidBufs);
716 status_t releaseRecordingFrame(const void *opaque);
717
718 status_t useMetaDataBufferMode(bool enable);
719
720 void EncoderDoneCb(void*, void*, CameraFrame::FrameType type, void* cookie1, void* cookie2, void *cookie3);
721
722 void useVideoBuffers(bool useVideoBuffers);
723
724 bool getUesVideoBuffers();
725 void setVideoRes(int width, int height);
726
727 void flushEventQueue();
728
729 //Internal class definitions
730 class NotificationThread : public android::Thread {
731 AppCallbackNotifier* mAppCallbackNotifier;
732 Utils::MessageQueue mNotificationThreadQ;
733 public:
734 enum NotificationThreadCommands
735 {
736 NOTIFIER_START,
737 NOTIFIER_STOP,
738 NOTIFIER_EXIT,
739 };
740 public:
NotificationThread(AppCallbackNotifier * nh)741 NotificationThread(AppCallbackNotifier* nh)
742 : Thread(false), mAppCallbackNotifier(nh) { }
threadLoop()743 virtual bool threadLoop() {
744 return mAppCallbackNotifier->notificationThread();
745 }
746
msgQ()747 Utils::MessageQueue &msgQ() { return mNotificationThreadQ;}
748 };
749
750 //Friend declarations
751 friend class NotificationThread;
752
753 private:
754 void notifyEvent();
755 void notifyFrame();
756 bool processMessage();
757 void releaseSharedVideoBuffers();
758 status_t dummyRaw();
759 void copyAndSendPictureFrame(CameraFrame* frame, int32_t msgType);
760 void copyAndSendPreviewFrame(CameraFrame* frame, int32_t msgType);
761 size_t calculateBufferSize(size_t width, size_t height, const char *pixelFormat);
762 const char* getContstantForPixelFormat(const char *pixelFormat);
763
764 private:
765 mutable android::Mutex mLock;
766 mutable android::Mutex mBurstLock;
767 CameraHal* mCameraHal;
768 camera_notify_callback mNotifyCb;
769 camera_data_callback mDataCb;
770 camera_data_timestamp_callback mDataCbTimestamp;
771 camera_request_memory mRequestMemory;
772 void *mCallbackCookie;
773
774 //Keeps Video MemoryHeaps and Buffers within
775 //these objects
776 android::KeyedVector<unsigned int, unsigned int> mVideoHeaps;
777 android::KeyedVector<unsigned int, unsigned int> mVideoBuffers;
778 android::KeyedVector<void *, CameraBuffer *> mVideoMap;
779
780 //Keeps list of Gralloc handles and associated Video Metadata Buffers
781 android::KeyedVector<void *, camera_memory_t *> mVideoMetadataBufferMemoryMap;
782 android::KeyedVector<void *, CameraBuffer *> mVideoMetadataBufferReverseMap;
783
784 bool mBufferReleased;
785
786 android::sp< NotificationThread> mNotificationThread;
787 EventProvider *mEventProvider;
788 FrameProvider *mFrameProvider;
789 Utils::MessageQueue mEventQ;
790 Utils::MessageQueue mFrameQ;
791 NotifierState mNotifierState;
792
793 bool mPreviewing;
794 camera_memory_t* mPreviewMemory;
795 CameraBuffer mPreviewBuffers[MAX_BUFFERS];
796 int mPreviewBufCount;
797 int mPreviewWidth;
798 int mPreviewHeight;
799 int mPreviewStride;
800 const char *mPreviewPixelFormat;
801 android::KeyedVector<unsigned int, android::sp<android::MemoryHeapBase> > mSharedPreviewHeaps;
802 android::KeyedVector<unsigned int, android::sp<android::MemoryBase> > mSharedPreviewBuffers;
803
804 //Burst mode active
805 bool mBurst;
806 mutable android::Mutex mRecordingLock;
807 bool mRecording;
808 bool mMeasurementEnabled;
809
810 bool mUseMetaDataBufferMode;
811 bool mRawAvailable;
812
813 bool mUseVideoBuffers;
814
815 int mVideoWidth;
816 int mVideoHeight;
817
818 };
819
820
821 /**
822 * Class used for allocating memory for JPEG bit stream buffers, output buffers of camera in no overlay case
823 */
824 class MemoryManager : public BufferProvider, public virtual android::RefBase
825 {
826 public:
827 MemoryManager();
828 ~MemoryManager();
829
830 status_t initialize();
831
832 int setErrorHandler(ErrorNotifier *errorNotifier);
833 virtual CameraBuffer * allocateBufferList(int width, int height, const char* format, int &bytes, int numBufs);
834 virtual CameraBuffer *getBufferList(int *numBufs);
835 virtual uint32_t * getOffsets();
836 virtual int getFd() ;
837 virtual int freeBufferList(CameraBuffer * buflist);
838
839 private:
840 android::sp<ErrorNotifier> mErrorNotifier;
841 int mIonFd;
842 };
843
844
845
846
847 /**
848 * CameraAdapter interface class
849 * Concrete classes derive from this class and provide implementations based on the specific camera h/w interface
850 */
851
852 class CameraAdapter: public FrameNotifier, public virtual android::RefBase
853 {
854 protected:
855 enum AdapterActiveStates {
856 INTIALIZED_ACTIVE = 1 << 0,
857 LOADED_PREVIEW_ACTIVE = 1 << 1,
858 PREVIEW_ACTIVE = 1 << 2,
859 LOADED_CAPTURE_ACTIVE = 1 << 3,
860 CAPTURE_ACTIVE = 1 << 4,
861 BRACKETING_ACTIVE = 1 << 5,
862 AF_ACTIVE = 1 << 6,
863 ZOOM_ACTIVE = 1 << 7,
864 VIDEO_ACTIVE = 1 << 8,
865 LOADED_REPROCESS_ACTIVE = 1 << 9,
866 REPROCESS_ACTIVE = 1 << 10,
867 };
868 public:
869 typedef struct
870 {
871 CameraBuffer *mBuffers;
872 uint32_t *mOffsets;
873 int mFd;
874 size_t mLength;
875 size_t mCount;
876 size_t mMaxQueueable;
877 } BuffersDescriptor;
878
879 enum CameraCommands
880 {
881 CAMERA_START_PREVIEW = 0,
882 CAMERA_STOP_PREVIEW = 1,
883 CAMERA_START_VIDEO = 2,
884 CAMERA_STOP_VIDEO = 3,
885 CAMERA_START_IMAGE_CAPTURE = 4,
886 CAMERA_STOP_IMAGE_CAPTURE = 5,
887 CAMERA_PERFORM_AUTOFOCUS = 6,
888 CAMERA_CANCEL_AUTOFOCUS = 7,
889 CAMERA_PREVIEW_FLUSH_BUFFERS = 8,
890 CAMERA_START_SMOOTH_ZOOM = 9,
891 CAMERA_STOP_SMOOTH_ZOOM = 10,
892 CAMERA_USE_BUFFERS_PREVIEW = 11,
893 CAMERA_SET_TIMEOUT = 12,
894 CAMERA_CANCEL_TIMEOUT = 13,
895 CAMERA_START_BRACKET_CAPTURE = 14,
896 CAMERA_STOP_BRACKET_CAPTURE = 15,
897 CAMERA_QUERY_RESOLUTION_PREVIEW = 16,
898 CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE = 17,
899 CAMERA_QUERY_BUFFER_SIZE_PREVIEW_DATA = 18,
900 CAMERA_USE_BUFFERS_IMAGE_CAPTURE = 19,
901 CAMERA_USE_BUFFERS_PREVIEW_DATA = 20,
902 CAMERA_TIMEOUT_EXPIRED = 21,
903 CAMERA_START_FD = 22,
904 CAMERA_STOP_FD = 23,
905 CAMERA_SWITCH_TO_EXECUTING = 24,
906 CAMERA_USE_BUFFERS_VIDEO_CAPTURE = 25,
907 #ifdef OMAP_ENHANCEMENT_CPCAM
908 CAMERA_USE_BUFFERS_REPROCESS = 26,
909 CAMERA_START_REPROCESS = 27,
910 #endif
911 #ifdef OMAP_ENHANCEMENT_VTC
912 CAMERA_SETUP_TUNNEL = 28,
913 CAMERA_DESTROY_TUNNEL = 29,
914 #endif
915 CAMERA_PREVIEW_INITIALIZATION = 30,
916 };
917
918 enum CameraMode
919 {
920 CAMERA_PREVIEW,
921 CAMERA_IMAGE_CAPTURE,
922 CAMERA_VIDEO,
923 CAMERA_MEASUREMENT,
924 CAMERA_REPROCESS,
925 };
926
927 enum AdapterState {
928 INTIALIZED_STATE = INTIALIZED_ACTIVE,
929 LOADED_PREVIEW_STATE = LOADED_PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
930 PREVIEW_STATE = PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
931 LOADED_CAPTURE_STATE = LOADED_CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
932 CAPTURE_STATE = CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
933 BRACKETING_STATE = BRACKETING_ACTIVE | CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE ,
934 AF_STATE = AF_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
935 ZOOM_STATE = ZOOM_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
936 VIDEO_STATE = VIDEO_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
937 VIDEO_AF_STATE = VIDEO_ACTIVE | AF_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
938 VIDEO_ZOOM_STATE = VIDEO_ACTIVE | ZOOM_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
939 VIDEO_LOADED_CAPTURE_STATE = VIDEO_ACTIVE | LOADED_CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
940 VIDEO_CAPTURE_STATE = VIDEO_ACTIVE | CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
941 AF_ZOOM_STATE = AF_ACTIVE | ZOOM_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
942 BRACKETING_ZOOM_STATE = BRACKETING_ACTIVE | ZOOM_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
943 LOADED_REPROCESS_STATE = LOADED_REPROCESS_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
944 LOADED_REPROCESS_CAPTURE_STATE = LOADED_REPROCESS_ACTIVE | LOADED_CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
945 REPROCESS_STATE = REPROCESS_ACTIVE | CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE,
946 };
947
948
949 public:
950
951 ///Initialzes the camera adapter creates any resources required
952 virtual int initialize(CameraProperties::Properties*) = 0;
953
954 virtual int setErrorHandler(ErrorNotifier *errorNotifier) = 0;
955
956 //Message/Frame notification APIs
957 virtual void enableMsgType(int32_t msgs,
958 frame_callback callback = NULL,
959 event_callback eventCb = NULL,
960 void *cookie = NULL) = 0;
961 virtual void disableMsgType(int32_t msgs, void* cookie) = 0;
962 virtual void returnFrame(CameraBuffer* frameBuf, CameraFrame::FrameType frameType) = 0;
963 virtual void addFramePointers(CameraBuffer *frameBuf, void *buf) = 0;
964 virtual void removeFramePointers() = 0;
965
966 //APIs to configure Camera adapter and get the current parameter set
967 virtual int setParameters(const android::CameraParameters& params) = 0;
968 virtual void getParameters(android::CameraParameters& params) = 0;
969
970 //Registers callback for returning image buffers back to CameraHAL
971 virtual int registerImageReleaseCallback(release_image_buffers_callback callback, void *user_data) = 0;
972
973 //Registers callback, which signals a completed image capture
974 virtual int registerEndCaptureCallback(end_image_capture_callback callback, void *user_data) = 0;
975
976 //API to send a command to the camera
977 virtual status_t sendCommand(CameraCommands operation, int value1=0, int value2=0, int value3=0, int value4=0) = 0;
978
~CameraAdapter()979 virtual ~CameraAdapter() {};
980
981 //Retrieves the current Adapter state
982 virtual AdapterState getState() = 0;
983
984 //Retrieves the next Adapter state
985 virtual AdapterState getNextState() = 0;
986
987 // Receive orientation events from CameraHal
988 virtual void onOrientationEvent(uint32_t orientation, uint32_t tilt) = 0;
989
990 // Rolls the state machine back to INTIALIZED_STATE from the current state
991 virtual status_t rollbackToInitializedState() = 0;
992
993 // Retrieves the current Adapter state - for internal use (not locked)
994 virtual status_t getState(AdapterState &state) = 0;
995 // Retrieves the next Adapter state - for internal use (not locked)
996 virtual status_t getNextState(AdapterState &state) = 0;
997
998 virtual status_t setSharedAllocator(camera_request_memory shmem_alloc) = 0;
999
1000 protected:
1001 //The first two methods will try to switch the adapter state.
1002 //Every call to setState() should be followed by a corresponding
1003 //call to commitState(). If the state switch fails, then it will
1004 //get reset to the previous state via rollbackState().
1005 virtual status_t setState(CameraCommands operation) = 0;
1006 virtual status_t commitState() = 0;
1007 virtual status_t rollbackState() = 0;
1008 };
1009
1010 class DisplayAdapter : public BufferProvider, public virtual android::RefBase
1011 {
1012 public:
1013 DisplayAdapter();
1014
1015 #ifdef OMAP_ENHANCEMENT
extendedOps()1016 preview_stream_extended_ops_t * extendedOps() const {
1017 return mExtendedOps;
1018 }
1019
1020 void setExtendedOps(preview_stream_extended_ops_t * extendedOps);
1021 #endif
1022
1023 ///Initializes the display adapter creates any resources required
1024 virtual int initialize() = 0;
1025
1026 virtual int setPreviewWindow(struct preview_stream_ops *window) = 0;
1027 virtual int setFrameProvider(FrameNotifier *frameProvider) = 0;
1028 virtual int setErrorHandler(ErrorNotifier *errorNotifier) = 0;
1029 virtual int enableDisplay(int width, int height, struct timeval *refTime = NULL) = 0;
1030 virtual int disableDisplay(bool cancel_buffer = true) = 0;
1031 //Used for Snapshot review temp. pause
1032 virtual int pauseDisplay(bool pause) = 0;
1033
1034 #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
1035 //Used for shot to snapshot measurement
1036 virtual int setSnapshotTimeRef(struct timeval *refTime = NULL) = 0;
1037 #endif
1038
1039 virtual bool supportsExternalBuffering() = 0;
1040
1041 // Get max queueable buffers display supports
1042 // This function should only be called after
1043 // allocateBufferList
1044 virtual status_t maxQueueableBuffers(unsigned int& queueable) = 0;
1045
1046 // Get min buffers display needs at any given time
1047 virtual status_t minUndequeueableBuffers(int& unqueueable) = 0;
1048
1049 // Given a vector of DisplayAdapters find the one corresponding to str
match(const char * str)1050 virtual bool match(const char * str) { return false; }
1051
1052 private:
1053 #ifdef OMAP_ENHANCEMENT
1054 preview_stream_extended_ops_t * mExtendedOps;
1055 #endif
1056 };
1057
1058 static void releaseImageBuffers(void *userData);
1059
1060 static void endImageCapture(void *userData);
1061
1062 /**
1063 Implementation of the Android Camera hardware abstraction layer
1064
1065 This class implements the interface methods defined in CameraHardwareInterface
1066 for the OMAP4 platform
1067
1068 */
1069 class CameraHal
1070
1071 {
1072
1073 public:
1074 ///Constants
1075 static const int NO_BUFFERS_PREVIEW;
1076 static const int NO_BUFFERS_IMAGE_CAPTURE;
1077 static const int NO_BUFFERS_IMAGE_CAPTURE_SYSTEM_HEAP;
1078 static const uint32_t VFR_SCALE = 1000;
1079
1080
1081 /*--------------------Interface Methods---------------------------------*/
1082
1083 //@{
1084 public:
1085
1086 /** Set the notification and data callbacks */
1087 void setCallbacks(camera_notify_callback notify_cb,
1088 camera_data_callback data_cb,
1089 camera_data_timestamp_callback data_cb_timestamp,
1090 camera_request_memory get_memory,
1091 void *user);
1092
1093 /** Receives orientation events from SensorListener **/
1094 void onOrientationEvent(uint32_t orientation, uint32_t tilt);
1095
1096 /**
1097 * The following three functions all take a msgtype,
1098 * which is a bitmask of the messages defined in
1099 * include/ui/Camera.h
1100 */
1101
1102 /**
1103 * Enable a message, or set of messages.
1104 */
1105 void enableMsgType(int32_t msgType);
1106
1107 /**
1108 * Disable a message, or a set of messages.
1109 */
1110 void disableMsgType(int32_t msgType);
1111
1112 /**
1113 * Query whether a message, or a set of messages, is enabled.
1114 * Note that this is operates as an AND, if any of the messages
1115 * queried are off, this will return false.
1116 */
1117 int msgTypeEnabled(int32_t msgType);
1118
1119 /**
1120 * Start preview mode.
1121 */
1122 int startPreview();
1123
1124 /**
1125 * Set preview mode related initialization.
1126 * Only used when slice based processing is enabled.
1127 */
1128 int cameraPreviewInitialization();
1129
1130 /**
1131 * Only used if overlays are used for camera preview.
1132 */
1133 int setPreviewWindow(struct preview_stream_ops *window);
1134
1135 #ifdef OMAP_ENHANCEMENT_CPCAM
1136 void setExtendedPreviewStreamOps(preview_stream_extended_ops_t *ops);
1137
1138 /**
1139 * Set a tap-in or tap-out point.
1140 */
1141 int setBufferSource(struct preview_stream_ops *tapin, struct preview_stream_ops *tapout);
1142 #endif
1143
1144 /**
1145 * Release a tap-in or tap-out point.
1146 */
1147 int releaseBufferSource(struct preview_stream_ops *tapin, struct preview_stream_ops *tapout);
1148
1149 /**
1150 * Stop a previously started preview.
1151 */
1152 void stopPreview();
1153
1154 /**
1155 * Returns true if preview is enabled.
1156 */
1157 bool previewEnabled();
1158
1159 /**
1160 * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME
1161 * message is sent with the corresponding frame. Every record frame must be released
1162 * by calling releaseRecordingFrame().
1163 */
1164 int startRecording();
1165
1166 /**
1167 * Stop a previously started recording.
1168 */
1169 void stopRecording();
1170
1171 /**
1172 * Returns true if recording is enabled.
1173 */
1174 int recordingEnabled();
1175
1176 /**
1177 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
1178 */
1179 void releaseRecordingFrame(const void *opaque);
1180
1181 /**
1182 * Start auto focus, the notification callback routine is called
1183 * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus()
1184 * will be called again if another auto focus is needed.
1185 */
1186 int autoFocus();
1187
1188 /**
1189 * Cancels auto-focus function. If the auto-focus is still in progress,
1190 * this function will cancel it. Whether the auto-focus is in progress
1191 * or not, this function will return the focus position to the default.
1192 * If the camera does not support auto-focus, this is a no-op.
1193 */
1194 int cancelAutoFocus();
1195
1196 /**
1197 * Take a picture.
1198 */
1199 int takePicture(const char* params);
1200
1201 /**
1202 * Cancel a picture that was started with takePicture. Calling this
1203 * method when no picture is being taken is a no-op.
1204 */
1205 int cancelPicture();
1206
1207 /** Set the camera parameters. */
1208 int setParameters(const char* params);
1209 int setParameters(const android::CameraParameters& params);
1210
1211 /** Return the camera parameters. */
1212 char* getParameters();
1213 void putParameters(char *);
1214
1215 /**
1216 * Send command to camera driver.
1217 */
1218 int sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
1219
1220 /**
1221 * Release the hardware resources owned by this object. Note that this is
1222 * *not* done in the destructor.
1223 */
1224 void release();
1225
1226 /**
1227 * Dump state of the camera hardware
1228 */
1229 int dump(int fd) const;
1230
1231 #ifdef OMAP_ENHANCEMENT_CPCAM
1232 /**
1233 * start a reprocessing operation.
1234 */
1235 int reprocess(const char* params);
1236
1237 /**
1238 * cancels current reprocessing operation
1239 */
1240 int cancel_reprocess();
1241 #endif
1242
1243 status_t storeMetaDataInBuffers(bool enable);
1244
1245 //@}
1246
1247 /*--------------------Internal Member functions - Public---------------------------------*/
1248
1249 public:
1250 /** @name internalFunctionsPublic */
1251 //@{
1252
1253 /** Constructor of CameraHal */
1254 CameraHal(int cameraId);
1255
1256 // Destructor of CameraHal
1257 ~CameraHal();
1258
1259 /** Initialize CameraHal */
1260 status_t initialize(CameraProperties::Properties*);
1261
1262 /** Deinitialize CameraHal */
1263 void deinitialize();
1264
1265 #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
1266
1267 //Uses the constructor timestamp as a reference to calcluate the
1268 // elapsed time
1269 static void PPM(const char *);
1270 //Uses a user provided timestamp as a reference to calcluate the
1271 // elapsed time
1272 static void PPM(const char *, struct timeval*, ...);
1273
1274 #endif
1275
1276 /** Free image bufs */
1277 status_t freeImageBufs();
1278
1279 //Signals the end of image capture
1280 status_t signalEndImageCapture();
1281
1282 //Events
1283 static void eventCallbackRelay(CameraHalEvent* event);
1284 void eventCallback(CameraHalEvent* event);
1285 void setEventProvider(int32_t eventMask, MessageNotifier * eventProvider);
1286
1287 static const char* getPixelFormatConstant(const char* parameters_format);
1288 static size_t calculateBufferSize(const char* parameters_format, int width, int height);
1289 static void getXYFromOffset(unsigned int *x, unsigned int *y,
1290 unsigned int offset, unsigned int stride,
1291 const char* format);
1292 static unsigned int getBPP(const char* format);
1293
1294 /*--------------------Internal Member functions - Private---------------------------------*/
1295 private:
1296
1297 /** @name internalFunctionsPrivate */
1298 //@{
1299
1300 /** Set the camera parameters specific to Video Recording. */
1301 bool setVideoModeParameters(const android::CameraParameters&);
1302
1303 /** Reset the camera parameters specific to Video Recording. */
1304 bool resetVideoModeParameters();
1305
1306 /** Restart the preview with setParameter. */
1307 status_t restartPreview();
1308
1309 status_t parseResolution(const char *resStr, int &width, int &height);
1310
1311 void insertSupportedParams();
1312
1313 /** Allocate preview data buffers */
1314 status_t allocPreviewDataBufs(size_t size, size_t bufferCount);
1315
1316 /** Free preview data buffers */
1317 status_t freePreviewDataBufs();
1318
1319 /** Allocate preview buffers */
1320 status_t allocPreviewBufs(int width, int height, const char* previewFormat, unsigned int bufferCount, unsigned int &max_queueable);
1321
1322 /** Allocate video buffers */
1323 status_t allocVideoBufs(uint32_t width, uint32_t height, uint32_t bufferCount);
1324
1325 /** Allocate image capture buffers */
1326 status_t allocImageBufs(unsigned int width, unsigned int height, size_t length,
1327 const char* previewFormat, unsigned int bufferCount);
1328
1329 /** Allocate Raw buffers */
1330 status_t allocRawBufs(int width, int height, const char* previewFormat, int bufferCount);
1331
1332 /** Free preview buffers */
1333 status_t freePreviewBufs();
1334
1335 /** Free video bufs */
1336 status_t freeVideoBufs(CameraBuffer *bufs);
1337
1338 /** Free RAW bufs */
1339 status_t freeRawBufs();
1340
1341 //Check if a given resolution is supported by the current camera
1342 //instance
1343 bool isResolutionValid(unsigned int width, unsigned int height, const char *supportedResolutions);
1344
1345 //Check if a given variable frame rate range is supported by the current camera
1346 //instance
1347 bool isFpsRangeValid(int fpsMin, int fpsMax, const char *supportedFpsRanges);
1348
1349 //Check if a given parameter is supported by the current camera
1350 // instance
1351 bool isParameterValid(const char *param, const char *supportedParams);
1352 bool isParameterValid(int param, const char *supportedParams);
1353 status_t doesSetParameterNeedUpdate(const char *new_param, const char *old_params, bool &update);
1354
1355 /** Initialize default parameters */
1356 void initDefaultParameters();
1357
1358 void dumpProperties(CameraProperties::Properties& cameraProps);
1359
1360 status_t startImageBracketing();
1361
1362 status_t stopImageBracketing();
1363
1364 void setShutter(bool enable);
1365
1366 void forceStopPreview();
1367
1368 void getPreferredPreviewRes(int *width, int *height);
1369 void resetPreviewRes(android::CameraParameters *params);
1370
1371 // Internal __takePicture function - used in public takePicture() and reprocess()
1372 int __takePicture(const char* params, struct timeval *captureStart = NULL);
1373 //@}
1374
1375 status_t setTapoutLocked(struct preview_stream_ops *out);
1376 status_t releaseTapoutLocked(struct preview_stream_ops *out);
1377 status_t setTapinLocked(struct preview_stream_ops *in);
1378 status_t releaseTapinLocked(struct preview_stream_ops *in);
1379 /*----------Member variables - Public ---------------------*/
1380 public:
1381 int32_t mMsgEnabled;
1382 bool mRecordEnabled;
1383 nsecs_t mCurrentTime;
1384 bool mFalsePreview;
1385 bool mPreviewEnabled;
1386 uint32_t mTakePictureQueue;
1387 bool mBracketingEnabled;
1388 bool mBracketingRunning;
1389 //User shutter override
1390 bool mShutterEnabled;
1391 bool mMeasurementEnabled;
1392 //Google's parameter delimiter
1393 static const char PARAMS_DELIMITER[];
1394
1395 CameraAdapter *mCameraAdapter;
1396 android::sp<AppCallbackNotifier> mAppCallbackNotifier;
1397 android::sp<DisplayAdapter> mDisplayAdapter;
1398 android::sp<MemoryManager> mMemoryManager;
1399
1400 android::Vector< android::sp<DisplayAdapter> > mOutAdapters;
1401 android::Vector< android::sp<DisplayAdapter> > mInAdapters;
1402
1403 // TODO(XXX): Even though we support user setting multiple BufferSourceAdapters now
1404 // only one tap in surface and one tap out surface is supported at a time.
1405 android::sp<DisplayAdapter> mBufferSourceAdapter_In;
1406 android::sp<DisplayAdapter> mBufferSourceAdapter_Out;
1407
1408 #ifdef OMAP_ENHANCEMENT
1409 preview_stream_extended_ops_t * mExtendedPreviewStreamOps;
1410 #endif
1411
1412 android::sp<android::IMemoryHeap> mPictureHeap;
1413
1414 int* mGrallocHandles;
1415 bool mFpsRangeChangedByApp;
1416
1417
1418 int mRawWidth;
1419 int mRawHeight;
1420 bool mRawCapture;
1421
1422
1423 ///static member vars
1424
1425 static const int SW_SCALING_FPS_LIMIT;
1426
1427 #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
1428
1429 //Timestamp from the CameraHal constructor
1430 static struct timeval ppm_start;
1431 //Timestamp of the autoFocus command
1432 static struct timeval mStartFocus;
1433 //Timestamp of the startPreview command
1434 static struct timeval mStartPreview;
1435 //Timestamp of the takePicture command
1436 static struct timeval mStartCapture;
1437
1438 #endif
1439
1440 /*----------Member variables - Private ---------------------*/
1441 private:
1442 bool mDynamicPreviewSwitch;
1443 //keeps paused state of display
1444 bool mDisplayPaused;
1445
1446 #ifdef OMAP_ENHANCEMENT_VTC
1447 bool mTunnelSetup;
1448 bool mVTCUseCase;
1449 #endif
1450
1451 //Index of current camera adapter
1452 int mCameraIndex;
1453
1454 mutable android::Mutex mLock;
1455
1456 android::sp<SensorListener> mSensorListener;
1457
1458 void* mCameraAdapterHandle;
1459
1460 android::CameraParameters mParameters;
1461 bool mPreviewRunning;
1462 bool mPreviewStateOld;
1463 bool mRecordingEnabled;
1464 EventProvider *mEventProvider;
1465
1466 CameraBuffer *mPreviewDataBuffers;
1467 uint32_t *mPreviewDataOffsets;
1468 int mPreviewDataFd;
1469 int mPreviewDataLength;
1470 CameraBuffer *mImageBuffers;
1471 uint32_t *mImageOffsets;
1472 int mImageFd;
1473 int mImageLength;
1474 unsigned int mImageCount;
1475 CameraBuffer *mPreviewBuffers;
1476 uint32_t *mPreviewOffsets;
1477 int mPreviewLength;
1478 int mPreviewFd;
1479 CameraBuffer *mVideoBuffers;
1480 uint32_t *mVideoOffsets;
1481 int mVideoFd;
1482 int mVideoLength;
1483
1484 int mBracketRangePositive;
1485 int mBracketRangeNegative;
1486
1487 ///@todo Rename this as preview buffer provider
1488 BufferProvider *mBufProvider;
1489 BufferProvider *mVideoBufProvider;
1490
1491
1492 CameraProperties::Properties* mCameraProperties;
1493
1494 bool mPreviewStartInProgress;
1495 bool mPreviewInitializationDone;
1496
1497 bool mSetPreviewWindowCalled;
1498
1499 uint32_t mPreviewWidth;
1500 uint32_t mPreviewHeight;
1501 int32_t mMaxZoomSupported;
1502
1503 int mVideoWidth;
1504 int mVideoHeight;
1505
1506 android::String8 mCapModeBackup;
1507 };
1508
1509 } // namespace Camera
1510 } // namespace Ti
1511
1512 #endif
1513