1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HOS_CAMERA_V4L2_COMMON_H 17 #define HOS_CAMERA_V4L2_COMMON_H 18 19 #include <string> 20 #include <cstdint> 21 #include <functional> 22 #include <iostream> 23 #include <memory> 24 #include <vector> 25 #if defined(V4L2_UTEST) || defined (V4L2_MAIN_TEST) 26 #include "v4l2_temp.h" 27 #else 28 #include <stream.h> 29 #endif 30 31 namespace OHOS::Camera { 32 #define MAXSTREAMCOUNT 4 33 #define MAXVIDEODEVICE 24 34 #define DEVICENAMEX "/dev/video" 35 #define MAXUVCNODE 10 36 37 struct V4l2Fract { 38 int32_t numerator; 39 int32_t denominator; 40 }; 41 42 struct V4l2Rect { 43 int32_t left; 44 int32_t top; 45 uint32_t width; 46 uint32_t height; 47 }; 48 49 struct V4l2CropCap { 50 struct V4l2Rect bounds; 51 struct V4l2Rect defrect; 52 struct V4l2Fract pixelaspect; 53 }; 54 55 struct V4l2FmtDesc { 56 std::string description; 57 uint32_t pixelformat; 58 uint32_t width; 59 uint32_t height; 60 uint32_t sizeimage; 61 struct V4l2Fract fps; 62 }; 63 64 using DeviceFormat = struct _V4l2DeviceFormat { 65 uint32_t portId; 66 struct V4l2CropCap cropcap; 67 struct V4l2Rect crop; 68 struct V4l2FmtDesc fmtdesc; 69 }; 70 71 struct V4l2Menu { 72 uint32_t id; 73 uint32_t index; 74 int64_t value; 75 std::string name; 76 }; 77 78 using DeviceControl = struct _V4l2Control { 79 uint32_t id; 80 uint32_t ctrl_class; 81 uint32_t type; 82 uint32_t flags; 83 int32_t minimum; 84 int32_t maximum; 85 int32_t step; 86 int32_t default_value; 87 int32_t value; 88 std::string name; 89 std::vector<V4l2Menu> menu; 90 }; 91 92 enum V4l2FmtCmd : uint32_t { 93 CMD_V4L2_GET_FORMAT, 94 CMD_V4L2_SET_FORMAT, 95 CMD_V4L2_GET_CROPCAP, 96 CMD_V4L2_SET_CROP, 97 CMD_V4L2_GET_CROP, 98 CMD_V4L2_SET_FPS, 99 CMD_V4L2_GET_FPS, 100 }; 101 102 namespace { 103 static constexpr uint32_t RCERRORFD = -1; 104 } 105 106 using BufCallback = std::function<void(std::shared_ptr<FrameSpec>)>; 107 using UvcCallback = std::function<void(const std::string, std::vector<DeviceControl>&, 108 std::vector<DeviceFormat>&, bool)>; 109 } 110 #endif // HOS_CAMERA_V4L2_COMMON_H 111