Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 1 | /* |
| 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 | // Loosely based on hardware/libhardware/modules/camera/ExampleCamera.h |
| 18 | |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 19 | #ifndef V4L2_CAMERA_HAL_V4L2_CAMERA_H_ |
| 20 | #define V4L2_CAMERA_HAL_V4L2_CAMERA_H_ |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 21 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 22 | #include <array> |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 23 | #include <string> |
| 24 | |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 25 | #include <camera/CameraMetadata.h> |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 26 | |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 27 | #include "camera.h" |
| 28 | #include "common.h" |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 29 | #include "metadata/metadata.h" |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 30 | #include "v4l2_wrapper.h" |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 31 | |
| 32 | namespace v4l2_camera_hal { |
| 33 | // V4L2Camera is a specific V4L2-supported camera device. The Camera object |
| 34 | // contains all logic common between all cameras (e.g. front and back cameras), |
| 35 | // while a specific camera device (e.g. V4L2Camera) holds all specific |
| 36 | // metadata and logic about that device. |
| 37 | class V4L2Camera : public default_camera_hal::Camera { |
Ari Hausman-Cohen | 9430ad9 | 2016-08-24 14:00:32 -0700 | [diff] [blame^] | 38 | public: |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame] | 39 | // Use this method to create V4L2Camera objects. Functionally equivalent |
| 40 | // to "new V4L2Camera", except that it may return nullptr in case of failure. |
| 41 | static V4L2Camera* NewV4L2Camera(int id, const std::string path); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 42 | ~V4L2Camera(); |
| 43 | |
Ari Hausman-Cohen | 9430ad9 | 2016-08-24 14:00:32 -0700 | [diff] [blame^] | 44 | private: |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame] | 45 | // Constructor private to allow failing on bad input. |
| 46 | // Use NewV4L2Camera instead. |
Ari Hausman-Cohen | 9430ad9 | 2016-08-24 14:00:32 -0700 | [diff] [blame^] | 47 | V4L2Camera(int id, |
| 48 | std::shared_ptr<V4L2Wrapper> v4l2_wrapper, |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 49 | std::unique_ptr<Metadata> metadata); |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame] | 50 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 51 | // default_camera_hal::Camera virtual methods. |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 52 | // Connect to the device: open dev nodes, etc. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 53 | int connect() override; |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 54 | // Disconnect from the device: close dev nodes, etc. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 55 | void disconnect() override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 56 | // Initialize static camera characteristics for individual device. |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 57 | int initStaticInfo(android::CameraMetadata* out) override; |
| 58 | // Initialize a template of the given type. |
| 59 | int initTemplate(int type, android::CameraMetadata* out) override; |
| 60 | // Initialize device info: resource cost and conflicting devices |
| 61 | // (/conflicting devices length). |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 62 | void initDeviceInfo(camera_info_t* info) override; |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 63 | // Extra initialization of device when opened. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 64 | int initDevice() override; |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 65 | // Verify stream configuration is device-compatible. |
| 66 | bool isSupportedStreamSet(default_camera_hal::Stream** streams, |
Ari Hausman-Cohen | 9430ad9 | 2016-08-24 14:00:32 -0700 | [diff] [blame^] | 67 | int count, |
| 68 | uint32_t mode) override; |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 69 | // Set up the device for a stream, and get the maximum number of |
| 70 | // buffers that stream can handle (max_buffers is an output parameter). |
| 71 | int setupStream(default_camera_hal::Stream* stream, |
| 72 | uint32_t* max_buffers) override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 73 | // Verify settings are valid for a capture with this device. |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 74 | bool isValidCaptureSettings(const android::CameraMetadata& settings) override; |
| 75 | // Set settings for a capture. |
Ari Hausman-Cohen | 9430ad9 | 2016-08-24 14:00:32 -0700 | [diff] [blame^] | 76 | int setSettings(const android::CameraMetadata& new_settings) override; |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 77 | // Enqueue a buffer to receive data from the camera. |
| 78 | int enqueueBuffer(const camera3_stream_buffer_t* camera_buffer) override; |
| 79 | // Get the shutter time and updated settings for the most recent frame. |
| 80 | // The metadata parameter is both an input and output; frame-specific |
| 81 | // result fields should be appended to what is passed in. |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 82 | int getResultSettings(android::CameraMetadata* metadata, uint64_t* timestamp); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 83 | |
Ari Hausman-Cohen | 660f8b8 | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 84 | // V4L2 helper. |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 85 | std::shared_ptr<V4L2Wrapper> device_; |
| 86 | std::unique_ptr<V4L2Wrapper::Connection> connection_; |
| 87 | std::unique_ptr<Metadata> metadata_; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 88 | |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 89 | int32_t max_input_streams_; |
| 90 | std::array<int, 3> max_output_streams_; // {raw, non-stalling, stalling}. |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 91 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 92 | DISALLOW_COPY_AND_ASSIGN(V4L2Camera); |
| 93 | }; |
| 94 | |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 95 | } // namespace v4l2_camera_hal |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 96 | |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 97 | #endif // V4L2_CAMERA_HAL_V4L2_CAMERA_H |