QCamera3HWI.h revision e6ab32d89cf169705236988f0f74309f914c88b7
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* translateMetadata(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
88    static void captureResultCb(metadata_buffer_t *metadata,
89                camera3_stream_buffer_t *buffer, uint32_t frame_number,
90                void *userdata);
91
92    void sendCaptureResult(const struct camera3_callback_ops *,
93                        const camera3_capture_result_t *result);
94    void notify(const struct camera3_callback_ops *,
95                        const camera3_notify_msg_t *msg);
96
97    int initialize(const camera3_callback_ops_t *callback_ops);
98    int configureStreams(camera3_stream_configuration_t *stream_list);
99    int registerStreamBuffers(const camera3_stream_buffer_set_t *buffer_set);
100    int processCaptureRequest(camera3_capture_request_t *request);
101    void getMetadataVendorTagOps(vendor_tag_query_ops_t* ops);
102    void dump(int fd);
103
104    int setFrameParameters(const camera_metadata_t *settings);
105    int translateMetadataToParameters(const camera_metadata_t *settings);
106
107    void captureResultCb(metadata_buffer_t *metadata,
108                camera3_stream_buffer_t *buffer, uint32_t frame_number);
109
110private:
111
112    int openCamera();
113    int closeCamera();
114
115    int validateCaptureRequest(camera3_capture_request_t *request);
116
117public:
118
119private:
120    camera3_device_t   mCameraDevice;
121    uint8_t            mCameraId;
122    mm_camera_vtbl_t  *mCameraHandle;
123    bool               mCameraOpened;
124    camera_metadata_t *mDefaultMetadata[CAMERA3_TEMPLATE_COUNT];
125
126    const camera3_callback_ops_t *mCallbackOps;
127
128    camera3_stream_t *mInputStream;
129    QCamera3MetadataChannel *mMetadataChannel;
130
131    QCamera3HeapMemory *mParamHeap;
132    parm_buffer_t* mParameters;
133
134    //mutex and conditional variable for request
135    pthread_mutex_t mRequestLock;
136    pthread_cond_t mRequestCond;
137    int mPendingRequest;
138
139    //mutex for serialized access to camera3_device_ops_t functions
140    pthread_mutex_t mMutex;
141
142    //mutex to protect the critial section for processCaptureResult
143    pthread_mutex_t mCaptureResultLock;
144};
145
146}; // namespace qcamera
147
148#endif /* __QCAMERA2HARDWAREINTERFACE_H__ */
149