• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
31 namespace android {
32     class CameraHardwareSec : public virtual RefBase {
33 public:
34     virtual void        setCallbacks(camera_notify_callback notify_cb,
35                                      camera_data_callback data_cb,
36                                      camera_data_timestamp_callback data_cb_timestamp,
37                                      camera_request_memory get_memory,
38                                      void *user);
39 
40     virtual void        enableMsgType(int32_t msgType);
41     virtual void        disableMsgType(int32_t msgType);
42     virtual bool        msgTypeEnabled(int32_t msgType);
43 
44     virtual status_t    startPreview();
45     virtual void        stopPreview();
46     virtual bool        previewEnabled();
47 
48     virtual status_t    startRecording();
49     virtual void        stopRecording();
50     virtual bool        recordingEnabled();
51     virtual void        releaseRecordingFrame(const void *opaque);
52 
53     virtual status_t    autoFocus();
54     virtual status_t    cancelAutoFocus();
55     virtual status_t    takePicture();
56     virtual status_t    cancelPicture();
57     virtual status_t    dump(int fd) const;
58     virtual status_t    setParameters(const CameraParameters& params);
59     virtual CameraParameters  getParameters() const;
60     virtual status_t    sendCommand(int32_t command, int32_t arg1, int32_t arg2);
61     virtual status_t    setPreviewWindow(preview_stream_ops *w);
62     virtual status_t    storeMetaDataInBuffers(bool enable);
63     virtual void        release();
64 
65     inline  int         getCameraId() const;
66 
67     CameraHardwareSec(int cameraId, camera_device_t *dev);
68     virtual             ~CameraHardwareSec();
69 private:
70     status_t    startPreviewInternal();
71     void stopPreviewInternal();
72 
73     static  const int   kBufferCount = MAX_BUFFERS;
74     static  const int   kBufferCountForRecord = MAX_BUFFERS;
75 
76     class PreviewThread : public Thread {
77         CameraHardwareSec *mHardware;
78     public:
PreviewThread(CameraHardwareSec * hw)79         PreviewThread(CameraHardwareSec *hw):
80         Thread(false),
81         mHardware(hw) { }
onFirstRef()82         virtual void onFirstRef() {
83             run("CameraPreviewThread", PRIORITY_URGENT_DISPLAY);
84         }
threadLoop()85         virtual bool threadLoop() {
86             mHardware->previewThreadWrapper();
87             return false;
88         }
89     };
90 
91     class PictureThread : public Thread {
92         CameraHardwareSec *mHardware;
93     public:
PictureThread(CameraHardwareSec * hw)94         PictureThread(CameraHardwareSec *hw):
95         Thread(false),
96         mHardware(hw) { }
threadLoop()97         virtual bool threadLoop() {
98             mHardware->pictureThread();
99             return false;
100         }
101     };
102 
103     class AutoFocusThread : public Thread {
104         CameraHardwareSec *mHardware;
105     public:
AutoFocusThread(CameraHardwareSec * hw)106         AutoFocusThread(CameraHardwareSec *hw): Thread(false), mHardware(hw) { }
onFirstRef()107         virtual void onFirstRef() {
108             run("CameraAutoFocusThread", PRIORITY_DEFAULT);
109         }
threadLoop()110         virtual bool threadLoop() {
111             mHardware->autoFocusThread();
112             return true;
113         }
114     };
115 
116             void        initDefaultParameters(int cameraId);
117             void        initHeapLocked();
118 
119     sp<PreviewThread>   mPreviewThread;
120             int         previewThread();
121             int         previewThreadWrapper();
122 
123     sp<AutoFocusThread> mAutoFocusThread;
124             int         autoFocusThread();
125 
126     sp<PictureThread>   mPictureThread;
127             int         pictureThread();
128             bool        mCaptureInProgress;
129 
130             int         save_jpeg(unsigned char *real_jpeg, int jpeg_size);
131             void        save_postview(const char *fname, uint8_t *buf,
132                                         uint32_t size);
133             int         decodeInterleaveData(unsigned char *pInterleaveData,
134                                                 int interleaveDataSize,
135                                                 int yuvWidth,
136                                                 int yuvHeight,
137                                                 int *pJpegSize,
138                                                 void *pJpegData,
139                                                 void *pYuvData);
140             bool        YUY2toNV21(void *srcBuf, void *dstBuf, uint32_t srcWidth, uint32_t srcHeight);
141             bool        scaleDownYuv422(char *srcBuf, uint32_t srcWidth,
142                                         uint32_t srcHight, char *dstBuf,
143                                         uint32_t dstWidth, uint32_t dstHight);
144 
145             bool        CheckVideoStartMarker(unsigned char *pBuf);
146             bool        CheckEOIMarker(unsigned char *pBuf);
147             bool        FindEOIMarkerInJPEG(unsigned char *pBuf,
148                                             int dwBufSize, int *pnJPEGsize);
149             bool        SplitFrame(unsigned char *pFrame, int dwSize,
150                                    int dwJPEGLineLength, int dwVideoLineLength,
151                                    int dwVideoHeight, void *pJPEG,
152                                    int *pdwJPEGSize, void *pVideo,
153                                    int *pdwVideoSize);
154             void        setSkipFrame(int frame);
155             bool        isSupportedPreviewSize(const int width,
156                                                const int height) const;
157             bool        isSupportedParameter(const char * const parm,
158                             const char * const supported_parm) const;
159             status_t    waitCaptureCompletion();
160     /* used by auto focus thread to block until it's told to run */
161     mutable Mutex       mFocusLock;
162     mutable Condition   mFocusCondition;
163             bool        mExitAutoFocusThread;
164 
165     /* used by preview thread to block until it's told to run */
166     mutable Mutex       mPreviewLock;
167     mutable Condition   mPreviewCondition;
168     mutable Condition   mPreviewStoppedCondition;
169             bool        mPreviewRunning;
170             bool        mPreviewStartDeferred;
171             bool        mExitPreviewThread;
172 
173             preview_stream_ops *mPreviewWindow;
174 
175     /* used to guard mCaptureInProgress */
176     mutable Mutex       mCaptureLock;
177     mutable Condition   mCaptureCondition;
178 
179     CameraParameters    mParameters;
180     CameraParameters    mInternalParameters;
181 
182     camera_memory_t     *mPreviewHeap;
183     camera_memory_t     *mRawHeap;
184     camera_memory_t     *mRecordHeap;
185 
186     SecCamera           *mSecCamera;
187             const __u8  *mCameraSensorName;
188 
189     mutable Mutex       mSkipFrameLock;
190             int         mSkipFrame;
191 
192     camera_notify_callback     mNotifyCb;
193     camera_data_callback       mDataCb;
194     camera_data_timestamp_callback mDataCbTimestamp;
195     camera_request_memory      mGetMemoryCb;
196             void        *mCallbackCookie;
197 
198             int32_t     mMsgEnabled;
199 
200             bool        mRecordRunning;
201     mutable Mutex       mRecordLock;
202             int         mPostViewWidth;
203             int         mPostViewHeight;
204             int         mPostViewSize;
205 
206             Vector<Size> mSupportedPreviewSizes;
207 
208     camera_device_t *mHalDevice;
209     static gralloc_module_t const* mGrallocHal;
210 };
211 
212 }; // namespace android
213 
214 #endif
215