blob: ff7275a0b8b7d038dd3b267310adfb19631f056b [file] [log] [blame]
Ari Hausman-Cohen73442152016-06-08 15:50:49 -07001/*
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-Cohen345bd3a2016-06-13 15:33:53 -070024#include <nativehelper/ScopedFd.h>
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070025#include <system/camera_metadata.h>
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070026
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070027#include "Camera.h"
28#include "Common.h"
29
30namespace 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.
35class V4L2Camera : public default_camera_hal::Camera {
36public:
37 V4L2Camera(int id, const std::string path);
38 ~V4L2Camera();
39
40private:
41 // default_camera_hal::Camera virtual methods.
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070042 // Connect to the device: open dev nodes, etc.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070043 int connect() override;
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070044 // Disconnect from the device: close dev nodes, etc.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070045 void disconnect() override;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070046 // Initialize static camera characteristics for individual device.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070047 int initStaticInfo(camera_metadata_t** out) override;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070048 // Initialize device info: facing, orientation, resource cost,
49 // and conflicting devices (/conflicting devices length).
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070050 void initDeviceInfo(camera_info_t* info) override;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070051 // Initialize whole device (templates/etc) when opened.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070052 int initDevice() override;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070053 // Verify settings are valid for a capture with this device.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070054 bool isValidCaptureSettings(const camera_metadata_t* settings) override;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070055
56 // The camera device path. For example, /dev/video0.
57 const std::string mDevicePath;
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070058 // The opened device fd.
59 ScopedFd mDeviceFd;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070060
61 DISALLOW_COPY_AND_ASSIGN(V4L2Camera);
62};
63
64} // namespace v4l2_camera_hal
65
66#endif // V4L2_CAMERA_H