blob: a61cee284771c730617cc23cc26ade4e6e2bf95e [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>)
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070043 int openDevice(const hw_module_t *module, hw_device_t **device);
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070044 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:
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070057 // Connect to the device: open dev nodes, etc.
58 virtual int connect() = 0;
59 // Disconnect from the device: close dev nodes, etc.
60 virtual void disconnect() = 0;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070061 // Initialize static camera characteristics for individual device
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070062 virtual int initStaticInfo(camera_metadata_t **out) = 0;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070063 // Initialize device info: facing, orientation, resource cost,
64 // and conflicting devices (/conflicting devices length)
65 virtual void initDeviceInfo(struct camera_info *info) = 0;
66 // Verify settings are valid for a capture
67 virtual bool isValidCaptureSettings(const camera_metadata_t *) = 0;
68 // Separate initialization method for individual devices when opened
69 virtual int initDevice() = 0;
70 // Accessor used by initDevice() to set the templates' metadata
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070071 int setTemplate(int type, const camera_metadata_t *static_info);
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070072 // Prettyprint template names
73 const char* templateToString(int type);
74
75 private:
76 // Camera device handle returned to framework for use
77 camera3_device_t mDevice;
78 // Reuse a stream already created by this device
79 Stream *reuseStream(camera3_stream_t *astream);
80 // Destroy all streams in a stream array, and the array itself
81 void destroyStreams(Stream **array, int count);
82 // Verify a set of streams is valid in aggregate
83 bool isValidStreamSet(Stream **array, int count);
84 // Calculate usage and max_bufs of each stream
85 void setupStreams(Stream **array, int count);
86 // Copy new settings for re-use and clean up old settings.
87 void setSettings(const camera_metadata_t *new_settings);
88 // Verify settings are valid for reprocessing an input buffer
89 bool isValidReprocessSettings(const camera_metadata_t *settings);
90 // Process an output buffer
91 int processCaptureBuffer(const camera3_stream_buffer_t *in,
92 camera3_stream_buffer_t *out);
93 // Send a shutter notify message with start of exposure time
94 void notifyShutter(uint32_t frame_number, uint64_t timestamp);
95 // Is type a valid template type (and valid index into mTemplates)
96 bool isValidTemplateType(int type);
97
98 // Identifier used by framework to distinguish cameras
99 const int mId;
100 // camera_metadata structure containing static characteristics
101 camera_metadata_t *mStaticInfo;
102 // Busy flag indicates camera is in use
103 bool mBusy;
104 // Camera device operations handle shared by all devices
105 const static camera3_device_ops_t sOps;
106 // Methods used to call back into the framework
107 const camera3_callback_ops_t *mCallbackOps;
108 // Lock protecting the Camera object for modifications
109 android::Mutex mDeviceLock;
110 // Lock protecting only static camera characteristics, which may
111 // be accessed without the camera device open
112 android::Mutex mStaticInfoLock;
113 // Array of handles to streams currently in use by the device
114 Stream **mStreams;
115 // Number of streams in mStreams
116 int mNumStreams;
117 // Static array of standard camera settings templates
118 camera_metadata_t *mTemplates[CAMERA3_TEMPLATE_COUNT];
119 // Most recent request settings seen, memoized to be reused
120 camera_metadata_t *mSettings;
121};
122} // namespace default_camera_hal
123
124#endif // CAMERA_H_