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 | |
| 19 | #ifndef V4L2_CAMERA_H |
| 20 | #define V4L2_CAMERA_H |
| 21 | |
| 22 | #include <string> |
| 23 | |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 24 | #include <nativehelper/ScopedFd.h> |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 25 | #include <system/camera_metadata.h> |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 26 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 27 | #include "Camera.h" |
| 28 | #include "Common.h" |
| 29 | |
| 30 | namespace v4l2_camera_hal { |
| 31 | // V4L2Camera is a specific V4L2-supported camera device. The Camera object |
| 32 | // contains all logic common between all cameras (e.g. front and back cameras), |
| 33 | // while a specific camera device (e.g. V4L2Camera) holds all specific |
| 34 | // metadata and logic about that device. |
| 35 | class V4L2Camera : public default_camera_hal::Camera { |
| 36 | public: |
| 37 | V4L2Camera(int id, const std::string path); |
| 38 | ~V4L2Camera(); |
| 39 | |
| 40 | private: |
| 41 | // default_camera_hal::Camera virtual methods. |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 42 | // Connect to the device: open dev nodes, etc. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 43 | int connect() override; |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 44 | // Disconnect from the device: close dev nodes, etc. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 45 | void disconnect() override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 46 | // Initialize static camera characteristics for individual device. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 47 | int initStaticInfo(camera_metadata_t** out) override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 48 | // Initialize device info: facing, orientation, resource cost, |
| 49 | // and conflicting devices (/conflicting devices length). |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 50 | void initDeviceInfo(camera_info_t* info) override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 51 | // Initialize whole device (templates/etc) when opened. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 52 | int initDevice() override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 53 | // Verify settings are valid for a capture with this device. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 54 | bool isValidCaptureSettings(const camera_metadata_t* settings) override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 55 | |
| 56 | // The camera device path. For example, /dev/video0. |
| 57 | const std::string mDevicePath; |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 58 | // The opened device fd. |
| 59 | ScopedFd mDeviceFd; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 60 | |
| 61 | DISALLOW_COPY_AND_ASSIGN(V4L2Camera); |
| 62 | }; |
| 63 | |
| 64 | } // namespace v4l2_camera_hal |
| 65 | |
| 66 | #endif // V4L2_CAMERA_H |