diff options
author | Ziyan <jaraidaniel@gmail.com> | 2016-01-03 14:19:34 +0100 |
---|---|---|
committer | Dániel Járai <jaraidaniel@gmail.com> | 2016-01-03 06:57:39 -0800 |
commit | e0c5a929875a3f858926d7fec7e236d6db1006a3 (patch) | |
tree | 175f7cedf1c33e09e5ede924348530827637e4fb /camera/inc | |
parent | 0b9a81bcf50f519eaaf7933984ec975f275f0530 (diff) | |
download | device_samsung_tuna-e0c5a929875a3f858926d7fec7e236d6db1006a3.zip device_samsung_tuna-e0c5a929875a3f858926d7fec7e236d6db1006a3.tar.gz device_samsung_tuna-e0c5a929875a3f858926d7fec7e236d6db1006a3.tar.bz2 |
Add camera sources in-tree
From hardware/ti/omap4 revision e57f2b6.
Change-Id: I2e6164fdf6c0e2a2e75aee3bba3fe58a9c470add
Diffstat (limited to 'camera/inc')
-rw-r--r-- | camera/inc/ANativeWindowDisplayAdapter.h | 196 | ||||
-rw-r--r-- | camera/inc/BaseCameraAdapter.h | 308 | ||||
-rw-r--r-- | camera/inc/BufferSourceAdapter.h | 228 | ||||
-rw-r--r-- | camera/inc/CameraHal.h | 1562 | ||||
-rw-r--r-- | camera/inc/CameraProperties.h | 244 | ||||
-rw-r--r-- | camera/inc/Common.h | 65 | ||||
-rw-r--r-- | camera/inc/DecoderFactory.h | 35 | ||||
-rw-r--r-- | camera/inc/Decoder_libjpeg.h | 58 | ||||
-rw-r--r-- | camera/inc/Encoder_libjpeg.h | 226 | ||||
-rw-r--r-- | camera/inc/FrameDecoder.h | 173 | ||||
-rw-r--r-- | camera/inc/General3A_Settings.h | 295 | ||||
-rw-r--r-- | camera/inc/NV12_resize.h | 135 | ||||
-rw-r--r-- | camera/inc/OMXCameraAdapter/OMXCameraAdapter.h | 1235 | ||||
-rw-r--r-- | camera/inc/OMXCameraAdapter/OMXDCC.h | 44 | ||||
-rw-r--r-- | camera/inc/OMXCameraAdapter/OMXSceneModeTables.h | 759 | ||||
-rw-r--r-- | camera/inc/OmxFrameDecoder.h | 204 | ||||
-rw-r--r-- | camera/inc/SensorListener.h | 105 | ||||
-rw-r--r-- | camera/inc/SwFrameDecoder.h | 47 | ||||
-rw-r--r-- | camera/inc/TICameraParameters.h | 270 | ||||
-rw-r--r-- | camera/inc/V4LCameraAdapter/V4LCameraAdapter.h | 262 | ||||
-rw-r--r-- | camera/inc/VideoMetadata.h | 32 |
21 files changed, 6483 insertions, 0 deletions
diff --git a/camera/inc/ANativeWindowDisplayAdapter.h b/camera/inc/ANativeWindowDisplayAdapter.h new file mode 100644 index 0000000..eba91bb --- /dev/null +++ b/camera/inc/ANativeWindowDisplayAdapter.h @@ -0,0 +1,196 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#include "CameraHal.h" +#include <ui/GraphicBufferMapper.h> +#include <hal_public.h> + +namespace Ti { +namespace Camera { + +/** + * Display handler class - This class basically handles the buffer posting to display + */ + +class ANativeWindowDisplayAdapter : public DisplayAdapter +{ +public: + + typedef struct + { + CameraBuffer *mBuffer; + void *mUser; + int mOffset; + int mWidth; + int mHeight; + int mWidthStride; + int mHeightStride; + int mLength; + CameraFrame::FrameType mType; + } DisplayFrame; + + enum DisplayStates + { + DISPLAY_INIT = 0, + DISPLAY_STARTED, + DISPLAY_STOPPED, + DISPLAY_EXITED + }; + +public: + + ANativeWindowDisplayAdapter(); + virtual ~ANativeWindowDisplayAdapter(); + + ///Initializes the display adapter creates any resources required + virtual status_t initialize(); + + virtual int setPreviewWindow(struct preview_stream_ops *window); + virtual int setFrameProvider(FrameNotifier *frameProvider); + virtual int setErrorHandler(ErrorNotifier *errorNotifier); + virtual int enableDisplay(int width, int height, struct timeval *refTime = NULL); + virtual int disableDisplay(bool cancel_buffer = true); + virtual status_t pauseDisplay(bool pause); + +#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS + + //Used for shot to snapshot measurement + virtual status_t setSnapshotTimeRef(struct timeval *refTime = NULL); + +#endif + + virtual bool supportsExternalBuffering(); + + //Implementation of inherited interfaces + virtual CameraBuffer * allocateBufferList(int width, int height, const char* format, int &bytes, int numBufs); + virtual CameraBuffer *getBufferList(int *numBufs); + virtual uint32_t * getOffsets() ; + virtual int getFd() ; + virtual int freeBufferList(CameraBuffer * buflist); + + virtual status_t maxQueueableBuffers(unsigned int& queueable); + virtual status_t minUndequeueableBuffers(int& unqueueable); + + // If set to true ANativeWindowDisplayAdapter will not lock/unlock graphic buffers + void setExternalLocking(bool extBuffLocking); + + ///Class specific functions + static void frameCallbackRelay(CameraFrame* caFrame); + void frameCallback(CameraFrame* caFrame); + + void displayThread(); + + private: + void destroy(); + bool processHalMsg(); + status_t PostFrame(ANativeWindowDisplayAdapter::DisplayFrame &dispFrame); + bool handleFrameReturn(); + status_t returnBuffersToWindow(); + +public: + + static const int DISPLAY_TIMEOUT; + static const int FAILED_DQS_TO_SUSPEND; + + class DisplayThread : public android::Thread + { + ANativeWindowDisplayAdapter* mDisplayAdapter; + Utils::MessageQueue mDisplayThreadQ; + + public: + DisplayThread(ANativeWindowDisplayAdapter* da) + : Thread(false), mDisplayAdapter(da) { } + + ///Returns a reference to the display message Q for display adapter to post messages + Utils::MessageQueue& msgQ() + { + return mDisplayThreadQ; + } + + virtual bool threadLoop() + { + mDisplayAdapter->displayThread(); + return false; + } + + enum DisplayThreadCommands + { + DISPLAY_START, + DISPLAY_STOP, + DISPLAY_FRAME, + DISPLAY_EXIT + }; + }; + + //friend declarations +friend class DisplayThread; + +private: + int postBuffer(void* displayBuf); + +private: + bool mFirstInit; + bool mSuspend; + int mFailedDQs; + bool mPaused; //Pause state + preview_stream_ops_t* mANativeWindow; + android::sp<DisplayThread> mDisplayThread; + FrameProvider *mFrameProvider; ///Pointer to the frame provider interface + Utils::MessageQueue mDisplayQ; + unsigned int mDisplayState; + ///@todo Have a common class for these members + mutable android::Mutex mLock; + bool mDisplayEnabled; + int mBufferCount; + CameraBuffer *mBuffers; + //buffer_handle_t** mBufferHandleMap; // -> frames[i].BufferHandle + //IMG_native_handle_t** mGrallocHandleMap; // -> frames[i].GrallocHandle + uint32_t* mOffsetsMap; // -> frames[i].Offset + int mFD; + android::KeyedVector<buffer_handle_t *, int> mFramesWithCameraAdapterMap; + android::KeyedVector<int, int> mFramesType; + android::sp<ErrorNotifier> mErrorNotifier; + + uint32_t mFrameWidth; + uint32_t mFrameHeight; + uint32_t mPreviewWidth; + uint32_t mPreviewHeight; + + uint32_t mXOff; + uint32_t mYOff; + + const char *mPixelFormat; + + //In case if we ,as example, using out buffers in Ducati Decoder + //DOMX will handle lock/unlock of graphic buffers + bool mUseExternalBufferLocking; + +#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS + //Used for calculating standby to first shot + struct timeval mStandbyToShot; + bool mMeasureStandby; + //Used for shot to snapshot/shot calculation + struct timeval mStartCapture; + bool mShotToShot; + +#endif + +}; + +} // namespace Camera +} // namespace Ti diff --git a/camera/inc/BaseCameraAdapter.h b/camera/inc/BaseCameraAdapter.h new file mode 100644 index 0000000..ffe0492 --- /dev/null +++ b/camera/inc/BaseCameraAdapter.h @@ -0,0 +1,308 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#ifndef BASE_CAMERA_ADAPTER_H +#define BASE_CAMERA_ADAPTER_H + +#include "CameraHal.h" + +namespace Ti { +namespace Camera { + +struct LUT { + const char * userDefinition; + int halDefinition; +}; + +struct LUTtypeHAL{ + int size; + const LUT *Table; +}; + +class BaseCameraAdapter : public CameraAdapter +{ + +public: + + BaseCameraAdapter(); + virtual ~BaseCameraAdapter(); + + ///Initialzes the camera adapter creates any resources required + virtual status_t initialize(CameraProperties::Properties*) = 0; + + virtual int setErrorHandler(ErrorNotifier *errorNotifier); + + //Message/Frame notification APIs + virtual void enableMsgType(int32_t msgs, frame_callback callback=NULL, event_callback eventCb=NULL, void* cookie=NULL); + virtual void disableMsgType(int32_t msgs, void* cookie); + virtual void returnFrame(CameraBuffer * frameBuf, CameraFrame::FrameType frameType); + virtual void addFramePointers(CameraBuffer *frameBuf, void *y_uv); + virtual void removeFramePointers(); + + //APIs to configure Camera adapter and get the current parameter set + virtual status_t setParameters(const android::CameraParameters& params) = 0; + virtual void getParameters(android::CameraParameters& params) = 0; + + //API to send a command to the camera + virtual status_t sendCommand(CameraCommands operation, int value1 = 0, int value2 = 0, int value3 = 0, int value4 = 0 ); + + virtual status_t registerImageReleaseCallback(release_image_buffers_callback callback, void *user_data); + + virtual status_t registerEndCaptureCallback(end_image_capture_callback callback, void *user_data); + + //Retrieves the current Adapter state + virtual AdapterState getState(); + //Retrieves the next Adapter state + virtual AdapterState getNextState(); + + virtual status_t setSharedAllocator(camera_request_memory shmem_alloc) { mSharedAllocator = shmem_alloc; return NO_ERROR; }; + + // Rolls the state machine back to INTIALIZED_STATE from the current state + virtual status_t rollbackToInitializedState(); + +protected: + //The first two methods will try to switch the adapter state. + //Every call to setState() should be followed by a corresponding + //call to commitState(). If the state switch fails, then it will + //get reset to the previous state via rollbackState(). + virtual status_t setState(CameraCommands operation); + virtual status_t commitState(); + virtual status_t rollbackState(); + + // Retrieves the current Adapter state - for internal use (not locked) + virtual status_t getState(AdapterState &state); + // Retrieves the next Adapter state - for internal use (not locked) + virtual status_t getNextState(AdapterState &state); + + //-----------Interface that needs to be implemented by deriving classes -------------------- + + //Should be implmented by deriving classes in order to start image capture + virtual status_t takePicture(); + + //Should be implmented by deriving classes in order to start image capture + virtual status_t stopImageCapture(); + + //Should be implmented by deriving classes in order to start temporal bracketing + virtual status_t startBracketing(int range); + + //Should be implemented by deriving classes in order to stop temporal bracketing + virtual status_t stopBracketing(); + + //Should be implemented by deriving classes in oder to initiate autoFocus + virtual status_t autoFocus(); + + //Should be implemented by deriving classes in oder to initiate autoFocus + virtual status_t cancelAutoFocus(); + + //Should be called by deriving classes in order to do some bookkeeping + virtual status_t startVideoCapture(); + + //Should be called by deriving classes in order to do some bookkeeping + virtual status_t stopVideoCapture(); + + //Should be implemented by deriving classes in order to start camera preview + virtual status_t startPreview(); + + //Should be implemented by deriving classes in order to stop camera preview + virtual status_t stopPreview(); + + //Should be implemented by deriving classes in order to start smooth zoom + virtual status_t startSmoothZoom(int targetIdx); + + //Should be implemented by deriving classes in order to stop smooth zoom + virtual status_t stopSmoothZoom(); + + //Should be implemented by deriving classes in order to stop smooth zoom + virtual status_t useBuffers(CameraMode mode, CameraBuffer* bufArr, int num, size_t length, unsigned int queueable); + + //Should be implemented by deriving classes in order queue a released buffer in CameraAdapter + virtual status_t fillThisBuffer(CameraBuffer* frameBuf, CameraFrame::FrameType frameType); + + //API to get the frame size required to be allocated. This size is used to override the size passed + //by camera service when VSTAB/VNF is turned ON for example + virtual status_t getFrameSize(size_t &width, size_t &height); + + //API to get required data frame size + virtual status_t getFrameDataSize(size_t &dataFrameSize, size_t bufferCount); + + //API to get required picture buffers size with the current configuration in CameraParameters + virtual status_t getPictureBufferSize(CameraFrame &frame, size_t bufferCount); + + // Should be implemented by deriving classes in order to start face detection + // ( if supported ) + virtual status_t startFaceDetection(); + + // Should be implemented by deriving classes in order to stop face detection + // ( if supported ) + virtual status_t stopFaceDetection(); + + virtual status_t switchToExecuting(); + + virtual status_t setupTunnel(uint32_t SliceHeight, uint32_t EncoderHandle, uint32_t width, uint32_t height); + + virtual status_t destroyTunnel(); + + virtual status_t cameraPreviewInitialization(); + + // Receive orientation events from CameraHal + virtual void onOrientationEvent(uint32_t orientation, uint32_t tilt); + + // ---------------------Interface ends----------------------------------- + + status_t notifyFocusSubscribers(CameraHalEvent::FocusStatus status); + status_t notifyShutterSubscribers(); + status_t notifyZoomSubscribers(int zoomIdx, bool targetReached); + status_t notifyMetadataSubscribers(android::sp<CameraMetadataResult> &meta); + + //Send the frame to subscribers + status_t sendFrameToSubscribers(CameraFrame *frame); + + //Resets the refCount for this particular frame + status_t resetFrameRefCount(CameraFrame &frame); + + //A couple of helper functions + void setFrameRefCountByType(CameraBuffer* frameBuf, CameraFrame::FrameType frameType, int refCount); + int getFrameRefCount(CameraBuffer* frameBuf); + int getFrameRefCountByType(CameraBuffer* frameBuf, CameraFrame::FrameType frameType); + int setInitFrameRefCount(CameraBuffer* buf, unsigned int mask); + static const char* getLUTvalue_translateHAL(int Value, LUTtypeHAL LUT); + +// private member functions +private: + status_t __sendFrameToSubscribers(CameraFrame* frame, + android::KeyedVector<int, frame_callback> *subscribers, + CameraFrame::FrameType frameType); + status_t rollbackToPreviousState(); + +// protected data types and variables +protected: + enum FrameState { + STOPPED = 0, + RUNNING + }; + + enum FrameCommands { + START_PREVIEW = 0, + START_RECORDING, + RETURN_FRAME, + STOP_PREVIEW, + STOP_RECORDING, + DO_AUTOFOCUS, + TAKE_PICTURE, + FRAME_EXIT + }; + + enum AdapterCommands { + ACK = 0, + ERROR + }; + +#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS + + struct timeval mStartFocus; + struct timeval mStartCapture; + +#endif + + mutable android::Mutex mReturnFrameLock; + + //Lock protecting the Adapter state + mutable android::Mutex mLock; + AdapterState mAdapterState; + AdapterState mNextState; + + //Different frame subscribers get stored using these + android::KeyedVector<int, frame_callback> mFrameSubscribers; + android::KeyedVector<int, frame_callback> mSnapshotSubscribers; + android::KeyedVector<int, frame_callback> mFrameDataSubscribers; + android::KeyedVector<int, frame_callback> mVideoSubscribers; + android::KeyedVector<int, frame_callback> mVideoInSubscribers; + android::KeyedVector<int, frame_callback> mImageSubscribers; + android::KeyedVector<int, frame_callback> mRawSubscribers; + android::KeyedVector<int, event_callback> mFocusSubscribers; + android::KeyedVector<int, event_callback> mZoomSubscribers; + android::KeyedVector<int, event_callback> mShutterSubscribers; + android::KeyedVector<int, event_callback> mMetadataSubscribers; + + //Preview buffer management data + CameraBuffer *mPreviewBuffers; + int mPreviewBufferCount; + size_t mPreviewBuffersLength; + android::KeyedVector<CameraBuffer *, int> mPreviewBuffersAvailable; + mutable android::Mutex mPreviewBufferLock; + + //Snapshot buffer management data + android::KeyedVector<CameraBuffer *, int> mSnapshotBuffersAvailable; + mutable android::Mutex mSnapshotBufferLock; + + //Video buffer management data + CameraBuffer *mVideoBuffers; + android::KeyedVector<CameraBuffer *, int> mVideoBuffersAvailable; + int mVideoBuffersCount; + size_t mVideoBuffersLength; + mutable android::Mutex mVideoBufferLock; + + //Image buffer management data + CameraBuffer *mCaptureBuffers; + android::KeyedVector<CameraBuffer *, int> mCaptureBuffersAvailable; + int mCaptureBuffersCount; + size_t mCaptureBuffersLength; + mutable android::Mutex mCaptureBufferLock; + + //Metadata buffermanagement + CameraBuffer *mPreviewDataBuffers; + android::KeyedVector<CameraBuffer *, int> mPreviewDataBuffersAvailable; + int mPreviewDataBuffersCount; + size_t mPreviewDataBuffersLength; + mutable android::Mutex mPreviewDataBufferLock; + + //Video input buffer management data (used for reproc pipe) + CameraBuffer *mVideoInBuffers; + android::KeyedVector<CameraBuffer *, int> mVideoInBuffersAvailable; + mutable android::Mutex mVideoInBufferLock; + + Utils::MessageQueue mFrameQ; + Utils::MessageQueue mAdapterQ; + mutable android::Mutex mSubscriberLock; + ErrorNotifier *mErrorNotifier; + release_image_buffers_callback mReleaseImageBuffersCallback; + end_image_capture_callback mEndImageCaptureCallback; + void *mReleaseData; + void *mEndCaptureData; + bool mRecording; + + camera_request_memory mSharedAllocator; + + uint32_t mFramesWithDucati; + uint32_t mFramesWithDisplay; + uint32_t mFramesWithEncoder; + +#ifdef CAMERAHAL_DEBUG + android::Mutex mBuffersWithDucatiLock; + android::KeyedVector<int, bool> mBuffersWithDucati; +#endif + + android::KeyedVector<void *, CameraFrame *> mFrameQueue; +}; + +} // namespace Camera +} // namespace Ti + +#endif //BASE_CAMERA_ADAPTER_H + + diff --git a/camera/inc/BufferSourceAdapter.h b/camera/inc/BufferSourceAdapter.h new file mode 100644 index 0000000..c006b9d --- /dev/null +++ b/camera/inc/BufferSourceAdapter.h @@ -0,0 +1,228 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BUFFER_SOURCE_ADAPTER_H +#define BUFFER_SOURCE_ADAPTER_H + +#ifdef OMAP_ENHANCEMENT_CPCAM + +#include "CameraHal.h" +#include <ui/GraphicBufferMapper.h> +#include <hal_public.h> + +namespace Ti { +namespace Camera { + +/** + * Handles enqueueing/dequeing buffers to tap-in/tap-out points + * TODO(XXX): this class implements DisplayAdapter for now + * but this will most likely change once tap-in/tap-out points + * are better defined + */ + +class BufferSourceAdapter : public DisplayAdapter +{ +// private types +private: + ///Constant declarations + static const int NO_BUFFERS_IMAGE_CAPTURE_SYSTEM_HEAP; + + + // helper class to return frame in different thread context + class ReturnFrame : public android::Thread { + public: + ReturnFrame(BufferSourceAdapter* __this) : mBufferSourceAdapter(__this) { + android::AutoMutex lock(mReturnFrameMutex); + mDestroying = false; + mFrameCount = 0; + } + + ~ReturnFrame() { + android::AutoMutex lock(mReturnFrameMutex); + } + + void signal() { + android::AutoMutex lock(mReturnFrameMutex); + mFrameCount++; + mReturnFrameCondition.signal(); + } + + virtual void requestExit() { + Thread::requestExit(); + + android::AutoMutex lock(mReturnFrameMutex); + mDestroying = true; + mReturnFrameCondition.signal(); + } + + virtual bool threadLoop() { + android::AutoMutex lock(mReturnFrameMutex); + if ( 0 >= mFrameCount ) { + mReturnFrameCondition.wait(mReturnFrameMutex); + } + if (!mDestroying) { + mBufferSourceAdapter->handleFrameReturn(); + mFrameCount--; + } + return true; + } + + private: + BufferSourceAdapter* mBufferSourceAdapter; + android::Condition mReturnFrameCondition; + android::Mutex mReturnFrameMutex; + int mFrameCount; + bool mDestroying; + }; + + // helper class to queue frame in different thread context + class QueueFrame : public android::Thread { + public: + QueueFrame(BufferSourceAdapter* __this) : mBufferSourceAdapter(__this) { + mDestroying = false; + } + + ~QueueFrame() { + } + + void addFrame(CameraFrame *frame) { + android::AutoMutex lock(mFramesMutex); + mFrames.add(new CameraFrame(*frame)); + mFramesCondition.signal(); + } + + virtual void requestExit() { + Thread::requestExit(); + + mDestroying = true; + + android::AutoMutex lock(mFramesMutex); + while (!mFrames.empty()) { + CameraFrame *frame = mFrames.itemAt(0); + mFrames.removeAt(0); + frame->mMetaData.clear(); + delete frame; + } + mFramesCondition.signal(); + } + + virtual bool threadLoop() { + CameraFrame *frame = NULL; + { + android::AutoMutex lock(mFramesMutex); + while (mFrames.empty() && !mDestroying) mFramesCondition.wait(mFramesMutex); + if (!mDestroying) { + frame = mFrames.itemAt(0); + mFrames.removeAt(0); + } + } + + if (frame) { + mBufferSourceAdapter->handleFrameCallback(frame); + frame->mMetaData.clear(); + + if (frame->mFrameType != CameraFrame::REPROCESS_INPUT_FRAME) { + // signal return frame thread that it can dequeue a buffer now + mBufferSourceAdapter->mReturnFrame->signal(); + } + + delete frame; + } + + return true; + } + + private: + BufferSourceAdapter* mBufferSourceAdapter; + android::Vector<CameraFrame *> mFrames; + android::Condition mFramesCondition; + android::Mutex mFramesMutex; + bool mDestroying; + }; + + enum { + BUFFER_SOURCE_TAP_IN, + BUFFER_SOURCE_TAP_OUT + }; + +// public member functions +public: + BufferSourceAdapter(); + virtual ~BufferSourceAdapter(); + + virtual status_t initialize(); + virtual int setPreviewWindow(struct preview_stream_ops *source); + virtual int setFrameProvider(FrameNotifier *frameProvider); + virtual int setErrorHandler(ErrorNotifier *errorNotifier); + virtual int enableDisplay(int width, int height, struct timeval *refTime = NULL); + virtual int disableDisplay(bool cancel_buffer = true); + virtual status_t pauseDisplay(bool pause); +#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS + // Not implemented in this class + virtual status_t setSnapshotTimeRef(struct timeval *refTime = NULL) { return NO_ERROR; } +#endif + virtual bool supportsExternalBuffering(); + virtual CameraBuffer * allocateBufferList(int width, int dummyHeight, const char* format, int &bytes, int numBufs); + virtual CameraBuffer *getBufferList(int *numBufs); + virtual uint32_t * getOffsets() ; + virtual int getFd() ; + virtual int freeBufferList(CameraBuffer * buflist); + virtual int maxQueueableBuffers(unsigned int& queueable); + virtual int minUndequeueableBuffers(int& unqueueable); + virtual bool match(const char * str); + + virtual CameraBuffer * getBuffers(bool reset = false); + virtual unsigned int getSize(); + virtual int getBufferCount(); + + static void frameCallback(CameraFrame* caFrame); + void addFrame(CameraFrame* caFrame); + void handleFrameCallback(CameraFrame* caFrame); + bool handleFrameReturn(); + +private: + void destroy(); + status_t returnBuffersToWindow(); + +private: + preview_stream_ops_t* mBufferSource; + FrameProvider *mFrameProvider; // Pointer to the frame provider interface + + mutable android::Mutex mLock; + int mBufferCount; + CameraBuffer *mBuffers; + + android::KeyedVector<buffer_handle_t *, int> mFramesWithCameraAdapterMap; + android::sp<ErrorNotifier> mErrorNotifier; + android::sp<ReturnFrame> mReturnFrame; + android::sp<QueueFrame> mQueueFrame; + + uint32_t mFrameWidth; + uint32_t mFrameHeight; + uint32_t mPreviewWidth; + uint32_t mPreviewHeight; + + int mBufferSourceDirection; + + const char *mPixelFormat; +}; + +} // namespace Camera +} // namespace Ti + +#endif + +#endif diff --git a/camera/inc/CameraHal.h b/camera/inc/CameraHal.h new file mode 100644 index 0000000..b6d19b7 --- /dev/null +++ b/camera/inc/CameraHal.h @@ -0,0 +1,1562 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_H +#define ANDROID_HARDWARE_CAMERA_HARDWARE_H + +#include <stdio.h> +#include <stdarg.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <time.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <sys/stat.h> + +#include <hardware/camera.h> +#include <utils/Log.h> +#include <utils/threads.h> +#include <utils/threads.h> +#include <binder/MemoryBase.h> +#include <binder/MemoryHeapBase.h> +#include <camera/CameraParameters.h> +#ifdef OMAP_ENHANCEMENT_CPCAM +#include <camera/CameraMetadata.h> +#include <camera/ShotParameters.h> +#endif +#include <ui/GraphicBufferAllocator.h> +#include <ui/GraphicBuffer.h> + +/* For IMG_native_handle_t */ +#include <ui/GraphicBufferMapper.h> +#include <hal_public.h> + +#ifdef USE_LIBION_TI +#include <ion_ti/ion.h> +#else +#include <ion/ion.h> +#endif + +#include "Common.h" +#include "MessageQueue.h" +#include "Semaphore.h" +#include "CameraProperties.h" +#include "SensorListener.h" + +//temporarily define format here +#define HAL_PIXEL_FORMAT_TI_NV12 0x100 +#define HAL_PIXEL_FORMAT_TI_Y8 0x103 +#define HAL_PIXEL_FORMAT_TI_Y16 0x104 +#define HAL_PIXEL_FORMAT_TI_UYVY 0x105 + +#define MIN_WIDTH 640 +#define MIN_HEIGHT 480 +#define PICTURE_WIDTH 3264 /* 5mp - 2560. 8mp - 3280 */ /* Make sure it is a multiple of 16. */ +#define PICTURE_HEIGHT 2448 /* 5mp - 2048. 8mp - 2464 */ /* Make sure it is a multiple of 16. */ +#define PREVIEW_WIDTH 176 +#define PREVIEW_HEIGHT 144 +#define PIXEL_FORMAT V4L2_PIX_FMT_UYVY + +#define VIDEO_FRAME_COUNT_MAX 8 //NUM_OVERLAY_BUFFERS_REQUESTED +#define MAX_CAMERA_BUFFERS 8 //NUM_OVERLAY_BUFFERS_REQUESTED +#define MAX_ZOOM 3 +#define THUMB_WIDTH 80 +#define THUMB_HEIGHT 60 +#define PIX_YUV422I 0 +#define PIX_YUV420P 1 + +#define SATURATION_OFFSET 100 +#define SHARPNESS_OFFSET 100 +#define CONTRAST_OFFSET 100 + +#ifdef MOTOROLA_CAMERA +#define DEFAULT_INTENSITY 100 +#define FLASH_VOLTAGE_THRESHOLD1 3700000 // intensity will be reduced to 50% below threshold1 +#define FLASH_VOLTAGE_THRESHOLD2 3300000 // flash disabled below threshold2 +#endif + +#define FRAME_RATE_HIGH_HD 60 + +#define CAMHAL_GRALLOC_USAGE GRALLOC_USAGE_HW_TEXTURE | \ + GRALLOC_USAGE_HW_RENDER | \ + GRALLOC_USAGE_SW_READ_RARELY | \ + GRALLOC_USAGE_SW_WRITE_NEVER + +//Enables Absolute PPM measurements in logcat +#define PPM_INSTRUMENTATION_ABS 1 + +#define LOCK_BUFFER_TRIES 5 +#define HAL_PIXEL_FORMAT_NV12 0x100 + +#define OP_STR_SIZE 100 + +#define NONNEG_ASSIGN(x,y) \ + if(x > -1) \ + y = x + +#define CAMHAL_SIZE_OF_ARRAY(x) static_cast<int>(sizeof(x)/sizeof(x[0])) + +namespace Ti { +namespace Camera { + +#ifdef CAMERAHAL_USE_RAW_IMAGE_SAVING +extern const char * const kRawImagesOutputDirPath; +extern const char * const kYuvImagesOutputDirPath; +#endif +#define V4L_CAMERA_NAME_USB "USBCAMERA" +#define OMX_CAMERA_NAME_OV "OV5640" +#define OMX_CAMERA_NAME_SONY "IMX060" +#ifdef MOTOROLA_CAMERA +#define OMX_CAMERA_NAME_OV8820 "OV8820" +#define OMX_CAMERA_NAME_OV7739 "OV7739" +#define OMX_CAMERA_NAME_MT9M114 "MT9M114" +#endif + + +///Forward declarations +class CameraHal; +class CameraFrame; +class CameraHalEvent; +class DisplayFrame; + +class FpsRange { +public: + static int compare(const FpsRange * left, const FpsRange * right); + + FpsRange(int min, int max); + FpsRange(); + + bool operator==(const FpsRange & fpsRange) const; + + bool isNull() const; + bool isFixed() const; + + int min() const; + int max() const; + +private: + int mMin; + int mMax; +}; + + +inline int FpsRange::compare(const FpsRange * const left, const FpsRange * const right) { + if ( left->max() < right->max() ) { + return -1; + } + + if ( left->max() > right->max() ) { + return 1; + } + + if ( left->min() < right->min() ) { + return -1; + } + + if ( left->min() > right->min() ) { + return 1; + } + + return 0; +} + +inline FpsRange::FpsRange(const int min, const int max) : mMin(min), mMax(max) {} + +inline FpsRange::FpsRange() : mMin(-1), mMax(-1) {} + +inline bool FpsRange::operator==(const FpsRange & fpsRange) const { + return mMin == fpsRange.mMin && mMax == fpsRange.mMax; +} + +inline bool FpsRange::isNull() const { + return mMin == -1 || mMax == -1; +} + +inline bool FpsRange::isFixed() const { + return mMin == mMax; +} + +inline int FpsRange::min() const { return mMin; } + +inline int FpsRange::max() const { return mMax; } + +class CameraArea : public android::RefBase +{ +public: + + CameraArea(ssize_t top, + ssize_t left, + ssize_t bottom, + ssize_t right, + size_t weight) : mTop(top), + mLeft(left), + mBottom(bottom), + mRight(right), + mWeight(weight) {} + + status_t transfrom(size_t width, + size_t height, + size_t &top, + size_t &left, + size_t &areaWidth, + size_t &areaHeight); + + bool isValid() + { + return ( ( 0 != mTop ) || ( 0 != mLeft ) || ( 0 != mBottom ) || ( 0 != mRight) ); + } + + bool isZeroArea() + { + return ( (0 == mTop ) && ( 0 == mLeft ) && ( 0 == mBottom ) + && ( 0 == mRight ) && ( 0 == mWeight )); + } + + size_t getWeight() + { + return mWeight; + } + + bool compare(const android::sp<CameraArea> &area); + + static status_t parseAreas(const char *area, + size_t areaLength, + android::Vector< android::sp<CameraArea> > &areas); + + static status_t checkArea(ssize_t top, + ssize_t left, + ssize_t bottom, + ssize_t right, + ssize_t weight); + + static bool areAreasDifferent(android::Vector< android::sp<CameraArea> > &, android::Vector< android::sp<CameraArea> > &); + +protected: + static const ssize_t TOP = -1000; + static const ssize_t LEFT = -1000; + static const ssize_t BOTTOM = 1000; + static const ssize_t RIGHT = 1000; + static const ssize_t WEIGHT_MIN = 1; + static const ssize_t WEIGHT_MAX = 1000; + + ssize_t mTop; + ssize_t mLeft; + ssize_t mBottom; + ssize_t mRight; + size_t mWeight; +}; + +class CameraMetadataResult : public android::RefBase +{ +public: + +#ifdef OMAP_ENHANCEMENT_CPCAM + CameraMetadataResult(camera_memory_t * extMeta) : mExtendedMetadata(extMeta) { + mMetadata.faces = NULL; + mMetadata.number_of_faces = 0; +#ifdef OMAP_ENHANCEMENT + mMetadata.analog_gain = 0; + mMetadata.exposure_time = 0; +#endif + }; +#endif + + CameraMetadataResult() { + mMetadata.faces = NULL; + mMetadata.number_of_faces = 0; +#ifdef OMAP_ENHANCEMENT_CPCAM + mMetadata.analog_gain = 0; + mMetadata.exposure_time = 0; +#endif + +#ifdef OMAP_ENHANCEMENT_CPCAM + mExtendedMetadata = NULL; +#endif + } + + virtual ~CameraMetadataResult() { + if ( NULL != mMetadata.faces ) { + free(mMetadata.faces); + } +#ifdef OMAP_ENHANCEMENT_CPCAM + if ( NULL != mExtendedMetadata ) { + mExtendedMetadata->release(mExtendedMetadata); + } +#endif + } + + camera_frame_metadata_t *getMetadataResult() { return &mMetadata; }; + +#ifdef OMAP_ENHANCEMENT_CPCAM + camera_memory_t *getExtendedMetadata() { return mExtendedMetadata; }; +#endif + + static const ssize_t TOP = -1000; + static const ssize_t LEFT = -1000; + static const ssize_t BOTTOM = 1000; + static const ssize_t RIGHT = 1000; + static const ssize_t INVALID_DATA = -2000; + +private: + + camera_frame_metadata_t mMetadata; +#ifdef OMAP_ENHANCEMENT_CPCAM + camera_memory_t *mExtendedMetadata; +#endif +}; + +typedef enum { + CAMERA_BUFFER_NONE = 0, + CAMERA_BUFFER_GRALLOC, + CAMERA_BUFFER_ANW, + CAMERA_BUFFER_MEMORY, + CAMERA_BUFFER_ION +} CameraBufferType; + +typedef struct _CameraBuffer { + CameraBufferType type; + /* opaque is the generic drop-in replacement for the pointers + * that were used previously */ + void *opaque; + + /* opaque has different meanings depending on the buffer type: + * GRALLOC - gralloc_handle_t + * ANW - a pointer to the buffer_handle_t (which corresponds to + * the ANativeWindowBuffer *) + * MEMORY - address of allocated memory + * ION - address of mapped ion allocation + * + * FIXME opaque should be split into several fields: + * - handle/pointer we got from the allocator + * - handle/value we pass to OMX + * - pointer to mapped memory (if the buffer is mapped) + */ + + /* mapped holds ptr to mapped memory in userspace */ + void *mapped; + + /* These are specific to ION buffers */ + struct ion_handle * ion_handle; + int ion_fd; + int fd; + size_t size; + int index; + + /* These describe the camera buffer */ + int width; + int stride; + int height; + const char *format; + +#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS + + struct timeval ppmStamp; + +#endif + + /* These are for buffers which include borders */ + int offset; // where valid data starts + int actual_size; // size of the entire buffer with borders + int privateData; +} CameraBuffer; + +void * camera_buffer_get_omx_ptr (CameraBuffer *buffer); + +class CameraFrame +{ + public: + + enum FrameType + { + PREVIEW_FRAME_SYNC = 0x1, ///SYNC implies that the frame needs to be explicitly returned after consuming in order to be filled by camera again + PREVIEW_FRAME = 0x2 , ///Preview frame includes viewfinder and snapshot frames + IMAGE_FRAME_SYNC = 0x4, ///Image Frame is the image capture output frame + IMAGE_FRAME = 0x8, + VIDEO_FRAME_SYNC = 0x10, ///Timestamp will be updated for these frames + VIDEO_FRAME = 0x20, + FRAME_DATA_SYNC = 0x40, ///Any extra data assosicated with the frame. Always synced with the frame + FRAME_DATA= 0x80, + RAW_FRAME = 0x100, + SNAPSHOT_FRAME = 0x200, + REPROCESS_INPUT_FRAME = 0x400, + ALL_FRAMES = 0xFFFF ///Maximum of 16 frame types supported + }; + + enum FrameQuirks + { + ENCODE_RAW_YUV422I_TO_JPEG = 0x1 << 0, + HAS_EXIF_DATA = 0x1 << 1, + FORMAT_YUV422I_YUYV = 0x1 << 2, + FORMAT_YUV422I_UYVY = 0x1 << 3, + }; + + //default contrustor + CameraFrame(): + mCookie(NULL), + mCookie2(NULL), + mBuffer(NULL), + mFrameType(0), + mTimestamp(0), + mWidth(0), + mHeight(0), + mOffset(0), + mAlignment(0), + mFd(0), + mLength(0), + mFrameMask(0), + mQuirks(0) + { + mYuv[0] = 0; // NULL is meant for pointers + mYuv[1] = 0; // NULL is meant for pointers + +#ifdef OMAP_ENHANCEMENT_CPCAM + mMetaData = 0; +#endif + } + + void *mCookie; + void *mCookie2; + CameraBuffer *mBuffer; + int mFrameType; + nsecs_t mTimestamp; + unsigned int mWidth, mHeight; + uint32_t mOffset; + unsigned int mAlignment; + int mFd; + size_t mLength; + unsigned mFrameMask; + unsigned int mQuirks; + unsigned int mYuv[2]; +#ifdef OMAP_ENHANCEMENT_CPCAM + android::sp<CameraMetadataResult> mMetaData; +#endif + ///@todo add other member vars like stride etc +}; + +enum CameraHalError +{ + CAMERA_ERROR_FATAL = 0x1, //Fatal errors can only be recovered by restarting media server + CAMERA_ERROR_HARD = 0x2, // Hard errors are hardware hangs that may be recoverable by resetting the hardware internally within the adapter + CAMERA_ERROR_SOFT = 0x4, // Soft errors are non fatal errors that can be recovered from without needing to stop use-case +}; + +///Common Camera Hal Event class which is visible to CameraAdapter,DisplayAdapter and AppCallbackNotifier +///@todo Rename this class to CameraEvent +class CameraHalEvent +{ +public: + //Enums + enum CameraHalEventType { + NO_EVENTS = 0x0, + EVENT_FOCUS_LOCKED = 0x1, + EVENT_FOCUS_ERROR = 0x2, + EVENT_ZOOM_INDEX_REACHED = 0x4, + EVENT_SHUTTER = 0x8, + EVENT_METADATA = 0x10, + ///@remarks Future enum related to display, like frame displayed event, could be added here + ALL_EVENTS = 0xFFFF ///Maximum of 16 event types supported + }; + + enum FocusStatus { + FOCUS_STATUS_SUCCESS = 0x1, + FOCUS_STATUS_FAIL = 0x2, + FOCUS_STATUS_PENDING = 0x4, + FOCUS_STATUS_DONE = 0x8, + }; + + ///Class declarations + ///@remarks Add a new class for a new event type added above + + //Shutter event specific data + typedef struct ShutterEventData_t { + bool shutterClosed; + }ShutterEventData; + + ///Focus event specific data + typedef struct FocusEventData_t { + FocusStatus focusStatus; + int currentFocusValue; + } FocusEventData; + + ///Zoom specific event data + typedef struct ZoomEventData_t { + int currentZoomIndex; + bool targetZoomIndexReached; + } ZoomEventData; + + typedef struct FaceData_t { + ssize_t top; + ssize_t left; + ssize_t bottom; + ssize_t right; + size_t score; + } FaceData; + + typedef android::sp<CameraMetadataResult> MetaEventData; + + class CameraHalEventData : public android::RefBase{ + + public: + + CameraHalEvent::FocusEventData focusEvent; + CameraHalEvent::ZoomEventData zoomEvent; + CameraHalEvent::ShutterEventData shutterEvent; + CameraHalEvent::MetaEventData metadataEvent; + }; + + //default contrustor + CameraHalEvent(): + mCookie(NULL), + mEventType(NO_EVENTS) {} + + //copy constructor + CameraHalEvent(const CameraHalEvent &event) : + mCookie(event.mCookie), + mEventType(event.mEventType), + mEventData(event.mEventData) {}; + + void* mCookie; + CameraHalEventType mEventType; + android::sp<CameraHalEventData> mEventData; + +}; + +/// Have a generic callback class based on template - to adapt CameraFrame and Event +typedef void (*frame_callback) (CameraFrame *cameraFrame); +typedef void (*event_callback) (CameraHalEvent *event); + +//signals CameraHAL to relase image buffers +typedef void (*release_image_buffers_callback) (void *userData); +typedef void (*end_image_capture_callback) (void *userData); + +/** + * Interface class implemented by classes that have some events to communicate to dependendent classes + * Dependent classes use this interface for registering for events + */ +class MessageNotifier +{ +public: + static const uint32_t EVENT_BIT_FIELD_POSITION; + static const uint32_t FRAME_BIT_FIELD_POSITION; + + ///@remarks Msg type comes from CameraFrame and CameraHalEvent classes + /// MSB 16 bits is for events and LSB 16 bits is for frame notifications + /// FrameProvider and EventProvider classes act as helpers to event/frame + /// consumers to call this api + virtual void enableMsgType(int32_t msgs, frame_callback frameCb=NULL, event_callback eventCb=NULL, void* cookie=NULL) = 0; + virtual void disableMsgType(int32_t msgs, void* cookie) = 0; + + virtual ~MessageNotifier() {}; +}; + +class ErrorNotifier : public virtual android::RefBase +{ +public: + virtual void errorNotify(int error) = 0; + + virtual ~ErrorNotifier() {}; +}; + + +/** + * Interace class abstraction for Camera Adapter to act as a frame provider + * This interface is fully implemented by Camera Adapter + */ +class FrameNotifier : public MessageNotifier +{ +public: + virtual void returnFrame(CameraBuffer* frameBuf, CameraFrame::FrameType frameType) = 0; + virtual void addFramePointers(CameraBuffer *frameBuf, void *buf) = 0; + virtual void removeFramePointers() = 0; + + virtual ~FrameNotifier() {}; +}; + +/** * Wrapper class around Frame Notifier, which is used by display and notification classes for interacting with Camera Adapter + */ +class FrameProvider +{ + FrameNotifier* mFrameNotifier; + void* mCookie; + frame_callback mFrameCallback; + +public: + FrameProvider(FrameNotifier *fn, void* cookie, frame_callback frameCallback) + :mFrameNotifier(fn), mCookie(cookie),mFrameCallback(frameCallback) { } + + int enableFrameNotification(int32_t frameTypes); + int disableFrameNotification(int32_t frameTypes); + int returnFrame(CameraBuffer *frameBuf, CameraFrame::FrameType frameType); + void addFramePointers(CameraBuffer *frameBuf, void *buf); + void removeFramePointers(); +}; + +/** Wrapper class around MessageNotifier, which is used by display and notification classes for interacting with + * Camera Adapter + */ +class EventProvider +{ +public: + MessageNotifier* mEventNotifier; + void* mCookie; + event_callback mEventCallback; + +public: + EventProvider(MessageNotifier *mn, void* cookie, event_callback eventCallback) + :mEventNotifier(mn), mCookie(cookie), mEventCallback(eventCallback) {} + + int enableEventNotification(int32_t eventTypes); + int disableEventNotification(int32_t eventTypes); +}; + +/* + * Interface for providing buffers + */ +class BufferProvider +{ +public: + virtual CameraBuffer * allocateBufferList(int width, int height, const char* format, int &bytes, int numBufs) = 0; + + // gets a buffer list from BufferProvider when buffers are sent from external source and already pre-allocated + // only call this function for an input source into CameraHal. If buffers are not from a pre-allocated source + // this function will return NULL and numBufs of -1 + virtual CameraBuffer *getBufferList(int *numBufs) = 0; + + //additional methods used for memory mapping + virtual uint32_t * getOffsets() = 0; + virtual int getFd() = 0; + virtual CameraBuffer * getBuffers(bool reset = false) { return NULL; } + virtual unsigned int getSize() {return 0; } + virtual int getBufferCount() {return -1; } + + virtual int freeBufferList(CameraBuffer * buf) = 0; + + virtual ~BufferProvider() {} +}; + +/** + * Class for handling data and notify callbacks to application + */ +class AppCallbackNotifier: public ErrorNotifier , public virtual android::RefBase +{ + +public: + + ///Constants + static const int NOTIFIER_TIMEOUT; + static const int32_t MAX_BUFFERS = 8; + + enum NotifierCommands + { + NOTIFIER_CMD_PROCESS_EVENT, + NOTIFIER_CMD_PROCESS_FRAME, + NOTIFIER_CMD_PROCESS_ERROR + }; + + enum NotifierState + { + NOTIFIER_STOPPED, + NOTIFIER_STARTED, + NOTIFIER_EXITED + }; + +public: + + ~AppCallbackNotifier(); + + ///Initialzes the callback notifier, creates any resources required + status_t initialize(); + + ///Starts the callbacks to application + status_t start(); + + ///Stops the callbacks from going to application + status_t stop(); + + void setEventProvider(int32_t eventMask, MessageNotifier * eventProvider); + void setFrameProvider(FrameNotifier *frameProvider); + + //All sub-components of Camera HAL call this whenever any error happens + virtual void errorNotify(int error); + + status_t startPreviewCallbacks(android::CameraParameters ¶ms, CameraBuffer *buffers, uint32_t *offsets, int fd, size_t length, size_t count); + status_t stopPreviewCallbacks(); + + status_t enableMsgType(int32_t msgType); + status_t disableMsgType(int32_t msgType); + + //API for enabling/disabling measurement data + void setMeasurements(bool enable); + + //thread loops + bool notificationThread(); + + ///Notification callback functions + static void frameCallbackRelay(CameraFrame* caFrame); + static void eventCallbackRelay(CameraHalEvent* chEvt); + void frameCallback(CameraFrame* caFrame); + void eventCallback(CameraHalEvent* chEvt); + void flushAndReturnFrames(); + + void setCallbacks(CameraHal *cameraHal, + camera_notify_callback notify_cb, + camera_data_callback data_cb, + camera_data_timestamp_callback data_cb_timestamp, + camera_request_memory get_memory, + void *user); + + //Set Burst mode + void setBurst(bool burst); + + //Notifications from CameraHal for video recording case + status_t startRecording(); + status_t stopRecording(); + status_t initSharedVideoBuffers(CameraBuffer *buffers, uint32_t *offsets, int fd, size_t length, size_t count, CameraBuffer *vidBufs); + status_t releaseRecordingFrame(const void *opaque); + + status_t useMetaDataBufferMode(bool enable); + + void EncoderDoneCb(void*, void*, CameraFrame::FrameType type, void* cookie1, void* cookie2, void *cookie3); + + void useVideoBuffers(bool useVideoBuffers); + + bool getUesVideoBuffers(); + void setVideoRes(int width, int height); + + void flushEventQueue(); + void setExternalLocking(bool extBuffLocking); + + //Internal class definitions + class NotificationThread : public android::Thread { + AppCallbackNotifier* mAppCallbackNotifier; + Utils::MessageQueue mNotificationThreadQ; + public: + enum NotificationThreadCommands + { + NOTIFIER_START, + NOTIFIER_STOP, + NOTIFIER_EXIT, + }; + public: + NotificationThread(AppCallbackNotifier* nh) + : Thread(false), mAppCallbackNotifier(nh) { } + virtual bool threadLoop() { + return mAppCallbackNotifier->notificationThread(); + } + + Utils::MessageQueue &msgQ() { return mNotificationThreadQ;} + }; + + //Friend declarations + friend class NotificationThread; + +private: + void notifyEvent(); + void notifyFrame(); + bool processMessage(); + void releaseSharedVideoBuffers(); + status_t dummyRaw(); + void copyAndSendPictureFrame(CameraFrame* frame, int32_t msgType); + void copyAndSendPreviewFrame(CameraFrame* frame, int32_t msgType); + size_t calculateBufferSize(size_t width, size_t height, const char *pixelFormat); + const char* getContstantForPixelFormat(const char *pixelFormat); + void lockBufferAndUpdatePtrs(CameraFrame* frame); + void unlockBufferAndUpdatePtrs(CameraFrame* frame); + +private: + mutable android::Mutex mLock; + mutable android::Mutex mBurstLock; + CameraHal* mCameraHal; + camera_notify_callback mNotifyCb; + camera_data_callback mDataCb; + camera_data_timestamp_callback mDataCbTimestamp; + camera_request_memory mRequestMemory; + void *mCallbackCookie; + + //Keeps Video MemoryHeaps and Buffers within + //these objects + android::KeyedVector<unsigned int, unsigned int> mVideoHeaps; + android::KeyedVector<unsigned int, unsigned int> mVideoBuffers; + android::KeyedVector<void *, CameraBuffer *> mVideoMap; + + //Keeps list of Gralloc handles and associated Video Metadata Buffers + android::KeyedVector<void *, camera_memory_t *> mVideoMetadataBufferMemoryMap; + android::KeyedVector<void *, CameraBuffer *> mVideoMetadataBufferReverseMap; + + bool mBufferReleased; + + android::sp< NotificationThread> mNotificationThread; + EventProvider *mEventProvider; + FrameProvider *mFrameProvider; + Utils::MessageQueue mEventQ; + Utils::MessageQueue mFrameQ; + NotifierState mNotifierState; + + bool mPreviewing; + camera_memory_t* mPreviewMemory; + CameraBuffer mPreviewBuffers[MAX_BUFFERS]; + int mPreviewBufCount; + int mPreviewWidth; + int mPreviewHeight; + int mPreviewStride; + const char *mPreviewPixelFormat; + android::KeyedVector<unsigned int, android::sp<android::MemoryHeapBase> > mSharedPreviewHeaps; + android::KeyedVector<unsigned int, android::sp<android::MemoryBase> > mSharedPreviewBuffers; + + //Burst mode active + bool mBurst; + mutable android::Mutex mRecordingLock; + bool mRecording; + bool mMeasurementEnabled; + + bool mUseMetaDataBufferMode; + bool mRawAvailable; + + bool mUseVideoBuffers; + + int mVideoWidth; + int mVideoHeight; + + bool mExternalLocking; + +}; + + +/** + * Class used for allocating memory for JPEG bit stream buffers, output buffers of camera in no overlay case + */ +class MemoryManager : public BufferProvider, public virtual android::RefBase +{ +public: + MemoryManager(); + ~MemoryManager(); + + status_t initialize(); + + int setErrorHandler(ErrorNotifier *errorNotifier); + virtual CameraBuffer * allocateBufferList(int width, int height, const char* format, int &bytes, int numBufs); + virtual CameraBuffer *getBufferList(int *numBufs); + virtual uint32_t * getOffsets(); + virtual int getFd() ; + virtual int freeBufferList(CameraBuffer * buflist); + +private: + android::sp<ErrorNotifier> mErrorNotifier; + int mIonFd; +}; + + + + +/** + * CameraAdapter interface class + * Concrete classes derive from this class and provide implementations based on the specific camera h/w interface + */ + +class CameraAdapter: public FrameNotifier, public virtual android::RefBase +{ +protected: + enum AdapterActiveStates { + INTIALIZED_ACTIVE = 1 << 0, + LOADED_PREVIEW_ACTIVE = 1 << 1, + PREVIEW_ACTIVE = 1 << 2, + LOADED_CAPTURE_ACTIVE = 1 << 3, + CAPTURE_ACTIVE = 1 << 4, + BRACKETING_ACTIVE = 1 << 5, + AF_ACTIVE = 1 << 6, + ZOOM_ACTIVE = 1 << 7, + VIDEO_ACTIVE = 1 << 8, + LOADED_REPROCESS_ACTIVE = 1 << 9, + REPROCESS_ACTIVE = 1 << 10, + }; +public: + typedef struct + { + CameraBuffer *mBuffers; + uint32_t *mOffsets; + int mFd; + size_t mLength; + size_t mCount; + size_t mMaxQueueable; + } BuffersDescriptor; + + enum CameraCommands + { + CAMERA_START_PREVIEW = 0, + CAMERA_STOP_PREVIEW = 1, + CAMERA_START_VIDEO = 2, + CAMERA_STOP_VIDEO = 3, + CAMERA_START_IMAGE_CAPTURE = 4, + CAMERA_STOP_IMAGE_CAPTURE = 5, + CAMERA_PERFORM_AUTOFOCUS = 6, + CAMERA_CANCEL_AUTOFOCUS = 7, + CAMERA_PREVIEW_FLUSH_BUFFERS = 8, + CAMERA_START_SMOOTH_ZOOM = 9, + CAMERA_STOP_SMOOTH_ZOOM = 10, + CAMERA_USE_BUFFERS_PREVIEW = 11, + CAMERA_SET_TIMEOUT = 12, + CAMERA_CANCEL_TIMEOUT = 13, + CAMERA_START_BRACKET_CAPTURE = 14, + CAMERA_STOP_BRACKET_CAPTURE = 15, + CAMERA_QUERY_RESOLUTION_PREVIEW = 16, + CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE = 17, + CAMERA_QUERY_BUFFER_SIZE_PREVIEW_DATA = 18, + CAMERA_USE_BUFFERS_IMAGE_CAPTURE = 19, + CAMERA_USE_BUFFERS_PREVIEW_DATA = 20, + CAMERA_TIMEOUT_EXPIRED = 21, + CAMERA_START_FD = 22, + CAMERA_STOP_FD = 23, + CAMERA_SWITCH_TO_EXECUTING = 24, + CAMERA_USE_BUFFERS_VIDEO_CAPTURE = 25, +#ifdef OMAP_ENHANCEMENT_CPCAM + CAMERA_USE_BUFFERS_REPROCESS = 26, + CAMERA_START_REPROCESS = 27, +#endif +#ifdef OMAP_ENHANCEMENT_VTC + CAMERA_SETUP_TUNNEL = 28, + CAMERA_DESTROY_TUNNEL = 29, +#endif + CAMERA_PREVIEW_INITIALIZATION = 30, + }; + + enum CameraMode + { + CAMERA_PREVIEW, + CAMERA_IMAGE_CAPTURE, + CAMERA_VIDEO, + CAMERA_MEASUREMENT, + CAMERA_REPROCESS, + }; + + enum AdapterState { + INTIALIZED_STATE = INTIALIZED_ACTIVE, + LOADED_PREVIEW_STATE = LOADED_PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + PREVIEW_STATE = PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + LOADED_CAPTURE_STATE = LOADED_CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + CAPTURE_STATE = CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + BRACKETING_STATE = BRACKETING_ACTIVE | CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE , + AF_STATE = AF_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + ZOOM_STATE = ZOOM_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + VIDEO_STATE = VIDEO_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + VIDEO_AF_STATE = VIDEO_ACTIVE | AF_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + VIDEO_ZOOM_STATE = VIDEO_ACTIVE | ZOOM_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + VIDEO_LOADED_CAPTURE_STATE = VIDEO_ACTIVE | LOADED_CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + VIDEO_CAPTURE_STATE = VIDEO_ACTIVE | CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + AF_ZOOM_STATE = AF_ACTIVE | ZOOM_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + BRACKETING_ZOOM_STATE = BRACKETING_ACTIVE | ZOOM_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + LOADED_REPROCESS_STATE = LOADED_REPROCESS_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + LOADED_REPROCESS_CAPTURE_STATE = LOADED_REPROCESS_ACTIVE | LOADED_CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + REPROCESS_STATE = REPROCESS_ACTIVE | CAPTURE_ACTIVE | PREVIEW_ACTIVE | INTIALIZED_ACTIVE, + }; + + +public: + + ///Initialzes the camera adapter creates any resources required + virtual int initialize(CameraProperties::Properties*) = 0; + + virtual int setErrorHandler(ErrorNotifier *errorNotifier) = 0; + + //Message/Frame notification APIs + virtual void enableMsgType(int32_t msgs, + frame_callback callback = NULL, + event_callback eventCb = NULL, + void *cookie = NULL) = 0; + virtual void disableMsgType(int32_t msgs, void* cookie) = 0; + virtual void returnFrame(CameraBuffer* frameBuf, CameraFrame::FrameType frameType) = 0; + virtual void addFramePointers(CameraBuffer *frameBuf, void *buf) = 0; + virtual void removeFramePointers() = 0; + + //APIs to configure Camera adapter and get the current parameter set + virtual int setParameters(const android::CameraParameters& params) = 0; + virtual void getParameters(android::CameraParameters& params) = 0; + + //Registers callback for returning image buffers back to CameraHAL + virtual int registerImageReleaseCallback(release_image_buffers_callback callback, void *user_data) = 0; + + //Registers callback, which signals a completed image capture + virtual int registerEndCaptureCallback(end_image_capture_callback callback, void *user_data) = 0; + + //API to send a command to the camera + virtual status_t sendCommand(CameraCommands operation, int value1=0, int value2=0, int value3=0, int value4=0) = 0; + + virtual ~CameraAdapter() {}; + + //Retrieves the current Adapter state + virtual AdapterState getState() = 0; + + //Retrieves the next Adapter state + virtual AdapterState getNextState() = 0; + + // Receive orientation events from CameraHal + virtual void onOrientationEvent(uint32_t orientation, uint32_t tilt) = 0; + + // Rolls the state machine back to INTIALIZED_STATE from the current state + virtual status_t rollbackToInitializedState() = 0; + + // Retrieves the current Adapter state - for internal use (not locked) + virtual status_t getState(AdapterState &state) = 0; + // Retrieves the next Adapter state - for internal use (not locked) + virtual status_t getNextState(AdapterState &state) = 0; + + virtual status_t setSharedAllocator(camera_request_memory shmem_alloc) = 0; + +protected: + //The first two methods will try to switch the adapter state. + //Every call to setState() should be followed by a corresponding + //call to commitState(). If the state switch fails, then it will + //get reset to the previous state via rollbackState(). + virtual status_t setState(CameraCommands operation) = 0; + virtual status_t commitState() = 0; + virtual status_t rollbackState() = 0; +}; + +class DisplayAdapter : public BufferProvider, public virtual android::RefBase +{ +public: + DisplayAdapter(); + +#ifdef OMAP_ENHANCEMENT_CPCAM + preview_stream_extended_ops_t * extendedOps() const { + return mExtendedOps; + } + + void setExtendedOps(preview_stream_extended_ops_t * extendedOps); +#endif + + ///Initializes the display adapter creates any resources required + virtual int initialize() = 0; + + virtual int setPreviewWindow(struct preview_stream_ops *window) = 0; + virtual int setFrameProvider(FrameNotifier *frameProvider) = 0; + virtual int setErrorHandler(ErrorNotifier *errorNotifier) = 0; + virtual int enableDisplay(int width, int height, struct timeval *refTime = NULL) = 0; + virtual int disableDisplay(bool cancel_buffer = true) = 0; + //Used for Snapshot review temp. pause + virtual int pauseDisplay(bool pause) = 0; + +#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS + //Used for shot to snapshot measurement + virtual int setSnapshotTimeRef(struct timeval *refTime = NULL) = 0; +#endif + + virtual bool supportsExternalBuffering() = 0; + + // Get max queueable buffers display supports + // This function should only be called after + // allocateBufferList + virtual status_t maxQueueableBuffers(unsigned int& queueable) = 0; + + // Get min buffers display needs at any given time + virtual status_t minUndequeueableBuffers(int& unqueueable) = 0; + + // Given a vector of DisplayAdapters find the one corresponding to str + virtual bool match(const char * str) { return false; } + +private: +#ifdef OMAP_ENHANCEMENT_CPCAM + preview_stream_extended_ops_t * mExtendedOps; +#endif +}; + +static void releaseImageBuffers(void *userData); + +static void endImageCapture(void *userData); + + /** + Implementation of the Android Camera hardware abstraction layer + + This class implements the interface methods defined in CameraHardwareInterface + for the OMAP4 platform + +*/ +class CameraHal + +{ + +public: + enum SocFamily { + SocFamily_Undefined = -1, + SocFamily_Omap4430 = 0, + SocFamily_Omap4460, + SocFamily_Omap4470, + SocFamily_ElementCount // element count of SocFamily + }; + + ///Constants + static const int NO_BUFFERS_PREVIEW; + static const int NO_BUFFERS_IMAGE_CAPTURE; + static const int NO_BUFFERS_IMAGE_CAPTURE_SYSTEM_HEAP; + static const uint32_t VFR_SCALE = 1000; + + + /*--------------------Interface Methods---------------------------------*/ + + //@{ +public: + +#ifdef MOTOROLA_CAMERA + bool SetFlashLedTorch(unsigned intensity); +#endif + + /** Set the notification and data callbacks */ + void setCallbacks(camera_notify_callback notify_cb, + camera_data_callback data_cb, + camera_data_timestamp_callback data_cb_timestamp, + camera_request_memory get_memory, + void *user); + + /** Receives orientation events from SensorListener **/ + void onOrientationEvent(uint32_t orientation, uint32_t tilt); + + /** + * The following three functions all take a msgtype, + * which is a bitmask of the messages defined in + * include/ui/Camera.h + */ + + /** + * Enable a message, or set of messages. + */ + void enableMsgType(int32_t msgType); + + /** + * Disable a message, or a set of messages. + */ + void disableMsgType(int32_t msgType); + + /** + * Query whether a message, or a set of messages, is enabled. + * Note that this is operates as an AND, if any of the messages + * queried are off, this will return false. + */ + int msgTypeEnabled(int32_t msgType); + + /** + * Start preview mode. + */ + int startPreview(); + + /** + * Set preview mode related initialization. + * Only used when slice based processing is enabled. + */ + int cameraPreviewInitialization(); + + /** + * Only used if overlays are used for camera preview. + */ + int setPreviewWindow(struct preview_stream_ops *window); + +#ifdef OMAP_ENHANCEMENT_CPCAM + void setExtendedPreviewStreamOps(preview_stream_extended_ops_t *ops); + + /** + * Set a tap-in or tap-out point. + */ + int setBufferSource(struct preview_stream_ops *tapin, struct preview_stream_ops *tapout); +#endif + + /** + * Release a tap-in or tap-out point. + */ + int releaseBufferSource(struct preview_stream_ops *tapin, struct preview_stream_ops *tapout); + + /** + * Stop a previously started preview. + */ + void stopPreview(); + + /** + * Returns true if preview is enabled. + */ + bool previewEnabled(); + + /** + * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME + * message is sent with the corresponding frame. Every record frame must be released + * by calling releaseRecordingFrame(). + */ + int startRecording(); + + /** + * Stop a previously started recording. + */ + void stopRecording(); + + /** + * Returns true if recording is enabled. + */ + int recordingEnabled(); + + /** + * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME. + */ + void releaseRecordingFrame(const void *opaque); + + /** + * Start auto focus, the notification callback routine is called + * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() + * will be called again if another auto focus is needed. + */ + int autoFocus(); + + /** + * Cancels auto-focus function. If the auto-focus is still in progress, + * this function will cancel it. Whether the auto-focus is in progress + * or not, this function will return the focus position to the default. + * If the camera does not support auto-focus, this is a no-op. + */ + int cancelAutoFocus(); + + /** + * Take a picture. + */ + int takePicture(const char* params); + + /** + * Cancel a picture that was started with takePicture. Calling this + * method when no picture is being taken is a no-op. + */ + int cancelPicture(); + + /** Set the camera parameters. */ + int setParameters(const char* params); + int setParameters(const android::CameraParameters& params); + + /** Return the camera parameters. */ + char* getParameters(); + void putParameters(char *); + + /** + * Send command to camera driver. + */ + int sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); + + /** + * Release the hardware resources owned by this object. Note that this is + * *not* done in the destructor. + */ + void release(); + + /** + * Dump state of the camera hardware + */ + int dump(int fd) const; + +#ifdef OMAP_ENHANCEMENT_CPCAM + /** + * start a reprocessing operation. + */ + int reprocess(const char* params); + + /** + * cancels current reprocessing operation + */ + int cancel_reprocess(); +#endif + + status_t storeMetaDataInBuffers(bool enable); + + // Use external locking for graphic buffers + void setExternalLocking(bool extBuffLocking); + + //@} + +/*--------------------Internal Member functions - Public---------------------------------*/ + +public: + /** @name internalFunctionsPublic */ + //@{ + + /** Constructor of CameraHal */ + CameraHal(int cameraId); + + // Destructor of CameraHal + ~CameraHal(); + + /** Initialize CameraHal */ + status_t initialize(CameraProperties::Properties*); + + /** Deinitialize CameraHal */ + void deinitialize(); + +#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS + + //Uses the constructor timestamp as a reference to calcluate the + // elapsed time + static void PPM(const char *); + //Uses a user provided timestamp as a reference to calcluate the + // elapsed time + static void PPM(const char *, struct timeval*, ...); + +#endif + + /** Free image bufs */ + status_t freeImageBufs(); + + //Signals the end of image capture + status_t signalEndImageCapture(); + + //Events + static void eventCallbackRelay(CameraHalEvent* event); + void eventCallback(CameraHalEvent* event); + void setEventProvider(int32_t eventMask, MessageNotifier * eventProvider); + + static const char* getPixelFormatConstant(const char* parameters_format); + static size_t calculateBufferSize(const char* parameters_format, int width, int height); + static void getXYFromOffset(unsigned int *x, unsigned int *y, + unsigned int offset, unsigned int stride, + const char* format); + static unsigned int getBPP(const char* format); + static bool parsePair(const char *str, int *first, int *second, char delim); + +/*--------------------Internal Member functions - Private---------------------------------*/ +private: + + /** @name internalFunctionsPrivate */ + //@{ + + /** Set the camera parameters specific to Video Recording. */ + bool setVideoModeParameters(const android::CameraParameters&); + + /** Reset the camera parameters specific to Video Recording. */ + bool resetVideoModeParameters(); + + /** Restart the preview with setParameter. */ + status_t restartPreview(); + + status_t parseResolution(const char *resStr, int &width, int &height); + + void insertSupportedParams(); + + /** Allocate preview data buffers */ + status_t allocPreviewDataBufs(size_t size, size_t bufferCount); + + /** Free preview data buffers */ + status_t freePreviewDataBufs(); + + /** Allocate preview buffers */ + status_t allocPreviewBufs(int width, int height, const char* previewFormat, unsigned int bufferCount, unsigned int &max_queueable); + + /** Allocate video buffers */ + status_t allocVideoBufs(uint32_t width, uint32_t height, uint32_t bufferCount); + + /** Allocate image capture buffers */ + status_t allocImageBufs(unsigned int width, unsigned int height, size_t length, + const char* previewFormat, unsigned int bufferCount); + + /** Allocate Raw buffers */ + status_t allocRawBufs(int width, int height, const char* previewFormat, int bufferCount); + + /** Free preview buffers */ + status_t freePreviewBufs(); + + /** Free video bufs */ + status_t freeVideoBufs(CameraBuffer *bufs); + + /** Free RAW bufs */ + status_t freeRawBufs(); + + //Check if a given resolution is supported by the current camera + //instance + bool isResolutionValid(unsigned int width, unsigned int height, const char *supportedResolutions); + + //Check if a given variable frame rate range is supported by the current camera + //instance + bool isFpsRangeValid(int fpsMin, int fpsMax, const char *supportedFpsRanges); + + //Check if a given parameter is supported by the current camera + // instance + bool isParameterValid(const char *param, const char *supportedParams); + bool isParameterValid(int param, const char *supportedParams); + status_t doesSetParameterNeedUpdate(const char *new_param, const char *old_params, bool &update); + + /** Initialize default parameters */ + void initDefaultParameters(); + + void dumpProperties(CameraProperties::Properties& cameraProps); + + status_t startImageBracketing(); + + status_t stopImageBracketing(); + + void setShutter(bool enable); + + void forceStopPreview(); + + void resetPreviewRes(android::CameraParameters *params); + + // Internal __takePicture function - used in public takePicture() and reprocess() + int __takePicture(const char* params, struct timeval *captureStart = NULL); + //@} + + status_t setTapoutLocked(struct preview_stream_ops *out); + status_t releaseTapoutLocked(struct preview_stream_ops *out); + status_t setTapinLocked(struct preview_stream_ops *in); + status_t releaseTapinLocked(struct preview_stream_ops *in); + + static SocFamily getSocFamily(); + +#ifdef MOTOROLA_CAMERA + // I2C read write utility to support factory test commands + bool i2cRW(int read_size, int write_size, unsigned char *read_data, unsigned char *write_data); + + // get best flash intensity level for the current battery level + unsigned int getFlashIntensity(void); +#endif +/*----------Member variables - Public ---------------------*/ +public: + int32_t mMsgEnabled; + bool mRecordEnabled; + nsecs_t mCurrentTime; + bool mFalsePreview; + bool mPreviewEnabled; + uint32_t mTakePictureQueue; + bool mBracketingEnabled; + bool mBracketingRunning; + //User shutter override + bool mShutterEnabled; + bool mMeasurementEnabled; + //Google's parameter delimiter + static const char PARAMS_DELIMITER[]; + + CameraAdapter *mCameraAdapter; + android::sp<AppCallbackNotifier> mAppCallbackNotifier; + android::sp<DisplayAdapter> mDisplayAdapter; + android::sp<MemoryManager> mMemoryManager; + + android::Vector< android::sp<DisplayAdapter> > mOutAdapters; + android::Vector< android::sp<DisplayAdapter> > mInAdapters; + + // TODO(XXX): Even though we support user setting multiple BufferSourceAdapters now + // only one tap in surface and one tap out surface is supported at a time. + android::sp<DisplayAdapter> mBufferSourceAdapter_In; + android::sp<DisplayAdapter> mBufferSourceAdapter_Out; + +#ifdef OMAP_ENHANCEMENT_CPCAM + preview_stream_extended_ops_t * mExtendedPreviewStreamOps; +#endif + + android::sp<android::IMemoryHeap> mPictureHeap; + + int* mGrallocHandles; + bool mFpsRangeChangedByApp; + + + int mRawWidth; + int mRawHeight; + bool mRawCapture; + + +///static member vars + + static const int SW_SCALING_FPS_LIMIT; + +#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS + + //Timestamp from the CameraHal constructor + static struct timeval ppm_start; + //Timestamp of the autoFocus command + static struct timeval mStartFocus; + //Timestamp of the startPreview command + static struct timeval mStartPreview; + //Timestamp of the takePicture command + static struct timeval mStartCapture; + +#endif + +/*----------Member variables - Private ---------------------*/ +private: + bool mDynamicPreviewSwitch; + //keeps paused state of display + bool mDisplayPaused; + +#ifdef OMAP_ENHANCEMENT_VTC + bool mTunnelSetup; + bool mVTCUseCase; +#endif + + //Index of current camera adapter + int mCameraIndex; + + mutable android::Mutex mLock; + + android::sp<SensorListener> mSensorListener; + + void* mCameraAdapterHandle; + + android::CameraParameters mParameters; + bool mPreviewRunning; + bool mPreviewStateOld; + bool mRecordingEnabled; + EventProvider *mEventProvider; + + CameraBuffer *mPreviewDataBuffers; + uint32_t *mPreviewDataOffsets; + int mPreviewDataFd; + int mPreviewDataLength; + CameraBuffer *mImageBuffers; + uint32_t *mImageOffsets; + int mImageFd; + int mImageLength; + unsigned int mImageCount; + CameraBuffer *mPreviewBuffers; + uint32_t *mPreviewOffsets; + int mPreviewLength; + int mPreviewFd; + CameraBuffer *mVideoBuffers; + uint32_t *mVideoOffsets; + int mVideoFd; + int mVideoLength; + + int mBracketRangePositive; + int mBracketRangeNegative; + + ///@todo Rename this as preview buffer provider + BufferProvider *mBufProvider; + BufferProvider *mVideoBufProvider; + + + CameraProperties::Properties* mCameraProperties; + + bool mPreviewStartInProgress; + bool mPreviewInitializationDone; + + bool mSetPreviewWindowCalled; + + uint32_t mPreviewWidth; + uint32_t mPreviewHeight; + int32_t mMaxZoomSupported; + + int mVideoWidth; + int mVideoHeight; + + android::String8 mCapModeBackup; + + bool mExternalLocking; + + const SocFamily mSocFamily; +}; + +} // namespace Camera +} // namespace Ti + +#endif diff --git a/camera/inc/CameraProperties.h b/camera/inc/CameraProperties.h new file mode 100644 index 0000000..0c003c3 --- /dev/null +++ b/camera/inc/CameraProperties.h @@ -0,0 +1,244 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + + +#ifndef CAMERA_PROPERTIES_H +#define CAMERA_PROPERTIES_H + +#include <utils/KeyedVector.h> +#include <utils/String8.h> +#include <stdio.h> +#include <dirent.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> +#include "cutils/properties.h" + +#include "Common.h" + +namespace Ti { +namespace Camera { + +#ifndef MAX_CAMERAS_SUPPORTED +#define MAX_CAMERAS_SUPPORTED 3 +#endif +#define MAX_SIMUL_CAMERAS_SUPPORTED 1 +#define MAX_PROP_NAME_LENGTH 50 +#define MAX_PROP_VALUE_LENGTH 2048 + +#define REMAINING_BYTES(buff) ((((int)sizeof(buff) - 1 - (int)strlen(buff)) < 0) ? 0 : (sizeof(buff) - 1 - strlen(buff))) + +enum OperatingMode { + MODE_HIGH_SPEED = 0, + MODE_HIGH_QUALITY, + MODE_ZEROSHUTTERLAG, + MODE_VIDEO, + MODE_STEREO, + MODE_CPCAM, + MODE_VIDEO_HIGH_QUALITY, + MODE_MAX +}; + +// Class that handles the Camera Properties +class CameraProperties +{ +public: + static const char INVALID[]; + static const char CAMERA_NAME[]; + static const char CAMERA_SENSOR_INDEX[]; + static const char CAMERA_SENSOR_ID[]; + static const char ORIENTATION_INDEX[]; + static const char FACING_INDEX[]; + static const char SUPPORTED_PREVIEW_SIZES[]; + static const char SUPPORTED_PREVIEW_SUBSAMPLED_SIZES[]; + static const char SUPPORTED_PREVIEW_TOPBOTTOM_SIZES[]; + static const char SUPPORTED_PREVIEW_SIDEBYSIDE_SIZES[]; + static const char SUPPORTED_PREVIEW_FORMATS[]; + static const char SUPPORTED_PREVIEW_FRAME_RATES[]; + static const char SUPPORTED_PREVIEW_FRAME_RATES_EXT[]; + static const char SUPPORTED_PICTURE_SIZES[]; + static const char SUPPORTED_PICTURE_SUBSAMPLED_SIZES[]; + static const char SUPPORTED_PICTURE_TOPBOTTOM_SIZES[]; + static const char SUPPORTED_PICTURE_SIDEBYSIDE_SIZES[]; + static const char SUPPORTED_PICTURE_FORMATS[]; + static const char SUPPORTED_THUMBNAIL_SIZES[]; + static const char SUPPORTED_WHITE_BALANCE[]; + static const char SUPPORTED_EFFECTS[]; + static const char SUPPORTED_ANTIBANDING[]; + static const char SUPPORTED_EXPOSURE_MODES[]; + static const char SUPPORTED_MANUAL_EXPOSURE_MIN[]; + static const char SUPPORTED_MANUAL_EXPOSURE_MAX[]; + static const char SUPPORTED_MANUAL_EXPOSURE_STEP[]; + static const char SUPPORTED_MANUAL_GAIN_ISO_MIN[]; + static const char SUPPORTED_MANUAL_GAIN_ISO_MAX[]; + static const char SUPPORTED_MANUAL_GAIN_ISO_STEP[]; + static const char SUPPORTED_EV_MIN[]; + static const char SUPPORTED_EV_MAX[]; + static const char SUPPORTED_EV_STEP[]; + static const char SUPPORTED_ISO_VALUES[]; + static const char SUPPORTED_SCENE_MODES[]; + static const char SUPPORTED_FLASH_MODES[]; + static const char SUPPORTED_FOCUS_MODES[]; + static const char REQUIRED_PREVIEW_BUFS[]; + static const char REQUIRED_IMAGE_BUFS[]; + static const char SUPPORTED_ZOOM_RATIOS[]; + static const char SUPPORTED_ZOOM_STAGES[]; + static const char SUPPORTED_IPP_MODES[]; + static const char SMOOTH_ZOOM_SUPPORTED[]; + static const char ZOOM_SUPPORTED[]; + static const char PREVIEW_SIZE[]; + static const char PREVIEW_FORMAT[]; + static const char PREVIEW_FRAME_RATE[]; + static const char ZOOM[]; + static const char PICTURE_SIZE[]; + static const char PICTURE_FORMAT[]; + static const char JPEG_THUMBNAIL_SIZE[]; + static const char WHITEBALANCE[]; + static const char EFFECT[]; + static const char ANTIBANDING[]; + static const char EXPOSURE_MODE[]; + static const char EV_COMPENSATION[]; + static const char ISO_MODE[]; + static const char FOCUS_MODE[]; + static const char SCENE_MODE[]; + static const char FLASH_MODE[]; + static const char JPEG_QUALITY[]; + static const char BRIGHTNESS[]; + static const char SATURATION[]; + static const char SHARPNESS[]; + static const char CONTRAST[]; + static const char IPP[]; + static const char GBCE[]; + static const char SUPPORTED_GBCE[]; + static const char GLBCE[]; + static const char SUPPORTED_GLBCE[]; + static const char AUTOCONVERGENCE_MODE[]; + static const char AUTOCONVERGENCE_MODE_VALUES[]; + static const char MANUAL_CONVERGENCE[]; + static const char SUPPORTED_MANUAL_CONVERGENCE_MIN[]; + static const char SUPPORTED_MANUAL_CONVERGENCE_MAX[]; + static const char SUPPORTED_MANUAL_CONVERGENCE_STEP[]; + static const char SENSOR_ORIENTATION[]; + static const char SENSOR_ORIENTATION_VALUES[]; + static const char REVISION[]; + static const char FOCAL_LENGTH[]; + static const char HOR_ANGLE[]; + static const char VER_ANGLE[]; + static const char EXIF_MAKE[]; + static const char EXIF_MODEL[]; + static const char JPEG_THUMBNAIL_QUALITY[]; + static const char MAX_FOCUS_AREAS[]; + static const char MAX_FD_HW_FACES[]; + static const char MAX_FD_SW_FACES[]; + + static const char MAX_PICTURE_WIDTH[]; + static const char MAX_PICTURE_HEIGHT[]; + + static const char PARAMS_DELIMITER []; + + static const char S3D_PRV_FRAME_LAYOUT[]; + static const char S3D_PRV_FRAME_LAYOUT_VALUES[]; + static const char S3D_CAP_FRAME_LAYOUT[]; + static const char S3D_CAP_FRAME_LAYOUT_VALUES[]; + static const char VSTAB[]; + static const char VSTAB_SUPPORTED[]; + static const char VNF[]; + static const char VNF_SUPPORTED[]; + static const char FRAMERATE_RANGE[]; + static const char FRAMERATE_RANGE_SUPPORTED[]; + static const char FRAMERATE_RANGE_EXT_SUPPORTED[]; + + static const char DEFAULT_VALUE[]; + + static const char AUTO_EXPOSURE_LOCK[]; + static const char AUTO_EXPOSURE_LOCK_SUPPORTED[]; + static const char AUTO_WHITEBALANCE_LOCK[]; + static const char AUTO_WHITEBALANCE_LOCK_SUPPORTED[]; + static const char MAX_NUM_METERING_AREAS[]; + static const char METERING_AREAS[]; + static const char MAX_NUM_FOCUS_AREAS[]; + + static const char VIDEO_SNAPSHOT_SUPPORTED[]; + + static const char VIDEO_SIZE[]; + static const char SUPPORTED_VIDEO_SIZES[]; + + static const char MECHANICAL_MISALIGNMENT_CORRECTION_SUPPORTED[]; + static const char MECHANICAL_MISALIGNMENT_CORRECTION[]; + + static const char RAW_WIDTH[]; + static const char RAW_HEIGHT[]; + + static const char CAP_MODE_VALUES[]; + + CameraProperties(); + ~CameraProperties(); + + // container class passed around for accessing properties + class Properties + { + public: + + Properties() + { + } + + ~Properties() + { + } + + void set(const char *prop, const char *value); + void set(const char *prop, int value); + const char* get(const char * prop) const; + int getInt(const char * prop) const; + void setSensorIndex(int idx); + void setMode(OperatingMode mode); + OperatingMode getMode() const; + void dump(); + + protected: + const char* keyAt(const unsigned int) const; + const char* valueAt(const unsigned int) const; + + private: + OperatingMode mCurrentMode; + android::DefaultKeyedVector<android::String8, android::String8> mProperties[MODE_MAX]; + + }; + + ///Initializes the CameraProperties class + status_t initialize(); + status_t loadProperties(); + int camerasSupported(); + int getProperties(int cameraIndex, Properties** properties); + +private: + + int mCamerasSupported; + int mInitialized; + mutable android::Mutex mLock; + + Properties mCameraProps[MAX_CAMERAS_SUPPORTED]; + +}; + +} // namespace Camera +} // namespace Ti + +#endif //CAMERA_PROPERTIES_H diff --git a/camera/inc/Common.h b/camera/inc/Common.h new file mode 100644 index 0000000..b369e65 --- /dev/null +++ b/camera/inc/Common.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CAMERAHAL_COMMON_H +#define CAMERAHAL_COMMON_H + +#include "UtilsCommon.h" +#include "DebugUtils.h" +#include "Status.h" + + + + +// logging functions +#ifdef CAMERAHAL_DEBUG +# define CAMHAL_LOGD DBGUTILS_LOGD +# define CAMHAL_LOGDA DBGUTILS_LOGDA +# define CAMHAL_LOGDB DBGUTILS_LOGDB +# ifdef CAMERAHAL_DEBUG_VERBOSE +# define CAMHAL_LOGV DBGUTILS_LOGV +# define CAMHAL_LOGVA DBGUTILS_LOGVA +# define CAMHAL_LOGVB DBGUTILS_LOGVB +# else +# define CAMHAL_LOGV(...) +# define CAMHAL_LOGVA(str) +# define CAMHAL_LOGVB(str, ...) +# endif +#else +# define CAMHAL_LOGD(...) +# define CAMHAL_LOGDA(str) +# define CAMHAL_LOGDB(str, ...) +# define CAMHAL_LOGV(...) +# define CAMHAL_LOGVA(str) +# define CAMHAL_LOGVB(str, ...) +#endif + +#define CAMHAL_LOGI DBGUTILS_LOGI +#define CAMHAL_LOGW DBGUTILS_LOGW +#define CAMHAL_LOGE DBGUTILS_LOGE +#define CAMHAL_LOGEA DBGUTILS_LOGEA +#define CAMHAL_LOGEB DBGUTILS_LOGEB +#define CAMHAL_LOGF DBGUTILS_LOGF + +#define CAMHAL_ASSERT DBGUTILS_ASSERT +#define CAMHAL_ASSERT_X DBGUTILS_ASSERT_X + +#define CAMHAL_UNUSED(x) (void)x + + + + +#endif // CAMERAHAL_COMMON_H diff --git a/camera/inc/DecoderFactory.h b/camera/inc/DecoderFactory.h new file mode 100644 index 0000000..d5e566f --- /dev/null +++ b/camera/inc/DecoderFactory.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DECODERFACTORY_H_ +#define DECODERFACTORY_H_ + +#include "FrameDecoder.h" + +namespace Ti { +namespace Camera { + +class DecoderFactory { + DecoderFactory(); + ~DecoderFactory(); +public: + static FrameDecoder* createDecoderByType(DecoderType type, bool forceSwDecoder = false); +}; + +} // namespace Camera +} // namespace Ti + +#endif /* DECODERFACTORY_H_ */ diff --git a/camera/inc/Decoder_libjpeg.h b/camera/inc/Decoder_libjpeg.h new file mode 100644 index 0000000..425ebf1 --- /dev/null +++ b/camera/inc/Decoder_libjpeg.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_CAMERA_HARDWARE_DECODER_LIBJPEG_H +#define ANDROID_CAMERA_HARDWARE_DECODER_LIBJPEG_H + +#include "CameraHal.h" + +extern "C" { +#include "jhead.h" + +#undef TRUE +#undef FALSE + +} + + +namespace Ti { +namespace Camera { + +class Decoder_libjpeg +{ + +public: + Decoder_libjpeg(); + ~Decoder_libjpeg(); + static int readDHTSize(); + static bool isDhtExist(unsigned char *jpeg_src, int filled_len); + static int appendDHT(unsigned char *jpeg_src, int filled_len, unsigned char *jpeg_with_dht_buffer, int buff_size); + bool decode(unsigned char *jpeg_src, int filled_len, unsigned char *nv12_buffer, int stride); + +private: + void release(); + unsigned char **Y_Plane; + unsigned char **U_Plane; + unsigned char **V_Plane; + unsigned char *UV_Plane; + unsigned int mWidth, mHeight; +}; + +} // namespace Camera +} // namespace Ti + +#endif + diff --git a/camera/inc/Encoder_libjpeg.h b/camera/inc/Encoder_libjpeg.h new file mode 100644 index 0000000..72feb08 --- /dev/null +++ b/camera/inc/Encoder_libjpeg.h @@ -0,0 +1,226 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @file Encoder_libjpeg.h +* +* This defines API for camerahal to encode YUV using libjpeg +* +*/ + +#ifndef ANDROID_CAMERA_HARDWARE_ENCODER_LIBJPEG_H +#define ANDROID_CAMERA_HARDWARE_ENCODER_LIBJPEG_H + +#include <utils/threads.h> +#include <utils/RefBase.h> + +extern "C" { +#include "jhead.h" + +#undef TRUE +#undef FALSE + +} + +#include "CameraHal.h" + +#define CANCEL_TIMEOUT 5000000 // 5 seconds + +namespace Ti { +namespace Camera { + +/** + * libjpeg encoder class - uses libjpeg to encode yuv + */ + +#define MAX_EXIF_TAGS_SUPPORTED 30 +typedef void (*encoder_libjpeg_callback_t) (void* main_jpeg, + void* thumb_jpeg, + CameraFrame::FrameType type, + void* cookie1, + void* cookie2, + void* cookie3, + void* cookie4, + bool canceled); + +// these have to match strings defined in external/jhead/exif.c +static const char TAG_MODEL[] = "Model"; +static const char TAG_MAKE[] = "Make"; +static const char TAG_FOCALLENGTH[] = "FocalLength"; +static const char TAG_DATETIME[] = "DateTime"; +static const char TAG_IMAGE_WIDTH[] = "ImageWidth"; +static const char TAG_IMAGE_LENGTH[] = "ImageLength"; +static const char TAG_GPS_LAT[] = "GPSLatitude"; +static const char TAG_GPS_LAT_REF[] = "GPSLatitudeRef"; +static const char TAG_GPS_LONG[] = "GPSLongitude"; +static const char TAG_GPS_LONG_REF[] = "GPSLongitudeRef"; +static const char TAG_GPS_ALT[] = "GPSAltitude"; +static const char TAG_GPS_ALT_REF[] = "GPSAltitudeRef"; +static const char TAG_GPS_MAP_DATUM[] = "GPSMapDatum"; +static const char TAG_GPS_PROCESSING_METHOD[] = "GPSProcessingMethod"; +static const char TAG_GPS_VERSION_ID[] = "GPSVersionID"; +static const char TAG_GPS_TIMESTAMP[] = "GPSTimeStamp"; +static const char TAG_GPS_DATESTAMP[] = "GPSDateStamp"; +static const char TAG_ORIENTATION[] = "Orientation"; +static const char TAG_FLASH[] = "Flash"; +static const char TAG_DIGITALZOOMRATIO[] = "DigitalZoomRatio"; +static const char TAG_EXPOSURETIME[] = "ExposureTime"; +static const char TAG_APERTURE[] = "ApertureValue"; +static const char TAG_ISO_EQUIVALENT[] = "ISOSpeedRatings"; +static const char TAG_WHITEBALANCE[] = "WhiteBalance"; +static const char TAG_LIGHT_SOURCE[] = "LightSource"; +static const char TAG_METERING_MODE[] = "MeteringMode"; +static const char TAG_EXPOSURE_PROGRAM[] = "ExposureProgram"; +static const char TAG_COLOR_SPACE[] = "ColorSpace"; +static const char TAG_CPRS_BITS_PER_PIXEL[] = "CompressedBitsPerPixel"; +static const char TAG_FNUMBER[] = "FNumber"; +static const char TAG_SHUTTERSPEED[] = "ShutterSpeedValue"; +static const char TAG_SENSING_METHOD[] = "SensingMethod"; +static const char TAG_CUSTOM_RENDERED[] = "CustomRendered"; + +class ExifElementsTable { + public: + ExifElementsTable() : + gps_tag_count(0), exif_tag_count(0), position(0), + jpeg_opened(false) + { +#ifdef ANDROID_API_JB_OR_LATER + has_datetime_tag = false; +#endif + } + ~ExifElementsTable(); + + status_t insertElement(const char* tag, const char* value); + void insertExifToJpeg(unsigned char* jpeg, size_t jpeg_size); + status_t insertExifThumbnailImage(const char*, int); + void saveJpeg(unsigned char* picture, size_t jpeg_size); + static const char* degreesToExifOrientation(unsigned int); + static void stringToRational(const char*, unsigned int*, unsigned int*); + static bool isAsciiTag(const char* tag); + private: + ExifElement_t table[MAX_EXIF_TAGS_SUPPORTED]; + unsigned int gps_tag_count; + unsigned int exif_tag_count; + unsigned int position; + bool jpeg_opened; +#ifdef ANDROID_API_JB_OR_LATER + bool has_datetime_tag; +#endif +}; + +class Encoder_libjpeg : public android::Thread { + /* public member types and variables */ + public: + struct params { + uint8_t* src; + int src_size; + uint8_t* dst; + int dst_size; + int quality; + int in_width; + int in_height; + int out_width; + int out_height; + int right_crop; + int start_offset; + const char* format; + size_t jpeg_size; + }; + /* public member functions */ + public: + Encoder_libjpeg(params* main_jpeg, + params* tn_jpeg, + encoder_libjpeg_callback_t cb, + CameraFrame::FrameType type, + void* cookie1, + void* cookie2, + void* cookie3, void *cookie4) + : android::Thread(false), mMainInput(main_jpeg), mThumbnailInput(tn_jpeg), mCb(cb), + mCancelEncoding(false), mCookie1(cookie1), mCookie2(cookie2), mCookie3(cookie3), mCookie4(cookie4), + mType(type), mThumb(NULL) { + this->incStrong(this); + mCancelSem.Create(0); + } + + ~Encoder_libjpeg() { + CAMHAL_LOGVB("~Encoder_libjpeg(%p)", this); + } + + virtual bool threadLoop() { + size_t size = 0; + if (mThumbnailInput) { + // start thread to encode thumbnail + mThumb = new Encoder_libjpeg(mThumbnailInput, NULL, NULL, mType, NULL, NULL, NULL, NULL); + mThumb->run(); + } + + // encode our main image + size = encode(mMainInput); + + // signal cancel semaphore incase somebody is waiting + mCancelSem.Signal(); + + // check if it is main jpeg thread + if(mThumb.get()) { + // wait until tn jpeg thread exits. + mThumb->join(); + mThumb.clear(); + mThumb = NULL; + } + + if(mCb) { + mCb(mMainInput, mThumbnailInput, mType, mCookie1, mCookie2, mCookie3, mCookie4, mCancelEncoding); + } + + // encoder thread runs, self-destructs, and then exits + this->decStrong(this); + return false; + } + + void cancel() { + mCancelEncoding = true; + if (mThumb.get()) { + mThumb->cancel(); + mCancelSem.WaitTimeout(CANCEL_TIMEOUT); + } + } + + void getCookies(void **cookie1, void **cookie2, void **cookie3) { + if (cookie1) *cookie1 = mCookie1; + if (cookie2) *cookie2 = mCookie2; + if (cookie3) *cookie3 = mCookie3; + } + + private: + params* mMainInput; + params* mThumbnailInput; + encoder_libjpeg_callback_t mCb; + bool mCancelEncoding; + void* mCookie1; + void* mCookie2; + void* mCookie3; + void* mCookie4; + CameraFrame::FrameType mType; + android::sp<Encoder_libjpeg> mThumb; + Utils::Semaphore mCancelSem; + + size_t encode(params*); +}; + +} // namespace Camera +} // namespace Ti + +#endif diff --git a/camera/inc/FrameDecoder.h b/camera/inc/FrameDecoder.h new file mode 100644 index 0000000..fab0544 --- /dev/null +++ b/camera/inc/FrameDecoder.h @@ -0,0 +1,173 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEDECODER_H_ +#define FRAMEDECODER_H_ + +#include <utils/Vector.h> +#include <utils/StrongPointer.h> +#include "CameraHal.h" + + +namespace Ti { +namespace Camera { + +enum DecoderType { + DecoderType_MJPEG, + DecoderType_H264 +}; + +enum BufferStatus { + BufferStatus_Unknown, + BufferStatus_InQueued, + BufferStatus_InWaitForEmpty, + BufferStatus_InDecoded, + BufferStatus_OutQueued, + BufferStatus_OutWaitForFill, + BufferStatus_OutFilled +}; + +enum DecoderState { + DecoderState_Uninitialized, + DecoderState_Initialized, + DecoderState_Running, + DecoderState_Requested_Stop, + DecoderState_Stoppped +}; + +class MediaBuffer: public virtual android::RefBase { + +public: + MediaBuffer() + : bufferId(-1), buffer(0), filledLen(0), size(0), + mOffset(0), mTimestamp(0), mStatus(BufferStatus_Unknown) { + } + + MediaBuffer(int id, void* buffer, size_t buffSize = 0) + : bufferId(id), buffer(buffer), filledLen(0), size(buffSize), + mOffset(0), mTimestamp(0), mStatus(BufferStatus_Unknown) { + } + + virtual ~MediaBuffer() { + } + + int bufferId; + void* buffer; + int filledLen; + size_t size; + + nsecs_t getTimestamp() const { + return mTimestamp; + } + void setTimestamp(nsecs_t ts) { + mTimestamp = ts; + } + + BufferStatus getStatus() const { + return mStatus; + } + + void setStatus(BufferStatus status) { + mStatus = status; + } + + android::Mutex& getLock() const { + return mLock; + } + + uint32_t getOffset() const { + return mOffset; + } + + void setOffset(uint32_t offset) { + mOffset = offset; + } + +private: + uint32_t mOffset; + nsecs_t mTimestamp; + BufferStatus mStatus; + mutable android::Mutex mLock; +}; + +struct DecoderParameters { + int width; + int height; + int inputBufferCount; + int outputBufferCount; +}; + +class FrameDecoder { +public: + FrameDecoder(); + virtual ~FrameDecoder(); + void configure(const DecoderParameters& config); + status_t start(); + void stop(); + void release(); + void flush(); + status_t queueInputBuffer(int id); + status_t dequeueInputBuffer(int &id); + status_t queueOutputBuffer(int id); + status_t dequeueOutputBuffer(int &id); + + void registerOutputBuffers(android::Vector< android::sp<MediaBuffer> > *outBuffers) { + android::AutoMutex lock(mLock); + mOutQueue.clear(); + mOutBuffers = outBuffers; + } + + void registerInputBuffers(android::Vector< android::sp<MediaBuffer> > *inBuffers) { + android::AutoMutex lock(mLock); + mInQueue.clear(); + mInBuffers = inBuffers; + } + + virtual bool getPaddedDimensions(size_t &width, size_t &height) { + return false; + } + + void setHal(CameraHal* hal) { + mCameraHal = hal; + } + +protected: + virtual void doConfigure(const DecoderParameters& config) = 0; + virtual void doProcessInputBuffer() = 0; + virtual status_t doStart() = 0; + virtual void doStop() = 0; + virtual void doFlush() = 0; + virtual void doRelease() = 0; + + DecoderParameters mParams; + + android::Vector<int> mInQueue; + android::Vector<int> mOutQueue; + + android::Vector< android::sp<MediaBuffer> >* mInBuffers; + android::Vector< android::sp<MediaBuffer> >* mOutBuffers; + + CameraHal* mCameraHal; + +private: + DecoderState mState; + android::Mutex mLock; +}; + +} // namespace Camera +} // namespace Ti + +#endif /* FRAMEDECODER_H_ */ diff --git a/camera/inc/General3A_Settings.h b/camera/inc/General3A_Settings.h new file mode 100644 index 0000000..c1e017c --- /dev/null +++ b/camera/inc/General3A_Settings.h @@ -0,0 +1,295 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @file General3A_Settings.h +* +* This file maps the Camera Hardware Interface to OMX. +* +*/ + +#include "OMX_TI_IVCommon.h" +#include "OMX_TI_Common.h" +#include "OMX_TI_Index.h" +#include "TICameraParameters.h" + +#ifndef GENERAL_3A_SETTINGS_H +#define GENERAL_3A_SETTINGS_H + +namespace Ti { +namespace Camera { + +struct userToOMX_LUT{ + const char * userDefinition; + int omxDefinition; +}; + +struct LUTtype{ + int size; + const userToOMX_LUT *Table; +}; + +const userToOMX_LUT isoUserToOMX[] = { + { TICameraParameters::ISO_MODE_AUTO, 0 }, + { TICameraParameters::ISO_MODE_100, 100 }, + { TICameraParameters::ISO_MODE_200, 200 }, + { TICameraParameters::ISO_MODE_400, 400 }, + { TICameraParameters::ISO_MODE_800, 800 }, + { TICameraParameters::ISO_MODE_1000, 1000 }, + { TICameraParameters::ISO_MODE_1200, 1200 }, + { TICameraParameters::ISO_MODE_1600, 1600 }, +}; + +const userToOMX_LUT effects_UserToOMX [] = { + { android::CameraParameters::EFFECT_NONE, OMX_ImageFilterNone }, + { android::CameraParameters::EFFECT_NEGATIVE, OMX_ImageFilterNegative }, + { android::CameraParameters::EFFECT_SOLARIZE, OMX_ImageFilterSolarize }, + { android::CameraParameters::EFFECT_SEPIA, OMX_ImageFilterSepia }, + { android::CameraParameters::EFFECT_MONO, OMX_ImageFilterGrayScale }, + { android::CameraParameters::EFFECT_BLACKBOARD, OMX_TI_ImageFilterBlackBoard }, + { android::CameraParameters::EFFECT_WHITEBOARD, OMX_TI_ImageFilterWhiteBoard }, + { android::CameraParameters::EFFECT_AQUA, OMX_TI_ImageFilterAqua }, + { android::CameraParameters::EFFECT_POSTERIZE, OMX_TI_ImageFilterPosterize }, +#ifdef OMAP_ENHANCEMENT + { TICameraParameters::EFFECT_NATURAL, OMX_ImageFilterNatural }, + { TICameraParameters::EFFECT_VIVID, OMX_ImageFilterVivid }, + { TICameraParameters::EFFECT_COLOR_SWAP, OMX_ImageFilterColourSwap }, + { TICameraParameters::EFFECT_BLACKWHITE, OMX_TI_ImageFilterBlackWhite } +#endif +}; + +const userToOMX_LUT scene_UserToOMX [] = { + { android::CameraParameters::SCENE_MODE_AUTO, OMX_Manual }, + { android::CameraParameters::SCENE_MODE_LANDSCAPE, OMX_Landscape }, + { android::CameraParameters::SCENE_MODE_NIGHT_PORTRAIT, OMX_NightPortrait }, + { android::CameraParameters::SCENE_MODE_FIREWORKS, OMX_Fireworks }, + { android::CameraParameters::SCENE_MODE_ACTION, OMX_TI_Action }, + { android::CameraParameters::SCENE_MODE_BEACH, OMX_TI_Beach }, + { android::CameraParameters::SCENE_MODE_CANDLELIGHT, OMX_TI_Candlelight }, + { android::CameraParameters::SCENE_MODE_NIGHT, OMX_TI_Night }, + { android::CameraParameters::SCENE_MODE_PARTY, OMX_TI_Party }, + { android::CameraParameters::SCENE_MODE_PORTRAIT, OMX_TI_Portrait }, + { android::CameraParameters::SCENE_MODE_SNOW, OMX_TI_Snow }, + { android::CameraParameters::SCENE_MODE_STEADYPHOTO, OMX_TI_Steadyphoto }, + { android::CameraParameters::SCENE_MODE_SUNSET, OMX_TI_Sunset }, + { android::CameraParameters::SCENE_MODE_THEATRE, OMX_TI_Theatre }, + { android::CameraParameters::SCENE_MODE_SPORTS, OMX_Sport }, +#ifdef OMAP_ENHANCEMENT + { TICameraParameters::SCENE_MODE_CLOSEUP, OMX_Closeup }, + { TICameraParameters::SCENE_MODE_AQUA, OMX_Underwater }, + { TICameraParameters::SCENE_MODE_MOOD, OMX_Mood }, + { TICameraParameters::SCENE_MODE_NIGHT_INDOOR, OMX_NightIndoor }, + { TICameraParameters::SCENE_MODE_DOCUMENT, OMX_Document }, + { TICameraParameters::SCENE_MODE_BARCODE, OMX_Barcode }, + { TICameraParameters::SCENE_MODE_VIDEO_SUPER_NIGHT, OMX_SuperNight }, + { TICameraParameters::SCENE_MODE_VIDEO_CINE, OMX_Cine }, + { TICameraParameters::SCENE_MODE_VIDEO_OLD_FILM, OMX_OldFilm }, +#endif +}; + +const userToOMX_LUT whiteBal_UserToOMX [] = { + { android::CameraParameters::WHITE_BALANCE_AUTO, OMX_WhiteBalControlAuto }, + { android::CameraParameters::WHITE_BALANCE_DAYLIGHT, OMX_WhiteBalControlSunLight }, + { android::CameraParameters::WHITE_BALANCE_CLOUDY_DAYLIGHT, OMX_WhiteBalControlCloudy }, + { android::CameraParameters::WHITE_BALANCE_FLUORESCENT, OMX_WhiteBalControlFluorescent }, + { android::CameraParameters::WHITE_BALANCE_INCANDESCENT, OMX_WhiteBalControlIncandescent }, + { android::CameraParameters::WHITE_BALANCE_SHADE, OMX_TI_WhiteBalControlShade }, + { android::CameraParameters::WHITE_BALANCE_TWILIGHT, OMX_TI_WhiteBalControlTwilight }, + { android::CameraParameters::WHITE_BALANCE_WARM_FLUORESCENT, OMX_TI_WhiteBalControlWarmFluorescent }, +#ifdef OMAP_ENHANCEMENT + { TICameraParameters::WHITE_BALANCE_TUNGSTEN, OMX_WhiteBalControlTungsten }, + { TICameraParameters::WHITE_BALANCE_HORIZON, OMX_WhiteBalControlHorizon }, + { TICameraParameters::WHITE_BALANCE_SUNSET, OMX_TI_WhiteBalControlSunset } +#endif +}; + +const userToOMX_LUT antibanding_UserToOMX [] = { + { android::CameraParameters::ANTIBANDING_OFF, OMX_FlickerCancelOff }, + { android::CameraParameters::ANTIBANDING_AUTO, OMX_FlickerCancelAuto }, + { android::CameraParameters::ANTIBANDING_50HZ, OMX_FlickerCancel50 }, + { android::CameraParameters::ANTIBANDING_60HZ, OMX_FlickerCancel60 } +}; + +const userToOMX_LUT focus_UserToOMX [] = { + { android::CameraParameters::FOCUS_MODE_AUTO, OMX_IMAGE_FocusControlAutoLock }, + { android::CameraParameters::FOCUS_MODE_INFINITY, OMX_IMAGE_FocusControlAutoInfinity }, + { android::CameraParameters::FOCUS_MODE_INFINITY, OMX_IMAGE_FocusControlHyperfocal }, + { android::CameraParameters::FOCUS_MODE_MACRO, OMX_IMAGE_FocusControlAutoMacro }, + { android::CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO, OMX_IMAGE_FocusControlAuto }, + { android::CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE, OMX_IMAGE_FocusControlAuto }, +#ifdef OMAP_ENHANCEMENT + { TICameraParameters::FOCUS_MODE_FACE , OMX_IMAGE_FocusControlContinousFacePriority }, + { TICameraParameters::FOCUS_MODE_PORTRAIT, OMX_IMAGE_FocusControlPortrait }, + { TICameraParameters::FOCUS_MODE_EXTENDED, OMX_IMAGE_FocusControlExtended }, +#endif + { TICameraParameters::FOCUS_MODE_OFF , OMX_IMAGE_FocusControlOff } +}; + +const userToOMX_LUT exposure_UserToOMX [] = { + { TICameraParameters::EXPOSURE_MODE_MANUAL, OMX_ExposureControlOff }, + { TICameraParameters::EXPOSURE_MODE_AUTO, OMX_ExposureControlAuto }, + { TICameraParameters::EXPOSURE_MODE_NIGHT, OMX_ExposureControlNight }, + { TICameraParameters::EXPOSURE_MODE_BACKLIGHT, OMX_ExposureControlBackLight }, + { TICameraParameters::EXPOSURE_MODE_SPOTLIGHT, OMX_ExposureControlSpotLight}, + { TICameraParameters::EXPOSURE_MODE_SPORTS, OMX_ExposureControlSports }, + { TICameraParameters::EXPOSURE_MODE_SNOW, OMX_ExposureControlSnow }, + { TICameraParameters::EXPOSURE_MODE_BEACH, OMX_ExposureControlBeach }, + { TICameraParameters::EXPOSURE_MODE_APERTURE, OMX_ExposureControlLargeAperture }, + { TICameraParameters::EXPOSURE_MODE_SMALL_APERTURE, OMX_ExposureControlSmallApperture }, +}; + +const userToOMX_LUT flash_UserToOMX [] = { + { android::CameraParameters::FLASH_MODE_OFF ,OMX_IMAGE_FlashControlOff }, + { android::CameraParameters::FLASH_MODE_ON ,OMX_IMAGE_FlashControlOn }, + { android::CameraParameters::FLASH_MODE_AUTO ,OMX_IMAGE_FlashControlAuto }, + { android::CameraParameters::FLASH_MODE_TORCH ,OMX_IMAGE_FlashControlTorch }, + { android::CameraParameters::FLASH_MODE_RED_EYE ,OMX_IMAGE_FlashControlRedEyeReduction }, +#ifdef OMAP_ENHANCEMENT + { TICameraParameters::FLASH_MODE_FILL_IN ,OMX_IMAGE_FlashControlFillin } +#endif +}; + +const LUTtype ExpLUT = + { + sizeof(exposure_UserToOMX)/sizeof(exposure_UserToOMX[0]), + exposure_UserToOMX + }; + +const LUTtype WBalLUT = + { + sizeof(whiteBal_UserToOMX)/sizeof(whiteBal_UserToOMX[0]), + whiteBal_UserToOMX + }; + +const LUTtype FlickerLUT = + { + sizeof(antibanding_UserToOMX)/sizeof(antibanding_UserToOMX[0]), + antibanding_UserToOMX + }; + +const LUTtype SceneLUT = + { + sizeof(scene_UserToOMX)/sizeof(scene_UserToOMX[0]), + scene_UserToOMX + }; + +const LUTtype FlashLUT = + { + sizeof(flash_UserToOMX)/sizeof(flash_UserToOMX[0]), + flash_UserToOMX + }; + +const LUTtype EffLUT = + { + sizeof(effects_UserToOMX)/sizeof(effects_UserToOMX[0]), + effects_UserToOMX + }; + +const LUTtype FocusLUT = + { + sizeof(focus_UserToOMX)/sizeof(focus_UserToOMX[0]), + focus_UserToOMX + }; + +const LUTtype IsoLUT = + { + sizeof(isoUserToOMX)/sizeof(isoUserToOMX[0]), + isoUserToOMX + }; + +/* +* class Gen3A_settings +* stores the 3A settings +* also defines the look up tables +* for mapping settings from Hal to OMX +*/ +class Gen3A_settings{ + public: + + int Exposure; + int WhiteBallance; + int Flicker; + int SceneMode; + int Effect; + int Focus; + int EVCompensation; + int Contrast; + int Saturation; + int Sharpness; + int ISO; + int FlashMode; + int ManualExposure; + int ManualExposureRight; + int ManualGain; + int ManualGainRight; + + unsigned int Brightness; + OMX_BOOL ExposureLock; + OMX_BOOL FocusLock; + OMX_BOOL WhiteBalanceLock; + + OMX_BOOL AlgoExternalGamma; + OMX_BOOL AlgoNSF1; + OMX_BOOL AlgoNSF2; + OMX_BOOL AlgoSharpening; + OMX_BOOL AlgoThreeLinColorMap; + OMX_BOOL AlgoGIC; + + OMX_TI_CONFIG_GAMMATABLE_TYPE mGammaTable; + +}; + +/* +* Flags raised when a setting is changed +*/ +enum E3ASettingsFlags +{ + SetSceneMode = 1 << 0, + SetEVCompensation = 1 << 1, + SetWhiteBallance = 1 << 2, + SetFlicker = 1 << 3, + SetExposure = 1 << 4, + SetSharpness = 1 << 5, + SetBrightness = 1 << 6, + SetContrast = 1 << 7, + SetISO = 1 << 8, + SetSaturation = 1 << 9, + SetEffect = 1 << 10, + SetFocus = 1 << 11, + SetExpMode = 1 << 14, + SetFlash = 1 << 15, + SetExpLock = 1 << 16, + SetWBLock = 1 << 17, + SetMeteringAreas = 1 << 18, + SetManualExposure = 1 << 19, + + SetAlgoExternalGamma = 1 << 20, + SetAlgoNSF1 = 1 << 21, + SetAlgoNSF2 = 1 << 22, + SetAlgoSharpening = 1 << 23, + SetAlgoThreeLinColorMap = 1 << 24, + SetAlgoGIC = 1 << 25, + SetGammaTable = 1 << 26, + + + E3aSettingMax, + E3AsettingsAll = ( ((E3aSettingMax -1 ) << 1) -1 ) /// all possible flags raised +}; + +} // namespace Camera +} // namespace Ti + +#endif //GENERAL_3A_SETTINGS_H diff --git a/camera/inc/NV12_resize.h b/camera/inc/NV12_resize.h new file mode 100644 index 0000000..4b05a4f --- /dev/null +++ b/camera/inc/NV12_resize.h @@ -0,0 +1,135 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NV12_RESIZE_H_ +#define NV12_RESIZE_H_ + +#include "Common.h" + +typedef unsigned char mmBool; +typedef unsigned char mmUchar; +typedef unsigned char mmUint8; +typedef unsigned char mmByte; +typedef unsigned short mmUint16; +typedef unsigned int mmUint32; +typedef unsigned long mmUint64; +typedef signed char mmInt8; +typedef char mmChar; +typedef signed short mmInt16; +typedef signed int mmInt32; +typedef signed long mmLong; +typedef signed int mmHandle; +typedef float mmFloat; +typedef double mmDouble; +typedef int HObj; +typedef HObj HFile; +typedef int HDir; +typedef void* mmMutexHandle; +typedef struct _fstat { + mmInt32 fileSize; +} VE_FileAttribute; + +typedef struct { + mmInt32 second; + mmInt32 millisecond; +} tsVE_Time; + +typedef struct { + mmInt32 year; + mmInt32 month; + mmInt32 day; + mmInt32 hour; + mmInt32 minute; + mmInt32 second; +} TmDateTime; + +const mmUint8 bWeights[8][8][4] = { + {{64, 0, 0, 0}, {56, 0, 0, 8}, {48, 0, 0,16}, {40, 0, 0,24}, + {32, 0, 0,32}, {24, 0, 0,40}, {16, 0, 0,48}, { 8, 0, 0,56}}, + + {{56, 8, 0, 0}, {49, 7, 1, 7}, {42, 6, 2,14}, {35, 5, 3,21}, + {28, 4, 4,28}, {21, 3, 5,35}, {14, 2, 6,42}, { 7, 1, 7,49}}, + + {{48,16, 0, 0}, {42,14, 2, 6}, {36,12,4 ,12}, {30,10,6 ,18}, + {24, 8, 8,24}, {18, 6,10,30}, {12,4 ,12,36}, { 6, 2,14,42}}, + + {{40,24,0 ,0 }, {35,21, 3, 5}, {30,18, 6,10}, {25,15, 9,15}, + {20,12,12,20}, {15, 9,15,25}, {10, 6,18,30}, { 5, 3,21,35}}, + + {{32,32, 0,0 }, {28,28, 4, 4}, {24,24, 8, 8}, {20,20,12,12}, + {16,16,16,16}, {12,12,20,20}, { 8, 8,24,24}, { 4, 4,28,28}}, + + {{24,40,0 ,0 }, {21,35, 5, 3}, {18,30,10, 6}, {15,25,15, 9}, + {12,20,20,12}, { 9,15,25,15}, { 6,10,30,18}, { 3, 5,35,21}}, + + {{16,48, 0,0 }, {14,42, 6, 2}, {12,36,12, 4}, {10,30,18, 6}, + {8 ,24,24,8 }, { 6,18,30,10}, { 4,12,36,12}, { 2, 6,42,14}}, + + {{ 8,56, 0,0 }, { 7,49, 7, 1}, { 6,42,14, 2}, { 5,35,21, 3}, + { 4,28,28,4 }, { 3,21,35, 5}, { 2,14,42, 6}, { 1,7 ,49, 7}} +}; + +typedef enum { + IC_FORMAT_NONE, + IC_FORMAT_RGB565, + IC_FORMAT_RGB888, + IC_FORMAT_YCbCr420_lp, + IC_FORMAT_YCbCr, + IC_FORMAT_YCbCr420_FRAME_PK, + IC_FORMAT_MAX +} enumImageFormat; + +/* This structure defines the format of an image */ +typedef struct { + mmInt32 uWidth; + mmInt32 uHeight; + mmInt32 uStride; + enumImageFormat eFormat; + mmByte *imgPtr; + mmByte *clrPtr; + mmInt32 uOffset; +} structConvImage; + +typedef struct IC_crop_struct { + mmUint32 x; /* x pos of rectangle */ + mmUint32 y; /* y pos of rectangle */ + mmUint32 uWidth; /* dx of rectangle */ + mmUint32 uHeight; /* dy of rectangle */ +} IC_rect_type; + +/*========================================================================== +* Function Name : VT_resizeFrame_Video_opt2_lp +* +* Description : Resize a yuv frame. +* +* Input(s) : input_img_ptr -> Input Image Structure +* : output_img_ptr -> Output Image Structure +* : cropout -> crop structure +* +* Value Returned : mmBool -> FALSE on error TRUE on success +* NOTE: +* Not tested for crop funtionallity. +* faster version. +============================================================================*/ +mmBool +VT_resizeFrame_Video_opt2_lp( + structConvImage* i_img_ptr, /* Points to the input image */ + structConvImage* o_img_ptr, /* Points to the output image */ + IC_rect_type* cropout, /* how much to resize to in final image */ + mmUint16 dummy /* Transparent pixel value */ + ); + +#endif //#define NV12_RESIZE_H_ diff --git a/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h b/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h new file mode 100644 index 0000000..10590df --- /dev/null +++ b/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h @@ -0,0 +1,1235 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#ifndef OMX_CAMERA_ADAPTER_H +#define OMX_CAMERA_ADAPTER_H + +#include "CameraHal.h" +#include "OMX_Types.h" +#include "OMX_Core.h" +#include "OMX_CoreExt.h" +#include "OMX_IVCommon.h" +#include "OMX_Component.h" +#include "OMX_Index.h" +#include "OMX_IndexExt.h" +#include "OMX_TI_Index.h" +#include "OMX_TI_IVCommon.h" +#include "OMX_TI_Common.h" +#include "OMX_TI_Image.h" +#include "General3A_Settings.h" +#include "OMXSceneModeTables.h" + +#include "BaseCameraAdapter.h" +#include "Encoder_libjpeg.h" +#include "DebugUtils.h" + + +extern "C" +{ +#include "timm_osal_error.h" +#include "timm_osal_events.h" +#include "timm_osal_trace.h" +#include "timm_osal_semaphores.h" +} + + +namespace Ti { +namespace Camera { + +#define Q16_OFFSET 16 + +#define OMX_CMD_TIMEOUT 3000000 //3 sec. +#define OMX_CAPTURE_TIMEOUT 5000000 //5 sec. + +#define FOCUS_THRESHOLD 5 //[s.] + +#define MIN_JPEG_QUALITY 1 +#define MAX_JPEG_QUALITY 100 +#define EXP_BRACKET_RANGE 10 +#define ZOOM_BRACKET_RANGE 10 + +#define FOCUS_DIST_SIZE 100 +#define FOCUS_DIST_BUFFER_SIZE 500 + +#define TOUCH_DATA_SIZE 200 +#define DEFAULT_THUMB_WIDTH 160 +#define DEFAULT_THUMB_HEIGHT 120 +#define FRAME_RATE_FULL_HD 27 +#define FRAME_RATE_HIGH_HD 60 + +#define ZOOM_STAGES 61 + +#define FACE_DETECTION_BUFFER_SIZE 0x1000 +#define MAX_NUM_FACES_SUPPORTED 35 + +#define EXIF_MODEL_SIZE 100 +#define EXIF_MAKE_SIZE 100 +#define EXIF_DATE_TIME_SIZE 20 + +#define GPS_MIN_DIV 60 +#define GPS_SEC_DIV 60 +#define GPS_SEC_ACCURACY 1000 +#define GPS_TIMESTAMP_SIZE 6 +#define GPS_DATESTAMP_SIZE 11 +#define GPS_REF_SIZE 2 +#define GPS_MAPDATUM_SIZE 100 +#define GPS_PROCESSING_SIZE 100 +#define GPS_VERSION_SIZE 4 +#define GPS_NORTH_REF "N" +#define GPS_SOUTH_REF "S" +#define GPS_EAST_REF "E" +#define GPS_WEST_REF "W" + +/* Default portstartnumber of Camera component */ +#define OMX_CAMERA_DEFAULT_START_PORT_NUM 0 + +/* Define number of ports for differt domains */ +#define OMX_CAMERA_PORT_OTHER_NUM 1 +#define OMX_CAMERA_PORT_VIDEO_NUM 4 +#define OMX_CAMERA_PORT_IMAGE_NUM 1 +#define OMX_CAMERA_PORT_AUDIO_NUM 0 +#define OMX_CAMERA_NUM_PORTS (OMX_CAMERA_PORT_OTHER_NUM + OMX_CAMERA_PORT_VIDEO_NUM + OMX_CAMERA_PORT_IMAGE_NUM + OMX_CAMERA_PORT_AUDIO_NUM) + +/* Define start port number for differt domains */ +#define OMX_CAMERA_PORT_OTHER_START OMX_CAMERA_DEFAULT_START_PORT_NUM +#define OMX_CAMERA_PORT_VIDEO_START (OMX_CAMERA_PORT_OTHER_START + OMX_CAMERA_PORT_OTHER_NUM) +#define OMX_CAMERA_PORT_IMAGE_START (OMX_CAMERA_PORT_VIDEO_START + OMX_CAMERA_PORT_VIDEO_NUM) +#define OMX_CAMERA_PORT_AUDIO_START (OMX_CAMERA_PORT_IMAGE_START + OMX_CAMERA_PORT_IMAGE_NUM) + +/* Port index for camera component */ +#define OMX_CAMERA_PORT_OTHER_IN (OMX_CAMERA_PORT_OTHER_START + 0) +#define OMX_CAMERA_PORT_VIDEO_IN_VIDEO (OMX_CAMERA_PORT_VIDEO_START + 0) +#define OMX_CAMERA_PORT_VIDEO_OUT_PREVIEW (OMX_CAMERA_PORT_VIDEO_START + 1) +#define OMX_CAMERA_PORT_VIDEO_OUT_VIDEO (OMX_CAMERA_PORT_VIDEO_START + 2) +#define OMX_CAMERA_PORT_VIDEO_OUT_MEASUREMENT (OMX_CAMERA_PORT_VIDEO_START + 3) +#define OMX_CAMERA_PORT_IMAGE_OUT_IMAGE (OMX_CAMERA_PORT_IMAGE_START + 0) + + +#define OMX_INIT_STRUCT(_s_, _name_) \ + memset(&(_s_), 0x0, sizeof(_name_)); \ + (_s_).nSize = sizeof(_name_); \ + (_s_).nVersion.s.nVersionMajor = 0x1; \ + (_s_).nVersion.s.nVersionMinor = 0x1; \ + (_s_).nVersion.s.nRevision = 0x0; \ + (_s_).nVersion.s.nStep = 0x0 + +#define OMX_INIT_STRUCT_PTR(_s_, _name_) \ + memset((_s_), 0x0, sizeof(_name_)); \ + (_s_)->nSize = sizeof(_name_); \ + (_s_)->nVersion.s.nVersionMajor = 0x1; \ + (_s_)->nVersion.s.nVersionMinor = 0x1; \ + (_s_)->nVersion.s.nRevision = 0x0; \ + (_s_)->nVersion.s.nStep = 0x0 + +#define GOTO_EXIT_IF(_CONDITION,_ERROR) { \ + if ((_CONDITION)) { \ + eError = (_ERROR); \ + goto EXIT; \ + } \ +} + +const int64_t kCameraBufferLatencyNs = 250000000LL; // 250 ms + +///OMX Specific Functions +static OMX_ERRORTYPE OMXCameraAdapterEventHandler(OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_PTR pAppData, + OMX_IN OMX_EVENTTYPE eEvent, + OMX_IN OMX_U32 nData1, + OMX_IN OMX_U32 nData2, + OMX_IN OMX_PTR pEventData); + +static OMX_ERRORTYPE OMXCameraAdapterEmptyBufferDone(OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_PTR pAppData, + OMX_IN OMX_BUFFERHEADERTYPE* pBuffer); + +static OMX_ERRORTYPE OMXCameraAdapterFillBufferDone(OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_PTR pAppData, + OMX_IN OMX_BUFFERHEADERTYPE* pBuffHeader); + +struct CapResolution { + size_t width, height; + const char *param; +}; + +struct CapPixelformat { + OMX_COLOR_FORMATTYPE pixelformat; + const char *param; +}; + +struct CapCodingFormat { + OMX_IMAGE_CODINGTYPE imageCodingFormat; + const char *param; +}; + +struct CapU32 { + OMX_U32 num; + const char *param; +}; + +struct CapS32 { + OMX_S32 num; + const char *param; +}; + +typedef CapU32 CapFramerate; +typedef CapU32 CapISO; +typedef CapU32 CapSensorName; +typedef CapS32 CapZoom; + +/** + * Class which completely abstracts the camera hardware interaction from camera hal + * TODO: Need to list down here, all the message types that will be supported by this class + Need to implement BufferProvider interface to use AllocateBuffer of OMX if needed + */ +class OMXCameraAdapter : public BaseCameraAdapter +{ +public: + + /*--------------------Constant declarations----------------------------------------*/ + static const int32_t MAX_NO_BUFFERS = 20; + + ///@remarks OMX Camera has six ports - buffer input, time input, preview, image, video, and meta data + static const int MAX_NO_PORTS = 6; + + ///Five second timeout + static const int CAMERA_ADAPTER_TIMEOUT = 5000*1000; + + enum CaptureMode + { + INITIAL_MODE = -1, + HIGH_SPEED = 1, + HIGH_QUALITY, + VIDEO_MODE, + HIGH_QUALITY_ZSL, + CP_CAM, + VIDEO_MODE_HQ, + }; + + enum IPPMode + { + IPP_NULL = -1, + IPP_NONE = 0, + IPP_NSF, + IPP_LDC, + IPP_LDCNSF, + }; + + enum CodingMode + { + CodingJPEG = 0, + CodingJPS, + CodingMPO, + }; + + enum Algorithm3A + { + WHITE_BALANCE_ALGO = 0x1, + EXPOSURE_ALGO = 0x2, + FOCUS_ALGO = 0x4, + }; + + enum AlgoPriority + { + FACE_PRIORITY = 0, + REGION_PRIORITY, + }; + + enum BrightnessMode + { + BRIGHTNESS_OFF = 0, + BRIGHTNESS_ON, + BRIGHTNESS_AUTO, + }; + + enum CaptureSettingsFlags { + SetFormat = 1 << 0, + SetThumb = 1 << 1, + SetBurstExpBracket = 1 << 2, + SetQuality = 1 << 3, + SetRotation = 1 << 4, + ECaptureSettingMax, + ECapturesettingsAll = ( ((ECaptureSettingMax -1 ) << 1) -1 ), /// all possible flags raised + ECaptureParamSettings = SetFormat | SetThumb | SetQuality | SetBurstExpBracket, // Settings set with SetParam + ECaptureConfigSettings = (ECapturesettingsAll & ~ECaptureParamSettings) + }; + + enum PreviewSettingsFlags { + SetLDC = 1 << 0, + SetNSF = 1 << 1, + SetCapMode = 1 << 2, + SetVNF = 1 << 3, + SetVSTAB = 1 << 4, + EPreviewSettingMax, + EPreviewSettingsAll = ( ((EPreviewSettingMax -1 ) << 1) -1 ) /// all possible flags raised + }; + + enum BracketingValueMode { + BracketingValueAbsolute, + BracketingValueRelative, + BracketingValueAbsoluteForced, + BracketingValueRelativeForced, + BracketingValueCompensation, + BracketingValueCompensationForced + }; + + class GPSData + { + public: + int mLongDeg, mLongMin, mLongSec, mLongSecDiv; + char mLongRef[GPS_REF_SIZE]; + bool mLongValid; + int mLatDeg, mLatMin, mLatSec, mLatSecDiv; + char mLatRef[GPS_REF_SIZE]; + bool mLatValid; + int mAltitude; + unsigned char mAltitudeRef; + bool mAltitudeValid; + char mMapDatum[GPS_MAPDATUM_SIZE]; + bool mMapDatumValid; + char mVersionId[GPS_VERSION_SIZE]; + bool mVersionIdValid; + char mProcMethod[GPS_PROCESSING_SIZE]; + bool mProcMethodValid; + char mDatestamp[GPS_DATESTAMP_SIZE]; + bool mDatestampValid; + uint32_t mTimeStampHour; + uint32_t mTimeStampMin; + uint32_t mTimeStampSec; + bool mTimeStampValid; + }; + + class EXIFData + { + public: + GPSData mGPSData; + char mMake[EXIF_MODEL_SIZE]; + char mModel[EXIF_MAKE_SIZE]; + unsigned int mFocalNum, mFocalDen; + bool mMakeValid; + bool mModelValid; + }; + + ///Parameters specific to any port of the OMX Camera component + class OMXCameraPortParameters + { + public: + //CameraBuffer * mHostBufaddr[MAX_NO_BUFFERS]; + OMX_BUFFERHEADERTYPE *mBufferHeader[MAX_NO_BUFFERS]; + OMX_U8 mStatus[MAX_NO_BUFFERS]; + OMX_U32 mWidth; + OMX_U32 mHeight; + OMX_U32 mStride; + OMX_U8 mNumBufs; + + // defines maximum number of buffers our of mNumBufs + // queueable at given moment + OMX_U8 mMaxQueueable; + + OMX_U32 mBufSize; + OMX_COLOR_FORMATTYPE mColorFormat; + OMX_PARAM_VIDEONOISEFILTERTYPE mVNFMode; + OMX_PARAM_VIDEOYUVRANGETYPE mYUVRange; + OMX_CONFIG_BOOLEANTYPE mVidStabParam; + OMX_CONFIG_FRAMESTABTYPE mVidStabConfig; + OMX_U32 mCapFrame; + OMX_U32 mFrameRate; + OMX_U32 mMinFrameRate; + OMX_U32 mMaxFrameRate; + CameraFrame::FrameType mImageType; + OMX_TI_STEREOFRAMELAYOUTTYPE mFrameLayoutType; + CameraBufferType mBufferType; + + CameraBuffer * lookup_omx_buffer (OMX_BUFFERHEADERTYPE *pBufHeader); + enum { + IDLE = 0, // buffer is neither with HAL or Ducati + FILL, // buffer is with Ducati + DONE, // buffer is filled and sent to HAL + }; + }; + + ///Context of the OMX Camera component + class OMXCameraAdapterComponentContext + { + public: + OMX_HANDLETYPE mHandleComp; + OMX_U32 mNumPorts; + OMX_STATETYPE mState ; + OMX_U32 mVideoPortIndex; + OMX_U32 mPrevPortIndex; + OMX_U32 mImagePortIndex; + OMX_U32 mMeasurementPortIndex; + OMX_U32 mVideoInPortIndex; + OMXCameraPortParameters mCameraPortParams[MAX_NO_PORTS]; + }; + + class CachedCaptureParameters + { + public: + unsigned int mPendingCaptureSettings; + unsigned int mPictureRotation; + int mExposureBracketingValues[EXP_BRACKET_RANGE]; + int mExposureGainBracketingValues[EXP_BRACKET_RANGE]; + int mExposureGainBracketingModes[EXP_BRACKET_RANGE]; + size_t mExposureBracketingValidEntries; + OMX_BRACKETMODETYPE mExposureBracketMode; + unsigned int mBurstFrames; + bool mFlushShotConfigQueue; + }; + +public: + + OMXCameraAdapter(size_t sensor_index); + ~OMXCameraAdapter(); + + ///Initialzes the camera adapter creates any resources required + virtual status_t initialize(CameraProperties::Properties*); + + //APIs to configure Camera adapter and get the current parameter set + virtual status_t setParameters(const android::CameraParameters& params); + virtual void getParameters(android::CameraParameters& params); + + // API + status_t UseBuffersPreview(CameraBuffer *bufArr, int num); + + //API to flush the buffers + status_t flushBuffers(OMX_U32 port = OMX_CAMERA_PORT_VIDEO_OUT_PREVIEW); + + // API + virtual status_t setFormat(OMX_U32 port, OMXCameraPortParameters &cap); + + // Function to get and populate caps from handle + static status_t getCaps(int sensorId, CameraProperties::Properties* props, OMX_HANDLETYPE handle); + static const char* getLUTvalue_OMXtoHAL(int OMXValue, LUTtype LUT); + static int getMultipleLUTvalue_OMXtoHAL(int OMXValue, LUTtype LUT, char * supported); + static int getLUTvalue_HALtoOMX(const char * HalValue, LUTtype LUT); + + OMX_ERRORTYPE OMXCameraAdapterEventHandler(OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_EVENTTYPE eEvent, + OMX_IN OMX_U32 nData1, + OMX_IN OMX_U32 nData2, + OMX_IN OMX_PTR pEventData); + + OMX_ERRORTYPE OMXCameraAdapterEmptyBufferDone(OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_BUFFERHEADERTYPE* pBuffer); + + OMX_ERRORTYPE OMXCameraAdapterFillBufferDone(OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_BUFFERHEADERTYPE* pBuffHeader); + + static OMX_ERRORTYPE OMXCameraGetHandle(OMX_HANDLETYPE *handle, OMX_PTR pAppData, + const OMX_CALLBACKTYPE & callbacks); + +protected: + + //Parent class method implementation + virtual status_t takePicture(); + virtual status_t stopImageCapture(); + virtual status_t startBracketing(int range); + virtual status_t stopBracketing(); + virtual status_t autoFocus(); + virtual status_t cancelAutoFocus(); + virtual status_t startSmoothZoom(int targetIdx); + virtual status_t stopSmoothZoom(); + virtual status_t startVideoCapture(); + virtual status_t stopVideoCapture(); + virtual status_t startPreview(); + virtual status_t stopPreview(); + virtual status_t useBuffers(CameraMode mode, CameraBuffer * bufArr, int num, size_t length, unsigned int queueable); + virtual status_t fillThisBuffer(CameraBuffer * frameBuf, CameraFrame::FrameType frameType); + virtual status_t getFrameSize(size_t &width, size_t &height); + virtual status_t getPictureBufferSize(CameraFrame &frame, size_t bufferCount); + virtual status_t getFrameDataSize(size_t &dataFrameSize, size_t bufferCount); + virtual status_t startFaceDetection(); + virtual status_t stopFaceDetection(); + virtual status_t switchToExecuting(); + virtual void onOrientationEvent(uint32_t orientation, uint32_t tilt); + +private: + + // Caches and returns current set of parameters + CachedCaptureParameters* cacheCaptureParameters(); + + status_t doSwitchToExecuting(); + + void performCleanupAfterError(); + + status_t switchToIdle(); + + status_t switchToLoaded(bool bPortEnableRequired = false); + status_t prevPortEnable(); + + OMXCameraPortParameters *getPortParams(CameraFrame::FrameType frameType); + + OMX_ERRORTYPE SignalEvent(OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_EVENTTYPE eEvent, + OMX_IN OMX_U32 nData1, + OMX_IN OMX_U32 nData2, + OMX_IN OMX_PTR pEventData); + OMX_ERRORTYPE RemoveEvent(OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_EVENTTYPE eEvent, + OMX_IN OMX_U32 nData1, + OMX_IN OMX_U32 nData2, + OMX_IN OMX_PTR pEventData); + + status_t RegisterForEvent(OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_EVENTTYPE eEvent, + OMX_IN OMX_U32 nData1, + OMX_IN OMX_U32 nData2, + OMX_IN Utils::Semaphore &semaphore); + + status_t setPictureRotation(unsigned int degree); + status_t setSensorOrientation(unsigned int degree); + status_t setImageQuality(unsigned int quality); + status_t setThumbnailParams(unsigned int width, unsigned int height, unsigned int quality); + status_t setSensorQuirks(int orientation, + OMXCameraPortParameters &portParams, + bool &portConfigured); + + status_t setupTunnel(uint32_t SliceHeight, uint32_t EncoderHandle, uint32_t width, uint32_t height); + status_t destroyTunnel(); + + //EXIF + status_t setParametersEXIF(const android::CameraParameters ¶ms, + BaseCameraAdapter::AdapterState state); + status_t convertGPSCoord(double coord, int °, int &min, int &sec, int &secDivisor); + status_t setupEXIF(); + status_t setupEXIF_libjpeg(ExifElementsTable*, OMX_TI_ANCILLARYDATATYPE*, + OMX_TI_WHITEBALANCERESULTTYPE*); + + //Focus functionality + status_t doAutoFocus(); + status_t stopAutoFocus(); + status_t checkFocus(OMX_PARAM_FOCUSSTATUSTYPE *eFocusStatus); + status_t returnFocusStatus(bool timeoutReached); + status_t getFocusMode(OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE &focusMode); + void handleFocusCallback(); + + + //Focus distances + status_t setParametersFocus(const android::CameraParameters ¶ms, + BaseCameraAdapter::AdapterState state); + status_t addFocusDistances(OMX_U32 &near, + OMX_U32 &optimal, + OMX_U32 &far, + android::CameraParameters& params); + status_t encodeFocusDistance(OMX_U32 dist, char *buffer, size_t length); + status_t getFocusDistances(OMX_U32 &near,OMX_U32 &optimal, OMX_U32 &far); + + //VSTAB and VNF Functionality + status_t enableVideoNoiseFilter(bool enable); + status_t enableVideoStabilization(bool enable); + + //Digital zoom + status_t setParametersZoom(const android::CameraParameters ¶ms, + BaseCameraAdapter::AdapterState state); + status_t doZoom(int index); + status_t advanceZoom(); + + //3A related parameters + status_t setParameters3A(const android::CameraParameters ¶ms, + BaseCameraAdapter::AdapterState state); + void declareParameter3ABool(const android::CameraParameters ¶ms, const char *key, + OMX_BOOL ¤t_setting, E3ASettingsFlags pending, + const char *msg); + + // scene modes + status_t setScene(Gen3A_settings& Gen3A); + // returns pointer to SceneModesEntry from the LUT for camera given 'name' and 'scene' + static const SceneModesEntry* getSceneModeEntry(const char* name, OMX_SCENEMODETYPE scene); + + + //Flash modes + status_t setFlashMode(Gen3A_settings& Gen3A); + status_t getFlashMode(Gen3A_settings& Gen3A); + + // Focus modes + status_t setFocusMode(Gen3A_settings& Gen3A); + status_t getFocusMode(Gen3A_settings& Gen3A); + + //Exposure Modes + status_t setExposureMode(Gen3A_settings& Gen3A); + status_t setManualExposureVal(Gen3A_settings& Gen3A); + status_t setEVCompensation(Gen3A_settings& Gen3A); + status_t setWBMode(Gen3A_settings& Gen3A); + status_t setFlicker(Gen3A_settings& Gen3A); + status_t setBrightness(Gen3A_settings& Gen3A); + status_t setContrast(Gen3A_settings& Gen3A); + status_t setSharpness(Gen3A_settings& Gen3A); + status_t setSaturation(Gen3A_settings& Gen3A); + status_t setISO(Gen3A_settings& Gen3A); + status_t setEffect(Gen3A_settings& Gen3A); + status_t setMeteringAreas(Gen3A_settings& Gen3A); + + //TI extensions for enable/disable algos + status_t setParameter3ABool(const OMX_INDEXTYPE omx_idx, + const OMX_BOOL data, const char *msg); + status_t setParameter3ABoolInvert(const OMX_INDEXTYPE omx_idx, + const OMX_BOOL data, const char *msg); + status_t setAlgoExternalGamma(Gen3A_settings& Gen3A); +#ifndef MOTOROLA_CAMERA + status_t setAlgoNSF1(Gen3A_settings& Gen3A); + status_t setAlgoNSF2(Gen3A_settings& Gen3A); + status_t setAlgoSharpening(Gen3A_settings& Gen3A); + status_t setAlgoThreeLinColorMap(Gen3A_settings& Gen3A); + status_t setAlgoGIC(Gen3A_settings& Gen3A); + + //Gamma table + void updateGammaTable(const char* gamma); + status_t setGammaTable(Gen3A_settings& Gen3A); +#endif + + status_t getEVCompensation(Gen3A_settings& Gen3A); + status_t getWBMode(Gen3A_settings& Gen3A); + status_t getSharpness(Gen3A_settings& Gen3A); + status_t getSaturation(Gen3A_settings& Gen3A); + status_t getISO(Gen3A_settings& Gen3A); + + // 3A locks + status_t setExposureLock(Gen3A_settings& Gen3A); + status_t setFocusLock(Gen3A_settings& Gen3A); + status_t setWhiteBalanceLock(Gen3A_settings& Gen3A); + status_t set3ALock(OMX_BOOL toggleExp, OMX_BOOL toggleWb, OMX_BOOL toggleFocus); + + //Stereo 3D + void setParamS3D(OMX_U32 port, const char *valstr); + status_t setS3DFrameLayout(OMX_U32 port) const; + + //API to set FrameRate using VFR interface + status_t setVFramerate(OMX_U32 minFrameRate,OMX_U32 maxFrameRate); + + status_t setParametersAlgo(const android::CameraParameters ¶ms, + BaseCameraAdapter::AdapterState state); + + //Noise filtering + status_t setNSF(OMXCameraAdapter::IPPMode mode); + + //LDC + status_t setLDC(OMXCameraAdapter::IPPMode mode); + + //GLBCE + status_t setGLBCE(OMXCameraAdapter::BrightnessMode mode); + + //GBCE + status_t setGBCE(OMXCameraAdapter::BrightnessMode mode); + + status_t printComponentVersion(OMX_HANDLETYPE handle); + + //Touch AF + status_t setTouchFocus(); + + //Face detection + status_t setParametersFD(const android::CameraParameters ¶ms, + BaseCameraAdapter::AdapterState state); + status_t updateFocusDistances(android::CameraParameters ¶ms); + status_t setFaceDetectionOrientation(OMX_U32 orientation); + status_t setFaceDetection(bool enable, OMX_U32 orientation); + status_t createPreviewMetadata(OMX_BUFFERHEADERTYPE* pBuffHeader, + android::sp<CameraMetadataResult> &result, + size_t previewWidth, + size_t previewHeight); + status_t encodeFaceCoordinates(const OMX_FACEDETECTIONTYPE *faceData, + camera_frame_metadata_t *metadataResult, + size_t previewWidth, + size_t previewHeight); + status_t encodePreviewMetadata(camera_frame_metadata_t *meta, const OMX_PTR plat_pvt); + + void pauseFaceDetection(bool pause); + + //3A Algorithms priority configuration + status_t setAlgoPriority(AlgoPriority priority, Algorithm3A algo, bool enable); + + //Sensor overclocking + status_t setSensorOverclock(bool enable); + + // Utility methods for OMX Capabilities + static bool _checkOmxTiCap(const OMX_TI_CAPTYPE & caps); + static bool _dumpOmxTiCap(int sensorId, const OMX_TI_CAPTYPE & caps); + + static status_t insertCapabilities(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t encodeSizeCap(OMX_TI_CAPRESTYPE&, const CapResolution *, size_t, char *, size_t); + static status_t encodeISOCap(OMX_U32, const CapISO*, size_t, char*, size_t); + static size_t encodeZoomCap(OMX_S32, const CapZoom*, size_t, char*, size_t); + static void encodeFrameRates(int minFrameRate, int maxFrameRate, const OMX_TI_CAPTYPE & caps, + const CapFramerate * fixedFrameRates, int frameRateCount, android::Vector<FpsRange> & fpsRanges); + static status_t encodeImageCodingFormatCap(OMX_IMAGE_CODINGTYPE, + const CapCodingFormat *, + size_t, + char *); + static status_t encodePixelformatCap(OMX_COLOR_FORMATTYPE, + const CapPixelformat*, + size_t, + char*, + size_t); + static status_t encodeSizeCap3D(OMX_TI_CAPRESTYPE&, + const CapResolution*, + size_t , + char * , + size_t); + static status_t insertImageSizes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertPreviewSizes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertThumbSizes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertZoomStages(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertImageFormats(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertPreviewFormats(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertFramerates(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertEVs(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertISOModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertIPPModes(CameraProperties::Properties*, OMX_TI_CAPTYPE &); + static status_t insertWBModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertEffects(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertExpModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertManualExpRanges(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertSceneModes(CameraProperties::Properties*, OMX_TI_CAPTYPE &); + static status_t insertFocusModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertFlickerModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertFlashModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertSenMount(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertDefaults(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertLocks(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertAreas(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertMechanicalMisalignmentCorrection(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertCaptureModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertVideoSizes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertFacing(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertFocalLength(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertAutoConvergenceModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertManualConvergenceRange(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertLayout(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertVideoSnapshotSupported(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + static status_t insertVNFSupported(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps); + static status_t insertVSTABSupported(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps); + static status_t insertGBCESupported(CameraProperties::Properties* params, + const OMX_TI_CAPTYPE &caps); + static status_t insertGLBCESupported(CameraProperties::Properties* params, + const OMX_TI_CAPTYPE &caps); + static status_t insertRaw(CameraProperties::Properties*, OMX_TI_CAPTYPE&); + + status_t setParametersCapture(const android::CameraParameters ¶ms, + BaseCameraAdapter::AdapterState state); + + //Exposure Bracketing + status_t initVectorShot(); + status_t setVectorShot(int *evValues, int *evValues2, int *evModes2, + size_t evCount, size_t frameCount, + bool flush, OMX_BRACKETMODETYPE bracketMode); + status_t setVectorStop(bool toPreview = false); + status_t setExposureBracketing(int *evValues, int *evValues2, + size_t evCount, size_t frameCount, + OMX_BRACKETMODETYPE bracketMode); + status_t doExposureBracketing(int *evValues, int *evValues2, + int *evModes2, + size_t evCount, size_t frameCount, + bool flush, + OMX_BRACKETMODETYPE bracketMode); + int getBracketingValueMode(const char *a, const char *b) const; + status_t parseExpRange(const char *rangeStr, int *expRange, int *gainRange, + int *expGainModes, + size_t count, size_t &validEntries); + + //Temporal Bracketing + status_t doBracketing(OMX_BUFFERHEADERTYPE *pBuffHeader, CameraFrame::FrameType typeOfFrame); + status_t sendBracketFrames(size_t &framesSent); + + // Image Capture Service + status_t startImageCapture(bool bracketing, CachedCaptureParameters*); + status_t disableImagePort(); + + //Shutter callback notifications + status_t setShutterCallback(bool enabled); + + //Sets eithter HQ or HS mode and the frame count + status_t setCaptureMode(OMXCameraAdapter::CaptureMode mode); + status_t UseBuffersCapture(CameraBuffer *bufArr, int num); + status_t UseBuffersPreviewData(CameraBuffer *bufArr, int num); + status_t UseBuffersRawCapture(CameraBuffer *bufArr, int num); + + //Used for calculation of the average frame rate during preview + status_t recalculateFPS(); + + //Sends the incoming OMX buffer header to subscribers + status_t sendCallBacks(CameraFrame frame, OMX_IN OMX_BUFFERHEADERTYPE *pBuffHeader, unsigned int mask, OMXCameraPortParameters *port); + + status_t apply3Asettings( Gen3A_settings& Gen3A ); + + // AutoConvergence + status_t setAutoConvergence(const char *valstr, const char *pValManualstr, const android::CameraParameters ¶ms); + + status_t setExtraData(bool enable, OMX_U32, OMX_EXT_EXTRADATATYPE); + OMX_OTHER_EXTRADATATYPE *getExtradata(const OMX_PTR ptrPrivate, OMX_EXTRADATATYPE type) const; + + // Meta data +#ifdef OMAP_ENHANCEMENT_CPCAM + camera_memory_t * getMetaData(const OMX_PTR plat_pvt, + camera_request_memory allocator) const; +#endif + + // Mechanical Misalignment Correction + status_t setMechanicalMisalignmentCorrection(bool enable); + + // DCC file data save + status_t initDccFileDataSave(OMX_HANDLETYPE* omxHandle, int portIndex); + status_t sniffDccFileDataSave(OMX_BUFFERHEADERTYPE* pBuffHeader); + status_t saveDccFileDataSave(); + status_t closeDccFileDataSave(); + status_t fseekDCCuseCasePos(FILE *pFile); + FILE * fopenCameraDCC(const char *dccFolderPath); + FILE * parseDCCsubDir(DIR *pDir, char *path); + +#ifdef CAMERAHAL_OMX_PROFILING + status_t storeProfilingData(OMX_BUFFERHEADERTYPE* pBuffHeader); +#endif + + // Internal buffers + status_t initInternalBuffers (OMX_U32); + status_t deinitInternalBuffers (OMX_U32); + + // Reprocess Methods -- implementation in OMXReprocess.cpp + status_t setParametersReprocess(const android::CameraParameters ¶ms, CameraBuffer* bufs, + BaseCameraAdapter::AdapterState state); + status_t startReprocess(); + status_t disableReprocess(); + status_t stopReprocess(); + status_t UseBuffersReprocess(CameraBuffer *bufArr, int num); + + class CommandHandler : public android::Thread { + public: + CommandHandler(OMXCameraAdapter* ca) + : android::Thread(false), mCameraAdapter(ca) { } + + virtual bool threadLoop() { + bool ret; + ret = Handler(); + return ret; + } + + status_t put(Utils::Message* msg){ + android::AutoMutex lock(mLock); + return mCommandMsgQ.put(msg); + } + + void clearCommandQ() + { + android::AutoMutex lock(mLock); + mCommandMsgQ.clear(); + } + + enum { + COMMAND_EXIT = -1, + CAMERA_START_IMAGE_CAPTURE = 0, + CAMERA_PERFORM_AUTOFOCUS, + CAMERA_SWITCH_TO_EXECUTING, + CAMERA_START_REPROCESS + }; + + private: + bool Handler(); + Utils::MessageQueue mCommandMsgQ; + OMXCameraAdapter* mCameraAdapter; + android::Mutex mLock; + }; + android::sp<CommandHandler> mCommandHandler; + +#ifdef MOTOROLA_CAMERA + status_t setLedFlash(int nLedFlashIntensP); + status_t setLedTorch(int nLedTorchIntensP); +#endif + +public: + +#ifdef MOTOROLA_CAMERA + status_t getOTPEeprom(unsigned char * pData, unsigned long nSize); +#endif + + class OMXCallbackHandler : public android::Thread { + public: + OMXCallbackHandler(OMXCameraAdapter* ca) + : Thread(false), mCameraAdapter(ca) + { + mIsProcessed = true; + } + + virtual bool threadLoop() { + bool ret; + ret = Handler(); + return ret; + } + + status_t put(Utils::Message* msg){ + android::AutoMutex lock(mLock); + mIsProcessed = false; + return mCommandMsgQ.put(msg); + } + + void clearCommandQ() + { + android::AutoMutex lock(mLock); + mCommandMsgQ.clear(); + } + + void flush(); + + enum { + COMMAND_EXIT = -1, + CAMERA_FILL_BUFFER_DONE, + CAMERA_FOCUS_STATUS + }; + + private: + bool Handler(); + Utils::MessageQueue mCommandMsgQ; + OMXCameraAdapter* mCameraAdapter; + android::Mutex mLock; + android::Condition mCondition; + bool mIsProcessed; + }; + + android::sp<OMXCallbackHandler> mOMXCallbackHandler; + +private: + + //AF callback + status_t setFocusCallback(bool enabled); + + //OMX Capabilities data + static const CapResolution mImageCapRes []; + static const CapResolution mImageCapResSS []; + static const CapResolution mImageCapResTB []; + static const CapResolution mPreviewRes []; + static const CapResolution mPreviewResSS []; + static const CapResolution mPreviewResTB []; + static const CapResolution mPreviewPortraitRes []; + static const CapResolution mThumbRes []; + static const CapPixelformat mPixelformats []; + static const userToOMX_LUT mFrameLayout []; + static const LUTtype mLayoutLUT; + static const CapCodingFormat mImageCodingFormat[]; + static const CapFramerate mFramerates []; + static const CapU32 mSensorNames[] ; + static const CapZoom mZoomStages []; + static const CapISO mISOStages []; + static const int SENSORID_IMX060; + static const int SENSORID_OV5650; + static const int SENSORID_OV5640; + static const int SENSORID_OV14825; + static const int SENSORID_S5K4E1GA; + static const int SENSORID_S5K6A1GX03; + static const int SENSORID_OV8830; + static const int SENSORID_OV2722; + static const int SENSORID_OV9726; +#ifdef MOTOROLA_CAMERA + static const int SENSORID_OV8820; + static const int SENSORID_MT9M114; +#endif + static const CapU32 mFacing []; + static const userToOMX_LUT mAutoConvergence []; + static const LUTtype mAutoConvergenceLUT; + static const userToOMX_LUT mBracketingModes[]; + static const LUTtype mBracketingModesLUT; + + static const int FPS_MIN; + static const int FPS_MAX; + static const int FPS_MAX_EXTENDED; + + // OMX Camera defaults + static const char DEFAULT_ANTIBANDING[]; + static const char DEFAULT_BRIGHTNESS[]; + static const char DEFAULT_CONTRAST[]; + static const char DEFAULT_EFFECT[]; + static const char DEFAULT_EV_COMPENSATION[]; + static const char DEFAULT_EV_STEP[]; + static const char DEFAULT_EXPOSURE_MODE[]; + static const char DEFAULT_FLASH_MODE[]; + static const char DEFAULT_FOCUS_MODE_PREFERRED[]; + static const char DEFAULT_FOCUS_MODE[]; + static const char DEFAULT_IPP[]; + static const char DEFAULT_ISO_MODE[]; + static const char DEFAULT_JPEG_QUALITY[]; + static const char DEFAULT_THUMBNAIL_QUALITY[]; + static const char DEFAULT_THUMBNAIL_SIZE[]; + static const char DEFAULT_PICTURE_FORMAT[]; + static const char DEFAULT_S3D_PICTURE_LAYOUT[]; + static const char DEFAULT_PICTURE_SIZE[]; + static const char DEFAULT_PICTURE_SS_SIZE[]; + static const char DEFAULT_PICTURE_TB_SIZE[]; + static const char DEFAULT_PREVIEW_FORMAT[]; + static const char DEFAULT_FRAMERATE[]; + static const char DEFAULT_S3D_PREVIEW_LAYOUT[]; + static const char DEFAULT_PREVIEW_SIZE[]; + static const char DEFAULT_PREVIEW_SS_SIZE[]; + static const char DEFAULT_PREVIEW_TB_SIZE[]; + static const char DEFAULT_NUM_PREV_BUFS[]; + static const char DEFAULT_NUM_PIC_BUFS[]; + static const char DEFAULT_SATURATION[]; + static const char DEFAULT_SCENE_MODE[]; + static const char DEFAULT_SHARPNESS[]; + static const char * DEFAULT_VSTAB; + static const char * DEFAULT_VNF; + static const char DEFAULT_WB[]; + static const char DEFAULT_ZOOM[]; + static const char DEFAULT_MAX_FD_HW_FACES[]; + static const char DEFAULT_MAX_FD_SW_FACES[]; + static const char * DEFAULT_AE_LOCK; + static const char * DEFAULT_AWB_LOCK; + static const char DEFAULT_HOR_ANGLE[]; + static const char DEFAULT_VER_ANGLE[]; + static const char DEFAULT_VIDEO_SIZE[]; + static const char DEFAULT_SENSOR_ORIENTATION[]; + static const char DEFAULT_AUTOCONVERGENCE_MODE[]; + static const char DEFAULT_MANUAL_CONVERGENCE[]; + static const char * DEFAULT_MECHANICAL_MISALIGNMENT_CORRECTION_MODE; + static const char DEFAULT_EXIF_MODEL[]; + static const char DEFAULT_EXIF_MAKE[]; + + static const size_t MAX_FOCUS_AREAS; + +#ifdef CAMERAHAL_OMX_PROFILING + + static const char DEFAULT_PROFILE_PATH[]; + int mDebugProfile; + +#endif + + OMX_VERSIONTYPE mCompRevision; + + //OMX Component UUID + OMX_UUIDTYPE mCompUUID; + + //Current Focus distances + char mFocusDistNear[FOCUS_DIST_SIZE]; + char mFocusDistOptimal[FOCUS_DIST_SIZE]; + char mFocusDistFar[FOCUS_DIST_SIZE]; + char mFocusDistBuffer[FOCUS_DIST_BUFFER_SIZE]; + + // Current Focus areas + android::Vector<android::sp<CameraArea> > mFocusAreas; + mutable android::Mutex mFocusAreasLock; + + // Current Touch convergence areas + android::Vector<android::sp<CameraArea> > mTouchAreas; + mutable android::Mutex mTouchAreasLock; + + // Current Metering areas + android::Vector<android::sp<CameraArea> > mMeteringAreas; + mutable android::Mutex mMeteringAreasLock; + + OperatingMode mCapabilitiesOpMode; + CaptureMode mCapMode; + // TODO(XXX): Do we really need this lock? Let's + // try to merge temporal bracketing and burst + // capture later + mutable android::Mutex mBurstLock; + size_t mBurstFrames; + size_t mBurstFramesAccum; + size_t mBurstFramesQueued; + size_t mCapturedFrames; + bool mFlushShotConfigQueue; + + bool mMeasurementEnabled; + + //Exposure Bracketing + int mExposureBracketingValues[EXP_BRACKET_RANGE]; + int mExposureGainBracketingValues[EXP_BRACKET_RANGE]; + int mExposureGainBracketingModes[EXP_BRACKET_RANGE]; + size_t mExposureBracketingValidEntries; + OMX_BRACKETMODETYPE mExposureBracketMode; + + //Zoom Bracketing + int mZoomBracketingValues[ZOOM_BRACKET_RANGE]; + size_t mZoomBracketingValidEntries; + + static const uint32_t FACE_DETECTION_THRESHOLD; + mutable android::Mutex mFaceDetectionLock; + //Face detection status + bool mFaceDetectionRunning; + bool mFaceDetectionPaused; + bool mFDSwitchAlgoPriority; + + camera_face_t faceDetectionLastOutput[MAX_NUM_FACES_SUPPORTED]; + int faceDetectionNumFacesLastOutput; + int metadataLastAnalogGain; + int metadataLastExposureTime; + + //Geo-tagging + EXIFData mEXIFData; + + //Image post-processing + IPPMode mIPP; + + //jpeg Picture Quality + unsigned int mPictureQuality; + + //thumbnail resolution + unsigned int mThumbWidth, mThumbHeight; + + //thumbnail quality + unsigned int mThumbQuality; + + //variables holding the estimated framerate + float mFPS, mLastFPS; + + //automatically disable AF after a given amount of frames + unsigned int mFocusThreshold; + + //This is needed for the CTS tests. They falsely assume, that during + //smooth zoom the current zoom stage will not change within the + //zoom callback scope, which in a real world situation is not always the + //case. This variable will "simulate" the expected behavior + unsigned int mZoomParameterIdx; + + //current zoom + android::Mutex mZoomLock; + unsigned int mCurrentZoomIdx, mTargetZoomIdx, mPreviousZoomIndx; + bool mZoomUpdating, mZoomUpdate; + int mZoomInc; + bool mReturnZoomStatus; + static const int32_t ZOOM_STEPS []; + + //local copy + OMX_VERSIONTYPE mLocalVersionParam; + + unsigned int mPending3Asettings; + android::Mutex m3ASettingsUpdateLock; + Gen3A_settings mParameters3A; + const char *mPictureFormatFromClient; + + BrightnessMode mGBCE; + BrightnessMode mGLBCE; + + OMX_TI_CONFIG_3A_FACE_PRIORITY mFacePriority; + OMX_TI_CONFIG_3A_REGION_PRIORITY mRegionPriority; + + android::CameraParameters mParams; + CameraProperties::Properties* mCapabilities; + unsigned int mPictureRotation; + bool mWaitingForSnapshot; + bool mCaptureConfigured; + unsigned int mPendingCaptureSettings; + unsigned int mPendingPreviewSettings; + unsigned int mPendingReprocessSettings; + OMX_TI_ANCILLARYDATATYPE* mCaptureAncillaryData; + OMX_TI_WHITEBALANCERESULTTYPE* mWhiteBalanceData; + bool mReprocConfigured; + + //Temporal bracketing management data + bool mBracketingSet; + mutable android::Mutex mBracketingLock; + bool *mBracketingBuffersQueued; + int mBracketingBuffersQueuedCount; + int mLastBracetingBufferIdx; + bool mBracketingEnabled; + bool mZoomBracketingEnabled; + size_t mBracketingRange; + int mCurrentZoomBracketing; + android::CameraParameters mParameters; + +#ifdef CAMERAHAL_TUNA + bool mIternalRecordingHint; +#endif + + bool mOmxInitialized; + OMXCameraAdapterComponentContext mCameraAdapterParameters; + bool mFirstTimeInit; + + ///Semaphores used internally + Utils::Semaphore mInitSem; + Utils::Semaphore mFlushSem; + Utils::Semaphore mUsePreviewDataSem; + Utils::Semaphore mUsePreviewSem; + Utils::Semaphore mUseCaptureSem; + Utils::Semaphore mStartPreviewSem; + Utils::Semaphore mStopPreviewSem; + Utils::Semaphore mStartCaptureSem; + Utils::Semaphore mStopCaptureSem; + Utils::Semaphore mSwitchToLoadedSem; + Utils::Semaphore mSwitchToExecSem; + Utils::Semaphore mStopReprocSem; + Utils::Semaphore mUseReprocessSem; + + mutable android::Mutex mStateSwitchLock; + mutable android::Mutex mIdleStateSwitchLock; + + android::Vector<Utils::Message *> mEventSignalQ; + android::Mutex mEventLock; + + OMX_STATETYPE mComponentState; + + OMX_TI_AUTOCONVERGENCEMODETYPE mAutoConv; + OMX_S32 mManualConv; + bool mVnfEnabled; + bool mVstabEnabled; + + int mSensorOrientation; + int mDeviceOrientation; + int mFaceOrientation; + bool mSensorOverclock; + + //Indicates if we should leave + //OMX_Executing state during + //stop-/startPreview + bool mOMXStateSwitch; + + int mFrameCount; + int mLastFrameCount; + unsigned int mIter; + nsecs_t mLastFPSTime; + android::Mutex mFrameCountMutex; + android::Condition mFirstFrameCondition; + + static const nsecs_t CANCEL_AF_TIMEOUT; + android::Mutex mCancelAFMutex; + android::Condition mCancelAFCond; + + android::Mutex mDoAFMutex; + android::Condition mDoAFCond; + + size_t mSensorIndex; + CodingMode mCodingMode; + + // Time source delta of ducati & system time + OMX_TICKS mTimeSourceDelta; + bool onlyOnce; + + Utils::Semaphore mCaptureSem; + bool mCaptureSignalled; + + OMX_BOOL mUserSetExpLock; + OMX_BOOL mUserSetWbLock; + +#ifdef CAMERAHAL_USE_RAW_IMAGE_SAVING + bool mRawCapture; + bool mYuvCapture; +#endif + + bool mSetFormatDone; + + OMX_TI_DCCDATATYPE mDccData; + android::Mutex mDccDataLock; + + int mMaxZoomSupported; + android::Mutex mImageCaptureLock; + + bool mTunnelDestroyed; + bool mPreviewPortInitialized; + + // Used for allocations that need to be sent to Ducati + MemoryManager mMemMgr; +}; + +} // namespace Camera +} // namespace Ti + +#endif //OMX_CAMERA_ADAPTER_H diff --git a/camera/inc/OMXCameraAdapter/OMXDCC.h b/camera/inc/OMXCameraAdapter/OMXDCC.h new file mode 100644 index 0000000..c75a24d --- /dev/null +++ b/camera/inc/OMXCameraAdapter/OMXDCC.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OMX_DCC_H +#define OMX_DCC_H + +namespace Ti { +namespace Camera { + +class DCCHandler +{ +public: + + status_t loadDCC(OMX_HANDLETYPE hComponent); + +private: + + OMX_ERRORTYPE initDCC(OMX_HANDLETYPE hComponent); + OMX_ERRORTYPE sendDCCBufPtr(OMX_HANDLETYPE hComponent, CameraBuffer *dccBuffer); + size_t readDCCdir(OMX_PTR buffer, const android::Vector<android::String8 *> &dirPaths); + +private: + + static android::String8 DCCPath; + static bool mDCCLoaded; +}; + +} // namespace Camera +} // namespace Ti + +#endif // OMX_DCC_H diff --git a/camera/inc/OMXCameraAdapter/OMXSceneModeTables.h b/camera/inc/OMXCameraAdapter/OMXSceneModeTables.h new file mode 100644 index 0000000..6ac9f2b --- /dev/null +++ b/camera/inc/OMXCameraAdapter/OMXSceneModeTables.h @@ -0,0 +1,759 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @file OMXSceneModeTables.h +* +* This holds scene mode settings for different omx cameras. +* +*/ + +#include "OMX_TI_IVCommon.h" +#include "OMX_TI_Common.h" +#include "OMX_TI_Index.h" + +#ifndef OMXCAMERAADAPTER_SCENEMODES_H +#define OMXCAMERAADAPTER_SCENEMODES_H + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(array) (sizeof((array)) / sizeof((array)[0])) +#endif + +namespace Ti { +namespace Camera { + +struct SceneModesEntry { + OMX_SCENEMODETYPE scene; + OMX_IMAGE_FLASHCONTROLTYPE flash; + int focus; + OMX_WHITEBALCONTROLTYPE wb; +}; + +struct CameraToSensorModesLUTEntry { + const char* name; + const SceneModesEntry* Table; + const unsigned int size; +}; + +static const SceneModesEntry S5K4E1GA_SceneModesLUT [] = { + { OMX_Closeup, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoMacro, + OMX_WhiteBalControlAuto }, + { OMX_Landscape, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Underwater, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoLock, + OMX_WhiteBalControlSunLight }, + { OMX_Sport, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Mood, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoLock, + OMX_WhiteBalControlAuto }, + { OMX_NightPortrait, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlPortrait, + OMX_WhiteBalControlAuto }, + { OMX_NightIndoor, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Fireworks, + OMX_IMAGE_FlashControlOn, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Document, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlAutoMacro, + OMX_WhiteBalControlAuto }, + { OMX_Barcode, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoMacro, + OMX_WhiteBalControlAuto }, + { OMX_SuperNight, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Cine, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_OldFilm, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Action, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlAuto, + OMX_WhiteBalControlAuto }, + { OMX_TI_Beach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlAutoLock, + OMX_WhiteBalControlAuto }, + { OMX_TI_Candlelight, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlIncandescent }, + { OMX_TI_Night, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlAuto, + OMX_WhiteBalControlAuto }, + { OMX_TI_Party, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAuto, + OMX_WhiteBalControlAuto }, + { OMX_TI_Portrait, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlPortrait, + OMX_WhiteBalControlAuto }, + { OMX_TI_Snow, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlAutoLock, + OMX_WhiteBalControlAuto }, + { OMX_TI_Steadyphoto, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Sunset, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlAuto, + OMX_WhiteBalControlSunLight }, + { OMX_TI_Theatre, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, +}; + +static const SceneModesEntry S5K6A1GX03_SceneModesLUT [] = { + { OMX_Closeup, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Landscape, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Underwater, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlSunLight }, + { OMX_Sport, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_SnowBeach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Mood, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_NightPortrait, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_NightIndoor, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Fireworks, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Document, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Barcode, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_SuperNight, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Cine, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_OldFilm, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Action, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Beach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Candlelight, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlIncandescent }, + { OMX_TI_Night, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Party, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Portrait, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Snow, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Steadyphoto, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Sunset, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlSunLight }, + { OMX_TI_Theatre, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, +}; + +static const SceneModesEntry IMX060_SceneModesLUT [] = { + { OMX_Closeup, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoMacro, + OMX_WhiteBalControlAuto }, + { OMX_Landscape, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlSunLight }, + { OMX_Underwater, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Sport, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_SnowBeach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Mood, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_NightPortrait, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlPortrait, + OMX_WhiteBalControlAuto }, + { OMX_NightIndoor, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Fireworks, + OMX_IMAGE_FlashControlOn, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Document, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoMacro, + OMX_WhiteBalControlAuto }, + { OMX_Barcode, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoMacro, + OMX_WhiteBalControlAuto }, + { OMX_SuperNight, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoInfinity, + OMX_WhiteBalControlAuto }, + { OMX_Cine, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_OldFilm, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Action, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Beach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Candlelight, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlIncandescent }, + { OMX_TI_Night, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Party, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoLock, + OMX_WhiteBalControlAuto }, + { OMX_TI_Portrait, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Snow, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Steadyphoto, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Sunset, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + ( OMX_WHITEBALCONTROLTYPE ) OMX_TI_WhiteBalControlSunset }, + { OMX_TI_Theatre, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, +}; + +static const SceneModesEntry OV5640_SceneModesLUT [] = { + { OMX_Closeup, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Landscape, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Underwater, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlSunLight }, + { OMX_Sport, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlAutoInfinity, + OMX_WhiteBalControlAuto }, + { OMX_SnowBeach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Mood, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_NightPortrait, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_NightIndoor, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Fireworks, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Document, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Barcode, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_SuperNight, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Cine, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_OldFilm, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Action, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Beach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Candlelight, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlIncandescent }, + { OMX_TI_Night, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Party, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Portrait, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Snow, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Steadyphoto, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Sunset, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Theatre, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, +}; + +static const SceneModesEntry OV5650_SceneModesLUT [] = { + { OMX_Closeup, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Landscape, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlSunLight }, + { OMX_Underwater, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Sport, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_SnowBeach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Mood, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_NightPortrait, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlPortrait, + OMX_WhiteBalControlAuto }, + { OMX_NightIndoor, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Fireworks, + OMX_IMAGE_FlashControlOn, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Document, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Barcode, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_SuperNight, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoInfinity, + OMX_WhiteBalControlAuto }, + { OMX_Cine, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_OldFilm, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Action, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Beach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Candlelight, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlIncandescent }, + { OMX_TI_Night, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Party, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoLock, + OMX_WhiteBalControlAuto }, + { OMX_TI_Portrait, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Snow, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Steadyphoto, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Sunset, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + ( OMX_WHITEBALCONTROLTYPE ) OMX_TI_WhiteBalControlSunset }, + { OMX_TI_Theatre, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, +}; + +static const SceneModesEntry OV8830_SceneModesLUT [] = { + { OMX_Closeup, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Landscape, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlSunLight }, + { OMX_Underwater, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Sport, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_SnowBeach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Mood, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_NightPortrait, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlPortrait, + OMX_WhiteBalControlAuto }, + { OMX_NightIndoor, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Fireworks, + OMX_IMAGE_FlashControlOn, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Document, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Barcode, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_SuperNight, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoInfinity, + OMX_WhiteBalControlAuto }, + { OMX_Cine, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_OldFilm, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Action, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Beach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Candlelight, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlIncandescent }, + { OMX_TI_Night, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Party, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoLock, + OMX_WhiteBalControlAuto }, + { OMX_TI_Portrait, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Snow, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Steadyphoto, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Sunset, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + ( OMX_WHITEBALCONTROLTYPE ) OMX_TI_WhiteBalControlSunset }, + { OMX_TI_Theatre, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, +}; + +static const SceneModesEntry OV2722_SceneModesLUT [] = { + { OMX_Closeup, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Landscape, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlSunLight }, + { OMX_Underwater, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Sport, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_SnowBeach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Mood, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_NightPortrait, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_NightIndoor, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Fireworks, + OMX_IMAGE_FlashControlOn, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Document, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_Barcode, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_SuperNight, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlAutoInfinity, + OMX_WhiteBalControlAuto }, + { OMX_Cine, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_OldFilm, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Action, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Beach, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Candlelight, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlIncandescent }, + { OMX_TI_Night, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Party, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Portrait, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Snow, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Steadyphoto, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, + { OMX_TI_Sunset, + OMX_IMAGE_FlashControlAuto, + OMX_IMAGE_FocusControlHyperfocal, + ( OMX_WHITEBALCONTROLTYPE ) OMX_TI_WhiteBalControlSunset }, + { OMX_TI_Theatre, + OMX_IMAGE_FlashControlOff, + OMX_IMAGE_FocusControlHyperfocal, + OMX_WhiteBalControlAuto }, +}; + +static const CameraToSensorModesLUTEntry CameraToSensorModesLUT [] = { + { "S5K4E1GA", S5K4E1GA_SceneModesLUT, ARRAY_SIZE(S5K4E1GA_SceneModesLUT)}, + { "S5K6A1GX03", S5K6A1GX03_SceneModesLUT, ARRAY_SIZE(S5K6A1GX03_SceneModesLUT)}, + { "IMX060", IMX060_SceneModesLUT, ARRAY_SIZE(IMX060_SceneModesLUT)}, + { "OV5640", OV5640_SceneModesLUT, ARRAY_SIZE(OV5640_SceneModesLUT)}, + { "OV5650", OV5650_SceneModesLUT, ARRAY_SIZE(OV5650_SceneModesLUT)}, + { "OV8830", OV8830_SceneModesLUT, ARRAY_SIZE(OV8830_SceneModesLUT)}, + { "OV9726", OV2722_SceneModesLUT, ARRAY_SIZE(OV2722_SceneModesLUT)}, + { "OV2722", OV2722_SceneModesLUT, ARRAY_SIZE(OV2722_SceneModesLUT)}, +#ifdef MOTOROLA_CAMERA + { "OV8820", OV8830_SceneModesLUT, ARRAY_SIZE(OV8830_SceneModesLUT)}, + { "OV7739", OV2722_SceneModesLUT, ARRAY_SIZE(OV2722_SceneModesLUT)}, + { "MT9M114", OV2722_SceneModesLUT, ARRAY_SIZE(OV2722_SceneModesLUT)}, +#endif +}; + +} // namespace Camera +} // namespace Ti + +#endif diff --git a/camera/inc/OmxFrameDecoder.h b/camera/inc/OmxFrameDecoder.h new file mode 100644 index 0000000..7cbbf2c --- /dev/null +++ b/camera/inc/OmxFrameDecoder.h @@ -0,0 +1,204 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OMXFRAMEDECODER_H_ +#define OMXFRAMEDECODER_H_ + + +#include <utils/threads.h> +#include <utils/List.h> +#include "FrameDecoder.h" +#include "OMX_Types.h" +#include "OMX_Core.h" +#include "OMX_Component.h" +#include "Decoder_libjpeg.h" + +namespace Ti { +namespace Camera { + +enum OmxDecoderState { + OmxDecoderState_Unloaded = 0, + OmxDecoderState_Loaded, + OmxDecoderState_Idle, + OmxDecoderState_Executing, + OmxDecoderState_Error, + OmxDecoderState_Invalid, + OmxDecoderState_Reconfigure, + OmxDecoderState_Exit +}; + +enum PortType { + PortIndexInput = 0, + PortIndexOutput = 1 +}; + + +struct OmxMessage { + enum { + EVENT, + EMPTY_BUFFER_DONE, + FILL_BUFFER_DONE, + }type; + + union { + // if type == EVENT + struct { + OMX_PTR appData; + OMX_EVENTTYPE event; + OMX_U32 data1; + OMX_U32 data2; + OMX_PTR pEventData; + } eventData; + + // if type == (EMPTY_BUFFER_DONE || FILL_BUFFER_DONE) + struct { + OMX_PTR appData; + OMX_BUFFERHEADERTYPE* pBuffHead; + } bufferData; + } u; +}; + +class CallbackDispatcher; + +struct CallbackDispatcherThread : public android::Thread { + CallbackDispatcherThread(CallbackDispatcher *dispatcher) + : mDispatcher(dispatcher) { + } + +private: + CallbackDispatcher *mDispatcher; + + bool threadLoop(); + + CallbackDispatcherThread(const CallbackDispatcherThread &); + CallbackDispatcherThread &operator=(const CallbackDispatcherThread &); +}; + +class CallbackDispatcher +{ + +public: + CallbackDispatcher(); + ~CallbackDispatcher(); + + void post(const OmxMessage &msg); + bool loop(); + +private: + void dispatch(const OmxMessage &msg); + + CallbackDispatcher(const CallbackDispatcher &); + CallbackDispatcher &operator=(const CallbackDispatcher &); + + android::Mutex mLock; + android::Condition mQueueChanged; + android::List<OmxMessage> mQueue; + android::sp<CallbackDispatcherThread> mThread; + bool mDone; +}; + +class OmxFrameDecoder : public FrameDecoder +{ + +public: + OmxFrameDecoder(DecoderType type = DecoderType_MJPEG); + virtual ~OmxFrameDecoder(); + + OMX_ERRORTYPE eventHandler(const OMX_EVENTTYPE event, const OMX_U32 data1, const OMX_U32 data2, + const OMX_PTR pEventData); + OMX_ERRORTYPE fillBufferDoneHandler(OMX_BUFFERHEADERTYPE* pBuffHead); + OMX_ERRORTYPE emptyBufferDoneHandler(OMX_BUFFERHEADERTYPE* pBuffHead); + + static OMX_ERRORTYPE eventCallback(const OMX_HANDLETYPE component, + const OMX_PTR appData, const OMX_EVENTTYPE event, const OMX_U32 data1, const OMX_U32 data2, + const OMX_PTR pEventData); + static OMX_ERRORTYPE emptyBufferDoneCallback(OMX_HANDLETYPE hComponent, OMX_PTR appData, OMX_BUFFERHEADERTYPE* pBuffHead); + static OMX_ERRORTYPE fillBufferDoneCallback(OMX_HANDLETYPE hComponent, OMX_PTR appData, OMX_BUFFERHEADERTYPE* pBuffHead); + + virtual bool getPaddedDimensions(size_t &width, size_t &height); + +protected: + virtual void doConfigure (const DecoderParameters& config); + virtual void doProcessInputBuffer(); + virtual status_t doStart(); + virtual void doStop(); + virtual void doFlush(); + virtual void doRelease(); + +private: + status_t setComponentRole(); + status_t enableGrallockHandles(); + status_t allocateBuffersOutput(); + void freeBuffersOnOutput(); + void freeBuffersOnInput(); + status_t doPortReconfigure(); + void dumpPortSettings(PortType port); + status_t getAndConfigureDecoder(); + status_t configureJpegPorts(int width, int height); + status_t switchToIdle(); + status_t allocateBuffersInput(); + status_t disablePortSync(int port); + status_t enablePortSync(int port); + void queueOutputBuffers(); + status_t setVideoOutputFormat(OMX_U32 width, OMX_U32 height); + + + status_t omxInit(); + status_t omxGetHandle(OMX_HANDLETYPE *handle, OMX_PTR pAppData, OMX_CALLBACKTYPE & callbacks); + OmxDecoderState getOmxState() { return mCurrentState; } + status_t commitState(OmxDecoderState state) { mPreviousState = mCurrentState; mCurrentState = state; return NO_ERROR; } + status_t setVideoPortFormatType( + OMX_U32 portIndex, + OMX_VIDEO_CODINGTYPE compressionFormat, + OMX_COLOR_FORMATTYPE colorFormat); + status_t omxGetParameter(OMX_INDEXTYPE index, OMX_PTR ptr); + status_t omxSetParameter(OMX_INDEXTYPE index, OMX_PTR ptr); + status_t omxSendCommand(OMX_COMMANDTYPE cmd, OMX_S32 param); + status_t omxGetConfig(OMX_INDEXTYPE index, OMX_PTR ptr); + status_t omxSetConfig(OMX_INDEXTYPE index, OMX_PTR ptr); + status_t omxFillThisBuffer(OMX_BUFFERHEADERTYPE *pOutBufHdr); + status_t omxEmptyThisBuffer(android::sp<MediaBuffer>& inBuffer, OMX_BUFFERHEADERTYPE *pInBufHdr); + void omxDumpPortSettings(OMX_PARAM_PORTDEFINITIONTYPE& def); + void omxDumpBufferHeader (OMX_BUFFERHEADERTYPE* bh); + status_t omxSwitchToExecutingSync(); + + bool mOmxInialized; + + OMX_HANDLETYPE mHandleComp; + OmxDecoderState mCurrentState; + OmxDecoderState mPreviousState; + + // Condition and Mutex used during OpenMAX state transitions & command completion + android::Condition mStateCondition; + android::Mutex mHwLock; + + android::Vector<OMX_BUFFERHEADERTYPE*> mOutBufferHeaders; + android::Vector<OMX_BUFFERHEADERTYPE*> mInBufferHeaders; + + CallbackDispatcher mDispatcher; + + bool mStopping; + DecoderType mDecoderType; + + // If true we will search for DHT in JPEG buffer + bool mIsNeedCheckDHT; + // If true we always append DHT to JPEG buffer + bool mAlwaysAppendDHT; +}; + +} //namespace Camera +} //namespace Ti +#endif /* OMXFRAMEDECODER_H_ */ diff --git a/camera/inc/SensorListener.h b/camera/inc/SensorListener.h new file mode 100644 index 0000000..44037b7 --- /dev/null +++ b/camera/inc/SensorListener.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @file SensorListener.h +* +* This defines API for camerahal to get sensor events +* +*/ + +#ifndef ANDROID_CAMERA_HARDWARE_SENSOR_LISTENER_H +#define ANDROID_CAMERA_HARDWARE_SENSOR_LISTENER_H + +#include <android/sensor.h> +#include <gui/Sensor.h> +#include <gui/SensorManager.h> +#include <gui/SensorEventQueue.h> +#include <utils/Looper.h> + +#include "Common.h" + +namespace Ti { +namespace Camera { + +/** + * SensorListner class - Registers with sensor manager to get sensor events + */ + +typedef void (*orientation_callback_t) (uint32_t orientation, uint32_t tilt, void* cookie); + +class SensorLooperThread : public android::Thread { + public: + SensorLooperThread(android::Looper* looper) + : Thread(false) { + mLooper = android::sp<android::Looper>(looper); + } + ~SensorLooperThread() { + mLooper.clear(); + } + + virtual bool threadLoop() { + int32_t ret = mLooper->pollOnce(-1); + return true; + } + + // force looper wake up + void wake() { + mLooper->wake(); + } + private: + android::sp<android::Looper> mLooper; +}; + + +class SensorListener : public android::RefBase +{ +/* public - types */ +public: + typedef enum { + SENSOR_ACCELEROMETER = 1 << 0, + SENSOR_MAGNETIC_FIELD = 1 << 1, + SENSOR_GYROSCOPE = 1 << 2, + SENSOR_LIGHT = 1 << 3, + SENSOR_PROXIMITY = 1 << 4, + SENSOR_ORIENTATION = 1 << 5, + } sensor_type_t; +/* public - functions */ +public: + SensorListener(); + ~SensorListener(); + status_t initialize(); + void setCallbacks(orientation_callback_t orientation_cb, void *cookie); + void enableSensor(sensor_type_t type); + void disableSensor(sensor_type_t type); + void handleOrientation(uint32_t orientation, uint32_t tilt); +/* public - member variables */ +public: + android::sp<android::SensorEventQueue> mSensorEventQueue; +/* private - member variables */ +private: + int sensorsEnabled; + orientation_callback_t mOrientationCb; + void *mCbCookie; + android::sp<android::Looper> mLooper; + android::sp<SensorLooperThread> mSensorLooperThread; + android::Mutex mLock; +}; + +} // namespace Camera +} // namespace Ti + +#endif diff --git a/camera/inc/SwFrameDecoder.h b/camera/inc/SwFrameDecoder.h new file mode 100644 index 0000000..f123940 --- /dev/null +++ b/camera/inc/SwFrameDecoder.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SWFRAMEDECODER_H_ +#define SWFRAMEDECODER_H_ + +#include "FrameDecoder.h" +#include "Decoder_libjpeg.h" + +namespace Ti { +namespace Camera { + +class SwFrameDecoder: public FrameDecoder { +public: + SwFrameDecoder(); + virtual ~SwFrameDecoder(); + +protected: + virtual void doConfigure(const DecoderParameters& config); + virtual void doProcessInputBuffer(); + virtual status_t doStart() { return NO_ERROR; } + virtual void doStop() { } + virtual void doFlush() { } + virtual void doRelease() { } + +private: + int mjpegWithHdrSize; + Decoder_libjpeg mJpgdecoder; + unsigned char* mJpegWithHeaderBuffer; +}; + +} // namespace Camera +} // namespace Ti +#endif /* SWFRAMEDECODER_H_ */ diff --git a/camera/inc/TICameraParameters.h b/camera/inc/TICameraParameters.h new file mode 100644 index 0000000..8686456 --- /dev/null +++ b/camera/inc/TICameraParameters.h @@ -0,0 +1,270 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TI_CAMERA_PARAMETERS_H +#define TI_CAMERA_PARAMETERS_H + +#include <utils/KeyedVector.h> +#include <utils/String8.h> + +namespace Ti { +namespace Camera { + +///TI Specific Camera Parameters +class TICameraParameters +{ +public: + +// Supported Camera indexes +// Example value: "0,1,2,3", where 0-primary, 1-secondary1, 2-secondary2, 3-sterocamera +static const char KEY_SUPPORTED_CAMERAS[]; +// Select logical Camera index +static const char KEY_CAMERA[]; +static const char KEY_CAMERA_NAME[]; +static const char KEY_BURST[]; +static const char KEY_CAP_MODE[]; +static const char KEY_CAP_MODE_VALUES[]; +static const char KEY_VNF[]; +static const char KEY_VNF_SUPPORTED[]; +static const char KEY_SATURATION[]; +static const char KEY_BRIGHTNESS[]; +static const char KEY_SUPPORTED_EXPOSURE[]; +static const char KEY_EXPOSURE_MODE[]; +static const char KEY_SUPPORTED_MANUAL_EXPOSURE_MIN[]; +static const char KEY_SUPPORTED_MANUAL_EXPOSURE_MAX[]; +static const char KEY_SUPPORTED_MANUAL_EXPOSURE_STEP[]; +static const char KEY_SUPPORTED_MANUAL_GAIN_ISO_MIN[]; +static const char KEY_SUPPORTED_MANUAL_GAIN_ISO_MAX[]; +static const char KEY_SUPPORTED_MANUAL_GAIN_ISO_STEP[]; +static const char KEY_MANUAL_EXPOSURE[]; +static const char KEY_MANUAL_EXPOSURE_RIGHT[]; +static const char KEY_MANUAL_GAIN_ISO[]; +static const char KEY_MANUAL_GAIN_ISO_RIGHT[]; +static const char KEY_CONTRAST[]; +static const char KEY_SHARPNESS[]; +static const char KEY_ISO[]; +static const char KEY_SUPPORTED_ISO_VALUES[]; +static const char KEY_SUPPORTED_IPP[]; +static const char KEY_IPP[]; +static const char KEY_METERING_MODE[]; +static const char KEY_EXP_BRACKETING_RANGE[]; +static const char KEY_EXP_GAIN_BRACKETING_RANGE[]; +static const char KEY_ZOOM_BRACKETING_RANGE[]; +static const char KEY_TEMP_BRACKETING[]; +static const char KEY_TEMP_BRACKETING_RANGE_POS[]; +static const char KEY_TEMP_BRACKETING_RANGE_NEG[]; +static const char KEY_FLUSH_SHOT_CONFIG_QUEUE[]; +static const char KEY_SHUTTER_ENABLE[]; +static const char KEY_MEASUREMENT_ENABLE[]; +static const char KEY_INITIAL_VALUES[]; +static const char KEY_GBCE[]; +static const char KEY_GBCE_SUPPORTED[]; +static const char KEY_GLBCE[]; +static const char KEY_GLBCE_SUPPORTED[]; +static const char KEY_FRAMERATE_RANGES_EXT_SUPPORTED[]; +static const char KEY_FRAMERATES_EXT_SUPPORTED[]; + +// TI recording hint to notify camera adapters of possible recording +static const char KEY_RECORDING_HINT[]; +static const char KEY_AUTO_FOCUS_LOCK[]; +static const char KEY_CURRENT_ISO[]; + +static const char KEY_SENSOR_ORIENTATION[]; + +//TI extensions for camera capabilies +static const char INITIAL_VALUES_TRUE[]; +static const char INITIAL_VALUES_FALSE[]; + +// TI extensions to add values for ManualConvergence and AutoConvergence mode +static const char KEY_AUTOCONVERGENCE_MODE[]; +static const char KEY_AUTOCONVERGENCE_MODE_VALUES[]; +static const char KEY_MANUAL_CONVERGENCE[]; +static const char KEY_SUPPORTED_MANUAL_CONVERGENCE_MIN[]; +static const char KEY_SUPPORTED_MANUAL_CONVERGENCE_MAX[]; +static const char KEY_SUPPORTED_MANUAL_CONVERGENCE_STEP[]; + +// TI extensions to add Min frame rate Values +static const char VIDEO_MINFRAMERATE_5[]; +static const char VIDEO_MINFRAMERATE_10[]; +static const char VIDEO_MINFRAMERATE_15[]; +static const char VIDEO_MINFRAMERATE_20[]; +static const char VIDEO_MINFRAMERATE_24[]; +static const char VIDEO_MINFRAMERATE_25[]; +static const char VIDEO_MINFRAMERATE_30[]; +static const char VIDEO_MINFRAMERATE_33[]; + +//TI extensions for setting EXIF tags +static const char KEY_EXIF_MODEL[]; +static const char KEY_EXIF_MAKE[]; + +//TI extensions for additional GPS data +static const char KEY_GPS_MAPDATUM[]; +static const char KEY_GPS_VERSION[]; +static const char KEY_GPS_DATESTAMP[]; + +// TI extensions for VTC +static const char KEY_VTC_HINT[]; +static const char KEY_VIDEO_ENCODER_HANDLE[]; +static const char KEY_VIDEO_ENCODER_SLICE_HEIGHT[]; + +static const char RAW_WIDTH[]; +static const char RAW_HEIGHT[]; + +//TI extensions to Image post-processing +static const char IPP_LDCNSF[]; +static const char IPP_LDC[]; +static const char IPP_NSF[]; +static const char IPP_NONE[]; + +//TI extensions to camera mode +static const char HIGH_PERFORMANCE_MODE[]; +static const char HIGH_QUALITY_MODE[]; +static const char HIGH_QUALITY_ZSL_MODE[]; +static const char CP_CAM_MODE[]; +static const char VIDEO_MODE[]; +static const char VIDEO_MODE_HQ[]; +static const char EXPOSURE_BRACKETING[]; +static const char ZOOM_BRACKETING[]; +static const char TEMP_BRACKETING[]; + +// TI extensions to standard android pixel formats +static const char PIXEL_FORMAT_UNUSED[]; +static const char PIXEL_FORMAT_JPS[]; +static const char PIXEL_FORMAT_MPO[]; +static const char PIXEL_FORMAT_YUV422I_UYVY[]; + +// TI extensions to standard android scene mode settings +static const char SCENE_MODE_CLOSEUP[]; +static const char SCENE_MODE_AQUA[]; +static const char SCENE_MODE_SNOWBEACH[]; +static const char SCENE_MODE_MOOD[]; +static const char SCENE_MODE_NIGHT_INDOOR[]; +static const char SCENE_MODE_DOCUMENT[]; +static const char SCENE_MODE_BARCODE[]; +static const char SCENE_MODE_VIDEO_SUPER_NIGHT[]; +static const char SCENE_MODE_VIDEO_CINE[]; +static const char SCENE_MODE_VIDEO_OLD_FILM[]; + +// TI extensions to standard android white balance settings. +static const char WHITE_BALANCE_TUNGSTEN[]; +static const char WHITE_BALANCE_HORIZON[]; +static const char WHITE_BALANCE_SUNSET[]; +static const char WHITE_BALANCE_FACE[]; + +// TI extensions to add exposure preset modes to android api +static const char EXPOSURE_MODE_MANUAL[]; +static const char EXPOSURE_MODE_AUTO[]; +static const char EXPOSURE_MODE_NIGHT[]; +static const char EXPOSURE_MODE_BACKLIGHT[]; +static const char EXPOSURE_MODE_SPOTLIGHT[]; +static const char EXPOSURE_MODE_SPORTS[]; +static const char EXPOSURE_MODE_SNOW[]; +static const char EXPOSURE_MODE_BEACH[]; +static const char EXPOSURE_MODE_APERTURE[]; +static const char EXPOSURE_MODE_SMALL_APERTURE[]; +static const char EXPOSURE_MODE_FACE[]; + +// TI extensions to standard android focus presets. +static const char FOCUS_MODE_PORTRAIT[]; +static const char FOCUS_MODE_EXTENDED[]; +static const char FOCUS_MODE_FACE[]; +static const char FOCUS_MODE_OFF[]; + +// TI extensions to add iso values +static const char ISO_MODE_AUTO[]; +static const char ISO_MODE_100[]; +static const char ISO_MODE_200[]; +static const char ISO_MODE_400[]; +static const char ISO_MODE_800[]; +static const char ISO_MODE_1000[]; +static const char ISO_MODE_1200[]; +static const char ISO_MODE_1600[]; + +// TI extensions to add values for effect settings. +static const char EFFECT_NATURAL[]; +static const char EFFECT_VIVID[]; +static const char EFFECT_COLOR_SWAP[]; +static const char EFFECT_BLACKWHITE[]; + +//TI extensions for stereo frame layouts +static const char KEY_S3D_PRV_FRAME_LAYOUT[]; +static const char KEY_S3D_PRV_FRAME_LAYOUT_VALUES[]; +static const char KEY_S3D_CAP_FRAME_LAYOUT[]; +static const char KEY_S3D_CAP_FRAME_LAYOUT_VALUES[]; + +//TI extensions for stereo frame layouts +static const char S3D_NONE[]; +static const char S3D_TB_FULL[]; +static const char S3D_SS_FULL[]; +static const char S3D_TB_SUBSAMPLED[]; +static const char S3D_SS_SUBSAMPLED[]; + +//TI extentions fo 3D resolutions +static const char KEY_SUPPORTED_PICTURE_SUBSAMPLED_SIZES[]; +static const char KEY_SUPPORTED_PICTURE_TOPBOTTOM_SIZES[]; +static const char KEY_SUPPORTED_PICTURE_SIDEBYSIDE_SIZES[]; +static const char KEY_SUPPORTED_PREVIEW_SUBSAMPLED_SIZES[]; +static const char KEY_SUPPORTED_PREVIEW_TOPBOTTOM_SIZES[]; +static const char KEY_SUPPORTED_PREVIEW_SIDEBYSIDE_SIZES[]; + +// TI extensions to add values for AutoConvergence settings. +static const char AUTOCONVERGENCE_MODE_DISABLE[]; +static const char AUTOCONVERGENCE_MODE_FRAME[]; +static const char AUTOCONVERGENCE_MODE_CENTER[]; +static const char AUTOCONVERGENCE_MODE_TOUCH[]; +static const char AUTOCONVERGENCE_MODE_MANUAL[]; + +//TI extensions for flash mode settings +static const char FLASH_MODE_FILL_IN[]; + +//TI extensions to add sensor orientation parameters +static const char ORIENTATION_SENSOR_NONE[]; +static const char ORIENTATION_SENSOR_90[]; +static const char ORIENTATION_SENSOR_180[]; +static const char ORIENTATION_SENSOR_270[]; + + +//TI values for camera direction +static const char FACING_FRONT[]; +static const char FACING_BACK[]; + +static const char KEY_MECHANICAL_MISALIGNMENT_CORRECTION_SUPPORTED[]; +static const char KEY_MECHANICAL_MISALIGNMENT_CORRECTION[]; + +//TI extensions for enable/disable algos +static const char KEY_ALGO_EXTERNAL_GAMMA[]; +static const char KEY_ALGO_NSF1[]; +static const char KEY_ALGO_NSF2[]; +static const char KEY_ALGO_SHARPENING[]; +static const char KEY_ALGO_THREELINCOLORMAP[]; +static const char KEY_ALGO_GIC[]; + +//Gamma table +static const char KEY_GAMMA_TABLE[]; + +static const char KEY_PREVIEW_FRAME_RATE_RANGE[]; + +#ifdef MOTOROLA_CAMERA +static const char KEY_MOT_LEDFLASH[]; +static const char KEY_MOT_LEDTORCH[]; +#endif + +}; + +} // namespace Camera +} // namespace Ti + +#endif diff --git a/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h b/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h new file mode 100644 index 0000000..e1e7cad --- /dev/null +++ b/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h @@ -0,0 +1,262 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#ifndef V4L_CAMERA_ADAPTER_H +#define V4L_CAMERA_ADAPTER_H + +#include <linux/videodev2.h> + +#include "CameraHal.h" +#include "BaseCameraAdapter.h" +#include "DebugUtils.h" +#include "Decoder_libjpeg.h" +#include "FrameDecoder.h" + + +namespace Ti { +namespace Camera { + +#ifndef V4L2_PIX_FMT_H264 +#define V4L2_PIX_FMT_H264 0 +#endif + +#define DEFAULT_PIXEL_FORMAT V4L2_PIX_FMT_YUYV +#define DEFAULT_CAPTURE_FORMAT V4L2_PIX_FMT_YUYV + +#define NB_BUFFER 10 +#define DEVICE "/dev/videoxx" +#define DEVICE_PATH "/dev/" +#define DEVICE_NAME "videoxx" + +typedef int V4L_HANDLETYPE; + +struct CapPixelformat { + uint32_t pixelformat; + const char *param; +}; + +struct CapResolution { + size_t width, height; + char param[10]; +}; + +struct CapU32 { + uint32_t num; + const char *param; +}; + +typedef CapU32 CapFramerate; + +struct VideoInfo { + struct v4l2_capability cap; + struct v4l2_format format; + struct v4l2_buffer buf; + struct v4l2_requestbuffers rb; + void *mem[NB_BUFFER]; + void *CaptureBuffers[NB_BUFFER]; + bool isStreaming; + int width; + int height; + int formatIn; + int framesizeIn; +}; + +typedef struct V4L_TI_CAPTYPE { + uint16_t ulPreviewFormatCount; // supported preview pixelformat count + uint32_t ePreviewFormats[32]; + uint16_t ulPreviewResCount; // supported preview resolution sizes + CapResolution tPreviewRes[32]; + uint16_t ulCaptureResCount; // supported capture resolution sizes + CapResolution tCaptureRes[32]; + uint16_t ulFrameRateCount; // supported frame rate + uint16_t ulFrameRates[32]; +}V4L_TI_CAPTYPE; + +/** + * Class which completely abstracts the camera hardware interaction from camera hal + * TODO: Need to list down here, all the message types that will be supported by this class + Need to implement BufferProvider interface to use AllocateBuffer of OMX if needed + */ +class V4LCameraAdapter : public BaseCameraAdapter +{ +public: + + /*--------------------Constant declarations----------------------------------------*/ + static const int32_t MAX_NO_BUFFERS = 20; + + ///@remarks OMX Camera has six ports - buffer input, time input, preview, image, video, and meta data + static const int MAX_NO_PORTS = 6; + + ///Five second timeout + static const int CAMERA_ADAPTER_TIMEOUT = 5000*1000; + +public: + + V4LCameraAdapter(size_t sensor_index, CameraHal* hal); + ~V4LCameraAdapter(); + + + ///Initialzes the camera adapter creates any resources required + virtual status_t initialize(CameraProperties::Properties*); + + //APIs to configure Camera adapter and get the current parameter set + virtual status_t setParameters(const android::CameraParameters& params); + virtual void getParameters(android::CameraParameters& params); + + // API + virtual status_t UseBuffersPreview(CameraBuffer *bufArr, int num); + virtual status_t UseBuffersCapture(CameraBuffer *bufArr, int num); + + static status_t getCaps(const int sensorId, CameraProperties::Properties* params, V4L_HANDLETYPE handle); + + void setupWorkingMode(); + +protected: + +//----------Parent class method implementation------------------------------------ + virtual status_t startPreview(); + virtual status_t stopPreview(); + virtual status_t takePicture(); + virtual status_t stopImageCapture(); + virtual status_t autoFocus(); + virtual status_t useBuffers(CameraMode mode, CameraBuffer *bufArr, int num, size_t length, unsigned int queueable); + virtual status_t fillThisBuffer(CameraBuffer *frameBuf, CameraFrame::FrameType frameType); + virtual status_t getFrameSize(size_t &width, size_t &height); + virtual status_t getPictureBufferSize(CameraFrame &frame, size_t bufferCount); + virtual status_t getFrameDataSize(size_t &dataFrameSize, size_t bufferCount); + virtual void onOrientationEvent(uint32_t orientation, uint32_t tilt); +//----------------------------------------------------------------------------- + + +private: + + class PreviewThread : public android::Thread { + V4LCameraAdapter* mAdapter; + public: + PreviewThread(V4LCameraAdapter* hw) : + Thread(false), mAdapter(hw) { } + virtual void onFirstRef() { + run("CameraPreviewThread", android::PRIORITY_URGENT_DISPLAY); + } + virtual bool threadLoop() { + mAdapter->previewThread(); + // loop until we need to quit + return true; + } + }; + + //Used for calculation of the average frame rate during preview + status_t recalculateFPS(); + + char * GetFrame(int &index, int &filledLen); + + int previewThread(); + +private: + //capabilities data + static const CapPixelformat mPixelformats []; + static const CapResolution mPreviewRes []; + static const CapFramerate mFramerates []; + static const CapResolution mImageCapRes []; + + //camera defaults + static const char DEFAULT_PREVIEW_FORMAT[]; + static const char DEFAULT_PREVIEW_SIZE[]; + static const char DEFAULT_FRAMERATE[]; + static const char DEFAULT_NUM_PREV_BUFS[]; + + static const char DEFAULT_PICTURE_FORMAT[]; + static const char DEFAULT_PICTURE_SIZE[]; + static const char DEFAULT_FOCUS_MODE[]; + static const char DEFAULT_FRAMERATE_RANGE[]; + static const char * DEFAULT_VSTAB; + static const char * DEFAULT_VNF; + + static status_t insertDefaults(CameraProperties::Properties*, V4L_TI_CAPTYPE&); + static status_t insertCapabilities(CameraProperties::Properties*, V4L_TI_CAPTYPE&); + static status_t insertPreviewFormats(CameraProperties::Properties* , V4L_TI_CAPTYPE&); + static status_t insertPreviewSizes(CameraProperties::Properties* , V4L_TI_CAPTYPE&); + static status_t insertImageSizes(CameraProperties::Properties* , V4L_TI_CAPTYPE&); + static status_t insertFrameRates(CameraProperties::Properties* , V4L_TI_CAPTYPE&); + static status_t sortAscend(V4L_TI_CAPTYPE&, uint16_t ) ; + + status_t v4lIoctl(int, int, void*); + status_t v4lInitMmap(int& count, int width, int height); + status_t v4lInitUsrPtr(int&); + status_t v4lStartStreaming(); + status_t v4lStopStreaming(int nBufferCount); + status_t v4lSetFormat(int, int, uint32_t); + status_t restartPreview(); + status_t applyFpsValue(); + status_t returnBufferToV4L(int id); + void returnOutputBuffer(int index); + bool isNeedToUseDecoder() const; + + int mPreviewBufferCount; + int mPreviewBufferCountQueueable; + int mCaptureBufferCount; + int mCaptureBufferCountQueueable; + CameraBuffer *mPreviewBufs[NB_BUFFER]; + android::KeyedVector<CameraBuffer *, int> mCaptureBufs; + + android::CameraParameters mParams; + + bool mPreviewing; + bool mCapturing; + mutable android::Mutex mLock; + + int mFrameCount; + int mLastFrameCount; + unsigned int mIter; + nsecs_t mLastFPSTime; + + //variables holding the estimated framerate + float mFPS, mLastFPS; + + int mSensorIndex; + + // protected by mLock + android::sp<PreviewThread> mPreviewThread; + + struct VideoInfo *mVideoInfo; + int mCameraHandle; + + int nQueued; + int nDequeued; + int mQueuedOutputBuffers; + + FrameDecoder* mDecoder; + android::Vector< android::sp<MediaBuffer> > mInBuffers; + android::Vector< android::sp<MediaBuffer> > mOutBuffers; + + android::Mutex mV4LLock; + + int mPixelFormat; + int mFrameRate; + + android::Mutex mStopLock; + android::Condition mStopCondition; + + CameraHal* mCameraHal; + int mSkipFramesCount; +}; + +} // namespace Camera +} // namespace Ti + +#endif //V4L_CAMERA_ADAPTER_H diff --git a/camera/inc/VideoMetadata.h b/camera/inc/VideoMetadata.h new file mode 100644 index 0000000..f05ee50 --- /dev/null +++ b/camera/inc/VideoMetadata.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VIDEO_METADATA_H +#define VIDEO_METADATA_H + +/* This structure is used to pass buffer offset from Camera-Hal to Encoder component + * for specific algorithms like VSTAB & VNF + */ + +typedef struct +{ + int metadataBufferType; + void* handle; + int offset; +} +video_metadata_t; + +#endif |