1 2 /* 3 * Copyright (C) 2024 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #pragma once 19 20 #include <linux/videodev2.h> 21 #include "common/libs/fs/shared_fd.h" 22 #include "common/libs/utils/result.h" 23 24 namespace cuttlefish { 25 26 // Opens a v4l2 device, located at given [device_path]. The device is then 27 // configured to receive frames of the given format, width, and height. Note 28 // that only format V4L2_PIX_FMT_BGRX32 is supported at this time 29 Result<SharedFD> V4l2InitDevice(const std::string& device_path, int format, 30 int width, int height); 31 32 // Returns # of bytes per pixel of given format, for 33 // frame size calculations 34 // Note that only format V4L2_PIX_FMT_BGRX32 is supported at this time 35 Result<size_t> V4l2GetBPP(int format); 36 37 // Returns size in bytes of single frame of given v4l2 format 38 // Note that only format V4L2_PIX_FMT_BGRX32 is supported at this time 39 Result<size_t> V4l2GetFrameSize(int format, int width, int height); 40 41 // Returns size in bytes of a single line data in video fram image 42 // Note that only format V4L2_PIX_FMT_BGRX32 is supported at this time 43 Result<size_t> V4l2GetLineWidth(int format, int width); 44 45 // Dump to logger debug info of the given v4l2_format 46 void V4l2PrintFormat(struct v4l2_format* vid_format); 47 48 // The following two optional methods are used for debugging / testing v4l2 49 // devices, not by the runtime streamer. 50 Result<void> V4l2StreamFile(); 51 52 // Reads a file containing raw frames in BGRA32 format. 53 Result<std::vector<char>> V4l2ReadRawFile(const std::string& filename); 54 55 } // End namespace cuttlefish