blob: 321eb15005ce347773011eeb05ce8cde4e37a2bd [file] [log] [blame]
codeworkx62f02ba2012-05-20 12:00:36 +02001/*
2**
3** Copyright 2008, The Android Open Source Project
4** Copyright 2010, Samsung Electronics Co. LTD
5**
6** Licensed under the Apache License, Version 2.0 (the "License");
7** you may not use this file except in compliance with the License.
8** You may obtain a copy of the License at
9**
10** http://www.apache.org/licenses/LICENSE-2.0
11**
12** Unless required by applicable law or agreed to in writing, software
13** distributed under the License is distributed on an "AS IS" BASIS,
14** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15** See the License for the specific language governing permissions and
16** limitations under the License.
17*/
18
19#ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_SEC_H
20#define ANDROID_HARDWARE_CAMERA_HARDWARE_SEC_H
21
22#include "SecCamera.h"
23#include <utils/threads.h>
24#include <utils/RefBase.h>
25#include <binder/MemoryBase.h>
26#include <binder/MemoryHeapBase.h>
27#include <hardware/camera.h>
28#include <hardware/gralloc.h>
29#include <camera/CameraParameters.h>
30#ifdef BOARD_USE_V4L2_ION
31#include <binder/MemoryHeapBaseIon.h>
32#include "gralloc_priv.h"
33
34#define BUFFER_COUNT_FOR_GRALLOC (MAX_BUFFERS + 4)
35#define BUFFER_COUNT_FOR_ARRAY (MAX_BUFFERS)
36#else
37#define BUFFER_COUNT_FOR_GRALLOC (MAX_BUFFERS)
38#define BUFFER_COUNT_FOR_ARRAY (1)
39#endif
40
41namespace android {
42 class CameraHardwareSec : public virtual RefBase {
43public:
44 virtual void setCallbacks(camera_notify_callback notify_cb,
45 camera_data_callback data_cb,
46 camera_data_timestamp_callback data_cb_timestamp,
47 camera_request_memory get_memory,
48 void *user);
49
50 virtual void enableMsgType(int32_t msgType);
51 virtual void disableMsgType(int32_t msgType);
52 virtual bool msgTypeEnabled(int32_t msgType);
53
54 virtual status_t startPreview();
55 virtual void stopPreview();
56 virtual bool previewEnabled();
57
58 virtual status_t startRecording();
59 virtual void stopRecording();
60 virtual bool recordingEnabled();
61 virtual void releaseRecordingFrame(const void *opaque);
62
63 virtual status_t autoFocus();
64 virtual status_t cancelAutoFocus();
65 virtual status_t takePicture();
66 virtual status_t cancelPicture();
67 virtual status_t dump(int fd) const;
68 virtual status_t setParameters(const CameraParameters& params);
69 virtual CameraParameters getParameters() const;
70 virtual status_t sendCommand(int32_t command, int32_t arg1, int32_t arg2);
71 virtual status_t setPreviewWindow(preview_stream_ops *w);
72 virtual status_t storeMetaDataInBuffers(bool enable);
73 virtual void release();
74
75 inline int getCameraId() const;
76
77 CameraHardwareSec(int cameraId, camera_device_t *dev);
78 virtual ~CameraHardwareSec();
79private:
80 status_t startPreviewInternal();
81 void stopPreviewInternal();
82
83 class PreviewThread : public Thread {
84 CameraHardwareSec *mHardware;
85 public:
86 PreviewThread(CameraHardwareSec *hw):
87 Thread(false),
88 mHardware(hw) { }
89 virtual void onFirstRef() {
90 run("CameraPreviewThread", PRIORITY_URGENT_DISPLAY);
91 }
92 virtual bool threadLoop() {
93 mHardware->previewThreadWrapper();
94 return false;
95 }
96 };
97
98 class PictureThread : public Thread {
99 CameraHardwareSec *mHardware;
100 public:
101 PictureThread(CameraHardwareSec *hw):
102 Thread(false),
103 mHardware(hw) { }
104 virtual bool threadLoop() {
105 mHardware->pictureThread();
106 return false;
107 }
108 };
109
110 class AutoFocusThread : public Thread {
111 CameraHardwareSec *mHardware;
112 public:
113 AutoFocusThread(CameraHardwareSec *hw): Thread(false), mHardware(hw) { }
114 virtual void onFirstRef() {
115 run("CameraAutoFocusThread", PRIORITY_DEFAULT);
116 }
117 virtual bool threadLoop() {
118 mHardware->autoFocusThread();
119 return true;
120 }
121 };
122
123 void initDefaultParameters(int cameraId);
124 void initHeapLocked();
125
126 sp<PreviewThread> mPreviewThread;
127 int previewThread();
128 int previewThreadWrapper();
129
130 sp<AutoFocusThread> mAutoFocusThread;
131 int autoFocusThread();
132
133 sp<PictureThread> mPictureThread;
134 int pictureThread();
135 bool mCaptureInProgress;
136
137 int save_jpeg(unsigned char *real_jpeg, int jpeg_size);
138 void save_postview(const char *fname, uint8_t *buf,
139 uint32_t size);
140 int decodeInterleaveData(unsigned char *pInterleaveData,
141 int interleaveDataSize,
142 int yuvWidth,
143 int yuvHeight,
144 int *pJpegSize,
145 void *pJpegData,
146 void *pYuvData);
147 bool YUY2toNV21(void *srcBuf, void *dstBuf, uint32_t srcWidth, uint32_t srcHeight);
148 bool scaleDownYuv422(char *srcBuf, uint32_t srcWidth,
149 uint32_t srcHight, char *dstBuf,
150 uint32_t dstWidth, uint32_t dstHight);
151
152 bool CheckVideoStartMarker(unsigned char *pBuf);
153 bool CheckEOIMarker(unsigned char *pBuf);
154 bool FindEOIMarkerInJPEG(unsigned char *pBuf,
155 int dwBufSize, int *pnJPEGsize);
156 bool SplitFrame(unsigned char *pFrame, int dwSize,
157 int dwJPEGLineLength, int dwVideoLineLength,
158 int dwVideoHeight, void *pJPEG,
159 int *pdwJPEGSize, void *pVideo,
160 int *pdwVideoSize);
161 void setSkipFrame(int frame);
162 bool isSupportedPreviewSize(const int width,
163 const int height) const;
164 bool getVideosnapshotSize(int *width, int *height);
165 /* used by auto focus thread to block until it's told to run */
166 mutable Mutex mFocusLock;
167 mutable Condition mFocusCondition;
168 bool mExitAutoFocusThread;
169 int mTouched;
170
171 /* used by preview thread to block until it's told to run */
172 mutable Mutex mPreviewLock;
173 mutable Condition mPreviewCondition;
174 mutable Condition mPreviewStoppedCondition;
175 bool mPreviewRunning;
176 bool mPreviewStartDeferred;
177 bool mExitPreviewThread;
178
179 preview_stream_ops *mPreviewWindow;
180
181 /* used to guard threading state */
182 mutable Mutex mStateLock;
183
184 enum PREVIEW_FMT {
185 PREVIEW_FMT_1_PLANE = 0,
186 PREVIEW_FMT_2_PLANE,
187 PREVIEW_FMT_3_PLANE,
188 };
189
190 int mPreviewFmtPlane;
191
192 CameraParameters mParameters;
193 CameraParameters mInternalParameters;
194
195 int mFrameSizeDelta;
196 camera_memory_t *mPreviewHeap;
197 camera_memory_t *mRawHeap;
198 sp<MemoryHeapBase> mPostviewHeap[CAP_BUFFERS];
199 sp<MemoryHeapBase> mThumbnailHeap;
200 camera_memory_t *mRecordHeap[BUFFER_COUNT_FOR_ARRAY];
201
202 camera_frame_metadata_t *mFaceData;
203 camera_memory_t *mFaceDataHeap;
204
205 buffer_handle_t *mBufferHandle[BUFFER_COUNT_FOR_ARRAY];
206 int mStride[BUFFER_COUNT_FOR_ARRAY];
207
208
209 SecCamera *mSecCamera;
210 const __u8 *mCameraSensorName;
211 bool mUseInternalISP;
212
213 mutable Mutex mSkipFrameLock;
214 int mSkipFrame;
215
216 camera_notify_callback mNotifyCb;
217 camera_data_callback mDataCb;
218 camera_data_timestamp_callback mDataCbTimestamp;
219 camera_request_memory mGetMemoryCb;
220 void *mCallbackCookie;
221
222 int32_t mMsgEnabled;
223
224 bool mRecordRunning;
225 bool mRecordHint;
226 mutable Mutex mRecordLock;
227 int mPostViewWidth;
228 int mPostViewHeight;
229 int mPostViewSize;
230 struct SecBuffer mCapBuffer;
231 int mCapIndex;
232 int mCameraID;
233
234 Vector<Size> mSupportedPreviewSizes;
235
236 camera_device_t *mHalDevice;
237 static gralloc_module_t const* mGrallocHal;
238};
239
240}; // namespace android
241
242#endif