blob: 4c869bb8c0c40446ea6dbcdfa8b900fbd4c25cdc [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
20#include <pthread.h>
Alex Raya0ed4be2013-02-25 15:02:16 -080021#include <hardware/hardware.h>
22#include <hardware/camera3.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.
Alex Raya0ed4be2013-02-25 15:02:16 -080037 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);
51 void getMetadataVendorTagOps(vendor_tag_query_ops_t *ops);
52 void dump(int fd);
53
Alex Ray61f7a0c2013-07-03 17:54:19 -070054
55 protected:
56 // Initialize static camera characteristics for individual device
57 virtual camera_metadata_t *initStaticInfo() = 0;
58 // Verify settings are valid for a capture
59 virtual bool isValidCaptureSettings(const camera_metadata_t *) = 0;
60 // Separate initialization method for individual devices when opened
61 virtual int initDevice() = 0;
Alex Ray62735082013-10-21 12:55:24 -070062 // Accessor used by initDevice() to set the templates' metadata
63 int setTemplate(int type, camera_metadata_t *static_info);
64 // Prettyprint template names
65 const char* templateToString(int type);
Alex Raya48dd3f2012-12-19 12:21:38 -080066
Alex Ray7ee0b7a2012-11-06 00:12:49 -080067 private:
Alex Ray61f7a0c2013-07-03 17:54:19 -070068 // Camera device handle returned to framework for use
69 camera3_device_t mDevice;
Alex Raybcaf7882013-02-28 16:04:35 -080070 // Reuse a stream already created by this device
71 Stream *reuseStream(camera3_stream_t *astream);
72 // Destroy all streams in a stream array, and the array itself
73 void destroyStreams(Stream **array, int count);
74 // Verify a set of streams is valid in aggregate
75 bool isValidStreamSet(Stream **array, int count);
76 // Calculate usage and max_bufs of each stream
77 void setupStreams(Stream **array, int count);
Alex Raybfcbd952013-03-20 13:20:02 -070078 // Copy new settings for re-use and clean up old settings.
79 void setSettings(const camera_metadata_t *new_settings);
Alex Ray11bbeef2013-04-26 14:47:08 -070080 // Verify settings are valid for reprocessing an input buffer
81 bool isValidReprocessSettings(const camera_metadata_t *settings);
Alex Ray083315c2013-04-26 19:32:29 -070082 // Process an output buffer
83 int processCaptureBuffer(const camera3_stream_buffer_t *in,
84 camera3_stream_buffer_t *out);
Alex Ray764e4422013-06-04 12:38:07 -070085 // Send a shutter notify message with start of exposure time
86 void notifyShutter(uint32_t frame_number, uint64_t timestamp);
Alex Ray61f7a0c2013-07-03 17:54:19 -070087 // Is type a valid template type (and valid index into mTemplates)
88 bool isValidTemplateType(int type);
Alex Raybcaf7882013-02-28 16:04:35 -080089
Alex Ray7ee0b7a2012-11-06 00:12:49 -080090 // Identifier used by framework to distinguish cameras
Alex Ray1f8af672013-02-28 15:40:08 -080091 const int mId;
Alex Rayb0be1032013-05-28 15:52:47 -070092 // Metadata containing persistent camera characteristics
93 Metadata mMetadata;
94 // camera_metadata structure containing static characteristics
95 camera_metadata_t *mStaticInfo;
Alex Raya0ed4be2013-02-25 15:02:16 -080096 // Busy flag indicates camera is in use
Alex Ray7ee0b7a2012-11-06 00:12:49 -080097 bool mBusy;
Alex Raya0ed4be2013-02-25 15:02:16 -080098 // Camera device operations handle shared by all devices
99 const static camera3_device_ops_t sOps;
100 // Methods used to call back into the framework
101 const camera3_callback_ops_t *mCallbackOps;
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800102 // Lock protecting the Camera object for modifications
103 pthread_mutex_t mMutex;
Alex Ray0f82f5a2013-07-17 14:23:04 -0700104 // Lock protecting only static camera characteristics, which may
105 // be accessed without the camera device open
106 pthread_mutex_t mStaticInfoMutex;
Alex Raybcaf7882013-02-28 16:04:35 -0800107 // Array of handles to streams currently in use by the device
108 Stream **mStreams;
109 // Number of streams in mStreams
110 int mNumStreams;
Alex Ray89a82662013-05-28 20:32:48 -0700111 // Static array of standard camera settings templates
Alex Ray61f7a0c2013-07-03 17:54:19 -0700112 camera_metadata_t *mTemplates[CAMERA3_TEMPLATE_COUNT];
Alex Raybfcbd952013-03-20 13:20:02 -0700113 // Most recent request settings seen, memoized to be reused
114 camera_metadata_t *mSettings;
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800115};
116} // namespace default_camera_hal
117
118#endif // CAMERA_H_