summaryrefslogtreecommitdiff
path: root/v3/EmulatedCamera3.h (plain)
blob: 1cf5f3318271f9875ed4d3c23b9af23e4552a13b
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef HW_EMULATOR_CAMERA_EMULATED_CAMERA3_H
18#define HW_EMULATOR_CAMERA_EMULATED_CAMERA3_H
19
20/**
21 * Contains declaration of a class EmulatedCamera that encapsulates
22 * functionality common to all version 3.0 emulated camera devices. Instances
23 * of this class (for each emulated camera) are created during the construction
24 * of the EmulatedCameraFactory instance. This class serves as an entry point
25 * for all camera API calls that defined by camera3_device_ops_t API.
26 */
27
28#include "hardware/camera3.h"
29#include "system/camera_metadata.h"
30#include "EmulatedBaseCamera.h"
31#include "DebugUtils.h"
32
33namespace android {
34
35/**
36 * Encapsulates functionality common to all version 3.0 emulated camera devices
37 *
38 * Note that EmulatedCameraFactory instantiates an object of this class just
39 * once, when EmulatedCameraFactory instance gets constructed. Connection to /
40 * disconnection from the actual camera device is handled by calls to
41 * connectDevice(), and closeCamera() methods of this class that are invoked in
42 * response to hw_module_methods_t::open, and camera_device::close callbacks.
43 */
44class EmulatedCamera3 : public camera3_device, public EmulatedBaseCamera {
45public:
46 /* Constructs EmulatedCamera3 instance.
47 * Param:
48 * cameraId - Zero based camera identifier, which is an index of the camera
49 * instance in camera factory's array.
50 * module - Emulated camera HAL module descriptor.
51 */
52 EmulatedCamera3(int cameraId,
53 struct hw_module_t* module);
54
55 /* Destructs EmulatedCamera2 instance. */
56 virtual ~EmulatedCamera3();
57
58 /****************************************************************************
59 * Abstract API
60 ***************************************************************************/
61
62public:
63
64 /****************************************************************************
65 * Public API
66 ***************************************************************************/
67
68public:
69 virtual status_t Initialize();
70
71 /****************************************************************************
72 * Camera module API and generic hardware device API implementation
73 ***************************************************************************/
74
75public:
76 virtual status_t connectCamera(hw_device_t** device);
77
78 virtual status_t closeCamera();
79
80 virtual status_t getCameraInfo(struct camera_info* info);
81
82 /****************************************************************************
83 * Camera API implementation.
84 * These methods are called from the camera API callback routines.
85 ***************************************************************************/
86
87protected:
88
89 virtual status_t initializeDevice(
90 const camera3_callback_ops *callbackOps);
91
92 virtual status_t configureStreams(
93 camera3_stream_configuration *streamList);
94
95 virtual status_t registerStreamBuffers(
96 const camera3_stream_buffer_set *bufferSet) ;
97
98 virtual const camera_metadata_t* constructDefaultRequestSettings(
99 int type);
100
101 virtual status_t processCaptureRequest(camera3_capture_request *request);
102
103 /** Debug methods */
104
105 virtual void dump(int fd);
106
107 virtual int flush_all_requests();
108 /** Tag query methods */
109 virtual const char *getVendorSectionName(uint32_t tag);
110
111 virtual const char *getVendorTagName(uint32_t tag);
112
113 virtual int getVendorTagType(uint32_t tag);
114
115 /****************************************************************************
116 * Camera API callbacks as defined by camera3_device_ops structure. See
117 * hardware/libhardware/include/hardware/camera3.h for information on each
118 * of these callbacks. Implemented in this class, these callbacks simply
119 * dispatch the call into an instance of EmulatedCamera3 class defined in
120 * the 'camera_device3' parameter.
121 ***************************************************************************/
122
123private:
124
125 /** Startup */
126 static int initialize(const struct camera3_device *,
127 const camera3_callback_ops_t *callback_ops);
128
129 /** Stream configuration and buffer registration */
130
131 static int configure_streams(const struct camera3_device *,
132 camera3_stream_configuration_t *stream_list);
133
134 static int register_stream_buffers(const struct camera3_device *,
135 const camera3_stream_buffer_set_t *buffer_set);
136
137 /** Template request settings provision */
138
139 static const camera_metadata_t* construct_default_request_settings(
140 const struct camera3_device *, int type);
141
142 /** Submission of capture requests to HAL */
143
144 static int process_capture_request(const struct camera3_device *,
145 camera3_capture_request_t *request);
146
147 /** Vendor metadata registration */
148 static void get_metadata_vendor_tag_ops(const camera3_device_t *,
149 vendor_tag_query_ops_t *ops);
150 // for get_metadata_vendor_tag_ops
151 static const char* get_camera_vendor_section_name(
152 const vendor_tag_query_ops_t *,
153 uint32_t tag);
154 static const char* get_camera_vendor_tag_name(
155 const vendor_tag_query_ops_t *,
156 uint32_t tag);
157 static int get_camera_vendor_tag_type(
158 const vendor_tag_query_ops_t *,
159 uint32_t tag);
160
161 static void dump(const camera3_device_t *, int fd);
162 static int flush(const struct camera3_device *d);
163
164 /** For hw_device_t ops */
165 static int close(struct hw_device_t* device);
166
167 /****************************************************************************
168 * Data members shared with implementations
169 ***************************************************************************/
170 protected:
171
172 struct TagOps : public vendor_tag_query_ops {
173 EmulatedCamera3 *parent;
174 };
175 TagOps mVendorTagOps;
176
177 enum {
178 // State at construction time, and after a device operation error
179 STATUS_ERROR = 0,
180 // State after startup-time init and after device instance close
181 STATUS_CLOSED,
182 // State after being opened, before device instance init
183 STATUS_OPEN,
184 // State after device instance initialization
185 STATUS_READY,
186 // State while actively capturing data
187 STATUS_ACTIVE
188 } mStatus;
189
190 bool mPlugged;
191 /**
192 * Callbacks back to the framework
193 */
194
195 void sendCaptureResult(camera3_capture_result_t *result);
196 void sendNotify(camera3_notify_msg_t *msg);
197
198 /****************************************************************************
199 * Data members
200 ***************************************************************************/
201 private:
202 static camera3_device_ops_t sDeviceOps;
203 const camera3_callback_ops_t *mCallbackOps;
204};
205
206}; /* namespace android */
207
208#endif /* HW_EMULATOR_CAMERA_EMULATED_CAMERA3_H */
209