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