QCamera3HWI.h revision 0e03eb09035f20fd3e45ad4b6be5eb84303377de
1/* Copyright (c) 2012-2013, The Linux Foundataion. All rights reserved.
2*
3* Redistribution and use in source and binary forms, with or without
4* modification, are permitted provided that the following conditions are
5* met:
6*     * Redistributions of source code must retain the above copyright
7*       notice, this list of conditions and the following disclaimer.
8*     * Redistributions in binary form must reproduce the above
9*       copyright notice, this list of conditions and the following
10*       disclaimer in the documentation and/or other materials provided
11*       with the distribution.
12*     * Neither the name of The Linux Foundation nor the names of its
13*       contributors may be used to endorse or promote products derived
14*       from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*
28*/
29
30#ifndef __QCAMERA3HARDWAREINTERFACE_H__
31#define __QCAMERA3HARDWAREINTERFACE_H__
32
33#include <pthread.h>
34#include <utils/List.h>
35#include <hardware/camera3.h>
36#include <camera/CameraMetadata.h>
37#include "QCamera3HALHeader.h"
38#include "QCamera3Channel.h"
39
40extern "C" {
41#include <mm_camera_interface.h>
42#include <mm_jpeg_interface.h>
43}
44
45using namespace android;
46
47namespace qcamera {
48
49#ifndef TRUE
50#define TRUE 1
51#endif
52
53#ifndef FALSE
54#define FALSE 0
55#endif
56
57/* Time related macros */
58typedef int64_t nsecs_t;
59#define NSEC_PER_SEC 1000000000LL
60#define NSEC_PER_USEC 1000
61
62
63class QCamera3MetadataChannel;
64class QCamera3PicChannel;
65class QCamera3HeapMemory;
66class QCamera3Exif;
67
68class QCamera3HardwareInterface {
69public:
70    /* static variable and functions accessed by camera service */
71    static camera3_device_ops_t mCameraOps;
72    static int initialize(const struct camera3_device *,
73                const camera3_callback_ops_t *callback_ops);
74    static int configure_streams(const struct camera3_device *,
75                camera3_stream_configuration_t *stream_list);
76    static int register_stream_buffers(const struct camera3_device *,
77                const camera3_stream_buffer_set_t *buffer_set);
78    static const camera_metadata_t* construct_default_request_settings(
79                                const struct camera3_device *, int type);
80    static int process_capture_request(const struct camera3_device *,
81                                camera3_capture_request_t *request);
82    static void get_metadata_vendor_tag_ops(const struct camera3_device *,
83                                               vendor_tag_query_ops_t* ops);
84    static void dump(const struct camera3_device *, int fd);
85    static int close_camera_device(struct hw_device_t* device);
86public:
87    QCamera3HardwareInterface(int cameraId);
88    virtual ~QCamera3HardwareInterface();
89    int openCamera(struct hw_device_t **hw_device);
90    int getMetadata(int type);
91    camera_metadata_t* translateCapabilityToMetadata(int type);
92
93    static int getCamInfo(int cameraId, struct camera_info *info);
94    static int initCapabilities(int cameraId);
95    static int initStaticMetadata(int cameraId);
96    static void makeTable(cam_dimension_t* dimTable, uint8_t size, int32_t* sizeTable);
97    static void makeFPSTable(cam_fps_range_t* fpsTable, uint8_t size,
98                                          float* fpsRangesTable);
99    static void convertRegions(cam_rect_t rect, int32_t* region, int weight);
100    static void convertLandmarks(cam_face_detection_info_t face, int32_t* landmarks);
101    static int32_t getScalarFormat(int32_t format);
102
103    static void captureResultCb(metadata_buffer_t *metadata,
104                camera3_stream_buffer_t *buffer, uint32_t frame_number,
105                void *userdata);
106
107    int initialize(const camera3_callback_ops_t *callback_ops);
108    int configureStreams(camera3_stream_configuration_t *stream_list);
109    int registerStreamBuffers(const camera3_stream_buffer_set_t *buffer_set);
110    int processCaptureRequest(camera3_capture_request_t *request);
111    void getMetadataVendorTagOps(vendor_tag_query_ops_t* ops);
112    void dump(int fd);
113
114    int setFrameParameters(int frame_id, const camera_metadata_t *settings);
115    int translateMetadataToParameters(const camera_metadata_t *settings);
116    camera_metadata_t* translateCbMetadataToResultMetadata(metadata_buffer_t *metadata,
117                            nsecs_t timestamp);
118    int getJpegSettings(const camera_metadata_t *settings);
119    int initParameters();
120    void deinitParameters();
121
122    void captureResultCb(metadata_buffer_t *metadata,
123                camera3_stream_buffer_t *buffer, uint32_t frame_number);
124
125    typedef struct {
126        uint8_t fwk_name;
127        uint8_t hal_name;
128    } QCameraMap;
129
130private:
131
132    int openCamera();
133    int closeCamera();
134    int AddSetParmEntryToBatch(parm_buffer_t *p_table,
135                               cam_intf_parm_type_t paramType,
136                               uint32_t paramLength,
137                               void *paramValue);
138    static int8_t lookupHalName(const QCameraMap arr[],
139                      int len, int fwk_name);
140    static int8_t lookupFwkName(const QCameraMap arr[],
141                      int len, int hal_name);
142
143    int validateCaptureRequest(camera3_capture_request_t *request);
144
145public:
146
147    bool needOnlineRotation();
148    void getThumbnailSize(cam_dimension_t &dim);
149    int getJpegQuality();
150    int getJpegRotation();
151    QCamera3Exif *getExifData();
152
153private:
154    camera3_device_t   mCameraDevice;
155    uint8_t            mCameraId;
156    mm_camera_vtbl_t  *mCameraHandle;
157    bool               mCameraOpened;
158    camera_metadata_t *mDefaultMetadata[CAMERA3_TEMPLATE_COUNT];
159
160    const camera3_callback_ops_t *mCallbackOps;
161
162    camera3_stream_t *mInputStream;
163    QCamera3MetadataChannel *mMetadataChannel;
164
165     //First request yet to be processed after configureStreams
166    bool mFirstRequest;
167    QCamera3HeapMemory *mParamHeap;
168    parm_buffer_t* mParameters;
169
170    //mutex and conditional variable for request
171    pthread_mutex_t mRequestLock;
172    pthread_cond_t mRequestCond;
173    int mPendingRequest;
174
175    //mutex for serialized access to camera3_device_ops_t functions
176    pthread_mutex_t mMutex;
177
178    //mutex to protect the critial section for processCaptureResult
179    pthread_mutex_t mCaptureResultLock;
180
181    jpeg_settings_t* mJpegSettings;
182    Vector<stream_info_t*> mStreamInfo;
183    static const QCameraMap EFFECT_MODES_MAP[];
184    static const QCameraMap WHITE_BALANCE_MODES_MAP[];
185    static const QCameraMap SCENE_MODES_MAP[];
186    static const QCameraMap FOCUS_MODES_MAP[];
187    static const QCameraMap ANTIBANDING_MODES_MAP[];
188    static const QCameraMap AUTO_EXPOSURE_MAP[];
189    static const QCameraMap FLASH_MODES_MAP[];
190};
191
192}; // namespace qcamera
193
194#endif /* __QCAMERA2HARDWAREINTERFACE_H__ */
195