• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BUFFER_H
17 #define HOS_CAMERA_V4L2_BUFFER_H
18 
19 #include <mutex>
20 #include <map>
21 #include <cstring>
22 #include <linux/videodev2.h>
23 #include <sys/ioctl.h>
24 #include "v4l2_common.h"
25 #if defined(V4L2_UTEST) || defined (V4L2_MAIN_TEST)
26 #include "v4l2_temp.h"
27 #else
28 #include <stream.h>
29 #include <camera.h>
30 #endif
31 
32 namespace OHOS::Camera {
33 class HosV4L2Buffers {
34 public:
35     HosV4L2Buffers(enum v4l2_memory memType, enum v4l2_buf_type bufferType);
36     ~HosV4L2Buffers();
37 
38     RetCode V4L2ReqBuffers(int fd, int unsigned buffCont);
39     RetCode V4L2ReleaseBuffers(int fd);
40 
41     RetCode V4L2QueueBuffer(int fd, const std::shared_ptr<FrameSpec>& frameSpec);
42     RetCode V4L2DequeueBuffer(int fd);
43 
44     RetCode V4L2AllocBuffer(int fd, const std::shared_ptr<FrameSpec>& frameSpec);
45 
46     void SetCallback(BufCallback cb);
47 
48     RetCode Flush(int fd);
49 
50 private:
51     BufCallback dequeueBuffer_;
52 
53     using FrameMap = std::map<unsigned int, std::shared_ptr<FrameSpec>>;
54     std::map<int, FrameMap> queueBuffers_;
55 
56     std::mutex bufferLock_;
57 
58     enum v4l2_memory memoryType_;
59     enum v4l2_buf_type bufferType_;
60 };
61 } // namespace OHOS::Camera
62 #endif // HOS_CAMERA_V4L2_BUFFER_H
63