1 /* 2 * Copyright (C) 2021–2022 Beijing OSWare Technology Co., Ltd 3 * This file contains confidential and proprietary information of 4 * OSWare Technology Co., Ltd 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #ifndef HOS_CAMERA_V4L2_BUFFER_H 20 #define HOS_CAMERA_V4L2_BUFFER_H 21 22 #include <mutex> 23 #include <map> 24 #include <cstring> 25 #include <sys/ioctl.h> 26 #include <sys/mman.h> 27 #include <linux/videodev2.h> 28 #if !defined(V4L2_UTEST) && !defined (V4L2_MAIN_TEST) 29 #include <stream.h> 30 #include <camera.h> 31 #else 32 #include "v4l2_temp.h" 33 #endif 34 #include "v4l2_common.h" 35 #include "imx8mm_image_buffer.h" 36 37 typedef struct AdapterBuffer { 38 void* start; 39 size_t length; 40 void* userBufPtr; 41 }; 42 43 namespace OHOS::Camera { 44 class HosV4L2Buffers { 45 public: 46 HosV4L2Buffers(enum v4l2_memory memType, enum v4l2_buf_type bufferType); 47 ~HosV4L2Buffers(); 48 49 RetCode V4L2ReqBuffers(int fd, int unsigned buffCont); 50 RetCode V4L2ReleaseBuffers(int fd); 51 52 RetCode V4L2QueueBuffer(int fd, const std::shared_ptr<FrameSpec>& frameSpec); 53 RetCode V4L2DequeueBuffer(int fd); 54 55 RetCode V4L2AllocBuffer(int fd, const std::shared_ptr<FrameSpec>& frameSpec); 56 57 void SetCallback(BufCallback cb); 58 59 RetCode Flush(int fd); 60 61 private: 62 BufCallback dequeueBuffer_; 63 64 using FrameMap = std::map<unsigned int, std::shared_ptr<FrameSpec>>; 65 std::map<int, FrameMap> queueBuffers_; 66 std::map<int, FrameMap> adapterBuffers_; 67 68 std::mutex bufferLock_; 69 70 struct AdapterBuffer* adapterBufferList; 71 void* virAddr; 72 73 enum v4l2_memory memoryType_; 74 enum v4l2_buf_type bufferType_; 75 76 Imx8mmImageAdditionalInfo *additional_info_; 77 }; 78 } // namespace OHOS::Camera 79 #endif // HOS_CAMERA_V4L2_BUFFER_H 80