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_FILEFORMAT_H
17 #define HOS_CAMERA_V4L2_FILEFORMAT_H
18 
19 #include <vector>
20 #include <cstring>
21 #include <fcntl.h>
22 #include <linux/videodev2.h>
23 #include <sys/ioctl.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include "v4l2_common.h"
27 #if defined(V4L2_UTEST) || defined (V4L2_MAIN_TEST)
28 #include "v4l2_temp.h"
29 #else
30 #include <camera.h>
31 #endif
32 
33 namespace OHOS::Camera {
34 class HosFileFormat {
35 public:
36     HosFileFormat();
37     ~HosFileFormat();
38     RetCode V4L2GetFmt(int fd, DeviceFormat& format);
39     RetCode V4L2SetFmt(int fd, DeviceFormat& format);
40     RetCode V4L2GetCrop(int fd, DeviceFormat& format);
41     RetCode V4L2SetCrop(int fd, DeviceFormat& format);
42     RetCode V4L2GetCropCap(int fd, DeviceFormat& format);
43     RetCode V4L2GetFmtDescs(int fd, std::vector<DeviceFormat>& fmtDesc);
44     int V4L2OpenDevice(const std::string& deviceName);
45     void V4L2CloseDevice(int fd);
46     void V4L2MatchDevice(const std::vector<std::string>& cameraIDs);
47     int V4L2SearchBufType(int fd);
48 
49 private:
50     RetCode V4L2GetCapability(int fd, const std::string& dev_name, const std::string& cameraId);
51     void V4L2GetCurrentFormat(int fd, std::vector<DeviceFormat>& fmtDesc,
52         struct v4l2_frmsizeenum &frmSize, struct v4l2_fmtdesc &enumFmtDesc);
53     RetCode V4L2SearchFormat(int fd, std::vector<DeviceFormat>& fmtDesc);
54     enum v4l2_buf_type bufType_ = V4L2_BUF_TYPE_PRIVATE;
55 };
56 } // namespace OHOS::Camera
57 #endif // HOS_CAMERA_V4L2_FILEFORMAT_H
58