blob: ab8f221b4028d38c05b9ed8ef9ebfa875e23799f [file] [log] [blame]
Ari Hausman-Cohen73442152016-06-08 15:50:49 -07001/*
2 * Copyright (C) 2016 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// Modified from hardware/libhardware/modules/camera/Camera.h
18
19#ifndef CAMERA_H_
20#define CAMERA_H_
21
22#include <hardware/hardware.h>
23#include <hardware/camera3.h>
24#include <utils/Mutex.h>
25#include "Stream.h"
26
27namespace default_camera_hal {
28// Camera represents a physical camera on a device.
29// This is constructed when the HAL module is loaded, one per physical camera.
30// TODO(b/29185945): Support hotplugging.
31// It is opened by the framework, and must be closed before it can be opened
32// again.
33// This is an abstract class, containing all logic and data shared between all
34// camera devices (front, back, etc) and common to the ISP.
35class Camera {
36 public:
37 // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS.
38 // module is a handle to the HAL module, used when the device is opened.
39 Camera(int id);
40 virtual ~Camera();
41
42 // Common Camera Device Operations (see <hardware/camera_common.h>)
43 int open(const hw_module_t *module, hw_device_t **device);
44 int getInfo(struct camera_info *info);
45 int close();
46
47 // Camera v3 Device Operations (see <hardware/camera3.h>)
48 int initialize(const camera3_callback_ops_t *callback_ops);
49 int configureStreams(camera3_stream_configuration_t *stream_list);
50 int registerStreamBuffers(const camera3_stream_buffer_set_t *buf_set);
51 const camera_metadata_t *constructDefaultRequestSettings(int type);
52 int processCaptureRequest(camera3_capture_request_t *request);
53 void dump(int fd);
54
55
56 protected:
57 // Initialize static camera characteristics for individual device
58 virtual camera_metadata_t *initStaticInfo() = 0;
59 // Initialize device info: facing, orientation, resource cost,
60 // and conflicting devices (/conflicting devices length)
61 virtual void initDeviceInfo(struct camera_info *info) = 0;
62 // Verify settings are valid for a capture
63 virtual bool isValidCaptureSettings(const camera_metadata_t *) = 0;
64 // Separate initialization method for individual devices when opened
65 virtual int initDevice() = 0;
66 // Accessor used by initDevice() to set the templates' metadata
67 int setTemplate(int type, camera_metadata_t *static_info);
68 // Prettyprint template names
69 const char* templateToString(int type);
70
71 private:
72 // Camera device handle returned to framework for use
73 camera3_device_t mDevice;
74 // Reuse a stream already created by this device
75 Stream *reuseStream(camera3_stream_t *astream);
76 // Destroy all streams in a stream array, and the array itself
77 void destroyStreams(Stream **array, int count);
78 // Verify a set of streams is valid in aggregate
79 bool isValidStreamSet(Stream **array, int count);
80 // Calculate usage and max_bufs of each stream
81 void setupStreams(Stream **array, int count);
82 // Copy new settings for re-use and clean up old settings.
83 void setSettings(const camera_metadata_t *new_settings);
84 // Verify settings are valid for reprocessing an input buffer
85 bool isValidReprocessSettings(const camera_metadata_t *settings);
86 // Process an output buffer
87 int processCaptureBuffer(const camera3_stream_buffer_t *in,
88 camera3_stream_buffer_t *out);
89 // Send a shutter notify message with start of exposure time
90 void notifyShutter(uint32_t frame_number, uint64_t timestamp);
91 // Is type a valid template type (and valid index into mTemplates)
92 bool isValidTemplateType(int type);
93
94 // Identifier used by framework to distinguish cameras
95 const int mId;
96 // camera_metadata structure containing static characteristics
97 camera_metadata_t *mStaticInfo;
98 // Busy flag indicates camera is in use
99 bool mBusy;
100 // Camera device operations handle shared by all devices
101 const static camera3_device_ops_t sOps;
102 // Methods used to call back into the framework
103 const camera3_callback_ops_t *mCallbackOps;
104 // Lock protecting the Camera object for modifications
105 android::Mutex mDeviceLock;
106 // Lock protecting only static camera characteristics, which may
107 // be accessed without the camera device open
108 android::Mutex mStaticInfoLock;
109 // Array of handles to streams currently in use by the device
110 Stream **mStreams;
111 // Number of streams in mStreams
112 int mNumStreams;
113 // Static array of standard camera settings templates
114 camera_metadata_t *mTemplates[CAMERA3_TEMPLATE_COUNT];
115 // Most recent request settings seen, memoized to be reused
116 camera_metadata_t *mSettings;
117};
118} // namespace default_camera_hal
119
120#endif // CAMERA_H_