blob: d9af15da63dd81564c5348844bbb8c277b2fc720 [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
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -070019#ifndef V4L2_CAMERA_HAL_V4L2_CAMERA_H_
20#define V4L2_CAMERA_HAL_V4L2_CAMERA_H_
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070021
Ari Hausman-Cohen49925842016-06-21 14:07:58 -070022#include <array>
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070023#include <string>
24
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070025#include <camera/CameraMetadata.h>
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070026
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -070027#include "camera.h"
28#include "common.h"
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070029#include "metadata/metadata.h"
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -070030#include "v4l2_wrapper.h"
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070031
32namespace 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.
37class V4L2Camera : public default_camera_hal::Camera {
38public:
Ari Hausman-Cohen681eaa22016-07-21 16:28:17 -070039 // 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-Cohen73442152016-06-08 15:50:49 -070042 ~V4L2Camera();
43
44private:
Ari Hausman-Cohen681eaa22016-07-21 16:28:17 -070045 // Constructor private to allow failing on bad input.
46 // Use NewV4L2Camera instead.
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070047 V4L2Camera(int id, std::shared_ptr<V4L2Wrapper> v4l2_wrapper,
48 std::unique_ptr<Metadata> metadata);
Ari Hausman-Cohen681eaa22016-07-21 16:28:17 -070049
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070050 // default_camera_hal::Camera virtual methods.
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070051 // Connect to the device: open dev nodes, etc.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070052 int connect() override;
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070053 // Disconnect from the device: close dev nodes, etc.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070054 void disconnect() override;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070055 // Initialize static camera characteristics for individual device.
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070056 int initStaticInfo(android::CameraMetadata* out) override;
57 // Initialize a template of the given type.
58 int initTemplate(int type, android::CameraMetadata* out) override;
59 // Initialize device info: resource cost and conflicting devices
60 // (/conflicting devices length).
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070061 void initDeviceInfo(camera_info_t* info) override;
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070062 // Extra initialization of device when opened.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070063 int initDevice() override;
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -070064 // Verify stream configuration is device-compatible.
65 bool isSupportedStreamSet(default_camera_hal::Stream** streams,
66 int count, uint32_t mode) override;
67 // Set up the device for a stream, and get the maximum number of
68 // buffers that stream can handle (max_buffers is an output parameter).
69 int setupStream(default_camera_hal::Stream* stream,
70 uint32_t* max_buffers) override;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070071 // Verify settings are valid for a capture with this device.
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070072 bool isValidCaptureSettings(const android::CameraMetadata& settings) override;
73 // Set settings for a capture.
74 int setSettings(
75 const android::CameraMetadata& new_settings) override;
Ari Hausman-Cohen24e541c2016-07-21 11:20:30 -070076 // Enqueue a buffer to receive data from the camera.
77 int enqueueBuffer(const camera3_stream_buffer_t* camera_buffer) override;
78 // Get the shutter time and updated settings for the most recent frame.
79 // The metadata parameter is both an input and output; frame-specific
80 // result fields should be appended to what is passed in.
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070081 int getResultSettings(android::CameraMetadata* metadata, uint64_t* timestamp);
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070082
Ari Hausman-Cohen660f8b82016-07-19 17:27:52 -070083 // V4L2 helper.
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070084 std::shared_ptr<V4L2Wrapper> device_;
85 std::unique_ptr<V4L2Wrapper::Connection> connection_;
86 std::unique_ptr<Metadata> metadata_;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070087
Ari Hausman-Cohenabbf9cc2016-08-23 11:59:59 -070088 int32_t max_input_streams_;
89 std::array<int, 3> max_output_streams_; // {raw, non-stalling, stalling}.
Ari Hausman-Cohen49925842016-06-21 14:07:58 -070090
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070091 DISALLOW_COPY_AND_ASSIGN(V4L2Camera);
92};
93
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -070094} // namespace v4l2_camera_hal
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070095
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -070096#endif // V4L2_CAMERA_HAL_V4L2_CAMERA_H