blob: 5e5c0c40b6f599d29bfb0bb9fe408ab9593de474 [file] [log] [blame]
Ari Hausman-Cohen73442152016-06-08 15:50:49 -07001/*
2 * Copyright 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#include "V4L2Camera.h"
18
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070019#include <fcntl.h>
20#include <sys/types.h>
21#include <sys/stat.h>
22
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070023#include <camera/CameraMetadata.h>
24#include <hardware/camera3.h>
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070025#include <nativehelper/ScopedFd.h>
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070026
27#include "Common.h"
28
29namespace v4l2_camera_hal {
30
31V4L2Camera::V4L2Camera(int id, std::string path)
32 : default_camera_hal::Camera(id), mDevicePath(std::move(path)) {
33 HAL_LOG_ENTER();
34}
35
36V4L2Camera::~V4L2Camera() {
37 HAL_LOG_ENTER();
38}
39
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070040int V4L2Camera::connect() {
41 HAL_LOG_ENTER();
42
43 if (mDeviceFd.get() >= 0) {
44 HAL_LOGE("Camera device %s is opened. Close it first", mDevicePath.c_str());
45 return -EIO;
46 }
47
48 int fd = TEMP_FAILURE_RETRY(open(mDevicePath.c_str(), O_RDWR));
49 if (fd < 0) {
50 HAL_LOGE("failed to open %s (%s)", mDevicePath.c_str(), strerror(errno));
51 return -errno;
52 }
53 mDeviceFd.reset(fd);
54
55 // TODO(b/29185945): confirm this is a supported device.
56 // This is checked by the HAL, but the device at mDevicePath may
57 // not be the same one that was there when the HAL was loaded.
58 // (Alternatively, better hotplugging support may make this unecessary
59 // by disabling cameras that get disconnected and checking newly connected
60 // cameras, so connect() is never called on an unsupported camera)
61 return 0;
62}
63
64void V4L2Camera::disconnect() {
65 HAL_LOG_ENTER();
66 mDeviceFd.reset();
67}
68
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070069camera_metadata_t* V4L2Camera::initStaticInfo() {
70 HAL_LOG_ENTER();
71
72 android::CameraMetadata metadata(1);
73 // TODO(b/29214516): fill this in.
Ari Hausman-Cohen63f69822016-06-10 11:40:35 -070074 uint8_t scene_mode = ANDROID_CONTROL_SCENE_MODE_DISABLED;
75 metadata.update(ANDROID_CONTROL_AVAILABLE_SCENE_MODES, &scene_mode, 1);
76
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070077 return metadata.release();
78}
79
80void V4L2Camera::initDeviceInfo(camera_info_t* info) {
81 HAL_LOG_ENTER();
82
83 // For now, just constants.
84 info->facing = CAMERA_FACING_EXTERNAL;
85 info->orientation = 0;
86 info->resource_cost = 100;
87 info->conflicting_devices = nullptr;
88 info->conflicting_devices_length = 0;
89}
90
91int V4L2Camera::initDevice() {
92 HAL_LOG_ENTER();
93
94 // TODO(b/29221795): fill in templates, etc.
95 return 0;
96}
97
98bool V4L2Camera::isValidCaptureSettings(const camera_metadata_t* settings) {
99 HAL_LOG_ENTER();
100
101 // TODO(b): reject capture settings this camera isn't capable of.
102 return true;
103}
104
105} // namespace v4l2_camera_hal