QCamera3HWI.h revision 662d6f3c8101a94f45f3b0f892817e062a5c0faa
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 __QCAMERA2HARDWAREINTERFACE_H__
31#define __QCAMERA2HARDWAREINTERFACE_H__
32
33#include <pthread.h>
34#include <utils/List.h>
35#include <hardware/camera3.h>
36#include <camera/CameraMetadata.h>
37
38extern "C" {
39#include <mm_camera_interface.h>
40#include <mm_jpeg_interface.h>
41}
42
43using namespace android;
44
45namespace qcamera {
46
47#ifndef TRUE
48#define TRUE 1
49#endif
50
51#ifndef FALSE
52#define FALSE 0
53#endif
54
55class QCamera3MetadataChannel;
56class QCamera3HeapMemory;
57
58class QCamera3HardwareInterface {
59public:
60    /* static variable and functions accessed by camera service */
61    static camera3_device_ops_t mCameraOps;
62    static int initialize(const struct camera3_device *,
63                const camera3_callback_ops_t *callback_ops);
64    static int configure_streams(const struct camera3_device *,
65                camera3_stream_configuration_t *stream_list);
66    static int register_stream_buffers(const struct camera3_device *,
67                const camera3_stream_buffer_set_t *buffer_set);
68    static const camera_metadata_t* construct_default_request_settings(
69                                const struct camera3_device *, int type);
70    static int process_capture_request(const struct camera3_device *,
71                                camera3_capture_request_t *request);
72    static void get_metadata_vendor_tag_ops(const struct camera3_device *,
73                                               vendor_tag_query_ops_t* ops);
74    static void dump(const struct camera3_device *, int fd);
75    static int close_camera_device(struct hw_device_t* device);
76public:
77    QCamera3HardwareInterface(int cameraId);
78    virtual ~QCamera3HardwareInterface();
79    int openCamera(struct hw_device_t **hw_device);
80    int getMetadata(int type);
81    camera_metadata_t* translateToMetadata(int type);
82    int metadataToParam(CameraMetadata &metadata);
83
84    static int getCamInfo(int cameraId, struct camera_info *info);
85    static int initCapabilities(int cameraId);
86    static int initStaticMetadata(int cameraId);
87    static void makeTable(cam_dimension_t* dimTable, uint8_t size, int32_t* sizeTable);
88    static int32_t getScalarFormat(int32_t format);
89
90    static void captureResultCb(metadata_buffer_t *metadata,
91                camera3_stream_buffer_t *buffer, uint32_t frame_number,
92                void *userdata);
93
94    void sendCaptureResult(const struct camera3_callback_ops *,
95                        const camera3_capture_result_t *result);
96    void notify(const struct camera3_callback_ops *,
97                        const camera3_notify_msg_t *msg);
98
99    int initialize(const camera3_callback_ops_t *callback_ops);
100    int configureStreams(camera3_stream_configuration_t *stream_list);
101    int registerStreamBuffers(const camera3_stream_buffer_set_t *buffer_set);
102    int processCaptureRequest(camera3_capture_request_t *request);
103    void getMetadataVendorTagOps(vendor_tag_query_ops_t* ops);
104    void dump(int fd);
105
106    int setFrameParameters(int frame_id, const camera_metadata_t *settings);
107    int translateMetadataToParameters(const camera_metadata_t *settings);
108    int getJpegSettings(const camera_metadata_t *settings);
109    int initParameters();
110
111    void captureResultCb(metadata_buffer_t *metadata,
112                camera3_stream_buffer_t *buffer, uint32_t frame_number);
113
114    typedef struct {
115        int fwk_name;
116        int hal_name;
117    } QCameraMap;
118
119private:
120
121    int openCamera();
122    int closeCamera();
123    int AddSetParmEntryToBatch(parm_buffer_t *p_table,
124                               cam_intf_parm_type_t paramType,
125                               uint32_t paramLength,
126                               void *paramValue);
127    static int lookupHalName(const QCameraMap arr[],
128                      int len, int fwk_name);
129    static int lookupFwkName(const QCameraMap arr[],
130                      int len, int hal_name);
131
132    int validateCaptureRequest(camera3_capture_request_t *request);
133
134public:
135
136private:
137    camera3_device_t   mCameraDevice;
138    uint8_t            mCameraId;
139    mm_camera_vtbl_t  *mCameraHandle;
140    bool               mCameraOpened;
141    camera_metadata_t *mDefaultMetadata[CAMERA3_TEMPLATE_COUNT];
142
143    const camera3_callback_ops_t *mCallbackOps;
144
145    camera3_stream_t *mInputStream;
146    QCamera3MetadataChannel *mMetadataChannel;
147
148    QCamera3HeapMemory *mParamHeap;
149    parm_buffer_t* mParameters;
150
151    //mutex and conditional variable for request
152    pthread_mutex_t mRequestLock;
153    pthread_cond_t mRequestCond;
154    int mPendingRequest;
155
156    //mutex for serialized access to camera3_device_ops_t functions
157    pthread_mutex_t mMutex;
158
159    //mutex to protect the critial section for processCaptureResult
160    pthread_mutex_t mCaptureResultLock;
161
162    typedef struct {
163        int32_t jpeg_orientation;
164        uint8_t jpeg_quality;
165        cam_dimension_t thumbnail_size;
166        int64_t gps_timestamp;
167        double gps_coordinates[3];
168        uint8_t gps_processing_method;
169        int32_t sensor_sensitivity;
170        float lens_focal_length;
171    } jpeg_settings_t;
172
173    jpeg_settings_t* mJpegSettings;
174    static const QCameraMap EFFECT_MODES_MAP[];
175    static const QCameraMap WHITE_BALANCE_MODES_MAP[];
176    static const QCameraMap SCENE_MODES_MAP[];
177    static const QCameraMap FOCUS_MODES_MAP[];
178    static const QCameraMap ANTIBANDING_MODES_MAP[];
179    static const QCameraMap AUTO_EXPOSURE_MAP[];
180    static const QCameraMap FLASH_MODES_MAP[];
181};
182
183}; // namespace qcamera
184
185#endif /* __QCAMERA2HARDWAREINTERFACE_H__ */
186