This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCameraHardware.h
361 lines (290 loc) · 13.2 KB
/
CameraHardware.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*
**
** Copyright 2008, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_H
#define ANDROID_HARDWARE_CAMERA_HARDWARE_H
#include <CameraParameters.h>
#include <hardware/camera.h>
#include <utils/threads.h>
#include <utils/threads.h>
#include "V4L2Camera.h"
using ::android::hardware::camera::common::V1_0::helper::CameraParameters;
using ::android::hardware::camera::common::V1_0::helper::Size;
namespace android {
class CameraHardware : public camera_device {
public:
/* Actual handler for camera_device_ops_t::set_preview_window callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t setPreviewWindow(struct preview_stream_ops *window);
/* Actual handler for camera_device_ops_t::set_callbacks callback.
* NOTE: When this method is called the object is locked.
*/
void setCallbacks(camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
void* user);
/* Actual handler for camera_device_ops_t::enable_msg_type callback.
* NOTE: When this method is called the object is locked.
*/
void enableMsgType(int32_t msg_type);
/* Actual handler for camera_device_ops_t::disable_msg_type callback.
* NOTE: When this method is called the object is locked.
*/
void disableMsgType(int32_t msg_type);
/* Actual handler for camera_device_ops_t::msg_type_enabled callback.
* NOTE: When this method is called the object is locked.
* Return:
* 0 if message(s) is (are) disabled, != 0 if enabled.
*/
int isMsgTypeEnabled(int32_t msg_type);
/* Actual handler for camera_device_ops_t::start_preview callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t startPreview();
/* Actual handler for camera_device_ops_t::stop_preview callback.
* NOTE: When this method is called the object is locked.
*/
void stopPreview();
/* Actual handler for camera_device_ops_t::preview_enabled callback.
* NOTE: When this method is called the object is locked.
* Return:
* 0 if preview is disabled, != 0 if enabled.
*/
int isPreviewEnabled();
/* Actual handler for camera_device_ops_t::store_meta_data_in_buffers callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t storeMetaDataInBuffers(int enable);
/* Actual handler for camera_device_ops_t::start_recording callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t startRecording();
/* Actual handler for camera_device_ops_t::stop_recording callback.
* NOTE: When this method is called the object is locked.
*/
void stopRecording();
/* Actual handler for camera_device_ops_t::recording_enabled callback.
* NOTE: When this method is called the object is locked.
* Return:
* 0 if recording is disabled, != 0 if enabled.
*/
int isRecordingEnabled();
/* Actual handler for camera_device_ops_t::release_recording_frame callback.
* NOTE: When this method is called the object is locked.
*/
void releaseRecordingFrame(const void* opaque);
/* Actual handler for camera_device_ops_t::auto_focus callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t setAutoFocus();
/* Actual handler for camera_device_ops_t::cancel_auto_focus callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t cancelAutoFocus();
/* Actual handler for camera_device_ops_t::take_picture callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t takePicture();
/* Actual handler for camera_device_ops_t::cancel_picture callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t cancelPicture();
/* Actual handler for camera_device_ops_t::set_parameters callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t setParameters(const char* parms);
/* Actual handler for camera_device_ops_t::get_parameters callback.
* NOTE: When this method is called the object is locked.
* Return:
* Flattened parameters string. The caller will free the buffer allocated
* for the string by calling camera_device_ops_t::put_parameters callback.
*/
char* getParameters();
/*
* Called to free the string returned from camera_device_ops_t::get_parameters
* callback. There is nothing more to it: the name of the callback is just
* misleading.
* NOTE: When this method is called the object is locked.
*/
void putParameters(char* params);
/* Actual handler for camera_device_ops_t::send_command callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
/* Actual handler for camera_device_ops_t::release callback.
* NOTE: When this method is called the object is locked.
*/
void releaseCamera();
status_t dumpCamera(int fd);
private:
bool PowerOn();
bool PowerOff();
bool NegotiatePreviewFormat(struct preview_stream_ops* win);
void ReleaseAllHeap();
void ResetRuntimeData();
public:
/* Constructs Camera instance.
* Param:
* cameraId - Zero based camera identifier, which is an index of the camera
* instance in camera factory's array.
* module - Emulated camera HAL module descriptor.
*/
CameraHardware(const hw_module_t* module, char* devLocation);
/* Destructs EmulatedCamera instance. */
virtual ~CameraHardware();
/****************************************************************************
* Camera API implementation
***************************************************************************/
public:
/* Creates connection to the emulated camera device.
* This method is called in response to hw_module_methods_t::open callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t connectCamera(hw_device_t** device);
/* Closes connection to the emulated camera.
* This method is called in response to camera_device::close callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
status_t closeCamera();
/* Gets camera information.
* This method is called in response to camera_module_t::get_camera_info
* callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
static status_t getCameraInfo(struct camera_info* info, int facing,
int orientation);
private:
static const int kBufferCount = 4;
void initDefaultParameters();
void initHeapLocked();
class PreviewThread : public Thread {
CameraHardware* mHardware;
public:
PreviewThread(CameraHardware* hw);
virtual void onFirstRef();
virtual bool threadLoop();
};
status_t startPreviewLocked();
void stopPreviewLocked();
int previewThread();
static int beginAutoFocusThread(void *cookie);
int autoFocusThread();
static int beginPictureThread(void *cookie);
int pictureThread();
void fillPreviewWindow(uint8_t* yuyv, int srcWidth, int srcHeight);
int getPreviewFrameRate(const CameraParameters& params);
mutable Mutex mLock;
preview_stream_ops* mWin;
int mPreviewWinFmt;
int mPreviewWinWidth;
int mPreviewWinHeight;
CameraParameters mParameters;
char* mVideoDevice;
camera_memory_t* mRawPreviewHeap;
int mRawPreviewFrameSize;
void* mRawPreviewBuffer;
int mRawPreviewWidth;
int mRawPreviewHeight;
camera_memory_t* mPreviewHeap;
int mPreviewFrameSize;
void* mPreviewBuffer[kBufferCount];
int mPreviewFmt;
camera_memory_t* mRawPictureHeap;
void* mRawBuffer;
int mRawPictureBufferSize;
camera_memory_t* mRecordingHeap;
void* mRecBuffers[kBufferCount];
int mRecordingFrameSize;
int mRecFmt;
camera_memory_t* mJpegPictureHeap;
int mJpegPictureBufferSize;
V4L2Camera camera;
bool mRecordingEnabled;
// protected by mLock
sp<PreviewThread> mPreviewThread;
camera_notify_callback mNotifyCb;
camera_data_callback mDataCb;
camera_data_timestamp_callback mDataCbTimestamp;
camera_request_memory mRequestMemory;
void *mCallbackCookie;
int32_t mMsgEnabled;
// only used from PreviewThread
int mCurrentPreviewFrame;
int mCurrentRecordingFrame;
char* mCameraPowerFile;
/****************************************************************************
* Camera API callbacks as defined by camera_device_ops structure.
* See hardware/libhardware/include/hardware/camera.h for information on
* each of these callbacks. Implemented in this class, these callbacks simply
* dispatch the call into an instance of EmulatedCamera class defined by the
* 'camera_device' parameter.
***************************************************************************/
private:
static int set_preview_window(struct camera_device* dev,
struct preview_stream_ops* window);
static void set_callbacks(struct camera_device* dev,
camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
void* user);
static void enable_msg_type(struct camera_device* dev, int32_t msg_type);
static void disable_msg_type(struct camera_device* dev, int32_t msg_type);
static int msg_type_enabled(struct camera_device* dev, int32_t msg_type);
static int start_preview(struct camera_device* dev);
static void stop_preview(struct camera_device* dev);
static int preview_enabled(struct camera_device* dev);
static int store_meta_data_in_buffers(struct camera_device* dev, int enable);
static int start_recording(struct camera_device* dev);
static void stop_recording(struct camera_device* dev);
static int recording_enabled(struct camera_device* dev);
static void release_recording_frame(struct camera_device* dev,
const void* opaque);
static int auto_focus(struct camera_device* dev);
static int cancel_auto_focus(struct camera_device* dev);
static int take_picture(struct camera_device* dev);
static int cancel_picture(struct camera_device* dev);
static int set_parameters(struct camera_device* dev, const char* parms);
static char* get_parameters(struct camera_device* dev);
static void put_parameters(struct camera_device* dev, char* params);
static int send_command(struct camera_device* dev,
int32_t cmd,
int32_t arg1,
int32_t arg2);
static void release(struct camera_device* dev);
static int dump(struct camera_device* dev, int fd);
static int close(struct hw_device_t* device);
private:
/* Registered callbacks implementing camera API. */
static camera_device_ops_t mDeviceOps;
};
}; // namespace android
#endif