blob: 072de358d080d4a7440959e162cc62ba2ca4af60 [file] [log] [blame]
Alex Ray7ee0b7a2012-11-06 00:12:49 -08001/*
2 * Copyright (C) 2012 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#ifndef CAMERA_H_
18#define CAMERA_H_
19
Alex Raya0ed4be2013-02-25 15:02:16 -080020#include <hardware/hardware.h>
21#include <hardware/camera3.h>
Alex Ray55567642013-11-12 12:58:39 -080022#include <utils/Mutex.h>
Alex Rayb0be1032013-05-28 15:52:47 -070023#include "Metadata.h"
Alex Raybcaf7882013-02-28 16:04:35 -080024#include "Stream.h"
Alex Ray7ee0b7a2012-11-06 00:12:49 -080025
26namespace default_camera_hal {
27// Camera represents a physical camera on a device.
28// This is constructed when the HAL module is loaded, one per physical camera.
29// It is opened by the framework, and must be closed before it can be opened
30// again.
Alex Ray61f7a0c2013-07-03 17:54:19 -070031// This is an abstract class, containing all logic and data shared between all
32// camera devices (front, back, etc) and common to the ISP.
Alex Ray7ee0b7a2012-11-06 00:12:49 -080033class Camera {
34 public:
35 // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS.
36 // module is a handle to the HAL module, used when the device is opened.
Chih-Hung Hsieh928e6792016-06-30 14:17:31 -070037 explicit Camera(int id);
Alex Ray61f7a0c2013-07-03 17:54:19 -070038 virtual ~Camera();
Alex Raya48dd3f2012-12-19 12:21:38 -080039
40 // Common Camera Device Operations (see <hardware/camera_common.h>)
Alex Raya0ed4be2013-02-25 15:02:16 -080041 int open(const hw_module_t *module, hw_device_t **device);
Alex Rayb0be1032013-05-28 15:52:47 -070042 int getInfo(struct camera_info *info);
Alex Raya48dd3f2012-12-19 12:21:38 -080043 int close();
Alex Raya0ed4be2013-02-25 15:02:16 -080044
45 // Camera v3 Device Operations (see <hardware/camera3.h>)
46 int initialize(const camera3_callback_ops_t *callback_ops);
47 int configureStreams(camera3_stream_configuration_t *stream_list);
48 int registerStreamBuffers(const camera3_stream_buffer_set_t *buf_set);
49 const camera_metadata_t *constructDefaultRequestSettings(int type);
50 int processCaptureRequest(camera3_capture_request_t *request);
Alex Raya0ed4be2013-02-25 15:02:16 -080051 void dump(int fd);
52
Alex Ray61f7a0c2013-07-03 17:54:19 -070053
54 protected:
55 // Initialize static camera characteristics for individual device
56 virtual camera_metadata_t *initStaticInfo() = 0;
57 // Verify settings are valid for a capture
58 virtual bool isValidCaptureSettings(const camera_metadata_t *) = 0;
59 // Separate initialization method for individual devices when opened
60 virtual int initDevice() = 0;
Alex Ray62735082013-10-21 12:55:24 -070061 // Accessor used by initDevice() to set the templates' metadata
62 int setTemplate(int type, camera_metadata_t *static_info);
63 // Prettyprint template names
64 const char* templateToString(int type);
Alex Raya48dd3f2012-12-19 12:21:38 -080065
Alex Ray7ee0b7a2012-11-06 00:12:49 -080066 private:
Alex Ray61f7a0c2013-07-03 17:54:19 -070067 // Camera device handle returned to framework for use
68 camera3_device_t mDevice;
Alex Raybcaf7882013-02-28 16:04:35 -080069 // Reuse a stream already created by this device
70 Stream *reuseStream(camera3_stream_t *astream);
71 // Destroy all streams in a stream array, and the array itself
72 void destroyStreams(Stream **array, int count);
73 // Verify a set of streams is valid in aggregate
74 bool isValidStreamSet(Stream **array, int count);
75 // Calculate usage and max_bufs of each stream
76 void setupStreams(Stream **array, int count);
Alex Raybfcbd952013-03-20 13:20:02 -070077 // Copy new settings for re-use and clean up old settings.
78 void setSettings(const camera_metadata_t *new_settings);
Alex Ray11bbeef2013-04-26 14:47:08 -070079 // Verify settings are valid for reprocessing an input buffer
80 bool isValidReprocessSettings(const camera_metadata_t *settings);
Alex Ray083315c2013-04-26 19:32:29 -070081 // Process an output buffer
82 int processCaptureBuffer(const camera3_stream_buffer_t *in,
83 camera3_stream_buffer_t *out);
Alex Ray764e4422013-06-04 12:38:07 -070084 // Send a shutter notify message with start of exposure time
85 void notifyShutter(uint32_t frame_number, uint64_t timestamp);
Alex Ray61f7a0c2013-07-03 17:54:19 -070086 // Is type a valid template type (and valid index into mTemplates)
87 bool isValidTemplateType(int type);
Alex Raybcaf7882013-02-28 16:04:35 -080088
Alex Ray7ee0b7a2012-11-06 00:12:49 -080089 // Identifier used by framework to distinguish cameras
Alex Ray1f8af672013-02-28 15:40:08 -080090 const int mId;
Alex Rayb0be1032013-05-28 15:52:47 -070091 // Metadata containing persistent camera characteristics
92 Metadata mMetadata;
93 // camera_metadata structure containing static characteristics
94 camera_metadata_t *mStaticInfo;
Alex Raya0ed4be2013-02-25 15:02:16 -080095 // Busy flag indicates camera is in use
Alex Ray7ee0b7a2012-11-06 00:12:49 -080096 bool mBusy;
Alex Raya0ed4be2013-02-25 15:02:16 -080097 // Camera device operations handle shared by all devices
98 const static camera3_device_ops_t sOps;
99 // Methods used to call back into the framework
100 const camera3_callback_ops_t *mCallbackOps;
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800101 // Lock protecting the Camera object for modifications
Alex Ray55567642013-11-12 12:58:39 -0800102 android::Mutex mDeviceLock;
Alex Ray0f82f5a2013-07-17 14:23:04 -0700103 // Lock protecting only static camera characteristics, which may
104 // be accessed without the camera device open
Alex Ray55567642013-11-12 12:58:39 -0800105 android::Mutex mStaticInfoLock;
Alex Raybcaf7882013-02-28 16:04:35 -0800106 // Array of handles to streams currently in use by the device
107 Stream **mStreams;
108 // Number of streams in mStreams
109 int mNumStreams;
Alex Ray89a82662013-05-28 20:32:48 -0700110 // Static array of standard camera settings templates
Alex Ray61f7a0c2013-07-03 17:54:19 -0700111 camera_metadata_t *mTemplates[CAMERA3_TEMPLATE_COUNT];
Alex Raybfcbd952013-03-20 13:20:02 -0700112 // Most recent request settings seen, memoized to be reused
113 camera_metadata_t *mSettings;
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800114};
115} // namespace default_camera_hal
116
117#endif // CAMERA_H_