blob: 158c36d929381a6fa8ea42961e1552484f7b4b21 [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
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -070019#ifndef DEFAULT_CAMERA_HAL_CAMERA_H_
20#define DEFAULT_CAMERA_HAL_CAMERA_H_
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070021
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070022#include <camera/CameraMetadata.h>
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070023#include <hardware/hardware.h>
24#include <hardware/camera3.h>
25#include <utils/Mutex.h>
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070026
27#include "metadata/metadata.h"
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -070028#include "stream.h"
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070029
30namespace default_camera_hal {
31// Camera represents a physical camera on a device.
32// This is constructed when the HAL module is loaded, one per physical camera.
33// TODO(b/29185945): Support hotplugging.
34// It is opened by the framework, and must be closed before it can be opened
35// again.
36// This is an abstract class, containing all logic and data shared between all
37// camera devices (front, back, etc) and common to the ISP.
38class Camera {
39 public:
40 // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS.
41 // module is a handle to the HAL module, used when the device is opened.
42 Camera(int id);
43 virtual ~Camera();
44
45 // Common Camera Device Operations (see <hardware/camera_common.h>)
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070046 int openDevice(const hw_module_t *module, hw_device_t **device);
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070047 int getInfo(struct camera_info *info);
48 int close();
49
50 // Camera v3 Device Operations (see <hardware/camera3.h>)
51 int initialize(const camera3_callback_ops_t *callback_ops);
52 int configureStreams(camera3_stream_configuration_t *stream_list);
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070053 const camera_metadata_t *constructDefaultRequestSettings(int type);
54 int processCaptureRequest(camera3_capture_request_t *request);
55 void dump(int fd);
56
57
58 protected:
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070059 // Connect to the device: open dev nodes, etc.
60 virtual int connect() = 0;
61 // Disconnect from the device: close dev nodes, etc.
62 virtual void disconnect() = 0;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070063 // Initialize static camera characteristics for individual device
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070064 virtual int initStaticInfo(android::CameraMetadata* out) = 0;
65 // Initialize a template of the given type
66 virtual int initTemplate(int type, android::CameraMetadata* out) = 0;
67 // Initialize device info: resource cost and conflicting devices
68 // (/conflicting devices length)
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070069 virtual void initDeviceInfo(struct camera_info *info) = 0;
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -070070 // Verify stream configuration is device-compatible
71 virtual bool isSupportedStreamSet(Stream** streams, int count,
72 uint32_t mode) = 0;
73 // Set up the device for a stream, and get the maximum number of
74 // buffers that stream can handle (max_buffers is an output parameter)
75 virtual int setupStream(Stream* stream, uint32_t* max_buffers) = 0;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070076 // Verify settings are valid for a capture
Ari Hausman-Cohen24e541c2016-07-21 11:20:30 -070077 virtual bool isValidCaptureSettings(
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070078 const android::CameraMetadata& settings) = 0;
79 // Set settings for a capture
80 virtual int setSettings(
81 const android::CameraMetadata& new_settings) = 0;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070082 // Separate initialization method for individual devices when opened
83 virtual int initDevice() = 0;
Ari Hausman-Cohen24e541c2016-07-21 11:20:30 -070084 // Enqueue a buffer to receive data from the camera
85 virtual int enqueueBuffer(
86 const camera3_stream_buffer_t *camera_buffer) = 0;
87 // Get the shutter time and updated settings for the most recent frame.
88 // The metadata parameter is both an input and output; frame-specific
89 // result fields should be appended to what is passed in.
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070090 virtual int getResultSettings(android::CameraMetadata* metadata,
Ari Hausman-Cohen24e541c2016-07-21 11:20:30 -070091 uint64_t *timestamp) = 0;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070092 // Prettyprint template names
93 const char* templateToString(int type);
94
95 private:
96 // Camera device handle returned to framework for use
97 camera3_device_t mDevice;
98 // Reuse a stream already created by this device
99 Stream *reuseStream(camera3_stream_t *astream);
100 // Destroy all streams in a stream array, and the array itself
101 void destroyStreams(Stream **array, int count);
102 // Verify a set of streams is valid in aggregate
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -0700103 bool isValidStreamSet(Stream **array, int count, uint32_t mode);
Ari Hausman-Cohen73442152016-06-08 15:50:49 -0700104 // Calculate usage and max_bufs of each stream
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -0700105 int setupStreams(Stream **array, int count);
Ari Hausman-Cohen73442152016-06-08 15:50:49 -0700106 // Verify settings are valid for reprocessing an input buffer
107 bool isValidReprocessSettings(const camera_metadata_t *settings);
108 // Process an output buffer
109 int processCaptureBuffer(const camera3_stream_buffer_t *in,
110 camera3_stream_buffer_t *out);
111 // Send a shutter notify message with start of exposure time
112 void notifyShutter(uint32_t frame_number, uint64_t timestamp);
113 // Is type a valid template type (and valid index into mTemplates)
114 bool isValidTemplateType(int type);
115
116 // Identifier used by framework to distinguish cameras
117 const int mId;
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -0700118 // CameraMetadata containing static characteristics
119 std::unique_ptr<const android::CameraMetadata> mStaticInfo;
120 // Flag indicating if settings have been set since
121 // the last configure_streams() call.
122 bool mSettingsSet;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -0700123 // Busy flag indicates camera is in use
124 bool mBusy;
125 // Camera device operations handle shared by all devices
126 const static camera3_device_ops_t sOps;
127 // Methods used to call back into the framework
128 const camera3_callback_ops_t *mCallbackOps;
129 // Lock protecting the Camera object for modifications
130 android::Mutex mDeviceLock;
131 // Lock protecting only static camera characteristics, which may
132 // be accessed without the camera device open
133 android::Mutex mStaticInfoLock;
134 // Array of handles to streams currently in use by the device
135 Stream **mStreams;
136 // Number of streams in mStreams
137 int mNumStreams;
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -0700138 // Standard camera settings templates
139 std::unique_ptr<const android::CameraMetadata> mTemplates[CAMERA3_TEMPLATE_COUNT];
Ari Hausman-Cohen73442152016-06-08 15:50:49 -0700140};
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -0700141} // namespace default_camera_hal
Ari Hausman-Cohen73442152016-06-08 15:50:49 -0700142
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -0700143#endif // DEFAULT_CAMERA_HAL_CAMERA_H_